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

Commit

Permalink
#4 Found DeviceId from response.
Browse files Browse the repository at this point in the history
  • Loading branch information
baardl committed Apr 7, 2021
1 parent bc87773 commit 2e57a95
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/java/no/entra/bacnet/services/BacnetResponse.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package no.entra.bacnet.services;

public interface BacnetResponse {

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import no.entra.bacnet.npdu.Npdu;
import no.entra.bacnet.npdu.NpduBuilder;
import no.entra.bacnet.objects.ObjectId;
import no.entra.bacnet.objects.ObjectIdMapper;
import no.entra.bacnet.objects.ObjectIdMapperResult;
import no.entra.bacnet.objects.ObjectProperties;
import no.entra.bacnet.octet.Octet;
import no.entra.bacnet.octet.OctetReader;
import no.entra.bacnet.properties.PropertyReference;

import java.util.Set;
Expand All @@ -18,7 +22,7 @@
import static no.entra.bacnet.apdu.ArrayTag.ARRAY1_START;
import static no.entra.bacnet.utils.HexUtils.intToHexString;

public class ReadPropertyMultipleService implements Service, BacnetRequest {
public class ReadPropertyMultipleService implements Service, BacnetRequest, BacnetResponse {

private Integer invokeId = null;
private Set<ObjectProperties> objectProperties = null;
Expand Down Expand Up @@ -76,10 +80,6 @@ public void setPropertyReferences(Set<PropertyReference> propertyReferences) {
// return requirement;
// }





@Override
public String buildHexString() {
Apdu apdu = Apdu.ApduBuilder.builder()
Expand Down Expand Up @@ -112,4 +112,40 @@ public String buildHexString() {
String hexString = bvlc.toHexString() + npdu.toHexString() + apduHexString;
return hexString;
}

public static ReadPropertyMultipleService parse(String hexString) {
//Expect
//ObjectId
//List of PropertyReferences
ObjectIdMapperResult<ObjectId> idMapperResult = ObjectIdMapper.parse(hexString);
ReadPropertyMultipleService service = new ReadPropertyMultipleService();
service.setObjectId(idMapperResult.getParsedObject());
int numberOfOctetsRead = idMapperResult.getNumberOfOctetsRead();
OctetReader listReader = new OctetReader(hexString);
listReader.next(numberOfOctetsRead); //Discard
Octet startList = listReader.next();
if (startList.equals(ARRAY1_START)) {
/*
//PresentValue
String unprocessedHexString = listReader.unprocessedHexString();
while (unprocessedHexString != null && !unprocessedHexString.isEmpty()) {
PropertyResult propertyResult = parseProperty(unprocessedHexString);
if (propertyResult != null ) {
if (propertyResult.getProperty() != null) {
Property property = propertyResult.getProperty();
String key = property.getKey();
Object value = property.getValue();
accessResult.setResultByKey(key, value);
}
unprocessedHexString = propertyResult.getUnprocessedHexString();
}
}
*/
}
return service;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/*
1. Find count of Objects available on a Device
Expand All @@ -17,7 +18,7 @@
public class FindDevicesAndSensorsOnADeviceFlowTest {

@Test
void findCountOfObjects() {
void findCountOfObjectsRequest() {

int invokeId = 69;
DeviceId deviceId = new DeviceId(8);
Expand All @@ -26,4 +27,15 @@ void findCountOfObjects() {
String expectedHexString = "810a001501040275450e0c020000081e094c19001f";
assertEquals(expectedHexString, countOfObjectsAvailable.buildHexString());
}

@Test
void findCountOfObjectsResponse() {
String fullBacnetHexString = "810a0019010030450e0c020000081e294c39004e2201694f1f";
String apduHexString = "30450e0c020000081e294c39004e2201694f1f";
String serviceHexString = "0c020000081e294c39004e2201694f1f";
ReadPropertyMultipleService countOfObjectsResponse = ReadPropertyMultipleService.parse(serviceHexString);
assertNotNull(countOfObjectsResponse);
DeviceId deviceId = new DeviceId(8);
assertEquals(deviceId, countOfObjectsResponse.getObjectId());
}
}

0 comments on commit 2e57a95

Please sign in to comment.