-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started adding pzem shunt code, fixed bug that affected many rover re…
…adings
- Loading branch information
1 parent
c569b3e
commit 326e876
Showing
22 changed files
with
418 additions
and
65 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
client/src/main/java/me/retrodaredevil/solarthing/config/request/PzemShuntDataRequester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package me.retrodaredevil.solarthing.config.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import me.retrodaredevil.io.IOBundle; | ||
import me.retrodaredevil.io.modbus.*; | ||
import me.retrodaredevil.solarthing.annotations.JsonExplicit; | ||
import me.retrodaredevil.solarthing.packets.handling.PacketListReceiver; | ||
import me.retrodaredevil.solarthing.program.PzemShuntPacketListUpdater; | ||
import me.retrodaredevil.solarthing.program.SolarMain; | ||
import me.retrodaredevil.solarthing.solar.pzem.PzemShuntReadTable; | ||
import me.retrodaredevil.solarthing.solar.pzem.modbus.PzemShuntModbusSlaveRead; | ||
|
||
import java.io.File; | ||
|
||
@JsonTypeName("pzem") | ||
@JsonExplicit | ||
public class PzemShuntDataRequester implements DataRequester { | ||
private final File ioBundleFile; | ||
private final int dataId; | ||
private final int modbusAddress; | ||
|
||
@JsonCreator | ||
public PzemShuntDataRequester( | ||
@JsonProperty(value = "io", required = true) File ioBundleFile, | ||
@JsonProperty(value = "data_id", required = true) int dataId, | ||
@JsonProperty(value = "modbus", required = true) int modbusAddress) { | ||
this.ioBundleFile = ioBundleFile; | ||
this.dataId = dataId; | ||
this.modbusAddress = modbusAddress; | ||
} | ||
|
||
@Override | ||
public PacketListReceiver createPacketListReceiver(PacketListReceiver eventPacketReceiver) { | ||
final IOBundle ioBundle = SolarMain.createIOBundle(ioBundleFile, PzemShuntReadTable.SERIAL_CONFIG); | ||
ModbusSlaveBus bus = new IOModbusSlaveBus(ioBundle, new RtuDataEncoder()); | ||
ModbusSlave slave = new ImmutableAddressModbusSlave(modbusAddress, bus); | ||
return new PzemShuntPacketListUpdater(dataId, modbusAddress, new PzemShuntModbusSlaveRead(slave)); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
client/src/main/java/me/retrodaredevil/solarthing/program/PzemShuntPacketListUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package me.retrodaredevil.solarthing.program; | ||
|
||
import me.retrodaredevil.io.modbus.ModbusRuntimeException; | ||
import me.retrodaredevil.solarthing.InstantType; | ||
import me.retrodaredevil.solarthing.packets.Packet; | ||
import me.retrodaredevil.solarthing.packets.handling.PacketListReceiver; | ||
import me.retrodaredevil.solarthing.solar.pzem.ImmutablePzemShuntStatusPacket; | ||
import me.retrodaredevil.solarthing.solar.pzem.PzemShuntReadTable; | ||
import me.retrodaredevil.solarthing.solar.pzem.PzemShuntStatusPacket; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
|
||
public class PzemShuntPacketListUpdater implements PacketListReceiver { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(PzemShuntPacketListUpdater.class); | ||
private final int dataId; | ||
private final int modbusAddress; | ||
private final PzemShuntReadTable read; | ||
|
||
public PzemShuntPacketListUpdater(int dataId, int modbusAddress, PzemShuntReadTable read) { | ||
this.dataId = dataId; | ||
this.modbusAddress = modbusAddress; | ||
this.read = read; | ||
} | ||
|
||
@Override | ||
public void receive(List<Packet> packets, InstantType instantType) { | ||
final PzemShuntStatusPacket packet; | ||
try { | ||
packet = ImmutablePzemShuntStatusPacket.createFromReadTable(dataId, modbusAddress, read); | ||
} catch (ModbusRuntimeException ex) { | ||
LOGGER.error("Modbus exception", ex); | ||
return; | ||
} | ||
packets.add(packet); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
core/src/main/java/me/retrodaredevil/solarthing/packets/VersionedPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package me.retrodaredevil.solarthing.packets; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import me.retrodaredevil.solarthing.annotations.Nullable; | ||
|
||
@JsonPropertyOrder({"packetType", "packetVersion"}) | ||
public interface VersionedPacket extends DocumentedPacket { | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonProperty("packetVersion") | ||
@Nullable Integer getPacketVersion(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
core/src/main/java/me/retrodaredevil/solarthing/solar/common/Shunt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package me.retrodaredevil.solarthing.solar.common; | ||
|
||
import me.retrodaredevil.solarthing.packets.identification.Identifiable; | ||
|
||
public interface Shunt extends Identifiable { | ||
} |
90 changes: 90 additions & 0 deletions
90
...src/main/java/me/retrodaredevil/solarthing/solar/pzem/ImmutablePzemShuntStatusPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package me.retrodaredevil.solarthing.solar.pzem; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import me.retrodaredevil.solarthing.annotations.NotNull; | ||
import me.retrodaredevil.solarthing.misc.common.DataIdentifier; | ||
import me.retrodaredevil.solarthing.packets.identification.IdentityInfo; | ||
|
||
public class ImmutablePzemShuntStatusPacket implements PzemShuntStatusPacket { | ||
private final DataIdentifier identifier; | ||
private final IdentityInfo identityInfo; | ||
private final int voltageValueRaw, currentValueRaw, powerValueRaw, energyValueRaw; | ||
private final int highVoltageAlarmStatus, lowVoltageAlarmStatus; | ||
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) { | ||
this.identifier = new DataIdentifier(dataId); | ||
this.identityInfo = new PzemShuntIdentityInfo(dataId); | ||
|
||
this.voltageValueRaw = voltageValueRaw; | ||
this.currentValueRaw = currentValueRaw; | ||
this.powerValueRaw = powerValueRaw; | ||
this.energyValueRaw = energyValueRaw; | ||
this.highVoltageAlarmStatus = highVoltageAlarmStatus; | ||
this.lowVoltageAlarmStatus = lowVoltageAlarmStatus; | ||
this.modbusAddress = modbusAddress; | ||
} | ||
public static ImmutablePzemShuntStatusPacket createFromReadTable(int dataId, int modbusAddress, PzemShuntReadTable read) { | ||
return new ImmutablePzemShuntStatusPacket( | ||
dataId, | ||
read.getVoltageValueRaw(), read.getCurrentValueRaw(), read.getPowerValueRaw(), read.getEnergyValueRaw(), | ||
read.getHighVoltageAlarmStatus(), read.getLowVoltageAlarmStatus(), | ||
modbusAddress | ||
); | ||
} | ||
@Override | ||
public @NotNull DataIdentifier getIdentifier() { | ||
return identifier; | ||
} | ||
|
||
@Override | ||
public @NotNull IdentityInfo getIdentityInfo() { | ||
return identityInfo; | ||
} | ||
|
||
@Override | ||
public int getDataId() { | ||
return identifier.getDataId(); | ||
} | ||
|
||
@Override | ||
public int getVoltageValueRaw() { | ||
return voltageValueRaw; | ||
} | ||
|
||
@Override | ||
public int getCurrentValueRaw() { | ||
return currentValueRaw; | ||
} | ||
|
||
@Override | ||
public int getPowerValueRaw() { | ||
return powerValueRaw; | ||
} | ||
|
||
@Override | ||
public int getEnergyValueRaw() { | ||
return energyValueRaw; | ||
} | ||
|
||
@Override | ||
public int getHighVoltageAlarmStatus() { | ||
return highVoltageAlarmStatus; | ||
} | ||
|
||
@Override | ||
public int getLowVoltageAlarmStatus() { | ||
return lowVoltageAlarmStatus; | ||
} | ||
|
||
@Override | ||
public int getModbusAddress() { | ||
return modbusAddress; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
core/src/main/java/me/retrodaredevil/solarthing/solar/pzem/PzemShuntIdentityInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package me.retrodaredevil.solarthing.solar.pzem; | ||
|
||
import me.retrodaredevil.solarthing.packets.identification.IdentityInfo; | ||
|
||
public class PzemShuntIdentityInfo implements IdentityInfo { | ||
private final int dataId; | ||
|
||
public PzemShuntIdentityInfo(int dataId) { | ||
this.dataId = dataId; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Pzem Shunt"; | ||
} | ||
|
||
@Override | ||
public String getSuffix() { | ||
return "" + dataId; | ||
} | ||
|
||
@Override | ||
public String getShortName() { | ||
return "PZ"; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
core/src/main/java/me/retrodaredevil/solarthing/solar/pzem/PzemShuntReadTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package me.retrodaredevil.solarthing.solar.pzem; | ||
|
||
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; | ||
|
||
public interface PzemShuntReadTable { | ||
SerialConfig SERIAL_CONFIG = new SerialConfigBuilder(9600).setDataBits(8).setStopBits(SerialConfig.StopBits.TWO).build(); | ||
|
||
@JsonProperty("voltageValueRaw") | ||
int getVoltageValueRaw(); | ||
default float getVoltage() { | ||
return getVoltageValueRaw() / 100.0f; | ||
} | ||
int getCurrentValueRaw(); | ||
default float getCurrentAmps() { | ||
return getCurrentValueRaw() / 100.0f; | ||
} | ||
int getPowerValueRaw(); | ||
default float getPowerWatts() { | ||
return getPowerValueRaw() / 10.0f; | ||
} | ||
|
||
int getEnergyValueRaw(); | ||
default int getEnergyWattHours() { return getEnergyValueRaw(); } | ||
default float getEnergyKWH() { return getEnergyValueRaw() / 1000.0f; } | ||
|
||
int getHighVoltageAlarmStatus(); | ||
int getLowVoltageAlarmStatus(); | ||
|
||
default boolean isHighVoltageAlarm() { return getHighVoltageAlarmStatus() != 0; } | ||
default boolean isLowVoltageAlarm() { return getLowVoltageAlarmStatus() != 0; } | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
core/src/main/java/me/retrodaredevil/solarthing/solar/pzem/PzemShuntStatusPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package me.retrodaredevil.solarthing.solar.pzem; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import me.retrodaredevil.solarthing.annotations.NotNull; | ||
import me.retrodaredevil.solarthing.misc.common.DataIdentifiable; | ||
import me.retrodaredevil.solarthing.solar.SolarStatusPacket; | ||
import me.retrodaredevil.solarthing.solar.SolarStatusPacketType; | ||
import me.retrodaredevil.solarthing.solar.common.Shunt; | ||
|
||
@JsonDeserialize(as = ImmutablePzemShuntStatusPacket.class) | ||
@JsonTypeName("PZEM_SHUNT") | ||
public interface PzemShuntStatusPacket extends SolarStatusPacket, PzemShuntReadTable, Shunt, DataIdentifiable { | ||
@Override | ||
default @NotNull SolarStatusPacketType getPacketType() { | ||
return SolarStatusPacketType.PZEM_SHUNT; | ||
} | ||
|
||
@JsonProperty("modbusAddress") | ||
int getModbusAddress(); | ||
} |
13 changes: 13 additions & 0 deletions
13
core/src/main/java/me/retrodaredevil/solarthing/solar/pzem/PzemShuntWriteTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package me.retrodaredevil.solarthing.solar.pzem; | ||
|
||
public interface PzemShuntWriteTable { | ||
void setHighVoltageAlarmThresholdRaw(int voltageRaw); | ||
void setLowVoltageAlarmThresholdRaw(int voltageRaw); | ||
void setModbusAddress(int modbusAddress); | ||
|
||
/** | ||
* Only works on PZEM-017s | ||
* @param currentRangeRawValue 0 is 100A, 1 is 50A, 2 is 200A, 3 is 300A | ||
*/ | ||
void setCurrentRangeRaw(int currentRangeRawValue); | ||
} |
Oops, something went wrong.