Search in sources :

Example 1 with LinkTypeDto

use of org.opensmartgridplatform.dto.valueobjects.LinkTypeDto 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 2 with LinkTypeDto

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

the class Iec61850GetConfigurationCommand method getConfigurationFromDevice.

public ConfigurationDto getConfigurationFromDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final Ssld ssld, final Iec61850Mapper mapper) throws ProtocolAdapterException {
    final Function<ConfigurationDto> function = new Function<ConfigurationDto>() {

        @Override
        public ConfigurationDto apply(final DeviceMessageLog deviceMessageLog) throws ProtocolAdapterException {
            // Keeping the hardcoded values and values that aren't fetched
            // from the device out of the Function.
            final LinkTypeDto preferredLinkType = LinkTypeDto.ETHERNET;
            // Map the relay configuration.
            final List<RelayMapDto> relayMaps = new ArrayList<>();
            for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
                Iec61850GetConfigurationCommand.this.checkRelayType(iec61850Client, deviceConnection, deviceOutputSetting, deviceMessageLog);
                relayMaps.add(mapper.map(deviceOutputSetting, RelayMapDto.class));
            }
            // Sort the relay configuration on index.
            Collections.sort(relayMaps, (o1, o2) -> o1.getIndex().compareTo(o2.getIndex()));
            final RelayConfigurationDto relayConfiguration = new RelayConfigurationDto(relayMaps);
            // PSLD specific => just sending null so it'll be ignored
            final DaliConfigurationDto daliConfiguration = null;
            // getting the software configuration values
            LOGGER.info("Reading the software configuration values");
            final NodeContainer softwareConfiguration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), softwareConfiguration.getFcmodelNode());
            String lightTypeValue = softwareConfiguration.getString(SubDataAttribute.LIGHT_TYPE);
            // Fix for Kaifa bug KI-31
            if (lightTypeValue == null || lightTypeValue.isEmpty()) {
                lightTypeValue = "RELAY";
            }
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, SubDataAttribute.LIGHT_TYPE, lightTypeValue);
            final LightTypeDto lightType = LightTypeDto.valueOf(lightTypeValue);
            final short astroGateSunRiseOffset = softwareConfiguration.getShort(SubDataAttribute.ASTRONOMIC_SUNRISE_OFFSET).getValue();
            final short astroGateSunSetOffset = softwareConfiguration.getShort(SubDataAttribute.ASTRONOMIC_SUNSET_OFFSET).getValue();
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, SubDataAttribute.ASTRONOMIC_SUNRISE_OFFSET, Short.toString(astroGateSunRiseOffset));
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, SubDataAttribute.ASTRONOMIC_SUNSET_OFFSET, Short.toString(astroGateSunSetOffset));
            final ConfigurationDto configuration = ConfigurationDto.newBuilder().withLightType(lightType).withDaliConfiguration(daliConfiguration).withRelayConfiguration(relayConfiguration).withPreferredLinkType(preferredLinkType).build();
            // getting the registration configuration values
            LOGGER.info("Reading the registration configuration values");
            final NodeContainer registration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REGISTRATION, Fc.CF);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), registration.getFcmodelNode());
            final String serverAddress = registration.getString(SubDataAttribute.SERVER_ADDRESS);
            final int serverPort = registration.getInteger(SubDataAttribute.SERVER_PORT).getValue();
            configuration.setOsgpIpAddress(serverAddress);
            configuration.setOsgpPortNumber(serverPort);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REGISTRATION, Fc.CF, SubDataAttribute.SERVER_ADDRESS, serverAddress);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REGISTRATION, Fc.CF, SubDataAttribute.SERVER_PORT, Integer.toString(serverPort));
            // getting the IP configuration values
            LOGGER.info("Reading the IP configuration values");
            final NodeContainer ipConfiguration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), ipConfiguration.getFcmodelNode());
            final String deviceFixedIpAddress = ipConfiguration.getString(SubDataAttribute.IP_ADDRESS);
            final String deviceFixedIpNetmask = ipConfiguration.getString(SubDataAttribute.NETMASK);
            final String deviceFixedIpGateway = ipConfiguration.getString(SubDataAttribute.GATEWAY);
            final boolean isDhcpEnabled = ipConfiguration.getBoolean(SubDataAttribute.ENABLE_DHCP).getValue();
            final DeviceFixedIpDto deviceFixedIp = new DeviceFixedIpDto(deviceFixedIpAddress, deviceFixedIpNetmask, deviceFixedIpGateway);
            configuration.setDeviceFixedIp(deviceFixedIp);
            configuration.setDhcpEnabled(isDhcpEnabled);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.IP_ADDRESS, deviceFixedIpAddress);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.NETMASK, deviceFixedIpNetmask);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.GATEWAY, deviceFixedIpGateway);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.ENABLE_DHCP, Boolean.toString(isDhcpEnabled));
            // setting the software configuration values
            configuration.setAstroGateSunRiseOffset((int) astroGateSunRiseOffset);
            configuration.setAstroGateSunSetOffset((int) astroGateSunSetOffset);
            // getting the clock configuration values
            LOGGER.info("Reading the clock configuration values");
            final NodeContainer clock = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), clock.getFcmodelNode());
            final int timeSyncFrequency = clock.getUnsignedShort(SubDataAttribute.TIME_SYNC_FREQUENCY).getValue();
            final boolean automaticSummerTimingEnabled = clock.getBoolean(SubDataAttribute.AUTOMATIC_SUMMER_TIMING_ENABLED).getValue();
            final String summerTimeDetails = clock.getString(SubDataAttribute.SUMMER_TIME_DETAILS);
            final String winterTimeDetails = clock.getString(SubDataAttribute.WINTER_TIME_DETAILS);
            final String ntpHost = clock.getString(SubDataAttribute.NTP_HOST);
            final boolean ntpEnabled = clock.getBoolean(SubDataAttribute.NTP_ENABLED).getValue();
            final int ntpSyncInterval = clock.getUnsignedShort(SubDataAttribute.NTP_SYNC_INTERVAL).getValue();
            configuration.setTimeSyncFrequency(timeSyncFrequency);
            configuration.setAutomaticSummerTimingEnabled(automaticSummerTimingEnabled);
            configuration.setSummerTimeDetails(new DaylightSavingTimeTransition(TIME_ZONE_AMSTERDAM, summerTimeDetails).getDateTimeForNextTransition().toDateTime(DateTimeZone.UTC));
            configuration.setWinterTimeDetails(new DaylightSavingTimeTransition(TIME_ZONE_AMSTERDAM, winterTimeDetails).getDateTimeForNextTransition().toDateTime(DateTimeZone.UTC));
            configuration.setNtpHost(ntpHost);
            configuration.setNtpEnabled(ntpEnabled);
            configuration.setNtpSyncInterval(ntpSyncInterval);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.TIME_SYNC_FREQUENCY, Integer.toString(timeSyncFrequency));
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.AUTOMATIC_SUMMER_TIMING_ENABLED, Boolean.toString(automaticSummerTimingEnabled));
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.SUMMER_TIME_DETAILS, summerTimeDetails);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.WINTER_TIME_DETAILS, winterTimeDetails);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.NTP_HOST, ntpHost);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.NTP_ENABLED, String.valueOf(ntpEnabled));
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.NTP_SYNC_INTERVAL, String.valueOf(ntpSyncInterval));
            Iec61850GetConfigurationCommand.this.loggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            return configuration;
        }
    };
    return iec61850Client.sendCommandWithRetry(function, "GetConfiguration", deviceConnection.getDeviceIdentification());
}
Also used : LinkTypeDto(org.opensmartgridplatform.dto.valueobjects.LinkTypeDto) DaliConfigurationDto(org.opensmartgridplatform.dto.valueobjects.DaliConfigurationDto) LightTypeDto(org.opensmartgridplatform.dto.valueobjects.LightTypeDto) DeviceFixedIpDto(org.opensmartgridplatform.dto.valueobjects.DeviceFixedIpDto) ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.core.db.api.iec61850.entities.DeviceOutputSetting) NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) Function(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Function) DaylightSavingTimeTransition(org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DaylightSavingTimeTransition) DeviceMessageLog(org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) DaliConfigurationDto(org.opensmartgridplatform.dto.valueobjects.DaliConfigurationDto) RelayConfigurationDto(org.opensmartgridplatform.dto.valueobjects.RelayConfigurationDto) ConfigurationDto(org.opensmartgridplatform.dto.valueobjects.ConfigurationDto) RelayMapDto(org.opensmartgridplatform.dto.valueobjects.RelayMapDto) RelayConfigurationDto(org.opensmartgridplatform.dto.valueobjects.RelayConfigurationDto)

Example 3 with LinkTypeDto

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

the class OslpGetConfigurationResponseToConfigurationConverter method convert.

@Override
public ConfigurationDto convert(final Oslp.GetConfigurationResponse source, final Type<? extends ConfigurationDto> destinationType, final MappingContext context) {
    // Convert the required values for the constructor of Configuration.
    final LightTypeDto lightType = this.getLightType(source);
    final DaliConfigurationDto daliConfiguration = this.getDaliConfiguration(source);
    final RelayConfigurationDto relayConfiguration = this.getRelayConfiguration(source);
    final LinkTypeDto preferredLinkType = this.getPreferredLinkType(source);
    final ConfigurationDto configuration = ConfigurationDto.newBuilder().withLightType(lightType).withDaliConfiguration(daliConfiguration).withRelayConfiguration(relayConfiguration).withPreferredLinkType(preferredLinkType).build();
    // Set the optional values using the set() functions.
    configuration.setTimeSyncFrequency(source.getTimeSyncFrequency());
    this.setFixedIpConfiguration(source, configuration);
    configuration.setDhcpEnabled(source.getIsDhcpEnabled());
    configuration.setCommunicationTimeout(source.getCommunicationTimeout());
    configuration.setCommunicationNumberOfRetries(source.getCommunicationNumberOfRetries());
    configuration.setCommunicationPauseTimeBetweenConnectionTrials(source.getCommunicationPauseTimeBetweenConnectionTrials());
    this.setOspgIpAddress(source, configuration);
    this.setOsgpPortNumber(source, configuration);
    configuration.setTestButtonEnabled(source.getIsTestButtonEnabled());
    configuration.setAutomaticSummerTimingEnabled(source.getIsAutomaticSummerTimingEnabled());
    configuration.setAstroGateSunRiseOffset(source.getAstroGateSunRiseOffset() / SECONDS_PER_MINUTE);
    configuration.setAstroGateSunSetOffset(source.getAstroGateSunSetOffset() / SECONDS_PER_MINUTE);
    configuration.setSwitchingDelays(source.getSwitchingDelayList());
    this.setRelayLinking(source, configuration);
    configuration.setRelayRefreshing(source.getRelayRefreshing());
    final DateTime summerTimeDetails = this.convertSummerTimeWinterTimeDetails(source.getSummerTimeDetails());
    configuration.setSummerTimeDetails(summerTimeDetails);
    final DateTime winterTimeDetails = this.convertSummerTimeWinterTimeDetails(source.getWinterTimeDetails());
    configuration.setWinterTimeDetails(winterTimeDetails);
    return configuration;
}
Also used : DaliConfigurationDto(org.opensmartgridplatform.dto.valueobjects.DaliConfigurationDto) LinkTypeDto(org.opensmartgridplatform.dto.valueobjects.LinkTypeDto) LightTypeDto(org.opensmartgridplatform.dto.valueobjects.LightTypeDto) DaliConfigurationDto(org.opensmartgridplatform.dto.valueobjects.DaliConfigurationDto) RelayConfigurationDto(org.opensmartgridplatform.dto.valueobjects.RelayConfigurationDto) ConfigurationDto(org.opensmartgridplatform.dto.valueobjects.ConfigurationDto) RelayConfigurationDto(org.opensmartgridplatform.dto.valueobjects.RelayConfigurationDto) DateTime(org.joda.time.DateTime) MutableDateTime(org.joda.time.MutableDateTime)

Aggregations

LightTypeDto (org.opensmartgridplatform.dto.valueobjects.LightTypeDto)3 LinkTypeDto (org.opensmartgridplatform.dto.valueobjects.LinkTypeDto)3 ConfigurationDto (org.opensmartgridplatform.dto.valueobjects.ConfigurationDto)2 DaliConfigurationDto (org.opensmartgridplatform.dto.valueobjects.DaliConfigurationDto)2 RelayConfigurationDto (org.opensmartgridplatform.dto.valueobjects.RelayConfigurationDto)2 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 MutableDateTime (org.joda.time.MutableDateTime)1 DaylightSavingTimeTransition (org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DaylightSavingTimeTransition)1 DeviceMessageLog (org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)1 Function (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Function)1 NodeContainer (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)1 DeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponse)1 EmptyDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.EmptyDeviceResponse)1 GetConfigurationDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetConfigurationDeviceResponse)1 GetFirmwareVersionDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetFirmwareVersionDeviceResponse)1 GetStatusDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse)1 DeviceOutputSetting (org.opensmartgridplatform.core.db.api.iec61850.entities.DeviceOutputSetting)1 DeviceFixedIpDto (org.opensmartgridplatform.dto.valueobjects.DeviceFixedIpDto)1 DeviceStatusDto (org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto)1