use of com.alliander.osgp.oslp.Oslp.LightValue 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.oslp.Oslp.LightValue in project Protocol-Adapter-OSLP by OSGP.
the class OslpChannelHandler method handleSetLightRequest.
private void handleSetLightRequest(final Device device, final SetLightRequest request) {
// Device simulator will only use first light value,
// other light values will be ignored
final LightValue lightValue = request.getValues(0);
device.setLightOn(lightValue.getOn());
if (lightValue.hasDimValue()) {
final int dimValue = lightValue.getDimValue().byteAt(0);
device.setDimValue(dimValue);
} else {
device.setDimValue(null);
}
// Send an event.
final Oslp.Event event = device.isLightOn() ? Oslp.Event.LIGHT_EVENTS_LIGHT_ON : Oslp.Event.LIGHT_EVENTS_LIGHT_OFF;
final String description = "setLightRequest [SET_LIGHT] SCHED[-]";
this.sendEvent(device, event, description);
}
Aggregations