Skip to content

Commit

Permalink
fixed units for pylon hv
Browse files Browse the repository at this point in the history
  • Loading branch information
ai-republic committed Feb 23, 2024
1 parent 780a189 commit 9c3c14f
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,11 @@ private void getPackTemp(final DalyMessage msg, final BMS bms) throws IOExceptio
final int bmsNo = 0;
final BatteryPack battery = bms.getBatteryPack(bmsNo);

// byte 0 maximum temperature with offset of 40
battery.tempMax = msg.data.get(0) - 40;
// byte 2 minimum temperature with offset of 40
battery.tempMin = msg.data.get(2) - 40;
// maximum temperature (1C)with offset of 40
battery.tempMax = (msg.data.get(0) - 40) * 10;
// minimum temperature (1C)with offset of 40
battery.tempMin = (msg.data.get(2) - 40) * 10;
// calculate average temperature
battery.tempAverage = (battery.tempMax + battery.tempMin) / 2;

if (LOG.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ 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 (C) offset -50
pack.tempMax = data.get();
// Maximum cell temperature (1C) offset -50
pack.tempMax = (data.get() - 50) * 10;
// Maximum cell temperature cell number
data.get();
// Minimum cell temperature (C) offset -50
pack.tempMin = data.get();
// Minimum cell temperature (1C) offset -50
pack.tempMin = (data.get() - 50) * 10;
// Minimum cell temperature cell number
data.get();
// Average cell temperature (C) offset -50
pack.tempAverage = data.get();
// Average cell temperature (1C) offset -50
pack.tempAverage = (data.get() - 50) * 10;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,18 @@ private void readTemperatureIds(final BatteryPack pack, final ByteBuffer data) {

// 0x35E
private void readManufacturer(final BatteryPack pack, final ByteBuffer data) {
final char first = (char) data.get();
final char second = (char) data.get();
pack.manufacturerCode = "";
byte chr;

pack.manufacturerCode = "" + first + second;
do {
chr = data.get();

if (chr != 0x00) {
pack.manufacturerCode += (char) chr;
}
} while (chr != 0x00 && data.position() < data.capacity());

LOG.debug("Manufacturer", pack.manufacturerCode);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ private void readBatteryStatus(final BatteryPack pack, final ByteBuffer data) {
pack.packVoltage = data.getShort();
// Battery current (0.1A) offset -3000A
pack.packCurrent = data.getShort() - 30000;
// second level temperature (0.1 Celcius) offset -100
pack.tempAverage = data.getShort() / 10 - 100;
// second level temperature (0.1 Celcius) offset -100C
pack.tempAverage = data.getShort() - 1000;
// Battery SOC (1%)
pack.packSOC = data.get() * 10;
// Battery SOH (1%)
pack.packSOH = data.get() * 10;

LOG.debug("\nPack V\tPack A\tTempAvg\tPack SOC\tPack SOH\n{}V\t{}A\t{}C\t{}%\t{}%", pack.packVoltage / 10f, pack.packCurrent / 10f, pack.tempAverage, pack.packSOC / 10f, pack.packSOH / 10f);
LOG.debug("\nPack V\tPack A\tTempAvg\tPack SOC\tPack SOH\n{}V\t{}A\t{}C\t\t{}%\t{}%", pack.packVoltage / 10f, pack.packCurrent / 10f, pack.tempAverage, pack.packSOC / 10f, pack.packSOH / 10f);
}


Expand All @@ -179,11 +179,11 @@ private void readChargeDischargeValues(final BatteryPack pack, final ByteBuffer
// Discharge cutoff voltage (0.1V)
pack.minPackVoltageLimit = data.getShort();
// Max charge current (0.1A) offset -3000A
pack.maxPackChargeCurrent = 30000 - data.getShort();
pack.maxPackChargeCurrent = data.getShort() - 30000;
// Max discharge current (0.1A) offset -3000A
pack.maxPackDischargeCurrent = 30000 - data.getShort();
pack.maxPackDischargeCurrent = data.getShort() - 30000;

LOG.debug("\nMaxLimit V\tMinLimit V\tMaxCharge A\tMaxDischarge\n{}V\t{}V\t{}A\t{}A", pack.maxPackVoltageLimit / 10f, pack.minPackVoltageLimit / 10f, (pack.maxPackChargeCurrent + 3000) / 10f, (pack.maxPackDischargeCurrent + 3000) / 10);
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,9 +207,9 @@ 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.getShort() - 1000) / 10;
pack.tempMax = data.getShort() - 1000;
// Minimum cell temperature (0.1C) offset -100C
pack.tempMin = (data.getShort() - 1000) / 10;
pack.tempMin = data.getShort() - 1000;
// Maximum cell temperature cell number
pack.tempMaxCellNum = data.getShort();
// Minimum cell temperature cell number
Expand Down Expand Up @@ -305,10 +305,10 @@ private void readModuleVoltage(final BatteryPack pack, final ByteBuffer data) {

// 0x4270
private void readModuleTemperature(final BatteryPack pack, final ByteBuffer data) {
// maximum module temperature (0.1C)
pack.maxModuleTemp = data.getShort();
// minimum module temperature (0.1C)
pack.minModuleTemp = data.getShort();
// maximum module temperature (0.1C) offset -100C
pack.maxModuleTemp = data.getShort() - 1000;
// minimum module temperature (0.1C) offset -100C
pack.minModuleTemp = data.getShort() - 1000;
// pack number with maximum module temperature
pack.maxModuleTempNum = data.getShort();
// pack number with minimum module temperature
Expand Down Expand Up @@ -374,13 +374,13 @@ private void readBatterModuleInfo(final BatteryPack pack, final ByteBuffer data)
// battery modules in series
pack.modulesInSeries = data.get();
// cell quantity in battery module
pack.moduleNumberOfCells = data.get(3);
pack.moduleNumberOfCells = data.get();
// battery cabinet voltage level (1V)
pack.moduleVoltage = data.getShort();
// battery cabinet AH (1AH)
pack.moduleRatedCapacityAh = data.getShort();

LOG.debug("\nNo of cells\n{}", pack.numberOfCells);
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{}", pack.numberOfCells, pack.modulesInSeries, pack.moduleNumberOfCells, pack.moduleVoltage, pack.moduleRatedCapacityAh);
}


Expand All @@ -396,7 +396,7 @@ private void readManufacturer(final BatteryPack pack, final ByteBuffer data) {
}
} while (chr != 0x00 && data.position() < data.capacity());

LOG.debug("Manufacturer", pack.manufacturerCode);
LOG.debug("\nManufacturer\n{}", pack.manufacturerCode);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public class BatteryPack {
public int cellDiffmV;

// data from 0x92
/** Maximum temperature sensor reading (1C) */
/** Maximum temperature sensor reading (0.1C) */
public int tempMax;
/** Minimum temperature sensor reading (1C) */
/** Minimum temperature sensor reading (0.1C) */
public int tempMin;
/** Average of temp sensors (1C) */
/** Average of temp sensors (0.1C) */
public int tempAverage;

// data from 0x93
Expand Down Expand Up @@ -121,28 +121,28 @@ public class BatteryPack {
public int tempMinCellNum;

/** The maximum module voltage (0.001V) of a pack */
public short maxModulemV;
public int maxModulemV;
/** The minimum module voltage (0.001V) of a pack */
public short minModulemV;
public int minModulemV;
/** The number of the pack with the maximum voltage */
public short maxModulemVNum;
public int maxModulemVNum;
/** The number of the pack with the minimum voltage */
public short minModulemVNum;
public int minModulemVNum;
/** The maximum module temperature (0.1C) */
public short maxModuleTemp;
public int maxModuleTemp;
/** The minimum module temperature (0.1C) */
public short minModuleTemp;
public int minModuleTemp;
/** The pack number with maximum module temperature */
public short maxModuleTempNum;
public int maxModuleTempNum;
/** The pack number with minimum module temperature */
public short minModuleTempNum;
public int minModuleTempNum;
/** The number of battery modules in series */
public byte modulesInSeries;
/** The number of cells in a module */
public byte moduleNumberOfCells;
/** The module voltage (1V) */
public short moduleVoltage;
public int moduleVoltage;
/** The rated capacity of the module (1Ah) */
public short moduleRatedCapacityAh;
public int moduleRatedCapacityAh;

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private ByteBuffer createSOC() {
private ByteBuffer createBatteryVoltage() {
final int aggregatedPackVoltage = (int) energyStorage.getBatteryPacks().stream().mapToInt(pack -> pack.packVoltage).average().orElse(500) * 10;
final int aggregatedPackCurrent = energyStorage.getBatteryPacks().stream().mapToInt(pack -> pack.packCurrent).sum();
final int aggregatedPackTemperature = (int) energyStorage.getBatteryPacks().stream().mapToInt(pack -> pack.tempMax).average().orElse(35) * 10;
final int aggregatedPackTemperature = (int) energyStorage.getBatteryPacks().stream().mapToInt(pack -> pack.tempMax).average().orElse(300);

final ByteBuffer frame = ByteBuffer.allocateDirect(16);
frame.putInt(0x0356)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private byte getChargeStates() {
private ByteBuffer createBatteryVoltage() {
final int aggregatedPackVoltage = (int) energyStorage.getBatteryPacks().stream().mapToInt(pack -> pack.packVoltage).average().orElse(500) * 10;
final int aggregatedPackCurrent = energyStorage.getBatteryPacks().stream().mapToInt(pack -> pack.packCurrent).sum();
final int aggregatedPackTemperature = (int) energyStorage.getBatteryPacks().stream().mapToInt(pack -> pack.tempMax).average().orElse(35) * 10;
final int aggregatedPackTemperature = (int) energyStorage.getBatteryPacks().stream().mapToInt(pack -> pack.tempMax).average().orElse(300);
final byte aggregatedSOC = (byte) (energyStorage.getBatteryPacks().stream().mapToInt(pack -> pack.packSOC).average().orElse(500) / 10);
final byte aggregatedSOH = (byte) (energyStorage.getBatteryPacks().stream().mapToInt(pack -> pack.packSOH).average().orElse(500) / 10);

Expand Down Expand Up @@ -416,7 +416,7 @@ public static void main(final String[] args) {
pack.packCurrent = 15;
pack.packSOC = 940;
pack.packSOH = 1000;
pack.tempMax = 22;
pack.tempMax = 220;
final EnergyStorage es = new EnergyStorage();
es.getBatteryPacks().add(pack);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ private void sendBatteryStatus(final Port port, final int bmsNo) throws IOExcept
frame.putShort((short) pack.packVoltage);
// Battery current (0.1A) offset -3000A
frame.putShort((short) (pack.packCurrent + 30000));
// second level temperature (0.1 Celcius) offset -100
frame.putShort((short) ((pack.tempAverage - 100) * 10));
// second level temperature (0.1 Celcius) offset -100C
frame.putShort((short) (pack.tempAverage + 1000));
// Battery SOC (1%)
frame.put((byte) (pack.packSOC / 10));
// Battery SOH (1%)
Expand Down Expand Up @@ -197,9 +197,9 @@ private void sendMaxMinCellTemperatures(final Port port, final int bmsNo) throws
final ByteBuffer frame = prepareSendFrame(0x00004240 | bmsNo);

// Maximum cell temperature (0.1C) offset -100C
frame.putShort((short) ((pack.tempMax + 100) * 10));
// Minimum cell temperature (0.1C) offset -100
frame.putShort((short) ((pack.tempMin + 100) * 10));
frame.putShort((short) (pack.tempMax + 1000));
// Minimum cell temperature (0.1C) offset -100C
frame.putShort((short) (pack.tempMin + 1000));
// Maximum cell temperature cell number
frame.putShort((short) pack.tempMaxCellNum);
// Minimum cell temperature cell number
Expand Down Expand Up @@ -304,13 +304,13 @@ private void sendMaxMinModuleVoltages(final Port port, final int bmsNo) throws I
final ByteBuffer frame = prepareSendFrame(0x00004260 | bmsNo);

// maximum module voltage (0.001V)
frame.putShort(pack.maxModulemV);
frame.putShort((short) pack.maxModulemV);
// minimum module voltage (0.001V)
frame.putShort(pack.minModulemV);
frame.putShort((short) pack.minModulemV);
// pack number with maximum module voltage
frame.putShort(pack.maxModulemVNum);
frame.putShort((short) pack.maxModulemVNum);
// pack number with minimum module voltage
frame.putShort(pack.minModulemVNum);
frame.putShort((short) pack.minModulemVNum);

LOG.debug("Sending max/min module V: {}", Port.printBuffer(frame));
sendFrame(port, frame);
Expand All @@ -322,14 +322,14 @@ private void sendMaxMinModuleTemperatures(final Port port, final int bmsNo) thro
final BatteryPack pack = energyStorage.getBatteryPack(bmsNo);
final ByteBuffer frame = prepareSendFrame(0x00004270 | bmsNo);

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

LOG.debug("Sending max/min module C: {}", Port.printBuffer(frame));
sendFrame(port, frame);
Expand Down Expand Up @@ -420,9 +420,9 @@ private void sendBatterModuleInfo(final Port port, final int bmsNo) throws IOExc
// cell quantity in battery module
frame.put(pack.moduleNumberOfCells);
// battery cabinet voltage level (1V)
frame.putShort(pack.moduleVoltage);
frame.putShort((short) pack.moduleVoltage);
// battery cabinet AH (1AH)
frame.putShort(pack.moduleRatedCapacityAh);
frame.putShort((short) pack.moduleRatedCapacityAh);

LOG.debug("Sending battery module info: {}", Port.printBuffer(frame));
sendFrame(port, frame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected List<ByteBuffer> createSendFrames() {

final short batteryVoltage = (short) (energyStorage.getBatteryPacks().stream().map(pack -> pack.packVoltage).filter(volt -> volt != 0).min((v1, v2) -> v1.compareTo(v2)).orElse(520) * 10);
final short batteryCurrent = (short) energyStorage.getBatteryPacks().stream().mapToInt(b -> b.packCurrent).sum();
final short batteryTemperature = (short) (energyStorage.getBatteryPacks().stream().mapToInt(b -> b.tempAverage).average().orElseGet(() -> 35d) * 10); // 35degC
final short batteryTemperature = (short) energyStorage.getBatteryPacks().stream().mapToInt(b -> b.tempAverage).average().orElseGet(() -> 350d); // 35degC

// battery voltage (0.01V) - s_int_16
frame.putShort(batteryVoltage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private ByteBuffer createSOC() {
private ByteBuffer createBatteryVoltage() {
final int aggregatedPackVoltage = (int) energyStorage.getBatteryPacks().stream().mapToInt(pack -> pack.packVoltage).average().orElse(500) * 10;
final int aggregatedPackCurrent = energyStorage.getBatteryPacks().stream().mapToInt(pack -> pack.packCurrent).sum();
final int aggregatedPackTemperature = (int) energyStorage.getBatteryPacks().stream().mapToInt(pack -> pack.tempMax).average().orElse(35) * 10;
final int aggregatedPackTemperature = (int) energyStorage.getBatteryPacks().stream().mapToInt(pack -> pack.tempMax).average().orElse(300);

final ByteBuffer frame = prepareFrame(0x356);

Expand Down Expand Up @@ -169,7 +169,7 @@ public static void main(final String[] args) {
pack.packCurrent = 15;
pack.packSOC = 94;
pack.packSOH = 100;
pack.tempMax = 22;
pack.tempMax = 220;
final EnergyStorage es = new EnergyStorage();
es.getBatteryPacks().add(pack);

Expand Down

0 comments on commit 9c3c14f

Please sign in to comment.