use of org.opensmartgridplatform.oslp.Oslp.IndexAddressMap in project open-smart-grid-platform by OSGP.
the class RelayConfigurationToOslpRelayConfigurationConverter method convertFrom.
@Override
public RelayConfigurationDto convertFrom(final org.opensmartgridplatform.oslp.Oslp.RelayConfiguration source, final Type<RelayConfigurationDto> destinationType, final MappingContext context) {
if (source == null) {
return null;
}
// Map the relay configuration.
final List<RelayMapDto> indexAddressMap = new ArrayList<>();
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));
}
// Sort the relay configuration on index.
Collections.sort(indexAddressMap, (o1, o2) -> o1.getIndex().compareTo(o2.getIndex()));
return new RelayConfigurationDto(indexAddressMap);
}
use of org.opensmartgridplatform.oslp.Oslp.IndexAddressMap in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method aSetConfigurationOslpMessageIsSentToDevice.
/**
* Verify that a set configuration OSLP message is sent to the device.
*
* @param deviceIdentification The device identification expected in the message to the device.
*/
@Then("^a set configuration \"([^\"]*)\" message is sent to device \"([^\"]*)\"$")
public void aSetConfigurationOslpMessageIsSentToDevice(final String protocol, final String deviceIdentification, final Map<String, String> expectedResponseData) throws DeviceSimulatorException {
final Message receivedMessage = this.oslpMockServer.waitForRequest(this.getDeviceUid(expectedResponseData), MessageType.SET_CONFIGURATION);
assertThat(receivedMessage).isNotNull();
assertThat(receivedMessage.hasSetConfigurationRequest()).isTrue();
final SetConfigurationRequest receivedConfiguration = receivedMessage.getSetConfigurationRequest();
if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_LIGHTTYPE)) && receivedConfiguration.getLightType() != null) {
final LightType expectedLightType = getEnum(expectedResponseData, PlatformKeys.KEY_LIGHTTYPE, LightType.class);
assertThat(receivedConfiguration.getLightType()).isEqualTo(expectedLightType);
switch(expectedLightType) {
case DALI:
final DaliConfiguration receivedDaliConfiguration = receivedConfiguration.getDaliConfiguration();
if (receivedDaliConfiguration != null) {
if (expectedResponseData.containsKey(PlatformKeys.DC_LIGHTS) && StringUtils.isNotBlank(expectedResponseData.get(PlatformKeys.DC_LIGHTS))) {
assertThat(OslpUtils.byteStringToInteger(receivedDaliConfiguration.getNumberOfLights())).isEqualTo(getInteger(expectedResponseData, PlatformKeys.DC_LIGHTS));
}
if (expectedResponseData.containsKey(PlatformKeys.DC_MAP) && StringUtils.isNotBlank(expectedResponseData.get(PlatformKeys.DC_MAP))) {
assertThat(receivedDaliConfiguration.getAddressMapList()).isNotNull();
final String[] expectedDcMapArray = getString(expectedResponseData, PlatformKeys.DC_MAP).split(";");
assertThat(receivedDaliConfiguration.getAddressMapList().size()).isEqualTo(expectedDcMapArray.length);
final List<IndexAddressMap> receivedIndexAddressMapList = receivedDaliConfiguration.getAddressMapList();
for (int i = 0; i < expectedDcMapArray.length; i++) {
final String[] expectedDcMapArrayElements = expectedDcMapArray[i].split(",");
assertThat(OslpUtils.byteStringToInteger(receivedIndexAddressMapList.get(i).getIndex())).isEqualTo((Integer) Integer.parseInt(expectedDcMapArrayElements[0]));
assertThat(OslpUtils.byteStringToInteger(receivedIndexAddressMapList.get(i).getAddress())).isEqualTo((Integer) Integer.parseInt(expectedDcMapArrayElements[1]));
}
}
}
break;
case RELAY:
final RelayConfiguration receivedRelayConfiguration = receivedConfiguration.getRelayConfiguration();
if (receivedRelayConfiguration != null) {
if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.RELAY_CONF)) && receivedRelayConfiguration.getAddressMapList() != null) {
// Construct sorted list of received relay maps
final List<RelayMap> receivedRelayMapList = RelayMapConverter.convertIndexAddressMapListToRelayMapList(receivedRelayConfiguration.getAddressMapList());
Collections.sort(receivedRelayMapList);
// Construct sorted list of expected relay maps
final String[] expectedRelayMapArray = getString(expectedResponseData, PlatformKeys.RELAY_CONF).split(";");
final List<RelayMap> expectedRelayMapList = RelayMapConverter.convertStringsListToRelayMapList(expectedRelayMapArray);
Collections.sort(expectedRelayMapList);
assertThat(CollectionUtils.isEmpty(receivedRelayMapList)).as("Either the expected or the received relay maps are empty, but not both").isEqualTo(CollectionUtils.isEmpty(expectedRelayMapList));
if (!CollectionUtils.isEmpty(receivedRelayMapList) && !CollectionUtils.isEmpty(expectedRelayMapList)) {
assertThat(receivedRelayMapList.size()).as("Size of expected and received relay map list differs").isEqualTo(expectedRelayMapList.size());
}
// Compare the contents of each relay map
for (int i = 0; i < expectedRelayMapList.size(); i++) {
assertThat(receivedRelayMapList.get(i)).as("Expected and received relay map differs for " + i).isEqualTo(expectedRelayMapList.get(i));
}
}
}
break;
case ONE_TO_TEN_VOLT:
case ONE_TO_TEN_VOLT_REVERSE:
case LT_NOT_SET:
default:
assertThat(receivedConfiguration.getDaliConfiguration().getAddressMapList().size()).isEqualTo(0);
assertThat(receivedConfiguration.getRelayConfiguration().getAddressMapList().size()).isEqualTo(0);
}
}
if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_PREFERRED_LINKTYPE)) && receivedConfiguration.getPreferredLinkType() != null) {
assertThat(receivedConfiguration.getPreferredLinkType()).isEqualTo(getEnum(expectedResponseData, PlatformKeys.KEY_PREFERRED_LINKTYPE, LinkType.class));
}
if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.OSGP_IP_ADDRESS))) {
assertThat(OslpDeviceSteps.convertIpAddress(receivedConfiguration.getOspgIpAddress())).isEqualTo(expectedResponseData.get(PlatformKeys.OSGP_IP_ADDRESS));
}
if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.OSGP_PORT))) {
assertThat(receivedConfiguration.getOsgpPortNumber()).isEqualTo(Integer.parseInt(expectedResponseData.get(PlatformKeys.OSGP_PORT)));
}
if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNRISE_OFFSET))) {
assertThat(receivedConfiguration.getAstroGateSunRiseOffset()).isEqualTo(Integer.parseInt(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNRISE_OFFSET)));
}
if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNSET_OFFSET))) {
assertThat(receivedConfiguration.getAstroGateSunSetOffset()).isEqualTo(Integer.parseInt(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNSET_OFFSET)));
}
}
use of org.opensmartgridplatform.oslp.Oslp.IndexAddressMap in project open-smart-grid-platform by OSGP.
the class DaliConfigurationToOslpDaliConfigurationConverter method convertFrom.
@Override
public DaliConfigurationDto convertFrom(final org.opensmartgridplatform.oslp.Oslp.DaliConfiguration source, final Type<DaliConfigurationDto> destinationType, final MappingContext context) {
if (source == null) {
return null;
}
final Map<Integer, Integer> indexAddressMap = new HashMap<>();
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<>();
return new DaliConfigurationDto(source.hasNumberOfLights() ? this.mapperFacade.map(source.getNumberOfLights(), Integer.class) : numberOfLights, !indexAddressMap.isEmpty() ? indexAddressMap : adresMap);
}
use of org.opensmartgridplatform.oslp.Oslp.IndexAddressMap in project open-smart-grid-platform 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);
}
}
Aggregations