Skip to content

Commit

Permalink
Revert "changed the datatypes from s_int_16 to u_int_16 as specified …
Browse files Browse the repository at this point in the history
…in the Solis specification"

This reverts commit 0344b5e.
  • Loading branch information
ai-republic committed Dec 15, 2024
1 parent 0344b5e commit cfef1c5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ protected ByteBuffer prepareSendFrame(final int frameId, final byte cmd) {
private void readBatteryStatus(final BatteryPack pack, final ByteBuffer data) {
// frame id is already read, so start at the first data byte
// Battery voltage (0.1V)
pack.packVoltage = data.getChar();
pack.packVoltage = data.getShort();
// Battery current (0.1A) offset -3000A
pack.packCurrent = data.getChar() - 30000;
pack.packCurrent = data.getShort() - 30000;
// second level temperature (0.1 Celcius) offset -100C
pack.tempAverage = data.getChar() - 1000;
pack.tempAverage = data.getShort() - 1000;
// Battery SOC (1%)
pack.packSOC = data.get() * 10;
// Battery SOH (1%)
Expand All @@ -189,15 +189,15 @@ private void readBatteryStatus(final BatteryPack pack, final ByteBuffer data) {
// 0x4220
private void readChargeDischargeValues(final BatteryPack pack, final ByteBuffer data) {
// Charge cutoff voltage (0.1V)
pack.maxPackVoltageLimit = data.getChar();
pack.maxPackVoltageLimit = data.getShort();
// Discharge cutoff voltage (0.1V)
pack.minPackVoltageLimit = data.getChar();
pack.minPackVoltageLimit = data.getShort();

// TODO check if these should be swapped as described in Growatt_Battery_BMS.pdf
// Max charge current (0.1A) offset -3000A
pack.maxPackChargeCurrent = data.getChar() - 30000;
pack.maxPackChargeCurrent = data.getShort() - 30000;
// Max discharge current (0.1A) offset -3000A
pack.maxPackDischargeCurrent = data.getChar() - 30000;
pack.maxPackDischargeCurrent = data.getShort() - 30000;

LOG.debug("\nMaxLimit V\tMinLimit V\tMaxCharge A\tMaxDischarge\n{}V\t\t{}V\t\t{}A\t\t\t{}A", pack.maxPackVoltageLimit / 10f, pack.minPackVoltageLimit / 10f, pack.maxPackChargeCurrent / 10f, pack.maxPackDischargeCurrent / 10);
}
Expand All @@ -207,13 +207,13 @@ private void readChargeDischargeValues(final BatteryPack pack, final ByteBuffer
private void readCellVoltage(final BatteryPack pack, final ByteBuffer data) {
// frame id is already read, so start at the first data byte
// Maximum cell voltage (1mV)
pack.maxCellmV = data.getChar();
pack.maxCellmV = data.getShort();
// Minimum cell voltage (1mV)
pack.minCellmV = data.getChar();
pack.minCellmV = data.getShort();
// Maximum cell voltage cell number
pack.maxCellVNum = data.getChar();
pack.maxCellVNum = data.getShort();
// Minimum cell voltage cell number
pack.minCellVNum = data.getChar();
pack.minCellVNum = data.getShort();

LOG.debug("\nMaxCell V\tMinCell V\n{} (#{})\t{} (#{})", pack.maxCellmV / 1000f, pack.maxCellVNum, pack.minCellmV / 1000f, pack.minCellVNum);
}
Expand All @@ -223,13 +223,13 @@ private void readCellVoltage(final BatteryPack pack, final ByteBuffer data) {
private void readCellTemperature(final BatteryPack pack, final ByteBuffer data) {
// frame id is already read, so start at the first data byte
// Maximum cell temperature (0.1C) offset -100C
pack.tempMax = data.getChar() - 1000;
pack.tempMax = data.getShort() - 1000;
// Minimum cell temperature (0.1C) offset -100C
pack.tempMin = data.getChar() - 1000;
pack.tempMin = data.getShort() - 1000;
// Maximum cell temperature cell number
pack.tempMaxCellNum = data.getChar();
pack.tempMaxCellNum = data.getShort();
// Minimum cell temperature cell number
pack.tempMinCellNum = data.getChar();
pack.tempMinCellNum = data.getShort();

LOG.debug("\nMaxCell C\tMinCell C\n{}C (#{})\t{}C (#{})", pack.tempMax / 10f, pack.tempMaxCellNum, pack.tempMin / 10f, pack.tempMinCellNum);
}
Expand Down Expand Up @@ -304,9 +304,9 @@ private void readModuleVoltage(final BatteryPack pack, final ByteBuffer data) {
// minimum module voltage (0.001V)
pack.minModulemV = data.getChar();
// pack number with maximum module voltage
pack.maxModulemVNum = data.getChar();
pack.maxModulemVNum = data.getShort();
// pack number with minimum module voltage
pack.minModulemVNum = data.getChar();
pack.minModulemVNum = data.getShort();

LOG.debug("\nMaxModule V\tMinModule V\n{}V (#{})\t{}V (#{})", pack.maxModulemV / 1000f, pack.maxModulemVNum, pack.minModulemV / 1000f, pack.minModulemVNum);
}
Expand All @@ -315,13 +315,13 @@ private void readModuleVoltage(final BatteryPack pack, final ByteBuffer data) {
// 0x4270
private void readModuleTemperature(final BatteryPack pack, final ByteBuffer data) {
// maximum module temperature (0.1C) offset -100C
pack.maxModuleTemp = data.getChar() - 1000;
pack.maxModuleTemp = data.getShort() - 1000;
// minimum module temperature (0.1C) offset -100C
pack.minModuleTemp = data.getChar() - 1000;
pack.minModuleTemp = data.getShort() - 1000;
// pack number with maximum module temperature
pack.maxModuleTempNum = data.getChar();
pack.maxModuleTempNum = data.getShort();
// pack number with minimum module temperature
pack.minModuleTempNum = data.getChar();
pack.minModuleTempNum = data.getShort();

LOG.debug("\nMaxModule C\tMinModule C\n{}C (#{})\t{}C (#{})", pack.maxModuleTemp / 10f, pack.maxModuleTempNum, pack.minModuleTemp / 10f, pack.minModuleTempNum);
}
Expand Down Expand Up @@ -380,15 +380,15 @@ private void readHardwareSoftwareVersion(final BatteryPack pack, final ByteBuffe
// 0x7320
private void readBatterModuleInfo(final BatteryPack pack, final ByteBuffer data) {
// battery module quantity
pack.numberOfCells = data.getChar();
pack.numberOfCells = data.getShort();
// battery modules in series
pack.modulesInSeries = data.get();
// cell quantity in battery module
pack.moduleNumberOfCells = data.get();
// battery cabinet voltage level (1V)
pack.moduleVoltage = data.getChar();
pack.moduleVoltage = data.getShort();
// battery cabinet AH (1AH)
pack.moduleRatedCapacityAh = data.getChar();
pack.moduleRatedCapacityAh = data.getShort();

LOG.debug("\nNo of cells\tModules in Series\tModule No of Cells\tModule V\tModule Capacity Ah\n{}\t\t\t\t{}\t\t\t\t{}\t\t\t\t{}\t\t{}", pack.numberOfCells, pack.modulesInSeries, pack.moduleNumberOfCells, pack.moduleVoltage, pack.moduleRatedCapacityAh);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ private ByteBuffer sendBatteryStatus(final BatteryPack pack) throws IOException
final ByteBuffer frame = prepareSendFrame(0x00004210);

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

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

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

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

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

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

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

LOG.debug("Sending max/min cell temparatures: {}", Port.printBuffer(frame));
return frame;
Expand Down Expand Up @@ -301,9 +301,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.putChar((char) pack.maxModulemVNum);
frame.putShort((short) pack.maxModulemVNum);
// pack number with minimum module voltage
frame.putChar((char) pack.minModulemVNum);
frame.putShort((short) pack.minModulemVNum);

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

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

LOG.debug("Sending max/min module C: {}", Port.printBuffer(frame));
return frame;
Expand All @@ -347,7 +347,7 @@ private ByteBuffer sendBatteyVoltageSOCSOH(final BatteryPack pack) throws IOExce
final ByteBuffer frame = prepareSendFrame(0x00004210);

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

// fill 4 0x00 bytes
frame.put((byte) 0).put((byte) 0).put((byte) 0).put((byte) 0);
Expand Down Expand Up @@ -423,15 +423,15 @@ private ByteBuffer sendBatterModuleInfo(final BatteryPack pack) throws IOExcepti
final ByteBuffer frame = prepareSendFrame(0x00007320);

// battery module quantity
frame.putChar((char) pack.numberOfCells);
frame.putShort((short) pack.numberOfCells);
// battery modules in series
frame.put((byte) pack.modulesInSeries);
// cell quantity in battery module
frame.put(pack.moduleNumberOfCells);
// battery cabinet voltage level (1V)
frame.putChar((char) pack.moduleVoltage);
frame.putShort((short) pack.moduleVoltage);
// battery cabinet AH (1AH)
frame.putChar((char) pack.moduleRatedCapacityAh);
frame.putShort((short) pack.moduleRatedCapacityAh);

LOG.debug("Sending battery module info: {}", Port.printBuffer(frame));
return frame;
Expand Down

0 comments on commit cfef1c5

Please sign in to comment.