Search in sources :

Example 66 with DeviceConnection

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);
}
Also used : ConfigurationDto(org.opensmartgridplatform.dto.valueobjects.ConfigurationDto) GetConfigurationDeviceResponse(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.GetConfigurationDeviceResponse) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) Iec61850GetConfigurationCommand(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850GetConfigurationCommand) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) JMSException(javax.jms.JMSException) NodeException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) Ssld(org.opensmartgridplatform.core.db.api.iec61850.entities.Ssld)

Example 67 with DeviceConnection

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);
    }
}
Also used : ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) Iec61850TransitionCommand(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850TransitionCommand) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) JMSException(javax.jms.JMSException) NodeException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)

Example 68 with DeviceConnection

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));
}
Also used : NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) Date(java.util.Date)

Example 69 with DeviceConnection

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));
}
Also used : NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) Date(java.util.Date)

Example 70 with DeviceConnection

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

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