Search in sources :

Example 6 with LogicalNode

use of com.alliander.osgp.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)

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 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)3 ArrayList (java.util.ArrayList)3 BdaBoolean (org.openmuc.openiec61850.BdaBoolean)3 DateTime (org.joda.time.DateTime)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 EventNotificationTypeDto (com.alliander.osgp.dto.valueobjects.EventNotificationTypeDto)1 LightTypeDto (com.alliander.osgp.dto.valueobjects.LightTypeDto)1 LightValueDto (com.alliander.osgp.dto.valueobjects.LightValueDto)1 PowerUsageDataDto (com.alliander.osgp.dto.valueobjects.PowerUsageDataDto)1 RelayDataDto (com.alliander.osgp.dto.valueobjects.RelayDataDto)1 RelayMapDto (com.alliander.osgp.dto.valueobjects.RelayMapDto)1