Skip to content

Commit

Permalink
fix(bacnet): added unmapped enums to static helper
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Jun 3, 2022
1 parent 535da88 commit 6ffab0e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
30 changes: 30 additions & 0 deletions plc4go/protocols/bacnetip/readwrite/model/StaticHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ package model
import (
"fmt"
"github.com/apache/plc4x/plc4go/internal/spi/utils"
"github.com/pkg/errors"
"math"
"math/big"
"reflect"
)
Expand All @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public static Object readEnumGenericFailing(ReadBuffer readBuffer, Long actualLe
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);
}
Expand Down

0 comments on commit 6ffab0e

Please sign in to comment.