Search in sources :

Example 6 with NodeException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException in project open-smart-grid-platform by OSGP.

the class Iec61850SetLightCommand method switchLightRelay.

private void switchLightRelay(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final DeviceMessageLog deviceMessageLog, final int index, final boolean on) throws NodeException {
    final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(index);
    Iec61850Commands.enableOperationOfRelay(deviceConnection, iec61850Client, deviceMessageLog, logicalNode, index);
    // Switch the relay using Pos.Oper.ctlVal [CO].
    final NodeContainer position = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.POSITION, Fc.CO);
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), position.getFcmodelNode());
    final NodeContainer operation = position.getChild(SubDataAttribute.OPERATION);
    final BdaBoolean controlValue = operation.getBoolean(SubDataAttribute.CONTROL_VALUE);
    LOGGER.info(String.format("Switching relay %d %s", index, on ? "on" : "off"));
    controlValue.setValue(on);
    operation.write();
    deviceMessageLog.addVariable(logicalNode, DataAttribute.POSITION, Fc.CO, SubDataAttribute.OPERATION, SubDataAttribute.CONTROL_VALUE, Boolean.toString(on));
}
Also used : BdaBoolean(com.beanit.openiec61850.BdaBoolean) NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) LogicalNode(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)

Example 7 with NodeException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException in project open-smart-grid-platform by OSGP.

the class Iec61850EnableReportingCommand method enableBufferedReportingOnLightMeasurementDevice.

public void enableBufferedReportingOnLightMeasurementDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection) throws NodeException {
    final NodeContainer reporting = deviceConnection.getFcModelNode(LogicalDevice.LD0, LogicalNode.LOGICAL_NODE_ZERO, DataAttribute.RCB_A, Fc.BR);
    // Read the reporting enabled boolean.
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), (FcModelNode) reporting.getFcmodelNode().getChild(SubDataAttribute.ENABLE_REPORTING.getDescription()));
    final boolean reportingEnabled = reporting.getBoolean(SubDataAttribute.ENABLE_REPORTING).getValue();
    LOGGER.info("reportingEnabled for buffered reports: {}", reportingEnabled);
    if (reportingEnabled) {
        LOGGER.info("Buffered reporting is already enabled for device: {}", deviceConnection.getDeviceIdentification());
        return;
    }
    // Only reading the sequence number for the report node, as the report
    // node is not fully described by the ServerModel when using an ICD
    // file. Since the report node differs from the ServerModel, a full read
    // of the node and all data-attributes will fail. Therefore, only the
    // needed data-attributes are read.
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), (FcModelNode) reporting.getFcmodelNode().getChild(SubDataAttribute.SEQUENCE_NUMBER.getDescription()));
    final Iec61850ClientBaseEventListener reportListener = deviceConnection.getConnection().getIec61850ClientAssociation().getReportListener();
    final short sqNum = reporting.getUnsignedByte(SubDataAttribute.SEQUENCE_NUMBER).getValue();
    reportListener.setSqNum(sqNum);
    final String dataSetReference = reporting.getString(SubDataAttribute.DATA_SET);
    LOGGER.info("dataSetReference for buffered reports: {}", dataSetReference);
    if (StringUtils.isEmpty(dataSetReference)) {
        // Data set reference should be something like:
        // "AA1TH01LD0/LLN0.StatNrmlA".
        // If not set, this will cause problems. Not possible to write to
        // this node.
        final String dataSet = this.getDataSetReferenceForLightMeasurementDevice();
        LOGGER.warn("Expected value like [{}] to be present in {}. This will most likely cause trouble when buffered reports are received in the future!", dataSet, SubDataAttribute.DATA_SET.getDescription());
    }
    // Enable reporting.
    reporting.writeBoolean(SubDataAttribute.ENABLE_REPORTING, true);
    LOGGER.info("Allowing light measurement device {} to send buffered reports containing events", deviceConnection.getDeviceIdentification());
}
Also used : NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) Iec61850ClientBaseEventListener(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener)

Example 8 with NodeException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException in project open-smart-grid-platform by OSGP.

the class Iec61850EnableReportingCommand method enableReportingOnDevice.

/**
 * Enable reporting so the device can send reports.
 *
 * @throws NodeException In case writing or reading of data-attributes fails.
 */
public void enableReportingOnDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection) throws NodeException {
    final NodeContainer reporting = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.LOGICAL_NODE_ZERO, DataAttribute.REPORTING, Fc.BR);
    // Only reading the sequence number for the report node, as the report
    // node is not fully described by the ServerModel when using an ICD
    // file. Since the report node differs from the ServerModel, a full read
    // of the node and all data-attributes will fail. Therefore, only the
    // needed data-attributes are read.
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), (FcModelNode) reporting.getFcmodelNode().getChild(SubDataAttribute.SEQUENCE_NUMBER.getDescription()));
    final Iec61850ClientBaseEventListener reportListener = deviceConnection.getConnection().getIec61850ClientAssociation().getReportListener();
    final short sqNum = reporting.getUnsignedByte(SubDataAttribute.SEQUENCE_NUMBER).getValue();
    reportListener.setSqNum(sqNum);
    reporting.writeBoolean(SubDataAttribute.ENABLE_REPORTING, true);
    LOGGER.info("Allowing device {} to send reports containing events", deviceConnection.getDeviceIdentification());
}
Also used : NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) Iec61850ClientBaseEventListener(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener)

Example 9 with NodeException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException in project open-smart-grid-platform by OSGP.

the class Iec61850MaterialFlowCommand method execute.

@Override
public MeasurementDto execute(final Iec61850Client client, final DeviceConnection connection, final LogicalDevice logicalDevice, final int logicalDeviceIndex) throws NodeException {
    final NodeContainer containingNode = connection.getFcModelNode(logicalDevice, logicalDeviceIndex, this.logicalNode, DataAttribute.MATERIAL_FLOW, Fc.MX);
    client.readNodeDataValues(connection.getConnection().getClientAssociation(), containingNode.getFcmodelNode());
    return this.translate(containingNode);
}
Also used : NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)

Example 10 with NodeException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException in project open-smart-grid-platform by OSGP.

the class Iec61850MaterialTypeCommand method execute.

@Override
public MeasurementDto execute(final Iec61850Client client, final DeviceConnection connection, final LogicalDevice logicalDevice, final int logicalDeviceIndex) throws NodeException {
    final NodeContainer containingNode = connection.getFcModelNode(logicalDevice, logicalDeviceIndex, this.logicalNode, DataAttribute.MATERIAL_TYPE, Fc.SP);
    client.readNodeDataValues(connection.getConnection().getClientAssociation(), containingNode.getFcmodelNode());
    return this.translate(containingNode);
}
Also used : NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)

Aggregations

NodeContainer (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)53 Iec61850ClientBaseEventListener (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener)5 BdaBoolean (com.beanit.openiec61850.BdaBoolean)2 Date (java.util.Date)2 DateTime (org.joda.time.DateTime)1 ProfilePair (org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.ProfilePair)1 LogicalNode (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)1