You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2022/11/04 15:45:31 UTC

[plc4x] 02/03: fix(plc4j/bacnet): fix static helper creating wrong requests

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

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

commit 3577f8bfd2036eeda7319d5198212ad78f54d094
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Nov 4 16:45:00 2022 +0100

    fix(plc4j/bacnet): fix static helper creating wrong requests
---
 .../java/bacnetip/readwrite/utils/StaticHelper.java    | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/readwrite/utils/StaticHelper.java b/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/readwrite/utils/StaticHelper.java
index 4b3ce0c43..c494461ca 100644
--- a/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/readwrite/utils/StaticHelper.java
+++ b/plc4j/drivers/bacnet/src/main/java/org/apache/plc4x/java/bacnetip/readwrite/utils/StaticHelper.java
@@ -161,6 +161,14 @@ public class StaticHelper {
             if (!BACnetConfirmedServiceRequestReinitializeDeviceReinitializedStateOfDevice.isDefined((short) rawValue))
                 return BACnetConfirmedServiceRequestReinitializeDeviceReinitializedStateOfDevice.VENDOR_PROPRIETARY_VALUE;
             return BACnetConfirmedServiceRequestReinitializeDeviceReinitializedStateOfDevice.enumForValue((short) rawValue);
+        } else if (declaringClass == BACnetSegmentation.class) {
+            if (!BACnetSegmentation.isDefined((short) rawValue))
+                LOGGER.error("{} not defined for segmentation falling back to no segmentation", rawValue);
+            return BACnetSegmentation.NO_SEGMENTATION;
+        } else if (declaringClass == BACnetVendorId.class) {
+            if (!BACnetVendorId.isDefined((short) rawValue))
+                return BACnetVendorId.UNKNOWN_VENDOR;
+            return BACnetVendorId.enumForValue((short) rawValue);
         } else {
             LOGGER.warn("using reflection for {}", declaringClass);
             Optional<Method> enumForValue = Arrays.stream(declaringClass.getDeclaredMethods()).filter(method -> method.getName().equals("enumForValue")).findAny();
@@ -242,6 +250,10 @@ public class StaticHelper {
             valueValue = ((BACnetConfirmedServiceRequestReinitializeDeviceReinitializedStateOfDevice) value).getValue();
         } else if (value.getDeclaringClass() == BACnetConfirmedServiceRequestDeviceCommunicationControlEnableDisable.class) {
             valueValue = ((BACnetConfirmedServiceRequestDeviceCommunicationControlEnableDisable) value).getValue();
+        } else if (value.getDeclaringClass() == BACnetSegmentation.class) {
+            valueValue = ((BACnetSegmentation) value).getValue();
+        } else if (value.getDeclaringClass() == BACnetVendorId.class) {
+            valueValue = ((BACnetVendorId) value).getValue();
         } else {
             LOGGER.warn("using reflection for {}", value.getDeclaringClass());
             try {
@@ -437,7 +449,7 @@ public class StaticHelper {
     }
 
     public static BACnetApplicationTagObjectIdentifier createBACnetApplicationTagObjectIdentifier(int objectType, long instance) {
-        BACnetTagHeader header = new BACnetTagHeader((byte) BACnetDataType.SIGNED_INTEGER.getValue(), TagClass.APPLICATION_TAGS, (byte) 4, null, null, null, null);
+        BACnetTagHeader header = new BACnetTagHeader((byte) BACnetDataType.BACNET_OBJECT_IDENTIFIER.getValue(), TagClass.APPLICATION_TAGS, (byte) 4, null, null, null, null);
         BACnetObjectType objectTypeEnum = BACnetObjectType.enumForValue(objectType);
         int proprietaryValue = 0;
         if (objectType >= 128 || !BACnetObjectType.isDefined(objectType)) {
@@ -494,8 +506,8 @@ public class StaticHelper {
     }
 
     public static BACnetSegmentationTagged creatBACnetSegmentationTagged(BACnetSegmentation value) {
-        BACnetTagHeader header = createBACnetTagHeaderBalanced(false, (byte) 0, 1);
-        return new BACnetSegmentationTagged(header, value, (short) 0, TagClass.APPLICATION_TAGS);
+        BACnetTagHeader header = createBACnetTagHeaderBalanced(false, (byte) 9, 1);
+        return new BACnetSegmentationTagged(header, value, (short) 9, TagClass.APPLICATION_TAGS);
     }
 
     public static BACnetApplicationTagBoolean createBACnetApplicationTagBoolean(boolean value) {