Search in sources :

Example 26 with DeviceConnection

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project open-smart-grid-platform by OSGP.

the class Iec61850SetLightCommand method switchLightRelays.

/**
 * Switch one or more light relays of a switching device.
 *
 * @param iec61850Client The {@link Iec61850Client} instance.
 * @param deviceConnection The {@link DeviceConnection} instance.
 * @param relaysWithInternalIdToSwitch List of {@link LightValueDto}'s which represent the relays
 *     to switch on or off.
 * @param functionName The name of the function reported to {@link DeviceMessageLog}.
 * @throws ProtocolAdapterException In case the switch action(s) for light relays fail.
 */
public void switchLightRelays(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final List<LightValueDto> relaysWithInternalIdToSwitch, final String functionName) throws ProtocolAdapterException {
    final Function<Void> function = new Function<Void>() {

        @Override
        public Void apply(final DeviceMessageLog deviceMessageLog) throws ProtocolAdapterException {
            for (final LightValueDto relayWithInternalIdToSwitch : relaysWithInternalIdToSwitch) {
                final int index = relayWithInternalIdToSwitch.getIndex();
                final boolean on = relayWithInternalIdToSwitch.isOn();
                final String deviceIdentification = deviceConnection.getDeviceIdentification();
                LOGGER.info("Trying to switch light relay with internal index: {} on: {} for device: {}", index, on, deviceIdentification);
                try {
                    Iec61850SetLightCommand.this.switchLightRelay(iec61850Client, deviceConnection, deviceMessageLog, index, on);
                } catch (final Exception e) {
                    LOGGER.error("Exception during switchLightRelay()", e);
                    throw new ProtocolAdapterException(String.format("Failed to switch light relay with internal index: %d for device: %s", relayWithInternalIdToSwitch.getIndex(), deviceConnection.getDeviceIdentification()));
                }
            }
            Iec61850SetLightCommand.this.loggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            return null;
        }
    };
    iec61850Client.sendCommandWithRetry(function, StringUtils.isEmpty(functionName) ? "SetLight" : functionName, deviceConnection.getDeviceIdentification());
}
Also used : Function(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Function) DeviceMessageLog(org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) NodeException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException) LightValueDto(org.opensmartgridplatform.dto.valueobjects.LightValueDto)

Example 27 with DeviceConnection

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection 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 28 with DeviceConnection

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection 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 29 with DeviceConnection

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project open-smart-grid-platform by OSGP.

the class Iec61850GetConfigurationCommand method checkRelayType.

private void checkRelayType(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final DeviceOutputSetting deviceOutputSetting, final DeviceMessageLog deviceMessageLog) throws ProtocolAdapterException {
    final RelayType registeredRelayType = deviceOutputSetting.getRelayType();
    final int expectedSwType;
    if (RelayType.LIGHT.equals(registeredRelayType)) {
        expectedSwType = SWITCH_TYPE_LIGHT;
    } else if (RelayType.TARIFF.equals(registeredRelayType) || RelayType.TARIFF_REVERSED.equals(registeredRelayType)) {
        expectedSwType = SWITCH_TYPE_TARIFF;
    } else {
        throw new ProtocolAdapterException("DeviceOutputSetting (internal index = " + deviceOutputSetting.getInternalId() + ", external index = " + deviceOutputSetting.getExternalId() + ") does not have a known RelayType: " + registeredRelayType);
    }
    final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(deviceOutputSetting.getInternalId());
    final NodeContainer switchType = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.SWITCH_TYPE, Fc.ST);
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), switchType.getFcmodelNode());
    final int switchTypeValue = switchType.getByte(SubDataAttribute.STATE).getValue();
    if (expectedSwType != switchTypeValue) {
        throw new ProtocolAdapterException("DeviceOutputSetting (internal index = " + deviceOutputSetting.getInternalId() + ", external index = " + deviceOutputSetting.getExternalId() + ") has a RelayType (" + registeredRelayType + ") that does not match the SwType on the device: " + (switchTypeValue == SWITCH_TYPE_TARIFF ? "Tariff switch (0)" : (switchTypeValue == SWITCH_TYPE_LIGHT ? "Light switch (1)" : "Unknown value: " + switchTypeValue)));
    }
    deviceMessageLog.addVariable(logicalNode, DataAttribute.SWITCH_TYPE, Fc.ST, SubDataAttribute.STATE, Integer.toString(switchTypeValue));
}
Also used : RelayType(org.opensmartgridplatform.core.db.api.iec61850valueobjects.RelayType) NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) LogicalNode(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)

Example 30 with DeviceConnection

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection 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)

Aggregations

NodeContainer (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)63 JMSException (javax.jms.JMSException)32 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)20 DeviceConnection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)18 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)18 ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)17 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)17 ConnectionFailureException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)17 NodeException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException)14 NodeWriteException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException)13 FunctionalException (com.alliander.osgp.shared.exceptionhandling.FunctionalException)13 TechnicalException (com.alliander.osgp.shared.exceptionhandling.TechnicalException)13 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)13 DeviceMessageLog (org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)12 Function (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Function)12 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)12 Ssld (com.alliander.osgp.core.db.api.iec61850.entities.Ssld)6 ArrayList (java.util.ArrayList)6 DateTime (org.joda.time.DateTime)6 Iec61850ClientBaseEventListener (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener)6