Search in sources :

Example 1 with LightValueDto

use of org.opensmartgridplatform.dto.valueobjects.LightValueDto in project open-smart-grid-platform by OSGP.

the class Iec61850SetScheduleCommand method createScheduleEntries.

/**
 * Returns a map of schedule entries, grouped by the internal index.
 */
private Map<Integer, List<ScheduleEntry>> createScheduleEntries(final List<ScheduleEntryDto> scheduleList, final Ssld ssld, final RelayTypeDto relayTypeDto) throws FunctionalException {
    final Map<Integer, List<ScheduleEntry>> relaySchedulesEntries = new HashMap<>();
    final RelayType relayType = RelayType.valueOf(relayTypeDto.name());
    final List<DeviceOutputSetting> settings = this.ssldDataService.findByRelayType(ssld, relayType);
    for (final ScheduleEntryDto schedule : scheduleList) {
        for (final LightValueDto lightValue : schedule.getLightValue()) {
            this.setScheduleEntry(ssld, relaySchedulesEntries, relayType, settings, schedule, lightValue);
        }
    }
    return relaySchedulesEntries;
}
Also used : RelayType(org.opensmartgridplatform.core.db.api.iec61850valueobjects.RelayType) ScheduleEntryDto(org.opensmartgridplatform.dto.valueobjects.ScheduleEntryDto) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) DeviceOutputSetting(org.opensmartgridplatform.core.db.api.iec61850.entities.DeviceOutputSetting) LightValueDto(org.opensmartgridplatform.dto.valueobjects.LightValueDto)

Example 2 with LightValueDto

use of org.opensmartgridplatform.dto.valueobjects.LightValueDto in project open-smart-grid-platform by OSGP.

the class Iec61850SetLightCommand method switchLightRelays.

/**
 * Switch one or more light relays of a switching device.
 *
 * @param iec61850Client The {@link Iec61850Client} instance.
 * @param deviceConnection The {@link DeviceConnection} instance.
 * @param relaysWithInternalIdToSwitch List of {@link LightValueDto}'s which represent the relays
 *     to switch on or off.
 * @param functionName The name of the function reported to {@link DeviceMessageLog}.
 * @throws ProtocolAdapterException In case the switch action(s) for light relays fail.
 */
public void switchLightRelays(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final List<LightValueDto> relaysWithInternalIdToSwitch, final String functionName) throws ProtocolAdapterException {
    final Function<Void> function = new Function<Void>() {

        @Override
        public Void apply(final DeviceMessageLog deviceMessageLog) throws ProtocolAdapterException {
            for (final LightValueDto relayWithInternalIdToSwitch : relaysWithInternalIdToSwitch) {
                final int index = relayWithInternalIdToSwitch.getIndex();
                final boolean on = relayWithInternalIdToSwitch.isOn();
                final String deviceIdentification = deviceConnection.getDeviceIdentification();
                LOGGER.info("Trying to switch light relay with internal index: {} on: {} for device: {}", index, on, deviceIdentification);
                try {
                    Iec61850SetLightCommand.this.switchLightRelay(iec61850Client, deviceConnection, deviceMessageLog, index, on);
                } catch (final Exception e) {
                    LOGGER.error("Exception during switchLightRelay()", e);
                    throw new ProtocolAdapterException(String.format("Failed to switch light relay with internal index: %d for device: %s", relayWithInternalIdToSwitch.getIndex(), deviceConnection.getDeviceIdentification()));
                }
            }
            Iec61850SetLightCommand.this.loggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            return null;
        }
    };
    iec61850Client.sendCommandWithRetry(function, StringUtils.isEmpty(functionName) ? "SetLight" : functionName, 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) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) NodeException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException) LightValueDto(org.opensmartgridplatform.dto.valueobjects.LightValueDto)

Example 3 with LightValueDto

use of org.opensmartgridplatform.dto.valueobjects.LightValueDto in project open-smart-grid-platform by OSGP.

the class OslpDeviceService method handleOslpResponseGetStatus.

private void handleOslpResponseGetStatus(final DeviceRequest deviceRequest, final OslpEnvelope oslpResponse, final DeviceResponseHandler deviceResponseHandler) {
    this.saveOslpResponseLogEntry(deviceRequest, oslpResponse);
    this.updateSequenceNumber(deviceRequest.getDeviceIdentification(), oslpResponse);
    DeviceStatusDto deviceStatus = null;
    if (oslpResponse.getPayloadMessage().hasGetStatusResponse()) {
        final Oslp.GetStatusResponse getStatusResponse = oslpResponse.getPayloadMessage().getGetStatusResponse();
        final Oslp.Status oslpStatus = getStatusResponse.getStatus();
        if (oslpStatus == Oslp.Status.OK) {
            // Required properties.
            final List<LightValueDto> lightValues = this.mapper.mapAsList(getStatusResponse.getValueList(), LightValueDto.class);
            final LinkTypeDto preferredType = this.getPreferredLinktype(getStatusResponse);
            final LinkTypeDto actualLinkType = this.getActualLinktype(getStatusResponse);
            final LightTypeDto lightType = this.getLightType(getStatusResponse);
            final int eventNotificationMask = getStatusResponse.getEventNotificationMask();
            deviceStatus = new DeviceStatusDto(lightValues, preferredType, actualLinkType, lightType, eventNotificationMask);
            // Optional properties.
            this.setBootLoaderVersion(deviceStatus, getStatusResponse);
            this.setCurrentConfigurationBankUsed(deviceStatus, getStatusResponse);
            this.setCurrentIp(deviceStatus, getStatusResponse);
            this.setCurrentTime(deviceStatus, getStatusResponse);
            this.setDcOutputVoltageCurrent(deviceStatus, getStatusResponse);
            this.setDcOutputVoltageMaximum(deviceStatus, getStatusResponse);
            this.setEventNotificationsMask(deviceStatus, getStatusResponse);
            this.setExternalFlashMemSize(deviceStatus, getStatusResponse);
            this.setFirmwareVersion(deviceStatus, getStatusResponse);
            this.setHardwareId(deviceStatus, getStatusResponse);
            this.setInternalFlashMemSize(deviceStatus, getStatusResponse);
            this.setLastInternalTestResultCode(deviceStatus, getStatusResponse);
            this.setMacAddress(deviceStatus, getStatusResponse);
            this.setMaximumOutputPowerOnDcOutput(deviceStatus, getStatusResponse);
            this.setName(deviceStatus, getStatusResponse);
            this.setNumberOfOutputs(deviceStatus, getStatusResponse);
            this.setSerialNumber(deviceStatus, getStatusResponse);
            this.setStartupCounter(deviceStatus, getStatusResponse);
        } else {
            // handle failure by throwing exceptions if needed
            LOGGER.error("Unable to convert Oslp.GetStatusResponse");
        }
    }
    final DeviceResponse deviceResponse = new GetStatusDeviceResponse(deviceRequest, deviceStatus);
    deviceResponseHandler.handleResponse(deviceResponse);
}
Also used : GetStatusDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse) LinkTypeDto(org.opensmartgridplatform.dto.valueobjects.LinkTypeDto) LightTypeDto(org.opensmartgridplatform.dto.valueobjects.LightTypeDto) DeviceStatusDto(org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto) EmptyDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.EmptyDeviceResponse) DeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponse) GetConfigurationDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetConfigurationDeviceResponse) GetStatusDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse) GetFirmwareVersionDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetFirmwareVersionDeviceResponse) Oslp(org.opensmartgridplatform.oslp.Oslp) LightValueDto(org.opensmartgridplatform.dto.valueobjects.LightValueDto)

Example 4 with LightValueDto

use of org.opensmartgridplatform.dto.valueobjects.LightValueDto in project open-smart-grid-platform 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());
        LOGGER.info("Turning all lights relays {}", startOfTest ? "on" : "off");
        final Iec61850SetLightCommand iec61850SetLightCommand = new Iec61850SetLightCommand(this.deviceMessageLoggingService);
        final List<LightValueDto> relaysWithInternalIdToSwitch = this.createListOfInternalIndicesToSwitch(this.ssldDataService.findByRelayType(ssld, RelayType.LIGHT), startOfTest);
        iec61850SetLightCommand.switchLightRelays(this.iec61850Client, deviceConnection, relaysWithInternalIdToSwitch, startOfTest ? "StartSelfTest" : "StopSelfTest");
        // Sleep and wait.
        this.selfTestSleep();
        // Getting the status.
        final DeviceStatusDto deviceStatus = new Iec61850GetStatusCommand(this.deviceMessageLoggingService).getStatusFromDevice(this.iec61850Client, deviceConnection, ssld);
        LOGGER.info("Fetching and checking the devicestatus");
        // Checking to see if all light relays have the correct state.
        this.checkLightRelaysState(startOfTest, relaysWithInternalIdToSwitch, deviceStatus);
        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);
}
Also used : DeviceMessageStatus(org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceMessageStatus) Iec61850GetStatusCommand(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850GetStatusCommand) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) 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) Iec61850SetLightCommand(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850SetLightCommand) LightValueDto(org.opensmartgridplatform.dto.valueobjects.LightValueDto)

Example 5 with LightValueDto

use of org.opensmartgridplatform.dto.valueobjects.LightValueDto 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)

Aggregations

LightValueDto (org.opensmartgridplatform.dto.valueobjects.LightValueDto)9 DeviceOutputSetting (org.opensmartgridplatform.core.db.api.iec61850.entities.DeviceOutputSetting)5 ArrayList (java.util.ArrayList)4 NodeException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException)3 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)3 DeviceStatusDto (org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto)3 JMSException (javax.jms.JMSException)2 DeviceMessageLog (org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)2 ConnectionFailureException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)2 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)2 Function (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Function)2 Iec61850SetLightCommand (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850SetLightCommand)2 Ssld (org.opensmartgridplatform.core.db.api.iec61850.entities.Ssld)2 LightTypeDto (org.opensmartgridplatform.dto.valueobjects.LightTypeDto)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)2 BdaBoolean (com.beanit.openiec61850.BdaBoolean)1 HashMap (java.util.HashMap)1 List (java.util.List)1 DeviceMessageStatus (org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceMessageStatus)1