Search in sources :

Example 1 with IndexAddressMap

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);
}
Also used : ArrayList(java.util.ArrayList) RelayMapDto(org.opensmartgridplatform.dto.valueobjects.RelayMapDto) IndexAddressMap(org.opensmartgridplatform.oslp.Oslp.IndexAddressMap) RelayTypeDto(org.opensmartgridplatform.dto.valueobjects.RelayTypeDto) RelayConfigurationDto(org.opensmartgridplatform.dto.valueobjects.RelayConfigurationDto)

Example 2 with 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)));
    }
}
Also used : LightType(org.opensmartgridplatform.oslp.Oslp.LightType) DaliConfiguration(org.opensmartgridplatform.oslp.Oslp.DaliConfiguration) Message(org.opensmartgridplatform.oslp.Oslp.Message) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) ByteString(com.google.protobuf.ByteString) IndexAddressMap(org.opensmartgridplatform.oslp.Oslp.IndexAddressMap) SetConfigurationRequest(org.opensmartgridplatform.oslp.Oslp.SetConfigurationRequest) RelayConfiguration(org.opensmartgridplatform.oslp.Oslp.RelayConfiguration) RelayMap(org.opensmartgridplatform.domain.core.valueobjects.RelayMap) LinkType(org.opensmartgridplatform.oslp.Oslp.LinkType) Then(io.cucumber.java.en.Then)

Example 3 with IndexAddressMap

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);
}
Also used : DaliConfigurationDto(org.opensmartgridplatform.dto.valueobjects.DaliConfigurationDto) HashMap(java.util.HashMap) IndexAddressMap(org.opensmartgridplatform.oslp.Oslp.IndexAddressMap)

Example 4 with IndexAddressMap

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);
    }
}
Also used : LightType(org.opensmartgridplatform.webdevicesimulator.domain.valueobjects.LightType) ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceOutputSetting) LinkType(org.opensmartgridplatform.webdevicesimulator.domain.valueobjects.LinkType) IndexAddressMap(org.opensmartgridplatform.oslp.Oslp.IndexAddressMap) OutputType(org.opensmartgridplatform.webdevicesimulator.domain.valueobjects.OutputType)

Aggregations

IndexAddressMap (org.opensmartgridplatform.oslp.Oslp.IndexAddressMap)4 ArrayList (java.util.ArrayList)2 ByteString (com.google.protobuf.ByteString)1 Then (io.cucumber.java.en.Then)1 HashMap (java.util.HashMap)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 RelayMap (org.opensmartgridplatform.domain.core.valueobjects.RelayMap)1 DaliConfigurationDto (org.opensmartgridplatform.dto.valueobjects.DaliConfigurationDto)1 RelayConfigurationDto (org.opensmartgridplatform.dto.valueobjects.RelayConfigurationDto)1 RelayMapDto (org.opensmartgridplatform.dto.valueobjects.RelayMapDto)1 RelayTypeDto (org.opensmartgridplatform.dto.valueobjects.RelayTypeDto)1 DaliConfiguration (org.opensmartgridplatform.oslp.Oslp.DaliConfiguration)1 LightType (org.opensmartgridplatform.oslp.Oslp.LightType)1 LinkType (org.opensmartgridplatform.oslp.Oslp.LinkType)1 Message (org.opensmartgridplatform.oslp.Oslp.Message)1 RelayConfiguration (org.opensmartgridplatform.oslp.Oslp.RelayConfiguration)1 SetConfigurationRequest (org.opensmartgridplatform.oslp.Oslp.SetConfigurationRequest)1 DeviceOutputSetting (org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceOutputSetting)1 LightType (org.opensmartgridplatform.webdevicesimulator.domain.valueobjects.LightType)1 LinkType (org.opensmartgridplatform.webdevicesimulator.domain.valueobjects.LinkType)1