Search in sources :

Example 6 with DeviceMessageLog

use of com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850SetScheduleCommand method setScheduleOnDevice.

public void setScheduleOnDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final RelayTypeDto relayType, final List<ScheduleDto> scheduleList, final Ssld ssld, final SsldDataService ssldDataService) throws ProtocolAdapterException {
    final String tariffOrLight = relayType.equals(RelayTypeDto.LIGHT) ? "light" : "tariff";
    try {
        // Creating a list of all Schedule entries, grouped by relay index.
        final Map<Integer, List<ScheduleEntry>> relaySchedulesEntries = this.createScheduleEntries(scheduleList, ssld, relayType, ssldDataService);
        final Function<Void> function = new Function<Void>() {

            @Override
            public Void apply(final DeviceMessageLog deviceMessageLog) throws Exception {
                for (final Integer relayIndex : relaySchedulesEntries.keySet()) {
                    final List<ScheduleEntry> scheduleEntries = relaySchedulesEntries.get(relayIndex);
                    final int numberOfScheduleEntries = scheduleEntries.size();
                    if (numberOfScheduleEntries > MAX_NUMBER_OF_SCHEDULE_ENTRIES) {
                        throw new ProtocolAdapterException("Received " + numberOfScheduleEntries + " " + tariffOrLight + " schedule entries for relay " + relayIndex + " for device " + ssld.getDeviceIdentification() + ". Setting more than " + MAX_NUMBER_OF_SCHEDULE_ENTRIES + " is not possible.");
                    }
                    final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(relayIndex);
                    final NodeContainer schedule = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.SCHEDULE, Fc.CF);
                    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), schedule.getFcmodelNode());
                    // entries.
                    for (int i = 0; i < MAX_NUMBER_OF_SCHEDULE_ENTRIES; i++) {
                        final String scheduleEntryName = SubDataAttribute.SCHEDULE_ENTRY.getDescription() + (i + 1);
                        final NodeContainer scheduleNode = schedule.getChild(scheduleEntryName);
                        final boolean enabled = scheduleNode.getBoolean(SubDataAttribute.SCHEDULE_ENABLE).getValue();
                        LOGGER.info("Checking if schedule entry {} is enabled: {}", i + 1, enabled);
                        if (enabled) {
                            LOGGER.info("Disabling schedule entry {} of {} for relay {} before setting new {} schedule", i + 1, MAX_NUMBER_OF_SCHEDULE_ENTRIES, relayIndex, tariffOrLight);
                            scheduleNode.writeBoolean(SubDataAttribute.SCHEDULE_ENABLE, false);
                            deviceMessageLog.addVariable(logicalNode, DataAttribute.SCHEDULE, Fc.CF, scheduleEntryName, SubDataAttribute.SCHEDULE_ENABLE, Boolean.toString(false));
                        }
                    }
                    for (int i = 0; i < numberOfScheduleEntries; i++) {
                        LOGGER.info("Writing {} schedule entry {} for relay {}", tariffOrLight, i + 1, relayIndex);
                        final ScheduleEntry scheduleEntry = scheduleEntries.get(i);
                        final String scheduleEntryName = SubDataAttribute.SCHEDULE_ENTRY.getDescription() + (i + 1);
                        final NodeContainer scheduleNode = schedule.getChild(scheduleEntryName);
                        final BdaBoolean enabled = scheduleNode.getBoolean(SubDataAttribute.SCHEDULE_ENABLE);
                        if (enabled.getValue() != scheduleEntry.isEnabled()) {
                            scheduleNode.writeBoolean(SubDataAttribute.SCHEDULE_ENABLE, scheduleEntry.isEnabled());
                            deviceMessageLog.addVariable(logicalNode, DataAttribute.SCHEDULE, Fc.CF, scheduleEntryName, SubDataAttribute.SCHEDULE_ENABLE, Boolean.toString(scheduleEntry.isEnabled()));
                        }
                        final Integer day = scheduleNode.getInteger(SubDataAttribute.SCHEDULE_DAY).getValue();
                        if (day != scheduleEntry.getDay()) {
                            scheduleNode.writeInteger(SubDataAttribute.SCHEDULE_DAY, scheduleEntry.getDay());
                            deviceMessageLog.addVariable(logicalNode, DataAttribute.SCHEDULE, Fc.CF, scheduleEntryName, SubDataAttribute.SCHEDULE_DAY, Integer.toString(scheduleEntry.getDay()));
                        }
                        /*
                             * A schedule entry on the platform is about
                             * switching on a certain time, or on a certain
                             * trigger. The schedule entries on the device are
                             * about a period with a time on and a time off. To
                             * bridge these different approaches, either the on
                             * or the off values on the device are set to a
                             * certain default to indicate they are not relevant
                             * to the schedule entry.
                             */
                        int timeOnValue = DEFAULT_SCHEDULE_VALUE;
                        byte timeOnTypeValue = DEFAULT_SCHEDULE_VALUE;
                        int timeOffValue = DEFAULT_SCHEDULE_VALUE;
                        byte timeOffTypeValue = DEFAULT_SCHEDULE_VALUE;
                        if (scheduleEntry.isOn()) {
                            timeOnValue = scheduleEntry.getTime();
                            timeOnTypeValue = (byte) scheduleEntry.getTriggerType().getIndex();
                        } else {
                            timeOffValue = scheduleEntry.getTime();
                            timeOffTypeValue = (byte) scheduleEntry.getTriggerType().getIndex();
                        }
                        final Integer timeOn = scheduleNode.getInteger(SubDataAttribute.SCHEDULE_TIME_ON).getValue();
                        if (timeOn != timeOnValue) {
                            scheduleNode.writeInteger(SubDataAttribute.SCHEDULE_TIME_ON, timeOnValue);
                            deviceMessageLog.addVariable(logicalNode, DataAttribute.SCHEDULE, Fc.CF, scheduleEntryName, SubDataAttribute.SCHEDULE_TIME_ON, Integer.toString(timeOnValue));
                        }
                        final Byte timeOnActionTime = scheduleNode.getByte(SubDataAttribute.SCHEDULE_TIME_ON_TYPE).getValue();
                        if (timeOnActionTime != timeOnTypeValue) {
                            scheduleNode.writeByte(SubDataAttribute.SCHEDULE_TIME_ON_TYPE, timeOnTypeValue);
                            deviceMessageLog.addVariable(logicalNode, DataAttribute.SCHEDULE, Fc.CF, scheduleEntryName, SubDataAttribute.SCHEDULE_TIME_ON_TYPE, Byte.toString(timeOnTypeValue));
                        }
                        final Integer timeOff = scheduleNode.getInteger(SubDataAttribute.SCHEDULE_TIME_OFF).getValue();
                        if (timeOff != timeOffValue) {
                            scheduleNode.writeInteger(SubDataAttribute.SCHEDULE_TIME_OFF, timeOffValue);
                            deviceMessageLog.addVariable(logicalNode, DataAttribute.SCHEDULE, Fc.CF, scheduleEntryName, SubDataAttribute.SCHEDULE_TIME_OFF, Integer.toString(timeOffValue));
                        }
                        final Byte timeOffActionTime = scheduleNode.getByte(SubDataAttribute.SCHEDULE_TIME_OFF_TYPE).getValue();
                        if (timeOffActionTime != timeOffTypeValue) {
                            scheduleNode.writeByte(SubDataAttribute.SCHEDULE_TIME_OFF_TYPE, timeOffTypeValue);
                            deviceMessageLog.addVariable(logicalNode, DataAttribute.SCHEDULE, Fc.CF, scheduleEntryName, SubDataAttribute.SCHEDULE_TIME_OFF_TYPE, Byte.toString(timeOffTypeValue));
                        }
                        final Integer minimumTimeOn = scheduleNode.getUnsignedShort(SubDataAttribute.MINIMUM_TIME_ON).getValue();
                        final Integer newMinimumTimeOn = scheduleEntry.getMinimumLightsOn() / 60;
                        if (minimumTimeOn != newMinimumTimeOn) {
                            scheduleNode.writeUnsignedShort(SubDataAttribute.MINIMUM_TIME_ON, newMinimumTimeOn);
                            deviceMessageLog.addVariable(logicalNode, DataAttribute.SCHEDULE, Fc.CF, scheduleEntryName, SubDataAttribute.MINIMUM_TIME_ON, Integer.toString(newMinimumTimeOn));
                        }
                        final Integer triggerMinutesBefore = scheduleNode.getUnsignedShort(SubDataAttribute.SCHEDULE_TRIGGER_MINUTES_BEFORE).getValue();
                        if (triggerMinutesBefore != scheduleEntry.getTriggerWindowMinutesBefore()) {
                            scheduleNode.writeUnsignedShort(SubDataAttribute.SCHEDULE_TRIGGER_MINUTES_BEFORE, scheduleEntry.getTriggerWindowMinutesBefore());
                            deviceMessageLog.addVariable(logicalNode, DataAttribute.SCHEDULE, Fc.CF, scheduleEntryName, SubDataAttribute.SCHEDULE_TRIGGER_MINUTES_BEFORE, Integer.toString(scheduleEntry.getTriggerWindowMinutesBefore()));
                        }
                        final Integer triggerMinutesAfter = scheduleNode.getUnsignedShort(SubDataAttribute.SCHEDULE_TRIGGER_MINUTES_AFTER).getValue();
                        if (triggerMinutesAfter != scheduleEntry.getTriggerWindowMinutesAfter()) {
                            scheduleNode.writeUnsignedShort(SubDataAttribute.SCHEDULE_TRIGGER_MINUTES_AFTER, scheduleEntry.getTriggerWindowMinutesAfter());
                            deviceMessageLog.addVariable(logicalNode, DataAttribute.SCHEDULE, Fc.CF, scheduleEntryName, SubDataAttribute.SCHEDULE_TRIGGER_MINUTES_AFTER, Integer.toString(scheduleEntry.getTriggerWindowMinutesAfter()));
                        }
                    }
                }
                DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
                return null;
            }
        };
        iec61850Client.sendCommandWithRetry(function, "SetSchedule", deviceConnection.getDeviceIdentification());
    } catch (final FunctionalException e) {
        throw new ProtocolAdapterException(e.getMessage(), e);
    }
}
Also used : NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) LogicalNode(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode) Function(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function) DeviceMessageLog(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) ScheduleEntry(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.ScheduleEntry) BdaBoolean(org.openmuc.openiec61850.BdaBoolean) ArrayList(java.util.ArrayList) List(java.util.List) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) FunctionalException(com.alliander.osgp.shared.exceptionhandling.FunctionalException)

Example 7 with DeviceMessageLog

use of com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850SetConfigurationCommand method setConfigurationOnDevice.

public void setConfigurationOnDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final ConfigurationDto configuration) throws ProtocolAdapterException {
    final Function<Void> function = new Function<Void>() {

        @Override
        public Void apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            if (configuration.getRelayConfiguration() != null && configuration.getRelayConfiguration().getRelayMap() != null) {
                final List<RelayMapDto> relayMaps = configuration.getRelayConfiguration().getRelayMap();
                for (final RelayMapDto relayMap : relayMaps) {
                    final Integer internalIndex = relayMap.getAddress();
                    final RelayTypeDto relayType = relayMap.getRelayType();
                    final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(internalIndex);
                    final NodeContainer switchType = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.SWITCH_TYPE, Fc.CO);
                    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), switchType.getFcmodelNode());
                    final NodeContainer operation = switchType.getChild(SubDataAttribute.OPERATION);
                    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), operation.getFcmodelNode());
                    final BdaInt8 ctlVal = operation.getByte(SubDataAttribute.CONTROL_VALUE);
                    final byte switchTypeValue = (byte) (RelayTypeDto.LIGHT.equals(relayType) ? SWITCH_TYPE_LIGHT : SWITCH_TYPE_TARIFF);
                    LOGGER.info("Updating Switch for internal index {} to {} ({})", internalIndex, switchTypeValue, relayType);
                    ctlVal.setValue(switchTypeValue);
                    operation.write();
                    deviceMessageLog.addVariable(logicalNode, DataAttribute.SWITCH_TYPE, Fc.CO, SubDataAttribute.OPERATION, SubDataAttribute.CONTROL_VALUE, Byte.toString(switchTypeValue));
                }
            }
            // don't read the values for no reason.
            if (!(configuration.getOsgpIpAddres() == null && configuration.getOsgpPortNumber() == null)) {
                final NodeContainer registration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REGISTRATION, Fc.CF);
                iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), registration.getFcmodelNode());
                if (configuration.getOsgpIpAddres() != null) {
                    LOGGER.info("Updating OspgIpAddress to {}", configuration.getOsgpIpAddres());
                    registration.writeString(SubDataAttribute.SERVER_ADDRESS, configuration.getOsgpIpAddres());
                    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REGISTRATION, Fc.CF, SubDataAttribute.SERVER_ADDRESS, configuration.getOsgpIpAddres());
                }
                if (configuration.getOsgpPortNumber() != null) {
                    LOGGER.info("Updating OsgpPortNumber to {}", configuration.getOsgpPortNumber());
                    registration.writeInteger(SubDataAttribute.SERVER_PORT, configuration.getOsgpPortNumber());
                    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REGISTRATION, Fc.CF, SubDataAttribute.SERVER_PORT, configuration.getOsgpPortNumber().toString());
                }
            }
            // that we don't read the values for no reason.
            if (!(configuration.getAstroGateSunRiseOffset() == null && configuration.getAstroGateSunSetOffset() == null && configuration.getLightType() == null)) {
                final NodeContainer softwareConfiguration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF);
                iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), softwareConfiguration.getFcmodelNode());
                if (configuration.getAstroGateSunRiseOffset() != null) {
                    LOGGER.info("Updating AstroGateSunRiseOffset to {}", configuration.getAstroGateSunRiseOffset());
                    softwareConfiguration.writeShort(SubDataAttribute.ASTRONOMIC_SUNRISE_OFFSET, configuration.getAstroGateSunRiseOffset().shortValue());
                    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, SubDataAttribute.ASTRONOMIC_SUNRISE_OFFSET, Short.toString(configuration.getAstroGateSunRiseOffset().shortValue()));
                }
                if (configuration.getAstroGateSunSetOffset() != null) {
                    LOGGER.info("Updating AstroGateSunSetOffset to {}", configuration.getAstroGateSunSetOffset());
                    softwareConfiguration.writeShort(SubDataAttribute.ASTRONOMIC_SUNSET_OFFSET, configuration.getAstroGateSunSetOffset().shortValue());
                    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, SubDataAttribute.ASTRONOMIC_SUNSET_OFFSET, Short.toString(configuration.getAstroGateSunSetOffset().shortValue()));
                }
                if (configuration.getLightType() != null) {
                    LOGGER.info("Updating LightType to {}", configuration.getLightType());
                    softwareConfiguration.writeString(SubDataAttribute.LIGHT_TYPE, configuration.getLightType().name());
                    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, SubDataAttribute.LIGHT_TYPE, configuration.getLightType().name());
                }
            }
            // don't read the values for no reason.
            if (!(configuration.getTimeSyncFrequency() == null && configuration.isAutomaticSummerTimingEnabled() == null && configuration.getSummerTimeDetails() == null && configuration.getWinterTimeDetails() == null)) {
                final NodeContainer clock = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF);
                iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), clock.getFcmodelNode());
                if (configuration.getTimeSyncFrequency() != null) {
                    LOGGER.info("Updating TimeSyncFrequency to {}", configuration.getTimeSyncFrequency());
                    clock.writeUnsignedShort(SubDataAttribute.TIME_SYNC_FREQUENCY, configuration.getTimeSyncFrequency());
                    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.TIME_SYNC_FREQUENCY, Integer.toString(configuration.getTimeSyncFrequency()));
                }
                if (configuration.isAutomaticSummerTimingEnabled() != null) {
                    LOGGER.info("Updating AutomaticSummerTimingEnabled to {}", configuration.isAutomaticSummerTimingEnabled());
                    clock.writeBoolean(SubDataAttribute.AUTOMATIC_SUMMER_TIMING_ENABLED, configuration.isAutomaticSummerTimingEnabled());
                    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.AUTOMATIC_SUMMER_TIMING_ENABLED, Boolean.toString(configuration.isAutomaticSummerTimingEnabled()));
                }
                /*
                     * Perform some effort to create dstBegT/dstEndt information
                     * based on provided DateTime values. This will work in a
                     * number of cases, but to be able to do this accurately in
                     * an international context, DST transition times will
                     * probably have to be based on information about the
                     * time-zone the device is operating in, instead of a
                     * particular DateTime provided by the caller without
                     * further information.
                     */
                final DaylightSavingTimeTransition.DstTransitionFormat dstFormatMwd = DaylightSavingTimeTransition.DstTransitionFormat.DAY_OF_WEEK_OF_MONTH;
                final DateTime summerTimeDetails = configuration.getSummerTimeDetails();
                final DateTime winterTimeDetails = configuration.getWinterTimeDetails();
                if (summerTimeDetails != null) {
                    final String mwdValueForBeginOfDst = DaylightSavingTimeTransition.forDateTimeAccordingToFormat(summerTimeDetails, dstFormatMwd).getTransition();
                    LOGGER.info("Updating DstBeginTime to {} based on SummerTimeDetails {}", mwdValueForBeginOfDst, summerTimeDetails);
                    clock.writeString(SubDataAttribute.SUMMER_TIME_DETAILS, mwdValueForBeginOfDst);
                    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.SUMMER_TIME_DETAILS, mwdValueForBeginOfDst);
                }
                if (winterTimeDetails != null) {
                    final String mwdValueForEndOfDst = DaylightSavingTimeTransition.forDateTimeAccordingToFormat(winterTimeDetails, dstFormatMwd).getTransition();
                    LOGGER.info("Updating DstEndTime to {} based on WinterTimeDetails {}", mwdValueForEndOfDst, winterTimeDetails);
                    clock.writeString(SubDataAttribute.WINTER_TIME_DETAILS, mwdValueForEndOfDst);
                    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.WINTER_TIME_DETAILS, mwdValueForEndOfDst);
                }
            }
            // don't read the values for no reason.
            if (!(configuration.isDhcpEnabled() == null && configuration.getDeviceFixedIp() == null)) {
                final NodeContainer ipConfiguration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF);
                iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), ipConfiguration.getFcmodelNode());
                if (configuration.isDhcpEnabled() != null) {
                    LOGGER.info("Updating DhcpEnabled to {}", configuration.isDhcpEnabled());
                    ipConfiguration.writeBoolean(SubDataAttribute.ENABLE_DHCP, configuration.isDhcpEnabled());
                    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.ENABLE_DHCP, Boolean.toString(configuration.isDhcpEnabled()));
                }
                // All values in DeviceFixedIpDto are non-nullable, so no
                // null-checks are needed.
                final DeviceFixedIpDto deviceFixedIp = configuration.getDeviceFixedIp();
                LOGGER.info("Updating deviceFixedIpAddress to {}", configuration.getDeviceFixedIp().getIpAddress());
                ipConfiguration.writeString(SubDataAttribute.IP_ADDRESS, deviceFixedIp.getIpAddress());
                deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.IP_ADDRESS, deviceFixedIp.getIpAddress());
                LOGGER.info("Updating deviceFixedIpNetmask to {}", configuration.getDeviceFixedIp().getNetMask());
                ipConfiguration.writeString(SubDataAttribute.NETMASK, deviceFixedIp.getNetMask());
                deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.NETMASK, deviceFixedIp.getNetMask());
                LOGGER.info("Updating deviceFixIpGateway to {}", configuration.getDeviceFixedIp().getGateWay());
                ipConfiguration.writeString(SubDataAttribute.GATEWAY, deviceFixedIp.getGateWay());
                deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.GATEWAY, deviceFixedIp.getGateWay());
            }
            // Checking to see if all TLS values are null, so that we
            // don't read the values for no reason.
            // if (!(configuration.getCommonNameString() == null &&
            // configuration.isTlsEnabled() == null && configuration
            // .getTlsPortNumber() == null)) {
            //
            // final NodeContainer tls =
            // deviceConnection.getFcModelNode(LogicalDevice.LIGHTING,
            // LogicalNode.STREET_LIGHT_CONFIGURATION,
            // DataAttribute.TLS_CONFIGURATION, Fc.CF);
            // iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(),
            // tls.getFcmodelNode());
            //
            // if (configuration.getTlsPortNumber() != null) {
            // LOGGER.info("Updating tlsPortNumber to {}",
            // configuration.getTlsPortNumber());
            // tls.writeUnsignedInteger(SubDataAttribute.TLS_PORT_NUMBER,
            // configuration.getTlsPortNumber());
            // }
            //
            // if (configuration.isTlsEnabled() != null) {
            // LOGGER.info("Updating tlsEnabled to {}",
            // configuration.isTlsEnabled());
            // tls.writeBoolean(SubDataAttribute.TLS_ENABLED,
            // configuration.isTlsEnabled());
            // }
            //
            // if (configuration.getCommonNameString() != null) {
            // LOGGER.info("Updating commonNameString to {}",
            // configuration.getCommonNameString());
            // tls.writeString(SubDataAttribute.TLS_COMMON_NAME,
            // configuration.getCommonNameString());
            // }
            // }
            DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            return null;
        }
    };
    iec61850Client.sendCommandWithRetry(function, "SetConfiguration", deviceConnection.getDeviceIdentification());
}
Also used : DeviceFixedIpDto(com.alliander.osgp.dto.valueobjects.DeviceFixedIpDto) NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) RelayTypeDto(com.alliander.osgp.dto.valueobjects.RelayTypeDto) LogicalNode(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode) DateTime(org.joda.time.DateTime) Function(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function) BdaInt8(org.openmuc.openiec61850.BdaInt8) DaylightSavingTimeTransition(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DaylightSavingTimeTransition) DeviceMessageLog(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) RelayMapDto(com.alliander.osgp.dto.valueobjects.RelayMapDto)

Example 8 with DeviceMessageLog

use of com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850UpdateFirmwareCommand method updateSecurityFirmware.

private void updateSecurityFirmware(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final String fullUrl, final DeviceMessageLog deviceMessageLog) throws NodeException {
    LOGGER.info("Reading the security firmware node for device: {}", deviceConnection.getDeviceIdentification());
    final NodeContainer securityFirmwareNode = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SECURITY_FIRMWARE, Fc.CF);
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), securityFirmwareNode.getFcmodelNode());
    final String currentSecurityFirmwareDownloadUrl = securityFirmwareNode.getString(SubDataAttribute.URL);
    final Date currentSecurityFirmwareUpdateDateTime = securityFirmwareNode.getDate(SubDataAttribute.START_TIME);
    LOGGER.info("Current security firmware download url: {}, start time: {} for device: {}", currentSecurityFirmwareDownloadUrl, currentSecurityFirmwareUpdateDateTime, deviceConnection.getDeviceIdentification());
    LOGGER.info("Updating the security firmware download url to : {} for device: {}", fullUrl, deviceConnection.getDeviceIdentification());
    securityFirmwareNode.writeString(SubDataAttribute.URL, fullUrl);
    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SECURITY_FIRMWARE, Fc.CF, SubDataAttribute.URL, fullUrl);
    final Date oneMinuteFromNow = this.determineFirmwareUpdateDateTime(iec61850Client, deviceConnection);
    LOGGER.info("Updating the security firmware download start time to: {} for device: {}", oneMinuteFromNow, deviceConnection.getDeviceIdentification());
    securityFirmwareNode.writeDate(SubDataAttribute.START_TIME, oneMinuteFromNow);
    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SECURITY_FIRMWARE, Fc.CF, SubDataAttribute.START_TIME, simpleDateFormat.format(oneMinuteFromNow));
}
Also used : NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) Date(java.util.Date)

Example 9 with DeviceMessageLog

use of com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850UpdateFirmwareCommand method pushFirmwareToDevice.

public void pushFirmwareToDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final String fullUrl, final FirmwareModuleData firmwareModuleData) throws ProtocolAdapterException {
    final Function<Void> function = new Function<Void>() {

        @Override
        public Void apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            final int count = firmwareModuleData.countNumberOfModules();
            if (count != 1) {
                throw new ProtocolAdapterException(String.format("Number of firmware modules is not equal to 1 but %d", count));
            }
            // updated.
            if (FirmwareModuleType.FUNCTIONAL.name().equalsIgnoreCase(firmwareModuleData.getModuleVersionFunc())) {
                Iec61850UpdateFirmwareCommand.this.updateFunctionalFirmware(iec61850Client, deviceConnection, fullUrl, deviceMessageLog);
            } else if (FirmwareModuleType.SECURITY.name().equalsIgnoreCase(firmwareModuleData.getModuleVersionSec())) {
                Iec61850UpdateFirmwareCommand.this.updateSecurityFirmware(iec61850Client, deviceConnection, fullUrl, deviceMessageLog);
            } else {
                throw new ProtocolAdapterException(String.format("Unsupported firmwareModuleData (only functional and security are allowed): communication: %s, functional: %s, module-active: %s, m-bus: %s, security: %s, fullUrl: %s", firmwareModuleData.getModuleVersionComm(), firmwareModuleData.getModuleVersionFunc(), firmwareModuleData.getModuleVersionMa(), firmwareModuleData.getModuleVersionMbus(), firmwareModuleData.getModuleVersionSec(), fullUrl));
            }
            DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            return null;
        }
    };
    iec61850Client.sendCommandWithRetry(function, "UpdateFirmware", deviceConnection.getDeviceIdentification());
}
Also used : Function(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function) DeviceMessageLog(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)

Example 10 with DeviceMessageLog

use of com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog in project Protocol-Adapter-IEC61850 by OSGP.

the class DeviceMessageLoggingService method logMessage.

public static void logMessage(final DeviceMessageLog deviceMessageLog, final String deviceIdentification, final String organisationIdentification, final boolean incoming) {
    final Iec61850LogItemRequestMessage iec61850LogItemRequestMessage = new Iec61850LogItemRequestMessage(deviceIdentification, organisationIdentification, incoming, true, deviceMessageLog.getMessage(), 0);
    LOGGER.info("Sending iec61850LogItemRequestMessage for device: {}", deviceIdentification);
    iec61850LogItemRequestMessageSender.send(iec61850LogItemRequestMessage);
}
Also used : Iec61850LogItemRequestMessage(com.alliander.osgp.adapter.protocol.iec61850.infra.messaging.Iec61850LogItemRequestMessage)

Aggregations

DeviceMessageLog (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)16 Function (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function)15 NodeContainer (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)14 ArrayList (java.util.ArrayList)7 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)6 LogicalNode (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)6 BdaBoolean (org.openmuc.openiec61850.BdaBoolean)5 DateTime (org.joda.time.DateTime)4 DeviceOutputSetting (com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting)3 Date (java.util.Date)3 List (java.util.List)3 DaylightSavingTimeTransition (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DaylightSavingTimeTransition)2 ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)2 NodeReadException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeReadException)2 NodeWriteException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException)2 SystemService (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.SystemService)2 Iec61850RtuDeviceReportingService (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850RtuDeviceReportingService)2 DeviceFixedIpDto (com.alliander.osgp.dto.valueobjects.DeviceFixedIpDto)2 LightTypeDto (com.alliander.osgp.dto.valueobjects.LightTypeDto)2 PowerUsageDataDto (com.alliander.osgp.dto.valueobjects.PowerUsageDataDto)2