Skip to content

Commit

Permalink
feat(bacnet): added helper for floating point data types
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Apr 20, 2022
1 parent aa14db7 commit 1c229ce
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
28 changes: 24 additions & 4 deletions plc4go/internal/plc4go/bacnetip/readwrite/model/StaticHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func CreateBACnetClosingTag(tagNum uint8) *BACnetClosingTag {
}

func CreateBACnetApplicationTagObjectIdentifier(objectType uint16, instance uint32) *BACnetApplicationTagObjectIdentifier {
header := NewBACnetTagHeader(0xC, TagClass_APPLICATION_TAGS, uint8(4), nil, nil, nil, nil)
header := NewBACnetTagHeader(uint8(BACnetDataType_BACNET_OBJECT_IDENTIFIER), TagClass_APPLICATION_TAGS, uint8(4), nil, nil, nil, nil)
objectTypeEnum := BACnetObjectTypeByValue(objectType)
proprietaryValue := uint16(0)
if objectType >= 128 || !BACnetObjectTypeKnows(objectType) {
Expand Down Expand Up @@ -411,7 +411,7 @@ func CreateBACnetContextTagPropertyIdentifier(tagNum uint8, propertyType uint32)

func CreateBACnetApplicationTagEnumerated(value uint32) *BACnetApplicationTagEnumerated {
length, payload := CreateEnumeratedPayload(value)
header := CreateBACnetTagHeaderBalanced(false, 0x9, length)
header := CreateBACnetTagHeaderBalanced(false, uint8(BACnetDataType_ENUMERATED), length)
result := NewBACnetApplicationTagEnumerated(payload, header)
return CastBACnetApplicationTagEnumerated(result)
}
Expand All @@ -432,7 +432,7 @@ func CreateEnumeratedPayload(value uint32) (uint32, *BACnetTagPayloadEnumerated)

func CreateBACnetApplicationTagUnsignedInteger(value uint32) *BACnetApplicationTagUnsignedInteger {
length, payload := CreateUnsignedPayload(value)
header := CreateBACnetTagHeaderBalanced(false, 0x2, length)
header := CreateBACnetTagHeaderBalanced(false, uint8(BACnetDataType_UNSIGNED_INTEGER), length)
return NewBACnetApplicationTagUnsignedInteger(payload, header)
}

Expand Down Expand Up @@ -475,7 +475,7 @@ func CreateUnsignedPayload(value uint32) (uint32, *BACnetTagPayloadUnsignedInteg

func CreateBACnetApplicationTagSignedInteger(value int32) *BACnetApplicationTagSignedInteger {
length, payload := CreateSignedPayload(value)
header := CreateBACnetTagHeaderBalanced(true, 0x3, length)
header := CreateBACnetTagHeaderBalanced(true, uint8(BACnetDataType_SIGNED_INTEGER), length)
return NewBACnetApplicationTagSignedInteger(payload, header)
}

Expand Down Expand Up @@ -512,6 +512,26 @@ func CreateSignedPayload(value int32) (uint32, *BACnetTagPayloadSignedInteger) {
return length, payload
}

func CreateBACnetApplicationTagReal(value float32) *BACnetApplicationTagReal {
header := CreateBACnetTagHeaderBalanced(false, uint8(BACnetDataType_REAL), 4)
return NewBACnetApplicationTagReal(NewBACnetTagPayloadReal(value), header)
}

func CreateBACnetContextTagReal(tagNumber uint8, value float32) *BACnetContextTagReal {
header := CreateBACnetTagHeaderBalanced(true, tagNumber, 4)
return NewBACnetContextTagReal(NewBACnetTagPayloadReal(value), header, tagNumber, true)
}

func CreateBACnetApplicationTagDouble(value float64) *BACnetApplicationTagDouble {
header := CreateBACnetTagHeaderBalanced(false, uint8(BACnetDataType_DOUBLE), 8)
return NewBACnetApplicationTagDouble(NewBACnetTagPayloadDouble(value), header)
}

func CreateBACnetContextTagDouble(tagNumber uint8, value float64) *BACnetContextTagDouble {
header := CreateBACnetTagHeaderBalanced(true, tagNumber, 8)
return NewBACnetContextTagDouble(NewBACnetTagPayloadDouble(value), header, tagNumber, true)
}

func requiredLength(value uint) uint32 {
var length uint32
switch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public static BACnetClosingTag createBACnetClosingTag(short tagNum) {
}

public static BACnetApplicationTagObjectIdentifier createBACnetApplicationTagObjectIdentifier(int objectType, long instance) {
BACnetTagHeader header = new BACnetTagHeader((byte) 0xC, TagClass.APPLICATION_TAGS, (byte) 4, null, null, null, null);
BACnetTagHeader header = new BACnetTagHeader((byte) BACnetDataType.SIGNED_INTEGER.getValue(), TagClass.APPLICATION_TAGS, (byte) 4, null, null, null, null);
BACnetObjectType objectTypeEnum = BACnetObjectType.enumForValue(objectType);
int proprietaryValue = 0;
if (objectType >= 128 || !BACnetObjectType.isDefined(objectType)) {
Expand Down Expand Up @@ -451,7 +451,7 @@ public static BACnetContextTagPropertyIdentifier createBACnetContextTagPropertyI

public static BACnetApplicationTagEnumerated createBACnetApplicationTagEnumerated(long value) {
Pair<Long, BACnetTagPayloadEnumerated> lengthPayload = CreateEnumeratedPayload(value);
BACnetTagHeader header = createBACnetTagHeaderBalanced(false, (byte) 0x9, lengthPayload.getLeft());
BACnetTagHeader header = createBACnetTagHeaderBalanced(false, BACnetDataType.ENUMERATED.getValue(), lengthPayload.getLeft());
return new BACnetApplicationTagEnumerated(header, lengthPayload.getRight());
}

Expand All @@ -470,7 +470,7 @@ public static Pair<Long, BACnetTagPayloadEnumerated> CreateEnumeratedPayload(lon

public static BACnetApplicationTagUnsignedInteger createBACnetApplicationTagUnsignedInteger(long value) {
Pair<Long, BACnetTagPayloadUnsignedInteger> lengthPayload = createUnsignedPayload(value);
BACnetTagHeader header = createBACnetTagHeaderBalanced(false, (byte) 0x2, lengthPayload.getLeft());
BACnetTagHeader header = createBACnetTagHeaderBalanced(false, BACnetDataType.UNSIGNED_INTEGER.getValue(), lengthPayload.getLeft());
return new BACnetApplicationTagUnsignedInteger(header, lengthPayload.getRight());
}

Expand Down Expand Up @@ -509,7 +509,7 @@ public static Pair<Long, BACnetTagPayloadUnsignedInteger> createUnsignedPayload(

public static BACnetApplicationTagSignedInteger createBACnetApplicationTagSignedInteger(long value) {
Pair<Long, BACnetTagPayloadSignedInteger> lengthPayload = createSignedPayload(value);
BACnetTagHeader header = createBACnetTagHeaderBalanced(false, (byte) 0x3, lengthPayload.getLeft());
BACnetTagHeader header = createBACnetTagHeaderBalanced(false, BACnetDataType.SIGNED_INTEGER.getValue(), lengthPayload.getLeft());
return new BACnetApplicationTagSignedInteger(header, lengthPayload.getRight());
}

Expand Down Expand Up @@ -542,6 +542,26 @@ public static Pair<Long, BACnetTagPayloadSignedInteger> createSignedPayload(long
return Pair.of(length, payload);
}

public static BACnetApplicationTagReal createBACnetApplicationTagReal(float value) {
BACnetTagHeader header = createBACnetTagHeaderBalanced(false, BACnetDataType.REAL.getValue(), 4);
return new BACnetApplicationTagReal(header, new BACnetTagPayloadReal(value));
}

public static BACnetContextTagReal createBACnetContextTagReal(byte tagNumber, float value) {
BACnetTagHeader header = createBACnetTagHeaderBalanced(true, tagNumber, 4);
return new BACnetContextTagReal(header, new BACnetTagPayloadReal(value), (short) tagNumber, true);
}

public static BACnetApplicationTagDouble createBACnetApplicationTagDouble(double value) {
BACnetTagHeader header = createBACnetTagHeaderBalanced(false, BACnetDataType.DOUBLE.getValue(), 8);
return new BACnetApplicationTagDouble(header, new BACnetTagPayloadDouble(value));
}

public static BACnetContextTagDouble createBACnetContextTagDouble(byte tagNumber, double value) {
BACnetTagHeader header = createBACnetTagHeaderBalanced(true, tagNumber, 8);
return new BACnetContextTagDouble(header, new BACnetTagPayloadDouble(value), (short) tagNumber, true);
}

private static long requiredLength(long value) {
long length;
if (value < 0x100)
Expand Down

0 comments on commit 1c229ce

Please sign in to comment.