use of com.alliander.osgp.webdevicesimulator.domain.entities.DeviceOutputSetting 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);
}
}
use of com.alliander.osgp.webdevicesimulator.domain.entities.DeviceOutputSetting in project Protocol-Adapter-OSLP 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 LightValue.Builder lightValue = LightValue.newBuilder().setIndex(OslpUtils.integerToByteString(dos.getInternalId()));
if (dos.getOutputType().equals(OutputType.LIGHT)) {
lightValue.setOn(device.isLightOn());
if (device.getDimValue() != null) {
lightValue.setDimValue(OslpUtils.integerToByteString(device.getDimValue()));
}
// Real device specifies dimvalue 0 when off.
if (!device.isLightOn()) {
lightValue.setDimValue(OslpUtils.integerToByteString(0));
}
} else if (dos.getOutputType().equals(OutputType.TARIFF)) {
lightValue.setOn(device.isTariffOn());
}
outputValues.add(lightValue.build());
}
// Fallback in case output settings are not yet defined.
if (outputValues.isEmpty()) {
final LightValue.Builder lightValue = LightValue.newBuilder().setIndex(OslpUtils.integerToByteString(0)).setOn(device.isLightOn());
if (device.getDimValue() != null) {
lightValue.setDimValue(OslpUtils.integerToByteString(device.getDimValue()));
}
// Real device specifies dimvalue 0 when off.
if (!device.isLightOn()) {
lightValue.setDimValue(OslpUtils.integerToByteString(0));
}
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.name());
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();
}
use of com.alliander.osgp.webdevicesimulator.domain.entities.DeviceOutputSetting in project Protocol-Adapter-OSLP 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();
}
Aggregations