Skip to content

Commit

Permalink
Liveview cleaned, only shows up when connected & better code , elimin…
Browse files Browse the repository at this point in the history
…ated get-Struct, cleaned code
  • Loading branch information
xpertsavenue committed Feb 24, 2024
1 parent b4fc542 commit c19cc3c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 504 deletions.
7 changes: 3 additions & 4 deletions include/BatteryStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,19 @@ class DalyBatteryStats : public BatteryStats {
float _minCellmV;
uint8_t _minCellVNum;
float _cellDiff;
std::string _dischargechargemosstate;
std::string _state;
uint8_t _numberOfCells;
uint8_t _numOfTempSensors;
uint8_t _chargeState;
uint8_t _loadState;
uint8_t _chargeFetState;
uint8_t _dischargeFetState;
bool _chargeFetState;
bool _dischargeFetState;
int _bmsHeartBeat;
float _resCapacityAh;
int _bmsCycles;
float _cellVmV[48];
bool _cellBalanceActive;
bool _connectionState;
String _failCodeString;
};

class JkBmsBatteryStats : public BatteryStats {
Expand Down
98 changes: 0 additions & 98 deletions include/DalyBms.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,85 +55,13 @@ class DalyBms : public BatteryProvider {
//after request the pc soft hangs a 0xD8 as last request, its empty, dont know what it means?
};

/**
* @brief get struct holds all the data collected from the BMS and is populated using the update() API
*/
struct
{
// data from 0x59
float maxCellThreshold1; // Level-1 alarm threshold for High Voltage in Millivolts
float minCellThreshold1; // Level-1 alarm threshold for low Voltage in Millivolts
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)
float packSOC; // State Of Charge

// data from 0x91
float maxCellmV; // maximum monomer voltage (mV)
int maxCellVNum; // Maximum Unit Voltage cell No.
float minCellmV; // minimum monomer voltage (mV)
int minCellVNum; // Minimum Unit Voltage cell No.
int cellDiff; // difference betwen cells

// data from 0x92
int tempAverage; // Avergae Temperature

// data from 0x93
const char *chargeDischargeStatus; // charge/discharge status (0 stationary ,1 charge ,2 discharge)
bool chargeFetState; // charging MOS tube status
bool disChargeFetState; // discharge MOS tube state
int bmsHeartBeat; // BMS life(0~255 cycles)
float resCapacityAh; // residual capacity mAH

// data from 0x94
unsigned int numberOfCells; // amount of cells
unsigned int numOfTempSensors; // amount of temp sensors
bool chargeState; // charger status 0=disconnected 1=connected
bool loadState; // Load Status 0=disconnected 1=connected
int bmsCycles; // charge / discharge cycles

// data from 0x95
float cellVmV[48]; // Store Cell Voltages in mV

// data from 0x96
int cellTemperature[16]; // array of cell Temperature sensors

// data from 0x97
bool cellBalanceState[48]; // bool array of cell balance states
bool cellBalanceActive; // bool is cell balance active

// get a state of the connection
bool connectionState;

} get;

/**
* @brief Gets Voltage, Current, and SOC measurements from the BMS
* @return True on successful aquisition, false otherwise
*/
bool getPackMeasurements();

/**
* @brief Gets Voltage thresholds
* @return True on successful aquisition, false otherwise
*/
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 All @@ -160,32 +88,6 @@ class DalyBms : public BatteryProvider {
*/
bool getCellVoltages();

/**
* @brief Each temperature accounts for 1 byte, according to the
actual number of temperature send, the maximum 21
byte, send in 3 frames
Byte0:frame number, starting at 0
Byte1~byte7:cell temperature(40 Offset ,℃)
*
*/
bool getCellTemperature();

/**
* @brief 0: Closed 1: Open
Bit0: Cell 1 balance state
...
Bit47:Cell 48 balance state
Bit48~Bit63:reserved
*
*/
bool getCellBalanceState();

/**
* @brief Get the Failure Codes
*
*/
bool getFailureCodes();

/**
* @brief
* set the Discharging MOS State
Expand Down
29 changes: 16 additions & 13 deletions src/BatteryStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,22 @@ void DalyBatteryStats::getLiveViewData(JsonVariant& root) const
{
BatteryStats::getLiveViewData(root);

if (_connectionState==true){
// values go into the "Status" card of the web application
addLiveViewValue(root, "voltage", _voltage, "V", 2);
addLiveViewValue(root, "current", _current, "A", 1);
addLiveViewValue(root, "temperature", _temperature, "°C", 1);
addLiveViewTextValue(root, "status", _dischargechargemosstate);
addLiveViewValue(root, "cellMaxVoltage", _maxCellmV, "mV", 0);
addLiveViewValue(root, "cellMinVoltage", _minCellmV, "mV", 0);
addLiveViewValue(root, "cellDiffVoltage", _cellDiff, "mV", 0);
addLiveViewValue(root, "chargeEnabled", _chargeFetState, "", 0);
addLiveViewValue(root, "dischargeEnabled", _dischargeFetState, "", 0);
addLiveViewValue(root, "chargeCycles", _bmsCycles,"",0);
addLiveViewValue(root, "remainingAh", _resCapacityAh,"Ah",1);
addLiveViewValue(root, "voltage", _voltage, "V", 2);
addLiveViewValue(root, "current", _current, "A", 1);
addLiveViewValue(root, "temperature", _temperature, "°C", 1);
addLiveViewTextValue(root, "status", _state);
addLiveViewValue(root, "cellMaxVoltage", _maxCellmV, "mV", 0);
addLiveViewValue(root, "cellMinVoltage", _minCellmV, "mV", 0);
addLiveViewValue(root, "cellDiffVoltage", _cellDiff, "mV", 0);
addLiveViewTextValue(root, "chargeEnabled", (_chargeFetState?"yes":"no"));
addLiveViewTextValue(root, "dischargeEnabled", (_dischargeFetState?"yes":"no"));
addLiveViewValue(root, "chargeCycles", _bmsCycles,"",0);
addLiveViewValue(root, "remainingAh", _resCapacityAh,"Ah",1);
} else {

}
}

void JkBmsBatteryStats::getJsonData(JsonVariant& root, bool verbose) const
Expand Down Expand Up @@ -281,15 +285,14 @@ void DalyBatteryStats::mqttPublish() const
MqttSettings.publish(F("battery/maxCellmV"), String(_maxCellmV));
MqttSettings.publish(F("battery/maxCellmVNum"), String(_maxCellVNum));
MqttSettings.publish(F("battery/cellmVDrift"), String(_cellDiff));
//MqttSettings.publish(F("battery/status"), String(_dischargechargemosstate));
MqttSettings.publish(F("battery/status"), _state.c_str());
MqttSettings.publish(F("battery/chargeFetState"), String(_chargeFetState));
MqttSettings.publish(F("battery/dischargeFetState"), String(_dischargeFetState));
MqttSettings.publish(F("battery/numberOfCells"), String(_numberOfCells));
MqttSettings.publish(F("battery/numOfTempSensors"), String(_numOfTempSensors));
MqttSettings.publish(F("battery/chargeState"), String(_cellDiff));
MqttSettings.publish(F("battery/loadState"), String(_loadState));
MqttSettings.publish(F("battery/cycles"), String(_bmsCycles));
MqttSettings.publish(F("battery/failures"), _failCodeString);
MqttSettings.publish(F("battery/remainingAh"), String(_resCapacityAh));
MqttSettings.publish(F("battery/bmsHeartBeat"), String(_bmsHeartBeat));
for (uint8_t c = 0; c<_numberOfCells;c++){
Expand Down
Loading

0 comments on commit c19cc3c

Please sign in to comment.