Add more battery info page for CMFA

This commit is contained in:
Daniel Öster 2025-03-31 15:18:53 +03:00
parent 9b77b135b6
commit 9626c04233
4 changed files with 77 additions and 21 deletions

View file

@ -1,6 +1,7 @@
#include "../include.h"
#ifdef CMFA_EV_BATTERY
#include "../datalayer/datalayer.h"
#include "../datalayer/datalayer_extended.h"
#include "../devboard/utils/events.h"
#include "CMFA-EV-BATTERY.h"
@ -42,12 +43,14 @@ CAN_frame CMFA_POLLING_FRAME = {.FD = false,
static uint32_t average_voltage_of_cells = 270000;
static uint16_t highest_cell_voltage_mv = 3700;
static uint16_t leadAcidBatteryVoltage = 12000;
static uint16_t highest_cell_voltage_number = 0;
static uint16_t lowest_cell_voltage_number = 0;
static uint64_t cumulative_energy_when_discharging = 0; // Wh
static uint16_t pack_voltage_polled = 2700;
static uint32_t poll_pid = PID_POLL_PACKVOLTAGE;
static uint16_t lead_acid_voltage = 12000;
static uint8_t highest_cell_voltage_number = 0;
static uint8_t lowest_cell_voltage_number = 0;
static uint64_t cumulative_energy_when_discharging = 0;
static uint64_t cumulative_energy_when_charging = 0;
static uint64_t cumulative_energy_in_regen = 0;
static uint16_t soh_average = 10000;
static uint32_t poll_pid = PID_POLL_SOH_AVERAGE;
static uint16_t pid_reply = 0;
static uint8_t counter_10ms = 0;
static uint8_t content_125[16] = {0x07, 0x0C, 0x01, 0x06, 0x0B, 0x00, 0x05, 0x0A,
@ -96,9 +99,18 @@ void update_values_battery() { //This function maps all the values fetched via
datalayer.battery.status.cell_max_voltage_mV = highest_cell_voltage_mv;
if (leadAcidBatteryVoltage < 11000) { //11.000V
set_event(EVENT_12V_LOW, leadAcidBatteryVoltage);
if (lead_acid_voltage < 11000) { //11.000V
set_event(EVENT_12V_LOW, lead_acid_voltage);
}
// Update webserver datalayer
datalayer_extended.CMFAEV.lead_acid_voltage = lead_acid_voltage;
datalayer_extended.CMFAEV.highest_cell_voltage_number = highest_cell_voltage_number;
datalayer_extended.CMFAEV.lowest_cell_voltage_number = lowest_cell_voltage_number;
datalayer_extended.CMFAEV.cumulative_energy_when_discharging = cumulative_energy_when_discharging;
datalayer_extended.CMFAEV.cumulative_energy_when_charging = cumulative_energy_when_charging;
datalayer_extended.CMFAEV.cumulative_energy_in_regen = cumulative_energy_in_regen;
datalayer_extended.CMFAEV.soh_average = soh_average;
}
void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
@ -155,9 +167,8 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
pid_reply = (rx_frame.data.u8[2] << 8) + rx_frame.data.u8[3];
switch (pid_reply) {
case PID_POLL_PACKVOLTAGE:
pack_voltage_polled =
(uint16_t)((rx_frame.data.u8[5] << 8) | rx_frame.data.u8[4]); //Hmm, not same LSB as others
case PID_POLL_SOH_AVERAGE:
soh_average = (uint16_t)((rx_frame.data.u8[4] << 8) | rx_frame.data.u8[5]);
break;
case PID_POLL_AVERAGE_VOLTAGE_OF_CELLS:
average_voltage_of_cells =
@ -173,12 +184,20 @@ void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
lowest_cell_voltage_number = rx_frame.data.u8[4];
break;
case PID_POLL_12V_BATTERY:
leadAcidBatteryVoltage = (uint16_t)((rx_frame.data.u8[4] << 8) | rx_frame.data.u8[5]);
lead_acid_voltage = (uint16_t)((rx_frame.data.u8[4] << 8) | rx_frame.data.u8[5]);
break;
case PID_POLL_CUMULATIVE_ENERGY_WHEN_DISCHARGING:
cumulative_energy_when_discharging = (uint64_t)((rx_frame.data.u8[4] << 24) | (rx_frame.data.u8[5] << 16) |
(rx_frame.data.u8[6] << 8) | (rx_frame.data.u8[7]));
break;
case PID_POLL_CUMULATIVE_ENERGY_WHEN_CHARGING:
cumulative_energy_when_charging = (uint64_t)((rx_frame.data.u8[4] << 24) | (rx_frame.data.u8[5] << 16) |
(rx_frame.data.u8[6] << 8) | (rx_frame.data.u8[7]));
break;
case PID_POLL_CUMULATIVE_ENERGY_IN_REGEN:
cumulative_energy_in_regen = (uint64_t)((rx_frame.data.u8[4] << 24) | (rx_frame.data.u8[5] << 16) |
(rx_frame.data.u8[6] << 8) | (rx_frame.data.u8[7]));
break;
default:
break;
}
@ -219,9 +238,9 @@ void transmit_can_battery() {
previousMillis200ms = currentMillis;
switch (poll_pid) {
case PID_POLL_PACKVOLTAGE:
CMFA_POLLING_FRAME.data.u8[2] = (uint8_t)(PID_POLL_PACKVOLTAGE >> 8);
CMFA_POLLING_FRAME.data.u8[3] = (uint8_t)PID_POLL_PACKVOLTAGE;
case PID_POLL_SOH_AVERAGE:
CMFA_POLLING_FRAME.data.u8[2] = (uint8_t)(PID_POLL_SOH_AVERAGE >> 8);
CMFA_POLLING_FRAME.data.u8[3] = (uint8_t)PID_POLL_SOH_AVERAGE;
poll_pid = PID_POLL_AVERAGE_VOLTAGE_OF_CELLS;
break;
case PID_POLL_AVERAGE_VOLTAGE_OF_CELLS:
@ -247,15 +266,25 @@ void transmit_can_battery() {
case PID_POLL_12V_BATTERY:
CMFA_POLLING_FRAME.data.u8[2] = (uint8_t)(PID_POLL_12V_BATTERY >> 8);
CMFA_POLLING_FRAME.data.u8[3] = (uint8_t)PID_POLL_12V_BATTERY;
poll_pid = PID_POLL_CUMULATIVE_ENERGY_WHEN_CHARGING;
break;
case PID_POLL_CUMULATIVE_ENERGY_WHEN_CHARGING:
CMFA_POLLING_FRAME.data.u8[2] = (uint8_t)(PID_POLL_CUMULATIVE_ENERGY_WHEN_CHARGING >> 8);
CMFA_POLLING_FRAME.data.u8[3] = (uint8_t)PID_POLL_CUMULATIVE_ENERGY_WHEN_CHARGING;
poll_pid = PID_POLL_CUMULATIVE_ENERGY_WHEN_DISCHARGING;
break;
case PID_POLL_CUMULATIVE_ENERGY_WHEN_DISCHARGING:
CMFA_POLLING_FRAME.data.u8[2] = (uint8_t)(PID_POLL_CUMULATIVE_ENERGY_WHEN_DISCHARGING >> 8);
CMFA_POLLING_FRAME.data.u8[3] = (uint8_t)PID_POLL_CUMULATIVE_ENERGY_WHEN_DISCHARGING;
poll_pid = PID_POLL_PACKVOLTAGE;
poll_pid = PID_POLL_CUMULATIVE_ENERGY_IN_REGEN;
break;
case PID_POLL_CUMULATIVE_ENERGY_IN_REGEN:
CMFA_POLLING_FRAME.data.u8[2] = (uint8_t)(PID_POLL_CUMULATIVE_ENERGY_IN_REGEN >> 8);
CMFA_POLLING_FRAME.data.u8[3] = (uint8_t)PID_POLL_CUMULATIVE_ENERGY_IN_REGEN;
poll_pid = PID_POLL_SOH_AVERAGE;
break;
default:
poll_pid = PID_POLL_PACKVOLTAGE;
poll_pid = PID_POLL_SOH_AVERAGE;
break;
}

View file

@ -14,7 +14,7 @@
#define PID_POLL_UNKNOWN1 0x9001 //122 in log
#define PID_POLL_UNKNOWNX 0x9002 //5531 (Possible SOC candidate)
*/
#define PID_POLL_PACKVOLTAGE 0x9003 //Best guess, not confirmed
#define PID_POLL_SOH_AVERAGE 0x9003
#define PID_POLL_AVERAGE_VOLTAGE_OF_CELLS 0x9006 //Guaranteed pack voltage
#define PID_POLL_HIGHEST_CELL_VOLTAGE 0x9007 //Best guess, not confirmed
#define PID_POLL_CELL_NUMBER_HIGHEST_VOLTAGE 0x9008 // Cell number with highest voltage
@ -42,6 +42,8 @@
#define PID_POLL_UNKNOWNX 0x913C
#define PID_POLL_UNKNOWN5 0x912F
#define PID_POLL_UNKNOWNX 0x91B7
#define PID_POLL_SOH_AVAILABLE_POWER_CALCULATION 0x91BC // 0-100%
#define PID_POLL_SOH_GENERATED_POWER_CALCULATION 0x91BD // 0-100%
#define PID_POLL_UNKNOWNX 0x91C1
#define PID_POLL_UNKNOWNX 0x91CD
#define PID_POLL_UNKNOWNX 0x91CF
@ -49,9 +51,10 @@
#define PID_POLL_UNKNOWNX 0x91F7
#define PID_POLL_UNKNOWNX 0x920F
#define PID_POLL_UNKNOWNx 0x9242
#define PID_POLL_UNKNOWNx 0x9243
*/
#define PID_POLL_CUMULATIVE_ENERGY_WHEN_DISCHARGING 0x9245 //OK
#define PID_POLL_CUMULATIVE_ENERGY_WHEN_CHARGING 0x9243
#define PID_POLL_CUMULATIVE_ENERGY_WHEN_DISCHARGING 0x9245
#define PID_POLL_CUMULATIVE_ENERGY_IN_REGEN 0x9247
/*
#define PID_POLL_UNKNOWNx 0x9256
#define PID_POLL_UNKNOWNx 0x9261

View file

@ -252,6 +252,16 @@ typedef struct {
bool warning_Charger_not_responding = false;
} DATALAYER_INFO_CELLPOWER;
typedef struct {
uint16_t lead_acid_voltage = 0;
uint8_t highest_cell_voltage_number = 0;
uint8_t lowest_cell_voltage_number = 0;
uint64_t cumulative_energy_when_discharging = 0;
uint64_t cumulative_energy_when_charging = 0;
uint64_t cumulative_energy_in_regen = 0;
uint16_t soh_average = 0;
} DATALAYER_INFO_CMFAEV;
typedef struct {
uint8_t total_cell_count = 0;
int16_t battery_12V = 0;
@ -733,6 +743,7 @@ class DataLayerExtended {
DATALAYER_INFO_BMWI3 bmwi3;
DATALAYER_INFO_BYDATTO3 bydAtto3;
DATALAYER_INFO_CELLPOWER cellpower;
DATALAYER_INFO_CMFAEV CMFAEV;
DATALAYER_INFO_KIAHYUNDAI64 KiaHyundai64;
DATALAYER_INFO_TESLA tesla;
DATALAYER_INFO_NISSAN_LEAF nissanleaf;

View file

@ -432,6 +432,19 @@ String advanced_battery_processor(const String& var) {
String(falseTrue[datalayer_extended.cellpower.warning_Charger_not_responding]) + "</h4>";
#endif //CELLPOWER_BMS
#ifdef CMFA_EV_BATTERY
content += "<h4>SOH Average: " + String(datalayer_extended.CMFAEV.soh_average) + "</h4>";
content += "<h4>12V voltage: " + String(datalayer_extended.CMFAEV.lead_acid_voltage) + "</h4>";
content += "<h4>Highest cell number: " + String(datalayer_extended.CMFAEV.highest_cell_voltage_number) + "</h4>";
content += "<h4>Lowest cell number: " + String(datalayer_extended.CMFAEV.lowest_cell_voltage_number) + "</h4>";
content +=
"<h4>Cumulative energy discharged: " + String(datalayer_extended.CMFAEV.cumulative_energy_when_discharging) +
"</h4>";
content +=
"<h4>Cumulative energy charged: " + String(datalayer_extended.CMFAEV.cumulative_energy_when_charging) + "</h4>";
content += "<h4>Cumulative energy regen: " + String(datalayer_extended.CMFAEV.cumulative_energy_in_regen) + "</h4>";
#endif //CMFA_EV_BATTERY
#ifdef KIA_HYUNDAI_64_BATTERY
content += "<h4>Cells: " + String(datalayer_extended.KiaHyundai64.total_cell_count) + "S</h4>";
content += "<h4>12V voltage: " + String(datalayer_extended.KiaHyundai64.battery_12V / 10.0, 1) + "</h4>";
@ -1430,7 +1443,7 @@ String advanced_battery_processor(const String& var) {
!defined(TESLA_BATTERY) && !defined(NISSAN_LEAF_BATTERY) && !defined(BMW_I3_BATTERY) && \
!defined(BYD_ATTO_3_BATTERY) && !defined(RENAULT_ZOE_GEN2_BATTERY) && !defined(CELLPOWER_BMS) && \
!defined(MEB_BATTERY) && !defined(VOLVO_SPA_BATTERY) && !defined(VOLVO_SPA_HYBRID_BATTERY) && \
!defined(KIA_HYUNDAI_64_BATTERY) //Only the listed types have extra info
!defined(KIA_HYUNDAI_64_BATTERY) && !defined(CMFA_EV_BATTERY) //Only the listed types have extra info
content += "No extra information available for this battery type";
#endif