Skip to content

Commit

Permalink
feat(bacnet): added helper for bit string data types
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Apr 20, 2022
1 parent 00417e4 commit 3cb822b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
20 changes: 20 additions & 0 deletions plc4go/internal/plc4go/bacnetip/readwrite/model/StaticHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,26 @@ func CreateBACnetContextTagCharacterString(tagNumber uint8, baCnetCharacterEncod
return NewBACnetContextTagCharacterString(NewBACnetTagPayloadCharacterString(baCnetCharacterEncoding, value, uint32(len(value)+1)), header, tagNumber, true)
}

func CreateBACnetApplicationTagBitString(value []bool) *BACnetApplicationTagBitString {
numberOfBytesNeeded := (len(value) + 7) / 8
unusedBits := 8 - (len(value) % 8)
if unusedBits == 8 {
unusedBits = 0
}
header := CreateBACnetTagHeaderBalanced(false, uint8(BACnetDataType_BIT_STRING), uint32(numberOfBytesNeeded+1))
return NewBACnetApplicationTagBitString(NewBACnetTagPayloadBitString(uint8(unusedBits), value, make([]bool, unusedBits), uint32(numberOfBytesNeeded+1)), header)
}

func CreateBACnetContextTagBitString(tagNumber uint8, value []bool) *BACnetContextTagBitString {
numberOfBytesNeeded := (len(value) + 7) / 8
unusedBits := 8 - (len(value) % 8)
if unusedBits == 8 {
unusedBits = 0
}
header := CreateBACnetTagHeaderBalanced(true, tagNumber, uint32(numberOfBytesNeeded+1))
return NewBACnetContextTagBitString(NewBACnetTagPayloadBitString(uint8(unusedBits), value, make([]bool, unusedBits), uint32(numberOfBytesNeeded+1)), 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 @@ -28,6 +28,8 @@
import org.slf4j.LoggerFactory;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import static org.apache.plc4x.java.spi.generation.WithReaderWriterArgs.WithAdditionalStringRepresentation;

Expand Down Expand Up @@ -592,6 +594,26 @@ public static BACnetContextTagCharacterString createBACnetContextTagCharacterStr
return new BACnetContextTagCharacterString(header, new BACnetTagPayloadCharacterString(baCnetCharacterEncoding, value, (long) value.length() + 1), (short) tagNumber, true);
}

public static BACnetApplicationTagBitString createBACnetApplicationTagBitString(List<Boolean> value) {
long numberOfBytesNeeded = (value.size() + 7) / 8;
short unusedBits = (short) (8 - (value.size() % 8));
if (unusedBits == 8) {
unusedBits = 0;
}
BACnetTagHeader header = createBACnetTagHeaderBalanced(false, BACnetDataType.BIT_STRING.getValue(), numberOfBytesNeeded + 1);
return new BACnetApplicationTagBitString(header, new BACnetTagPayloadBitString(unusedBits, value, new ArrayList<>(unusedBits), numberOfBytesNeeded + 1));
}

public static BACnetContextTagBitString createBACnetContextTagBitString(byte tagNumber, List<Boolean> value) {
long numberOfBytesNeeded = (value.size() + 7) / 8;
short unusedBits = (short) (8 - (value.size() % 8));
if (unusedBits == 8) {
unusedBits = 0;
}
BACnetTagHeader header = createBACnetTagHeaderBalanced(true, tagNumber, numberOfBytesNeeded + 1);
return new BACnetContextTagBitString(header, new BACnetTagPayloadBitString(unusedBits, value, new ArrayList<>(unusedBits), numberOfBytesNeeded + 1), (short) tagNumber, true);
}

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

0 comments on commit 3cb822b

Please sign in to comment.