Search in sources :

Example 11 with DeviceRequest

use of org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest in project open-smart-grid-platform by OSGP.

the class Iec61850SsldDeviceService method getStatus.

@Override
public void getStatus(final DeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
    DeviceConnection devCon = null;
    try {
        final DeviceConnection deviceConnection = this.connectToDevice(deviceRequest);
        devCon = deviceConnection;
        // Getting the SSLD for the device output-settings.
        final Ssld ssld = this.ssldDataService.findDevice(deviceRequest.getDeviceIdentification());
        final DeviceStatusDto deviceStatus = new Iec61850GetStatusCommand(this.deviceMessageLoggingService).getStatusFromDevice(this.iec61850Client, deviceConnection, ssld);
        final GetStatusDeviceResponse deviceResponse = new GetStatusDeviceResponse(deviceRequest, deviceStatus);
        deviceResponseHandler.handleResponse(deviceResponse);
        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 : Iec61850GetStatusCommand(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850GetStatusCommand) GetStatusDeviceResponse(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.GetStatusDeviceResponse) DeviceStatusDto(org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) 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 12 with DeviceRequest

use of org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest in project open-smart-grid-platform by OSGP.

the class Iec61850SsldDeviceService method handleConnectionFailureException.

private void handleConnectionFailureException(final DeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler, final ConnectionFailureException connectionFailureException) throws JMSException {
    LOGGER.error("Could not connect to device", connectionFailureException);
    final EmptyDeviceResponse deviceResponse = this.createDefaultResponse(deviceRequest, DeviceMessageStatus.FAILURE);
    deviceResponseHandler.handleConnectionFailure(connectionFailureException, deviceResponse);
}
Also used : EmptyDeviceResponse(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.EmptyDeviceResponse)

Example 13 with DeviceRequest

use of org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest in project open-smart-grid-platform 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: {} for device: {}", deviceRequest.getMessageType(), deviceRequest.getDeviceIdentification(), protocolAdapterException);
    final EmptyDeviceResponse deviceResponse = this.createDefaultResponse(deviceRequest, DeviceMessageStatus.FAILURE);
    deviceResponseHandler.handleException(protocolAdapterException, deviceResponse);
}
Also used : EmptyDeviceResponse(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.EmptyDeviceResponse)

Example 14 with DeviceRequest

use of org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest in project open-smart-grid-platform by OSGP.

the class Iec61850SsldDeviceService method setLight.

@Override
public void setLight(final SetLightDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
    DeviceConnection devCon = null;
    try {
        final DeviceConnection deviceConnection = this.connectToDevice(deviceRequest);
        devCon = deviceConnection;
        // 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();
        final 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(this.deviceMessageLoggingService);
        iec61850SetLightCommand.switchLightRelays(this.iec61850Client, deviceConnection, relaysWithInternalIdToSwitch, null);
        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) DeviceOutputSetting(org.opensmartgridplatform.core.db.api.iec61850.entities.DeviceOutputSetting) 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) LightValueDto(org.opensmartgridplatform.dto.valueobjects.LightValueDto) Iec61850SetLightCommand(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850SetLightCommand)

Example 15 with DeviceRequest

use of org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest in project open-smart-grid-platform by OSGP.

the class Iec61850RtuDeviceService method setData.

@Override
public void setData(final SetDataDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
    try {
        final String serverName = this.getServerName(deviceRequest);
        final ServerModel serverModel = this.connectAndRetrieveServerModel(deviceRequest, serverName);
        final ClientAssociation clientAssociation = this.iec61850DeviceConnectionService.getClientAssociation(deviceRequest.getDeviceIdentification());
        this.handleSetData(new DeviceConnection(new Iec61850Connection(new Iec61850ClientAssociation(clientAssociation, null), serverModel), deviceRequest.getDeviceIdentification(), deviceRequest.getOrganisationIdentification(), serverName), deviceRequest);
        final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest, DeviceMessageStatus.OK);
        deviceResponseHandler.handleResponse(deviceResponse);
    } catch (final ConnectionFailureException se) {
        LOGGER.error("Could not connect to device after all retries", se);
        final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest, DeviceMessageStatus.FAILURE);
        deviceResponseHandler.handleConnectionFailure(se, deviceResponse);
    } catch (final Exception e) {
        LOGGER.error("Unexpected exception during Set Data", e);
        final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest, DeviceMessageStatus.FAILURE);
        deviceResponseHandler.handleException(e, deviceResponse);
    }
}
Also used : ServerModel(com.beanit.openiec61850.ServerModel) Iec61850Connection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection) Iec61850ClientAssociation(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) Iec61850ClientAssociation(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) ClientAssociation(com.beanit.openiec61850.ClientAssociation) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) JMSException(javax.jms.JMSException) EmptyDeviceResponse(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.EmptyDeviceResponse)

Aggregations

JMSException (javax.jms.JMSException)33 ConnectionFailureException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)16 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)16 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)16 NodeException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException)13 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)13 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)12 DeviceRequest (org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest)9 EmptyDeviceResponse (org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.EmptyDeviceResponse)9 RequestMessageData (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)9 Iec61850DeviceResponseHandler (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler)9 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)9 DeviceRequest (com.alliander.osgp.adapter.protocol.iec61850.device.DeviceRequest)8 RequestMessageData (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)8 Iec61850DeviceResponseHandler (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler)8 Ssld (org.opensmartgridplatform.core.db.api.iec61850.entities.Ssld)5 ClientAssociation (com.beanit.openiec61850.ClientAssociation)3 ServerModel (com.beanit.openiec61850.ServerModel)3 Iec61850ClientAssociation (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation)3 Iec61850Connection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection)3