use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project open-smart-grid-platform 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(this.deviceMessageLoggingService).getConfigurationFromDevice(this.iec61850Client, deviceConnection, ssld, this.mapper);
final GetConfigurationDeviceResponse response = new GetConfigurationDeviceResponse(deviceRequest, 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 org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project open-smart-grid-platform by OSGP.
the class Iec61850SsldDeviceService method setTransition.
@Override
public void setTransition(final SetTransitionDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
DeviceConnection devCon = null;
try {
final DeviceConnection deviceConnection = this.connectToDevice(deviceRequest);
devCon = deviceConnection;
new Iec61850TransitionCommand(this.deviceMessageLoggingService).transitionDevice(this.iec61850Client, deviceConnection, deviceRequest.getTransitionTypeContainer());
this.createSuccessfulDefaultResponse(deviceRequest, deviceResponseHandler);
this.enableReporting(deviceConnection, deviceRequest);
} catch (final ConnectionFailureException se) {
this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, se);
this.iec61850DeviceConnectionService.disconnect(devCon, deviceRequest);
} catch (final Exception e) {
this.handleException(deviceRequest, deviceResponseHandler, e);
this.iec61850DeviceConnectionService.disconnect(devCon, deviceRequest);
}
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project open-smart-grid-platform by OSGP.
the class Iec61850UpdateFirmwareCommand method updateSecurityFirmware.
private void updateSecurityFirmware(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final String fullUrl, final DeviceMessageLog deviceMessageLog) throws NodeException {
LOGGER.info("Reading the security firmware node for device: {}", deviceConnection.getDeviceIdentification());
final NodeContainer securityFirmwareNode = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SECURITY_FIRMWARE, Fc.CF);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), securityFirmwareNode.getFcmodelNode());
final String currentSecurityFirmwareDownloadUrl = securityFirmwareNode.getString(SubDataAttribute.URL);
final Date currentSecurityFirmwareUpdateDateTime = securityFirmwareNode.getDate(SubDataAttribute.START_TIME);
LOGGER.info("Current security firmware download url: {}, start time: {} for device: {}", currentSecurityFirmwareDownloadUrl, currentSecurityFirmwareUpdateDateTime, deviceConnection.getDeviceIdentification());
LOGGER.info("Updating the security firmware download url to : {} for device: {}", fullUrl, deviceConnection.getDeviceIdentification());
securityFirmwareNode.writeString(SubDataAttribute.URL, fullUrl);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SECURITY_FIRMWARE, Fc.CF, SubDataAttribute.URL, fullUrl);
final Date oneMinuteFromNow = this.determineFirmwareUpdateDateTime(iec61850Client, deviceConnection);
LOGGER.info("Updating the security firmware download start time to: {} for device: {}", oneMinuteFromNow, deviceConnection.getDeviceIdentification());
securityFirmwareNode.writeDate(SubDataAttribute.START_TIME, oneMinuteFromNow);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SECURITY_FIRMWARE, Fc.CF, SubDataAttribute.START_TIME, this.simpleDateFormat.format(oneMinuteFromNow));
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project open-smart-grid-platform by OSGP.
the class Iec61850UpdateFirmwareCommand method updateFunctionalFirmware.
private void updateFunctionalFirmware(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final String fullUrl, final DeviceMessageLog deviceMessageLog) throws NodeException {
LOGGER.info("Reading the functional firmware node for device: {}", deviceConnection.getDeviceIdentification());
final NodeContainer functionalFirmwareNode = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.FUNCTIONAL_FIRMWARE, Fc.CF);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), functionalFirmwareNode.getFcmodelNode());
final String currentFunctionalFirmwareDownloadUrl = functionalFirmwareNode.getString(SubDataAttribute.URL);
final Date currentFunctionalFirmwareUpdateDateTime = functionalFirmwareNode.getDate(SubDataAttribute.START_TIME);
LOGGER.info("Current functional firmware download url: {}, start time: {} for device: {}", currentFunctionalFirmwareDownloadUrl, currentFunctionalFirmwareUpdateDateTime, deviceConnection.getDeviceIdentification());
LOGGER.info("Updating the functional firmware download url to: {} for device: {}", fullUrl, deviceConnection.getDeviceIdentification());
functionalFirmwareNode.writeString(SubDataAttribute.URL, fullUrl);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.FUNCTIONAL_FIRMWARE, Fc.CF, SubDataAttribute.URL, fullUrl);
final Date oneMinuteFromNow = this.determineFirmwareUpdateDateTime(iec61850Client, deviceConnection);
LOGGER.info("Updating the functional firmware download start time to: {} for device: {}", oneMinuteFromNow, deviceConnection.getDeviceIdentification());
functionalFirmwareNode.writeDate(SubDataAttribute.START_TIME, oneMinuteFromNow);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.FUNCTIONAL_FIRMWARE, Fc.CF, SubDataAttribute.START_TIME, this.simpleDateFormat.format(oneMinuteFromNow));
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project open-smart-grid-platform by OSGP.
the class Iec61850UpdateFirmwareCommand method pushFirmwareToDevice.
public void pushFirmwareToDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final String fullUrl, final FirmwareModuleData firmwareModuleData) throws ProtocolAdapterException {
final Function<Void> function = new Function<Void>() {
@Override
public Void apply(final DeviceMessageLog deviceMessageLog) throws ProtocolAdapterException {
final int count = firmwareModuleData.countNumberOfModules();
if (count != 1) {
throw new ProtocolAdapterException(String.format("Number of firmware modules is not equal to 1 but %d", count));
}
// updated.
if (FirmwareModuleType.FUNCTIONAL.name().equalsIgnoreCase(firmwareModuleData.getModuleVersionFunc())) {
Iec61850UpdateFirmwareCommand.this.updateFunctionalFirmware(iec61850Client, deviceConnection, fullUrl, deviceMessageLog);
} else if (FirmwareModuleType.SECURITY.name().equalsIgnoreCase(firmwareModuleData.getModuleVersionSec())) {
Iec61850UpdateFirmwareCommand.this.updateSecurityFirmware(iec61850Client, deviceConnection, fullUrl, deviceMessageLog);
} else {
throw new ProtocolAdapterException(String.format("Unsupported firmwareModuleData (only functional and security are allowed): communication: %s, functional: %s, module-active: %s, m-bus: %s, security: %s, fullUrl: %s", firmwareModuleData.getModuleVersionComm(), firmwareModuleData.getModuleVersionFunc(), firmwareModuleData.getModuleVersionMa(), firmwareModuleData.getModuleVersionMbus(), firmwareModuleData.getModuleVersionSec(), fullUrl));
}
Iec61850UpdateFirmwareCommand.this.loggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
return null;
}
};
iec61850Client.sendCommandWithRetry(function, "UpdateFirmware", deviceConnection.getDeviceIdentification());
}
Aggregations