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 69d962c..ccdb213 100644 --- a/src/main/java/no/entra/bacnet/json/observation/ObservationParser.java +++ b/src/main/java/no/entra/bacnet/json/observation/ObservationParser.java @@ -28,7 +28,14 @@ public class ObservationParser { private static final Logger log = getLogger(ObservationParser.class); - public static ObservationList mapToChangeOfValueObservation(Service service, String changeOfValueHexString) { + /** + * Transform a BacNet message notification describing values updated. Each message may contain a single update, + * or multiple updates from multiple sensors. + * @param service detect if the notification is single, multiple, confirmed or unconfirmed. + * @param changeOfValueHexString BacNet hex string where the BVLC and NPDU part is previously parsed, and removed. + * @return list of individual observations seen in this COV Notification. + */ + public static ObservationList parseChangeOfValueNotification(Service service, String changeOfValueHexString) { /* Confirmed COV 060109121c020003e92c008000013a012b4e09552e44000000002f096f2e8204002f4f diff --git a/src/main/java/no/entra/bacnet/json/services/UnconfirmedService.java b/src/main/java/no/entra/bacnet/json/services/UnconfirmedService.java index 0284478..4c4268b 100644 --- a/src/main/java/no/entra/bacnet/json/services/UnconfirmedService.java +++ b/src/main/java/no/entra/bacnet/json/services/UnconfirmedService.java @@ -6,7 +6,7 @@ import org.slf4j.Logger; import static no.entra.bacnet.json.configuration.ConfigurationParser.*; -import static no.entra.bacnet.json.observation.ObservationParser.mapToChangeOfValueObservation; +import static no.entra.bacnet.json.observation.ObservationParser.parseChangeOfValueNotification; import static org.slf4j.LoggerFactory.getLogger; public class UnconfirmedService extends Service { @@ -47,7 +47,7 @@ public static BacnetMessage tryToUnderstandUnconfirmedRequest(Service service) { break; case UnconfirmedCovNotification: String changeOfValueHexString = service.getUnprocessedHexString(); - bacnetMessage = mapToChangeOfValueObservation(service, changeOfValueHexString); + bacnetMessage = parseChangeOfValueNotification(service, changeOfValueHexString); break; default: log.trace("I do not know how to parse this service: {}", service); 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 50bdfcf..5bd0a84 100644 --- a/src/test/java/no/entra/bacnet/json/observation/ObservationParserTest.java +++ b/src/test/java/no/entra/bacnet/json/observation/ObservationParserTest.java @@ -18,7 +18,7 @@ import java.util.List; -import static no.entra.bacnet.json.observation.ObservationParser.mapToChangeOfValueObservation; +import static no.entra.bacnet.json.observation.ObservationParser.parseChangeOfValueNotification; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.slf4j.LoggerFactory.getLogger; @@ -36,7 +36,7 @@ void validateUnConfirmedCovNotificationTest() { String apduHexString = npduResult.getUnprocessedHexString(); Service service = ServiceParser.fromApduHexString(apduHexString); String covHexString = service.getUnprocessedHexString(); - ObservationList observations = mapToChangeOfValueObservation(service, covHexString); + ObservationList observations = parseChangeOfValueNotification(service, covHexString); assertNotNull(observations); Source source = observations.getObservations().get(0).getSource(); assertEquals("1001", source.getDeviceId()); @@ -69,7 +69,7 @@ void buildObservationFromUnConfirmedCovNotificationTest() { String apduHexString = npduResult.getUnprocessedHexString(); Service service = ServiceParser.fromApduHexString(apduHexString); String covHexString = service.getUnprocessedHexString(); - ObservationList observations = mapToChangeOfValueObservation(service, covHexString); + ObservationList observations = parseChangeOfValueNotification(service, covHexString); assertNotNull(observations); assertEquals(2, observations.getObservations().size()); } @@ -84,7 +84,7 @@ void buildObservationFromConfirmedCovNotificationTest() { String apduHexString = npduResult.getUnprocessedHexString(); Service service = ServiceParser.fromApduHexString(apduHexString); String covHexString = service.getUnprocessedHexString(); - ObservationList observations = mapToChangeOfValueObservation(service, covHexString); + ObservationList observations = parseChangeOfValueNotification(service, covHexString); assertNotNull(observations); Source source = observations.getObservations().get(0).getSource(); assertEquals("1001", source.getDeviceId()); @@ -111,7 +111,7 @@ void buildObservationFromConfirmedCovNotificationTest() { void validateConfirmedCovNotificationWithPresentValue() { String covHexString = "0f0109121c020200252c0000000039004e095519012e4441a4cccd2f4f"; Service service = new Service(PduType.ConfirmedRequest, null); - ObservationList observations = mapToChangeOfValueObservation(service, covHexString); + ObservationList observations = parseChangeOfValueNotification(service, covHexString); // ObservationList observations = parseConfirmedCOVNotification(covHexString); Observation observation = observations.getObservations().get(0); assertEquals("131109", observation.getSource().getDeviceId()); @@ -131,10 +131,9 @@ void validateRestartTime() { String apduHexString = npduResult.getUnprocessedHexString(); Service service = ServiceParser.fromApduHexString(apduHexString); String covHexString = service.getUnprocessedHexString(); - ObservationList observations = mapToChangeOfValueObservation(service, covHexString); + ObservationList observations = parseChangeOfValueNotification(service, covHexString); assertNotNull(observations); assertEquals(2, observations.getObservations().size()); - //#13 Fix test to fail, then succed } @Test