Search in sources :

Example 11 with DeviceMessageLog

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

the class DeviceRegistrationService method disableRegistration.

/**
     * After the device has registered with the platform successfully, the
     * device has to be informed that the registration worked. Disable an
     * attribute so the device will stop attempting to register once a minute.
     *
     * @param deviceIdentification
     *            The device identification.
     * @param ipAddress
     *            The IP address of the device.
     * @param ied
     *            The type of IED.
     * @param serverName
     *            The server name.
     *
     * @throws ProtocolAdapterException
     *             In case the connection to the device can not be established
     *             or the connection breaks during communication.
     */
public void disableRegistration(final String deviceIdentification, final InetAddress ipAddress, final IED ied, final String serverName) throws ProtocolAdapterException {
    final DeviceConnection deviceConnection = this.iec61850DeviceConnectionService.connectWithoutConnectionCaching(ipAddress.getHostAddress(), deviceIdentification, "", ied, serverName, LogicalDevice.LIGHTING.getDescription());
    final Function<Void> function = new Function<Void>() {

        @Override
        public Void apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            DeviceRegistrationService.this.disableRegistration(deviceConnection);
            DeviceRegistrationService.this.setLocationInformation(deviceConnection);
            if (DeviceRegistrationService.this.isReportingAfterDeviceRegistrationEnabled) {
                LOGGER.info("Reporting enabled for device: {}", deviceConnection.getDeviceIdentification());
                DeviceRegistrationService.this.enableReporting(deviceConnection);
            } else {
                LOGGER.info("Reporting disabled for device: {}", deviceIdentification);
                DeviceRegistrationService.this.iec61850DeviceConnectionService.disconnect(deviceConnection, null);
            }
            return null;
        }
    };
    this.iec61850DeviceConnectionService.sendCommandWithRetry(function, deviceIdentification);
}
Also used : Function(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function) DeviceMessageLog(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) DeviceConnection(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)

Example 12 with DeviceMessageLog

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

the class Iec61850RtuDeviceService method handleGetData.

// ========================
// PRIVATE HELPER METHODS =
// ========================
private GetDataResponseDto handleGetData(final DeviceConnection connection, final GetDataDeviceRequest deviceRequest) throws ProtocolAdapterException {
    final GetDataRequestDto requestedData = deviceRequest.getDataRequest();
    final String serverName = this.getServerName(deviceRequest);
    final Function<GetDataResponseDto> function = new Function<GetDataResponseDto>() {

        @Override
        public GetDataResponseDto apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            final Iec61850RtuDeviceReportingService reportingService = new Iec61850RtuDeviceReportingService(serverName);
            reportingService.enableReportingOnDevice(connection, deviceRequest.getDeviceIdentification());
            final List<GetDataSystemIdentifierDto> identifiers = new ArrayList<>();
            for (final SystemFilterDto systemFilter : requestedData.getSystemFilters()) {
                final SystemService systemService = Iec61850RtuDeviceService.this.systemServiceFactory.getSystemService(systemFilter);
                final GetDataSystemIdentifierDto getDataSystemIdentifier = systemService.getData(systemFilter, Iec61850RtuDeviceService.this.iec61850Client, connection);
                identifiers.add(getDataSystemIdentifier);
            }
            return new GetDataResponseDto(identifiers, null);
        }
    };
    return this.iec61850Client.sendCommandWithRetry(function, deviceRequest.getDeviceIdentification());
}
Also used : Function(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function) GetDataRequestDto(com.alliander.osgp.dto.valueobjects.microgrids.GetDataRequestDto) DeviceMessageLog(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) SystemFilterDto(com.alliander.osgp.dto.valueobjects.microgrids.SystemFilterDto) SystemService(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.SystemService) GetDataResponseDto(com.alliander.osgp.dto.valueobjects.microgrids.GetDataResponseDto) GetDataSystemIdentifierDto(com.alliander.osgp.dto.valueobjects.microgrids.GetDataSystemIdentifierDto) Iec61850RtuDeviceReportingService(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850RtuDeviceReportingService) ArrayList(java.util.ArrayList)

Example 13 with DeviceMessageLog

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

the class Iec61850RtuDeviceService method handleSetData.

private void handleSetData(final DeviceConnection connection, final SetDataDeviceRequest deviceRequest) throws ProtocolAdapterException {
    final SetDataRequestDto setDataRequest = deviceRequest.getSetDataRequest();
    final String serverName = this.getServerName(deviceRequest);
    final Function<Void> function = new Function<Void>() {

        @Override
        public Void apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            final Iec61850RtuDeviceReportingService reportingService = new Iec61850RtuDeviceReportingService(serverName);
            reportingService.enableReportingOnDevice(connection, deviceRequest.getDeviceIdentification());
            for (final SetDataSystemIdentifierDto identifier : setDataRequest.getSetDataSystemIdentifiers()) {
                final SystemService systemService = Iec61850RtuDeviceService.this.systemServiceFactory.getSystemService(identifier.getSystemType());
                systemService.setData(identifier, Iec61850RtuDeviceService.this.iec61850Client, connection);
            }
            return null;
        }
    };
    this.iec61850Client.sendCommandWithRetry(function, deviceRequest.getDeviceIdentification());
}
Also used : Function(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function) DeviceMessageLog(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) SystemService(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.SystemService) SetDataRequestDto(com.alliander.osgp.dto.valueobjects.microgrids.SetDataRequestDto) Iec61850RtuDeviceReportingService(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850RtuDeviceReportingService) SetDataSystemIdentifierDto(com.alliander.osgp.dto.valueobjects.microgrids.SetDataSystemIdentifierDto)

Example 14 with DeviceMessageLog

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

the class Iec61850PowerUsageHistoryCommand method getPowerUsageHistoryDataFromDevice.

public List<PowerUsageDataDto> getPowerUsageHistoryDataFromDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final PowerUsageHistoryMessageDataContainerDto powerUsageHistoryContainer, final List<DeviceOutputSetting> deviceOutputSettingsLightRelays) throws ProtocolAdapterException {
    final Function<List<PowerUsageDataDto>> function = new Function<List<PowerUsageDataDto>>() {

        @Override
        public List<PowerUsageDataDto> apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            final HistoryTermTypeDto historyTermType = powerUsageHistoryContainer.getHistoryTermType();
            if (historyTermType != null) {
                LOGGER.info("device: {}, ignoring HistoryTermType ({}) determining power usage history", deviceConnection.getDeviceIdentification(), historyTermType);
            }
            final TimePeriodDto timePeriod = powerUsageHistoryContainer.getTimePeriod();
            final List<PowerUsageDataDto> powerUsageHistoryData = new ArrayList<>();
            for (final DeviceOutputSetting deviceOutputSetting : deviceOutputSettingsLightRelays) {
                final List<PowerUsageDataDto> powerUsageData = Iec61850PowerUsageHistoryCommand.this.getPowerUsageHistoryDataFromRelay(iec61850Client, deviceConnection, timePeriod, deviceOutputSetting, deviceMessageLog);
                powerUsageHistoryData.addAll(powerUsageData);
            }
            DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            /*
                 * This way of gathering leads to PowerUsageData elements per
                 * relay. If it is necessary to only include one PowerUsageData
                 * element for the device, where data for the different relays
                 * is combined in the SsldData.relayData some sort of merge
                 * needs to be performed.
                 * 
                 * This can either be a rework of the list currently returned,
                 * or it can be a list constructed based on an altered return
                 * type from getPowerUsageHistoryDataFromRelay (for instance a
                 * Map of Date to a Map of Relay Index to Total Lighting
                 * Minutes).
                 */
            return powerUsageHistoryData;
        }
    };
    return iec61850Client.sendCommandWithRetry(function, "GetPowerUsageHistory", 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) HistoryTermTypeDto(com.alliander.osgp.dto.valueobjects.HistoryTermTypeDto) ArrayList(java.util.ArrayList) DeviceOutputSetting(com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting) ArrayList(java.util.ArrayList) List(java.util.List) PowerUsageDataDto(com.alliander.osgp.dto.valueobjects.PowerUsageDataDto) TimePeriodDto(com.alliander.osgp.dto.valueobjects.TimePeriodDto)

Example 15 with DeviceMessageLog

use of com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog 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

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