use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850GetStatusCommand method getStatusFromDevice.
public DeviceStatusDto getStatusFromDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final Ssld ssld) throws ProtocolAdapterException {
final Function<DeviceStatusDto> function = new Function<DeviceStatusDto>() {
@Override
public DeviceStatusDto apply(final DeviceMessageLog deviceMessageLog) throws Exception {
// getting the light relay values
final List<LightValueDto> lightValues = new ArrayList<>();
for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(deviceOutputSetting.getInternalId());
final NodeContainer position = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.POSITION, Fc.ST);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), position.getFcmodelNode());
final BdaBoolean state = position.getBoolean(SubDataAttribute.STATE);
final boolean on = state.getValue();
lightValues.add(new LightValueDto(deviceOutputSetting.getExternalId(), on, null));
LOGGER.info(String.format("Got status of relay %d => %s", deviceOutputSetting.getInternalId(), on ? "on" : "off"));
deviceMessageLog.addVariable(logicalNode, DataAttribute.POSITION, Fc.ST, Boolean.toString(on));
}
final NodeContainer eventBuffer = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.EVENT_BUFFER, Fc.CF);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), eventBuffer.getFcmodelNode());
final String filter = eventBuffer.getString(SubDataAttribute.EVENT_BUFFER_FILTER);
LOGGER.info("Got EvnBuf.enbEvnType filter {}", filter);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.EVENT_BUFFER, Fc.CF, filter);
final Set<EventNotificationTypeDto> notificationTypes = EventType.getNotificationTypesForFilter(filter);
int eventNotificationsMask = 0;
for (final EventNotificationTypeDto notificationType : notificationTypes) {
eventNotificationsMask |= notificationType.getValue();
}
final NodeContainer softwareConfiguration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), softwareConfiguration.getFcmodelNode());
String lightTypeValue = softwareConfiguration.getString(SubDataAttribute.LIGHT_TYPE);
// Fix for Kaifa bug KI-31
if (lightTypeValue == null || lightTypeValue.isEmpty()) {
lightTypeValue = "RELAY";
}
final LightTypeDto lightType = LightTypeDto.valueOf(lightTypeValue);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, lightTypeValue);
DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
/*
* The preferredLinkType and actualLinkType are hard-coded to
* LinkTypeDto.ETHERNET, other link types do not apply to the
* device type in use.
*/
return new DeviceStatusDto(lightValues, LinkTypeDto.ETHERNET, LinkTypeDto.ETHERNET, lightType, eventNotificationsMask);
}
};
return iec61850Client.sendCommandWithRetry(function, "GetStatus", deviceConnection.getDeviceIdentification());
}
use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850SsldDeviceService method setLight.
@Override
public void setLight(final SetLightDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
DeviceConnection deviceConnection = null;
try {
deviceConnection = this.connectToDevice(deviceRequest);
// Getting the SSLD for the device output-settings.
final Ssld ssld = this.ssldDataService.findDevice(deviceRequest.getDeviceIdentification());
final List<DeviceOutputSetting> deviceOutputSettings = this.ssldDataService.findByRelayType(ssld, RelayType.LIGHT);
final List<LightValueDto> lightValues = deviceRequest.getLightValuesContainer().getLightValues();
List<LightValueDto> relaysWithInternalIdToSwitch;
// Check if external index 0 is used.
final LightValueDto index0LightValue = this.checkForIndex0(lightValues);
if (index0LightValue != null) {
// If external index 0 is used, create a list of all light
// relays according to the device output settings.
relaysWithInternalIdToSwitch = this.createListOfInternalIndicesToSwitch(deviceOutputSettings, index0LightValue.isOn());
} else {
// Else, create a list of internal indices based on the given
// external indices in the light values list.
relaysWithInternalIdToSwitch = this.createListOfInternalIndicesToSwitch(deviceOutputSettings, lightValues);
}
// Switch light relays based on internal indices.
final Iec61850SetLightCommand iec61850SetLightCommand = new Iec61850SetLightCommand();
for (final LightValueDto relayWithInternalIdToSwitch : relaysWithInternalIdToSwitch) {
LOGGER.info("Trying to switch light relay with internal index: {} for device: {}", relayWithInternalIdToSwitch.getIndex(), deviceRequest.getDeviceIdentification());
if (!iec61850SetLightCommand.switchLightRelay(this.iec61850Client, deviceConnection, relayWithInternalIdToSwitch.getIndex(), relayWithInternalIdToSwitch.isOn())) {
throw new ProtocolAdapterException(String.format("Failed to switch light relay with internal index: %d for device: %s", relayWithInternalIdToSwitch.getIndex(), deviceRequest.getDeviceIdentification()));
}
}
this.createSuccessfulDefaultResponse(deviceRequest, deviceResponseHandler);
} catch (final ConnectionFailureException se) {
this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, se);
} catch (final Exception e) {
this.handleException(deviceRequest, deviceResponseHandler, e);
}
this.iec61850DeviceConnectionService.disconnect(deviceConnection, deviceRequest);
}
use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850SsldDeviceService method getConfiguration.
@Override
public void getConfiguration(final DeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
DeviceConnection deviceConnection = null;
try {
deviceConnection = this.connectToDevice(deviceRequest);
// Getting the SSLD for the device output-settings.
final Ssld ssld = this.ssldDataService.findDevice(deviceRequest.getDeviceIdentification());
final ConfigurationDto configuration = new Iec61850GetConfigurationCommand().getConfigurationFromDevice(this.iec61850Client, deviceConnection, ssld, this.mapper);
final GetConfigurationDeviceResponse response = new GetConfigurationDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.OK, configuration);
deviceResponseHandler.handleResponse(response);
} catch (final ConnectionFailureException se) {
this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, se);
} catch (final Exception e) {
this.handleException(deviceRequest, deviceResponseHandler, e);
}
this.iec61850DeviceConnectionService.disconnect(deviceConnection, deviceRequest);
}
use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850SsldDeviceService method setReboot.
@Override
public void setReboot(final DeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
DeviceConnection deviceConnection = null;
try {
deviceConnection = this.connectToDevice(deviceRequest);
new Iec61850RebootCommand().rebootDevice(this.iec61850Client, deviceConnection);
this.createSuccessfulDefaultResponse(deviceRequest, deviceResponseHandler);
} catch (final ConnectionFailureException se) {
this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, se);
} catch (final Exception e) {
this.handleException(deviceRequest, deviceResponseHandler, e);
}
this.iec61850DeviceConnectionService.disconnect(deviceConnection, deviceRequest);
}
use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 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));
}
Aggregations