Search in sources :

Example 1 with RelayTypeDto

use of org.opensmartgridplatform.dto.valueobjects.RelayTypeDto in project open-smart-grid-platform by OSGP.

the class Iec61850SetScheduleCommand method setScheduleOnDevice.

public void setScheduleOnDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final SetScheduleDeviceRequest deviceRequest, final Ssld ssld) throws ProtocolAdapterException {
    final ScheduleDto scheduleDto = deviceRequest.getSchedule();
    final RelayTypeDto relayType = deviceRequest.getRelayType();
    final List<ScheduleEntryDto> scheduleList = scheduleDto.getScheduleList();
    try {
        // Creating a list of all Schedule entries, grouped by relay index.
        final Map<Integer, List<ScheduleEntry>> relaySchedulesEntries = this.createScheduleEntries(scheduleList, ssld, relayType);
        final Function<Void> function = new Iec61850SetScheduleFunction(iec61850Client, deviceConnection, deviceRequest, ssld, relaySchedulesEntries, this.loggingService, this.ssldDataService);
        iec61850Client.sendCommandWithRetry(function, "SetSchedule", deviceConnection.getDeviceIdentification());
    } catch (final FunctionalException e) {
        throw new ProtocolAdapterException(e.getMessage(), e);
    }
}
Also used : ScheduleEntryDto(org.opensmartgridplatform.dto.valueobjects.ScheduleEntryDto) Iec61850SetScheduleFunction(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Iec61850SetScheduleFunction) ArrayList(java.util.ArrayList) List(java.util.List) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) RelayTypeDto(org.opensmartgridplatform.dto.valueobjects.RelayTypeDto) ScheduleDto(org.opensmartgridplatform.dto.valueobjects.ScheduleDto)

Example 2 with RelayTypeDto

use of org.opensmartgridplatform.dto.valueobjects.RelayTypeDto in project open-smart-grid-platform by OSGP.

the class Iec61850SetConfigurationFunction method setRelayConfiguration.

private void setRelayConfiguration(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final ConfigurationDto configuration, final DeviceMessageLog deviceMessageLog) throws NodeException {
    if (configuration.getRelayConfiguration() != null && configuration.getRelayConfiguration().getRelayMap() != null) {
        final List<RelayMapDto> relayMaps = configuration.getRelayConfiguration().getRelayMap();
        for (final RelayMapDto relayMap : relayMaps) {
            final Integer internalIndex = relayMap.getAddress();
            final RelayTypeDto relayType = relayMap.getRelayType();
            final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(internalIndex);
            final NodeContainer switchType = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.SWITCH_TYPE, Fc.CO);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), switchType.getFcmodelNode());
            final NodeContainer operation = switchType.getChild(SubDataAttribute.OPERATION);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), operation.getFcmodelNode());
            final BdaInt8 ctlVal = operation.getByte(SubDataAttribute.CONTROL_VALUE);
            final byte switchTypeValue = (byte) (RelayTypeDto.LIGHT.equals(relayType) ? SWITCH_TYPE_LIGHT : SWITCH_TYPE_TARIFF);
            LOGGER.info("Updating Switch for internal index {} to {} ({})", internalIndex, switchTypeValue, relayType);
            ctlVal.setValue(switchTypeValue);
            operation.write();
            deviceMessageLog.addVariable(logicalNode, DataAttribute.SWITCH_TYPE, Fc.CO, SubDataAttribute.OPERATION, SubDataAttribute.CONTROL_VALUE, Byte.toString(switchTypeValue));
        }
    }
}
Also used : BdaInt8(com.beanit.openiec61850.BdaInt8) RelayMapDto(org.opensmartgridplatform.dto.valueobjects.RelayMapDto) RelayTypeDto(org.opensmartgridplatform.dto.valueobjects.RelayTypeDto)

Aggregations

RelayTypeDto (org.opensmartgridplatform.dto.valueobjects.RelayTypeDto)2 BdaInt8 (com.beanit.openiec61850.BdaInt8)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 Iec61850SetScheduleFunction (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Iec61850SetScheduleFunction)1 RelayMapDto (org.opensmartgridplatform.dto.valueobjects.RelayMapDto)1 ScheduleDto (org.opensmartgridplatform.dto.valueobjects.ScheduleDto)1 ScheduleEntryDto (org.opensmartgridplatform.dto.valueobjects.ScheduleEntryDto)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1