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/06/03 11:32:17 UTC

[plc4x] branch develop updated: fix(bacnet): added unmapped enums to static helper

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


The following commit(s) were added to refs/heads/develop by this push:
     new 6ffab0e4d6 fix(bacnet): added unmapped enums to static helper
6ffab0e4d6 is described below

commit 6ffab0e4d6133356aebcc1c04b2a0222d6c3cf8c
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Jun 3 13:32:11 2022 +0200

    fix(bacnet): added unmapped enums to static helper
---
 .../bacnetip/readwrite/model/StaticHelper.go       | 30 ++++++++++++++++++++++
 .../bacnetip/readwrite/utils/StaticHelper.java     |  8 ++++++
 2 files changed, 38 insertions(+)

diff --git a/plc4go/protocols/bacnetip/readwrite/model/StaticHelper.go b/plc4go/protocols/bacnetip/readwrite/model/StaticHelper.go
index 2e03f90709..e357ded7b9 100644
--- a/plc4go/protocols/bacnetip/readwrite/model/StaticHelper.go
+++ b/plc4go/protocols/bacnetip/readwrite/model/StaticHelper.go
@@ -22,6 +22,8 @@ package model
 import (
 	"fmt"
 	"github.com/apache/plc4x/plc4go/internal/spi/utils"
+	"github.com/pkg/errors"
+	"math"
 	"math/big"
 	"reflect"
 )
@@ -34,17 +36,45 @@ func ReadEnumGenericFailing(readBuffer utils.ReadBuffer, actualLength uint32, te
 	}
 	switch template.(type) {
 	case BACnetConfirmedServiceRequestDeviceCommunicationControlEnableDisable:
+		if value := uint8(rawValue); rawValue > math.MaxUint8 || BACnetConfirmedServiceRequestDeviceCommunicationControlEnableDisableKnows(value) {
+			return 0, errors.Errorf("unmapped value %d", rawValue)
+		}
 		return BACnetConfirmedServiceRequestDeviceCommunicationControlEnableDisable(rawValue), nil
 	case BACnetConfirmedServiceRequestReinitializeDeviceReinitializedStateOfDevice:
+		if value := uint8(rawValue); rawValue > math.MaxUint8 || BACnetConfirmedServiceRequestReinitializeDeviceReinitializedStateOfDeviceKnows(value) {
+			return 0, errors.Errorf("unmapped value %d", rawValue)
+		}
 		return BACnetConfirmedServiceRequestReinitializeDeviceReinitializedStateOfDevice(rawValue), nil
 	case BACnetSegmentation:
+		if value := uint8(rawValue); rawValue > math.MaxUint8 || BACnetSegmentationKnows(value) {
+			return 0, errors.Errorf("unmapped value %d", rawValue)
+		}
 		return BACnetSegmentation(rawValue), nil
 	case BACnetAction:
+		if value := uint8(rawValue); rawValue > math.MaxUint8 || BACnetActionKnows(value) {
+			return 0, errors.Errorf("unmapped value %d", rawValue)
+		}
 		return BACnetAction(rawValue), nil
 	case BACnetNotifyType:
+		if value := uint8(rawValue); rawValue > math.MaxUint8 || BACnetNotifyTypeKnows(value) {
+			return 0, errors.Errorf("unmapped value %d", rawValue)
+		}
 		return BACnetNotifyType(rawValue), nil
 	case BACnetBinaryPV:
+		if value := uint8(rawValue); rawValue > math.MaxUint8 || BACnetBinaryPVKnows(value) {
+			return 0, errors.Errorf("unmapped value %d", rawValue)
+		}
 		return BACnetBinaryPV(rawValue), nil
+	case BACnetLockStatus:
+		if value := uint8(rawValue); rawValue > math.MaxUint8 || BACnetLockStatusKnows(value) {
+			return 0, errors.Errorf("unmapped value %d", rawValue)
+		}
+		return BACnetLockStatus(rawValue), nil
+	case BACnetDoorSecuredStatus:
+		if value := uint8(rawValue); rawValue > math.MaxUint8 || BACnetDoorSecuredStatusKnows(value) {
+			return 0, errors.Errorf("unmapped value %d", rawValue)
+		}
+		return BACnetDoorSecuredStatus(rawValue), nil
 	default:
 		panic(fmt.Sprintf("support for %T not yet implemented", template))
 	}
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 7b8c2c081b..11e317a576 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
@@ -70,6 +70,14 @@ public class StaticHelper {
             if (!BACnetBinaryPV.isDefined((short) rawValue))
                 throw new ParseException("Invalid value " + rawValue + " for " + BACnetBinaryPV.class.getSimpleName());
             return BACnetBinaryPV.enumForValue((short) rawValue);
+        } else if (declaringClass == BACnetLockStatus.class) {
+            if (!BACnetLockStatus.isDefined((short) rawValue))
+                throw new ParseException("Invalid value " + rawValue + " for " + BACnetLockStatus.class.getSimpleName());
+            return BACnetLockStatus.enumForValue((short) rawValue);
+        } else if (declaringClass == BACnetDoorSecuredStatus.class) {
+            if (!BACnetDoorSecuredStatus.isDefined((short) rawValue))
+                throw new ParseException("Invalid value " + rawValue + " for " + BACnetDoorSecuredStatus.class.getSimpleName());
+            return BACnetDoorSecuredStatus.enumForValue((short) rawValue);
         }
         throw new ParseException("Unmapped type " + declaringClass);
     }