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 2020/03/01 11:36:55 UTC

[plc4x] 02/02: - Updated the NiFi version in the NiFi Integration - Made the KNXNetIP Driver a little more robust

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 3c52aad8d4572cf6a275e229538a4f2679cfc2b8
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sun Mar 1 12:36:47 2020 +0100

    - Updated the NiFi version in the NiFi Integration
    - Made the KNXNetIP Driver a little more robust
---
 .../knxnetip/protocol/KnxNetIpProtocolLogic.java   | 120 +++++++++++----------
 .../apache-nifi/nifi-plc4x-nar/pom.xml             |  31 ++++++
 plc4j/integrations/apache-nifi/pom.xml             |   4 +-
 3 files changed, 94 insertions(+), 61 deletions(-)

diff --git a/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/protocol/KnxNetIpProtocolLogic.java b/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/protocol/KnxNetIpProtocolLogic.java
index 64da9be..45046d7 100644
--- a/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/protocol/KnxNetIpProtocolLogic.java
+++ b/plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/protocol/KnxNetIpProtocolLogic.java
@@ -237,68 +237,70 @@ public class KnxNetIpProtocolLogic extends Plc4xProtocolBase<KNXNetIPMessage> im
 
             // Only if the communication channel id match, do anything with the request.
             if(curCommunicationChannelId == communicationChannelId) {
-                CEMIBusmonInd busmonInd = (CEMIBusmonInd) tunnelingRequest.getCemi();
-                if (busmonInd.getCemiFrame() instanceof CEMIFrameData) {
-                    CEMIFrameData cemiDataFrame = (CEMIFrameData) busmonInd.getCemiFrame();
-
-                    // The first byte is actually just 6 bit long, but we'll treat it as a full one.
-                    // So here we create a byte array containing the first and all the following bytes.
-                    byte[] payload = new byte[1 + cemiDataFrame.getData().length];
-                    payload[0] = cemiDataFrame.getDataFirstByte();
-                    System.arraycopy(cemiDataFrame.getData(), 0, payload, 1, cemiDataFrame.getData().length);
-
-                    final KNXAddress sourceAddress = cemiDataFrame.getSourceAddress();
-                    final byte[] destinationGroupAddress = cemiDataFrame.getDestinationAddress();
-
-                    // Decode the group address depending on the project settings.
-                    ReadBuffer addressBuffer = new ReadBuffer(destinationGroupAddress);
-                    final KNXGroupAddress knxGroupAddress =
-                        KNXGroupAddressIO.staticParse(addressBuffer, groupAddressType);
-                    final String destinationAddress = toString(knxGroupAddress);
-
-                    // If there is an ETS5 model provided, continue decoding the payload.
-                    if(ets5Model != null) {
-                        final GroupAddress groupAddress = ets5Model.getGroupAddresses().get(destinationAddress);
-
-                        if((groupAddress != null) && (groupAddress.getType() != null)){
-                            LOGGER.info("Message from: '" + toString(sourceAddress) +
-                                "' to: '" + destinationAddress + "'");
-
-                            // Parse the payload depending on the type of the group-address.
-                            ReadBuffer rawDataReader = new ReadBuffer(payload);
-                            final PlcValue value = KnxDatapointIO.staticParse(rawDataReader,
-                                groupAddress.getType().getMainType(), groupAddress.getType().getSubType());
-
-                            // Assemble the plc4x return data-structure.
-                            Map<String, PlcValue> dataPointMap = new HashMap<>();
-                            dataPointMap.put("sourceAddress", new PlcString(toString(sourceAddress)));
-                            dataPointMap.put("targetAddress", new PlcString(groupAddress.getGroupAddress()));
-                            if(groupAddress.getFunction() != null) {
-                                dataPointMap.put("location", new PlcString(groupAddress.getFunction().getSpaceName()));
-                                dataPointMap.put("function", new PlcString(groupAddress.getFunction().getName()));
+                if(tunnelingRequest.getCemi() instanceof CEMIBusmonInd) {
+                    CEMIBusmonInd busmonInd = (CEMIBusmonInd) tunnelingRequest.getCemi();
+                    if (busmonInd.getCemiFrame() instanceof CEMIFrameData) {
+                        CEMIFrameData cemiDataFrame = (CEMIFrameData) busmonInd.getCemiFrame();
+
+                        // The first byte is actually just 6 bit long, but we'll treat it as a full one.
+                        // So here we create a byte array containing the first and all the following bytes.
+                        byte[] payload = new byte[1 + cemiDataFrame.getData().length];
+                        payload[0] = cemiDataFrame.getDataFirstByte();
+                        System.arraycopy(cemiDataFrame.getData(), 0, payload, 1, cemiDataFrame.getData().length);
+
+                        final KNXAddress sourceAddress = cemiDataFrame.getSourceAddress();
+                        final byte[] destinationGroupAddress = cemiDataFrame.getDestinationAddress();
+
+                        // Decode the group address depending on the project settings.
+                        ReadBuffer addressBuffer = new ReadBuffer(destinationGroupAddress);
+                        final KNXGroupAddress knxGroupAddress =
+                            KNXGroupAddressIO.staticParse(addressBuffer, groupAddressType);
+                        final String destinationAddress = toString(knxGroupAddress);
+
+                        // If there is an ETS5 model provided, continue decoding the payload.
+                        if (ets5Model != null) {
+                            final GroupAddress groupAddress = ets5Model.getGroupAddresses().get(destinationAddress);
+
+                            if ((groupAddress != null) && (groupAddress.getType() != null)) {
+                                LOGGER.info("Message from: '" + toString(sourceAddress) +
+                                    "' to: '" + destinationAddress + "'");
+
+                                // Parse the payload depending on the type of the group-address.
+                                ReadBuffer rawDataReader = new ReadBuffer(payload);
+                                final PlcValue value = KnxDatapointIO.staticParse(rawDataReader,
+                                    groupAddress.getType().getMainType(), groupAddress.getType().getSubType());
+
+                                // Assemble the plc4x return data-structure.
+                                Map<String, PlcValue> dataPointMap = new HashMap<>();
+                                dataPointMap.put("sourceAddress", new PlcString(toString(sourceAddress)));
+                                dataPointMap.put("targetAddress", new PlcString(groupAddress.getGroupAddress()));
+                                if (groupAddress.getFunction() != null) {
+                                    dataPointMap.put("location", new PlcString(groupAddress.getFunction().getSpaceName()));
+                                    dataPointMap.put("function", new PlcString(groupAddress.getFunction().getName()));
+                                } else {
+                                    dataPointMap.put("location", null);
+                                    dataPointMap.put("function", null);
+                                }
+                                dataPointMap.put("description", new PlcString(groupAddress.getName()));
+                                dataPointMap.put("unitOfMeasurement", new PlcString(groupAddress.getType().getName()));
+                                dataPointMap.put("value", value);
+                                final PlcStruct dataPoint = new PlcStruct(dataPointMap);
+
+                                // Send the data-structure.
+                                publishEvent(groupAddress, dataPoint);
                             } else {
-                                dataPointMap.put("location", null);
-                                dataPointMap.put("function", null);
+                                LOGGER.warn("Message from: '" + toString(sourceAddress) + "'" +
+                                    " to unknown group address: '" + destinationAddress + "'" +
+                                    "\n payload: '" + Hex.encodeHexString(payload) + "'");
                             }
-                            dataPointMap.put("description", new PlcString(groupAddress.getName()));
-                            dataPointMap.put("unitOfMeasurement", new PlcString(groupAddress.getType().getName()));
-                            dataPointMap.put("value", value);
-                            final PlcStruct dataPoint = new PlcStruct(dataPointMap);
-
-                            // Send the data-structure.
-                            publishEvent(groupAddress, dataPoint);
-                        } else {
-                            LOGGER.warn("Message from: '" + toString(sourceAddress) + "'" +
-                                " to unknown group address: '" + destinationAddress + "'" +
-                                "\n payload: '" + Hex.encodeHexString(payload) + "'");
                         }
-                    }
-                    // Else just output the raw payload.
-                    else {
-                        LOGGER.info("Raw Message: '" + KnxNetIpProtocolLogic.toString(sourceAddress) + "'" +
-                            " to: '" + destinationAddress + "'" +
-                            "\n payload: '" + Hex.encodeHexString(payload) + "'"
-                        );
+                        // Else just output the raw payload.
+                        else {
+                            LOGGER.info("Raw Message: '" + KnxNetIpProtocolLogic.toString(sourceAddress) + "'" +
+                                " to: '" + destinationAddress + "'" +
+                                "\n payload: '" + Hex.encodeHexString(payload) + "'"
+                            );
+                        }
                     }
                 }
 
diff --git a/plc4j/integrations/apache-nifi/nifi-plc4x-nar/pom.xml b/plc4j/integrations/apache-nifi/nifi-plc4x-nar/pom.xml
index 7d8fac3..101561a 100644
--- a/plc4j/integrations/apache-nifi/nifi-plc4x-nar/pom.xml
+++ b/plc4j/integrations/apache-nifi/nifi-plc4x-nar/pom.xml
@@ -57,6 +57,11 @@
               <usedDependency>org.apache.plc4x:plc4j-driver-opcua</usedDependency>
               <usedDependency>org.apache.plc4x:plc4j-driver-s7</usedDependency>
               <usedDependency>org.apache.plc4x:plc4j-driver-simulated</usedDependency>
+              <usedDependency>org.apache.plc4x:plc4j-transport-pcap-replay</usedDependency>
+              <usedDependency>org.apache.plc4x:plc4j-transport-raw-socket</usedDependency>
+              <usedDependency>org.apache.plc4x:plc4j-transport-serial</usedDependency>
+              <usedDependency>org.apache.plc4x:plc4j-transport-tcp</usedDependency>
+              <usedDependency>org.apache.plc4x:plc4j-transport-udp</usedDependency>
             </usedDependencies>
           </configuration>
         </plugin>
@@ -117,6 +122,32 @@
       <artifactId>plc4j-driver-simulated</artifactId>
       <version>0.7.0-SNAPSHOT</version>
     </dependency>
+
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-transport-pcap-replay</artifactId>
+      <version>0.7.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-transport-raw-socket</artifactId>
+      <version>0.7.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-transport-serial</artifactId>
+      <version>0.7.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-transport-tcp</artifactId>
+      <version>0.7.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-transport-udp</artifactId>
+      <version>0.7.0-SNAPSHOT</version>
+    </dependency>
   </dependencies>
 
 </project>
diff --git a/plc4j/integrations/apache-nifi/pom.xml b/plc4j/integrations/apache-nifi/pom.xml
index 40dd0fa..e2188e7 100644
--- a/plc4j/integrations/apache-nifi/pom.xml
+++ b/plc4j/integrations/apache-nifi/pom.xml
@@ -29,7 +29,7 @@
   <description>Integration module for integrating PLC4X into Apache Nifi.</description>
 
   <properties>
-    <nifi.version>1.9.2</nifi.version>
+    <nifi.version>1.11.3</nifi.version>
   </properties>
 
   <modules>
@@ -43,7 +43,7 @@
       <plugin>
         <groupId>org.apache.nifi</groupId>
         <artifactId>nifi-nar-maven-plugin</artifactId>
-        <version>1.2.0</version>
+        <version>1.3.1</version>
         <extensions>true</extensions>
       </plugin>
       <!-- Makes buildRevision and buildBranch available to the NAR Plugin so they can be populated in the MANIFEST -->