Skip to content

Commit

Permalink
corrected offset for min max cell temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
ai-republic committed Dec 27, 2024
1 parent ec3ca9b commit 41435bc
Showing 1 changed file with 21 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ private List<ByteBuffer> sendEnsembleInformation(final BatteryPack pack) throws
sendFrames.add(sendMaxMinModuleTemperatures(pack));
// 0x4280
sendFrames.add(sendChargeForbiddenMarks(pack));
// 0x42B0
sendFrames.add(sendBatteyVoltageSOCSOH(pack));

return sendFrames;
}
Expand All @@ -134,11 +132,11 @@ private ByteBuffer sendBatteryStatus(final BatteryPack pack) throws IOException
final ByteBuffer frame = prepareSendFrame(0x00004210);

// Battery voltage (0.1V)
frame.putShort((short) pack.packVoltage);
frame.putChar((char) pack.packVoltage);
// Battery current (0.1A) offset -3000A
frame.putShort((short) (pack.packCurrent + 30000));
frame.putChar((char) (pack.packCurrent + 30000));
// second level temperature (0.1 Celcius) offset -100C
frame.putShort((short) (pack.tempAverage + 1000));
frame.putChar((char) (pack.tempAverage + 1000));
// Battery SOC (1%)
frame.put((byte) (pack.packSOC / 10));
// Battery SOH (1%)
Expand All @@ -154,15 +152,15 @@ private ByteBuffer sendChargeDischargeLimits(final BatteryPack pack) throws IOEx
final ByteBuffer frame = prepareSendFrame(0x00004220);

// Charge cutoff voltage (0.1V)
frame.putShort((short) pack.maxPackVoltageLimit);
frame.putChar((char) pack.maxPackVoltageLimit);
// Discharge cutoff voltage (0.1V)
frame.putShort((short) pack.minPackVoltageLimit);
frame.putChar((char) pack.minPackVoltageLimit);

// TODO check if these should be swapped as described in Growatt_Battery_BMS.pdf
// Max charge current (0.1A) offset -3000A
frame.putShort((short) (pack.maxPackChargeCurrent + 30000));
frame.putChar((char) (pack.maxPackChargeCurrent + 30000));
// Max discharge current (0.1A) offset -3000A
frame.putShort((short) (pack.maxPackDischargeCurrent + 30000));
frame.putChar((char) (pack.maxPackDischargeCurrent + 30000));

LOG.debug("Sending max/min voltage, current, charge and discharge limits: {}", Port.printBuffer(frame));
return frame;
Expand All @@ -174,13 +172,13 @@ private ByteBuffer sendMaxMinCellVoltages(final BatteryPack pack) throws IOExcep
final ByteBuffer frame = prepareSendFrame(0x00004230);

// Maximum cell voltage (0.001V)
frame.putShort((short) pack.maxCellmV);
frame.putChar((char) pack.maxCellmV);
// Minimum cell voltage (0.001V)
frame.putShort((short) pack.minCellmV);
frame.putChar((char) pack.minCellmV);
// Cell no with maximum voltage
frame.putShort((short) pack.maxCellVNum);
frame.putChar((char) pack.maxCellVNum);
// Cell no with minimum voltage
frame.putShort((short) pack.minCellVNum);
frame.putChar((char) pack.minCellVNum);

LOG.debug("Sending max/min cell voltages: {}", Port.printBuffer(frame));
return frame;
Expand All @@ -192,13 +190,13 @@ private ByteBuffer sendMaxMinCellTemperatures(final BatteryPack pack) throws IOE
final ByteBuffer frame = prepareSendFrame(0x00004240);

// Maximum cell temperature (0.1C) offset -100C
frame.putShort((short) (pack.tempMax - 100));
frame.putChar((char) (pack.tempMax + 1000));
// Minimum cell temperature (0.1C) offset -100C
frame.putShort((short) (pack.tempMin - 100));
frame.putChar((char) (pack.tempMin + 1000));
// Maximum cell temperature cell number
frame.putShort((short) pack.tempMaxCellNum);
frame.putChar((char) pack.tempMaxCellNum);
// Minimum cell temperature cell number
frame.putShort((short) pack.tempMinCellNum);
frame.putChar((char) pack.tempMinCellNum);

LOG.debug("Sending max/min cell temparatures: {}", Port.printBuffer(frame));
return frame;
Expand Down Expand Up @@ -301,9 +299,9 @@ private ByteBuffer sendMaxMinModuleVoltages(final BatteryPack pack) throws IOExc
// minimum module voltage (0.001V)
frame.putChar((char) pack.minModulemV);
// pack number with maximum module voltage
frame.putShort((short) pack.maxModulemVNum);
frame.putChar((char) pack.maxModulemVNum);
// pack number with minimum module voltage
frame.putShort((short) pack.minModulemVNum);
frame.putChar((char) pack.minModulemVNum);

LOG.debug("Sending max/min module V: {}", Port.printBuffer(frame));
return frame;
Expand All @@ -315,13 +313,13 @@ private ByteBuffer sendMaxMinModuleTemperatures(final BatteryPack pack) throws I
final ByteBuffer frame = prepareSendFrame(0x00004270);

// maximum module temperature (0.1C) offset -100C
frame.putShort((short) (pack.maxModuleTemp + 1000));
frame.putChar((char) (pack.maxModuleTemp + 1000));
// minimum module temperature (0.1C) offset -100C
frame.putShort((short) (pack.minModuleTemp + 1000));
frame.putChar((char) (pack.minModuleTemp + 1000));
// pack number with maximum module temperature
frame.putShort((short) pack.maxModuleTempNum);
frame.putChar((char) pack.maxModuleTempNum);
// pack number with minimum module temperature
frame.putShort((short) pack.minModuleTempNum);
frame.putChar((char) pack.minModuleTempNum);

LOG.debug("Sending max/min module C: {}", Port.printBuffer(frame));
return frame;
Expand All @@ -342,26 +340,6 @@ private ByteBuffer sendChargeForbiddenMarks(final BatteryPack pack) throws IOExc
}


// 0x42B0
private ByteBuffer sendBatteyVoltageSOCSOH(final BatteryPack pack) throws IOException {
final ByteBuffer frame = prepareSendFrame(0x00004210);

// Battery voltage (0.1V)
frame.putShort((short) pack.packVoltage);

// fill 4 0x00 bytes
frame.put((byte) 0).put((byte) 0).put((byte) 0).put((byte) 0);

// Battery SOC (1%)
frame.put((byte) (pack.packSOC / 10));
// Battery SOH (1%)
frame.put((byte) (pack.packSOH / 10));

LOG.debug("Sending battery status: {}", Port.printBuffer(frame));
return frame;
}


// 0x7310
private ByteBuffer sendHardwareSoftwareVersion(final BatteryPack pack) throws IOException {
final ByteBuffer frame = prepareSendFrame(0x00007310);
Expand Down

0 comments on commit 41435bc

Please sign in to comment.