Search in sources :

Example 16 with BdaBoolean

use of com.beanit.openiec61850.BdaBoolean in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850GetStatusCommand method getStatusFromDevice.

public DeviceStatusDto getStatusFromDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final Ssld ssld) throws ProtocolAdapterException {
    final Function<DeviceStatusDto> function = new Function<DeviceStatusDto>() {

        @Override
        public DeviceStatusDto apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            // getting the light relay values
            final List<LightValueDto> lightValues = new ArrayList<>();
            for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
                final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(deviceOutputSetting.getInternalId());
                final NodeContainer position = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.POSITION, Fc.ST);
                iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), position.getFcmodelNode());
                final BdaBoolean state = position.getBoolean(SubDataAttribute.STATE);
                final boolean on = state.getValue();
                lightValues.add(new LightValueDto(deviceOutputSetting.getExternalId(), on, null));
                LOGGER.info(String.format("Got status of relay %d => %s", deviceOutputSetting.getInternalId(), on ? "on" : "off"));
                deviceMessageLog.addVariable(logicalNode, DataAttribute.POSITION, Fc.ST, Boolean.toString(on));
            }
            final NodeContainer eventBuffer = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.EVENT_BUFFER, Fc.CF);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), eventBuffer.getFcmodelNode());
            final String filter = eventBuffer.getString(SubDataAttribute.EVENT_BUFFER_FILTER);
            LOGGER.info("Got EvnBuf.enbEvnType filter {}", filter);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.EVENT_BUFFER, Fc.CF, filter);
            final Set<EventNotificationTypeDto> notificationTypes = EventType.getNotificationTypesForFilter(filter);
            int eventNotificationsMask = 0;
            for (final EventNotificationTypeDto notificationType : notificationTypes) {
                eventNotificationsMask |= notificationType.getValue();
            }
            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";
            }
            final LightTypeDto lightType = LightTypeDto.valueOf(lightTypeValue);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, lightTypeValue);
            DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            /*
                 * The preferredLinkType and actualLinkType are hard-coded to
                 * LinkTypeDto.ETHERNET, other link types do not apply to the
                 * device type in use.
                 */
            return new DeviceStatusDto(lightValues, LinkTypeDto.ETHERNET, LinkTypeDto.ETHERNET, lightType, eventNotificationsMask);
        }
    };
    return iec61850Client.sendCommandWithRetry(function, "GetStatus", deviceConnection.getDeviceIdentification());
}
Also used : LightTypeDto(com.alliander.osgp.dto.valueobjects.LightTypeDto) ArrayList(java.util.ArrayList) DeviceOutputSetting(com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting) NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) LogicalNode(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode) LightValueDto(com.alliander.osgp.dto.valueobjects.LightValueDto) Function(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function) DeviceMessageLog(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) DeviceStatusDto(com.alliander.osgp.dto.valueobjects.DeviceStatusDto) BdaBoolean(org.openmuc.openiec61850.BdaBoolean) EventNotificationTypeDto(com.alliander.osgp.dto.valueobjects.EventNotificationTypeDto)

Example 17 with BdaBoolean

use of com.beanit.openiec61850.BdaBoolean in project open-smart-grid-platform by OSGP.

the class Iec61850GetStatusCommand method getStatusFromDevice.

public DeviceStatusDto getStatusFromDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final Ssld ssld) throws ProtocolAdapterException {
    final Function<DeviceStatusDto> function = new Function<DeviceStatusDto>() {

        @Override
        public DeviceStatusDto apply(final DeviceMessageLog deviceMessageLog) throws ProtocolAdapterException {
            // getting the light relay values
            final List<LightValueDto> lightValues = new ArrayList<>();
            for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
                final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(deviceOutputSetting.getInternalId());
                final NodeContainer position = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.POSITION, Fc.ST);
                iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), position.getFcmodelNode());
                final BdaBoolean state = position.getBoolean(SubDataAttribute.STATE);
                final boolean on = state.getValue();
                lightValues.add(new LightValueDto(deviceOutputSetting.getExternalId(), on, null));
                LOGGER.info(String.format("Got status of relay %d => %s", deviceOutputSetting.getInternalId(), on ? "on" : "off"));
                deviceMessageLog.addVariable(logicalNode, DataAttribute.POSITION, Fc.ST, SubDataAttribute.STATE, Boolean.toString(on));
            }
            final NodeContainer eventBuffer = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.EVENT_BUFFER, Fc.CF);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), eventBuffer.getFcmodelNode());
            final String filter = eventBuffer.getString(SubDataAttribute.EVENT_BUFFER_FILTER);
            LOGGER.info("Got EvnBuf.enbEvnType filter {}", filter);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.EVENT_BUFFER, Fc.CF, SubDataAttribute.EVENT_BUFFER_FILTER, filter);
            final Set<EventNotificationTypeDto> notificationTypes = EventType.getNotificationTypesForFilter(filter);
            int eventNotificationsMask = 0;
            for (final EventNotificationTypeDto notificationType : notificationTypes) {
                eventNotificationsMask |= notificationType.getValue();
            }
            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";
            }
            final LightTypeDto lightType = LightTypeDto.valueOf(lightTypeValue);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, SubDataAttribute.LIGHT_TYPE, lightTypeValue);
            Iec61850GetStatusCommand.this.loggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            /*
             * The preferredLinkType and actualLinkType are hard-coded to
             * LinkTypeDto.ETHERNET, other link types do not apply to the
             * device type in use.
             */
            return new DeviceStatusDto(lightValues, LinkTypeDto.ETHERNET, LinkTypeDto.ETHERNET, lightType, eventNotificationsMask);
        }
    };
    return iec61850Client.sendCommandWithRetry(function, "GetStatus", deviceConnection.getDeviceIdentification());
}
Also used : LightTypeDto(org.opensmartgridplatform.dto.valueobjects.LightTypeDto) ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.core.db.api.iec61850.entities.DeviceOutputSetting) NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) LogicalNode(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.LogicalNode) LightValueDto(org.opensmartgridplatform.dto.valueobjects.LightValueDto) Function(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Function) DeviceMessageLog(org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) DeviceStatusDto(org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto) BdaBoolean(com.beanit.openiec61850.BdaBoolean) EventNotificationTypeDto(org.opensmartgridplatform.dto.valueobjects.EventNotificationTypeDto)

Example 18 with BdaBoolean

use of com.beanit.openiec61850.BdaBoolean in project open-smart-grid-platform 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 ProtocolAdapterException {
            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));
            Iec61850TransitionCommand.this.loggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            return null;
        }
    };
    iec61850Client.sendCommandWithRetry(function, "SetTransition", deviceConnection.getDeviceIdentification());
}
Also used : Function(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Function) DeviceMessageLog(org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) TransitionTypeDto(org.opensmartgridplatform.dto.valueobjects.TransitionTypeDto) BdaBoolean(com.beanit.openiec61850.BdaBoolean) NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) DateTime(org.joda.time.DateTime)

Example 19 with BdaBoolean

use of com.beanit.openiec61850.BdaBoolean in project open-smart-grid-platform by OSGP.

the class Iec61850Commands method enableOperationOfRelay.

/**
 * Checks if {@code CfSt.enbOper [CF]} for the given {@code logicalNode} is set to {@code true} on
 * the Lighting device, because this is necessary to be able to operate the relay.
 *
 * <p>If it is {@code false}, switching of the relay is enabled by writing boolean {@code true} to
 * {@code CfSt.enbOper [CF]}.
 */
public static void enableOperationOfRelay(final DeviceConnection deviceConnection, final Iec61850Client iec61850Client, final DeviceMessageLog deviceMessageLog, final LogicalNode logicalNode, final Integer index) throws NodeException {
    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);
        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));
    }
}
Also used : BdaBoolean(com.beanit.openiec61850.BdaBoolean) NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)

Example 20 with BdaBoolean

use of com.beanit.openiec61850.BdaBoolean in project open-smart-grid-platform by OSGP.

the class NodeContainer method writeBoolean.

public void writeBoolean(final SubDataAttribute child, final boolean value) throws NodeWriteException {
    final BdaBoolean bdaBoolean = (BdaBoolean) this.parent.getChild(child.getDescription());
    bdaBoolean.setValue(value);
    this.writeNode(bdaBoolean);
}
Also used : BdaBoolean(com.beanit.openiec61850.BdaBoolean)

Aggregations

BdaBoolean (com.beanit.openiec61850.BdaBoolean)12 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 NodeContainer (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)5 DateTime (org.joda.time.DateTime)4 DeviceMessageLog (org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)4 LogicalNode (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)3 ArrayList (java.util.ArrayList)3 Function (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Function)3 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)2 BdaInt8U (com.beanit.openiec61850.BdaInt8U)2 BdaTimestamp (com.beanit.openiec61850.BdaTimestamp)2 BdaVisibleString (com.beanit.openiec61850.BdaVisibleString)2 LogicalNode (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)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