Search in sources :

Example 1 with ChannelScanInfo

use of org.openmuc.framework.config.ChannelScanInfo in project OpenMUC by isc-konstanz.

the class ToJson method addChannelScanInfoList.

public void addChannelScanInfoList(List<ChannelScanInfo> channelScanInfoList) {
    JsonArray jsa = new JsonArray();
    for (ChannelScanInfo channelScanInfo : channelScanInfoList) {
        JsonObject jso = new JsonObject();
        jso.addProperty(Const.ADDRESS, channelScanInfo.getChannelAddress());
        jso.addProperty(Const.SETTINGS, channelScanInfo.getChannelSettings());
        jso.addProperty(Const.VALUE_TYPE, channelScanInfo.getValueType().name());
        jso.addProperty(Const.VALUE_TYPE_LENGTH, channelScanInfo.getValueTypeLength());
        jso.addProperty(Const.DESCRIPTION, channelScanInfo.getDescription());
        jso.addProperty(Const.METADATA, channelScanInfo.getMetaData());
        jso.addProperty(Const.UNIT, channelScanInfo.getUnit());
        jsa.add(jso);
    }
    jsonObject.add(Const.CHANNELS, jsa);
}
Also used : JsonArray(com.google.gson.JsonArray) ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) JsonObject(com.google.gson.JsonObject)

Example 2 with ChannelScanInfo

use of org.openmuc.framework.config.ChannelScanInfo in project OpenMUC by isc-konstanz.

the class DriverConnection method fillDataRecordInChannelScanInfo.

private void fillDataRecordInChannelScanInfo(List<ChannelScanInfo> channelScanInfo, DataRecord dataRecord) {
    String vib = Helper.bytesToHex(dataRecord.getVib());
    String dib = Helper.bytesToHex(dataRecord.getDib());
    ValueType valueType;
    Integer valueLength;
    switch(dataRecord.getDataValueType()) {
        case STRING:
            valueType = ValueType.STRING;
            valueLength = 25;
            break;
        case LONG:
            if (dataRecord.getMultiplierExponent() == 0) {
                valueType = ValueType.LONG;
            } else {
                valueType = ValueType.DOUBLE;
            }
            valueLength = null;
            break;
        case DOUBLE:
        case DATE:
            valueType = ValueType.DOUBLE;
            valueLength = null;
            break;
        case BCD:
            if (dataRecord.getMultiplierExponent() == 0) {
                valueType = ValueType.DOUBLE;
            } else {
                valueType = ValueType.LONG;
            }
            valueLength = null;
            break;
        case NONE:
        default:
            valueType = ValueType.BYTE_ARRAY;
            valueLength = 100;
            break;
    }
    String unit = "";
    if (dataRecord.getUnit() != null) {
        unit = dataRecord.getUnit().getUnit();
    }
    channelScanInfo.add(new ChannelScanInfo(dib + ':' + vib, getDescription(dataRecord), valueType, valueLength, true, true, "", unit));
}
Also used : ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) DataValueType(org.openmuc.jmbus.DataRecord.DataValueType) ValueType(org.openmuc.framework.data.ValueType)

Example 3 with ChannelScanInfo

use of org.openmuc.framework.config.ChannelScanInfo in project OpenMUC by isc-konstanz.

the class RestChannelScanner method scan.

@Override
public void scan(List<ChannelScanInfo> channelScanInfos) throws ArgumentSyntaxException, ScanException, ConnectionException {
    try (RestConnection connection = new RestConnection((RestConfigs) getContext())) {
        FromJson json = new FromJson(connection.get(""));
        List<RestChannel> channels = json.getRestChannelList();
        for (RestChannel channel : channels) {
            // TODO: get channel config list with valueTypeLength, description, ...
            ChannelScanInfo channelScanInfo = new ChannelScanInfo(channel.getId(), "", channel.getValueType(), 0);
            channelScanInfos.add(channelScanInfo);
        }
    } catch (IOException e) {
        throw new ConnectionException(e.getMessage());
    }
}
Also used : ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) FromJson(org.openmuc.framework.lib.rest.FromJson) RestChannel(org.openmuc.framework.lib.rest.objects.RestChannel) IOException(java.io.IOException) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException)

Example 4 with ChannelScanInfo

use of org.openmuc.framework.config.ChannelScanInfo in project OpenMUC by isc-konstanz.

the class Iec61850Connection method scanForChannels.

@Override
public List<ChannelScanInfo> scanForChannels(String settings) throws UnsupportedOperationException, ConnectionException {
    List<BasicDataAttribute> bdas = serverModel.getBasicDataAttributes();
    List<ChannelScanInfo> scanInfos = new ArrayList<>(bdas.size());
    for (BasicDataAttribute bda : bdas) {
        scanInfos.add(createScanInfo(bda));
    }
    return scanInfos;
}
Also used : ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) ArrayList(java.util.ArrayList) BasicDataAttribute(com.beanit.iec61850bean.BasicDataAttribute)

Example 5 with ChannelScanInfo

use of org.openmuc.framework.config.ChannelScanInfo 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)

Aggregations

ChannelScanInfo (org.openmuc.framework.config.ChannelScanInfo)21 ArrayList (java.util.ArrayList)10 ValueType (org.openmuc.framework.data.ValueType)6 IOException (java.io.IOException)5 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)5 ScanException (org.openmuc.framework.config.ScanException)4 ServerModel (com.beanit.iec61850bean.ServerModel)3 Test (org.junit.jupiter.api.Test)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 ArgumentSyntaxException (org.openmuc.framework.config.ArgumentSyntaxException)2 ChannelRecordContainer (org.openmuc.framework.driver.spi.ChannelRecordContainer)2 FromJson (org.openmuc.framework.lib.rest.FromJson)2 RestChannel (org.openmuc.framework.lib.rest.objects.RestChannel)2 DataObject (org.openmuc.jdlms.datatypes.DataObject)2 MBusConnection (org.openmuc.jmbus.MBusConnection)2 VariableDataStructure (org.openmuc.jmbus.VariableDataStructure)2 BasicDataAttribute (com.beanit.iec61850bean.BasicDataAttribute)1