Search in sources :

Example 16 with DeviceMessageLog

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

the class Iec61850RebootCommand method rebootDevice.

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

        @Override
        public Void apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            final NodeContainer rebootOperationNode = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REBOOT_OPERATION, Fc.CO);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), rebootOperationNode.getFcmodelNode());
            LOGGER.info("device: {}, rebootOperationNode: {}", deviceConnection.getDeviceIdentification(), rebootOperationNode);
            final NodeContainer oper = rebootOperationNode.getChild(SubDataAttribute.OPERATION);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), oper.getFcmodelNode());
            LOGGER.info("device: {}, oper: {}", deviceConnection.getDeviceIdentification(), oper);
            final BdaBoolean ctlVal = oper.getBoolean(SubDataAttribute.CONTROL_VALUE);
            LOGGER.info("device: {}, ctlVal: {}", deviceConnection.getDeviceIdentification(), ctlVal);
            ctlVal.setValue(true);
            LOGGER.info("device: {}, set ctlVal to true in order to reboot the device", deviceConnection.getDeviceIdentification());
            oper.write();
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REBOOT_OPERATION, Fc.ST, SubDataAttribute.OPERATION, SubDataAttribute.CONTROL_VALUE, Boolean.toString(true));
            DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            return null;
        }
    };
    iec61850Client.sendCommandWithRetry(function, "Reboot", 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) BdaBoolean(org.openmuc.openiec61850.BdaBoolean) NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)

Example 17 with DeviceMessageLog

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

the class Iec61850UpdateFirmwareCommand method updateFunctionalFirmware.

private void updateFunctionalFirmware(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final String fullUrl, final DeviceMessageLog deviceMessageLog) throws NodeException {
    LOGGER.info("Reading the functional firmware node for device: {}", deviceConnection.getDeviceIdentification());
    final NodeContainer functionalFirmwareNode = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.FUNCTIONAL_FIRMWARE, Fc.CF);
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), functionalFirmwareNode.getFcmodelNode());
    final String currentFunctionalFirmwareDownloadUrl = functionalFirmwareNode.getString(SubDataAttribute.URL);
    final Date currentFunctionalFirmwareUpdateDateTime = functionalFirmwareNode.getDate(SubDataAttribute.START_TIME);
    LOGGER.info("Current functional firmware download url: {}, start time: {} for device: {}", currentFunctionalFirmwareDownloadUrl, currentFunctionalFirmwareUpdateDateTime, deviceConnection.getDeviceIdentification());
    LOGGER.info("Updating the functional firmware download url to: {} for device: {}", fullUrl, deviceConnection.getDeviceIdentification());
    functionalFirmwareNode.writeString(SubDataAttribute.URL, fullUrl);
    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.FUNCTIONAL_FIRMWARE, Fc.CF, SubDataAttribute.URL, fullUrl);
    final Date oneMinuteFromNow = this.determineFirmwareUpdateDateTime(iec61850Client, deviceConnection);
    LOGGER.info("Updating the functional firmware download start time to: {} for device: {}", oneMinuteFromNow, deviceConnection.getDeviceIdentification());
    functionalFirmwareNode.writeDate(SubDataAttribute.START_TIME, oneMinuteFromNow);
    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.FUNCTIONAL_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 18 with DeviceMessageLog

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

the class Iec61850UpdateSslCertificateCommand method pushSslCertificateToDevice.

public void pushSslCertificateToDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final CertificationDto certification) throws ProtocolAdapterException {
    final Function<Void> function = new Function<Void>() {

        @Override
        public Void apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            LOGGER.info("Reading the certificate authority url");
            final NodeContainer sslConfiguration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CERTIFICATE_AUTHORITY_REPLACE, Fc.CF);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), sslConfiguration.getFcmodelNode());
            // Removing trailing and leading slashes (if present) from the
            // domain and the URL.
            String adjustedDomain = certification.getCertificateDomain();
            if (adjustedDomain.endsWith("/")) {
                adjustedDomain = adjustedDomain.substring(0, adjustedDomain.length() - 1);
            }
            String adjustedUrl = certification.getCertificateUrl();
            if (adjustedUrl.startsWith("/")) {
                adjustedUrl = adjustedUrl.substring(1, adjustedUrl.length());
            }
            final String fullUrl = adjustedDomain.concat("/").concat(adjustedUrl);
            LOGGER.info("Updating the certificate download url to {}", fullUrl);
            sslConfiguration.writeString(SubDataAttribute.URL, fullUrl);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CERTIFICATE_AUTHORITY_REPLACE, Fc.CF, SubDataAttribute.URL, fullUrl);
            final NodeContainer clock = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), clock.getFcmodelNode());
            final DateTime deviceTime = new DateTime(clock.getDate(SubDataAttribute.CURRENT_TIME));
            final Date oneMinuteFromNow = deviceTime.plusMinutes(1).toDate();
            LOGGER.info("Updating the certificate download start time to: {}", oneMinuteFromNow);
            sslConfiguration.writeDate(SubDataAttribute.START_TIME, oneMinuteFromNow);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CERTIFICATE_AUTHORITY_REPLACE, Fc.CF, SubDataAttribute.START_TIME, simpleDateFormat.format(oneMinuteFromNow));
            DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            return null;
        }
    };
    iec61850Client.sendCommandWithRetry(function, "UpdateSslCertificate", 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) NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) DateTime(org.joda.time.DateTime) Date(java.util.Date)

Example 19 with DeviceMessageLog

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

the class Iec61850TransitionCommand method transitionDevice.

public void transitionDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final TransitionMessageDataContainerDto transitionMessageDataContainer) throws ProtocolAdapterException {
    final TransitionTypeDto transitionType = transitionMessageDataContainer.getTransitionType();
    LOGGER.info("device: {}, transition: {}", deviceConnection.getDeviceIdentification(), transitionType);
    final boolean controlValueForTransition = transitionType.equals(TransitionTypeDto.DAY_NIGHT);
    final DateTime dateTime = transitionMessageDataContainer.getDateTime();
    if (dateTime != null) {
        LOGGER.warn("device: {}, setting date/time {} for transition {} not supported", deviceConnection.getDeviceIdentification(), dateTime, transitionType);
    }
    final Function<Void> function = new Function<Void>() {

        @Override
        public Void apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            final NodeContainer sensorNode = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SENSOR, Fc.CO);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), sensorNode.getFcmodelNode());
            LOGGER.info("device: {}, sensorNode: {}", deviceConnection.getDeviceIdentification(), sensorNode);
            final NodeContainer oper = sensorNode.getChild(SubDataAttribute.OPERATION);
            LOGGER.info("device: {}, oper: {}", deviceConnection.getDeviceIdentification(), oper);
            final BdaBoolean ctlVal = oper.getBoolean(SubDataAttribute.CONTROL_VALUE);
            LOGGER.info("device: {}, ctlVal: {}", deviceConnection.getDeviceIdentification(), ctlVal);
            ctlVal.setValue(controlValueForTransition);
            LOGGER.info("device: {}, set ctlVal to {} in order to transition the device", deviceConnection.getDeviceIdentification(), controlValueForTransition);
            oper.write();
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SENSOR, Fc.CO, SubDataAttribute.OPERATION, SubDataAttribute.CONTROL_VALUE, Boolean.toString(controlValueForTransition));
            DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            return null;
        }
    };
    iec61850Client.sendCommandWithRetry(function, "SetTransition", 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) TransitionTypeDto(com.alliander.osgp.dto.valueobjects.TransitionTypeDto) BdaBoolean(org.openmuc.openiec61850.BdaBoolean) NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) DateTime(org.joda.time.DateTime)

Example 20 with DeviceMessageLog

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

the class Iec61850SetEventNotificationFilterCommand method setEventNotificationFilterOnDevice.

public void setEventNotificationFilterOnDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final String filter) throws ProtocolAdapterException {
    final Function<Void> function = new Function<Void>() {

        @Override
        public Void apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            LOGGER.info("Setting the event notification filter");
            final NodeContainer eventBufferConfiguration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.EVENT_BUFFER, Fc.CF);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), eventBufferConfiguration.getFcmodelNode());
            LOGGER.info("Updating the enabled EventType filter to {}", filter);
            eventBufferConfiguration.writeString(SubDataAttribute.EVENT_BUFFER_FILTER, filter);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.EVENT_BUFFER, Fc.CF, SubDataAttribute.EVENT_BUFFER_FILTER, filter);
            DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            return null;
        }
    };
    iec61850Client.sendCommandWithRetry(function, "SetEventNoficationFilter", 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) NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)

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