Search in sources :

Example 1 with BasicDataAttribute

use of com.beanit.iec61850bean.BasicDataAttribute in project OpenMUC by isc-konstanz.

the class Iec61850Connection method setRecordContainer.

private FcModelNode setRecordContainer(ChannelRecordContainer container) throws ConnectionException {
    if (container.getChannelHandle() == null) {
        return null;
    }
    FcModelNode fcModelNode = (FcModelNode) container.getChannelHandle();
    try {
        clientAssociation.getDataValues(fcModelNode);
    } catch (ServiceError e) {
        logger.debug("Error reading channel: service error calling getDataValues on {}: {}", container.getChannelAddress(), e);
        container.setRecord(new Record(Flag.DRIVER_ERROR_CHANNEL_NOT_ACCESSIBLE));
        return fcModelNode;
    } catch (IOException e) {
        throw new ConnectionException(e);
    }
    if (fcModelNode instanceof BasicDataAttribute) {
        long receiveTime = System.currentTimeMillis();
        setRecord(container, (BasicDataAttribute) fcModelNode, receiveTime);
    } else {
        StringBuilder sb = new StringBuilder("");
        for (BasicDataAttribute bda : fcModelNode.getBasicDataAttributes()) {
            sb.append(bda2String(bda) + STRING_SEPARATOR);
        }
        // remove last separator
        sb.delete(sb.length() - 1, sb.length());
        long receiveTime = System.currentTimeMillis();
        setRecord(container, sb.toString(), receiveTime);
    }
    return null;
}
Also used : ServiceError(com.beanit.iec61850bean.ServiceError) FcModelNode(com.beanit.iec61850bean.FcModelNode) Record(org.openmuc.framework.data.Record) IOException(java.io.IOException) BasicDataAttribute(com.beanit.iec61850bean.BasicDataAttribute) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException)

Example 2 with BasicDataAttribute

use of com.beanit.iec61850bean.BasicDataAttribute 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 3 with BasicDataAttribute

use of com.beanit.iec61850bean.BasicDataAttribute in project OpenMUC by isc-konstanz.

the class Iec61850Connection method checkParent.

boolean checkParent(ModelNode modelNode, List<FcModelNode> fcNodesToBeRequested, List<FcModelNode> remainingModelNodes, ServerModel serverModel) {
    if (!(modelNode instanceof FcModelNode)) {
        return false;
    }
    FcModelNode fcModelNode = (FcModelNode) modelNode;
    ModelNode parentNode = serverModel;
    for (int i = 0; i < fcModelNode.getReference().size() - 1; i++) {
        parentNode = parentNode.getChild(fcModelNode.getReference().get(i), fcModelNode.getFc());
    }
    List<BasicDataAttribute> basicDataAttributes = parentNode.getBasicDataAttributes();
    for (BasicDataAttribute bda : basicDataAttributes) {
        if (!remainingModelNodes.contains(bda)) {
            return false;
        }
    }
    if (!checkParent(parentNode, fcNodesToBeRequested, remainingModelNodes, serverModel)) {
        for (BasicDataAttribute bda : basicDataAttributes) {
            remainingModelNodes.remove(bda);
        }
        fcNodesToBeRequested.add((FcModelNode) parentNode);
    }
    return true;
}
Also used : FcModelNode(com.beanit.iec61850bean.FcModelNode) BasicDataAttribute(com.beanit.iec61850bean.BasicDataAttribute) FcModelNode(com.beanit.iec61850bean.FcModelNode) ModelNode(com.beanit.iec61850bean.ModelNode)

Example 4 with BasicDataAttribute

use of com.beanit.iec61850bean.BasicDataAttribute in project OpenMUC by isc-konstanz.

the class Iec61850Connection method setFcModelNode.

private void setFcModelNode(ChannelValueContainer container, FcModelNode fcModelNode) {
    if (fcModelNode instanceof BasicDataAttribute) {
        setBda(container, (BasicDataAttribute) fcModelNode);
    } else {
        List<BasicDataAttribute> bdas = fcModelNode.getBasicDataAttributes();
        String valueString = container.getValue().toString();
        String[] bdaValues = valueString.split(STRING_SEPARATOR);
        if (bdaValues.length != bdas.size()) {
            throw new IllegalStateException("attempt to write array " + valueString + " into fcModelNode " + fcModelNode.getName() + " failed as the dimensions don't fit.");
        }
        for (int i = 0; i < bdaValues.length; i++) {
            setBda(bdaValues[i], bdas.get(i));
        }
    }
}
Also used : BasicDataAttribute(com.beanit.iec61850bean.BasicDataAttribute) BdaVisibleString(com.beanit.iec61850bean.BdaVisibleString) BdaBitString(com.beanit.iec61850bean.BdaBitString) BdaUnicodeString(com.beanit.iec61850bean.BdaUnicodeString) BdaOctetString(com.beanit.iec61850bean.BdaOctetString)

Example 5 with BasicDataAttribute

use of com.beanit.iec61850bean.BasicDataAttribute 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

BasicDataAttribute (com.beanit.iec61850bean.BasicDataAttribute)5 FcModelNode (com.beanit.iec61850bean.FcModelNode)3 BdaBitString (com.beanit.iec61850bean.BdaBitString)2 BdaOctetString (com.beanit.iec61850bean.BdaOctetString)2 BdaUnicodeString (com.beanit.iec61850bean.BdaUnicodeString)2 BdaVisibleString (com.beanit.iec61850bean.BdaVisibleString)2 ModelNode (com.beanit.iec61850bean.ModelNode)2 ServiceError (com.beanit.iec61850bean.ServiceError)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)2 ChannelScanInfo (org.openmuc.framework.config.ChannelScanInfo)1 Record (org.openmuc.framework.data.Record)1 ChannelValueContainer (org.openmuc.framework.driver.spi.ChannelValueContainer)1