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());
}
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());
}
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());
}
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));
}
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);
}
Aggregations