Skip to content

Commit

Permalink
Merge pull request #148 from s10l/feat_voltage_thresholds
Browse files Browse the repository at this point in the history
Add pack voltage thresholds
  • Loading branch information
softwarecrash authored Dec 30, 2023
2 parents e5d8f6e + 03458aa commit 3a3c0cb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/daly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ bool DalyBms::loop()
case 10:
if (!getStaticData)
requestCounter = getVoltageThreshold() ? (requestCounter + 1) : 0;
requestCallback();
break;
case 11:
if (!getStaticData)
requestCounter = getPackVoltageThreshold() ? (requestCounter + 1) : 0;
requestCounter = 0;
requestCallback();
getStaticData = true;
Expand Down Expand Up @@ -128,6 +133,23 @@ bool DalyBms::getVoltageThreshold() // 0x59
return true;
}

bool DalyBms::getPackVoltageThreshold() // 0x5A
{
if (!this->requestData(COMMAND::PACK_THRESHOLDS, 1))
{
BMS_DEBUG_PRINT("<DALY-BMS DEBUG> Receive failed, min/max pack voltage thresholds won't be modified!\n");
BMS_DEBUG_WEB("<DALY-BMS DEBUG> Receive failed, min/max pack voltage thresholds won't be modified!\n");
return false;
}

get.maxPackThreshold1 = (float)((this->frameBuff[0][4] << 8) | this->frameBuff[0][5]);
get.maxPackThreshold2 = (float)((this->frameBuff[0][6] << 8) | this->frameBuff[0][7]);
get.minPackThreshold1 = (float)((this->frameBuff[0][8] << 8) | this->frameBuff[0][9]);
get.minPackThreshold2 = (float)((this->frameBuff[0][10] << 8) | this->frameBuff[0][11]);

return true;
}

bool DalyBms::getPackMeasurements() // 0x90
{
if (!this->requestData(COMMAND::VOUT_IOUT_SOC, 1))
Expand Down
13 changes: 13 additions & 0 deletions src/daly.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class DalyBms
enum COMMAND
{
CELL_THRESHOLDS = 0x59,
PACK_THRESHOLDS = 0x5A,
VOUT_IOUT_SOC = 0x90,
MIN_MAX_CELL_VOLTAGE = 0x91,
MIN_MAX_TEMPERATURE = 0x92,
Expand Down Expand Up @@ -93,6 +94,12 @@ class DalyBms
float maxCellThreshold2; // Level-2 alarm threshold for High Voltage in Millivolts
float minCellThreshold2; // Level-2 alarm threshold for low Voltage in Millivolts

// data from 0x5A
float maxPackThreshold1; // Level-1 alarm threshold for high voltage in decivolts
float minPackThreshold1; // Level-1 alarm threshold for low voltage in decivolts
float maxPackThreshold2; // Level-2 alarm threshold for high voltage in decivolts
float minPackThreshold2; // Level-2 alarm threshold for low voltage in decivolts

// data from 0x90
float packVoltage; // pressure (0.1 V)
float packCurrent; // acquisition (0.1 V)
Expand Down Expand Up @@ -253,6 +260,12 @@ class DalyBms
*/
bool getVoltageThreshold();

/**
* @brief Gets pack voltage thresholds
* @return True on successful aquisition, false otherwise
*/
bool getPackVoltageThreshold();

/**
* @brief Gets the pack temperature from the min and max of all the available temperature sensors
* @details Populates tempMax, tempMax, and tempAverage in the "get" struct
Expand Down
6 changes: 6 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,12 @@ void getJsonData()
packJson[F("Cell_Temp")] = bms.get.cellTemperature[0];
packJson[F("cell_hVt")] = bms.get.maxCellThreshold1 / 1000;
packJson[F("cell_lVt")] = bms.get.minCellThreshold1 / 1000;
packJson[F("cell_hVt2")] = bms.get.maxCellThreshold2 / 1000;
packJson[F("cell_lVt2")] = bms.get.minCellThreshold2 / 1000;
packJson[F("pack_hVt")] = bms.get.maxPackThreshold1 / 10;
packJson[F("pack_lVt")] = bms.get.minPackThreshold1 / 10;
packJson[F("pack_hVt2")] = bms.get.maxPackThreshold2 / 10;
packJson[F("pack_lVt2")] = bms.get.minPackThreshold2 / 10;
packJson[F("High_CellNr")] = bms.get.maxCellVNum;
packJson[F("High_CellV")] = bms.get.maxCellmV / 1000;
packJson[F("Low_CellNr")] = bms.get.minCellVNum;
Expand Down

0 comments on commit 3a3c0cb

Please sign in to comment.