Search in sources :

Example 1 with DeviceOutputSetting

use of org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.

the class OslpChannelHandler method createRelayConfiguration.

/**
 * Create relay configuration based on stored configuration values.
 */
private static RelayConfiguration createRelayConfiguration(final List<DeviceOutputSetting> outputSettings) {
    final RelayConfiguration.Builder configuration = RelayConfiguration.newBuilder();
    for (final DeviceOutputSetting dos : outputSettings) {
        final IndexAddressMap.Builder relayMap = IndexAddressMap.newBuilder().setIndex(OslpUtils.integerToByteString(dos.getInternalId())).setAddress(OslpUtils.integerToByteString(dos.getExternalId()));
        // Map device-simulator enum OutputType to OSLP enum RelayType
        if (dos.getOutputType() == OutputType.LIGHT) {
            relayMap.setRelayType(RelayType.LIGHT);
        } else if (dos.getOutputType() == OutputType.TARIFF) {
            relayMap.setRelayType(RelayType.TARIFF);
        } else {
            relayMap.setRelayType(RelayType.RT_NOT_SET);
        }
        configuration.addAddressMap(relayMap);
    }
    return configuration.build();
}
Also used : RelayConfiguration(org.opensmartgridplatform.oslp.Oslp.RelayConfiguration) DeviceOutputSetting(org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceOutputSetting) IndexAddressMap(org.opensmartgridplatform.oslp.Oslp.IndexAddressMap)

Example 2 with DeviceOutputSetting

use of org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.

the class OslpChannelHandler method createGetStatusResponse.

private Message createGetStatusResponse(final Device device) {
    final List<LightValue> outputValues = new ArrayList<>();
    for (final DeviceOutputSetting dos : device.getOutputSettings()) {
        final Builder lightValue = this.getLightValueForDeviceOutputSetting(device, dos);
        outputValues.add(lightValue.build());
    }
    // Fallback in case output settings are not yet defined.
    if (outputValues.isEmpty()) {
        final Builder lightValue = this.getDefaultLightValue(device);
        outputValues.add(lightValue.build());
    }
    final Oslp.GetStatusResponse.Builder builder = GetStatusResponse.newBuilder();
    builder.setStatus(Oslp.Status.OK);
    builder.addAllValue(outputValues);
    builder.setPreferredLinktype(Enum.valueOf(Oslp.LinkType.class, device.getPreferredLinkType().name()));
    builder.setActualLinktype(Enum.valueOf(Oslp.LinkType.class, device.getActualLinkType().name()));
    builder.setLightType(Enum.valueOf(Oslp.LightType.class, device.getLightType().name()));
    builder.setEventNotificationMask(device.getEventNotificationMask());
    LOGGER.info("device.getProtocol(): {}", device.getProtocol());
    LOGGER.info("ProtocolType.OSLP_ELSTER.name(): {}", ProtocolType.OSLP_ELSTER);
    if (device.getProtocol().equals(ProtocolType.OSLP_ELSTER.toString())) {
        builder.setNumberOfOutputs(4);
        builder.setDcOutputVoltageMaximum(24000);
        builder.setDcOutputVoltageCurrent(24000);
        builder.setMaximumOutputPowerOnDcOutput(15000);
        builder.setSerialNumber(ByteString.copyFrom(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
        builder.setMacAddress(ByteString.copyFrom(new byte[] { 1, 2, 3, 4, 5, 6 }));
        builder.setHardwareId("Hardware ID").setInternalFlashMemSize(1024);
        builder.setExternalFlashMemSize(2048).setLastInternalTestResultCode(0).setStartupCounter(42);
        builder.setBootLoaderVersion("1.1.1").setFirmwareVersion("2.8.5");
        builder.setCurrentConfigurationBackUsed(ByteString.copyFrom(new byte[] { 0 }));
        builder.setName("ELS_DEV-SIM-DEVICE").setCurrentTime("20251231155959");
        builder.setCurrentIp(this.statusInternalIpAddress);
    }
    return Oslp.Message.newBuilder().setGetStatusResponse(builder.build()).build();
}
Also used : LightType(org.opensmartgridplatform.webdevicesimulator.domain.valueobjects.LightType) GetStatusResponse(org.opensmartgridplatform.oslp.Oslp.GetStatusResponse) LightValue(org.opensmartgridplatform.oslp.Oslp.LightValue) Builder(org.opensmartgridplatform.oslp.Oslp.LightValue.Builder) ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceOutputSetting) LinkType(org.opensmartgridplatform.webdevicesimulator.domain.valueobjects.LinkType)

Example 3 with DeviceOutputSetting

use of org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceOutputSetting 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

DeviceOutputSetting (org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceOutputSetting)3 ArrayList (java.util.ArrayList)2 IndexAddressMap (org.opensmartgridplatform.oslp.Oslp.IndexAddressMap)2 LightType (org.opensmartgridplatform.webdevicesimulator.domain.valueobjects.LightType)2 LinkType (org.opensmartgridplatform.webdevicesimulator.domain.valueobjects.LinkType)2 GetStatusResponse (org.opensmartgridplatform.oslp.Oslp.GetStatusResponse)1 LightValue (org.opensmartgridplatform.oslp.Oslp.LightValue)1 Builder (org.opensmartgridplatform.oslp.Oslp.LightValue.Builder)1 RelayConfiguration (org.opensmartgridplatform.oslp.Oslp.RelayConfiguration)1 OutputType (org.opensmartgridplatform.webdevicesimulator.domain.valueobjects.OutputType)1