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;
}
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));
}
Aggregations