diff --git a/client/src/main/java/me/retrodaredevil/solarthing/config/options/PacketHandlingOptionBase.java b/client/src/main/java/me/retrodaredevil/solarthing/config/options/PacketHandlingOptionBase.java index a3fce2d5..3c506ec1 100644 --- a/client/src/main/java/me/retrodaredevil/solarthing/config/options/PacketHandlingOptionBase.java +++ b/client/src/main/java/me/retrodaredevil/solarthing/config/options/PacketHandlingOptionBase.java @@ -24,6 +24,7 @@ abstract class PacketHandlingOptionBase extends TimeZoneOptionBase implements Pa @JsonProperty private Integer unique = null; + @JsonProperty("request") private @Nullable List dataRequesterList; @Override diff --git a/client/src/main/java/me/retrodaredevil/solarthing/config/options/ProgramOptions.java b/client/src/main/java/me/retrodaredevil/solarthing/config/options/ProgramOptions.java index 0c1013d2..fd6a6afd 100644 --- a/client/src/main/java/me/retrodaredevil/solarthing/config/options/ProgramOptions.java +++ b/client/src/main/java/me/retrodaredevil/solarthing/config/options/ProgramOptions.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import me.retrodaredevil.solarthing.annotations.JsonExplicit; @JsonSubTypes({ @JsonSubTypes.Type(MateProgramOptions.class), @@ -12,6 +13,7 @@ @JsonSubTypes.Type(AutomationProgramOptions.class), }) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") +@JsonExplicit public interface ProgramOptions { ProgramType getProgramType(); } diff --git a/client/src/main/java/me/retrodaredevil/solarthing/config/request/DataRequester.java b/client/src/main/java/me/retrodaredevil/solarthing/config/request/DataRequester.java index 78e356ae..3eb06048 100644 --- a/client/src/main/java/me/retrodaredevil/solarthing/config/request/DataRequester.java +++ b/client/src/main/java/me/retrodaredevil/solarthing/config/request/DataRequester.java @@ -3,13 +3,12 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import me.retrodaredevil.solarthing.packets.handling.PacketListReceiver; -import me.retrodaredevil.solarthing.solar.pzem.modbus.PzemShuntModbusSlaveRead; @JsonSubTypes({ @JsonSubTypes.Type(RaspberryPiCpuTemperatureDataRequester.class), @JsonSubTypes.Type(W1TemperatureDataRequester.class), @JsonSubTypes.Type(BatteryVoltageIODataRequester.class), - @JsonSubTypes.Type(PzemShuntModbusSlaveRead.class), + @JsonSubTypes.Type(PzemShuntDataRequester.class), }) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public interface DataRequester { diff --git a/core/src/main/java/me/retrodaredevil/solarthing/solar/pzem/ImmutablePzemShuntStatusPacket.java b/core/src/main/java/me/retrodaredevil/solarthing/solar/pzem/ImmutablePzemShuntStatusPacket.java index 2ab5312e..690d19c9 100644 --- a/core/src/main/java/me/retrodaredevil/solarthing/solar/pzem/ImmutablePzemShuntStatusPacket.java +++ b/core/src/main/java/me/retrodaredevil/solarthing/solar/pzem/ImmutablePzemShuntStatusPacket.java @@ -14,11 +14,11 @@ public class ImmutablePzemShuntStatusPacket implements PzemShuntStatusPacket { private final int modbusAddress; @JsonCreator public ImmutablePzemShuntStatusPacket( - @JsonProperty("dataId") int dataId, - @JsonProperty("voltageValueRaw") int voltageValueRaw, @JsonProperty("currentValueRaw") int currentValueRaw, - @JsonProperty("powerValueRaw") int powerValueRaw, @JsonProperty("energyValueRaw") int energyValueRaw, - @JsonProperty("highVoltageAlarmStatus") int highVoltageAlarmStatus, @JsonProperty("lowVoltageAlarmStatus") int lowVoltageAlarmStatus, - @JsonProperty("modbusAddress") int modbusAddress) { + @JsonProperty(value = "dataId", required = true) int dataId, + @JsonProperty(value = "voltageValueRaw", required = true) int voltageValueRaw, @JsonProperty(value = "currentValueRaw", required = true) int currentValueRaw, + @JsonProperty(value = "powerValueRaw", required = true) int powerValueRaw, @JsonProperty(value = "energyValueRaw", required = true) int energyValueRaw, + @JsonProperty(value = "highVoltageAlarmStatus", required = true) int highVoltageAlarmStatus, @JsonProperty(value = "lowVoltageAlarmStatus", required = true) int lowVoltageAlarmStatus, + @JsonProperty(value = "modbusAddress", required = true) int modbusAddress) { this.identifier = new DataIdentifier(dataId); this.identityInfo = new PzemShuntIdentityInfo(dataId); diff --git a/core/src/main/java/me/retrodaredevil/solarthing/solar/pzem/PzemShuntReadTable.java b/core/src/main/java/me/retrodaredevil/solarthing/solar/pzem/PzemShuntReadTable.java index 756d1348..dbc191f5 100644 --- a/core/src/main/java/me/retrodaredevil/solarthing/solar/pzem/PzemShuntReadTable.java +++ b/core/src/main/java/me/retrodaredevil/solarthing/solar/pzem/PzemShuntReadTable.java @@ -3,8 +3,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import me.retrodaredevil.io.serial.SerialConfig; import me.retrodaredevil.io.serial.SerialConfigBuilder; -import me.retrodaredevil.solarthing.solar.common.Shunt; +import me.retrodaredevil.solarthing.annotations.JsonExplicit; +@JsonExplicit public interface PzemShuntReadTable { SerialConfig SERIAL_CONFIG = new SerialConfigBuilder(9600).setDataBits(8).setStopBits(SerialConfig.StopBits.TWO).build(); @@ -13,20 +14,25 @@ public interface PzemShuntReadTable { default float getVoltage() { return getVoltageValueRaw() / 100.0f; } + @JsonProperty("currentValueRaw") int getCurrentValueRaw(); default float getCurrentAmps() { return getCurrentValueRaw() / 100.0f; } + @JsonProperty("powerValueRaw") int getPowerValueRaw(); default float getPowerWatts() { return getPowerValueRaw() / 10.0f; } + @JsonProperty("energyValueRaw") int getEnergyValueRaw(); default int getEnergyWattHours() { return getEnergyValueRaw(); } default float getEnergyKWH() { return getEnergyValueRaw() / 1000.0f; } + @JsonProperty("highVoltageAlarmStatus") int getHighVoltageAlarmStatus(); + @JsonProperty("lowVoltageAlarmStatus") int getLowVoltageAlarmStatus(); default boolean isHighVoltageAlarm() { return getHighVoltageAlarmStatus() != 0; } diff --git a/core/src/test/java/me/retrodaredevil/solarthing/solar/pzem/PzemTest.java b/core/src/test/java/me/retrodaredevil/solarthing/solar/pzem/PzemTest.java new file mode 100644 index 00000000..8bf661fb --- /dev/null +++ b/core/src/test/java/me/retrodaredevil/solarthing/solar/pzem/PzemTest.java @@ -0,0 +1,43 @@ +package me.retrodaredevil.solarthing.solar.pzem; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import me.retrodaredevil.solarthing.util.JacksonUtil; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + +public class PzemTest { + @Test + void test() throws JsonProcessingException { + + String json = "{\n" + + " \n" + + "\"packetType\" : \"PZEM_SHUNT\",\n" + + " \"dataId\" : 1,\n" + + " \"voltageValueRaw\" : 25,\n" + + " \"currentValueRaw\" : 4,\n" + + " \"powerValueRaw\" : 100,\n" + + " \"energyValueRaw\" : 2210,\n" + + " \"highVoltageAlarmStatus\" : 0,\n" + + " \"lowVoltageAlarmStatus\" : 0,\n" + + " \"modbusAddress\" : 1\n" + + "}"; + ObjectMapper mapper = JacksonUtil.defaultMapper(); + PzemShuntStatusPacket parsedPacket = mapper.readValue(json, PzemShuntStatusPacket.class); + String generatedJson = mapper.writeValueAsString(parsedPacket); + PzemShuntStatusPacket reparsedPacket = mapper.readValue(generatedJson, PzemShuntStatusPacket.class); + for (PzemShuntStatusPacket packet : new PzemShuntStatusPacket[] { parsedPacket, reparsedPacket}) { + assertEquals(1, packet.getDataId()); + assertEquals(25, packet.getVoltageValueRaw()); + assertEquals(4, packet.getCurrentValueRaw()); + assertEquals(100, packet.getPowerValueRaw()); + assertEquals(2210, packet.getEnergyValueRaw()); + assertEquals(0, packet.getHighVoltageAlarmStatus()); + assertEquals(0, packet.getLowVoltageAlarmStatus()); + assertFalse(packet.isHighVoltageAlarm()); + assertFalse(packet.isLowVoltageAlarm()); + } + } +} diff --git a/core/src/test/java/me/retrodaredevil/solarthing/solar/renogy/rover/RoverElitePacketTest.java b/core/src/test/java/me/retrodaredevil/solarthing/solar/renogy/rover/RoverElitePacketTest.java index aebd66b4..7bca39c6 100644 --- a/core/src/test/java/me/retrodaredevil/solarthing/solar/renogy/rover/RoverElitePacketTest.java +++ b/core/src/test/java/me/retrodaredevil/solarthing/solar/renogy/rover/RoverElitePacketTest.java @@ -120,6 +120,7 @@ void test() throws JsonProcessingException { assertNull(roverStatusPacket.getSensingTimeDelayRaw()); assertNull(roverStatusPacket.getLEDLoadCurrentRaw()); assertNull(roverStatusPacket.getSpecialPowerControlE02DRaw()); + assertNull(roverStatusPacket.getPacketVersion()); assertFalse(roverStatusPacket.supportsMesLoad()); } }