Search in sources :

Example 1 with SetLightDeviceRequest

use of org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.requests.SetLightDeviceRequest 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 2 with SetLightDeviceRequest

use of org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.requests.SetLightDeviceRequest in project Protocol-Adapter-IEC61850 by OSGP.

the class PublicLightingSetLightRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing public lighting set light request message");
    String correlationUid = null;
    String domain = null;
    String domainVersion = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    String ipAddress = null;
    int retryCount = 0;
    boolean isScheduled = false;
    LightValueMessageDataContainerDto lightValueMessageDataContainer = null;
    try {
        correlationUid = message.getJMSCorrelationID();
        domain = message.getStringProperty(Constants.DOMAIN);
        domainVersion = message.getStringProperty(Constants.DOMAIN_VERSION);
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        ipAddress = message.getStringProperty(Constants.IP_ADDRESS);
        retryCount = message.getIntProperty(Constants.RETRY_COUNT);
        isScheduled = message.propertyExists(Constants.IS_SCHEDULED) ? message.getBooleanProperty(Constants.IS_SCHEDULED) : false;
        lightValueMessageDataContainer = (LightValueMessageDataContainerDto) message.getObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("domain: {}", domain);
        LOGGER.debug("domainVersion: {}", domainVersion);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("ipAddress: {}", ipAddress);
        return;
    }
    final RequestMessageData requestMessageData = new RequestMessageData(lightValueMessageDataContainer, domain, domainVersion, messageType, retryCount, isScheduled, correlationUid, organisationIdentification, deviceIdentification);
    this.printDomainInfo(messageType, domain, domainVersion);
    final Iec61850DeviceResponseHandler iec61850DeviceResponseHandler = this.createIec61850DeviceResponseHandler(requestMessageData, message);
    final SetLightDeviceRequest deviceRequest = new SetLightDeviceRequest(organisationIdentification, deviceIdentification, correlationUid, lightValueMessageDataContainer, domain, domainVersion, messageType, ipAddress, retryCount, isScheduled);
    this.deviceService.setLight(deviceRequest, iec61850DeviceResponseHandler);
}
Also used : Iec61850DeviceResponseHandler(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler) SetLightDeviceRequest(com.alliander.osgp.adapter.protocol.iec61850.device.ssld.requests.SetLightDeviceRequest) LightValueMessageDataContainerDto(com.alliander.osgp.dto.valueobjects.LightValueMessageDataContainerDto) JMSException(javax.jms.JMSException) RequestMessageData(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)

Example 3 with SetLightDeviceRequest

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

the class PublicLightingSetLightRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing public lighting set light request message");
    MessageMetadata messageMetadata;
    LightValueMessageDataContainerDto lightValueMessageDataContainer;
    try {
        messageMetadata = MessageMetadata.fromMessage(message);
        lightValueMessageDataContainer = (LightValueMessageDataContainerDto) message.getObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        return;
    }
    final RequestMessageData requestMessageData = RequestMessageData.newBuilder().messageMetadata(messageMetadata).build();
    this.printDomainInfo(requestMessageData);
    final Iec61850DeviceResponseHandler iec61850DeviceResponseHandler = this.createIec61850DeviceResponseHandler(requestMessageData, message);
    final DeviceRequest.Builder deviceRequestBuilder = DeviceRequest.newBuilder().messageMetaData(messageMetadata);
    this.deviceService.setLight(new SetLightDeviceRequest(deviceRequestBuilder, lightValueMessageDataContainer), iec61850DeviceResponseHandler);
}
Also used : Iec61850DeviceResponseHandler(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) SetLightDeviceRequest(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.requests.SetLightDeviceRequest) LightValueMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.LightValueMessageDataContainerDto) JMSException(javax.jms.JMSException) DeviceRequest(org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest) SetLightDeviceRequest(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.requests.SetLightDeviceRequest) RequestMessageData(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)

Aggregations

JMSException (javax.jms.JMSException)3 SetLightDeviceRequest (com.alliander.osgp.adapter.protocol.iec61850.device.ssld.requests.SetLightDeviceRequest)1 RequestMessageData (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)1 Iec61850DeviceResponseHandler (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler)1 LightValueMessageDataContainerDto (com.alliander.osgp.dto.valueobjects.LightValueMessageDataContainerDto)1 DeviceRequest (org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest)1 SetLightDeviceRequest (org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.requests.SetLightDeviceRequest)1 ConnectionFailureException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)1 NodeException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)1 RequestMessageData (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)1 Iec61850DeviceResponseHandler (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler)1 Iec61850SetLightCommand (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850SetLightCommand)1 DeviceOutputSetting (org.opensmartgridplatform.core.db.api.iec61850.entities.DeviceOutputSetting)1 Ssld (org.opensmartgridplatform.core.db.api.iec61850.entities.Ssld)1 LightValueDto (org.opensmartgridplatform.dto.valueobjects.LightValueDto)1 LightValueMessageDataContainerDto (org.opensmartgridplatform.dto.valueobjects.LightValueMessageDataContainerDto)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1