Search in sources :

Example 1 with DeviceConnection

use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850DisableRegistrationCommand method disableRegistration.

public void disableRegistration(final DeviceConnection deviceConnection) throws NodeWriteException {
    final NodeContainer deviceRegistration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REGISTRATION, Fc.CF);
    deviceRegistration.writeBoolean(SubDataAttribute.DEVICE_REGISTRATION_ENABLED, false);
    LOGGER.info("Registration disabled for device: {}", deviceConnection.getDeviceIdentification());
}
Also used : NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)

Example 2 with DeviceConnection

use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850EnableReportingCommand method enableReportingOnDevice.

/**
     * Enable reporting so the device can send reports.
     *
     * @throws NodeException
     *             In case writing or reading of data-attributes fails.
     */
public void enableReportingOnDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection) throws NodeException {
    final NodeContainer reporting = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.LOGICAL_NODE_ZERO, DataAttribute.REPORTING, Fc.BR);
    // Only reading the sequence number for the report node, as the report
    // node is not fully described by the ServerModel when using an ICD
    // file. Since the report node differs from the ServerModel, a full read
    // of the node and all data-attributes will fail. Therefore, only the
    // needed data-attributes are read.
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), (FcModelNode) reporting.getFcmodelNode().getChild(SubDataAttribute.SEQUENCE_NUMBER.getDescription()));
    final Iec61850ClientBaseEventListener reportListener = deviceConnection.getConnection().getIec61850ClientAssociation().getReportListener();
    final short sqNum = reporting.getUnsignedByte(SubDataAttribute.SEQUENCE_NUMBER).getValue();
    reportListener.setSqNum(sqNum);
    reporting.writeBoolean(SubDataAttribute.ENABLE_REPORTING, true);
    LOGGER.info("Allowing device {} to send reports containing events", deviceConnection.getDeviceIdentification());
}
Also used : NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) Iec61850ClientBaseEventListener(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener)

Example 3 with DeviceConnection

use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850EnableReportingCommand method enableReportingOnDeviceWithoutUsingSequenceNumber.

/**
     * Enable reporting so the device can send reports. This version of the
     * function does not use the 'sequence number' to filter incoming reports.
     * When using the {@link Iec61850ClearReportCommand} the 'sequence number'
     * will always be reset to 0.
     *
     * @throws NodeWriteException
     *             In case writing of data-attributes fails.
     */
public void enableReportingOnDeviceWithoutUsingSequenceNumber(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection) throws NodeWriteException {
    final NodeContainer reporting = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.LOGICAL_NODE_ZERO, DataAttribute.REPORTING, Fc.BR);
    final Iec61850ClientBaseEventListener reportListener = deviceConnection.getConnection().getIec61850ClientAssociation().getReportListener();
    reportListener.setSqNum(0);
    reporting.writeBoolean(SubDataAttribute.ENABLE_REPORTING, true);
    LOGGER.info("Allowing device {} to send reports containing events", deviceConnection.getDeviceIdentification());
}
Also used : NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) Iec61850ClientBaseEventListener(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener)

Example 4 with DeviceConnection

use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 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 Exception {
            // Keeping the hardcoded values and values that aren't fetched
            // from the device out of the Function.
            // Hardcoded (not supported)
            final MeterTypeDto meterType = MeterTypeDto.AUX;
            // Hardcoded (not supported)
            final Integer shortTermHistoryIntervalMinutes = 15;
            // Hardcoded (not supported)
            final LinkTypeDto preferredLinkType = LinkTypeDto.ETHERNET;
            // Hardcoded (not supported)
            final Integer longTermHistoryInterval = 1;
            // Hardcoded (not supported)
            final LongTermIntervalTypeDto longTermHistoryIntervalType = LongTermIntervalTypeDto.DAYS;
            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));
            }
            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 = new ConfigurationDto(lightType, daliConfiguration, relayConfiguration, shortTermHistoryIntervalMinutes, preferredLinkType, meterType, longTermHistoryInterval, longTermHistoryIntervalType);
            // 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);
            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));
            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);
            // getting the TLS configuration values
            // LOGGER.info("Reading the TLS configuration values");
            // final NodeContainer tls =
            // deviceConnection.getFcModelNode(LogicalDevice.LIGHTING,
            // LogicalNode.STREET_LIGHT_CONFIGURATION,
            // DataAttribute.TLS_CONFIGURATION, Fc.CF);
            //
            // iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(),
            // tls.getFcmodelNode());
            //
            // final int tlsPortNumber = (int)
            // tls.getUnsignedInteger(SubDataAttribute.TLS_PORT_NUMBER).getValue();
            // final boolean tlsEnabled =
            // tls.getBoolean(SubDataAttribute.TLS_ENABLED).getValue();
            // final String commonName =
            // tls.getString(SubDataAttribute.TLS_COMMON_NAME);
            //
            // configuration.setTlsPortNumber(tlsPortNumber);
            // configuration.setTlsEnabled(tlsEnabled);
            // configuration.setCommonNameString(commonName);
            DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            return configuration;
        }
    };
    return iec61850Client.sendCommandWithRetry(function, "GetConfiguration", deviceConnection.getDeviceIdentification());
}
Also used : LinkTypeDto(com.alliander.osgp.dto.valueobjects.LinkTypeDto) DaliConfigurationDto(com.alliander.osgp.dto.valueobjects.DaliConfigurationDto) LightTypeDto(com.alliander.osgp.dto.valueobjects.LightTypeDto) DeviceFixedIpDto(com.alliander.osgp.dto.valueobjects.DeviceFixedIpDto) ArrayList(java.util.ArrayList) MeterTypeDto(com.alliander.osgp.dto.valueobjects.MeterTypeDto) DeviceOutputSetting(com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting) NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) LongTermIntervalTypeDto(com.alliander.osgp.dto.valueobjects.LongTermIntervalTypeDto) Function(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function) DaylightSavingTimeTransition(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DaylightSavingTimeTransition) DeviceMessageLog(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) ConfigurationDto(com.alliander.osgp.dto.valueobjects.ConfigurationDto) DaliConfigurationDto(com.alliander.osgp.dto.valueobjects.DaliConfigurationDto) RelayConfigurationDto(com.alliander.osgp.dto.valueobjects.RelayConfigurationDto) RelayMapDto(com.alliander.osgp.dto.valueobjects.RelayMapDto) RelayConfigurationDto(com.alliander.osgp.dto.valueobjects.RelayConfigurationDto)

Example 5 with DeviceConnection

use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 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, meterType,
        // shortTermHistoryIntervalMinutes, preferredLinkType,
        // longTermHistoryInterval and longTermHistoryIntervalType.
        new Iec61850SetConfigurationCommand().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(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850SetConfigurationCommand) ConfigurationDto(com.alliander.osgp.dto.valueobjects.ConfigurationDto) ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) NodeWriteException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException) FunctionalException(com.alliander.osgp.shared.exceptionhandling.FunctionalException) JMSException(javax.jms.JMSException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException)

Aggregations

NodeContainer (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)55 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)22 DeviceConnection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)18 ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)17 NodeWriteException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException)17 JMSException (javax.jms.JMSException)16 DeviceMessageLog (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)15 Function (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function)15 FunctionalException (com.alliander.osgp.shared.exceptionhandling.FunctionalException)14 TechnicalException (com.alliander.osgp.shared.exceptionhandling.TechnicalException)13 ArrayList (java.util.ArrayList)8 Ssld (com.alliander.osgp.core.db.api.iec61850.entities.Ssld)7 LogicalNode (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)6 DeviceOutputSetting (com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting)6 DateTime (org.joda.time.DateTime)6 BdaBoolean (org.openmuc.openiec61850.BdaBoolean)5 Iec61850ClientAssociation (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation)4 Iec61850Connection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850Connection)4 ClientAssociation (org.openmuc.openiec61850.ClientAssociation)4 ServerModel (org.openmuc.openiec61850.ServerModel)4