You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2021/07/02 13:50:49 UTC
[plc4x] 05/05: - Got the Profinet driver to compile
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch feature/profinet-chris
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit ef1f54ecd7309dd552367ff80957fb660a6d3edf
Author: cdutz <ch...@c-ware.de>
AuthorDate: Fri Jul 2 15:48:12 2021 +0200
- Got the Profinet driver to compile
---
.../org/apache/plc4x/java/PlcDriverManager.java | 4 +-
.../plc4x/java/api/messages/PlcDiscoveryItem.java | 18 +++++++
.../services/org.apache.plc4x.java.api.PlcDriver | 19 --------
.../services/org.apache.plc4x.java.api.PlcDriver | 19 --------
plc4j/drivers/profinet/pom.xml | 10 ++--
.../plc4x/java/profinet/utils/StaticHelper.java | 30 ++++++++++++
.../java/spi/messages/DefaultPlcDiscoveryItem.java | 27 ++++++++++
.../spi/messages/DefaultPlcDiscoveryRequest.java | 7 +++
.../spi/messages/DefaultPlcDiscoveryResponse.java | 7 +++
.../resources/protocols/profinet/profinet.mspec | 57 +++++++++++++---------
10 files changed, 130 insertions(+), 68 deletions(-)
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/PlcDriverManager.java b/plc4j/api/src/main/java/org/apache/plc4x/java/PlcDriverManager.java
index af4ee11..e3a3fbe 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/PlcDriverManager.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/PlcDriverManager.java
@@ -70,7 +70,7 @@ public class PlcDriverManager {
* @throws PlcConnectionException an exception if the connection attempt failed.
*/
public PlcConnection getConnection(String url) throws PlcConnectionException {
- PlcDriver driver = getDriver(url);
+ PlcDriver driver = getDriverForUrl(url);
PlcConnection connection = driver.getConnection(url);
connection.connect();
return connection;
@@ -85,7 +85,7 @@ public class PlcDriverManager {
* @throws PlcConnectionException an exception if the connection attempt failed.
*/
public PlcConnection getConnection(String url, PlcAuthentication authentication) throws PlcConnectionException {
- PlcDriver driver = getDriver(url);
+ PlcDriver driver = getDriverForUrl(url);
PlcConnection connection = driver.getConnection(url, authentication);
connection.connect();
return connection;
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcDiscoveryItem.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcDiscoveryItem.java
index b0692e0..fddc77d 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcDiscoveryItem.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcDiscoveryItem.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.plc4x.java.api.messages;
import java.net.URL;
diff --git a/plc4j/api/src/test/resources/META-INF/services/org.apache.plc4x.java.api.PlcDriver b/plc4j/api/src/test/resources/META-INF/services/org.apache.plc4x.java.api.PlcDriver
index e017520..1565d3a 100644
--- a/plc4j/api/src/test/resources/META-INF/services/org.apache.plc4x.java.api.PlcDriver
+++ b/plc4j/api/src/test/resources/META-INF/services/org.apache.plc4x.java.api.PlcDriver
@@ -16,23 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
org.apache.plc4x.java.mock.ApiMockDriver
diff --git a/plc4j/api/src/test/resources/test/META-INF/services/org.apache.plc4x.java.api.PlcDriver b/plc4j/api/src/test/resources/test/META-INF/services/org.apache.plc4x.java.api.PlcDriver
index 9e42a5e..4211709 100644
--- a/plc4j/api/src/test/resources/test/META-INF/services/org.apache.plc4x.java.api.PlcDriver
+++ b/plc4j/api/src/test/resources/test/META-INF/services/org.apache.plc4x.java.api.PlcDriver
@@ -16,23 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
org.apache.plc4x.java.mock.DuplicateMockDriver
diff --git a/plc4j/drivers/profinet/pom.xml b/plc4j/drivers/profinet/pom.xml
index c71fab9..60fecd6 100644
--- a/plc4j/drivers/profinet/pom.xml
+++ b/plc4j/drivers/profinet/pom.xml
@@ -102,7 +102,6 @@
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<usedDependencies combine.children="append">
- <usedDependency>org.apache.plc4x:plc4j-transport-raw-socket</usedDependency>
<usedDependency>org.apache.plc4x:plc4x-code-generation-language-java</usedDependency>
<usedDependency>org.apache.plc4x:plc4x-protocols-profinet</usedDependency>
</usedDependencies>
@@ -128,16 +127,17 @@
<artifactId>plc4j-transport-raw-socket</artifactId>
<version>0.9.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-utils-pcap-shared</artifactId>
+ <version>0.9.0-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
</dependency>
<dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-annotations</artifactId>
- </dependency>
- <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
diff --git a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/utils/StaticHelper.java b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/utils/StaticHelper.java
new file mode 100644
index 0000000..984d8ff
--- /dev/null
+++ b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/utils/StaticHelper.java
@@ -0,0 +1,30 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.plc4x.java.profinet.utils;
+
+public class StaticHelper {
+
+ public static int stringLength(String str) {
+ if (str == null) {
+ return 0;
+ }
+ return str.length();
+ }
+
+}
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcDiscoveryItem.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcDiscoveryItem.java
index 1516793..8d9f4eb 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcDiscoveryItem.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcDiscoveryItem.java
@@ -22,11 +22,14 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.apache.plc4x.java.api.messages.PlcDiscoveryItem;
+import org.apache.plc4x.java.spi.generation.ParseException;
+import org.apache.plc4x.java.spi.generation.WriteBuffer;
import org.apache.plc4x.java.spi.utils.XmlSerializable;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.Map;
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "className")
@@ -95,6 +98,30 @@ public class DefaultPlcDiscoveryItem implements PlcDiscoveryItem, XmlSerializabl
}
@Override
+ public void serialize(WriteBuffer writeBuffer) throws ParseException {
+ writeBuffer.pushContext(getClass().getSimpleName());
+
+ writeBuffer.writeString("protocolCode", protocolCode.getBytes(StandardCharsets.UTF_8).length * 8, StandardCharsets.UTF_8.name(), protocolCode);
+ writeBuffer.writeString("transportCode", transportCode.getBytes(StandardCharsets.UTF_8).length * 8, StandardCharsets.UTF_8.name(), transportCode);
+ writeBuffer.writeString("transportUrl", transportUrl.toString().getBytes(StandardCharsets.UTF_8).length * 8, StandardCharsets.UTF_8.name(), transportUrl.toString());
+ if(options != null && !options.isEmpty()) {
+ writeBuffer.pushContext("options");
+ for (Map.Entry<String, String> optionEntry : options.entrySet()) {
+ writeBuffer.pushContext("option");
+ writeBuffer.writeString("name", optionEntry.getKey().getBytes(StandardCharsets.UTF_8).length * 8, StandardCharsets.UTF_8.name(), optionEntry.getKey());
+ writeBuffer.writeString("value", optionEntry.getValue().getBytes(StandardCharsets.UTF_8).length * 8, StandardCharsets.UTF_8.name(), optionEntry.getValue());
+ writeBuffer.popContext("option");
+ }
+ writeBuffer.popContext("options");
+ }
+ if(name != null && !name.isEmpty()) {
+ writeBuffer.writeString("name", name.getBytes(StandardCharsets.UTF_8).length * 8, StandardCharsets.UTF_8.name(), name);
+ }
+
+ writeBuffer.popContext(getClass().getSimpleName());
+ }
+
+ @Override
public void xmlSerialize(Element parent) {
Document doc = parent.getOwnerDocument();
Element messageElement = doc.createElement("PlcDiscoveryItem");
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcDiscoveryRequest.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcDiscoveryRequest.java
index fa97866..967eed6 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcDiscoveryRequest.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcDiscoveryRequest.java
@@ -20,6 +20,8 @@ package org.apache.plc4x.java.spi.messages;
import com.fasterxml.jackson.annotation.*;
import org.apache.plc4x.java.api.messages.*;
+import org.apache.plc4x.java.spi.generation.ParseException;
+import org.apache.plc4x.java.spi.generation.WriteBuffer;
import org.apache.plc4x.java.spi.utils.XmlSerializable;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -42,6 +44,11 @@ public class DefaultPlcDiscoveryRequest implements PlcDiscoveryRequest, XmlSeria
}
@Override
+ public void serialize(WriteBuffer writeBuffer) throws ParseException {
+ // TODO: Implement
+ }
+
+ @Override
public void xmlSerialize(Element parent) {
Document doc = parent.getOwnerDocument();
Element messageElement = doc.createElement("PlcDiscoveryRequest");
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcDiscoveryResponse.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcDiscoveryResponse.java
index 8b0a59e..d5c62ec 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcDiscoveryResponse.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcDiscoveryResponse.java
@@ -20,6 +20,8 @@ package org.apache.plc4x.java.spi.messages;
import com.fasterxml.jackson.annotation.*;
import org.apache.plc4x.java.api.messages.*;
+import org.apache.plc4x.java.spi.generation.ParseException;
+import org.apache.plc4x.java.spi.generation.WriteBuffer;
import org.apache.plc4x.java.spi.utils.XmlSerializable;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -49,6 +51,11 @@ public class DefaultPlcDiscoveryResponse implements PlcDiscoveryResponse, XmlSer
}
@Override
+ public void serialize(WriteBuffer writeBuffer) throws ParseException {
+ // TODO: Implement
+ }
+
+ @Override
public void xmlSerialize(Element parent) {
Document doc = parent.getOwnerDocument();
Element messageElement = doc.createElement("PlcDiscoveryResponse");
diff --git a/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec b/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
index 277b4d5..90ad1af 100644
--- a/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
+++ b/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
@@ -43,7 +43,7 @@
[discriminatedType 'DCP_PDU'
[discriminator ProfinetFrameId 'frameId']
[discriminator ServiceId 'serviceId']
- [discriminator ServiceType 'serviceType']
+ [simple ServiceType 'serviceType']
// 4.3.1.3.4 (Page 95)
[simple uint 32 'xid']
// 4.3.1.3.5 (Page 95ff)
@@ -69,13 +69,13 @@
// Packet a Profinet station might emit once it is turned on
['DCP_Hello_ReqPDU','HELLO','false' DCP_Hello_ReqPDU
- [simple NameOfStationBlockRes 'nameOfStationBlockRes']
- [simple IPParameterBlockRes 'iPParameterBlockRes']
- [simple DeviceIdBlockRes 'deviceIdBlockRes']
- [simple DeviceVendorBlockRes 'deviceVendorBlockRes']
- [simple DeviceOptionsBlockRes 'deviceOptionsBlockRes']
- [simple DeviceRoleBlockRes 'deviceRoleBlockRes']
- [simple DeviceInitiativeBlockRes 'deviceInitiativeBlockRes']
+// [simple NameOfStationBlockRes 'nameOfStationBlockRes']
+// [simple IPParameterBlockRes 'iPParameterBlockRes']
+// [simple DeviceIdBlockRes 'deviceIdBlockRes']
+// [simple DeviceVendorBlockRes 'deviceVendorBlockRes']
+// [simple DeviceOptionsBlockRes 'deviceOptionsBlockRes']
+// [simple DeviceRoleBlockRes 'deviceRoleBlockRes']
+// [simple DeviceInitiativeBlockRes 'deviceInitiativeBlockRes']
]
////////////////////////////////////////////////////////////////////////////
@@ -83,24 +83,24 @@
////////////////////////////////////////////////////////////////////////////
['DCP_GetSet_PDU','GET','false' DCP_Get_ReqPDU
- [simple GetReqBlock 'getReqBlock']
+// [simple GetReqBlock 'getReqBlock']
]
['DCP_GetSet_PDU','GET','true' DCP_Get_ResPDU
- [simple GetResBlock 'getResBlock']
- [simple GetNegResBlock 'getNegResBlock']
+// [simple GetResBlock 'getResBlock']
+// [simple GetNegResBlock 'getNegResBlock']
]
['DCP_GetSet_PDU','SET','false' DCP_Set_ReqPDU
- [simple StartTransactionBlock 'startTransactionBlock']
- [simple BlockQualifier 'blockQualifier']
- [simple SetResetReqBlock 'setResetReqBlock']
- [simple SetReqBlock 'setReqBlock']
- [simple StopTransactionBlock 'stopTransactionBlock']
- [simple BlockQualifier 'blockQualifier']
+// [simple StartTransactionBlock 'startTransactionBlock']
+// [simple BlockQualifier 'blockQualifier']
+// [simple SetResetReqBlock 'setResetReqBlock']
+// [simple SetReqBlock 'setReqBlock']
+// [simple StopTransactionBlock 'stopTransactionBlock']
+// [simple BlockQualifier 'blockQualifier']
]
['DCP_GetSet_PDU','SET','true' DCP_Set_ResPDU
- [simple SetResBlock 'setResBlock']
- [simple SetNegResBlock 'setNegResBlock']
+// [simple SetResBlock 'setResBlock']
+// [simple SetNegResBlock 'setNegResBlock']
]
]
]
@@ -143,13 +143,13 @@
[reserved uint 16 '0x0000' ]
// TODO: Figure out how to do this correctly.
[simple string '-1' 'deviceVendorValue' ]
- [padding uint 8 'pad' '0x00' 'LENGTH(deviceVendorValue) % 2 == 1' ]
+ [padding uint 8 'pad' '0x00' 'STATIC_CALL("org.apache.plc4x.java.profinet.utils.StaticHelper.stringLength", deviceVendorValue) % 2' ]
]
['DEVICE_PROPERTIES_OPTION','2' DCP_BlockDevicePropertiesNameOfStation
[reserved uint 16 '0x0000' ]
// TODO: Figure out how to do this correctly.
[simple string '-1' 'nameOfStation' ]
- [padding uint 8 'pad' '0x00' 'LENGTH(nameOfStation) % 2 == 1' ]
+ [padding uint 8 'pad' '0x00' 'STATIC_CALL("org.apache.plc4x.java.profinet.utils.StaticHelper.stringLength", nameOfStation) % 2' ]
]
['DEVICE_PROPERTIES_OPTION','3' DCP_BlockDevicePropertiesDeviceId
[reserved uint 16 '0x0000' ]
@@ -171,7 +171,7 @@
['DEVICE_PROPERTIES_OPTION','6' DCP_BlockDevicePropertiesAliasName
[reserved uint 16 '0x0000' ]
[simple string '-1' 'aliasNameValue' ]
- [padding uint 8 'pad' '0x00' 'LENGTH(nameOfStation) % 2 == 1' ]
+ [padding uint 8 'pad' '0x00' 'STATIC_CALL("org.apache.plc4x.java.profinet.utils.StaticHelper.stringLength", aliasNameValue) % 2' ]
]
['DEVICE_PROPERTIES_OPTION','7' DCP_BlockDevicePropertiesDeviceInstance
[reserved uint 16 '0x0000' ]
@@ -273,7 +273,7 @@
[type 'ServiceType'
[reserved uint 5 '0x00']
[simple bit 'notSupported']
- [reserved bit '0x00']
+ [reserved uint 1 '0x00']
[simple bit 'response']
]
@@ -328,6 +328,17 @@
['0xFF' ALL_SELECTOR_OPTION]
]
+[enum uint 3 'VirtualLanPriority' [string '2' 'acronym']
+ ['0x0' BACKGROUND ['BK' ]]
+ ['0x1' BEST_EFFORT ['BE' ]]
+ ['0x2' EXCELLENT_EFFORT ['EE' ]]
+ ['0x3' CRITICAL_APPLICATIONS ['CA' ]]
+ ['0x4' VIDEO ['VI' ]]
+ ['0x5' VOICE ['VO' ]]
+ ['0x6' INTERNETWORK_CONTROL ['IC' ]]
+ ['0x7' NETWORK_CONTROL ['NC' ]]
+]
+
// There are some special MAC addresses reserved:
// 01-0E-CF-00-00-00: As destination for DCP-Identify-ReqPDU (The FrameID is then required to be set to 0xFEFE)
// 01-0E-CF-00-00-01: As destination for DCP-Helo-ReqPDU (The FrameID is then required to be set to 0xFEFC)