Search in sources :

Example 1 with ModeDMessage

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;
}
Also used : DataSet(org.openmuc.framework.driver.ehz.iec62056_21.DataSet) ValueType(org.openmuc.framework.data.ValueType) IOException(java.io.IOException) LinkedList(java.util.LinkedList) ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) ParseException(java.text.ParseException) ModeDMessage(org.openmuc.framework.driver.ehz.iec62056_21.ModeDMessage)

Example 2 with ModeDMessage

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);
    }
}
Also used : DataSet(org.openmuc.framework.driver.ehz.iec62056_21.DataSet) Value(org.openmuc.framework.data.Value) IOException(java.io.IOException) ParseException(java.text.ParseException) ModeDMessage(org.openmuc.framework.driver.ehz.iec62056_21.ModeDMessage) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 DataSet (org.openmuc.framework.driver.ehz.iec62056_21.DataSet)2 ModeDMessage (org.openmuc.framework.driver.ehz.iec62056_21.ModeDMessage)2 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 ChannelScanInfo (org.openmuc.framework.config.ChannelScanInfo)1 Value (org.openmuc.framework.data.Value)1 ValueType (org.openmuc.framework.data.ValueType)1 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)1