Skip to content

Commit

Permalink
feat(bacnet): added helpers for vendor id
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed May 23, 2022
1 parent 337ed95 commit 3a188a5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
22 changes: 22 additions & 0 deletions plc4go/protocols/bacnetip/readwrite/model/StaticHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,28 @@ func CreateBACnetPropertyIdentifierTagged(tagNum uint8, propertyType uint32) *BA
return NewBACnetPropertyIdentifierTagged(header, propertyTypeEnum, proprietaryValue, tagNum, TagClass_CONTEXT_SPECIFIC_TAGS)
}

func CreateBACnetVendorIdApplicationTagged(vendorId uint16) *BACnetVendorIdTagged {
header := NewBACnetTagHeader(0x2, TagClass_APPLICATION_TAGS, uint8(requiredLength(uint(vendorId))), nil, nil, nil, nil)
baCnetVendorId := BACnetVendorIdByValue(vendorId)
unknownVendorId := uint32(0)
if !BACnetVendorIdKnows(vendorId) {
baCnetVendorId = BACnetVendorId_UNKNOWN_VENDOR
unknownVendorId = uint32(vendorId)
}
return NewBACnetVendorIdTagged(header, baCnetVendorId, unknownVendorId, 0x2, TagClass_APPLICATION_TAGS)
}

func CreateBACnetVendorIdContextTagged(tagNum uint8, vendorId uint16) *BACnetVendorIdTagged {
header := NewBACnetTagHeader(tagNum, TagClass_CONTEXT_SPECIFIC_TAGS, uint8(requiredLength(uint(vendorId))), nil, nil, nil, nil)
baCnetVendorId := BACnetVendorIdByValue(vendorId)
unknownVendorId := uint32(0)
if !BACnetVendorIdKnows(vendorId) {
baCnetVendorId = BACnetVendorId_UNKNOWN_VENDOR
unknownVendorId = uint32(vendorId)
}
return NewBACnetVendorIdTagged(header, baCnetVendorId, unknownVendorId, tagNum, TagClass_CONTEXT_SPECIFIC_TAGS)
}

func CreateBACnetApplicationTagUnsignedInteger(value uint) *BACnetApplicationTagUnsignedInteger {
length, payload := CreateUnsignedPayload(value)
header := CreateBACnetTagHeaderBalanced(false, uint8(BACnetDataType_UNSIGNED_INTEGER), length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,28 @@ public static BACnetPropertyIdentifierTagged createBACnetPropertyIdentifierTagge
return new BACnetPropertyIdentifierTagged(header, propertyIdentifier, proprietaryValue, (short) tagNum, TagClass.CONTEXT_SPECIFIC_TAGS);
}

public static BACnetVendorIdTagged createBACnetVendorIdApplicationTagged(int vendorId) {
BACnetVendorId baCnetVendorId = BACnetVendorId.enumForValue(vendorId);
int unknownVendorId = 0;
if (!BACnetVendorId.isDefined(vendorId)) {
baCnetVendorId = BACnetVendorId.UNKNOWN_VENDOR;
unknownVendorId = vendorId;
}
BACnetTagHeader header = new BACnetTagHeader((byte) 0x2, TagClass.APPLICATION_TAGS, (byte) requiredLength(vendorId), null, null, null, null);
return new BACnetVendorIdTagged(header, baCnetVendorId, unknownVendorId, (short) 0x2, TagClass.APPLICATION_TAGS);
}

public static BACnetVendorIdTagged createBACnetVendorIdContextTagged(byte tagNum, int vendorId) {
BACnetVendorId baCnetVendorId = BACnetVendorId.enumForValue(vendorId);
int unknownVendorId = 0;
if (!BACnetVendorId.isDefined(vendorId)) {
baCnetVendorId = BACnetVendorId.UNKNOWN_VENDOR;
unknownVendorId = vendorId;
}
BACnetTagHeader header = new BACnetTagHeader(tagNum, TagClass.CONTEXT_SPECIFIC_TAGS, (byte) requiredLength(vendorId), null, null, null, null);
return new BACnetVendorIdTagged(header, baCnetVendorId, unknownVendorId, (short) tagNum, TagClass.CONTEXT_SPECIFIC_TAGS);
}

public static BACnetSegmentationTagged creatBACnetSegmentationTagged(BACnetSegmentation value) {
BACnetTagHeader header = createBACnetTagHeaderBalanced(false, (byte) 0, 1);
return new BACnetSegmentationTagged(header, value, (short) 0, TagClass.APPLICATION_TAGS);
Expand Down Expand Up @@ -543,7 +565,7 @@ public static BACnetApplicationTagOctetString createBACnetApplicationTagOctetStr

public static BACnetContextTagOctetString createBACnetContextTagOctetString(byte tagNumber, byte[] octets) {
BACnetTagHeader header = createBACnetTagHeaderBalanced(true, tagNumber, octets.length + 1);
return new BACnetContextTagOctetString(header, new BACnetTagPayloadOctetString(octets, (long) octets.length + 1), (short) tagNumber);
return new BACnetContextTagOctetString(header, new BACnetTagPayloadOctetString(octets, (long) octets.length + 1), (short) tagNumber);
}

public static BACnetApplicationTagCharacterString createBACnetApplicationTagCharacterString(BACnetCharacterEncoding baCnetCharacterEncoding, String value) {
Expand Down
5 changes: 3 additions & 2 deletions protocols/bacnetip/src/main/script/getVendorIds.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@ mspecTemplate = """
'STATIC_CALL("writeEnumGeneric", writeBuffer, value)'
'header.actualLength * 8' ]
[virtual bit isUnknownId
'value == BACnetVendorId.UNKNOWN_VENDOR' ]
'value == BACnetVendorId.UNKNOWN_VENDOR' ]
//TODO: change to uint32 once cast is inserted
[manual uint 32
unknownId
'STATIC_CALL("readProprietaryEnumGeneric", readBuffer, header.actualLength, isUnknownId)'
'STATIC_CALL("writeProprietaryEnumGeneric", writeBuffer, unknownId, isUnknownId)'
'_value.isUnknownId?header.actualLength * 8:0' ]
'_value.isUnknownId?header.actualLength * 8:0' ]
]
"""
SimpleTemplateEngine templateEngine = new SimpleTemplateEngine()
Expand Down

0 comments on commit 3a188a5

Please sign in to comment.