use of org.openmuc.framework.driver.ehz.iec62056_21.ModeDMessage in project OpenMUC by isc-konstanz.
the class IecConnection method scanForChannels.
@Override
public List<ChannelScanInfo> scanForChannels(int timeout) {
List<ChannelScanInfo> channelInfos = new LinkedList<>();
logger.debug("scanning channels");
try {
byte[] frame = receiver.receiveMessage(timeout);
ModeDMessage message = ModeDMessage.parse(frame);
List<String> dataSets = message.getDataSets();
for (String data : dataSets) {
DataSet dataSet = new DataSet(data);
String channelAddress = dataSet.getAddress();
String description = "Current value: " + dataSet.parseValueAsDouble() + dataSet.getUnit();
ValueType valueType = ValueType.DOUBLE;
Integer valueTypeLength = null;
Boolean readable = true;
Boolean writable = false;
ChannelScanInfo channelInfo = new ChannelScanInfo(channelAddress, description, valueType, valueTypeLength, readable, writable);
channelInfos.add(channelInfo);
}
} catch (ParseException | IOException e) {
logger.warn("read failed", e);
}
return channelInfos;
}
use of org.openmuc.framework.driver.ehz.iec62056_21.ModeDMessage in project OpenMUC by isc-konstanz.
the class IecConnection method read.
@Override
public void read(List<ChannelRecordContainer> containers, int timeout) throws ConnectionException {
logger.trace("reading channels");
long timestamp = System.currentTimeMillis();
try {
byte[] frame = receiver.receiveMessage(timeout);
ModeDMessage message = ModeDMessage.parse(frame);
List<String> dataSets = message.getDataSets();
Map<String, Value> values = new LinkedHashMap<>();
for (String ds : dataSets) {
DataSet dataSet = new DataSet(ds);
String address = dataSet.getAddress();
Value value = dataSet.parseValueAsDouble();
values.put(address, value);
logger.trace("{} = {}", address, value);
}
handleChannelRecordContainer(containers, values, timestamp);
} catch (IOException e) {
logger.error("read failed", e);
disconnect();
throw new ConnectionException(e);
} catch (ParseException e) {
logger.error("parsing failed", e);
}
}
Aggregations