Search in sources :

Example 6 with LogicalNode

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.LogicalNode in project open-smart-grid-platform by OSGP.

the class Iec61850GetConfigurationCommand method checkRelayType.

private void checkRelayType(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final DeviceOutputSetting deviceOutputSetting, final DeviceMessageLog deviceMessageLog) throws ProtocolAdapterException {
    final RelayType registeredRelayType = deviceOutputSetting.getRelayType();
    final int expectedSwType;
    if (RelayType.LIGHT.equals(registeredRelayType)) {
        expectedSwType = SWITCH_TYPE_LIGHT;
    } else if (RelayType.TARIFF.equals(registeredRelayType) || RelayType.TARIFF_REVERSED.equals(registeredRelayType)) {
        expectedSwType = SWITCH_TYPE_TARIFF;
    } else {
        throw new ProtocolAdapterException("DeviceOutputSetting (internal index = " + deviceOutputSetting.getInternalId() + ", external index = " + deviceOutputSetting.getExternalId() + ") does not have a known RelayType: " + registeredRelayType);
    }
    final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(deviceOutputSetting.getInternalId());
    final NodeContainer switchType = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.SWITCH_TYPE, Fc.ST);
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), switchType.getFcmodelNode());
    final int switchTypeValue = switchType.getByte(SubDataAttribute.STATE).getValue();
    if (expectedSwType != switchTypeValue) {
        throw new ProtocolAdapterException("DeviceOutputSetting (internal index = " + deviceOutputSetting.getInternalId() + ", external index = " + deviceOutputSetting.getExternalId() + ") has a RelayType (" + registeredRelayType + ") that does not match the SwType on the device: " + (switchTypeValue == SWITCH_TYPE_TARIFF ? "Tariff switch (0)" : (switchTypeValue == SWITCH_TYPE_LIGHT ? "Light switch (1)" : "Unknown value: " + switchTypeValue)));
    }
    deviceMessageLog.addVariable(logicalNode, DataAttribute.SWITCH_TYPE, Fc.ST, SubDataAttribute.STATE, Integer.toString(switchTypeValue));
}
Also used : RelayType(org.opensmartgridplatform.core.db.api.iec61850valueobjects.RelayType) NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) LogicalNode(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)

Example 7 with LogicalNode

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.LogicalNode in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850PowerUsageHistoryCommand method getPowerUsageHistoryDataFromRelay.

private List<PowerUsageDataDto> getPowerUsageHistoryDataFromRelay(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final TimePeriodDto timePeriod, final DeviceOutputSetting deviceOutputSetting, final DeviceMessageLog deviceMessageLog) throws NodeReadException {
    final List<PowerUsageDataDto> powerUsageHistoryDataFromRelay = new ArrayList<>();
    final int relayIndex = deviceOutputSetting.getExternalId();
    final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(deviceOutputSetting.getInternalId());
    final NodeContainer onIntervalBuffer = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.SWITCH_ON_INTERVAL_BUFFER, Fc.ST);
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), onIntervalBuffer.getFcmodelNode());
    final Short lastIndex = onIntervalBuffer.getUnsignedByte(SubDataAttribute.LAST_INDEX).getValue();
    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SWITCH_ON_INTERVAL_BUFFER, Fc.ST, SubDataAttribute.LAST_INDEX, lastIndex.toString());
    /*
         * Last index is the last index written in the 60-entry buffer. When the
         * last buffer entry is written, the next entry will be placed at the
         * first position in the buffer (cyclically). To preserve the order of
         * entries written in the response, iteration starts with the next index
         * (oldest entry) and loops from there.
         */
    final int numberOfEntries = 60;
    final int idxOldest = (lastIndex + 1) % numberOfEntries;
    for (int i = 0; i < numberOfEntries; i++) {
        final int bufferIndex = (idxOldest + i) % numberOfEntries;
        final NodeContainer indexedItvNode = onIntervalBuffer.getChild(SubDataAttribute.INTERVAL.getDescription() + (bufferIndex + 1));
        LOGGER.info("device: {}, itv{}: {}", deviceConnection.getDeviceIdentification(), bufferIndex + 1, indexedItvNode);
        final Integer itvNode = indexedItvNode.getInteger(SubDataAttribute.INTERVAL).getValue();
        LOGGER.info("device: {}, itv{}.itv: {}", deviceConnection.getDeviceIdentification(), bufferIndex + 1, itvNode);
        deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SWITCH_ON_INTERVAL_BUFFER, Fc.ST, SubDataAttribute.INTERVAL, SubDataAttribute.INTERVAL, itvNode + "");
        final DateTime date = new DateTime(indexedItvNode.getDate(SubDataAttribute.DAY));
        LOGGER.info("device: {}, itv{}.day: {}", deviceConnection.getDeviceIdentification(), bufferIndex + 1, date);
        deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SWITCH_ON_INTERVAL_BUFFER, Fc.ST, SubDataAttribute.INTERVAL, SubDataAttribute.DAY, itvNode + "");
        final int totalMinutesOnForDate = itvNode;
        final boolean includeEntryInResponse = this.timePeriodContainsDateTime(timePeriod, date, deviceConnection.getDeviceIdentification(), relayIndex, bufferIndex);
        if (!includeEntryInResponse) {
            continue;
        }
        // MeterType.AUX hard-coded (not supported).
        final PowerUsageDataDto powerUsageData = new PowerUsageDataDto(date, MeterTypeDto.AUX, 0, 0);
        final List<RelayDataDto> relayDataList = new ArrayList<>();
        final RelayDataDto relayData = new RelayDataDto(relayIndex, totalMinutesOnForDate);
        relayDataList.add(relayData);
        final SsldDataDto ssldData = new SsldDataDto(0, 0, 0, 0, 0, 0, 0, 0, 0, relayDataList);
        powerUsageData.setSsldData(ssldData);
        powerUsageHistoryDataFromRelay.add(powerUsageData);
    }
    DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
    return powerUsageHistoryDataFromRelay;
}
Also used : ArrayList(java.util.ArrayList) SsldDataDto(com.alliander.osgp.dto.valueobjects.SsldDataDto) NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) PowerUsageDataDto(com.alliander.osgp.dto.valueobjects.PowerUsageDataDto) LogicalNode(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode) DateTime(org.joda.time.DateTime) RelayDataDto(com.alliander.osgp.dto.valueobjects.RelayDataDto)

Example 8 with LogicalNode

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.LogicalNode 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 9 with LogicalNode

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.LogicalNode in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850GetConfigurationCommand method checkRelayType.

private void checkRelayType(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final DeviceOutputSetting deviceOutputSetting, final DeviceMessageLog deviceMessageLog) throws ProtocolAdapterException {
    final RelayType registeredRelayType = deviceOutputSetting.getRelayType();
    final int expectedSwType;
    if (RelayType.LIGHT.equals(registeredRelayType)) {
        expectedSwType = SWITCH_TYPE_LIGHT;
    } else if (RelayType.TARIFF.equals(registeredRelayType) || RelayType.TARIFF_REVERSED.equals(registeredRelayType)) {
        expectedSwType = SWITCH_TYPE_TARIFF;
    } else {
        throw new ProtocolAdapterException("DeviceOutputSetting (internal index = " + deviceOutputSetting.getInternalId() + ", external index = " + deviceOutputSetting.getExternalId() + ") does not have a known RelayType: " + registeredRelayType);
    }
    final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(deviceOutputSetting.getInternalId());
    final NodeContainer switchType = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.SWITCH_TYPE, Fc.ST);
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), switchType.getFcmodelNode());
    final int switchTypeValue = switchType.getByte(SubDataAttribute.STATE).getValue();
    if (expectedSwType != switchTypeValue) {
        throw new ProtocolAdapterException("DeviceOutputSetting (internal index = " + deviceOutputSetting.getInternalId() + ", external index = " + deviceOutputSetting.getExternalId() + ") has a RelayType (" + registeredRelayType + ") that does not match the SwType on the device: " + (switchTypeValue == SWITCH_TYPE_TARIFF ? "Tariff switch (0)" : (switchTypeValue == SWITCH_TYPE_LIGHT ? "Light switch (1)" : "Unknown value: " + switchTypeValue)));
    }
    deviceMessageLog.addVariable(logicalNode, DataAttribute.SWITCH_TYPE, Fc.ST, SubDataAttribute.STATE, Integer.toString(switchTypeValue));
}
Also used : RelayType(com.alliander.osgp.core.db.api.iec61850valueobjects.RelayType) NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) LogicalNode(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)

Example 10 with LogicalNode

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.LogicalNode 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)

Aggregations

LogicalNode (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)6 NodeContainer (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)6 DeviceMessageLog (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)4 Function (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function)4 ArrayList (java.util.ArrayList)4 NodeContainer (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)4 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)3 BdaBoolean (com.beanit.openiec61850.BdaBoolean)3 BdaBoolean (org.openmuc.openiec61850.BdaBoolean)3 LogicalNode (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)3 FcModelNode (com.beanit.openiec61850.FcModelNode)2 ObjectReference (com.beanit.openiec61850.ObjectReference)2 DateTime (org.joda.time.DateTime)2 NodeNotFoundException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeNotFoundException)2 DaylightSavingTimeTransition (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DaylightSavingTimeTransition)1 ScheduleEntry (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.ScheduleEntry)1 DeviceOutputSetting (com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting)1 RelayType (com.alliander.osgp.core.db.api.iec61850valueobjects.RelayType)1 DeviceFixedIpDto (com.alliander.osgp.dto.valueobjects.DeviceFixedIpDto)1 DeviceStatusDto (com.alliander.osgp.dto.valueobjects.DeviceStatusDto)1