From 8d302caad3c4c0fc86bd12666bc26f1b4fca016a Mon Sep 17 00:00:00 2001 From: baardl Date: Thu, 10 Sep 2020 07:37:13 +0200 Subject: [PATCH] #14 Push commit to correspond with issue on github. Will break the tests. --- .../json/observation/ObservationParser.java | 38 +++++++++++++++++-- .../entra/bacnet/json/values/ValueParser.java | 2 +- .../observation/ObservationParserTest.java | 4 +- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/main/java/no/entra/bacnet/json/observation/ObservationParser.java b/src/main/java/no/entra/bacnet/json/observation/ObservationParser.java index 4448f0e..69d962c 100644 --- a/src/main/java/no/entra/bacnet/json/observation/ObservationParser.java +++ b/src/main/java/no/entra/bacnet/json/observation/ObservationParser.java @@ -60,10 +60,24 @@ public static ObservationList mapToChangeOfValueObservation(Service service, Str Octet[] timeRemainingOctets = covReader.nextOctets(numTimeRemainingOctets); int timeRemainingSec = toInt(timeRemainingOctets); +// String resultListHexString = covReader.unprocessedHexString(); +// resultListHexString = filterResultList(resultListHexString); +// log.info("*** {}", resultListHexString); +// properties = findProperties(covReader, resultListHexString); + + String objectId = monitoredObjectId.getObjectType() + "_" + monitoredObjectId.getInstanceNumber(); + Source source = new Source(deviceId.getInstanceNumber(), objectId); + String resultListHexString = covReader.unprocessedHexString(); - resultListHexString = filterResultList(resultListHexString); - log.info("*** {}", resultListHexString); - properties = findProperties(covReader, resultListHexString); +// resultListHexString = filterResultList(resultListHexString); + List bacnetValues = parseListOfValues(resultListHexString); + for (Value bacnetValue : bacnetValues) { + String observationId = null; //TODO how to create unique id for the observation. Is that needed? + Object value = bacnetValue.getValue(); + String name = bacnetValue.getPropertyIdentifier().name(); + Observation observation = new Observation(observationId, source, value, name); + observations.add(observation); + } /* try { Octet startList = covReader.next(); @@ -93,6 +107,7 @@ public static ObservationList mapToChangeOfValueObservation(Service service, Str */ + /* if (properties != null && properties.size() > 0) { for (String key : properties.keySet()) { Object value = properties.get(key); @@ -112,6 +127,8 @@ public static ObservationList mapToChangeOfValueObservation(Service service, Str } } + */ + ObservationList observationList = new ObservationList(observations); observationList.setSubscriptionRemainingSeconds(timeRemainingSec); @@ -179,8 +196,20 @@ public static ObservationList parseConfirmedCOVNotification(String changeOfValue //List of values //4e095519012e4441a4cccd2f4f + String objectId = objectIdentifier.getObjectType() + "_" + objectIdentifier.getInstanceNumber(); + Source source = new Source(deviceId.getInstanceNumber(), objectId); + String resultListHexString = covReader.unprocessedHexString(); - resultListHexString = filterResultList(resultListHexString); +// resultListHexString = filterResultList(resultListHexString); + List bacnetValues = parseListOfValues(resultListHexString); + for (Value bacnetValue : bacnetValues) { + String observationId = null; //TODO how to create unique id for the observation. Is that needed? + Object value = bacnetValue.getValue(); + String name = bacnetValue.getPropertyIdentifier().name(); + Observation observation = new Observation(observationId, source, value, name); + observations.add(observation); + } + /* properties = findProperties(covReader, resultListHexString); if (properties != null && properties.size() > 0) { @@ -201,6 +230,7 @@ public static ObservationList parseConfirmedCOVNotification(String changeOfValue observations.add(observation); } } + */ ObservationList observationList = new ObservationList(observations); diff --git a/src/main/java/no/entra/bacnet/json/values/ValueParser.java b/src/main/java/no/entra/bacnet/json/values/ValueParser.java index 3370542..5d68718 100644 --- a/src/main/java/no/entra/bacnet/json/values/ValueParser.java +++ b/src/main/java/no/entra/bacnet/json/values/ValueParser.java @@ -101,7 +101,7 @@ public static List parseListOfValues(String listOfValuesHexString) { return values; } - private static Object findValue(ApplicationTag applicationTag, String valueHex) { + static Object findValue(ApplicationTag applicationTag, String valueHex) { Object value = null; int type = applicationTag.findType(); switch (type) { diff --git a/src/test/java/no/entra/bacnet/json/observation/ObservationParserTest.java b/src/test/java/no/entra/bacnet/json/observation/ObservationParserTest.java index 03d0b20..4190bd0 100644 --- a/src/test/java/no/entra/bacnet/json/observation/ObservationParserTest.java +++ b/src/test/java/no/entra/bacnet/json/observation/ObservationParserTest.java @@ -46,10 +46,10 @@ void validateUnConfirmedCovNotificationTest() { assertEquals("AnalogValue_1", source.getObjectId()); //Verify value - Observation observation = observations.getObservations().get(0); + Observation observation = observations.getObservations().get(1); assertEquals("StatusFlags", observation.getName()); assertEquals("0400", observation.getValue()); - observation = observations.getObservations().get(1); + observation = observations.getObservations().get(0); assertEquals("PresentValue", observation.getName()); assertEquals("00000000", observation.getValue());