Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
#14 find array with value
Browse files Browse the repository at this point in the history
  • Loading branch information
baardl committed Aug 25, 2020
1 parent 0e76c6c commit 6c4b9af
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ public static ObservationList parseConfirmedCOVNotification(String changeOfValue
if (arraySize > -1) {
//exptect array
//array start = 2e, end i 2f
String arrayContent = findArrayContent(covReader);
OctetReader arrayReader = new OctetReader(arrayContent);
if (arrayReader.next().toString().equals("44")) {
String realValueString = arrayReader.next(4);

}
}
Octet valueTagKey = covReader.next();
Octet propertyIdKey = covReader.next();
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/no/entra/bacnet/json/utils/HexUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ public static int toInt(Octet[] octets) throws IllegalArgumentException {
return toInt(octetsToString(octets));
}

public static float toFloat(String hexString) throws IllegalArgumentException {
if (hexString == null || hexString.isEmpty()) {
throw new IllegalArgumentException("hexString may not be null.");
}
Long realLong = Long.parseLong(hexString, 16);
Float real = Float.intBitsToFloat(realLong.intValue());
return real;
}



public static long toLong(String hexString) {
if (hexString == null || hexString.isEmpty()) {
throw new IllegalArgumentException("hexString may not be null.");
}
if (hexString.length() == 16) {
return (toLong(hexString.substring(0, 1)) << 60)
| toLong(hexString.substring(1));
}
return Long.parseLong(hexString, 16);
}

public static String toBitString(char nibble) {
String bitString = null;
if (HexMatcher.isValidHexChar(nibble)) {
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/no/entra/bacnet/json/utils/HexUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,14 @@ void toIntTest() {
assertThrows(IllegalArgumentException.class, () -> toInt(isnull));
assertEquals(12, toInt("0c"));
}

@Test
void toFloatTest() {
assertThrows(IllegalArgumentException.class, () -> toFloat(""));
String isnull = null;
assertThrows(IllegalArgumentException.class, () -> toFloat(isnull));
assertEquals(Float.valueOf("20.6"), toFloat("41a4cccd"));
}


}

0 comments on commit 6c4b9af

Please sign in to comment.