Search in sources :

Example 1 with BdaBoolean

use of org.openmuc.openiec61850.BdaBoolean in project Protocol-Adapter-IEC61850 by OSGP.

the class LogicalDevice method setBoolean.

protected BasicDataAttribute setBoolean(final String node, final Fc fc, final boolean b) {
    final BdaBoolean value = (BdaBoolean) this.serverModel.findModelNode(this.createNodeName(node), fc);
    value.setValue(b);
    return value;
}
Also used : BdaBoolean(org.openmuc.openiec61850.BdaBoolean)

Example 2 with BdaBoolean

use of org.openmuc.openiec61850.BdaBoolean in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850SetLightCommand method switchLightRelay.

public Boolean switchLightRelay(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final int index, final boolean on) throws ProtocolAdapterException {
    // Commands don't return anything, so returnType is Void.
    final Function<Boolean> function = new Function<Boolean>() {

        @Override
        public Boolean apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            try {
                final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(index);
                // Check if CfSt.enbOper [CF] is set to true. If it is not
                // set to true, the relay can not be operated.
                final NodeContainer masterControl = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.MASTER_CONTROL, Fc.CF);
                iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), masterControl.getFcmodelNode());
                final BdaBoolean enbOper = masterControl.getBoolean(SubDataAttribute.ENABLE_OPERATION);
                if (enbOper.getValue()) {
                    LOGGER.info("masterControl.enbOper is true, switching of relay {} is enabled", index);
                } else {
                    LOGGER.info("masterControl.enbOper is false, switching of relay {} is disabled", index);
                    // Set the value to true.
                    masterControl.writeBoolean(SubDataAttribute.ENABLE_OPERATION, true);
                    LOGGER.info("set masterControl.enbOper to true to enable switching of relay {}", index);
                    deviceMessageLog.addVariable(logicalNode, DataAttribute.MASTER_CONTROL, Fc.CF, SubDataAttribute.ENABLE_OPERATION, Boolean.toString(true));
                }
                // Switch the relay using Pos.Oper.ctlVal [CO].
                final NodeContainer position = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.POSITION, Fc.CO);
                iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), position.getFcmodelNode());
                final NodeContainer operation = position.getChild(SubDataAttribute.OPERATION);
                final BdaBoolean controlValue = operation.getBoolean(SubDataAttribute.CONTROL_VALUE);
                LOGGER.info(String.format("Switching relay %d %s", index, on ? "on" : "off"));
                controlValue.setValue(on);
                operation.write();
                deviceMessageLog.addVariable(logicalNode, DataAttribute.POSITION, Fc.CO, SubDataAttribute.OPERATION, SubDataAttribute.CONTROL_VALUE, Boolean.toString(on));
                DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
                return true;
            } catch (final Exception e) {
                LOGGER.error("Exception during switchLightRelay()", e);
                return false;
            }
        }
    };
    return iec61850Client.sendCommandWithRetry(function, "SetLight", 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) LogicalNode(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode) BdaBoolean(org.openmuc.openiec61850.BdaBoolean) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)

Example 3 with BdaBoolean

use of org.openmuc.openiec61850.BdaBoolean 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 4 with BdaBoolean

use of org.openmuc.openiec61850.BdaBoolean 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 5 with BdaBoolean

use of org.openmuc.openiec61850.BdaBoolean 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)

Aggregations

BdaBoolean (org.openmuc.openiec61850.BdaBoolean)8 DeviceMessageLog (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)5 Function (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function)5 NodeContainer (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)5 LogicalNode (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)3 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)2 ArrayList (java.util.ArrayList)2 DateTime (org.joda.time.DateTime)2 ScheduleEntry (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.ScheduleEntry)1 DeviceOutputSetting (com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting)1 DeviceStatusDto (com.alliander.osgp.dto.valueobjects.DeviceStatusDto)1 EventNotificationTypeDto (com.alliander.osgp.dto.valueobjects.EventNotificationTypeDto)1 LightTypeDto (com.alliander.osgp.dto.valueobjects.LightTypeDto)1 LightValueDto (com.alliander.osgp.dto.valueobjects.LightValueDto)1 TransitionTypeDto (com.alliander.osgp.dto.valueobjects.TransitionTypeDto)1 FunctionalException (com.alliander.osgp.shared.exceptionhandling.FunctionalException)1 List (java.util.List)1 BdaInt8U (org.openmuc.openiec61850.BdaInt8U)1 BdaTimestamp (org.openmuc.openiec61850.BdaTimestamp)1 BdaVisibleString (org.openmuc.openiec61850.BdaVisibleString)1