From db1e6790448ec177c27241a54adcf9c2aad7606a Mon Sep 17 00:00:00 2001 From: Cabooman <81711263+Cabooman@users.noreply.github.com> Date: Mon, 12 Feb 2024 20:16:39 +0100 Subject: [PATCH 01/15] Initial commit --- Software/src/devboard/utils/events.cpp | 3 +++ Software/src/devboard/utils/events.h | 1 + Software/src/devboard/webserver/webserver.cpp | 23 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/Software/src/devboard/utils/events.cpp b/Software/src/devboard/utils/events.cpp index 0cc51e8d..2b426b53 100644 --- a/Software/src/devboard/utils/events.cpp +++ b/Software/src/devboard/utils/events.cpp @@ -131,6 +131,7 @@ void init_events(void) { events.entries[EVENT_SERIAL_RX_FAILURE].level = EVENT_LEVEL_ERROR; events.entries[EVENT_SERIAL_TX_FAILURE].level = EVENT_LEVEL_ERROR; events.entries[EVENT_SERIAL_TRANSMITTER_FAILURE].level = EVENT_LEVEL_ERROR; + events.entries[EVENT_OTA_UPDATE_TIMEOUT].level = EVENT_LEVEL_INFO; events.entries[EVENT_DUMMY_INFO].log = true; events.entries[EVENT_DUMMY_DEBUG].log = true; @@ -213,6 +214,8 @@ const char* get_event_message_string(EVENTS_ENUM_TYPE event) { return "Error in serial function: Some ERROR level fault in transmitter, received by receiver"; case EVENT_OTA_UPDATE: return "OTA update started!"; + case EVENT_OTA_UPDATE_TIMEOUT: + return "OTA update timed out!"; default: return ""; } diff --git a/Software/src/devboard/utils/events.h b/Software/src/devboard/utils/events.h index ddd32227..fbafa5f2 100644 --- a/Software/src/devboard/utils/events.h +++ b/Software/src/devboard/utils/events.h @@ -39,6 +39,7 @@ XX(EVENT_CELL_DEVIATION_HIGH) \ XX(EVENT_UNKNOWN_EVENT_SET) \ XX(EVENT_OTA_UPDATE) \ + XX(EVENT_OTA_UPDATE_TIMEOUT) \ XX(EVENT_DUMMY_INFO) \ XX(EVENT_DUMMY_DEBUG) \ XX(EVENT_DUMMY_WARNING) \ diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index c2eab57a..28cb3fdd 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -1,6 +1,7 @@ #include "webserver.h" #include #include "../utils/events.h" +#include "../utils/timer.h" // Create AsyncWebServer object on port 80 AsyncWebServer server(80); @@ -21,6 +22,9 @@ enum WifiState { WifiState wifi_state = INIT; +MyTimer ota_timeout_timer = MyTimer(5000); +bool ota_active = false; + unsigned const long WIFI_MONITOR_INTERVAL_TIME = 15000; unsigned const long INIT_WIFI_CONNECT_TIMEOUT = 8000; // Timeout for initial WiFi connect in milliseconds unsigned const long DEFAULT_WIFI_RECONNECT_INTERVAL = 1000; // Default WiFi reconnect interval in ms @@ -299,6 +303,13 @@ void wifi_monitor() { Serial.println(" Hostname: " + String(WiFi.getHostname())); } } + + if (ota_active && ota_timeout_timer.elapsed()) { + // OTA timeout, try to restore can and clear the update event + ESP32Can.CANInit(); + clear_event(EVENT_OTA_UPDATE); + set_event(EVENT_OTA_UPDATE_TIMEOUT, 0); + } } void init_WiFi_STA(const char* ssid, const char* password, const uint8_t wifi_channel) { @@ -635,6 +646,11 @@ void onOTAStart() { // Log when OTA has started ESP32Can.CANStop(); set_event(EVENT_OTA_UPDATE, 0); + + // If already set, make a new attempt + clear_event(EVENT_OTA_UPDATE_TIMEOUT); + ota_active = true; + ota_timeout_timer.reset(); } void onOTAProgress(size_t current, size_t final) { @@ -642,6 +658,9 @@ void onOTAProgress(size_t current, size_t final) { if (millis() - ota_progress_millis > 1000) { ota_progress_millis = millis(); Serial.printf("OTA Progress Current: %u bytes, Final: %u bytes\n", current, final); + + // Reset the "watchdog" + ota_timeout_timer.reset(); } } @@ -651,7 +670,11 @@ void onOTAEnd(bool success) { Serial.println("OTA update finished successfully!"); } else { Serial.println("There was an error during OTA update!"); + + // If we fail without a timeout, try to restore CAN + ESP32Can.CANInit(); } + ota_active = false; clear_event(EVENT_OTA_UPDATE); } From 9c1e2c3333c40e0f3232bc3f3950be2b269f3d3e Mon Sep 17 00:00:00 2001 From: Cabooman <81711263+Cabooman@users.noreply.github.com> Date: Mon, 12 Feb 2024 20:23:19 +0100 Subject: [PATCH 02/15] Minor addition --- Software/src/devboard/webserver/webserver.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 28cb3fdd..26de0909 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -309,6 +309,7 @@ void wifi_monitor() { ESP32Can.CANInit(); clear_event(EVENT_OTA_UPDATE); set_event(EVENT_OTA_UPDATE_TIMEOUT, 0); + ota_active = false; } } From fa69220c6abbf9fcc17971d5c044fe3990a7b13f Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 14 Feb 2024 17:16:51 +0200 Subject: [PATCH 03/15] Add base for SMA Tripower protocol --- Software/Software.ino | 12 + Software/USER_SETTINGS.h | 5 +- Software/src/inverter/INVERTERS.h | 4 + Software/src/inverter/SMA-TRIPOWER-CAN.cpp | 364 +++++++++++++++++++++ Software/src/inverter/SMA-TRIPOWER-CAN.h | 32 ++ 5 files changed, 415 insertions(+), 2 deletions(-) create mode 100644 Software/src/inverter/SMA-TRIPOWER-CAN.cpp create mode 100644 Software/src/inverter/SMA-TRIPOWER-CAN.h diff --git a/Software/Software.ino b/Software/Software.ino index 5578ed38..e2b4e5a1 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -345,6 +345,9 @@ void inform_user_on_inverter() { #ifdef SMA_CAN Serial.println("SMA CAN protocol selected"); #endif +#ifdef SMA_TRIPOWER_CAN + Serial.println("SMA Tripower CAN protocol selected"); +#endif #ifdef SOFAR_CAN Serial.println("SOFAR CAN protocol selected"); #endif @@ -439,6 +442,9 @@ void receive_can() { // This section checks if we have a complete CAN message i #endif #ifdef SMA_CAN receive_can_sma(rx_frame); +#endif +#ifdef SMA_TRIPOWER_CAN + receive_can_sma_tripower(rx_frame); #endif // Charger #ifdef CHEVYVOLT_CHARGER @@ -471,6 +477,9 @@ void send_can() { #ifdef SMA_CAN send_can_sma(); #endif +#ifdef SMA_TRIPOWER_CAN + send_can_sma_tripower(); +#endif #ifdef SOFAR_CAN send_can_sofar(); #endif @@ -730,6 +739,9 @@ void update_values() { #ifdef SMA_CAN update_values_can_sma(); #endif +#ifdef SMA_TRIPOWER_CAN + update_values_can_sma_tripower(); +#endif #ifdef SOFAR_CAN update_values_can_sofar(); #endif diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h index 373922c8..708e692d 100644 --- a/Software/USER_SETTINGS.h +++ b/Software/USER_SETTINGS.h @@ -12,7 +12,7 @@ //#define CHADEMO_BATTERY //#define IMIEV_CZERO_ION_BATTERY //#define KIA_HYUNDAI_64_BATTERY -// #define NISSAN_LEAF_BATTERY +//#define NISSAN_LEAF_BATTERY //#define RENAULT_KANGOO_BATTERY //#define RENAULT_ZOE_BATTERY //#define SANTA_FE_PHEV_BATTERY @@ -21,10 +21,11 @@ /* Select inverter communication protocol. See Wiki for which to use with your inverter: https://github.com/dalathegreat/BYD-Battery-Emulator-For-Gen24/wiki */ //#define BYD_CAN //Enable this line to emulate a "BYD Battery-Box Premium HVS" over CAN Bus -// #define BYD_MODBUS //Enable this line to emulate a "BYD 11kWh HVM battery" over Modbus RTU +//#define BYD_MODBUS //Enable this line to emulate a "BYD 11kWh HVM battery" over Modbus RTU //#define LUNA2000_MODBUS //Enable this line to emulate a "Luna2000 battery" over Modbus RTU //#define PYLON_CAN //Enable this line to emulate a "Pylontech battery" over CAN bus //#define SMA_CAN //Enable this line to emulate a "BYD Battery-Box H 8.9kWh, 7 mod" over CAN bus +//#define SMA_TRIPOWER_CAN //Enable this line to emulate a "SMA Home Storage battery" over CAN bus //#define SOFAR_CAN //Enable this line to emulate a "Sofar Energy Storage Inverter High Voltage BMS General Protocol (Extended Frame)" over CAN bus //#define SOLAX_CAN //Enable this line to emulate a "SolaX Triple Power LFP" over CAN bus diff --git a/Software/src/inverter/INVERTERS.h b/Software/src/inverter/INVERTERS.h index 01a9d550..979051de 100644 --- a/Software/src/inverter/INVERTERS.h +++ b/Software/src/inverter/INVERTERS.h @@ -21,6 +21,10 @@ #include "SMA-CAN.h" #endif +#ifdef SMA_TRIPOWER_CAN +#include "SMA-TRIPOWER-CAN.h" +#endif + #ifdef SOFAR_CAN #include "SOFAR-CAN.h" #endif diff --git a/Software/src/inverter/SMA-TRIPOWER-CAN.cpp b/Software/src/inverter/SMA-TRIPOWER-CAN.cpp new file mode 100644 index 00000000..963c4407 --- /dev/null +++ b/Software/src/inverter/SMA-TRIPOWER-CAN.cpp @@ -0,0 +1,364 @@ +#include "SMA-TRIPOWER-CAN.h" +#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" +#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" + +/* TODO: +- Figure out the manufacturer info needed in send_tripower_init() CAN messages + - CAN logs from real system might be needed +- Figure out how cellvoltages need to be displayed +- Figure out if sending send_tripower_init() like we do now is OK +- Figure out how to send the non-cyclic messages when needed +*/ + +/* Do not change code below unless you are sure what you are doing */ +static unsigned long previousMillis500ms = 0; // will store last time a 100ms CAN Message was send +static const int interval500ms = 100; // interval (ms) at which send CAN Messages + +//Actual content messages +static CAN_frame_t SMA_00D = { // Battery Limits + .FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x00D, + .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +static CAN_frame_t SMA_00F = { // Battery State + .FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x00F, + .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +static CAN_frame_t SMA_011 = { // Battery Energy + .FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x011, + .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +static CAN_frame_t SMA_013 = { // Battery Measurements + .FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x013, + .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +static CAN_frame_t SMA_014 = { // Battery Tempeartures and Cellvoltages + .FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x014, + .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +static CAN_frame_t SMA_005 = { // Battery Alarms 1 + .FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x005, + .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +static CAN_frame_t SMA_007 = { // Battery Alarms 2 + .FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x007, + .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +static CAN_frame_t SMA_006 = { // Battery Error Codes + .FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x006, + .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +static CAN_frame_t SMA_008 = { // Battery Events + .FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x008, + .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +static CAN_frame_t SMA_015 = { // Battery Data 1 + .FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x015, + .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +static CAN_frame_t SMA_016 = { // Battery Data 2 + .FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x016, + .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +static CAN_frame_t SMA_017 = { // Battery Manufacturer + .FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x017, + .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +static CAN_frame_t SMA_018 = { // Battery Name + .FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x018, + .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; + +static int discharge_current = 0; +static int charge_current = 0; +static int temperature_average = 0; +static int ampere_hours_remaining = 0; +static int ampere_hours_max = 0; +static bool batteryAlarm = false; +static bool BMSevent = false; + +enum BatteryState { NA, INIT, BAT_STANDBY, OPERATE, WARNING, FAULTED, UPDATE, BAT_UPDATE }; +BatteryState batteryState = OPERATE; +enum InverterControlFlags { + EMG_CHARGE_REQUEST, + EMG_DISCHARGE_REQUEST, + NOT_ENOUGH_ENERGY_FOR_START, + INVERTER_STAY_ON, + FORCED_BATTERY_SHUTDOWN, + RESERVED, + BATTERY_UPDATE_AVAILABLE, + NO_BATTERY_UPDATED_BY_INV +}; +InverterControlFlags inverterControlFlags = BATTERY_UPDATE_AVAILABLE; +enum Events0 { + START_SOC_CALIBRATE, + STOP_SOC_CALIBRATE, + START_POWERLIMIT, + STOP_POWERLIMIT, + PREVENTATIVE_BAT_SHUTDOWN, + THERMAL_MANAGEMENT, + START_BALANCING, + STOP_BALANCING +}; +Events0 events0 = START_BALANCING; +enum Events1 { START_BATTERY_SELFTEST, STOP_BATTERY_SELFTEST }; +Events1 events1 = START_BATTERY_SELFTEST; +enum Command2Battery { IDLE, RUN, NOT_USED1, NOT_USED2, SHUTDOWN, FIRMWARE_UPDATE, BATSELFUPDATE, NOT_USED3 }; +Command2Battery command2Battery = RUN; +enum InvInitState { SYSTEM_FREQUENCY, XPHASE_SYSTEM, BLACKSTART_OPERATION }; +InvInitState invInitState = SYSTEM_FREQUENCY; + +void update_values_can_sma_tripower() { //This function maps all the values fetched from battery CAN to the inverter CAN + //Calculate values + charge_current = + ((max_target_charge_power * 10) / max_voltage); //Charge power in W , max volt in V+1decimal (P=UI, solve for I) + //The above calculation results in (30 000*10)/3700=81A + charge_current = (charge_current * 10); //Value needs a decimal before getting sent to inverter (81.0A) + + discharge_current = ((max_target_discharge_power * 10) / + max_voltage); //Charge power in W , max volt in V+1decimal (P=UI, solve for I) + //The above calculation results in (30 000*10)/3700=81A + discharge_current = (discharge_current * 10); //Value needs a decimal before getting sent to inverter (81.0A) + + temperature_average = ((temperature_max + temperature_min) / 2); + + ampere_hours_remaining = + ((remaining_capacity_Wh / battery_voltage) * 100); //(WH[10000] * V+1[3600])*100 = 270 (27.0Ah) + ampere_hours_max = ((capacity_Wh / battery_voltage) * 100); //(WH[10000] * V+1[3600])*100 = 270 (27.0Ah) + + batteryState = OPERATE; + inverterControlFlags = INVERTER_STAY_ON; + + //Map values to CAN messages + // Battery Limits + //Battery Max Charge Voltage (eg 400.0V = 4000 , 16bits long) + SMA_00D.data.u8[0] = (max_voltage >> 8); + SMA_00D.data.u8[1] = (max_voltage & 0x00FF); + //Battery Min Discharge Voltage (eg 300.0V = 3000 , 16bits long) + SMA_00D.data.u8[2] = (min_voltage >> 8); + SMA_00D.data.u8[3] = (min_voltage & 0x00FF); + //Discharge limited current, 500 = 50A, (0.1, A) + SMA_00D.data.u8[4] = (discharge_current >> 8); + SMA_00D.data.u8[5] = (discharge_current & 0x00FF); + //Charge limited current, 125 =12.5A (0.1, A) + SMA_00D.data.u8[6] = (charge_current >> 8); + SMA_00D.data.u8[7] = (charge_current & 0x00FF); + + // Battery State + //SOC (100.00%) + SMA_00F.data.u8[0] = (SOC >> 8); + SMA_00F.data.u8[1] = (SOC & 0x00FF); + //StateOfHealth (100.00%) + SMA_00F.data.u8[2] = (StateOfHealth >> 8); + SMA_00F.data.u8[3] = (StateOfHealth & 0x00FF); + //State of charge (AH, 0.1) + SMA_00F.data.u8[4] = (ampere_hours_remaining >> 8); + SMA_00F.data.u8[5] = (ampere_hours_remaining & 0x00FF); + //Fully charged (AH, 0.1) + SMA_00F.data.u8[6] = (ampere_hours_max >> 8); + SMA_00F.data.u8[7] = (ampere_hours_max & 0x00FF); + + // Battery Energy + //Charged Energy Counter TODO: are these needed? + //SMA_011.data.u8[0] = (X >> 8); + //SMA_011.data.u8[1] = (X & 0x00FF); + //SMA_011.data.u8[2] = (X >> 8); + //SMA_011.data.u8[3] = (X & 0x00FF); + //Discharged Energy Counter TODO: are these needed? + //SMA_011.data.u8[4] = (X >> 8); + //SMA_011.data.u8[5] = (X & 0x00FF); + //SMA_011.data.u8[6] = (X >> 8); + //SMA_011.data.u8[7] = (X & 0x00FF); + + // Battery Measurements + //Voltage (370.0) + SMA_013.data.u8[0] = (battery_voltage >> 8); + SMA_013.data.u8[1] = (battery_voltage & 0x00FF); + //Current (TODO: signed OK?) + SMA_013.data.u8[2] = (battery_current >> 8); + SMA_013.data.u8[3] = (battery_current & 0x00FF); + //Temperature average + SMA_013.data.u8[4] = (temperature_average >> 8); + SMA_013.data.u8[5] = (temperature_average & 0x00FF); + //Battery state + SMA_013.data.u8[6] = batteryState; + SMA_013.data.u8[6] = inverterControlFlags; + + // Battery Temperature and Cellvoltages + // Battery max temperature + SMA_014.data.u8[0] = (temperature_max >> 8); + SMA_014.data.u8[1] = (temperature_max & 0x00FF); + // Battery min temperature + SMA_014.data.u8[2] = (temperature_min >> 8); + SMA_014.data.u8[3] = (temperature_min & 0x00FF); + // Battery Cell Voltage (sum) + //SMA_014.data.u8[4] = (??? >> 8); //TODO scaling? + //SMA_014.data.u8[5] = (??? & 0x00FF); //TODO scaling? + // Cell voltage min + //SMA_014.data.u8[6] = (??? >> 8); //TODO scaling? 0-255 + // Cell voltage max + //SMA_014.data.u8[7] = (??? >> 8); //TODO scaling? 0-255 + + //SMA_006.data.u8[0] = (ErrorCode >> 8); + //SMA_006.data.u8[1] = (ErrorCode & 0x00FF); + //SMA_006.data.u8[2] = ModuleNumber; + //SMA_006.data.u8[3] = ErrorLevel; + //SMA_008.data.u8[0] = Events0; + //SMA_008.data.u8[1] = Events1; + + //SMA_005.data.u8[0] = BMSalarms0; + //SMA_005.data.u8[1] = BMSalarms1; + //SMA_005.data.u8[2] = BMSalarms2; + //SMA_005.data.u8[3] = BMSalarms3; + //SMA_005.data.u8[4] = BMSalarms4; + //SMA_005.data.u8[5] = BMSalarms5; + //SMA_005.data.u8[6] = BMSalarms6; + //SMA_005.data.u8[7] = BMSalarms7; + + //SMA_007.data.u8[0] = DCDCalarms0; + //SMA_007.data.u8[1] = DCDCalarms1; + //SMA_007.data.u8[2] = DCDCalarms2; + //SMA_007.data.u8[3] = DCDCalarms3; + //SMA_007.data.u8[4] = DCDCwarnings0; + //SMA_007.data.u8[5] = DCDCwarnings1; + //SMA_007.data.u8[6] = DCDCwarnings2; + //SMA_007.data.u8[7] = DCDCwarnings3; + + //SMA_015.data.u8[0] = BatterySystemVersion; + //SMA_015.data.u8[1] = BatterySystemVersion; + //SMA_015.data.u8[2] = BatterySystemVersion; + //SMA_015.data.u8[3] = BatterySystemVersion; + //SMA_015.data.u8[4] = BatteryCapacity; + //SMA_015.data.u8[5] = BatteryCapacity; + //SMA_015.data.u8[6] = NumberOfModules; + //SMA_015.data.u8[7] = BatteryManufacturerID; + + //SMA_016.data.u8[0] = SerialNumber; + //SMA_016.data.u8[1] = SerialNumber; + //SMA_016.data.u8[2] = SerialNumber; + //SMA_016.data.u8[3] = SerialNumber; + //SMA_016.data.u8[4] = ManufacturingDate; + //SMA_016.data.u8[5] = ManufacturingDate; + //SMA_016.data.u8[6] = ManufacturingDate; + //SMA_016.data.u8[7] = ManufacturingDate; + + //SMA_017.data.u8[0] = Multiplex; + //SMA_017.data.u8[1] = ManufacturerName; + //SMA_017.data.u8[2] = ManufacturerName; + //SMA_017.data.u8[3] = ManufacturerName; + //SMA_017.data.u8[4] = ManufacturerName; + //SMA_017.data.u8[5] = ManufacturerName; + //SMA_017.data.u8[6] = ManufacturerName; + //SMA_017.data.u8[7] = ManufacturerName; + + //SMA_018.data.u8[0] = Multiplex; + //SMA_018.data.u8[1] = BatteryName; + //SMA_018.data.u8[2] = BatteryName; + //SMA_018.data.u8[3] = BatteryName; + //SMA_018.data.u8[4] = BatteryName; + //SMA_018.data.u8[5] = BatteryName; + //SMA_018.data.u8[6] = BatteryName; + //SMA_018.data.u8[7] = BatteryName; +} + +void receive_can_sma_tripower(CAN_frame_t rx_frame) { + switch (rx_frame.MsgID) { + case 0x00D: //Inverter Measurements + break; + case 0x00F: //Inverter Feedback + break; + case 0x010: //Time from inverter + break; + case 0x015: //Initialization message from inverter + send_tripower_init(); + break; + case 0x017: //Initialization message from inverter 2 + //send_tripower_init(); + break; + default: + break; + } +} + +void send_can_sma_tripower() { + unsigned long currentMillis = millis(); + + // Send CAN Message every 500ms + if (currentMillis - previousMillis500ms >= interval500ms) { + previousMillis500ms = currentMillis; + + ESP32Can.CANWriteFrame(&SMA_00D); //Battery limits + ESP32Can.CANWriteFrame(&SMA_00F); // Battery state + ESP32Can.CANWriteFrame(&SMA_011); // Battery Energy + ESP32Can.CANWriteFrame(&SMA_013); // Battery Measurements + ESP32Can.CANWriteFrame(&SMA_014); // Battery Temperatures and cellvoltages + } + + if (batteryAlarm) { //Non-cyclic + ESP32Can.CANWriteFrame(&SMA_005); // Battery Alarms 1 + ESP32Can.CANWriteFrame(&SMA_007); // Battery Alarms 2 + } + + if (BMSevent) { //Non-cyclic + ESP32Can.CANWriteFrame(&SMA_006); // Battery Errorcode + ESP32Can.CANWriteFrame(&SMA_008); // Battery Events + } +} + +void send_tripower_init() { + ESP32Can.CANWriteFrame(&SMA_015); // Battery Data 1 + ESP32Can.CANWriteFrame(&SMA_016); // Battery Data 2 + ESP32Can.CANWriteFrame(&SMA_017); // Battery Manufacturer + ESP32Can.CANWriteFrame(&SMA_018); // Battery Name +} diff --git a/Software/src/inverter/SMA-TRIPOWER-CAN.h b/Software/src/inverter/SMA-TRIPOWER-CAN.h new file mode 100644 index 00000000..7b31d9b8 --- /dev/null +++ b/Software/src/inverter/SMA-TRIPOWER-CAN.h @@ -0,0 +1,32 @@ +#ifndef SMA_CAN_TRIPOWER_H +#define SMA_CAN_TRIPOWER_H +#include +#include "../../USER_SETTINGS.h" +#include "../devboard/config.h" // Needed for all defines +#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" + +extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) +extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) +extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485) +extern uint16_t capacity_Wh; //Wh, 0-60000 +extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 +extern uint16_t max_target_discharge_power; //W, 0-60000 +extern uint16_t max_target_charge_power; //W, 0-60000 +extern uint8_t bms_char_dis_status; //Enum, 0-2 +extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) +extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +extern uint16_t cell_max_voltage; //mV, 0-4350 +extern uint16_t cell_min_voltage; //mV, 0-4350 +extern uint16_t min_voltage; +extern uint16_t max_voltage; +extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false +extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false + +void update_values_can_sma_tripower(); +void send_can_sma_tripower(); +void receive_can_sma_tripower(CAN_frame_t rx_frame); +void send_tripower_init(); + +#endif From 2408da389ce7718751a35d5bfb72a33c080ed22c Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 15 Feb 2024 21:38:44 +0200 Subject: [PATCH 04/15] Fix charge allowed message --- Software/src/inverter/SMA-CAN.cpp | 81 ++++++++++++++++++++++++++----- Software/src/inverter/SMA-CAN.h | 4 ++ 2 files changed, 74 insertions(+), 11 deletions(-) diff --git a/Software/src/inverter/SMA-CAN.cpp b/Software/src/inverter/SMA-CAN.cpp index 5ec6554e..abd73c70 100644 --- a/Software/src/inverter/SMA-CAN.cpp +++ b/Software/src/inverter/SMA-CAN.cpp @@ -2,6 +2,8 @@ #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +/* TODO: Map error bits in 0x158 */ + /* Do not change code below unless you are sure what you are doing */ static unsigned long previousMillis100ms = 0; // will store last time a 100ms CAN Message was send static const int interval100ms = 100; // interval (ms) at which send CAN Messages @@ -94,10 +96,12 @@ CAN_frame_t SMA_158 = {.FIR = {.B = .MsgID = 0x158, .data = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0x6A, 0xAA, 0xAA}}; -static int discharge_current = 0; -static int charge_current = 0; -static int temperature_average = 0; -static int ampere_hours_remaining = 0; +static int16_t discharge_current = 0; +static int16_t charge_current = 0; +static int16_t temperature_average = 0; +static int16_t temp_min = 0; +static int16_t temp_max = 0; +static uint16_t ampere_hours_remaining = 0; void update_values_can_sma() { //This function maps all the values fetched from battery CAN to the correct CAN messages //Calculate values @@ -111,7 +115,9 @@ void update_values_can_sma() { //This function maps all the values fetched from //The above calculation results in (30 000*10)/3700=81A discharge_current = (discharge_current * 10); //Value needs a decimal before getting sent to inverter (81.0A) - temperature_average = ((temperature_max + temperature_min) / 2); + temp_min = temperature_min; //Convert from unsigned to signed + temp_max = temperature_max; + temperature_average = ((temp_max + temp_min) / 2); ampere_hours_remaining = ((remaining_capacity_Wh / battery_voltage) * 100); //(WH[10000] * V+1[3600])*100 = 270 (27.0Ah) @@ -149,10 +155,63 @@ void update_values_can_sma() { //This function maps all the values fetched from //Temperature average SMA_4D8.data.u8[4] = (temperature_average >> 8); SMA_4D8.data.u8[5] = (temperature_average & 0x00FF); + //Battery ready + if (bms_status == ACTIVE) { + SMA_4D8.data.u8[6] = READY_STATE; + } else { + SMA_4D8.data.u8[6] = STOP_STATE; + } //Error bits + /* //SMA_158.data.u8[0] = //bit12 Fault high temperature, bit34Battery cellundervoltage, bit56 Battery cell overvoltage, bit78 batterysystemdefect //TODO: add all error bits. Sending message with all 0xAA until that. + + 0x158 can be used to send error messages or warnings. + + Each message is defined of two bits: + 01=message triggered + 10=no message triggered + 0xA9=10101001, triggers first message + 0xA6=10100110, triggers second message + 0x9A=10011010, triggers third message + 0x6A=01101010, triggers forth message + bX defines the byte + + b0 A9 Battery system defect + b0 A6 Battery cell overvoltage fault + b0 9A Battery cell undervoltage fault + b0 6A Battery high temperature fault + b1 A9 Battery low temperature fault + b1 A6 Battery high temperature fault + b1 9A Battery low temperature fault + b1 6A Overload (reboot required) + b2 A9 Overload (reboot required) + b2 A6 Incorrect switch position for the battery disconnection point + b2 9A Battery system short circuit + b2 6A Internal battery hardware fault + b3 A9 Battery imbalancing fault + b3 A6 Battery service life expiry + b3 9A Battery system thermal management defective + b3 6A Internal battery hardware fault + b4 A9 Battery system defect (warning) + b4 A6 Battery cell overvoltage fault (warning) + b4 9A Battery cell undervoltage fault (warning) + b4 6A Battery high temperature fault (warning) + b5 A9 Battery low temperature fault (warning) + b5 A6 Battery high temperature fault (warning) + b5 9A Battery low temperature fault (warning) + b5 6A Self-diagnosis (warning) + b6 A9 Self-diagnosis (warning) + b6 A6 Incorrect switch position for the battery disconnection point (warning) + b6 9A Battery system short circuit (warning) + b6 6A Internal battery hardware fault (warning) + b7 A9 Battery imbalancing fault (warning) + b7 A6 Battery service life expiry (warning) + b7 9A Battery system thermal management defective (warning) + b7 6A Internal battery hardware fault (warning) + +*/ } void receive_can_sma(CAN_frame_t rx_frame) { @@ -164,11 +223,11 @@ void receive_can_sma(CAN_frame_t rx_frame) { case 0x420: //Message originating from SMA inverter - Timestamp //Frame0-3 Timestamp break; - case 0x660: //Message originating from SMA inverter + case 0x3E0: //Message originating from SMA inverter - ? break; - case 0x5E0: //Message originating from SMA inverter + case 0x5E0: //Message originating from SMA inverter - String break; - case 0x560: //Message originating from SMA inverter + case 0x560: //Message originating from SMA inverter - Init break; default: break; @@ -185,9 +244,9 @@ void send_can_sma() { ESP32Can.CANWriteFrame(&SMA_558); ESP32Can.CANWriteFrame(&SMA_598); ESP32Can.CANWriteFrame(&SMA_5D8); - ESP32Can.CANWriteFrame(&SMA_618_1); - ESP32Can.CANWriteFrame(&SMA_618_2); - ESP32Can.CANWriteFrame(&SMA_618_3); + ESP32Can.CANWriteFrame(&SMA_618_1); // TODO, should these 3x + ESP32Can.CANWriteFrame(&SMA_618_2); // be sent as batch? + ESP32Can.CANWriteFrame(&SMA_618_3); // or alternate on each send? ESP32Can.CANWriteFrame(&SMA_358); ESP32Can.CANWriteFrame(&SMA_3D8); ESP32Can.CANWriteFrame(&SMA_458); diff --git a/Software/src/inverter/SMA-CAN.h b/Software/src/inverter/SMA-CAN.h index ad8fa09d..c760f4a5 100644 --- a/Software/src/inverter/SMA-CAN.h +++ b/Software/src/inverter/SMA-CAN.h @@ -19,11 +19,15 @@ extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 funct extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) extern uint16_t cell_max_voltage; //mV, 0-4350 extern uint16_t cell_min_voltage; //mV, 0-4350 +extern uint8_t bms_status; extern uint16_t min_voltage; extern uint16_t max_voltage; extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false +#define READY_STATE 0x03 +#define STOP_STATE 0x02 + void update_values_can_sma(); void send_can_sma(); void receive_can_sma(CAN_frame_t rx_frame); From b7696f3baa714f5913b636b85cdecd57a859379c Mon Sep 17 00:00:00 2001 From: Cabooman <81711263+Cabooman@users.noreply.github.com> Date: Fri, 16 Feb 2024 21:02:44 +0100 Subject: [PATCH 05/15] Initial commit --- Software/Software.ino | 124 +----------------- Software/USER_SETTINGS.cpp | 10 +- Software/USER_SETTINGS.h | 4 +- Software/src/battery/BATTERIES.h | 7 + Software/src/battery/BMW-I3-BATTERY.cpp | 15 ++- Software/src/battery/BMW-I3-BATTERY.h | 6 +- Software/src/battery/CHADEMO-BATTERY.cpp | 13 +- Software/src/battery/CHADEMO-BATTERY.h | 6 +- .../src/battery/IMIEV-CZERO-ION-BATTERY.cpp | 13 +- .../src/battery/IMIEV-CZERO-ION-BATTERY.h | 6 +- .../src/battery/KIA-HYUNDAI-64-BATTERY.cpp | 13 +- Software/src/battery/KIA-HYUNDAI-64-BATTERY.h | 5 +- Software/src/battery/NISSAN-LEAF-BATTERY.cpp | 13 +- Software/src/battery/NISSAN-LEAF-BATTERY.h | 5 +- .../src/battery/RENAULT-KANGOO-BATTERY.cpp | 13 +- Software/src/battery/RENAULT-KANGOO-BATTERY.h | 5 +- Software/src/battery/RENAULT-ZOE-BATTERY.cpp | 13 +- Software/src/battery/RENAULT-ZOE-BATTERY.h | 6 +- .../src/battery/SANTA-FE-PHEV-BATTERY.cpp | 13 +- Software/src/battery/SANTA-FE-PHEV-BATTERY.h | 5 +- .../src/battery/TESLA-MODEL-3-BATTERY.cpp | 13 +- Software/src/battery/TESLA-MODEL-3-BATTERY.h | 5 +- Software/src/battery/TEST-FAKE-BATTERY.cpp | 15 ++- Software/src/battery/TEST-FAKE-BATTERY.h | 6 +- 24 files changed, 140 insertions(+), 194 deletions(-) diff --git a/Software/Software.ino b/Software/Software.ino index e2b4e5a1..a21c44d7 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -360,36 +360,7 @@ void inform_user_on_inverter() { void inform_user_on_battery() { // Inform user what battery is used -#ifdef BMW_I3_BATTERY - Serial.println("BMW i3 battery selected"); -#endif -#ifdef CHADEMO_BATTERY - Serial.println("Chademo battery selected"); -#endif -#ifdef IMIEV_CZERO_ION_BATTERY - Serial.println("Mitsubishi i-MiEV / Citroen C-Zero / Peugeot Ion battery selected"); -#endif -#ifdef KIA_HYUNDAI_64_BATTERY - Serial.println("Kia Niro / Hyundai Kona 64kWh battery selected"); -#endif -#ifdef NISSAN_LEAF_BATTERY - Serial.println("Nissan LEAF battery selected"); -#endif -#ifdef RENAULT_KANGOO_BATTERY - Serial.println("Renault Kangoo battery selected"); -#endif -#ifdef SANTA_FE_PHEV_BATTERY - Serial.println("Hyundai Santa Fe PHEV battery selected"); -#endif -#ifdef RENAULT_ZOE_BATTERY - Serial.println("Renault Zoe battery selected"); -#endif -#ifdef TESLA_MODEL_3_BATTERY - Serial.println("Tesla Model 3 battery selected"); -#endif -#ifdef TEST_FAKE_BATTERY - Serial.println("Test mode with fake battery selected"); -#endif + announce_battery(); #ifdef SERIAL_LINK_RECEIVER Serial.println("SERIAL_DATA_LINK_RECEIVER selected"); #endif @@ -406,36 +377,7 @@ void receive_can() { // This section checks if we have a complete CAN message i if (rx_frame.FIR.B.FF == CAN_frame_std) { //printf("New standard frame"); // Battery -#ifdef BMW_I3_BATTERY - receive_can_i3_battery(rx_frame); -#endif -#ifdef CHADEMO_BATTERY - receive_can_chademo_battery(rx_frame); -#endif -#ifdef IMIEV_CZERO_ION_BATTERY - receive_can_imiev_battery(rx_frame); -#endif -#ifdef KIA_HYUNDAI_64_BATTERY - receive_can_kiaHyundai_64_battery(rx_frame); -#endif -#ifdef NISSAN_LEAF_BATTERY - receive_can_leaf_battery(rx_frame); -#endif -#ifdef RENAULT_KANGOO_BATTERY - receive_can_kangoo_battery(rx_frame); -#endif -#ifdef SANTA_FE_PHEV_BATTERY - receive_can_santafe_phev_battery(rx_frame); -#endif -#ifdef RENAULT_ZOE_BATTERY - receive_can_zoe_battery(rx_frame); -#endif -#ifdef TESLA_MODEL_3_BATTERY - receive_can_tesla_model_3_battery(rx_frame); -#endif -#ifdef TEST_FAKE_BATTERY - receive_can_test_battery(rx_frame); -#endif + receive_can_battery(rx_frame); // Inverter #ifdef BYD_CAN receive_can_byd(rx_frame); @@ -484,36 +426,7 @@ void send_can() { send_can_sofar(); #endif // Battery -#ifdef BMW_I3_BATTERY - send_can_i3_battery(); -#endif -#ifdef CHADEMO_BATTERY - send_can_chademo_battery(); -#endif -#ifdef IMIEV_CZERO_ION_BATTERY - send_can_imiev_battery(); -#endif -#ifdef KIA_HYUNDAI_64_BATTERY - send_can_kiaHyundai_64_battery(); -#endif -#ifdef NISSAN_LEAF_BATTERY - send_can_leaf_battery(); -#endif -#ifdef RENAULT_KANGOO_BATTERY - send_can_kangoo_battery(); -#endif -#ifdef SANTA_FE_PHEV_BATTERY - send_can_santafe_phev_battery(); -#endif -#ifdef RENAULT_ZOE_BATTERY - send_can_zoe_battery(); -#endif -#ifdef TESLA_MODEL_3_BATTERY - send_can_tesla_model_3_battery(); -#endif -#ifdef TEST_FAKE_BATTERY - send_can_test_battery(); -#endif + send_can_battery(); #ifdef CHEVYVOLT_CHARGER send_can_chevyvolt_charger(); #endif @@ -693,36 +606,7 @@ void handle_contactors() { void update_values() { // Battery -#ifdef BMW_I3_BATTERY - update_values_i3_battery(); // Map the values to the correct registers -#endif -#ifdef CHADEMO_BATTERY - update_values_chademo_battery(); // Map the values to the correct registers -#endif -#ifdef IMIEV_CZERO_ION_BATTERY - update_values_imiev_battery(); // Map the values to the correct registers -#endif -#ifdef KIA_HYUNDAI_64_BATTERY - update_values_kiaHyundai_64_battery(); // Map the values to the correct registers -#endif -#ifdef NISSAN_LEAF_BATTERY - update_values_leaf_battery(); // Map the values to the correct registers -#endif -#ifdef RENAULT_KANGOO_BATTERY - update_values_kangoo_battery(); // Map the values to the correct registers -#endif -#ifdef SANTA_FE_PHEV_BATTERY - update_values_santafe_phev_battery(); // Map the values to the correct registers -#endif -#ifdef RENAULT_ZOE_BATTERY - update_values_zoe_battery(); // Map the values to the correct registers -#endif -#ifdef TESLA_MODEL_3_BATTERY - update_values_tesla_model_3_battery(); // Map the values to the correct registers -#endif -#ifdef TEST_FAKE_BATTERY - update_values_test_battery(); // Map the fake values to the correct registers -#endif + update_values_battery(); // Map the fake values to the correct registers // Inverter #ifdef BYD_CAN update_values_can_byd(); diff --git a/Software/USER_SETTINGS.cpp b/Software/USER_SETTINGS.cpp index bcc2a677..a232190d 100644 --- a/Software/USER_SETTINGS.cpp +++ b/Software/USER_SETTINGS.cpp @@ -27,16 +27,16 @@ volatile float CHARGER_END_A = 1.0; // Current at which charging is consid #ifdef WEBSERVER volatile uint8_t AccessPointEnabled = true; //Set to either true or false incase you want the board to enable a direct wifi access point -const char* ssid = "REPLACE_WITH_YOUR_SSID"; // Maximum of 63 characters; -const char* password = "REPLACE_WITH_YOUR_PASSWORD"; // Minimum of 8 characters; -const char* ssidAP = "Battery Emulator"; // Maximum of 63 characters; +const char* ssid = "comhem_F0A1A5"; // Maximum of 63 characters; +const char* password = "3027CCA803"; // Minimum of 8 characters; +const char* ssidAP = "Battery Emulator"; // Maximum of 63 characters; const char* passwordAP = "123456789"; // Minimum of 8 characters; set to NULL if you want the access point to be open const uint8_t wifi_channel = 0; // set to 0 for automatic channel selection // MQTT #ifdef MQTT -const char* mqtt_user = "REDACTED"; -const char* mqtt_password = "REDACTED"; +const char* mqtt_user = "test"; +const char* mqtt_password = "test"; #endif // USE_MQTT #endif diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h index 708e692d..f86bdc3e 100644 --- a/Software/USER_SETTINGS.h +++ b/Software/USER_SETTINGS.h @@ -17,11 +17,11 @@ //#define RENAULT_ZOE_BATTERY //#define SANTA_FE_PHEV_BATTERY //#define TESLA_MODEL_3_BATTERY -//#define TEST_FAKE_BATTERY +#define TEST_FAKE_BATTERY /* Select inverter communication protocol. See Wiki for which to use with your inverter: https://github.com/dalathegreat/BYD-Battery-Emulator-For-Gen24/wiki */ //#define BYD_CAN //Enable this line to emulate a "BYD Battery-Box Premium HVS" over CAN Bus -//#define BYD_MODBUS //Enable this line to emulate a "BYD 11kWh HVM battery" over Modbus RTU +#define BYD_MODBUS //Enable this line to emulate a "BYD 11kWh HVM battery" over Modbus RTU //#define LUNA2000_MODBUS //Enable this line to emulate a "Luna2000 battery" over Modbus RTU //#define PYLON_CAN //Enable this line to emulate a "Pylontech battery" over CAN bus //#define SMA_CAN //Enable this line to emulate a "BYD Battery-Box H 8.9kWh, 7 mod" over CAN bus diff --git a/Software/src/battery/BATTERIES.h b/Software/src/battery/BATTERIES.h index 2f823ab3..e80ea3c4 100644 --- a/Software/src/battery/BATTERIES.h +++ b/Software/src/battery/BATTERIES.h @@ -48,4 +48,11 @@ #include "SERIAL-LINK-RECEIVER-FROM-BATTERY.h" //See this file for more Serial-battery settings #endif +#ifndef SERIAL_LINK_RECEIVER // The serial thing does its thing +void update_values_battery(); +void receive_can_battery(CAN_frame_t rx_frame); +void send_can_battery(); +void announce_battery(void); +#endif + #endif diff --git a/Software/src/battery/BMW-I3-BATTERY.cpp b/Software/src/battery/BMW-I3-BATTERY.cpp index 5d53c10e..2b112a9a 100644 --- a/Software/src/battery/BMW-I3-BATTERY.cpp +++ b/Software/src/battery/BMW-I3-BATTERY.cpp @@ -1,10 +1,11 @@ +#ifdef BMW_I3_BATTERY #include "BMW-I3-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" //TODO: before using -// Map the final values in update_values_i3_battery, set some to static values if not available (current, discharge max , charge max) +// Map the final values in update_values_battery, set some to static values if not available (current, discharge max , charge max) // Check if I3 battery stays alive with only 10B and 512. If not, add 12F. If that doesn't help, add more from CAN log (ask Dala) /* Do not change code below unless you are sure what you are doing */ @@ -54,7 +55,7 @@ static uint16_t Battery_Status = 0; static uint16_t DC_link = 0; static int16_t Battery_Power = 0; -void update_values_i3_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 //Calculate the SOC% value to send to inverter Calculated_SOC = (Display_SOC * 10); //Increase decimal amount Calculated_SOC = @@ -122,7 +123,7 @@ void update_values_i3_battery() { //This function maps all the values fetched v #endif } -void receive_can_i3_battery(CAN_frame_t rx_frame) { +void receive_can_battery(CAN_frame_t rx_frame) { CANstillAlive = 12; switch (rx_frame.MsgID) { case 0x431: //Battery capacity [200ms] @@ -168,7 +169,7 @@ void receive_can_i3_battery(CAN_frame_t rx_frame) { break; } } -void send_can_i3_battery() { +void send_can_battery() { unsigned long currentMillis = millis(); // Send 600ms CAN Message if (currentMillis - previousMillis600 >= interval600) { @@ -190,3 +191,9 @@ void send_can_i3_battery() { ESP32Can.CANWriteFrame(&BMW_10B); } } + +void announce_battery(void) { + Serial.println("BMW i3 battery selected"); +} + +#endif diff --git a/Software/src/battery/BMW-I3-BATTERY.h b/Software/src/battery/BMW-I3-BATTERY.h index 99bc8a8c..4e3697d7 100644 --- a/Software/src/battery/BMW-I3-BATTERY.h +++ b/Software/src/battery/BMW-I3-BATTERY.h @@ -5,6 +5,8 @@ #include "../devboard/config.h" // Needed for all defines #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#define BATTERY_SELECTED + #define ABSOLUTE_MAX_VOLTAGE \ 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) #define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled @@ -26,8 +28,4 @@ extern uint16_t CANerror; extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false -void update_values_i3_battery(); -void receive_can_i3_battery(CAN_frame_t rx_frame); -void send_can_i3_battery(); - #endif diff --git a/Software/src/battery/CHADEMO-BATTERY.cpp b/Software/src/battery/CHADEMO-BATTERY.cpp index 95a03c57..54d69243 100644 --- a/Software/src/battery/CHADEMO-BATTERY.cpp +++ b/Software/src/battery/CHADEMO-BATTERY.cpp @@ -1,3 +1,4 @@ +#ifdef CHADEMO_BATTERY #include "CHADEMO-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" @@ -89,7 +90,7 @@ uint8_t DynamicControlStatus = 0; uint8_t HighCurrentControlStatus = 0; uint8_t HighVoltageControlStatus = 0; -void update_values_chademo_battery() { //This function maps all the values fetched via CAN to the correct parameters used for the inverter +void update_values_battery() { //This function maps all the values fetched via CAN to the correct parameters used for the inverter SOC = ChargingRate; @@ -146,7 +147,7 @@ void update_values_chademo_battery() { //This function maps all the values fetc #endif } -void receive_can_chademo_battery(CAN_frame_t rx_frame) { +void receive_can_battery(CAN_frame_t rx_frame) { CANstillAlive == 12; //We are getting CAN messages from the vehicle, inform the watchdog switch (rx_frame.MsgID) { @@ -202,7 +203,7 @@ void receive_can_chademo_battery(CAN_frame_t rx_frame) { break; } } -void send_can_chademo_battery() { +void send_can_battery() { unsigned long currentMillis = millis(); // Send 100ms CAN Message if (currentMillis - previousMillis100 >= interval100) { @@ -218,3 +219,9 @@ void send_can_chademo_battery() { } } } + +void announce_battery(void) { + Serial.println("Chademo battery selected"); +} + +#endif diff --git a/Software/src/battery/CHADEMO-BATTERY.h b/Software/src/battery/CHADEMO-BATTERY.h index 6eccc66c..1bce665b 100644 --- a/Software/src/battery/CHADEMO-BATTERY.h +++ b/Software/src/battery/CHADEMO-BATTERY.h @@ -5,6 +5,8 @@ #include "../devboard/config.h" // Needed for all defines #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#define BATTERY_SELECTED + #define ABSOLUTE_MAX_VOLTAGE \ 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) #define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled @@ -27,8 +29,4 @@ extern uint16_t CANerror; extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false -void update_values_chademo_battery(); -void receive_can_chademo_battery(CAN_frame_t rx_frame); -void send_can_chademo_battery(); - #endif diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp index e2e68a3d..16da252a 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp @@ -1,3 +1,4 @@ +#ifdef IMIEV_CZERO_ION_BATTERY #include "IMIEV-CZERO-ION-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" @@ -40,7 +41,7 @@ static double min_volt_cel = 3.70; static double max_temp_cel = 20.00; static double min_temp_cel = 19.00; -void update_values_imiev_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 SOC = (uint16_t)(BMU_SOC * 100); //increase BMU_SOC range from 0-100 -> 100.00 battery_voltage = (uint16_t)(BMU_PackVoltage * 10); // Multiply by 10 and cast to uint16_t @@ -161,7 +162,7 @@ void update_values_imiev_battery() { //This function maps all the values fetche #endif } -void receive_can_imiev_battery(CAN_frame_t rx_frame) { +void receive_can_battery(CAN_frame_t rx_frame) { CANstillAlive = 12; //TODO: move this inside a known message ID to prevent CAN inverter from keeping battery alive detection going switch (rx_frame.MsgID) { @@ -217,10 +218,16 @@ void receive_can_imiev_battery(CAN_frame_t rx_frame) { } } -void send_can_imiev_battery() { +void send_can_battery() { unsigned long currentMillis = millis(); // Send 100ms CAN Message if (currentMillis - previousMillis100 >= interval100) { previousMillis100 = currentMillis; } } + +void announce_battery(void) { + Serial.println("Mitsubishi i-MiEV / Citroen C-Zero / Peugeot Ion battery selected"); +} + +#endif diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h index d72ba04a..1d125a08 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h @@ -5,6 +5,8 @@ #include "../devboard/config.h" // Needed for all defines #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#define BATTERY_SELECTED + #define ABSOLUTE_MAX_VOLTAGE \ 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) #define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled @@ -28,8 +30,4 @@ extern uint16_t cell_min_voltage; extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false -void update_values_imiev_battery(); -void receive_can_imiev_battery(CAN_frame_t rx_frame); -void send_can_imiev_battery(); - #endif diff --git a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp index d2011e36..3ef0f79a 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp +++ b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp @@ -1,3 +1,4 @@ +#ifdef KIA_HYUNDAI_64_BATTERY #include "KIA-HYUNDAI-64-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" @@ -146,7 +147,7 @@ CAN_frame_t KIA64_7E4_ack = { .MsgID = 0x7E4, .data = {0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; //Ack frame, correct PID is returned -void update_values_kiaHyundai_64_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 //Calculate the SOC% value to send to inverter soc_calculated = SOC_Display; @@ -293,7 +294,7 @@ void update_values_kiaHyundai_64_battery() { //This function maps all the value #endif } -void receive_can_kiaHyundai_64_battery(CAN_frame_t rx_frame) { +void receive_can_battery(CAN_frame_t rx_frame) { switch (rx_frame.MsgID) { case 0x4DE: break; @@ -523,7 +524,7 @@ void receive_can_kiaHyundai_64_battery(CAN_frame_t rx_frame) { } } -void send_can_kiaHyundai_64_battery() { +void send_can_battery() { unsigned long currentMillis = millis(); //Send 100ms message if (currentMillis - previousMillis100 >= interval100) { @@ -596,3 +597,9 @@ uint16_t convertToUnsignedInt16(int16_t signed_value) { return (uint16_t)signed_value; } } + +void announce_battery(void) { + Serial.println("Kia Niro / Hyundai Kona 64kWh battery selected"); +} + +#endif diff --git a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h index ff357842..36e63b4c 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h +++ b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h @@ -5,6 +5,8 @@ #include "../devboard/config.h" // Needed for all defines #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#define BATTERY_SELECTED + #define ABSOLUTE_MAX_VOLTAGE \ 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) #define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled @@ -31,9 +33,6 @@ extern uint8_t nof_cellvoltages; // Total number of cell voltages, set by eac extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false -void update_values_kiaHyundai_64_battery(); -void receive_can_kiaHyundai_64_battery(CAN_frame_t rx_frame); -void send_can_kiaHyundai_64_battery(); uint16_t convertToUnsignedInt16(int16_t signed_value); #endif diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp index aecf242d..b538933b 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp @@ -1,3 +1,4 @@ +#ifdef NISSAN_LEAF_BATTERY #include "NISSAN-LEAF-BATTERY.h" #ifdef MQTT #include "../devboard/mqtt/mqtt.h" @@ -165,7 +166,7 @@ void print_with_units(char* header, int value, char* units) { Serial.print(units); } -void update_values_leaf_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 */ /* Start with mapping all values */ StateOfHealth = (LB_StateOfHealth * 100); //Increase range from 99% -> 99.00% @@ -425,7 +426,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched #endif } -void receive_can_leaf_battery(CAN_frame_t rx_frame) { +void receive_can_battery(CAN_frame_t rx_frame) { switch (rx_frame.MsgID) { case 0x1DB: if (is_message_corrupt(rx_frame)) { @@ -689,7 +690,7 @@ void receive_can_leaf_battery(CAN_frame_t rx_frame) { break; } } -void send_can_leaf_battery() { +void send_can_battery() { unsigned long currentMillis = millis(); // Send 100ms CAN Message if (currentMillis - previousMillis100 >= interval100) { @@ -923,3 +924,9 @@ uint16_t Temp_fromRAW_to_F(uint16_t temperature) { //This function feels horrib void init_battery(void) { nof_cellvoltages = 96; } + +void announce_battery(void) { + Serial.println("Nissan LEAF battery selected"); +} + +#endif diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.h b/Software/src/battery/NISSAN-LEAF-BATTERY.h index 34fdf23d..12b183aa 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.h +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.h @@ -5,6 +5,8 @@ #include "../devboard/config.h" // Needed for all defines #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#define BATTERY_SELECTED + #define ABSOLUTE_MAX_VOLTAGE \ 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) #define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled @@ -28,9 +30,6 @@ extern uint16_t cellvoltages[120]; //mV 0-4350 per cell extern uint8_t nof_cellvoltages; // Total number of cell voltages, set by each battery. extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false -void update_values_leaf_battery(); -void receive_can_leaf_battery(CAN_frame_t rx_frame); -void send_can_leaf_battery(); uint16_t convert2unsignedint16(int16_t signed_value); uint16_t Temp_fromRAW_to_F(uint16_t temperature); bool is_message_corrupt(CAN_frame_t rx_frame); diff --git a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp index 1173cd21..b72bfbdd 100644 --- a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp +++ b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp @@ -1,3 +1,4 @@ +#ifdef RENAULT_KANGOO_BATTERY #include "RENAULT-KANGOO-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" @@ -57,7 +58,7 @@ static const int interval10 = 10; // interval (ms) at which send CAN Messag static const int interval100 = 100; // interval (ms) at which send CAN Messages static const int interval1000 = 1000; // interval (ms) at which send CAN Messages -void update_values_kangoo_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 StateOfHealth = (LB_SOH * 100); //Increase range from 99% -> 99.00% //Calculate the SOC% value to send to Fronius @@ -175,7 +176,7 @@ void update_values_kangoo_battery() { //This function maps all the values fetch #endif } -void receive_can_kangoo_battery(CAN_frame_t rx_frame) //GKOE reworked +void receive_can_battery(CAN_frame_t rx_frame) //GKOE reworked { switch (rx_frame.MsgID) { @@ -237,7 +238,7 @@ void receive_can_kangoo_battery(CAN_frame_t rx_frame) //GKOE reworked } } -void send_can_kangoo_battery() { +void send_can_battery() { unsigned long currentMillis = millis(); // Send 100ms CAN Message (for 2.4s, then pause 10s) if ((currentMillis - previousMillis100) >= (interval100 + GVL_pause)) { @@ -267,3 +268,9 @@ uint16_t convert2uint16(int16_t signed_value) { return (uint16_t)signed_value; } } + +void announce_battery(void) { + Serial.println("Renault Kangoo battery selected"); +} + +#endif diff --git a/Software/src/battery/RENAULT-KANGOO-BATTERY.h b/Software/src/battery/RENAULT-KANGOO-BATTERY.h index 105f60a9..bfa8c9d6 100644 --- a/Software/src/battery/RENAULT-KANGOO-BATTERY.h +++ b/Software/src/battery/RENAULT-KANGOO-BATTERY.h @@ -5,6 +5,8 @@ #include "../devboard/config.h" // Needed for defines #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#define BATTERY_SELECTED + #define ABSOLUTE_MAX_VOLTAGE \ 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) #define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled @@ -33,9 +35,6 @@ extern uint16_t CANerror; extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false -void update_values_kangoo_battery(); -void receive_can_kangoo_battery(CAN_frame_t rx_frame); -void send_can_kangoo_battery(); uint16_t convert2uint16(int16_t signed_value); #endif diff --git a/Software/src/battery/RENAULT-ZOE-BATTERY.cpp b/Software/src/battery/RENAULT-ZOE-BATTERY.cpp index bf9c7b4a..8cb010ba 100644 --- a/Software/src/battery/RENAULT-ZOE-BATTERY.cpp +++ b/Software/src/battery/RENAULT-ZOE-BATTERY.cpp @@ -1,3 +1,4 @@ +#ifdef RENAULT_ZOE_BATTERY #include "RENAULT-ZOE-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" @@ -42,7 +43,7 @@ static const int interval10 = 10; // interval (ms) at which send CAN Messag static const int interval100 = 100; // interval (ms) at which send CAN Messages static const int interval1000 = 1000; // interval (ms) at which send CAN Messages -void update_values_zoe_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 StateOfHealth = (LB_SOH * 100); //Increase range from 99% -> 99.00% //Calculate the SOC% value to send to Fronius @@ -136,7 +137,7 @@ void update_values_zoe_battery() { //This function maps all the values fetched #endif } -void receive_can_zoe_battery(CAN_frame_t rx_frame) { +void receive_can_battery(CAN_frame_t rx_frame) { switch (rx_frame.MsgID) { case 0x42E: //HV SOC & Battery Temp & Charging Power @@ -150,7 +151,7 @@ void receive_can_zoe_battery(CAN_frame_t rx_frame) { } } -void send_can_zoe_battery() { +void send_can_battery() { unsigned long currentMillis = millis(); // Send 100ms CAN Message if (currentMillis - previousMillis100 >= interval100) { @@ -163,3 +164,9 @@ void send_can_zoe_battery() { //ESP32Can.CANWriteFrame(&ZOE_423); } } + +void announce_battery(void) { + Serial.println("Renault Zoe battery selected"); +} + +#endif diff --git a/Software/src/battery/RENAULT-ZOE-BATTERY.h b/Software/src/battery/RENAULT-ZOE-BATTERY.h index 7a2e46c4..7fbf5beb 100644 --- a/Software/src/battery/RENAULT-ZOE-BATTERY.h +++ b/Software/src/battery/RENAULT-ZOE-BATTERY.h @@ -5,6 +5,8 @@ #include "../devboard/config.h" // Needed for all defines #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#define BATTERY_SELECTED + #define ABSOLUTE_MAX_VOLTAGE \ 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) #define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled @@ -33,8 +35,4 @@ extern uint16_t CANerror; extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false -void update_values_zoe_battery(); -void receive_can_zoe_battery(CAN_frame_t rx_frame); -void send_can_zoe_battery(); - #endif diff --git a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp index 1e7b2b94..c8ca2ee7 100644 --- a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp +++ b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp @@ -1,3 +1,4 @@ +#ifdef SANTA_FE_PHEV_BATTERY #include "SANTA-FE-PHEV-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" @@ -57,7 +58,7 @@ CAN_frame_t SANTAFE_523 = {.FIR = {.B = .MsgID = 0x523, .data = {0x60, 0x00, 0x60, 0, 0, 0, 0, 0}}; -void update_values_santafe_phev_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 SOC; @@ -92,7 +93,7 @@ void update_values_santafe_phev_battery() { //This function maps all the values #endif } -void receive_can_santafe_phev_battery(CAN_frame_t rx_frame) { +void receive_can_battery(CAN_frame_t rx_frame) { CANstillAlive = 12; switch (rx_frame.MsgID) { case 0x200: @@ -127,7 +128,7 @@ void receive_can_santafe_phev_battery(CAN_frame_t rx_frame) { break; } } -void send_can_santafe_phev_battery() { +void send_can_battery() { unsigned long currentMillis = millis(); //Send 10ms message if (currentMillis - previousMillis10 >= interval10) { @@ -174,3 +175,9 @@ uint8_t CalculateCRC8(CAN_frame_t rx_frame) { } return (uint8_t)crc; } + +void announce_battery(void) { + Serial.println("Hyundai Santa Fe PHEV battery selected"); +} + +#endif diff --git a/Software/src/battery/SANTA-FE-PHEV-BATTERY.h b/Software/src/battery/SANTA-FE-PHEV-BATTERY.h index f2d977f8..c96b0673 100644 --- a/Software/src/battery/SANTA-FE-PHEV-BATTERY.h +++ b/Software/src/battery/SANTA-FE-PHEV-BATTERY.h @@ -5,6 +5,8 @@ #include "../devboard/config.h" // Needed for all defines #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#define BATTERY_SELECTED + #define ABSOLUTE_MAX_VOLTAGE \ 4030 // 403.0V,if battery voltage goes over this, charging is not possible (goes into forced discharge) #define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled @@ -26,9 +28,6 @@ extern uint16_t CANerror; extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false -void update_values_santafe_phev_battery(); -void receive_can_santafe_phev_battery(CAN_frame_t rx_frame); -void send_can_santafe_phev_battery(); uint8_t CalculateCRC8(CAN_frame_t rx_frame); #endif diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp index 3e9508a7..942fdb9a 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp @@ -1,3 +1,4 @@ +#ifdef TESLA_MODEL_3_BATTERY #include "TESLA-MODEL-3-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" @@ -163,7 +164,7 @@ static const char* hvilStatusState[] = {"NOT OK", #define REASONABLE_ENERGYAMOUNT 20 //When the BMS stops making sense on some values, they are always <20 -void update_values_tesla_model_3_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 //After values are mapped, we perform some safety checks, and do some serial printouts //Calculate the SOH% to send to inverter if (bat_beginning_of_life != 0) { //div/0 safeguard @@ -368,7 +369,7 @@ void update_values_tesla_model_3_battery() { //This function maps all the value #endif } -void receive_can_tesla_model_3_battery(CAN_frame_t rx_frame) { +void receive_can_battery(CAN_frame_t rx_frame) { static int mux = 0; static int temp = 0; @@ -558,7 +559,7 @@ void receive_can_tesla_model_3_battery(CAN_frame_t rx_frame) { break; } } -void send_can_tesla_model_3_battery() { +void send_can_battery() { /*From bielec: My fist 221 message, to close the contactors is 0x41, 0x11, 0x01, 0x00, 0x00, 0x00, 0x20, 0x96 and then, to cause "hv_up_for_drive" I send an additional 221 message 0x61, 0x15, 0x01, 0x00, 0x00, 0x00, 0x20, 0xBA so two 221 messages are being continuously transmitted. When I want to shut down, I stop the second message and only send @@ -683,3 +684,9 @@ void printDebugIfActive(uint8_t symbol, const char* message) { Serial.println(message); } } + +void announce_battery(void) { + Serial.println("Tesla Model 3 battery selected"); +} + +#endif diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.h b/Software/src/battery/TESLA-MODEL-3-BATTERY.h index ed2ba9c1..5d4904d0 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.h +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.h @@ -5,6 +5,8 @@ #include "../devboard/config.h" // Needed for all defines #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#define BATTERY_SELECTED + #define ABSOLUTE_MAX_VOLTAGE \ 4030 // 403.0V,if battery voltage goes over this, charging is not possible (goes into forced discharge) #define ABSOLUTE_MIN_VOLTAGE 2450 // 245.0V if battery voltage goes under this, discharging further is disabled @@ -33,9 +35,6 @@ extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false extern bool LFP_Chemistry; -void update_values_tesla_model_3_battery(); -void receive_can_tesla_model_3_battery(CAN_frame_t rx_frame); -void send_can_tesla_model_3_battery(); void printFaultCodesIfActive(); void printDebugIfActive(uint8_t symbol, const char* message); void print_int_with_units(char* header, int value, char* units); diff --git a/Software/src/battery/TEST-FAKE-BATTERY.cpp b/Software/src/battery/TEST-FAKE-BATTERY.cpp index dcce6e04..18300a95 100644 --- a/Software/src/battery/TEST-FAKE-BATTERY.cpp +++ b/Software/src/battery/TEST-FAKE-BATTERY.cpp @@ -1,3 +1,4 @@ +#ifdef TEST_FAKE_BATTERY #include "TEST-FAKE-BATTERY.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" @@ -16,8 +17,8 @@ void print_units(char* header, int value, char* units) { Serial.print(units); } -void update_values_test_battery() { /* This function puts fake values onto the parameters sent towards the inverter */ - SOC = 5000; // 50.00% +void update_values_battery() { /* This function puts fake values onto the parameters sent towards the inverter */ + SOC = 5000; // 50.00% StateOfHealth = 9900; // 99.00% @@ -63,7 +64,7 @@ void update_values_test_battery() { /* This function puts fake values onto the p #endif } -void receive_can_test_battery(CAN_frame_t rx_frame) { +void receive_can_battery(CAN_frame_t rx_frame) { switch (rx_frame.MsgID) { case 0xABC: break; @@ -71,7 +72,7 @@ void receive_can_test_battery(CAN_frame_t rx_frame) { break; } } -void send_can_test_battery() { +void send_can_battery() { unsigned long currentMillis = millis(); // Send 100ms CAN Message if (currentMillis - previousMillis100 >= interval100) { @@ -79,3 +80,9 @@ void send_can_test_battery() { // Put fake messages here incase you want to test sending CAN } } + +void announce_battery(void) { + Serial.println("Test mode with fake battery selected"); +} + +#endif diff --git a/Software/src/battery/TEST-FAKE-BATTERY.h b/Software/src/battery/TEST-FAKE-BATTERY.h index 8fde83ad..877b2736 100644 --- a/Software/src/battery/TEST-FAKE-BATTERY.h +++ b/Software/src/battery/TEST-FAKE-BATTERY.h @@ -5,6 +5,8 @@ #include "../devboard/config.h" // Needed for all defines #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#define BATTERY_SELECTED + #define ABSOLUTE_MAX_VOLTAGE \ 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) #define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled @@ -29,8 +31,4 @@ extern uint16_t cellvoltages[120]; //mV 0-5000 per cell extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false -void update_values_test_battery(); -void receive_can_test_battery(CAN_frame_t rx_frame); -void send_can_test_battery(); - #endif From 5677c6d952c93fbe0f8a117b859ecfdde949e12d Mon Sep 17 00:00:00 2001 From: Cabooman <81711263+Cabooman@users.noreply.github.com> Date: Fri, 16 Feb 2024 21:06:54 +0100 Subject: [PATCH 06/15] Well... --- Software/USER_SETTINGS.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Software/USER_SETTINGS.cpp b/Software/USER_SETTINGS.cpp index a232190d..bcc2a677 100644 --- a/Software/USER_SETTINGS.cpp +++ b/Software/USER_SETTINGS.cpp @@ -27,16 +27,16 @@ volatile float CHARGER_END_A = 1.0; // Current at which charging is consid #ifdef WEBSERVER volatile uint8_t AccessPointEnabled = true; //Set to either true or false incase you want the board to enable a direct wifi access point -const char* ssid = "comhem_F0A1A5"; // Maximum of 63 characters; -const char* password = "3027CCA803"; // Minimum of 8 characters; -const char* ssidAP = "Battery Emulator"; // Maximum of 63 characters; +const char* ssid = "REPLACE_WITH_YOUR_SSID"; // Maximum of 63 characters; +const char* password = "REPLACE_WITH_YOUR_PASSWORD"; // Minimum of 8 characters; +const char* ssidAP = "Battery Emulator"; // Maximum of 63 characters; const char* passwordAP = "123456789"; // Minimum of 8 characters; set to NULL if you want the access point to be open const uint8_t wifi_channel = 0; // set to 0 for automatic channel selection // MQTT #ifdef MQTT -const char* mqtt_user = "test"; -const char* mqtt_password = "test"; +const char* mqtt_user = "REDACTED"; +const char* mqtt_password = "REDACTED"; #endif // USE_MQTT #endif From 9d9030c7dbe075707ecb830fe35daca331d92534 Mon Sep 17 00:00:00 2001 From: Cabooman <81711263+Cabooman@users.noreply.github.com> Date: Fri, 16 Feb 2024 21:10:10 +0100 Subject: [PATCH 07/15] Update Software.ino --- Software/Software.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/Software.ino b/Software/Software.ino index a21c44d7..7e08e6bc 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -364,7 +364,7 @@ void inform_user_on_battery() { #ifdef SERIAL_LINK_RECEIVER Serial.println("SERIAL_DATA_LINK_RECEIVER selected"); #endif -#if !defined(ABSOLUTE_MAX_VOLTAGE) +#ifndef BATTERY_SELECTED #error No battery selected! Choose one from the USER_SETTINGS.h file #endif } From f6b655bbe1a6084e72fda8135b740ae71591047f Mon Sep 17 00:00:00 2001 From: Cabooman <81711263+Cabooman@users.noreply.github.com> Date: Fri, 16 Feb 2024 21:13:24 +0100 Subject: [PATCH 08/15] Update USER_SETTINGS.h --- Software/USER_SETTINGS.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h index f86bdc3e..53a762cf 100644 --- a/Software/USER_SETTINGS.h +++ b/Software/USER_SETTINGS.h @@ -17,11 +17,11 @@ //#define RENAULT_ZOE_BATTERY //#define SANTA_FE_PHEV_BATTERY //#define TESLA_MODEL_3_BATTERY -#define TEST_FAKE_BATTERY +//#define TEST_FAKE_BATTERY /* Select inverter communication protocol. See Wiki for which to use with your inverter: https://github.com/dalathegreat/BYD-Battery-Emulator-For-Gen24/wiki */ //#define BYD_CAN //Enable this line to emulate a "BYD Battery-Box Premium HVS" over CAN Bus -#define BYD_MODBUS //Enable this line to emulate a "BYD 11kWh HVM battery" over Modbus RTU +//#define BYD_MODBUS //Enable this line to emulate a "BYD 11kWh HVM battery" over Modbus RTU //#define LUNA2000_MODBUS //Enable this line to emulate a "Luna2000 battery" over Modbus RTU //#define PYLON_CAN //Enable this line to emulate a "Pylontech battery" over CAN bus //#define SMA_CAN //Enable this line to emulate a "BYD Battery-Box H 8.9kWh, 7 mod" over CAN bus From e49f4d9234b9f211775be3b8e0d5d13aba2d1928 Mon Sep 17 00:00:00 2001 From: Cabooman <81711263+Cabooman@users.noreply.github.com> Date: Fri, 16 Feb 2024 21:30:22 +0100 Subject: [PATCH 09/15] Added include to compile in IDE --- Software/src/battery/BMW-I3-BATTERY.cpp | 3 ++- Software/src/battery/CHADEMO-BATTERY.cpp | 3 ++- Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp | 3 ++- Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp | 3 ++- Software/src/battery/NISSAN-LEAF-BATTERY.cpp | 1 + Software/src/battery/RENAULT-KANGOO-BATTERY.cpp | 3 ++- Software/src/battery/RENAULT-ZOE-BATTERY.cpp | 3 ++- Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp | 3 ++- Software/src/battery/TESLA-MODEL-3-BATTERY.cpp | 3 ++- Software/src/battery/TEST-FAKE-BATTERY.cpp | 3 ++- 10 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Software/src/battery/BMW-I3-BATTERY.cpp b/Software/src/battery/BMW-I3-BATTERY.cpp index 2b112a9a..ee42cae4 100644 --- a/Software/src/battery/BMW-I3-BATTERY.cpp +++ b/Software/src/battery/BMW-I3-BATTERY.cpp @@ -1,8 +1,9 @@ +#include "BATTERIES.h" #ifdef BMW_I3_BATTERY -#include "BMW-I3-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#include "BMW-I3-BATTERY.h" //TODO: before using // Map the final values in update_values_battery, set some to static values if not available (current, discharge max , charge max) diff --git a/Software/src/battery/CHADEMO-BATTERY.cpp b/Software/src/battery/CHADEMO-BATTERY.cpp index 54d69243..628746f1 100644 --- a/Software/src/battery/CHADEMO-BATTERY.cpp +++ b/Software/src/battery/CHADEMO-BATTERY.cpp @@ -1,8 +1,9 @@ +#include "BATTERIES.h" #ifdef CHADEMO_BATTERY -#include "CHADEMO-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#include "CHADEMO-BATTERY.h" /* Do not change code below unless you are sure what you are doing */ static unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was send diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp index 16da252a..4ccaf57e 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp @@ -1,8 +1,9 @@ +#include "BATTERIES.h" #ifdef IMIEV_CZERO_ION_BATTERY -#include "IMIEV-CZERO-ION-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#include "IMIEV-CZERO-ION-BATTERY.h" //Code still work in progress, TODO: //Figure out if CAN messages need to be sent to keep the system happy? diff --git a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp index 3ef0f79a..aa6d2f3d 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp +++ b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp @@ -1,8 +1,9 @@ +#include "BATTERIES.h" #ifdef KIA_HYUNDAI_64_BATTERY -#include "KIA-HYUNDAI-64-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#include "KIA-HYUNDAI-64-BATTERY.h" /* Do not change code below unless you are sure what you are doing */ static unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was send diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp index b538933b..29f19f39 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp @@ -1,3 +1,4 @@ +#include "BATTERIES.h" #ifdef NISSAN_LEAF_BATTERY #include "NISSAN-LEAF-BATTERY.h" #ifdef MQTT diff --git a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp index b72bfbdd..794aface 100644 --- a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp +++ b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp @@ -1,8 +1,9 @@ +#include "BATTERIES.h" #ifdef RENAULT_KANGOO_BATTERY -#include "RENAULT-KANGOO-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#include "RENAULT-KANGOO-BATTERY.h" /* Do not change code below unless you are sure what you are doing */ #define LB_MAX_SOC 1000 //BMS never goes over this value. We use this info to rescale SOC% sent to Fronius diff --git a/Software/src/battery/RENAULT-ZOE-BATTERY.cpp b/Software/src/battery/RENAULT-ZOE-BATTERY.cpp index 8cb010ba..977cdb91 100644 --- a/Software/src/battery/RENAULT-ZOE-BATTERY.cpp +++ b/Software/src/battery/RENAULT-ZOE-BATTERY.cpp @@ -1,8 +1,9 @@ +#include "BATTERIES.h" #ifdef RENAULT_ZOE_BATTERY -#include "RENAULT-ZOE-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#include "RENAULT-ZOE-BATTERY.h" /* Do not change code below unless you are sure what you are doing */ #define LB_MAX_SOC 1000 //BMS never goes over this value. We use this info to rescale SOC% sent to Fronius diff --git a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp index c8ca2ee7..8334a053 100644 --- a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp +++ b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp @@ -1,8 +1,9 @@ +#include "BATTERIES.h" #ifdef SANTA_FE_PHEV_BATTERY -#include "SANTA-FE-PHEV-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#include "SANTA-FE-PHEV-BATTERY.h" /* Credits go to maciek16c for these findings! https://github.com/maciek16c/hyundai-santa-fe-phev-battery diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp index 942fdb9a..ea583602 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp @@ -1,8 +1,9 @@ +#include "BATTERIES.h" #ifdef TESLA_MODEL_3_BATTERY -#include "TESLA-MODEL-3-BATTERY.h" #include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#include "TESLA-MODEL-3-BATTERY.h" /* Do not change code below unless you are sure what you are doing */ /* Credits: Most of the code comes from Per Carlen's bms_comms_tesla_model3.py (https://gitlab.com/pelle8/batt2gen24/) */ diff --git a/Software/src/battery/TEST-FAKE-BATTERY.cpp b/Software/src/battery/TEST-FAKE-BATTERY.cpp index 18300a95..c1fb00ae 100644 --- a/Software/src/battery/TEST-FAKE-BATTERY.cpp +++ b/Software/src/battery/TEST-FAKE-BATTERY.cpp @@ -1,7 +1,8 @@ +#include "BATTERIES.h" #ifdef TEST_FAKE_BATTERY -#include "TEST-FAKE-BATTERY.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" +#include "TEST-FAKE-BATTERY.h" /* Do not change code below unless you are sure what you are doing */ static unsigned long previousMillis10 = 0; // will store last time a 10ms CAN Message was send From 77345ec41f4b01f94fcc77f4c38281a68e7ffdcd Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 17 Feb 2024 10:45:23 +0200 Subject: [PATCH 10/15] Add cellamount LFP autodetect --- Software/src/battery/TESLA-MODEL-3-BATTERY.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp index ea583602..e1a446f9 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp @@ -244,7 +244,7 @@ void update_values_battery() { //This function maps all the values fetched via cell_deviation_mV = (cell_max_v - cell_min_v); - //Determine which chemistry battery pack is using (crude method, TODO: replace with real CAN data later) + //Determine which chemistry battery pack is using (crude method, TODO: replace with real CAN identifier later) if (soc_vi > 900) { //When SOC% is over 90.0%, we can use max cell voltage to estimate what chemistry is used if (cell_max_v < 3450) { LFP_Chemistry = true; @@ -253,6 +253,10 @@ void update_values_battery() { //This function maps all the values fetched via LFP_Chemistry = false; } } + // An even better way is to check how many cells are in the pack. NCM/A batteries have 96s, LFP has 102-106s + if (nof_cellvoltages > 101) { + LFP_Chemistry = true; + } //Check if SOC% is plausible if (battery_voltage > From 4841464400846b57ded9657719b25c1d57af5732 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 17 Feb 2024 12:51:47 +0200 Subject: [PATCH 11/15] Make min/maxvoltage variable --- Software/Software.ino | 16 +++----- Software/src/battery/BATTERIES.h | 3 +- Software/src/battery/BMW-I3-BATTERY.cpp | 5 ++- Software/src/battery/BMW-I3-BATTERY.h | 6 +-- Software/src/battery/CHADEMO-BATTERY.cpp | 6 ++- Software/src/battery/CHADEMO-BATTERY.h | 6 +-- .../src/battery/IMIEV-CZERO-ION-BATTERY.cpp | 5 ++- .../src/battery/IMIEV-CZERO-ION-BATTERY.h | 41 ++++++++++--------- .../src/battery/KIA-HYUNDAI-64-BATTERY.cpp | 5 ++- Software/src/battery/KIA-HYUNDAI-64-BATTERY.h | 8 ++-- Software/src/battery/NISSAN-LEAF-BATTERY.cpp | 10 ++--- Software/src/battery/NISSAN-LEAF-BATTERY.h | 9 ++-- .../src/battery/RENAULT-KANGOO-BATTERY.cpp | 5 ++- Software/src/battery/RENAULT-KANGOO-BATTERY.h | 8 ++-- Software/src/battery/RENAULT-ZOE-BATTERY.cpp | 5 ++- Software/src/battery/RENAULT-ZOE-BATTERY.h | 9 ++-- .../src/battery/SANTA-FE-PHEV-BATTERY.cpp | 5 ++- Software/src/battery/SANTA-FE-PHEV-BATTERY.h | 41 ++++++++++--------- .../SERIAL-LINK-RECEIVER-FROM-BATTERY.h | 6 +-- .../src/battery/TESLA-MODEL-3-BATTERY.cpp | 6 ++- Software/src/battery/TESLA-MODEL-3-BATTERY.h | 8 ++-- Software/src/battery/TEST-FAKE-BATTERY.cpp | 5 ++- Software/src/battery/TEST-FAKE-BATTERY.h | 8 ++-- 23 files changed, 121 insertions(+), 105 deletions(-) diff --git a/Software/Software.ino b/Software/Software.ino index 7e08e6bc..0cbbf5c8 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -54,9 +54,9 @@ ModbusServerRTU MBserver(Serial2, 2000); #endif // Common inverter parameters. Batteries map their values to these variables -uint16_t max_voltage = ABSOLUTE_MAX_VOLTAGE; // If higher charging is not possible (goes into forced discharge) -uint16_t min_voltage = ABSOLUTE_MIN_VOLTAGE; // If lower disables discharging battery -uint16_t battery_voltage = 3700; //V+1, 0-500.0 (0-5000) +uint16_t max_voltage = 5000; //V+1, 0-500.0 (0-5000) +uint16_t min_voltage = 2500; //V+1, 0-500.0 (0-5000) +uint16_t battery_voltage = 3700; //V+1, 0-500.0 (0-5000) uint16_t battery_current = 0; uint16_t SOC = 5000; //SOC%, 0-100.00 (0-10000) uint16_t StateOfHealth = 9900; //SOH%, 0-100.00 (0-10000) @@ -145,11 +145,7 @@ void setup() { inform_user_on_inverter(); - inform_user_on_battery(); - -#ifdef BATTERY_HAS_INIT init_battery(); -#endif // BOOT button at runtime is used as an input for various things pinMode(0, INPUT_PULLUP); @@ -358,9 +354,9 @@ void inform_user_on_inverter() { #endif } -void inform_user_on_battery() { - // Inform user what battery is used - announce_battery(); +void init_battery() { + // Inform user what battery is used and perform setup + setup_battery(); #ifdef SERIAL_LINK_RECEIVER Serial.println("SERIAL_DATA_LINK_RECEIVER selected"); #endif diff --git a/Software/src/battery/BATTERIES.h b/Software/src/battery/BATTERIES.h index e80ea3c4..f6efe68e 100644 --- a/Software/src/battery/BATTERIES.h +++ b/Software/src/battery/BATTERIES.h @@ -21,7 +21,6 @@ #ifdef NISSAN_LEAF_BATTERY #include "NISSAN-LEAF-BATTERY.h" //See this file for more LEAF battery settings -#define BATTERY_HAS_INIT #endif #ifdef RENAULT_KANGOO_BATTERY @@ -52,7 +51,7 @@ void update_values_battery(); void receive_can_battery(CAN_frame_t rx_frame); void send_can_battery(); -void announce_battery(void); +void setup_battery(void); #endif #endif diff --git a/Software/src/battery/BMW-I3-BATTERY.cpp b/Software/src/battery/BMW-I3-BATTERY.cpp index ee42cae4..11c6794f 100644 --- a/Software/src/battery/BMW-I3-BATTERY.cpp +++ b/Software/src/battery/BMW-I3-BATTERY.cpp @@ -193,8 +193,11 @@ void send_can_battery() { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("BMW i3 battery selected"); + + max_voltage = 4040; // 404.4V, over this, charging is not possible (goes into forced discharge) + min_voltage = 3100; // 310.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/BMW-I3-BATTERY.h b/Software/src/battery/BMW-I3-BATTERY.h index 4e3697d7..22525e11 100644 --- a/Software/src/battery/BMW-I3-BATTERY.h +++ b/Software/src/battery/BMW-I3-BATTERY.h @@ -7,10 +7,6 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled - // These parameters need to be mapped for the inverter extern uint16_t SOC; extern uint16_t StateOfHealth; @@ -28,4 +24,6 @@ extern uint16_t CANerror; extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false +void setup_battery(void); + #endif diff --git a/Software/src/battery/CHADEMO-BATTERY.cpp b/Software/src/battery/CHADEMO-BATTERY.cpp index 628746f1..846c08bc 100644 --- a/Software/src/battery/CHADEMO-BATTERY.cpp +++ b/Software/src/battery/CHADEMO-BATTERY.cpp @@ -221,8 +221,10 @@ void send_can_battery() { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Chademo battery selected"); -} + max_voltage = 4040; // 404.4V, over this, charging is not possible (goes into forced discharge) + min_voltage = 2000; // 200.0V under this, discharging further is disabled +} #endif diff --git a/Software/src/battery/CHADEMO-BATTERY.h b/Software/src/battery/CHADEMO-BATTERY.h index 1bce665b..abadbfb7 100644 --- a/Software/src/battery/CHADEMO-BATTERY.h +++ b/Software/src/battery/CHADEMO-BATTERY.h @@ -7,10 +7,6 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled - // These parameters need to be mapped extern uint16_t SOC; extern uint16_t StateOfHealth; @@ -29,4 +25,6 @@ extern uint16_t CANerror; extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false +void setup_battery(void); + #endif diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp index 4ccaf57e..7530c37e 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp @@ -227,8 +227,11 @@ void send_can_battery() { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Mitsubishi i-MiEV / Citroen C-Zero / Peugeot Ion battery selected"); + + max_voltage = 4040; // 404.4V, over this, charging is not possible (goes into forced discharge) + min_voltage = 3100; // 310.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h index 1d125a08..dd690a1c 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h @@ -7,27 +7,28 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled - -// These parameters need to be mapped for the Gen24 -extern uint16_t SOC; -extern uint16_t StateOfHealth; -extern uint16_t battery_voltage; -extern uint16_t battery_current; -extern uint16_t capacity_Wh; -extern uint16_t remaining_capacity_Wh; -extern uint16_t max_target_discharge_power; -extern uint16_t max_target_charge_power; -extern uint8_t bms_char_dis_status; -extern uint16_t stat_batt_power; -extern uint16_t temperature_min; -extern uint16_t temperature_max; -extern uint16_t CANerror; -extern uint16_t cell_max_voltage; -extern uint16_t cell_min_voltage; +// These parameters need to be mapped for the Inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) +extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) +extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485) +extern uint16_t capacity_Wh; //Wh, 0-60000 +extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 +extern uint16_t max_target_discharge_power; //W, 0-60000 +extern uint16_t max_target_charge_power; //W, 0-60000 +extern uint8_t bms_char_dis_status; //Enum, 0-2 +extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) +extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +extern uint16_t cell_max_voltage; //mV, 0-4350 +extern uint16_t cell_min_voltage; //mV, 0-4350 +extern uint16_t cellvoltages[120]; //mV 0-4350 per cell +extern uint8_t nof_cellvoltages; // Total number of cell voltages, set by each battery. extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false +void setup_battery(void); + #endif diff --git a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp index aa6d2f3d..4cb3a4cb 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp +++ b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp @@ -599,8 +599,11 @@ uint16_t convertToUnsignedInt16(int16_t signed_value) { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Kia Niro / Hyundai Kona 64kWh battery selected"); + + max_voltage = 4040; // 404.0V, over this, charging is not possible (goes into forced discharge) + min_voltage = 3100; // 310.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h index 36e63b4c..c9901608 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h +++ b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h @@ -7,13 +7,12 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled #define MAXCHARGEPOWERALLOWED 10000 #define MAXDISCHARGEPOWERALLOWED 10000 -// These parameters need to be mapped for the Gen24 +// These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) @@ -34,5 +33,6 @@ extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false uint16_t convertToUnsignedInt16(int16_t signed_value); +void setup_battery(void); #endif diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp index 29f19f39..422bba28 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp @@ -922,12 +922,12 @@ uint16_t Temp_fromRAW_to_F(uint16_t temperature) { //This function feels horrib return static_cast(1094 + (309 - temperature) * 2.5714285714285715); } -void init_battery(void) { - nof_cellvoltages = 96; -} - -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Nissan LEAF battery selected"); + + nof_cellvoltages = 96; + max_voltage = 4040; // 404.4V, over this, charging is not possible (goes into forced discharge) + min_voltage = 2450; // 245.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.h b/Software/src/battery/NISSAN-LEAF-BATTERY.h index 12b183aa..7c4b1b83 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.h +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.h @@ -7,11 +7,9 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled - // These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) @@ -33,7 +31,6 @@ extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false uint16_t convert2unsignedint16(int16_t signed_value); uint16_t Temp_fromRAW_to_F(uint16_t temperature); bool is_message_corrupt(CAN_frame_t rx_frame); - -void init_battery(void); +void setup_battery(void); #endif diff --git a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp index 794aface..eee07cb8 100644 --- a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp +++ b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp @@ -270,8 +270,11 @@ uint16_t convert2uint16(int16_t signed_value) { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Renault Kangoo battery selected"); + + max_voltage = 4040; // 404.0V, over this, charging is not possible (goes into forced discharge) + min_voltage = 3100; // 310.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/RENAULT-KANGOO-BATTERY.h b/Software/src/battery/RENAULT-KANGOO-BATTERY.h index bfa8c9d6..2d6c5c35 100644 --- a/Software/src/battery/RENAULT-KANGOO-BATTERY.h +++ b/Software/src/battery/RENAULT-KANGOO-BATTERY.h @@ -7,16 +7,15 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled #define ABSOLUTE_CELL_MAX_VOLTAGE \ 4100 // Max Cell Voltage mV! if voltage goes over this, charging is not possible (goes into forced discharge) #define ABSOLUTE_CELL_MIN_VOLTAGE \ 3000 // Min Cell Voltage mV! if voltage goes under this, discharging further is disabled #define MAX_CELL_DEVIATION_MV 500 //LED turns yellow on the board if mv delta exceeds this value -// These parameters need to be mapped for the Gen24 +// These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) @@ -36,5 +35,6 @@ extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false uint16_t convert2uint16(int16_t signed_value); +void setup_battery(void); #endif diff --git a/Software/src/battery/RENAULT-ZOE-BATTERY.cpp b/Software/src/battery/RENAULT-ZOE-BATTERY.cpp index 977cdb91..1c718077 100644 --- a/Software/src/battery/RENAULT-ZOE-BATTERY.cpp +++ b/Software/src/battery/RENAULT-ZOE-BATTERY.cpp @@ -166,8 +166,11 @@ void send_can_battery() { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Renault Zoe battery selected"); + + max_voltage = 4040; // 404.0V, over this, charging is not possible (goes into forced discharge) + min_voltage = 3100; // 310.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/RENAULT-ZOE-BATTERY.h b/Software/src/battery/RENAULT-ZOE-BATTERY.h index 7fbf5beb..a376f5ad 100644 --- a/Software/src/battery/RENAULT-ZOE-BATTERY.h +++ b/Software/src/battery/RENAULT-ZOE-BATTERY.h @@ -7,16 +7,15 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled #define ABSOLUTE_CELL_MAX_VOLTAGE \ 4100 // Max Cell Voltage mV! if voltage goes over this, charging is not possible (goes into forced discharge) #define ABSOLUTE_CELL_MIN_VOLTAGE \ 3000 // Min Cell Voltage mV! if voltage goes under this, discharging further is disabled #define MAX_CELL_DEVIATION_MV 500 //LED turns yellow on the board if mv delta exceeds this value -// These parameters need to be mapped for the Gen24 +// These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) @@ -35,4 +34,6 @@ extern uint16_t CANerror; extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false +void setup_battery(void); + #endif diff --git a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp index 8334a053..f6717089 100644 --- a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp +++ b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp @@ -177,8 +177,11 @@ uint8_t CalculateCRC8(CAN_frame_t rx_frame) { return (uint8_t)crc; } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Hyundai Santa Fe PHEV battery selected"); + + max_voltage = 4040; // 404.0V, over this, charging is not possible (goes into forced discharge) + min_voltage = 3100; // 310.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/SANTA-FE-PHEV-BATTERY.h b/Software/src/battery/SANTA-FE-PHEV-BATTERY.h index c96b0673..448a7a85 100644 --- a/Software/src/battery/SANTA-FE-PHEV-BATTERY.h +++ b/Software/src/battery/SANTA-FE-PHEV-BATTERY.h @@ -7,27 +7,28 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4030 // 403.0V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled - -// These parameters need to be mapped for the Gen24 -extern uint16_t SOC; -extern uint16_t StateOfHealth; -extern uint16_t battery_voltage; -extern uint16_t battery_current; -extern uint16_t capacity_Wh; -extern uint16_t remaining_capacity_Wh; -extern uint16_t max_target_discharge_power; -extern uint16_t max_target_charge_power; -extern uint8_t bms_char_dis_status; -extern uint16_t stat_batt_power; -extern uint16_t temperature_min; -extern uint16_t temperature_max; -extern uint16_t CANerror; -extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false -extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false +// These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) +extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) +extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485) +extern uint16_t capacity_Wh; //Wh, 0-60000 +extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 +extern uint16_t max_target_discharge_power; //W, 0-60000 +extern uint16_t max_target_charge_power; //W, 0-60000 +extern uint8_t bms_char_dis_status; //Enum, 0-2 +extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) +extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +extern uint16_t cell_max_voltage; //mV, 0-4350 +extern uint16_t cell_min_voltage; //mV, 0-4350 +extern uint16_t cellvoltages[120]; //mV 0-4350 per cell +extern uint8_t nof_cellvoltages; // Total number of cell voltages, set by each battery. +extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false uint8_t CalculateCRC8(CAN_frame_t rx_frame); +void setup_battery(void); #endif diff --git a/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.h b/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.h index 089276a5..752d0118 100644 --- a/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.h +++ b/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.h @@ -10,11 +10,9 @@ // https://github.com/mackelec/SerialDataLink -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled - // These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp index ea583602..7d3045d0 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp @@ -337,6 +337,7 @@ void update_values_battery() { //This function maps all the values fetched via if (LFP_Chemistry) { Serial.print("LFP chemistry detected!"); } + Serial.print(nof_cellvoltages); Serial.println(""); Serial.print("Cellstats, Max: "); Serial.print(cell_max_v); @@ -686,8 +687,11 @@ void printDebugIfActive(uint8_t symbol, const char* message) { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Tesla Model 3 battery selected"); + + max_voltage = 4030; // 403.0V, over this, charging is not possible (goes into forced discharge) + min_voltage = 3100; // 310.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.h b/Software/src/battery/TESLA-MODEL-3-BATTERY.h index 5d4904d0..901cc468 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.h +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.h @@ -7,14 +7,13 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4030 // 403.0V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 2450 // 245.0V if battery voltage goes under this, discharging further is disabled #define MAXCHARGEPOWERALLOWED 15000 // 15000W we use a define since the value supplied by Tesla is always 0 #define MAXDISCHARGEPOWERALLOWED \ 60000 // 60000W we need to cap this value to max 60kW, most inverters overflow otherwise -// These parameters need to be mapped for the Inverter +// These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) @@ -40,5 +39,6 @@ void printDebugIfActive(uint8_t symbol, const char* message); void print_int_with_units(char* header, int value, char* units); void print_SOC(char* header, int SOC); uint16_t convert2unsignedInt16(int16_t signed_value); +void setup_battery(void); #endif diff --git a/Software/src/battery/TEST-FAKE-BATTERY.cpp b/Software/src/battery/TEST-FAKE-BATTERY.cpp index c1fb00ae..045521f5 100644 --- a/Software/src/battery/TEST-FAKE-BATTERY.cpp +++ b/Software/src/battery/TEST-FAKE-BATTERY.cpp @@ -82,8 +82,11 @@ void send_can_battery() { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Test mode with fake battery selected"); + + max_voltage = 4040; // 404.4V, over this, charging is not possible (goes into forced discharge) + min_voltage = 2450; // 245.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/TEST-FAKE-BATTERY.h b/Software/src/battery/TEST-FAKE-BATTERY.h index 877b2736..75d70513 100644 --- a/Software/src/battery/TEST-FAKE-BATTERY.h +++ b/Software/src/battery/TEST-FAKE-BATTERY.h @@ -7,11 +7,9 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled - // These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) @@ -31,4 +29,6 @@ extern uint16_t cellvoltages[120]; //mV 0-5000 per cell extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false +void setup_battery(void); + #endif From f35db250f48cb65c5b96b2d1c025e41f75140f21 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 17 Feb 2024 13:01:53 +0200 Subject: [PATCH 12/15] Fix compile error --- Software/src/battery/BMW-I3-BATTERY.h | 34 ++++++++++++----------- Software/src/battery/CHADEMO-BATTERY.h | 37 ++++++++++++++------------ 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/Software/src/battery/BMW-I3-BATTERY.h b/Software/src/battery/BMW-I3-BATTERY.h index 22525e11..c12a1402 100644 --- a/Software/src/battery/BMW-I3-BATTERY.h +++ b/Software/src/battery/BMW-I3-BATTERY.h @@ -8,21 +8,25 @@ #define BATTERY_SELECTED // These parameters need to be mapped for the inverter -extern uint16_t SOC; -extern uint16_t StateOfHealth; -extern uint16_t battery_voltage; -extern uint16_t battery_current; -extern uint16_t capacity_Wh; -extern uint16_t remaining_capacity_Wh; -extern uint16_t max_target_discharge_power; -extern uint16_t max_target_charge_power; -extern uint8_t bms_char_dis_status; -extern uint16_t stat_batt_power; -extern uint16_t temperature_min; -extern uint16_t temperature_max; -extern uint16_t CANerror; -extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false -extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) +extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) +extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485) +extern uint16_t capacity_Wh; //Wh, 0-60000 +extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 +extern uint16_t max_target_discharge_power; //W, 0-60000 +extern uint16_t max_target_charge_power; //W, 0-60000 +extern uint8_t bms_char_dis_status; //Enum, 0-2 +extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) +extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +extern uint16_t cell_max_voltage; //mV, 0-4350 +extern uint16_t cell_min_voltage; //mV, 0-4350 +extern uint16_t cellvoltages[120]; //mV 0-4350 per cell +extern uint8_t nof_cellvoltages; // Total number of cell voltages, set by each battery. +extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false void setup_battery(void); diff --git a/Software/src/battery/CHADEMO-BATTERY.h b/Software/src/battery/CHADEMO-BATTERY.h index abadbfb7..bd49c943 100644 --- a/Software/src/battery/CHADEMO-BATTERY.h +++ b/Software/src/battery/CHADEMO-BATTERY.h @@ -7,23 +7,26 @@ #define BATTERY_SELECTED -// These parameters need to be mapped -extern uint16_t SOC; -extern uint16_t StateOfHealth; -extern uint16_t battery_voltage; -extern uint16_t battery_current; -extern uint16_t capacity_Wh; -extern uint16_t remaining_capacity_Wh; -extern uint16_t max_target_discharge_power; -extern uint16_t max_target_charge_power; -extern uint8_t bms_status; -extern uint8_t bms_char_dis_status; -extern uint16_t stat_batt_power; -extern uint16_t temperature_min; -extern uint16_t temperature_max; -extern uint16_t CANerror; -extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false -extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false +// These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) +extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) +extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485) +extern uint16_t capacity_Wh; //Wh, 0-60000 +extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 +extern uint16_t max_target_discharge_power; //W, 0-60000 +extern uint16_t max_target_charge_power; //W, 0-60000 +extern uint8_t bms_char_dis_status; //Enum, 0-2 +extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) +extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +extern uint16_t cell_max_voltage; //mV, 0-4350 +extern uint16_t cell_min_voltage; //mV, 0-4350 +extern uint16_t cellvoltages[120]; //mV 0-4350 per cell +extern uint8_t nof_cellvoltages; // Total number of cell voltages, set by each battery. +extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false void setup_battery(void); From 8b0b57ea706ac6211de201b3a50b9851d6106f8b Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 17 Feb 2024 13:09:12 +0200 Subject: [PATCH 13/15] Tesla: Make min/max values chemistry dependent --- Software/src/battery/NISSAN-LEAF-BATTERY.cpp | 3 +-- Software/src/battery/TESLA-MODEL-3-BATTERY.cpp | 14 +++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp index 422bba28..a476b5b3 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp @@ -257,8 +257,7 @@ void update_values_battery() { /* This function maps all the values fetched via } //Check if SOC% is plausible - if (battery_voltage > - (ABSOLUTE_MAX_VOLTAGE - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT + if (battery_voltage > (max_voltage - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT if (LB_SOC < 650) { set_event(EVENT_SOC_PLAUSIBILITY_ERROR, LB_SOC / 10); // Set event with the SOC as data } else { diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp index 7d3045d0..3676a833 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp @@ -254,10 +254,18 @@ void update_values_battery() { //This function maps all the values fetched via } } + //Once cell chemistry is determined, set maximum and minimum total pack voltage safety limits + if (LFP_Chemistry) { + max_voltage = 3640; + min_voltage = 2450; + } else { // NCM/A chemistry + max_voltage = 4030; + min_voltage = 3100; + } + //Check if SOC% is plausible - if (battery_voltage > - (ABSOLUTE_MAX_VOLTAGE - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT - if (SOC < 6500) { //When SOC is less than 65.00% when approaching max voltage + if (battery_voltage > (max_voltage - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT + if (SOC < 6500) { //When SOC is less than 65.00% when approaching max voltage set_event(EVENT_SOC_PLAUSIBILITY_ERROR, SOC / 100); } } From 80b660c4c18add3409d652307475857ebcd6b506 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 17 Feb 2024 13:15:00 +0200 Subject: [PATCH 14/15] Fix compile error --- Software/src/battery/TESLA-MODEL-3-BATTERY.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp index 3676a833..3e742a36 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp @@ -53,8 +53,8 @@ static uint16_t hvac_max_power = 0; static uint16_t min_voltage = 0; static uint16_t max_discharge_current = 0; static uint16_t max_charge_current = 0; -static uint16_t max_voltage = 0; -static uint16_t high_voltage = 0; +static uint16_t bms_max_voltage = 0; +static uint16_t bms_high_voltage = 0; static uint16_t low_voltage = 0; static uint16_t output_current = 0; static uint16_t soc_min = 0; @@ -492,8 +492,10 @@ void receive_can_battery(CAN_frame_t rx_frame) { break; case 0x2d2: //Min / max limits - min_voltage = ((rx_frame.data.u8[1] << 8) | rx_frame.data.u8[0]) * 0.01 * 2; //Example 24148mv * 0.01 = 241.48 V - max_voltage = ((rx_frame.data.u8[3] << 8) | rx_frame.data.u8[2]) * 0.01 * 2; //Example 40282mv * 0.01 = 402.82 V + bms_min_voltage = + ((rx_frame.data.u8[1] << 8) | rx_frame.data.u8[0]) * 0.01 * 2; //Example 24148mv * 0.01 = 241.48 V + bms_max_voltage = + ((rx_frame.data.u8[3] << 8) | rx_frame.data.u8[2]) * 0.01 * 2; //Example 40282mv * 0.01 = 402.82 V max_charge_current = (((rx_frame.data.u8[5] & 0x3F) << 8) | rx_frame.data.u8[4]) * 0.1; //Example 1301? * 0.1 = 130.1? max_discharge_current = From f799ab45b4eedfba9b855a75e793e88a08779829 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 17 Feb 2024 13:20:18 +0200 Subject: [PATCH 15/15] Variable redefine --- Software/src/battery/TESLA-MODEL-3-BATTERY.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp index 3e742a36..9e692596 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp @@ -50,11 +50,11 @@ static uint16_t regenerative_limit = 0; static uint16_t discharge_limit = 0; static uint16_t max_heat_park = 0; static uint16_t hvac_max_power = 0; -static uint16_t min_voltage = 0; static uint16_t max_discharge_current = 0; static uint16_t max_charge_current = 0; static uint16_t bms_max_voltage = 0; -static uint16_t bms_high_voltage = 0; +static uint16_t bms_min_voltage = 0; +static uint16_t high_voltage = 0; static uint16_t low_voltage = 0; static uint16_t output_current = 0; static uint16_t soc_min = 0;