Search in sources :

Example 6 with ConfigurationDto

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

the class Iec61850SsldDeviceService method setConfiguration.

@Override
public void setConfiguration(final SetConfigurationDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
    DeviceConnection deviceConnection = null;
    try {
        deviceConnection = this.connectToDevice(deviceRequest);
        final ConfigurationDto configuration = deviceRequest.getConfiguration();
        // Ignoring required, unused fields DALI-configuration and
        // preferredLinkType.
        new Iec61850SetConfigurationCommand(this.deviceMessageLoggingService).setConfigurationOnDevice(this.iec61850Client, deviceConnection, configuration);
        this.createSuccessfulDefaultResponse(deviceRequest, deviceResponseHandler);
    } 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 : Iec61850SetConfigurationCommand(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850SetConfigurationCommand) ConfigurationDto(org.opensmartgridplatform.dto.valueobjects.ConfigurationDto) 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)

Example 7 with ConfigurationDto

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

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

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

the class ConfigurationManagementService method setConfiguration.

// === SET CONFIGURATION ===
public void setConfiguration(final CorrelationIds ids, final Configuration configuration, final Long scheduleTime, final String messageType, final int messagePriority) throws FunctionalException {
    LOGGER.debug("setConfiguration called with organisation {} and device {}", ids.getOrganisationIdentification(), ids.getDeviceIdentification());
    this.findOrganisation(ids.getOrganisationIdentification());
    final Device device = this.findActiveDevice(ids.getDeviceIdentification());
    if (configuration == null) {
        LOGGER.info("Configuration is empty, skip sending a request to device");
        return;
    }
    // First, persist the configuration of the device output settings.
    this.updateDeviceOutputSettings(device, configuration);
    // contain a TARIFF_REVERSED enum entry.
    if (configuration.getRelayConfiguration() != null && configuration.getRelayConfiguration().getRelayMap() != null) {
        for (final RelayMap rm : configuration.getRelayConfiguration().getRelayMap()) {
            if (rm.getRelayType().equals(RelayType.TARIFF_REVERSED)) {
                rm.changeRelayType(RelayType.TARIFF);
            }
        }
    }
    final org.opensmartgridplatform.dto.valueobjects.ConfigurationDto configurationDto = this.domainCoreMapper.map(configuration, org.opensmartgridplatform.dto.valueobjects.ConfigurationDto.class);
    this.osgpCoreRequestMessageSender.sendWithScheduledTime(new RequestMessage(ids, configurationDto), messageType, messagePriority, device.getIpAddress(), scheduleTime);
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) RelayMap(org.opensmartgridplatform.domain.core.valueobjects.RelayMap) ConfigurationDto(org.opensmartgridplatform.dto.valueobjects.ConfigurationDto)

Example 10 with ConfigurationDto

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

the class CommonGetConfigurationRequestMessageProcessor method handleGetConfigurationDeviceResponse.

private void handleGetConfigurationDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = null;
    ConfigurationDto configuration = null;
    try {
        final GetConfigurationDeviceResponse response = (GetConfigurationDeviceResponse) deviceResponse;
        this.deviceResponseService.handleDeviceMessageStatus(response.getStatus());
        configuration = response.getConfiguration();
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device configuration", e);
    }
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(MessageMetadataFactory.from(deviceResponse, messageType).builder().withDomain(domain).withDomainVersion(domainVersion).withRetryCount(retryCount).build()).result(result).osgpException(osgpException).dataObject(configuration).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ConfigurationDto(org.opensmartgridplatform.dto.valueobjects.ConfigurationDto) GetConfigurationDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetConfigurationDeviceResponse) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

Aggregations

ConfigurationDto (org.opensmartgridplatform.dto.valueobjects.ConfigurationDto)15 JMSException (javax.jms.JMSException)7 DaliConfigurationDto (org.opensmartgridplatform.dto.valueobjects.DaliConfigurationDto)4 RelayConfigurationDto (org.opensmartgridplatform.dto.valueobjects.RelayConfigurationDto)4 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)4 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)3 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)3 DateTime (org.joda.time.DateTime)2 GetConfigurationDeviceResponse (org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.GetConfigurationDeviceResponse)2 ConnectionFailureException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)2 NodeException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException)2 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)2 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)2 GetConfigurationDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetConfigurationDeviceResponse)2 DeviceFixedIpDto (org.opensmartgridplatform.dto.valueobjects.DeviceFixedIpDto)2 LightTypeDto (org.opensmartgridplatform.dto.valueobjects.LightTypeDto)2 LinkTypeDto (org.opensmartgridplatform.dto.valueobjects.LinkTypeDto)2 Oslp (org.opensmartgridplatform.oslp.Oslp)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)2