Search in sources :

Example 1 with RelayType

use of com.alliander.osgp.core.db.api.iec61850valueobjects.RelayType in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850SetScheduleCommand method createScheduleEntries.

/**
     * Returns a map of schedule entries, grouped by the internal index.
     */
private Map<Integer, List<ScheduleEntry>> createScheduleEntries(final List<ScheduleDto> scheduleList, final Ssld ssld, final RelayTypeDto relayTypeDto, final SsldDataService ssldDataService) throws FunctionalException {
    final Map<Integer, List<ScheduleEntry>> relaySchedulesEntries = new HashMap<>();
    final RelayType relayType = RelayType.valueOf(relayTypeDto.name());
    for (final ScheduleDto schedule : scheduleList) {
        for (final LightValueDto lightValue : schedule.getLightValue()) {
            final List<Integer> indexes = new ArrayList<>();
            if (lightValue.getIndex() == 0 && (RelayType.TARIFF.equals(relayType) || RelayType.TARIFF_REVERSED.equals(relayType))) {
                // Index 0 is not allowed for tariff switching.
                throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.PROTOCOL_IEC61850);
            } else if (lightValue.getIndex() == 0 && RelayType.LIGHT.equals(relayType)) {
                // Index == 0, getting all light relays and adding their
                // internal indexes to the indexes list.
                final List<DeviceOutputSetting> settings = ssldDataService.findByRelayType(ssld, relayType);
                for (final DeviceOutputSetting deviceOutputSetting : settings) {
                    indexes.add(deviceOutputSetting.getInternalId());
                }
            } else {
                // Index != 0, adding just the one index to the list.
                indexes.add(ssldDataService.convertToInternalIndex(ssld, lightValue.getIndex()));
            }
            ScheduleEntry scheduleEntry;
            try {
                scheduleEntry = this.convertToScheduleEntry(schedule, lightValue);
            } catch (final ProtocolAdapterException e) {
                throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.PROTOCOL_IEC61850, e);
            }
            for (final Integer internalIndex : indexes) {
                if (relaySchedulesEntries.containsKey(internalIndex)) {
                    // Internal index already in the Map, adding to the List
                    relaySchedulesEntries.get(internalIndex).add(scheduleEntry);
                } else {
                    // First time we come across this relay, checking its
                    // type.
                    this.checkRelayForSchedules(ssldDataService.getDeviceOutputSettingForInternalIndex(ssld, internalIndex).getRelayType(), relayType, internalIndex);
                    // Adding it to scheduleEntries.
                    final List<ScheduleEntry> scheduleEntries = new ArrayList<>();
                    scheduleEntries.add(scheduleEntry);
                    relaySchedulesEntries.put(internalIndex, scheduleEntries);
                }
            }
        }
    }
    return relaySchedulesEntries;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DeviceOutputSetting(com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting) ScheduleDto(com.alliander.osgp.dto.valueobjects.ScheduleDto) LightValueDto(com.alliander.osgp.dto.valueobjects.LightValueDto) RelayType(com.alliander.osgp.core.db.api.iec61850valueobjects.RelayType) ScheduleEntry(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.ScheduleEntry) ArrayList(java.util.ArrayList) List(java.util.List) FunctionalException(com.alliander.osgp.shared.exceptionhandling.FunctionalException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)

Example 2 with RelayType

use of com.alliander.osgp.core.db.api.iec61850valueobjects.RelayType 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)

Aggregations

ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)2 RelayType (com.alliander.osgp.core.db.api.iec61850valueobjects.RelayType)2 ScheduleEntry (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.ScheduleEntry)1 LogicalNode (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)1 NodeContainer (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)1 DeviceOutputSetting (com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting)1 LightValueDto (com.alliander.osgp.dto.valueobjects.LightValueDto)1 ScheduleDto (com.alliander.osgp.dto.valueobjects.ScheduleDto)1 FunctionalException (com.alliander.osgp.shared.exceptionhandling.FunctionalException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1