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 a9d4418 commit 0e76c6c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,15 @@ public static ObservationList parseConfirmedCOVNotification(String changeOfValue
int timeRemainingSec = 0;
Octet contextTag = covReader.next();
if (SDContextTag.fromOctet(contextTag) == SDContextTag.TimeStamp) {
if (contextTag.getSecondNibble() == 9) {
if (contextTag.getSecondNibble() == '9') {
//read one octet
Octet timeRemainingOctet = covReader.next();
timeRemainingSec = toInt(timeRemainingOctet);
}
}

//List of values


//Confirmed notifications 2901
// String devicdId = "TODO"; //TODO #4 find source device from APDU, NPDU or IP address/port
// Octet intiatingDeviceidKey = covReader.next();
// Octet[] initiatingDeviceIdValue = covReader.nextOctets(4);
// Octet monitoredDeviceIdKey = covReader.next();
// Octet[] monitoredDeviceIdValue = covReader.nextOctets(4);
// Octet timeRemainingKey = covReader.next();
// Octet timeRemainingValue = covReader.next();
//4e095519012e4441a4cccd2f4f

String resultListHexString = covReader.unprocessedHexString();
resultListHexString = filterResultList(resultListHexString);
Expand All @@ -174,9 +165,23 @@ public static ObservationList parseConfirmedCOVNotification(String changeOfValue
PropertyIdentifier propertyId = null;
if (contextTagKey != null && contextTagKey.equals(new Octet("09"))) {
Octet contextTagValue = covReader.next();
//PresentValue
propertyId = PropertyIdentifier.fromPropertyIdentifierHex(contextTagValue.toString());
}
//Property Array Index
//1901, 19 = array, 01 = length

if (propertyId != null) {
Octet valueTypeOctet = covReader.next(); //19
int arraySize = -1;
if (valueTypeOctet.equals(new Octet("19"))) {
Octet sizeOctet = covReader.next();
arraySize = toInt(sizeOctet);
}
if (arraySize > -1) {
//exptect array
//array start = 2e, end i 2f
}
Octet valueTagKey = covReader.next();
Octet propertyIdKey = covReader.next();
char lengthChar = propertyIdKey.getSecondNibble();
Expand Down Expand Up @@ -224,4 +229,20 @@ static String filterResultList(String hexString) {
}
return listResulHexString;
}

static String findArrayContent(OctetReader fullReader) {
String arrayContent = "";
Octet foundOctet = null;
do {
foundOctet = fullReader.next();
if (foundOctet.equals(new Octet("2f"))) {
break;
}
if (!foundOctet.equals(new Octet("2e"))) {
arrayContent += foundOctet.toString();
}

} while (fullReader.hasNext());
return arrayContent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import no.entra.bacnet.json.bvlc.BvlcResult;
import no.entra.bacnet.json.npdu.NpduParser;
import no.entra.bacnet.json.npdu.NpduResult;
import no.entra.bacnet.json.reader.OctetReader;
import no.entra.bacnet.json.services.Service;
import no.entra.bacnet.json.services.ServiceParser;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -46,4 +47,12 @@ void validateRestartTime() {
//#13 Fix test to fail, then succed
}

@Test
void findArray() {
String arrayWithMoreHex = "2e4441a4cccd2f4f";
OctetReader reader = new OctetReader(arrayWithMoreHex);
String arrayContent = ObservationParser.findArrayContent(reader);
assertEquals("4441a4cccd", arrayContent);
assertEquals("4f", reader.unprocessedHexString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ void findConfirmedCov() {
@Test
void verifyConfirmedCOVNotificationSingleProperty() {
String observedHex = "810a0025010400050f0109121c020200252c0000000039004e095519012e4441a4cccd2f4f";
// 810a0025010400050f0109121c020200252c0000000039004e095519012e4441a4cccd2f4f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
String expectedJson = "{" +
" \"configurationRequest\": {" +
" \"observations\": [{" +
Expand All @@ -38,7 +37,7 @@ void verifyConfirmedCOVNotificationSingleProperty() {
" \"deviceId\": \"131109\"," +
" \"objectId\": \"0\"" +
" }," +
" \"value\": \"2e\"" +
" \"value\": \"20\"" +
" }]" +
" }," +
" \"sender\": \"unknown\"," +
Expand Down

0 comments on commit 0e76c6c

Please sign in to comment.