This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
src/main/java/no/entra/bacnet/internal/property/ReadSinglePropertyResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package no.entra.bacnet.internal.property; | ||
|
||
import no.entra.bacnet.internal.properties.PropertyIdentifier; | ||
import no.entra.bacnet.objects.ObjectId; | ||
|
||
import java.util.Objects; | ||
|
||
public class ReadSinglePropertyResult { | ||
private ObjectId objectId; | ||
private PropertyIdentifier propertyIdentifier; | ||
private Object value; | ||
private Integer arrayIndexNumber = null; | ||
|
||
public ReadSinglePropertyResult() { | ||
} | ||
|
||
public ReadSinglePropertyResult(ObjectId objectId, PropertyIdentifier propertyIdentifier, Object value) { | ||
this.objectId = objectId; | ||
this.propertyIdentifier = propertyIdentifier; | ||
this.value = value; | ||
} | ||
|
||
public ObjectId getObjectId() { | ||
return objectId; | ||
} | ||
|
||
public void setObjectId(ObjectId objectId) { | ||
this.objectId = objectId; | ||
} | ||
|
||
public PropertyIdentifier getPropertyIdentifier() { | ||
return propertyIdentifier; | ||
} | ||
|
||
public void setPropertyIdentifier(PropertyIdentifier propertyIdentifier) { | ||
this.propertyIdentifier = propertyIdentifier; | ||
} | ||
|
||
public Object getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(Object value) { | ||
this.value = value; | ||
} | ||
|
||
public Integer getArrayIndexNumber() { | ||
return arrayIndexNumber; | ||
} | ||
|
||
public void setArrayIndexNumber(Integer arrayIndexNumber) { | ||
this.arrayIndexNumber = arrayIndexNumber; | ||
} | ||
|
||
public boolean isValid() { | ||
return objectId != null && propertyIdentifier != null && value != null; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ReadSinglePropertyResult{" + | ||
"objectId=" + objectId + | ||
", propertyIdentifier=" + propertyIdentifier + | ||
", value=" + value + | ||
", arrayIndexNumber=" + arrayIndexNumber + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ReadSinglePropertyResult that = (ReadSinglePropertyResult) o; | ||
return Objects.equals(getObjectId(), that.getObjectId()) && | ||
getPropertyIdentifier() == that.getPropertyIdentifier() && | ||
Objects.equals(getValue(), that.getValue()) && | ||
Objects.equals(getArrayIndexNumber(), that.getArrayIndexNumber()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getObjectId(), getPropertyIdentifier(), getValue(), getArrayIndexNumber()); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/no/entra/bacnet/internal/property/ReadSinglePropertyResultParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package no.entra.bacnet.internal.property; | ||
|
||
import no.entra.bacnet.internal.apdu.SDContextTag; | ||
import no.entra.bacnet.internal.objects.ObjectIdMapper; | ||
import no.entra.bacnet.internal.octet.OctetReader; | ||
import no.entra.bacnet.internal.parseandmap.ParserResult; | ||
import no.entra.bacnet.internal.properties.PropertyIdentifier; | ||
import no.entra.bacnet.objects.ObjectId; | ||
import no.entra.bacnet.octet.Octet; | ||
import no.entra.bacnet.services.BacnetParserException; | ||
import org.slf4j.Logger; | ||
|
||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
public class ReadSinglePropertyResultParser { | ||
private static final Logger log = getLogger(ReadSinglePropertyResultParser.class); | ||
|
||
public static ParserResult<ReadSinglePropertyResult> parse(String hexString) throws BacnetParserException { | ||
ParserResult<ReadSinglePropertyResult> parserResult = new ParserResult(); | ||
parserResult.setInitialHexString(hexString); | ||
OctetReader propertyReader = new OctetReader(hexString); | ||
|
||
ReadSinglePropertyResult propertyResult = new ReadSinglePropertyResult(); | ||
//1 Read ObjectId | ||
Octet sdContextTag0 = propertyReader.next(); | ||
if (!sdContextTag0.equals(SDContextTag.TAG0LENGTH4)) { | ||
parserResult.setUnparsedHexString(propertyReader.unprocessedHexString()); | ||
parserResult.setErrorMessage("PropertyResult must start with SD-ContextTag 0. Value is: " + sdContextTag0); | ||
parserResult.setParsedOk(false); | ||
throw new BacnetParserException("PropertyResult must start with SD-ContextTag 0. Value is: " + sdContextTag0, parserResult); | ||
} | ||
String objectIdHexString = propertyReader.next(4); | ||
ParserResult<ObjectId> objectIdResult = ObjectIdMapper.parse(objectIdHexString); | ||
if (!objectIdResult.isParsedOk()) { | ||
parserResult.setUnparsedHexString(propertyReader.unprocessedHexString()); | ||
parserResult.setErrorMessage("Could not parse required parameter ObjectId from :" + objectIdHexString); | ||
parserResult.setParsedOk(false); | ||
throw new BacnetParserException("Could not parse required parameter ObjectId.", parserResult); | ||
} else { | ||
propertyResult.setObjectId(objectIdResult.getParsedObject()); | ||
} | ||
|
||
//2 Read Property Identifier | ||
Octet sdContextTag1 = propertyReader.next(); | ||
if (!sdContextTag1.equals(SDContextTag.TAG1LENGTH1)) { | ||
parserResult.setUnparsedHexString(propertyReader.unprocessedHexString()); | ||
parserResult.setErrorMessage("PropertyResult must have SD-ContextTag 1. Value is: " + sdContextTag1); | ||
parserResult.setParsedOk(false); | ||
throw new BacnetParserException("PropertyResult must have with SD-ContextTag 1. Value is: " + sdContextTag1, parserResult); | ||
} | ||
final Octet propertyIdentifierOctet = propertyReader.next(); | ||
PropertyIdentifier propertyIdentifier = PropertyIdentifier.fromOctet(propertyIdentifierOctet); | ||
propertyResult.setPropertyIdentifier(propertyIdentifier); | ||
parserResult.setParsedObject(propertyResult); | ||
return parserResult; | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/no/entra/bacnet/property/ReadPropertyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package no.entra.bacnet.property; | ||
|
||
import no.entra.bacnet.BacnetRequest; | ||
import no.entra.bacnet.services.Service; | ||
|
||
public class ReadPropertyService extends BacnetRequest implements Service { | ||
@Override | ||
public String buildHexString() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean expectReply() { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package no.entra.bacnet.services; | ||
|
||
public enum ServiceType { | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/no/entra/bacnet/services/ServicesSupported.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package no.entra.bacnet.services; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ServicesSupported { | ||
|
||
private final List<ServiceType> supportedServices; | ||
|
||
public ServicesSupported() { | ||
supportedServices = new ArrayList<>(); | ||
} | ||
|
||
public ServicesSupported(List<ServiceType> supportedServices) { | ||
this.supportedServices = supportedServices; | ||
} | ||
public void addSupportedService(ServiceType serviceType) { | ||
supportedServices.add(serviceType); | ||
} | ||
public void removeSupportedService(ServiceType serviceType) { | ||
if (isServiceSupported(serviceType)) { | ||
supportedServices.remove(serviceType); | ||
} | ||
} | ||
public boolean isServiceSupported(ServiceType serviceType) { | ||
return supportedServices.contains(serviceType); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/test/java/no/entra/bacnet/internal/property/ReadSinglePropertyResultParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package no.entra.bacnet.internal.property; | ||
|
||
import no.entra.bacnet.device.DeviceId; | ||
import no.entra.bacnet.internal.parseandmap.ParserResult; | ||
import no.entra.bacnet.internal.properties.PropertyIdentifier; | ||
import no.entra.bacnet.services.BacnetParserException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
class ReadSinglePropertyResultParserTest { | ||
|
||
@BeforeEach | ||
void setUp() { | ||
} | ||
|
||
@Test | ||
void parseSupportedServices() throws BacnetParserException { | ||
String hexString = "0c0200000819613e850707000bc000f8003f"; | ||
ParserResult<ReadSinglePropertyResult> parserResult = ReadSinglePropertyResultParser.parse(hexString); | ||
assertNotNull(parserResult); | ||
assertEquals(new DeviceId(8),parserResult.getParsedObject().getObjectId()); | ||
assertEquals(PropertyIdentifier.ProtocolServicesSupported, parserResult.getParsedObject().getPropertyIdentifier()); | ||
} | ||
} |