use of com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException in project Protocol-Adapter-IEC61850 by OSGP.
the class OsgpResponseMessageListener method onMessage.
@Override
public void onMessage(final Message message) {
try {
LOGGER.info("Received message of type: {}", message.getJMSType());
final ObjectMessage objectMessage = (ObjectMessage) message;
final String messageType = objectMessage.getJMSType();
final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);
final ResponseMessage responseMessage = (ResponseMessage) objectMessage.getObject();
final String result = responseMessage == null ? null : responseMessage.getResult().toString();
final OsgpException osgpException = responseMessage == null ? null : responseMessage.getOsgpException();
if (DeviceFunctionDto.valueOf(messageType).equals(DeviceFunctionDto.REGISTER_DEVICE)) {
this.handleDeviceRegistration(result, deviceIdentification, messageType, osgpException);
} else {
throw new UnknownMessageTypeException("Unknown JMSType: " + messageType);
}
} catch (final JMSException ex) {
LOGGER.error("Exception: {} ", ex.getMessage(), ex);
} catch (final ProtocolAdapterException e) {
LOGGER.error("ProtocolAdapterException", e);
} catch (final UnknownMessageTypeException e) {
LOGGER.error("UnknownMessageTypeException", e);
}
}
use of com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850GetConfigurationCommand method getConfigurationFromDevice.
public ConfigurationDto getConfigurationFromDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final Ssld ssld, final Iec61850Mapper mapper) throws ProtocolAdapterException {
final Function<ConfigurationDto> function = new Function<ConfigurationDto>() {
@Override
public ConfigurationDto apply(final DeviceMessageLog deviceMessageLog) throws Exception {
// Keeping the hardcoded values and values that aren't fetched
// from the device out of the Function.
// Hardcoded (not supported)
final MeterTypeDto meterType = MeterTypeDto.AUX;
// Hardcoded (not supported)
final Integer shortTermHistoryIntervalMinutes = 15;
// Hardcoded (not supported)
final LinkTypeDto preferredLinkType = LinkTypeDto.ETHERNET;
// Hardcoded (not supported)
final Integer longTermHistoryInterval = 1;
// Hardcoded (not supported)
final LongTermIntervalTypeDto longTermHistoryIntervalType = LongTermIntervalTypeDto.DAYS;
final List<RelayMapDto> relayMaps = new ArrayList<>();
for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
Iec61850GetConfigurationCommand.this.checkRelayType(iec61850Client, deviceConnection, deviceOutputSetting, deviceMessageLog);
relayMaps.add(mapper.map(deviceOutputSetting, RelayMapDto.class));
}
final RelayConfigurationDto relayConfiguration = new RelayConfigurationDto(relayMaps);
// PSLD specific => just sending null so it'll be ignored
final DaliConfigurationDto daliConfiguration = null;
// getting the software configuration values
LOGGER.info("Reading the software configuration values");
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";
}
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, SubDataAttribute.LIGHT_TYPE, lightTypeValue);
final LightTypeDto lightType = LightTypeDto.valueOf(lightTypeValue);
final short astroGateSunRiseOffset = softwareConfiguration.getShort(SubDataAttribute.ASTRONOMIC_SUNRISE_OFFSET).getValue();
final short astroGateSunSetOffset = softwareConfiguration.getShort(SubDataAttribute.ASTRONOMIC_SUNSET_OFFSET).getValue();
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, SubDataAttribute.ASTRONOMIC_SUNRISE_OFFSET, Short.toString(astroGateSunRiseOffset));
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, SubDataAttribute.ASTRONOMIC_SUNSET_OFFSET, Short.toString(astroGateSunSetOffset));
final ConfigurationDto configuration = new ConfigurationDto(lightType, daliConfiguration, relayConfiguration, shortTermHistoryIntervalMinutes, preferredLinkType, meterType, longTermHistoryInterval, longTermHistoryIntervalType);
// getting the registration configuration values
LOGGER.info("Reading the registration configuration values");
final NodeContainer registration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REGISTRATION, Fc.CF);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), registration.getFcmodelNode());
final String serverAddress = registration.getString(SubDataAttribute.SERVER_ADDRESS);
final int serverPort = registration.getInteger(SubDataAttribute.SERVER_PORT).getValue();
configuration.setOsgpIpAddress(serverAddress);
configuration.setOsgpPortNumber(serverPort);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REGISTRATION, Fc.CF, SubDataAttribute.SERVER_ADDRESS, serverAddress);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REGISTRATION, Fc.CF, SubDataAttribute.SERVER_PORT, Integer.toString(serverPort));
// getting the IP configuration values
LOGGER.info("Reading the IP configuration values");
final NodeContainer ipConfiguration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), ipConfiguration.getFcmodelNode());
final String deviceFixedIpAddress = ipConfiguration.getString(SubDataAttribute.IP_ADDRESS);
final String deviceFixedIpNetmask = ipConfiguration.getString(SubDataAttribute.NETMASK);
final String deviceFixedIpGateway = ipConfiguration.getString(SubDataAttribute.GATEWAY);
final boolean isDhcpEnabled = ipConfiguration.getBoolean(SubDataAttribute.ENABLE_DHCP).getValue();
final DeviceFixedIpDto deviceFixedIp = new DeviceFixedIpDto(deviceFixedIpAddress, deviceFixedIpNetmask, deviceFixedIpGateway);
configuration.setDeviceFixedIp(deviceFixedIp);
configuration.setDhcpEnabled(isDhcpEnabled);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.IP_ADDRESS, deviceFixedIpAddress);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.NETMASK, deviceFixedIpNetmask);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.GATEWAY, deviceFixedIpGateway);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.ENABLE_DHCP, Boolean.toString(isDhcpEnabled));
// setting the software configuration values
configuration.setAstroGateSunRiseOffset((int) astroGateSunRiseOffset);
configuration.setAstroGateSunSetOffset((int) astroGateSunSetOffset);
// getting the clock configuration values
LOGGER.info("Reading the clock configuration values");
final NodeContainer clock = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), clock.getFcmodelNode());
final int timeSyncFrequency = clock.getUnsignedShort(SubDataAttribute.TIME_SYNC_FREQUENCY).getValue();
final boolean automaticSummerTimingEnabled = clock.getBoolean(SubDataAttribute.AUTOMATIC_SUMMER_TIMING_ENABLED).getValue();
final String summerTimeDetails = clock.getString(SubDataAttribute.SUMMER_TIME_DETAILS);
final String winterTimeDetails = clock.getString(SubDataAttribute.WINTER_TIME_DETAILS);
configuration.setTimeSyncFrequency(timeSyncFrequency);
configuration.setAutomaticSummerTimingEnabled(automaticSummerTimingEnabled);
configuration.setSummerTimeDetails(new DaylightSavingTimeTransition(TIME_ZONE_AMSTERDAM, summerTimeDetails).getDateTimeForNextTransition().toDateTime(DateTimeZone.UTC));
configuration.setWinterTimeDetails(new DaylightSavingTimeTransition(TIME_ZONE_AMSTERDAM, winterTimeDetails).getDateTimeForNextTransition().toDateTime(DateTimeZone.UTC));
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.TIME_SYNC_FREQUENCY, Integer.toString(timeSyncFrequency));
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.AUTOMATIC_SUMMER_TIMING_ENABLED, Boolean.toString(automaticSummerTimingEnabled));
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.SUMMER_TIME_DETAILS, summerTimeDetails);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.WINTER_TIME_DETAILS, winterTimeDetails);
// getting the TLS configuration values
// LOGGER.info("Reading the TLS configuration values");
// final NodeContainer tls =
// deviceConnection.getFcModelNode(LogicalDevice.LIGHTING,
// LogicalNode.STREET_LIGHT_CONFIGURATION,
// DataAttribute.TLS_CONFIGURATION, Fc.CF);
//
// iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(),
// tls.getFcmodelNode());
//
// final int tlsPortNumber = (int)
// tls.getUnsignedInteger(SubDataAttribute.TLS_PORT_NUMBER).getValue();
// final boolean tlsEnabled =
// tls.getBoolean(SubDataAttribute.TLS_ENABLED).getValue();
// final String commonName =
// tls.getString(SubDataAttribute.TLS_COMMON_NAME);
//
// configuration.setTlsPortNumber(tlsPortNumber);
// configuration.setTlsEnabled(tlsEnabled);
// configuration.setCommonNameString(commonName);
DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
return configuration;
}
};
return iec61850Client.sendCommandWithRetry(function, "GetConfiguration", deviceConnection.getDeviceIdentification());
}
use of com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850SsldDeviceService method runSelfTest.
@Override
public void runSelfTest(final DeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler, final boolean startOfTest) throws JMSException {
// Assuming all goes well.
final DeviceMessageStatus status = DeviceMessageStatus.OK;
DeviceConnection deviceConnection = null;
try {
deviceConnection = this.connectToDevice(deviceRequest);
// Getting the SSLD for the device output-settings.
final Ssld ssld = this.ssldDataService.findDevice(deviceRequest.getDeviceIdentification());
// This list will contain the external indexes of all light relays.
// It's used to interpret the deviceStatus data later on.
final List<Integer> lightRelays = new ArrayList<>();
LOGGER.info("Turning all lights relays {}", startOfTest ? "on" : "off");
final Iec61850SetLightCommand iec61850SetLightCommand = new Iec61850SetLightCommand();
// startOfTest.
for (final DeviceOutputSetting deviceOutputSetting : this.ssldDataService.findByRelayType(ssld, RelayType.LIGHT)) {
lightRelays.add(deviceOutputSetting.getExternalId());
if (!iec61850SetLightCommand.switchLightRelay(this.iec61850Client, deviceConnection, deviceOutputSetting.getInternalId(), startOfTest)) {
throw new ProtocolAdapterException(String.format("Failed to switch light relay during self-test with internal index: %d for device: %s", deviceOutputSetting.getInternalId(), deviceRequest.getDeviceIdentification()));
}
}
// Sleep and wait.
this.selfTestSleep();
// Getting the status.
final DeviceStatusDto deviceStatus = new Iec61850GetStatusCommand().getStatusFromDevice(this.iec61850Client, deviceConnection, ssld);
LOGGER.info("Fetching and checking the devicestatus");
// Checking to see if all light relays have the correct state.
for (final LightValueDto lightValue : deviceStatus.getLightValues()) {
if (lightRelays.contains(lightValue.getIndex()) && lightValue.isOn() != startOfTest) {
// request failed.
throw new ProtocolAdapterException("not all relays are ".concat(startOfTest ? "on" : "off"));
}
}
LOGGER.info("All lights relays are {}, returning OK", startOfTest ? "on" : "off");
this.createSuccessfulDefaultResponse(deviceRequest, deviceResponseHandler, status);
} catch (final ConnectionFailureException se) {
LOGGER.info("Original ConnectionFailureException message: {}", se.getMessage());
final ConnectionFailureException seGeneric = new ConnectionFailureException("Connection failure", se);
this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, seGeneric);
} catch (final Exception e) {
LOGGER.info("Selftest failure", e);
final TechnicalException te = new TechnicalException(ComponentType.PROTOCOL_IEC61850, "Selftest failure - " + e.getMessage());
this.handleException(deviceRequest, deviceResponseHandler, te);
}
this.iec61850DeviceConnectionService.disconnect(deviceConnection, deviceRequest);
}
use of com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850SsldDeviceService method handleProtocolAdapterException.
private void handleProtocolAdapterException(final SetScheduleDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler, final ProtocolAdapterException protocolAdapterException) {
LOGGER.error("Could not complete the request: " + deviceRequest.getMessageType() + " for device: " + deviceRequest.getDeviceIdentification(), protocolAdapterException);
final EmptyDeviceResponse deviceResponse = this.createDefaultResponse(deviceRequest, DeviceMessageStatus.FAILURE);
deviceResponseHandler.handleException(protocolAdapterException, deviceResponse);
}
use of com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850GetFirmwareVersionCommand method getFirmwareVersionFromDevice.
public List<FirmwareVersionDto> getFirmwareVersionFromDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection) throws ProtocolAdapterException {
final Function<List<FirmwareVersionDto>> function = new Function<List<FirmwareVersionDto>>() {
@Override
public List<FirmwareVersionDto> apply(final DeviceMessageLog deviceMessageLog) throws Exception {
final List<FirmwareVersionDto> output = new ArrayList<>();
// Getting the functional firmware version
LOGGER.info("Reading the functional firmware version");
final NodeContainer functionalFirmwareNode = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.FUNCTIONAL_FIRMWARE, Fc.ST);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), functionalFirmwareNode.getFcmodelNode());
final String functionalFirmwareVersion = functionalFirmwareNode.getString(SubDataAttribute.CURRENT_VERSION);
// Adding it to the list
output.add(new FirmwareVersionDto(FirmwareModuleType.FUNCTIONAL, functionalFirmwareVersion));
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.FUNCTIONAL_FIRMWARE, Fc.ST, SubDataAttribute.CURRENT_VERSION, functionalFirmwareVersion);
// Getting the security firmware version
LOGGER.info("Reading the security firmware version");
final NodeContainer securityFirmwareNode = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SECURITY_FIRMWARE, Fc.ST);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), securityFirmwareNode.getFcmodelNode());
final String securityFirmwareVersion = securityFirmwareNode.getString(SubDataAttribute.CURRENT_VERSION);
// Adding it to the list
output.add(new FirmwareVersionDto(FirmwareModuleType.SECURITY, securityFirmwareVersion));
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SECURITY_FIRMWARE, Fc.ST, SubDataAttribute.CURRENT_VERSION, securityFirmwareVersion);
DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
return output;
}
};
return iec61850Client.sendCommandWithRetry(function, "GetFirmwareVersion", deviceConnection.getDeviceIdentification());
}
Aggregations