Search in sources :

Example 1 with IndexAddressMap

use of com.alliander.osgp.oslp.Oslp.IndexAddressMap in project Protocol-Adapter-OSLP by OSGP.

the class OslpChannelHandler method handleSetConfigurationRequest.

private void handleSetConfigurationRequest(final Device device, final Oslp.SetConfigurationRequest setConfigurationRequest) {
    if (setConfigurationRequest.hasPreferredLinkType()) {
        device.setPreferredLinkType(Enum.valueOf(LinkType.class, setConfigurationRequest.getPreferredLinkType().name()));
    }
    if (setConfigurationRequest.hasLightType()) {
        device.setLightType(Enum.valueOf(LightType.class, setConfigurationRequest.getLightType().name()));
    }
    if (setConfigurationRequest.hasRelayConfiguration()) {
        final List<DeviceOutputSetting> outputSettings = new ArrayList<>();
        for (final IndexAddressMap iam : setConfigurationRequest.getRelayConfiguration().getAddressMapList()) {
            final int index = iam.getIndex().byteAt(0);
            final int address = iam.getAddress().byteAt(0);
            final OutputType outputType = OutputType.valueOf(iam.getRelayType().name());
            outputSettings.add(new DeviceOutputSetting(index, address, outputType));
        }
        device.setOutputSettings(outputSettings);
    }
}
Also used : LightType(com.alliander.osgp.webdevicesimulator.domain.valueobjects.LightType) ArrayList(java.util.ArrayList) DeviceOutputSetting(com.alliander.osgp.webdevicesimulator.domain.entities.DeviceOutputSetting) LinkType(com.alliander.osgp.webdevicesimulator.domain.valueobjects.LinkType) IndexAddressMap(com.alliander.osgp.oslp.Oslp.IndexAddressMap) OutputType(com.alliander.osgp.webdevicesimulator.domain.valueobjects.OutputType)

Example 2 with IndexAddressMap

use of com.alliander.osgp.oslp.Oslp.IndexAddressMap in project Protocol-Adapter-OSLP by OSGP.

the class RelayConfigurationToOslpRelayConfigurationConverter method convertFrom.

@Override
public RelayConfigurationDto convertFrom(final com.alliander.osgp.oslp.Oslp.RelayConfiguration source, final Type<RelayConfigurationDto> destinationType, final MappingContext context) {
    if (source == null) {
        return null;
    }
    final List<RelayMapDto> indexAddressMap = new ArrayList<RelayMapDto>();
    for (final IndexAddressMap entry : source.getAddressMapList()) {
        // Map OSLP RT_NOT_SET to null
        indexAddressMap.add(new RelayMapDto(this.mapperFacade.map(entry.getIndex(), Integer.class), this.mapperFacade.map(entry.getAddress(), Integer.class), entry.hasRelayType() && entry.getRelayType() != Oslp.RelayType.RT_NOT_SET ? this.mapperFacade.map(entry.getRelayType(), RelayTypeDto.class) : null, null));
    }
    final List<RelayMapDto> relayMaps = new ArrayList<RelayMapDto>();
    return new RelayConfigurationDto(!indexAddressMap.isEmpty() ? indexAddressMap : relayMaps);
}
Also used : ArrayList(java.util.ArrayList) RelayMapDto(com.alliander.osgp.dto.valueobjects.RelayMapDto) IndexAddressMap(com.alliander.osgp.oslp.Oslp.IndexAddressMap) RelayTypeDto(com.alliander.osgp.dto.valueobjects.RelayTypeDto) RelayConfigurationDto(com.alliander.osgp.dto.valueobjects.RelayConfigurationDto)

Example 3 with IndexAddressMap

use of com.alliander.osgp.oslp.Oslp.IndexAddressMap in project Protocol-Adapter-OSLP by OSGP.

the class DaliConfigurationToOslpDaliConfigurationConverter method convertFrom.

@Override
public DaliConfigurationDto convertFrom(final com.alliander.osgp.oslp.Oslp.DaliConfiguration source, final Type<DaliConfigurationDto> destinationType, final MappingContext context) {
    if (source == null) {
        return null;
    }
    final Map<Integer, Integer> indexAddressMap = new HashMap<Integer, Integer>();
    for (final IndexAddressMap entry : source.getAddressMapList()) {
        indexAddressMap.put(this.mapperFacade.map(entry.getIndex(), Integer.class), this.mapperFacade.map(entry.getAddress(), Integer.class));
    }
    final Integer numberOfLights = Integer.valueOf(0);
    final Map<Integer, Integer> adresMap = new HashMap<Integer, Integer>();
    return new DaliConfigurationDto(source.hasNumberOfLights() ? this.mapperFacade.map(source.getNumberOfLights(), Integer.class) : numberOfLights, !indexAddressMap.isEmpty() ? indexAddressMap : adresMap);
}
Also used : DaliConfigurationDto(com.alliander.osgp.dto.valueobjects.DaliConfigurationDto) HashMap(java.util.HashMap) IndexAddressMap(com.alliander.osgp.oslp.Oslp.IndexAddressMap)

Aggregations

IndexAddressMap (com.alliander.osgp.oslp.Oslp.IndexAddressMap)3 ArrayList (java.util.ArrayList)2 DaliConfigurationDto (com.alliander.osgp.dto.valueobjects.DaliConfigurationDto)1 RelayConfigurationDto (com.alliander.osgp.dto.valueobjects.RelayConfigurationDto)1 RelayMapDto (com.alliander.osgp.dto.valueobjects.RelayMapDto)1 RelayTypeDto (com.alliander.osgp.dto.valueobjects.RelayTypeDto)1 DeviceOutputSetting (com.alliander.osgp.webdevicesimulator.domain.entities.DeviceOutputSetting)1 LightType (com.alliander.osgp.webdevicesimulator.domain.valueobjects.LightType)1 LinkType (com.alliander.osgp.webdevicesimulator.domain.valueobjects.LinkType)1 OutputType (com.alliander.osgp.webdevicesimulator.domain.valueobjects.OutputType)1 HashMap (java.util.HashMap)1