Skip to content

Commit

Permalink
fixed batterypack access for modbus BMSes
Browse files Browse the repository at this point in the history
  • Loading branch information
ai-republic committed Oct 22, 2024
1 parent d97a438 commit 8eaa93e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@
import com.airepublic.bmstoinverter.core.Port;
import com.airepublic.bmstoinverter.core.bms.data.Alarm;
import com.airepublic.bmstoinverter.core.bms.data.BatteryPack;
import com.airepublic.bmstoinverter.core.bms.data.EnergyStorage;
import com.airepublic.bmstoinverter.core.util.Util;
import com.airepublic.bmstoinverter.protocol.modbus.ModbusUtil;
import com.airepublic.bmstoinverter.protocol.modbus.ModbusUtil.RegisterCode;

import jakarta.inject.Inject;

/**
* The class to handle Modbus messages from a Huawei {@link BMS}.
*/
public class HuaweiBmsModbusProcessor extends BMS {
private final static Logger LOG = LoggerFactory.getLogger(HuaweiBmsModbusProcessor.class);
@Inject
private EnergyStorage energyStorage;

@Override
protected void collectData(final Port port) {
Expand All @@ -58,7 +53,7 @@ protected void readBatteryStatus(final ByteBuffer frame) {
frame.getInt(); // functionCode
frame.getInt(); // numRegisters
final int unitId = frame.getInt();
final BatteryPack pack = energyStorage.getBatteryPack(unitId);
final BatteryPack pack = getBatteryPack(unitId);

pack.numberOfCells = frame.getChar();
frame.getShort(); // device status
Expand Down Expand Up @@ -86,7 +81,7 @@ private void readAlarms(final ByteBuffer frame) {
frame.getInt(); // functionCode
frame.getInt(); // numRegisters
final int unitId = frame.getInt();
final BatteryPack pack = energyStorage.getBatteryPack(unitId - 1);
final BatteryPack pack = getBatteryPack(unitId);

final short bits39014 = frame.getShort();
final short bits39015 = frame.getShort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@
import com.airepublic.bmstoinverter.core.Port;
import com.airepublic.bmstoinverter.core.bms.data.Alarm;
import com.airepublic.bmstoinverter.core.bms.data.BatteryPack;
import com.airepublic.bmstoinverter.core.bms.data.EnergyStorage;
import com.airepublic.bmstoinverter.core.util.Util;
import com.airepublic.bmstoinverter.protocol.modbus.ModbusUtil;
import com.airepublic.bmstoinverter.protocol.modbus.ModbusUtil.RegisterCode;

import jakarta.inject.Inject;

/**
* The class to handle Modbus messages from a JK {@link BMS}.
*/
public class JKBmsModbusProcessor extends BMS {
private final static Logger LOG = LoggerFactory.getLogger(JKBmsModbusProcessor.class);
@Inject
private EnergyStorage energyStorage;

@Override
protected void collectData(final Port port) {
Expand All @@ -60,7 +55,7 @@ protected void readBatteryStatus(final ByteBuffer frame) {
frame.getInt(); // functionCode
frame.getInt(); // numRegisters
final int unitId = frame.getInt();
final BatteryPack pack = energyStorage.getBatteryPack(unitId);
final BatteryPack pack = getBatteryPack(unitId);

pack.numberOfCells = frame.getInt();
pack.chargeMOSState = frame.getInt() == 1;
Expand All @@ -74,7 +69,7 @@ private void readVoltCurrentTemp(final ByteBuffer frame) {
frame.getInt(); // functionCode
frame.getInt(); // numRegisters
final int unitId = frame.getInt();
final BatteryPack pack = energyStorage.getBatteryPack(unitId);
final BatteryPack pack = getBatteryPack(unitId);

// voltage in mV
pack.packVoltage = frame.getInt() / 100;
Expand All @@ -91,7 +86,7 @@ protected void readSOC(final ByteBuffer frame) {
frame.getInt(); // functionCode
frame.getInt(); // numRegisters
final int unitId = frame.getInt();
final BatteryPack pack = energyStorage.getBatteryPack(unitId);
final BatteryPack pack = getBatteryPack(unitId);

// SOC in 1%
pack.packSOC = (frame.getInt() & 0xF0) >> 8;
Expand All @@ -102,7 +97,7 @@ private void readAlarms(final ByteBuffer frame) {
frame.getInt(); // functionCode
frame.getInt(); // numRegisters
final int unitId = frame.getInt();
final BatteryPack pack = energyStorage.getBatteryPack(unitId - 1);
final BatteryPack pack = getBatteryPack(unitId);

final int bits = frame.getInt();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@
import com.airepublic.bmstoinverter.core.Port;
import com.airepublic.bmstoinverter.core.bms.data.Alarm;
import com.airepublic.bmstoinverter.core.bms.data.BatteryPack;
import com.airepublic.bmstoinverter.core.bms.data.EnergyStorage;
import com.airepublic.bmstoinverter.core.util.Util;
import com.airepublic.bmstoinverter.protocol.modbus.ModbusUtil;
import com.airepublic.bmstoinverter.protocol.modbus.ModbusUtil.RegisterCode;

import jakarta.inject.Inject;

/**
* The class to handle Modbus messages from a Tian {@link BMS}.
*/
public class TianBmsModbusProcessor extends BMS {
private final static Logger LOG = LoggerFactory.getLogger(TianBmsModbusProcessor.class);
@Inject
private EnergyStorage energyStorage;

@Override
protected void collectData(final Port port) {
Expand All @@ -57,7 +52,7 @@ protected void readBatteryData(final ByteBuffer frame) {
frame.getInt(); // functionCode
frame.getInt(); // numRegisters
final int unitId = frame.getInt();
final BatteryPack pack = energyStorage.getBatteryPack(unitId);
final BatteryPack pack = getBatteryPack(unitId);

// pack voltage 0.01V
pack.packVoltage = frame.getInt() / 10;
Expand Down

0 comments on commit 8eaa93e

Please sign in to comment.