Search in sources :

Example 6 with ChannelValueContainer

use of org.openmuc.framework.driver.spi.ChannelValueContainer in project OpenMUC by isc-konstanz.

the class WriteHandle method multiSet.

private void multiSet(List<ChannelValueContainer> writeList) throws ConnectionException {
    List<AccessResultCode> resultCodes = callSet(writeList);
    Iterator<AccessResultCode> iterResult = resultCodes.iterator();
    Iterator<ChannelValueContainer> iterWriteList = writeList.iterator();
    while (iterResult.hasNext() && iterWriteList.hasNext()) {
        ChannelValueContainer valueContainer = iterWriteList.next();
        AccessResultCode resCode = iterResult.next();
        Flag flag = convertToFlag(resCode);
        valueContainer.setFlag(flag);
    }
}
Also used : AccessResultCode(org.openmuc.jdlms.AccessResultCode) Flag(org.openmuc.framework.data.Flag) ChannelValueContainer(org.openmuc.framework.driver.spi.ChannelValueContainer)

Example 7 with ChannelValueContainer

use of org.openmuc.framework.driver.spi.ChannelValueContainer in project OpenMUC by isc-konstanz.

the class AmqpDriverConnection method write.

@Override
public Object write(List<ChannelValueContainer> containers, Object containerListHandle) throws UnsupportedOperationException {
    for (ChannelValueContainer container : containers) {
        Record record = new Record(container.getValue(), System.currentTimeMillis());
        if (parsers.containsKey(setting.parser)) {
            byte[] message = new byte[0];
            try {
                message = parsers.get(setting.parser).serialize(record, container);
            } catch (SerializationException e) {
                logger.error(e.getMessage());
            }
            writer.write(container.getChannelAddress(), message);
            container.setFlag(Flag.VALID);
        } else {
            throw new UnsupportedOperationException("A parser is needed to write messages");
        }
    }
    return null;
}
Also used : SerializationException(org.openmuc.framework.parser.spi.SerializationException) Record(org.openmuc.framework.data.Record) ChannelValueContainer(org.openmuc.framework.driver.spi.ChannelValueContainer)

Example 8 with ChannelValueContainer

use of org.openmuc.framework.driver.spi.ChannelValueContainer in project OpenMUC by isc-konstanz.

the class SnmpDevice method write.

/**
 * At least device address and channel address must be specified in the container.<br>
 * <br>
 * containers.deviceAddress = device address (eg. 1.1.1.1/161) <br>
 * containers.channelAddress = OID (eg. 1.3.6.1.2.1.1.0)
 */
@Override
public Object write(List<ChannelValueContainer> containers, Object containerListHandle) throws ConnectionException {
    try {
        for (ChannelValueContainer container : containers) {
            String oid = container.getChannelAddress();
            Value value = container.getValue();
            logger.debug("Write value for OID {}: {}", oid, value);
            setRequest(oid, value);
            container.setFlag(Flag.VALID);
        }
    } catch (SnmpTimeoutException e) {
        logger.warn("Error while requesting SNMP SET: {}", e.getMessage());
    }
    return null;
}
Also used : StringValue(org.openmuc.framework.data.StringValue) Value(org.openmuc.framework.data.Value) IntValue(org.openmuc.framework.data.IntValue) OctetString(org.snmp4j.smi.OctetString) ChannelValueContainer(org.openmuc.framework.driver.spi.ChannelValueContainer)

Example 9 with ChannelValueContainer

use of org.openmuc.framework.driver.spi.ChannelValueContainer in project OpenMUC by isc-konstanz.

the class Iec61850ConnectionTest method testWrite.

@Test
public void testWrite() throws IOException, ServiceError, ConfigurationException, javax.naming.ConfigurationException, SclParseException, InterruptedException, UnsupportedOperationException, ConnectionException {
    System.out.println("Attempting to connect to server " + host + " on port " + port);
    clientAssociation = clientSap.associate(InetAddress.getByName(host), port, null, this);
    ServerModel serverModel = SclParser.parse("src/test/resources/testOpenmuc.icd").get(0);
    clientAssociation.setServerModel(serverModel);
    getAllBdas(serverModel, clientAssociation);
    // ------------SCAN FOR CHANNELS-------------------
    Iec61850Connection testIec61850Connection = new Iec61850Connection(clientAssociation, serverModel);
    List<ChannelScanInfo> testChannelScanList = testIec61850Connection.scanForChannels("");
    // ----------WRITE-----------------
    List<ChannelValueContainer> testChannelValueContainers = new ArrayList<>();
    byte[] newValue = { 0x44 };
    testChannelValueContainers.add(new ChannelValueContainerImpl(testChannelScanList.get(14).getChannelAddress(), new ByteArrayValue(newValue)));
    testChannelValueContainers.add(new ChannelValueContainerImpl(testChannelScanList.get(25).getChannelAddress(), new FloatValue((float) 12.5)));
    testChannelValueContainers.add(new ChannelValueContainerImpl(testChannelScanList.get(24).getChannelAddress(), new BooleanValue(true)));
    testIec61850Connection.write(testChannelValueContainers, null);
    // Create record container to read the changes made by "write"
    List<ChannelRecordContainer> testRecordContainers = new ArrayList<>();
    for (int i = 0; i < 34; i++) {
        testRecordContainers.add(new ChannelRecordContainerImpl(testChannelScanList.get(i).getChannelAddress()));
    }
    testIec61850Connection.read(testRecordContainers, null, "");
    Assert.assertEquals("[68]", testRecordContainers.get(14).getRecord().getValue().toString());
    Assert.assertEquals("12.5", testRecordContainers.get(25).getRecord().getValue().toString());
    Assert.assertEquals("true", testRecordContainers.get(24).getRecord().getValue().toString());
}
Also used : ArrayList(java.util.ArrayList) ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) ServerModel(com.beanit.iec61850bean.ServerModel) BooleanValue(org.openmuc.framework.data.BooleanValue) ByteArrayValue(org.openmuc.framework.data.ByteArrayValue) FloatValue(org.openmuc.framework.data.FloatValue) ChannelValueContainer(org.openmuc.framework.driver.spi.ChannelValueContainer) Test(org.junit.jupiter.api.Test)

Example 10 with ChannelValueContainer

use of org.openmuc.framework.driver.spi.ChannelValueContainer in project OpenMUC by isc-konstanz.

the class Iec61850Connection method write.

@Override
public Object write(List<ChannelValueContainer> containers, Object containerListHandle) throws UnsupportedOperationException, ConnectionException {
    List<FcModelNode> modelNodesToBeWritten = new ArrayList<>(containers.size());
    for (ChannelValueContainer container : containers) {
        if (container.getChannelHandle() != null) {
            modelNodesToBeWritten.add((FcModelNode) container.getChannelHandle());
            setFcModelNode(container, (FcModelNode) container.getChannelHandle());
        } else {
            String[] args = container.getChannelAddress().split(":", 3);
            if (args.length != 2) {
                logger.debug("Wrong channel address syntax: {}", container.getChannelAddress());
                container.setFlag(Flag.DRIVER_ERROR_CHANNEL_WITH_THIS_ADDRESS_NOT_FOUND);
                continue;
            }
            ModelNode modelNode = serverModel.findModelNode(args[0], Fc.fromString(args[1]));
            if (modelNode == null) {
                logger.debug("No Basic Data Attribute for the channel address {} was found in the server model.", container.getChannelAddress());
                container.setFlag(Flag.DRIVER_ERROR_CHANNEL_WITH_THIS_ADDRESS_NOT_FOUND);
                continue;
            }
            FcModelNode fcModelNode;
            try {
                fcModelNode = (FcModelNode) modelNode;
            } catch (ClassCastException e) {
                logger.debug("ModelNode with object reference {} was found in the server model but is not a Basic Data Attribute.", container.getChannelAddress());
                container.setFlag(Flag.DRIVER_ERROR_CHANNEL_WITH_THIS_ADDRESS_NOT_FOUND);
                continue;
            }
            container.setChannelHandle(fcModelNode);
            modelNodesToBeWritten.add(fcModelNode);
            setFcModelNode(container, fcModelNode);
        }
    }
    // TODO
    // first check all datasets if the are some that contain only requested channels
    // then check all remaining model nodes
    List<FcModelNode> fcNodesToBeRequested = new ArrayList<>();
    while (modelNodesToBeWritten.size() > 0) {
        fillRequestedNodes(fcNodesToBeRequested, modelNodesToBeWritten, serverModel);
    }
    for (FcModelNode fcModelNode : fcNodesToBeRequested) {
        try {
            if (fcModelNode.getFc().toString().equals("CO")) {
                logger.info("writing CO model node");
                fcModelNode = (FcModelNode) fcModelNode.getParent().getParent();
                clientAssociation.operate(fcModelNode);
            } else {
                clientAssociation.setDataValues(fcModelNode);
            }
        } catch (ServiceError e) {
            logger.error("Error writing to channel: service error calling setDataValues on {}: {}", fcModelNode.getReference(), e);
            for (BasicDataAttribute bda : fcModelNode.getBasicDataAttributes()) {
                for (ChannelValueContainer valueContainer : containers) {
                    if (valueContainer.getChannelHandle() == bda) {
                        valueContainer.setFlag(Flag.DRIVER_ERROR_CHANNEL_NOT_ACCESSIBLE);
                    }
                }
            }
            return null;
        } catch (IOException e) {
            throw new ConnectionException(e);
        }
        for (BasicDataAttribute bda : fcModelNode.getBasicDataAttributes()) {
            for (ChannelValueContainer valueContainer : containers) {
                if (valueContainer.getChannelHandle() == bda) {
                    valueContainer.setFlag(Flag.VALID);
                }
            }
        }
    }
    return null;
}
Also used : ServiceError(com.beanit.iec61850bean.ServiceError) ArrayList(java.util.ArrayList) FcModelNode(com.beanit.iec61850bean.FcModelNode) BdaVisibleString(com.beanit.iec61850bean.BdaVisibleString) BdaBitString(com.beanit.iec61850bean.BdaBitString) BdaUnicodeString(com.beanit.iec61850bean.BdaUnicodeString) BdaOctetString(com.beanit.iec61850bean.BdaOctetString) BasicDataAttribute(com.beanit.iec61850bean.BasicDataAttribute) IOException(java.io.IOException) FcModelNode(com.beanit.iec61850bean.FcModelNode) ModelNode(com.beanit.iec61850bean.ModelNode) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) ChannelValueContainer(org.openmuc.framework.driver.spi.ChannelValueContainer)

Aggregations

ChannelValueContainer (org.openmuc.framework.driver.spi.ChannelValueContainer)12 ArgumentSyntaxException (org.openmuc.framework.config.ArgumentSyntaxException)6 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)6 ModbusException (com.ghgande.j2mod.modbus.ModbusException)3 ModbusIOException (com.ghgande.j2mod.modbus.ModbusIOException)3 ArrayList (java.util.ArrayList)3 ScanException (org.openmuc.framework.config.ScanException)3 Record (org.openmuc.framework.data.Record)3 ModbusChannel (org.openmuc.framework.driver.modbus.ModbusChannel)3 IOException (java.io.IOException)2 SerializationException (org.openmuc.framework.parser.spi.SerializationException)2 BasicDataAttribute (com.beanit.iec61850bean.BasicDataAttribute)1 BdaBitString (com.beanit.iec61850bean.BdaBitString)1 BdaOctetString (com.beanit.iec61850bean.BdaOctetString)1 BdaUnicodeString (com.beanit.iec61850bean.BdaUnicodeString)1 BdaVisibleString (com.beanit.iec61850bean.BdaVisibleString)1 FcModelNode (com.beanit.iec61850bean.FcModelNode)1 ModelNode (com.beanit.iec61850bean.ModelNode)1 ServerModel (com.beanit.iec61850bean.ServerModel)1 ServiceError (com.beanit.iec61850bean.ServiceError)1