mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 10:19:29 +02:00
Added additional data from battery
This commit is contained in:
parent
a891257019
commit
db57a23dea
3 changed files with 76 additions and 5 deletions
|
@ -16,6 +16,7 @@ static unsigned long previousMillis5000 = 0; // will store last time a 5000ms
|
||||||
static unsigned long previousMillis10000 = 0; // will store last time a 10000ms CAN Message was send
|
static unsigned long previousMillis10000 = 0; // will store last time a 10000ms CAN Message was send
|
||||||
static uint8_t CANstillAlive = 12; // counter for checking if CAN is still alive
|
static uint8_t CANstillAlive = 12; // counter for checking if CAN is still alive
|
||||||
static uint16_t CANerror = 0; // counter on how many CAN errors encountered
|
static uint16_t CANerror = 0; // counter on how many CAN errors encountered
|
||||||
|
#define MAX_CAN_FAILURES 500 // Amount of malformed CAN messages to allow before raising a warning
|
||||||
#define ALIVE_MAX_VALUE 14 // BMW CAN messages contain alive counter, goes from 0...14
|
#define ALIVE_MAX_VALUE 14 // BMW CAN messages contain alive counter, goes from 0...14
|
||||||
|
|
||||||
static const uint16_t WUPonDuration = 477; // in milliseconds how long WUP should be ON after poweron
|
static const uint16_t WUPonDuration = 477; // in milliseconds how long WUP should be ON after poweron
|
||||||
|
@ -25,6 +26,9 @@ unsigned long turnOnTime; // Variables to store timestamps
|
||||||
enum State { POWERON, STATE_ON, STATE_OFF };
|
enum State { POWERON, STATE_ON, STATE_OFF };
|
||||||
static State WUPState = POWERON;
|
static State WUPState = POWERON;
|
||||||
|
|
||||||
|
enum CmdState { SOH, CELL_VOLTAGE, SOC, CELL_VOLTAGE_AVG };
|
||||||
|
static CmdState cmdState = SOH;
|
||||||
|
|
||||||
const unsigned char crc8_table[256] =
|
const unsigned char crc8_table[256] =
|
||||||
{ // CRC8_SAE_J1850_ZER0 formula,0x1D Poly,initial value 0x3F,Final XOR value varies
|
{ // CRC8_SAE_J1850_ZER0 formula,0x1D Poly,initial value 0x3F,Final XOR value varies
|
||||||
0x00, 0x1D, 0x3A, 0x27, 0x74, 0x69, 0x4E, 0x53, 0xE8, 0xF5, 0xD2, 0xCF, 0x9C, 0x81, 0xA6, 0xBB, 0xCD, 0xD0,
|
0x00, 0x1D, 0x3A, 0x27, 0x74, 0x69, 0x4E, 0x53, 0xE8, 0xF5, 0xD2, 0xCF, 0x9C, 0x81, 0xA6, 0xBB, 0xCD, 0xD0,
|
||||||
|
@ -273,6 +277,28 @@ CAN_frame_t BMW_6F1_CELL = { .FIR = { .B = {
|
||||||
.MsgID = 0x6F1,
|
.MsgID = 0x6F1,
|
||||||
.data = { 0x07, 0x03, 0x22, 0xDD, 0xBF } };
|
.data = { 0x07, 0x03, 0x22, 0xDD, 0xBF } };
|
||||||
|
|
||||||
|
CAN_frame_t BMW_6F1_SOH = { .FIR = { .B = {
|
||||||
|
.DLC = 5,
|
||||||
|
.FF = CAN_frame_std,
|
||||||
|
} },
|
||||||
|
.MsgID = 0x6F1,
|
||||||
|
.data = { 0x07, 0x03, 0x22, 0x63, 0x35 } };
|
||||||
|
|
||||||
|
|
||||||
|
CAN_frame_t BMW_6F1_SOC = { .FIR = { .B = {
|
||||||
|
.DLC = 5,
|
||||||
|
.FF = CAN_frame_std,
|
||||||
|
} },
|
||||||
|
.MsgID = 0x6F1,
|
||||||
|
.data = { 0x07, 0x03, 0x22, 0xDD, 0xBC } };
|
||||||
|
|
||||||
|
CAN_frame_t BMW_6F1_CELL_VOLTAGE_AVG = { .FIR = { .B = {
|
||||||
|
.DLC = 5,
|
||||||
|
.FF = CAN_frame_std,
|
||||||
|
} },
|
||||||
|
.MsgID = 0x6F1,
|
||||||
|
.data = { 0x07, 0x03, 0x22, 0xDF, 0xA0 } };
|
||||||
|
|
||||||
CAN_frame_t BMW_6F1_CONTINUE = { .FIR = { .B = {
|
CAN_frame_t BMW_6F1_CONTINUE = { .FIR = { .B = {
|
||||||
.DLC = 4,
|
.DLC = 4,
|
||||||
.FF = CAN_frame_std,
|
.FF = CAN_frame_std,
|
||||||
|
@ -320,6 +346,12 @@ static uint16_t battery_prediction_voltage_longterm_charge = 0;
|
||||||
static uint16_t battery_prediction_voltage_longterm_discharge = 0;
|
static uint16_t battery_prediction_voltage_longterm_discharge = 0;
|
||||||
static uint16_t battery_prediction_duration_charging_minutes = 0;
|
static uint16_t battery_prediction_duration_charging_minutes = 0;
|
||||||
static uint16_t battery_target_voltage_in_CV_mode = 0;
|
static uint16_t battery_target_voltage_in_CV_mode = 0;
|
||||||
|
|
||||||
|
uint16_t battery_soc = 0;
|
||||||
|
uint16_t battery_soc_hvmax = 0;
|
||||||
|
uint16_t battery_soc_hvmin = 0;
|
||||||
|
uint16_t battery_capacity_cah = 0;
|
||||||
|
|
||||||
static int16_t battery_temperature_HV = 0;
|
static int16_t battery_temperature_HV = 0;
|
||||||
static int16_t battery_temperature_heat_exchanger = 0;
|
static int16_t battery_temperature_heat_exchanger = 0;
|
||||||
static int16_t battery_temperature_max = 0;
|
static int16_t battery_temperature_max = 0;
|
||||||
|
@ -358,6 +390,7 @@ static uint8_t battery_status_diagnosis_powertrain_maximum_multiplexer = 0;
|
||||||
static uint8_t battery_status_diagnosis_powertrain_immediate_multiplexer = 0;
|
static uint8_t battery_status_diagnosis_powertrain_immediate_multiplexer = 0;
|
||||||
static uint8_t battery_ID2 = 0;
|
static uint8_t battery_ID2 = 0;
|
||||||
static uint8_t battery_cellvoltage_mux = 0;
|
static uint8_t battery_cellvoltage_mux = 0;
|
||||||
|
static uint8_t battery_soh = 0;
|
||||||
|
|
||||||
static uint8_t message_data[50];
|
static uint8_t message_data[50];
|
||||||
static uint8_t next_data = 0;
|
static uint8_t next_data = 0;
|
||||||
|
@ -380,7 +413,7 @@ static uint8_t increment_alive_counter(uint8_t counter) {
|
||||||
|
|
||||||
void update_values_battery() { //This function maps all the values fetched via CAN to the correct parameters used for modbus
|
void update_values_battery() { //This function maps all the values fetched via CAN to the correct parameters used for modbus
|
||||||
|
|
||||||
system_real_SOC_pptt = (battery_HVBatt_SOC * 10); //increase Display_SOC range from 0-100 -> 100.00
|
system_real_SOC_pptt = (battery_HVBatt_SOC * 10);
|
||||||
|
|
||||||
system_battery_voltage_dV = battery_volts; //Unit V+1 (5000 = 500.0V)
|
system_battery_voltage_dV = battery_volts; //Unit V+1 (5000 = 500.0V)
|
||||||
|
|
||||||
|
@ -390,7 +423,7 @@ void update_values_battery() { //This function maps all the values fetched via
|
||||||
|
|
||||||
system_remaining_capacity_Wh = (battery_energy_content_maximum_kWh * 1000); // Convert kWh to Wh
|
system_remaining_capacity_Wh = (battery_energy_content_maximum_kWh * 1000); // Convert kWh to Wh
|
||||||
|
|
||||||
system_SOH_pptt = battery_energy_content_maximum_kWh * 10000 / 27.2;
|
system_SOH_pptt = battery_soh * 100;
|
||||||
|
|
||||||
if (battery_BEV_available_power_longterm_discharge > 65000) {
|
if (battery_BEV_available_power_longterm_discharge > 65000) {
|
||||||
system_max_discharge_power_W = 65000;
|
system_max_discharge_power_W = 65000;
|
||||||
|
@ -570,7 +603,7 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
||||||
case 0x587: //BMS [5s] Services
|
case 0x587: //BMS [5s] Services
|
||||||
battery_ID2 = rx_frame.data.u8[0];
|
battery_ID2 = rx_frame.data.u8[0];
|
||||||
break;
|
break;
|
||||||
case 0x607: //BMS - messages requested on 0x615
|
case 0x607: //BMS - responses to message requests on 0x615
|
||||||
if (rx_frame.FIR.B.DLC > 6
|
if (rx_frame.FIR.B.DLC > 6
|
||||||
&& next_data == 0
|
&& next_data == 0
|
||||||
&& rx_frame.data.u8[0] == 0xf1) {
|
&& rx_frame.data.u8[0] == 0xf1) {
|
||||||
|
@ -589,8 +622,32 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
||||||
message_data[next_data++] = rx_frame.data.u8[count++];
|
message_data[next_data++] = rx_frame.data.u8[count++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (cmdState) {
|
||||||
|
case CELL_VOLTAGE:
|
||||||
|
if (next_data>=4) {
|
||||||
system_cellvoltages_mV[0] = (message_data[0] << 8 | message_data[1]);
|
system_cellvoltages_mV[0] = (message_data[0] << 8 | message_data[1]);
|
||||||
system_cellvoltages_mV[1] = (message_data[2] << 8 | message_data[3]);
|
system_cellvoltages_mV[2] = (message_data[2] << 8 | message_data[3]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CELL_VOLTAGE_AVG:
|
||||||
|
if (next_data>=30) {
|
||||||
|
system_cellvoltages_mV[1] = (message_data[10] << 8 | message_data[11]) / 10;
|
||||||
|
battery_capacity_cah = (message_data[4] << 8 | message_data[5]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SOH:
|
||||||
|
if (next_data>=4) {
|
||||||
|
battery_soh = message_data[3];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SOC:
|
||||||
|
if (next_data>=6) {
|
||||||
|
battery_soc = (message_data[0] << 8 | message_data[1]);
|
||||||
|
battery_soc_hvmax = (message_data[2] << 8 | message_data[3]);
|
||||||
|
battery_soc_hvmin = (message_data[4] << 8 | message_data[5]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -526,6 +526,13 @@ String processor(const String& var) {
|
||||||
} else { // > 0
|
} else { // > 0
|
||||||
content += "<h4>Battery charging!</h4>";
|
content += "<h4>Battery charging!</h4>";
|
||||||
}
|
}
|
||||||
|
#ifdef BMW_I3_BATTERY
|
||||||
|
content += "<h4>Battery Capacity cAh: " + String(battery_capacity_cah / 100.0, 2) + " Ah</h4>";
|
||||||
|
content += "<h4>Battery SOC: " + String(battery_soc / 10.0, 1) + "%%</h4>";
|
||||||
|
content += "<h4>Battery SOC hvMax: " + String(battery_soc_hvmax / 10.0, 1) + "%%</h4>";
|
||||||
|
content += "<h4>Battery SOC hvMin: " + String(battery_soc_hvmin / 10.0, 1) + "%%</h4>";
|
||||||
|
#endif
|
||||||
|
|
||||||
content += "<h4>Automatic contactor closing allowed:</h4>";
|
content += "<h4>Automatic contactor closing allowed:</h4>";
|
||||||
content += "<h4>Battery: ";
|
content += "<h4>Battery: ";
|
||||||
if (batteryAllowsContactorClosing) {
|
if (batteryAllowsContactorClosing) {
|
||||||
|
|
|
@ -40,6 +40,13 @@ extern uint8_t LEDcolor; //Enum, 0-10
|
||||||
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
|
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
|
|
||||||
|
#ifdef BMW_I3_BATTERY
|
||||||
|
extern uint16_t battery_soc;
|
||||||
|
extern uint16_t battery_soc_hvmax;
|
||||||
|
extern uint16_t battery_soc_hvmin;
|
||||||
|
extern uint16_t battery_capacity_cah;
|
||||||
|
#endif
|
||||||
|
|
||||||
extern const char* ssid;
|
extern const char* ssid;
|
||||||
extern const char* password;
|
extern const char* password;
|
||||||
extern const uint8_t wifi_channel;
|
extern const uint8_t wifi_channel;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue