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

Commit

Permalink
#11 Display service choice
Browse files Browse the repository at this point in the history
  • Loading branch information
baardl committed Jan 10, 2020
1 parent accd697 commit fe7bbb7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Parse BacnetUDP and convert to Json.

## Json "schema"

Observation
```
{"observation": {
"id": "uuid when known",
Expand All @@ -18,6 +19,25 @@ Parse BacnetUDP and convert to Json.
}
```

ConfigurationRequest
```
{
"configurationRequest": {
"observedAt": "2020-01-10T12:40:15.064620",
"id": "TODO",
"source": "1234",
"properties": {
"Request": "IHave",
"NotificationClass": "0",
"Device": "12",
"ObjectName": "eg the Norwegian \"tverrfaglig merkesystem\" aka tfm"
}
},
"sender": "1234",
"service": "IHave"
}
```

## How To

String bacnetMessage -> You need to find the HexString from an Datagram Packet. [Baelung's UDP example](https://www.baeldung.com/udp-in-java)
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/no/entra/bacnet/json/Bacnet2Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Bacnet2Json {


public static final String SENDER = "sender";
public static final String SERVICE = "service";
public static final String OBSERVATION = "observation";
public static final String OBSERVED_AT = "observedAt";
public static final String CONFIGURATION_REQUEST = "configurationRequest";
Expand Down Expand Up @@ -60,6 +61,7 @@ static JSONObject addServiceInfo(JSONObject bacnetJson, Bvlc bvlc, Npdu npdu, Se
if (bacnetJson == null) {
bacnetJson = new JSONObject();
}
bacnetJson.put(SERVICE, service.getServiceChoice());
Map<String, String> observationMap = new HashMap<>();
observationMap.put(OBSERVED_AT, LocalDateTime.now().toString());
JSONObject observationJson = new JSONObject(observationMap);
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/no/entra/bacnet/json/Bacnet2JsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ void fixNumberFormatError() {

@Test
void addServiceInfo() {
String confirmedEventHexString = "8104001e0a3f0010bac001080961010c1001c40200000cc403c000007100310036002d004e004100450032002f004600430042002e004c006f00630061006c0020004100700070006c00690063006100740069006f006e002e005500520020006e00610074007400730065006e006b002000670075006c0076007600610072006d00650020003100200065007400670072003400330033003300300031002e0044006100670042007600690031002d00310031002e004400610067004200760076";
String expected = " {\"sender\":\"0961\",\"service\":\"IHave\",\"configurationRequest\":{\"properties\":{\"Request\":\"IHave\", \"Device\":\"12\"," +
"\"NotificationClass\":\"0\"},\"source\":\"0961\"}}";
String configurationRequestJson = Bacnet2Json.hexStringToJson(confirmedEventHexString);
log.trace("ConfigurationRequest: {}", configurationRequestJson);
assertNotNull(configurationRequestJson);
JSONAssert.assertEquals(expected, configurationRequestJson, false);
}

@Test
Expand Down

0 comments on commit fe7bbb7

Please sign in to comment.