Commit acae79c0 authored by Adam Kučera's avatar Adam Kučera
Browse files

adjustments to the bacnet connector (new version of bacnet4j)

parent 94a210b9
......@@ -9,7 +9,7 @@ data.providers.trends.historian.class=cz.muni.fi.lasaris.sbms.data.providers.bac
data.providers.datapoints.bacnet.class=cz.muni.fi.lasaris.sbms.data.providers.bacnet.BACnetPropertiesProvider
data.providers.datapoints.bacnet.ip.address=147.251.130.76
data.providers.datapoints.bacnet.ip.broadcast=147.251.130.255
data.providers.datapoints.bacnet.ip.mask=255.255.255.224
data.providers.datapoints.bacnet.ip.prefixLength=19
data.providers.datapoints.bacnet.tcp.port=47808
data.providers.datapoints.bacnet.device.id=19
......
......@@ -16,17 +16,27 @@
<repositories>
<repository>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bacnet-data-source</id>
<name>BACnet Dependencies</name>
<url>http://mangoautomation.net:9902/maven-repo/</url>
</repository>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>ias-snapshots</id>
<name>Infinite Automation Snapshot Repository</name>
<url>https://maven.mangoautomation.net/repository/ias-snapshot/</url>
</repository>
<repository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>ias-releases</id>
<name>Infinite Automation Release Repository</name>
<url>https://maven.mangoautomation.net/repository/ias-release/</url>
</repository>
</repositories>
<dependencies>
......@@ -54,7 +64,7 @@
<dependency>
<groupId>com.serotonin</groupId>
<artifactId>bacnet4j</artifactId>
<version>3.2.4</version>
<version>4.0.1</version>
</dependency>
<dependency>
......
......@@ -117,20 +117,18 @@ public class BACnetConnector {
IpNetworkBuilder nb = new IpNetworkBuilder();
String ip = props.getProperty(propertiesPrefix + ".ip.address");
String broadcast = props.getProperty(propertiesPrefix + ".ip.broadcast");
String mask = props.getProperty(propertiesPrefix + ".ip.mask");
int prefixLength = MutableInteger.parsePositiveInt(props.getProperty(propertiesPrefix + ".ip.prefixLength"), 0);
String port = props.getProperty(propertiesPrefix + ".tcp.port");
if(ip != null && isIP(ip)){
nb.localBindAddress(ip);
nb.withLocalBindAddress(ip);
}
if(broadcast != null && isIP(broadcast)){
nb.broadcastIp(broadcast);
}
if(mask != null & isIP(mask)) {
nb.subnetMask(mask);
nb.withBroadcast(broadcast, prefixLength);
}
MutableInteger intPort = new MutableInteger();
if(port != null && intPort.parsePositiveInt(port)) {
nb.port(intPort.getValue());
nb.withPort(intPort.getValue());
}
try {
......@@ -220,16 +218,20 @@ public class BACnetConnector {
// TODO check if remote device is known (check implementation of getRemoteDevice)
try {
//try {
// prepare batch for the device i
RemoteDevice rd = device.getRemoteDevice(i);
RemoteDevice rd = device.getCachedRemoteDevice(i);
if(rd == null) {
logger.debug("Unknown device");
fillReadingError(remoteValues.get(i), results, "Unknown device", finished);
continue;
}
SequenceOf<ReadAccessSpecification> specs = new SequenceOf<ReadAccessSpecification>();
List<BACnetAddress> objects = remoteValues.get(i);
for(BACnetAddress ba : objects) {
ReadAccessSpecification ras = new ReadAccessSpecification(
new ObjectIdentifier(new ObjectType(ba.getType()), ba.getInstance()),
new PropertyIdentifier(ba.getProperty()));
new ObjectIdentifier(ObjectType.forId(ba.getType()), ba.getInstance()),
PropertyIdentifier.forId(ba.getProperty()));
specs.add(ras);
}
ConfirmedRequestService crs = new ReadPropertyMultipleRequest(specs);
......@@ -247,7 +249,7 @@ public class BACnetConnector {
public void fail(AckAPDU fail) {
if(fail instanceof com.serotonin.bacnet4j.apdu.Error) {
fillReadingError(remoteValues.get(i), results, String.format("BACnet error: %s",
((com.serotonin.bacnet4j.apdu.Error)fail).getError().getError()), finished);
((com.serotonin.bacnet4j.apdu.Error)fail).getError().toString()), finished);
} else {
fillReadingError(remoteValues.get(i), results, "Unknown error", finished);
}
......@@ -262,12 +264,12 @@ public class BACnetConnector {
}
});
} catch (BACnetException e) {
/*} catch (BACnetException e) {
logger.debug("Unknown device", e);
fillReadingError(remoteValues.get(i), results, "Unknown device", finished);
}
*/
}
//after all the request were sent, wait for them to complete
......@@ -326,6 +328,40 @@ public class BACnetConnector {
//return RawValue.getReadingError("Unsupported data type");
}
private RawValue getValueFromLogRecord(LogRecord data) {
if(data.isBoolean()) {
return new RawValue(((com.serotonin.bacnet4j.type.primitive.Boolean)data.getChoice()).booleanValue());
}
if(data.isSignedInteger()) {
return new RawValue(((com.serotonin.bacnet4j.type.primitive.SignedInteger)data.getChoice()).intValue());
}
if(data.isUnsignedInteger()) {
return new RawValue(((com.serotonin.bacnet4j.type.primitive.Unsigned32)data.getChoice()).intValue());
}
/*
if(data instanceof com.serotonin.bacnet4j.type.primitive.Unsigned16) {
return new RawValue(((com.serotonin.bacnet4j.type.primitive.Unsigned16)data.getChoice()).intValue());
}
if(data instanceof com.serotonin.bacnet4j.type.primitive.Unsigned8) {
return new RawValue(((com.serotonin.bacnet4j.type.primitive.Unsigned8)data.getChoice()).intValue());
}
*/
if(data.isReal()) {
return new RawValue(((com.serotonin.bacnet4j.type.primitive.Real)data.getChoice()).floatValue());
}
if(data.isEnumerated()) {
return new RawValue(((com.serotonin.bacnet4j.type.primitive.Enumerated)data.getChoice()).intValue());
}
/*
if(data.isBitString()) {
return new RawValue(((com.serotonin.bacnet4j.type.primitive.CharacterString)data.getChoice()).getValue());
}
*/
return new RawValue("Generic toString: " + data.toString());
//return RawValue.getReadingError("Unsupported data type");
}
private void fillReadingError(List<BACnetAddress> list, Map<Address, RawValue> results, String msg, AtomicInteger counter) {
for(BACnetAddress ba : list) {
synchronized(results) {
......@@ -417,12 +453,17 @@ public class BACnetConnector {
//logger.info("Preparing ReadRange request...");
RemoteDevice rd = null;
try {
rd = device.getRemoteDevice(trend.getDevice());
} catch (BACnetException e) {
//try {
rd = device.getCachedRemoteDevice(trend.getDevice());
if(rd == null) {
exit();
return;
}
/*
} catch (BACnetException e) {
exit();
return;
}*/
ConfirmedRequestService crs = new ReadRangeRequest(new ObjectIdentifier(ObjectType.trendLog, trend.getInstance()), PropertyIdentifier.logBuffer, null,
new ReadRangeRequest.ByTime(getBACnetDateTime(from), new SignedInteger(this.bufferReadLimit)));
......@@ -459,7 +500,7 @@ public class BACnetConnector {
// filters valid data records (management events - such as log enable/disable or time changes
// do not have status flags set
if(lr.getStatusFlags() != null) {
values.add(last, getValueFromEncodable(lr.getEncodable()));
values.add(last, getValueFromLogRecord(lr));
}
i++;
}
......@@ -487,7 +528,7 @@ public class BACnetConnector {
// filters valid data records (management events - such as log enable/disable or time changes
// do not have status flags set
if(lr.getStatusFlags() != null) {
values.add(last, getValueFromEncodable(lr.getEncodable()));
values.add(last, getValueFromLogRecord(lr));
}
i+=i2;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment