mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 10:49:42 +02:00
Make all components use new transmit function
This commit is contained in:
parent
d8b91eb34e
commit
635f450e53
53 changed files with 409 additions and 477 deletions
|
@ -201,13 +201,13 @@ void core_loop(void* task_time_us) {
|
|||
while (true) {
|
||||
START_TIME_MEASUREMENT(all);
|
||||
START_TIME_MEASUREMENT(comm);
|
||||
// Input
|
||||
receive_can(); // Receive CAN messages. Runs as fast as possible
|
||||
// Input, Runs as fast as possible
|
||||
receive_can_native(); // Receive CAN messages from native CAN port
|
||||
#ifdef CAN_FD
|
||||
receive_canfd(); // Receive CAN-FD messages. Runs as fast as possible
|
||||
receive_canfd(); // Receive CAN-FD messages.
|
||||
#endif
|
||||
#ifdef DUAL_CAN
|
||||
receive_can2(); // Receive CAN messages on CAN2. Runs as fast as possible
|
||||
receive_can_addonMCP2515(); // Receive CAN messages on add-on MCP2515 chip
|
||||
#endif
|
||||
#if defined(SERIAL_LINK_RECEIVER) || defined(SERIAL_LINK_TRANSMITTER)
|
||||
runSerialDataLink();
|
||||
|
@ -254,10 +254,8 @@ void core_loop(void* task_time_us) {
|
|||
|
||||
START_TIME_MEASUREMENT(cantx);
|
||||
// Output
|
||||
send_can(); // Send CAN messages
|
||||
#ifdef DUAL_CAN
|
||||
send_can2();
|
||||
#endif
|
||||
send_can(); // Send CAN messages to all components
|
||||
|
||||
END_TIME_MEASUREMENT_MAX(cantx, datalayer.system.status.time_cantx_us);
|
||||
END_TIME_MEASUREMENT_MAX(all, datalayer.system.status.core_task_10s_max_us);
|
||||
#ifdef FUNCTION_TIME_MEASUREMENT
|
||||
|
@ -531,72 +529,84 @@ void receive_canfd() { // This section checks if we have a complete CAN-FD mess
|
|||
}
|
||||
#endif
|
||||
|
||||
void receive_can() { // This section checks if we have a complete CAN message incoming
|
||||
// Depending on which battery/inverter is selected, we forward this to their respective CAN routines
|
||||
void receive_can_native() { // This section checks if we have a complete CAN message incoming on native CAN port
|
||||
// Depending on which battery/inverter is selected, we forward this to their respective CAN handlers
|
||||
CAN_frame_t rx_frame;
|
||||
if (xQueueReceive(CAN_cfg.rx_queue, &rx_frame, 0) == pdTRUE) {
|
||||
|
||||
// Battery
|
||||
#ifndef SERIAL_LINK_RECEIVER // Only needs to see inverter
|
||||
if (can_config.battery == CAN_NATIVE) {
|
||||
receive_can_battery(rx_frame);
|
||||
#endif
|
||||
// Inverter
|
||||
}
|
||||
if (can_config.inverter == CAN_NATIVE) {
|
||||
#ifdef CAN_INVERTER_SELECTED
|
||||
receive_can_inverter(rx_frame);
|
||||
#endif
|
||||
// Charger
|
||||
#endif // CAN_INVERTER_SELECTED
|
||||
}
|
||||
if (can_config.battery_double == CAN_NATIVE) {
|
||||
#ifdef DOUBLE_BATTERY
|
||||
receive_can_battery2(rx_frame);
|
||||
#endif // DOUBLE_BATTERY
|
||||
}
|
||||
if (can_config.charger == CAN_NATIVE) {
|
||||
#ifdef CHARGER_SELECTED
|
||||
receive_can_charger(rx_frame);
|
||||
#endif
|
||||
#endif // CHARGER_SELECTED
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void send_can() {
|
||||
// Battery
|
||||
|
||||
send_can_battery();
|
||||
// Inverter
|
||||
|
||||
#ifdef CAN_INVERTER_SELECTED
|
||||
send_can_inverter();
|
||||
#endif
|
||||
// Charger
|
||||
#endif // CAN_INVERTER_SELECTED
|
||||
|
||||
#ifdef CHARGER_SELECTED
|
||||
send_can_charger();
|
||||
#endif
|
||||
#endif // CHARGER_SELECTED
|
||||
}
|
||||
|
||||
#ifdef DUAL_CAN
|
||||
void receive_can2() { // This function is similar to receive_can, but just takes care of inverters in the 2nd bus OR double battery
|
||||
// Depending on which inverter is selected, we forward this to their respective CAN routines
|
||||
CAN_frame_t rx_frame_can2; // Struct with ESP32Can library format, compatible with the rest of the program
|
||||
void receive_can_addonMCP2515() { // This section checks if we have a complete CAN message incoming on native CAN port
|
||||
// Depending on which battery/inverter is selected, we forward this to their respective CAN handlers
|
||||
CAN_frame_t
|
||||
rx_frame_can_addonMCP2515; // Struct with ESP32Can library format, compatible with the rest of the program
|
||||
CANMessage MCP2515Frame; // Struct with ACAN2515 library format, needed to use thw MCP2515 library
|
||||
|
||||
if (can.available()) {
|
||||
can.receive(MCP2515Frame);
|
||||
|
||||
rx_frame_can2.MsgID = MCP2515Frame.id;
|
||||
rx_frame_can2.FIR.B.FF = MCP2515Frame.ext ? CAN_frame_ext : CAN_frame_std;
|
||||
rx_frame_can2.FIR.B.RTR = MCP2515Frame.rtr ? CAN_RTR : CAN_no_RTR;
|
||||
rx_frame_can2.FIR.B.DLC = MCP2515Frame.len;
|
||||
rx_frame_can_addonMCP2515.MsgID = MCP2515Frame.id;
|
||||
rx_frame_can_addonMCP2515.FIR.B.FF = MCP2515Frame.ext ? CAN_frame_ext : CAN_frame_std;
|
||||
rx_frame_can_addonMCP2515.FIR.B.RTR = MCP2515Frame.rtr ? CAN_RTR : CAN_no_RTR;
|
||||
rx_frame_can_addonMCP2515.FIR.B.DLC = MCP2515Frame.len;
|
||||
for (uint8_t i = 0; i < MCP2515Frame.len; i++) {
|
||||
rx_frame_can2.data.u8[i] = MCP2515Frame.data[i];
|
||||
rx_frame_can_addonMCP2515.data.u8[i] = MCP2515Frame.data[i];
|
||||
}
|
||||
|
||||
if (can_config.battery == CAN_ADDON_MCP2515) {
|
||||
receive_can_battery(rx_frame_can_addonMCP2515);
|
||||
}
|
||||
if (can_config.inverter == CAN_ADDON_MCP2515) {
|
||||
#ifdef CAN_INVERTER_SELECTED
|
||||
receive_can_inverter(rx_frame_can2);
|
||||
#endif
|
||||
receive_can_inverter(rx_frame_can_addonMCP2515);
|
||||
#endif // CAN_INVERTER_SELECTED
|
||||
}
|
||||
if (can_config.battery_double == CAN_ADDON_MCP2515) {
|
||||
#ifdef DOUBLE_BATTERY
|
||||
receive_can_battery2(rx_frame_can2);
|
||||
receive_can_battery2(rx_frame_can_addonMCP2515);
|
||||
#endif // DOUBLE_BATTERY
|
||||
}
|
||||
if (can_config.charger == CAN_ADDON_MCP2515) {
|
||||
#ifdef CHARGER_SELECTED
|
||||
receive_can_charger(rx_frame_can_addonMCP2515);
|
||||
#endif // CHARGER_SELECTED
|
||||
}
|
||||
|
||||
void send_can2() {
|
||||
// Inverter
|
||||
#ifdef CAN_INVERTER_SELECTED
|
||||
send_can_inverter(); //Note this will only send to CAN1, unless we use SOLAX
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif // DUAL_CAN
|
||||
|
||||
#ifdef DOUBLE_BATTERY
|
||||
void check_interconnect_available() {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
//#define KIA_E_GMP_BATTERY
|
||||
//#define KIA_HYUNDAI_HYBRID_BATTERY
|
||||
//#define MG_5_BATTERY
|
||||
#define NISSAN_LEAF_BATTERY
|
||||
//#define NISSAN_LEAF_BATTERY
|
||||
//#define PYLON_BATTERY
|
||||
//#define RENAULT_KANGOO_BATTERY
|
||||
//#define RENAULT_ZOE_GEN1_BATTERY
|
||||
|
@ -30,7 +30,7 @@
|
|||
|
||||
/* 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
|
||||
|
@ -48,7 +48,7 @@
|
|||
//#define INTERLOCK_REQUIRED //Nissan LEAF specific setting, if enabled requires both high voltage conenctors to be seated before starting
|
||||
//#define CONTACTOR_CONTROL //Enable this line to have pins 25,32,33 handle automatic precharge/contactor+/contactor- closing sequence
|
||||
//#define PWM_CONTACTOR_CONTROL //Enable this line to use PWM logic for contactors, which lower power consumption and heat generation
|
||||
#define DUAL_CAN //Enable this line to activate an isolated secondary CAN Bus using add-on MCP2515 controller (Needed for some inverters / double battery)
|
||||
//#define DUAL_CAN //Enable this line to activate an isolated secondary CAN Bus using add-on MCP2515 controller (Needed for some inverters / double battery)
|
||||
//#define CAN_FD //Enable this line to activate an isolated secondary CAN-FD bus using add-on MCP2517FD controller (Needed for some batteries)
|
||||
//#define SERIAL_LINK_RECEIVER //Enable this line to receive battery data over RS485 pins from another Lilygo (This LilyGo interfaces with inverter)
|
||||
//#define SERIAL_LINK_TRANSMITTER //Enable this line to send battery data over RS485 pins to another Lilygo (This LilyGo interfaces with battery)
|
||||
|
@ -65,7 +65,7 @@
|
|||
#define DUMMY_EVENT_ENABLED false //Enable this line to have a dummy event that gets logged to test the interface
|
||||
|
||||
/* Select charger used (Optional) */
|
||||
//#define CHEVYVOLT_CHARGER //Enable this line to control a Chevrolet Volt charger connected to battery - for example, when generator charging or using an inverter without a charging function.
|
||||
#define CHEVYVOLT_CHARGER //Enable this line to control a Chevrolet Volt charger connected to battery - for example, when generator charging or using an inverter without a charging function.
|
||||
//#define NISSANLEAF_CHARGER //Enable this line to control a Nissan LEAF PDM connected to battery - for example, when generator charging
|
||||
|
||||
/* Battery settings */
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef BMW_I3_BATTERY
|
||||
#include "../datalayer/datalayer.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"
|
||||
|
||||
/* Do not change code below unless you are sure what you are doing */
|
||||
|
@ -478,17 +476,6 @@ static uint8_t increment_alive_counter(uint8_t counter) {
|
|||
return counter;
|
||||
}
|
||||
|
||||
void CAN_WriteFrame(CAN_frame_t* tx_frame) {
|
||||
CANMessage MCP2515Frame; //Struct with ACAN2515 library format, needed to use the MCP2515 library for CAN2
|
||||
MCP2515Frame.id = tx_frame->MsgID;
|
||||
//MCP2515Frame.ext = tx_frame->FIR.B.FF;
|
||||
MCP2515Frame.len = tx_frame->FIR.B.DLC;
|
||||
for (uint8_t i = 0; i < MCP2515Frame.len; i++) {
|
||||
MCP2515Frame.data[i] = tx_frame->data.u8[i];
|
||||
}
|
||||
can.tryToSend(MCP2515Frame);
|
||||
}
|
||||
|
||||
void update_values_battery2() { //This function maps all the values fetched via CAN2 to the battery2 datalayer
|
||||
if (!battery2_awake) {
|
||||
return;
|
||||
|
@ -750,7 +737,7 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
while (count < rx_frame.FIR.B.DLC && next_data < 49) {
|
||||
message_data[next_data++] = rx_frame.data.u8[count++];
|
||||
}
|
||||
ESP32Can.CANWriteFrame(&BMW_6F1_CONTINUE); // tell battery to send additional messages
|
||||
transmit_can(&BMW_6F1_CONTINUE, can_config.battery); // tell battery to send additional messages
|
||||
|
||||
} else if (rx_frame.FIR.B.DLC > 3 && next_data > 0 && rx_frame.data.u8[0] == 0xf1 &&
|
||||
((rx_frame.data.u8[1] & 0xF0) == 0x20)) {
|
||||
|
@ -919,7 +906,7 @@ void receive_can_battery2(CAN_frame_t rx_frame) {
|
|||
while (count2 < rx_frame.FIR.B.DLC && next_data < 49) {
|
||||
message_data[next_data++] = rx_frame.data.u8[count2++];
|
||||
}
|
||||
//ESP32Can.CANWriteFrame(&BMW_6F1_CONTINUE); // tell battery to send additional messages TODO: Make this send to Can2 instead of CAN1
|
||||
transmit_can(&BMW_6F1_CONTINUE, can_config.battery_double);
|
||||
|
||||
} else if (rx_frame.FIR.B.DLC > 3 && next_data > 0 && rx_frame.data.u8[0] == 0xf1 &&
|
||||
((rx_frame.data.u8[1] & 0xF0) == 0x20)) {
|
||||
|
@ -991,12 +978,12 @@ void send_can_battery() {
|
|||
if (datalayer.battery.status.bms_status == FAULT) {
|
||||
} //If battery is not in Fault mode, allow contactor to close by sending 10B
|
||||
else {
|
||||
ESP32Can.CANWriteFrame(&BMW_10B);
|
||||
transmit_can(&BMW_10B, can_config.battery);
|
||||
}
|
||||
|
||||
#ifdef DOUBLE_BATTERY //If second battery is allowed to join in, also send 10B
|
||||
if (datalayer.system.status.battery2_allows_contactor_closing == true) {
|
||||
CAN_WriteFrame(&BMW_10B);
|
||||
transmit_can(&BMW_10B, can_config.battery_double);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -1009,9 +996,9 @@ void send_can_battery() {
|
|||
|
||||
alive_counter_100ms = increment_alive_counter(alive_counter_100ms);
|
||||
|
||||
ESP32Can.CANWriteFrame(&BMW_12F);
|
||||
transmit_can(&BMW_12F, can_config.battery);
|
||||
#ifdef DOUBLE_BATTERY
|
||||
CAN_WriteFrame(&BMW_12F);
|
||||
transmit_can(&BMW_12F, can_config.battery_double);
|
||||
#endif
|
||||
}
|
||||
// Send 200ms CAN Message
|
||||
|
@ -1023,9 +1010,9 @@ void send_can_battery() {
|
|||
|
||||
alive_counter_200ms = increment_alive_counter(alive_counter_200ms);
|
||||
|
||||
ESP32Can.CANWriteFrame(&BMW_19B);
|
||||
transmit_can(&BMW_19B, can_config.battery);
|
||||
#ifdef DOUBLE_BATTERY
|
||||
CAN_WriteFrame(&BMW_19B);
|
||||
transmit_can(&BMW_19B, can_config.battery_double);
|
||||
#endif
|
||||
}
|
||||
// Send 500ms CAN Message
|
||||
|
@ -1037,20 +1024,20 @@ void send_can_battery() {
|
|||
|
||||
alive_counter_500ms = increment_alive_counter(alive_counter_500ms);
|
||||
|
||||
ESP32Can.CANWriteFrame(&BMW_30B);
|
||||
transmit_can(&BMW_30B, can_config.battery);
|
||||
#ifdef DOUBLE_BATTERY
|
||||
CAN_WriteFrame(&BMW_30B);
|
||||
transmit_can(&BMW_30B, can_config.battery_double);
|
||||
#endif
|
||||
}
|
||||
// Send 640ms CAN Message
|
||||
if (currentMillis - previousMillis640 >= INTERVAL_640_MS) {
|
||||
previousMillis640 = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&BMW_512); // Keep BMS alive
|
||||
ESP32Can.CANWriteFrame(&BMW_5F8);
|
||||
transmit_can(&BMW_512, can_config.battery); // Keep BMS alive
|
||||
transmit_can(&BMW_5F8, can_config.battery);
|
||||
#ifdef DOUBLE_BATTERY
|
||||
CAN_WriteFrame(&BMW_512);
|
||||
CAN_WriteFrame(&BMW_5F8);
|
||||
transmit_can(&BMW_512, can_config.battery_double);
|
||||
transmit_can(&BMW_5F8, can_config.battery_double);
|
||||
#endif
|
||||
}
|
||||
// Send 1000ms CAN Message
|
||||
|
@ -1077,39 +1064,39 @@ void send_can_battery() {
|
|||
|
||||
alive_counter_1000ms = increment_alive_counter(alive_counter_1000ms);
|
||||
|
||||
ESP32Can.CANWriteFrame(&BMW_3E8); //Order comes from CAN logs
|
||||
ESP32Can.CANWriteFrame(&BMW_328);
|
||||
ESP32Can.CANWriteFrame(&BMW_3F9);
|
||||
ESP32Can.CANWriteFrame(&BMW_2E2);
|
||||
ESP32Can.CANWriteFrame(&BMW_41D);
|
||||
ESP32Can.CANWriteFrame(&BMW_3D0);
|
||||
ESP32Can.CANWriteFrame(&BMW_3CA);
|
||||
ESP32Can.CANWriteFrame(&BMW_3A7);
|
||||
ESP32Can.CANWriteFrame(&BMW_2CA);
|
||||
ESP32Can.CANWriteFrame(&BMW_3FB);
|
||||
ESP32Can.CANWriteFrame(&BMW_418);
|
||||
ESP32Can.CANWriteFrame(&BMW_1D0);
|
||||
ESP32Can.CANWriteFrame(&BMW_3EC);
|
||||
ESP32Can.CANWriteFrame(&BMW_192);
|
||||
ESP32Can.CANWriteFrame(&BMW_13E);
|
||||
ESP32Can.CANWriteFrame(&BMW_433);
|
||||
transmit_can(&BMW_3E8, can_config.battery); //Order comes from CAN logs
|
||||
transmit_can(&BMW_328, can_config.battery);
|
||||
transmit_can(&BMW_3F9, can_config.battery);
|
||||
transmit_can(&BMW_2E2, can_config.battery);
|
||||
transmit_can(&BMW_41D, can_config.battery);
|
||||
transmit_can(&BMW_3D0, can_config.battery);
|
||||
transmit_can(&BMW_3CA, can_config.battery);
|
||||
transmit_can(&BMW_3A7, can_config.battery);
|
||||
transmit_can(&BMW_2CA, can_config.battery);
|
||||
transmit_can(&BMW_3FB, can_config.battery);
|
||||
transmit_can(&BMW_418, can_config.battery);
|
||||
transmit_can(&BMW_1D0, can_config.battery);
|
||||
transmit_can(&BMW_3EC, can_config.battery);
|
||||
transmit_can(&BMW_192, can_config.battery);
|
||||
transmit_can(&BMW_13E, can_config.battery);
|
||||
transmit_can(&BMW_433, can_config.battery);
|
||||
#ifdef DOUBLE_BATTERY
|
||||
CAN_WriteFrame(&BMW_3E8);
|
||||
CAN_WriteFrame(&BMW_328);
|
||||
CAN_WriteFrame(&BMW_3F9);
|
||||
CAN_WriteFrame(&BMW_2E2);
|
||||
CAN_WriteFrame(&BMW_41D);
|
||||
CAN_WriteFrame(&BMW_3D0);
|
||||
CAN_WriteFrame(&BMW_3CA);
|
||||
CAN_WriteFrame(&BMW_3A7);
|
||||
CAN_WriteFrame(&BMW_2CA);
|
||||
CAN_WriteFrame(&BMW_3FB);
|
||||
CAN_WriteFrame(&BMW_418);
|
||||
CAN_WriteFrame(&BMW_1D0);
|
||||
CAN_WriteFrame(&BMW_3EC);
|
||||
CAN_WriteFrame(&BMW_192);
|
||||
CAN_WriteFrame(&BMW_13E);
|
||||
CAN_WriteFrame(&BMW_433);
|
||||
transmit_can(&BMW_3E8, can_config.battery_double);
|
||||
transmit_can(&BMW_328, can_config.battery_double);
|
||||
transmit_can(&BMW_3F9, can_config.battery_double);
|
||||
transmit_can(&BMW_2E2, can_config.battery_double);
|
||||
transmit_can(&BMW_41D, can_config.battery_double);
|
||||
transmit_can(&BMW_3D0, can_config.battery_double);
|
||||
transmit_can(&BMW_3CA, can_config.battery_double);
|
||||
transmit_can(&BMW_3A7, can_config.battery_double);
|
||||
transmit_can(&BMW_2CA, can_config.battery_double);
|
||||
transmit_can(&BMW_3FB, can_config.battery_double);
|
||||
transmit_can(&BMW_418, can_config.battery_double);
|
||||
transmit_can(&BMW_1D0, can_config.battery_double);
|
||||
transmit_can(&BMW_3EC, can_config.battery_double);
|
||||
transmit_can(&BMW_192, can_config.battery_double);
|
||||
transmit_can(&BMW_13E, can_config.battery_double);
|
||||
transmit_can(&BMW_433, can_config.battery_double);
|
||||
#endif
|
||||
|
||||
BMW_433.data.u8[1] = 0x01; // First 433 message byte1 we send is unique, once we sent initial value send this
|
||||
|
@ -1118,30 +1105,30 @@ void send_can_battery() {
|
|||
next_data = 0;
|
||||
switch (cmdState) {
|
||||
case SOC:
|
||||
ESP32Can.CANWriteFrame(&BMW_6F1_CELL);
|
||||
transmit_can(&BMW_6F1_CELL, can_config.battery);
|
||||
#ifdef DOUBLE_BATTERY
|
||||
CAN_WriteFrame(&BMW_6F1_CELL);
|
||||
transmit_can(&BMW_6F1_CELL, can_config.battery_double);
|
||||
#endif
|
||||
cmdState = CELL_VOLTAGE;
|
||||
break;
|
||||
case CELL_VOLTAGE:
|
||||
ESP32Can.CANWriteFrame(&BMW_6F1_SOH);
|
||||
transmit_can(&BMW_6F1_SOH, can_config.battery);
|
||||
#ifdef DOUBLE_BATTERY
|
||||
CAN_WriteFrame(&BMW_6F1_SOH);
|
||||
transmit_can(&BMW_6F1_SOH, can_config.battery_double);
|
||||
#endif
|
||||
cmdState = SOH;
|
||||
break;
|
||||
case SOH:
|
||||
ESP32Can.CANWriteFrame(&BMW_6F1_CELL_VOLTAGE_AVG);
|
||||
transmit_can(&BMW_6F1_CELL_VOLTAGE_AVG, can_config.battery);
|
||||
#ifdef DOUBLE_BATTERY
|
||||
CAN_WriteFrame(&BMW_6F1_CELL_VOLTAGE_AVG);
|
||||
transmit_can(&BMW_6F1_CELL_VOLTAGE_AVG, can_config.battery_double);
|
||||
#endif
|
||||
cmdState = CELL_VOLTAGE_AVG;
|
||||
break;
|
||||
case CELL_VOLTAGE_AVG:
|
||||
ESP32Can.CANWriteFrame(&BMW_6F1_SOC);
|
||||
transmit_can(&BMW_6F1_SOC, can_config.battery);
|
||||
#ifdef DOUBLE_BATTERY
|
||||
CAN_WriteFrame(&BMW_6F1_SOC);
|
||||
transmit_can(&BMW_6F1_SOC, can_config.battery_double);
|
||||
#endif
|
||||
cmdState = SOC;
|
||||
break;
|
||||
|
@ -1154,25 +1141,25 @@ void send_can_battery() {
|
|||
BMW_3FC.data.u8[1] = ((BMW_3FC.data.u8[1] & 0xF0) + alive_counter_5000ms);
|
||||
BMW_3C5.data.u8[0] = ((BMW_3C5.data.u8[0] & 0xF0) + alive_counter_5000ms);
|
||||
|
||||
ESP32Can.CANWriteFrame(&BMW_3FC); //Order comes from CAN logs
|
||||
ESP32Can.CANWriteFrame(&BMW_3C5);
|
||||
ESP32Can.CANWriteFrame(&BMW_3A0);
|
||||
ESP32Can.CANWriteFrame(&BMW_592_0);
|
||||
ESP32Can.CANWriteFrame(&BMW_592_1);
|
||||
transmit_can(&BMW_3FC, can_config.battery); //Order comes from CAN logs
|
||||
transmit_can(&BMW_3C5, can_config.battery);
|
||||
transmit_can(&BMW_3A0, can_config.battery);
|
||||
transmit_can(&BMW_592_0, can_config.battery);
|
||||
transmit_can(&BMW_592_1, can_config.battery);
|
||||
#ifdef DOUBLE_BATTERY
|
||||
CAN_WriteFrame(&BMW_3FC);
|
||||
CAN_WriteFrame(&BMW_3C5);
|
||||
CAN_WriteFrame(&BMW_3A0);
|
||||
CAN_WriteFrame(&BMW_592_0);
|
||||
CAN_WriteFrame(&BMW_592_1);
|
||||
transmit_can(&BMW_3FC, can_config.battery_double);
|
||||
transmit_can(&BMW_3C5, can_config.battery_double);
|
||||
transmit_can(&BMW_3A0, can_config.battery_double);
|
||||
transmit_can(&BMW_592_0, can_config.battery_double);
|
||||
transmit_can(&BMW_592_1, can_config.battery_double);
|
||||
#endif
|
||||
|
||||
alive_counter_5000ms = increment_alive_counter(alive_counter_5000ms);
|
||||
|
||||
if (BMW_380_counter < 3) {
|
||||
ESP32Can.CANWriteFrame(&BMW_380); // This message stops after 3 times on startup
|
||||
transmit_can(&BMW_380, can_config.battery); // This message stops after 3 times on startup
|
||||
#ifdef DOUBLE_BATTERY
|
||||
CAN_WriteFrame(&BMW_380);
|
||||
transmit_can(&BMW_380, can_config.battery_double);
|
||||
#endif
|
||||
BMW_380_counter++;
|
||||
}
|
||||
|
@ -1181,13 +1168,13 @@ void send_can_battery() {
|
|||
if (currentMillis - previousMillis10000 >= INTERVAL_10_S) {
|
||||
previousMillis10000 = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&BMW_3E5); //Order comes from CAN logs
|
||||
ESP32Can.CANWriteFrame(&BMW_3E4);
|
||||
ESP32Can.CANWriteFrame(&BMW_37B);
|
||||
transmit_can(&BMW_3E5, can_config.battery); //Order comes from CAN logs
|
||||
transmit_can(&BMW_3E4, can_config.battery);
|
||||
transmit_can(&BMW_37B, can_config.battery);
|
||||
#ifdef DOUBLE_BATTERY
|
||||
CAN_WriteFrame(&BMW_3E5);
|
||||
CAN_WriteFrame(&BMW_3E4);
|
||||
CAN_WriteFrame(&BMW_37B);
|
||||
transmit_can(&BMW_3E5, can_config.battery_double);
|
||||
transmit_can(&BMW_3E4, can_config.battery_double);
|
||||
transmit_can(&BMW_37B, can_config.battery_double);
|
||||
#endif
|
||||
|
||||
BMW_3E5.data.u8[0] = 0xFD; // First 3E5 message byte0 we send is unique, once we sent initial value send this
|
||||
|
|
|
@ -3,9 +3,6 @@
|
|||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "../lib/pierremolinaro-acan2515/ACAN2515.h"
|
||||
|
||||
extern ACAN2515 can;
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
|
||||
|
@ -24,5 +21,6 @@ extern ACAN2515 can;
|
|||
#define MAX_PACK_VOLTAGE_120AH 4030 // Charge stops if pack voltage exceeds this value
|
||||
#define MIN_PACK_VOLTAGE_120AH 2680 // Discharge stops if pack voltage exceeds this value
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef BYD_ATTO_3_BATTERY
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "BYD-ATTO-3-BATTERY.h"
|
||||
|
||||
/* TODO:
|
||||
|
@ -232,7 +230,7 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; // Let system know battery is sending CAN
|
||||
|
||||
//This message transmits every 5?seconds. Seems like suitable place to poll for a PID
|
||||
ESP32Can.CANWriteFrame(&ATTO_3_7E7_POLL);
|
||||
transmit_can(&ATTO_3_7E7_POLL, can_config.battery);
|
||||
|
||||
switch (ATTO_3_7E7_POLL.data.u8[3]) {
|
||||
case POLL_FOR_BATTERY_SOC:
|
||||
|
@ -341,7 +339,7 @@ void send_can_battery() {
|
|||
ATTO_3_12D.data.u8[6] = (0x0F | (frame6_counter << 4));
|
||||
ATTO_3_12D.data.u8[7] = (0x09 | (frame7_counter << 4));
|
||||
|
||||
ESP32Can.CANWriteFrame(&ATTO_3_12D);
|
||||
transmit_can(&ATTO_3_12D, can_config.battery);
|
||||
}
|
||||
// Send 100ms CAN Message
|
||||
if (currentMillis - previousMillis100 >= INTERVAL_100_MS) {
|
||||
|
@ -354,7 +352,7 @@ void send_can_battery() {
|
|||
ATTO_3_411.data.u8[7] = 0xF5;
|
||||
}
|
||||
|
||||
ESP32Can.CANWriteFrame(&ATTO_3_411);
|
||||
transmit_can(&ATTO_3_411, can_config.battery);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
#define MAX_CELL_DEVIATION_MV 150
|
||||
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -702,8 +702,8 @@ void send_can_battery() {
|
|||
* that is the limiting factor. Therefore, we
|
||||
* can generally send as is without tweaks here.
|
||||
*/
|
||||
ESP32Can.CANWriteFrame(&CHADEMO_108);
|
||||
ESP32Can.CANWriteFrame(&CHADEMO_109);
|
||||
transmit_can(&CHADEMO_108, can_config.battery);
|
||||
transmit_can(&CHADEMO_109, can_config.battery);
|
||||
|
||||
/* TODO for dynamic control: can send x118 with byte 6 bit 0 set to 0 for 1s (before flipping back to 1) as a way of giving vehicle a chance to update 101.1 and 101.2
|
||||
* within 6 seconds of x118 toggle.
|
||||
|
@ -712,9 +712,9 @@ void send_can_battery() {
|
|||
*/
|
||||
|
||||
if (EVSE_mode == CHADEMO_DISCHARGE || EVSE_mode == CHADEMO_BIDIRECTIONAL) {
|
||||
ESP32Can.CANWriteFrame(&CHADEMO_208);
|
||||
transmit_can(&CHADEMO_208, can_config.battery);
|
||||
if (x201_received) {
|
||||
ESP32Can.CANWriteFrame(&CHADEMO_209);
|
||||
transmit_can(&CHADEMO_209, can_config.battery);
|
||||
x209_sent = true;
|
||||
}
|
||||
}
|
||||
|
@ -726,7 +726,7 @@ void send_can_battery() {
|
|||
//FIXME REMOVE
|
||||
Serial.println("REMOVE: proto 2.0");
|
||||
#endif
|
||||
ESP32Can.CANWriteFrame(&CHADEMO_118);
|
||||
transmit_can(&CHADEMO_118, can_config.battery);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,5 +15,6 @@
|
|||
#define ISA_SHUNT
|
||||
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -244,7 +244,7 @@ void ISA_initialize() {
|
|||
outframe.data.u8[6]=0x00;
|
||||
outframe.data.u8[7]=0x00;
|
||||
|
||||
ESP32Can.CANWriteFrame(&outframe);
|
||||
transmit_can((&outframe, can_config.battery);
|
||||
|
||||
delay(500);
|
||||
|
||||
|
@ -268,7 +268,7 @@ void ISA_STOP() {
|
|||
outframe.data.u8[5]=0x00;
|
||||
outframe.data.u8[6]=0x00;
|
||||
outframe.data.u8[7]=0x00;
|
||||
ESP32Can.CANWriteFrame(&outframe);
|
||||
transmit_can((&outframe, can_config.battery);
|
||||
|
||||
}
|
||||
|
||||
|
@ -281,7 +281,7 @@ void ISA_sendSTORE() {
|
|||
outframe.data.u8[5]=0x00;
|
||||
outframe.data.u8[6]=0x00;
|
||||
outframe.data.u8[7]=0x00;
|
||||
ESP32Can.CANWriteFrame(&outframe);
|
||||
transmit_can((&outframe, can_config.battery);
|
||||
}
|
||||
|
||||
void ISA_START() {
|
||||
|
@ -293,7 +293,7 @@ void ISA_START() {
|
|||
outframe.data.u8[5]=0x00;
|
||||
outframe.data.u8[6]=0x00;
|
||||
outframe.data.u8[7]=0x00;
|
||||
ESP32Can.CANWriteFrame(&outframe);
|
||||
transmit_can((&outframe, can_config.battery);
|
||||
}
|
||||
|
||||
void ISA_RESTART() {
|
||||
|
@ -306,7 +306,7 @@ void ISA_RESTART() {
|
|||
outframe.data.u8[5]=0x00;
|
||||
outframe.data.u8[6]=0x00;
|
||||
outframe.data.u8[7]=0x00;
|
||||
ESP32Can.CANWriteFrame(&outframe);
|
||||
transmit_can((&outframe, can_config.battery);
|
||||
}
|
||||
|
||||
void ISA_deFAULT() {
|
||||
|
@ -319,7 +319,7 @@ void ISA_deFAULT() {
|
|||
outframe.data.u8[5]=0x00;
|
||||
outframe.data.u8[6]=0x00;
|
||||
outframe.data.u8[7]=0x00;
|
||||
ESP32Can.CANWriteFrame(&outframe);
|
||||
transmit_can((&outframe, can_config.battery);
|
||||
}
|
||||
|
||||
void ISA_initCurrent() {
|
||||
|
@ -337,7 +337,7 @@ void ISA_initCurrent() {
|
|||
outframe.data.u8[6]=0x00;
|
||||
outframe.data.u8[7]=0x00;
|
||||
|
||||
ESP32Can.CANWriteFrame(&outframe);
|
||||
transmit_can((&outframe, can_config.battery);
|
||||
|
||||
delay(500);
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef CHADEMO_SHUNTS_H
|
||||
#define CHADEMO_SHUNTS_H
|
||||
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
uint16_t get_measured_voltage();
|
||||
uint16_t get_measured_current();
|
||||
inline void ISA_handler(CAN_frame_t* frame);
|
||||
|
@ -13,4 +15,6 @@ inline void ISA_handle526(CAN_frame_t* frame);
|
|||
inline void ISA_handle527(CAN_frame_t* frame);
|
||||
inline void ISA_handle528(CAN_frame_t* frame);
|
||||
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef IMIEV_CZERO_ION_BATTERY
|
||||
#include "../datalayer/datalayer.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:
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
#define MAX_CELL_DEVIATION_MV 500
|
||||
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#ifdef JAGUAR_IPACE_BATTERY
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "JAGUAR-IPACE-BATTERY.h"
|
||||
|
||||
/* Do not change code below unless you are sure what you are doing */
|
||||
|
@ -257,7 +256,7 @@ void send_can_battery() {
|
|||
if (currentMillis - previousMillis100 >= INTERVAL_100_MS) {
|
||||
previousMillis100 = currentMillis;
|
||||
|
||||
//ESP32Can.CANWriteFrame(&ipace_keep_alive);
|
||||
//transmit_can(&ipace_keep_alive);
|
||||
}
|
||||
|
||||
// Send 500ms CAN Message
|
||||
|
@ -281,7 +280,7 @@ void send_can_battery() {
|
|||
}},
|
||||
.MsgID = 0x7e4,
|
||||
.data = {0x03, 0x19, 0x02, 0x8f, 0x00, 0x00, 0x00, 0x00}};
|
||||
err = ESP32Can.CANWriteFrame(&msg);
|
||||
err = transmit_can(&msg, can_config.battery);
|
||||
if (err == 0)
|
||||
state++;
|
||||
|
||||
|
@ -297,7 +296,7 @@ void send_can_battery() {
|
|||
}},
|
||||
.MsgID = 0x7e4,
|
||||
.data = {0x06, 0x19, 0x04, 0xc0, 0x64, 0x88, 0xff, 0x00}};
|
||||
err = ESP32Can.CANWriteFrame(&msg);
|
||||
err = transmit_can(&msg, can_config.battery);
|
||||
if (err == 0)
|
||||
state++;
|
||||
break;
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
#ifndef JAGUAR_IPACE_BATTERY_H
|
||||
#define JAGUAR_IPACE_BATTERY_H
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
#define MAX_CELL_DEVIATION_MV 9999 // TODO is this ok ?
|
||||
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -13,5 +13,6 @@ extern ACAN2517FD canfd;
|
|||
#define MAXDISCHARGEPOWERALLOWED 10000
|
||||
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef KIA_HYUNDAI_64_BATTERY
|
||||
#include "../datalayer/datalayer.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 */
|
||||
|
@ -313,17 +311,17 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
}
|
||||
poll_data_pid++;
|
||||
if (poll_data_pid == 1) {
|
||||
ESP32Can.CANWriteFrame(&KIA64_7E4_id1);
|
||||
transmit_can(&KIA64_7E4_id1, can_config.battery);
|
||||
} else if (poll_data_pid == 2) {
|
||||
ESP32Can.CANWriteFrame(&KIA64_7E4_id2);
|
||||
transmit_can(&KIA64_7E4_id2, can_config.battery);
|
||||
} else if (poll_data_pid == 3) {
|
||||
ESP32Can.CANWriteFrame(&KIA64_7E4_id3);
|
||||
transmit_can(&KIA64_7E4_id3, can_config.battery);
|
||||
} else if (poll_data_pid == 4) {
|
||||
ESP32Can.CANWriteFrame(&KIA64_7E4_id4);
|
||||
transmit_can(&KIA64_7E4_id4, can_config.battery);
|
||||
} else if (poll_data_pid == 5) {
|
||||
ESP32Can.CANWriteFrame(&KIA64_7E4_id5);
|
||||
transmit_can(&KIA64_7E4_id5, can_config.battery);
|
||||
} else if (poll_data_pid == 6) {
|
||||
ESP32Can.CANWriteFrame(&KIA64_7E4_id6);
|
||||
transmit_can(&KIA64_7E4_id6, can_config.battery);
|
||||
} else if (poll_data_pid == 7) {
|
||||
} else if (poll_data_pid == 8) {
|
||||
} else if (poll_data_pid == 9) {
|
||||
|
@ -334,7 +332,7 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
switch (rx_frame.data.u8[0]) {
|
||||
case 0x10: //"PID Header"
|
||||
if (rx_frame.data.u8[4] == poll_data_pid) {
|
||||
ESP32Can.CANWriteFrame(&KIA64_7E4_ack); //Send ack to BMS if the same frame is sent as polled
|
||||
transmit_can(&KIA64_7E4_ack, can_config.battery); //Send ack to BMS if the same frame is sent as polled
|
||||
}
|
||||
break;
|
||||
case 0x21: //First frame in PID group
|
||||
|
@ -516,9 +514,9 @@ void send_can_battery() {
|
|||
if (currentMillis - previousMillis100 >= INTERVAL_100_MS) {
|
||||
previousMillis100 = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&KIA64_553);
|
||||
ESP32Can.CANWriteFrame(&KIA64_57F);
|
||||
ESP32Can.CANWriteFrame(&KIA64_2A1);
|
||||
transmit_can(&KIA64_553, can_config.battery);
|
||||
transmit_can(&KIA64_57F, can_config.battery);
|
||||
transmit_can(&KIA64_2A1, can_config.battery);
|
||||
}
|
||||
// Send 10ms CAN Message
|
||||
if (currentMillis - previousMillis10 >= INTERVAL_10_MS) {
|
||||
|
@ -570,11 +568,11 @@ void send_can_battery() {
|
|||
break;
|
||||
}
|
||||
|
||||
ESP32Can.CANWriteFrame(&KIA_HYUNDAI_200);
|
||||
transmit_can(&KIA_HYUNDAI_200, can_config.battery);
|
||||
|
||||
ESP32Can.CANWriteFrame(&KIA_HYUNDAI_523);
|
||||
transmit_can(&KIA_HYUNDAI_523, can_config.battery);
|
||||
|
||||
ESP32Can.CANWriteFrame(&KIA_HYUNDAI_524);
|
||||
transmit_can(&KIA_HYUNDAI_524, can_config.battery);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -583,9 +581,8 @@ void setup_battery(void) { // Performs one time setup at startup
|
|||
Serial.println("Kia Niro / Hyundai Kona 64kWh battery selected");
|
||||
#endif
|
||||
|
||||
datalayer.battery.info.max_design_voltage_dV =
|
||||
4040; // 404.0V, over this, charging is not possible (goes into forced discharge)
|
||||
datalayer.battery.info.min_design_voltage_dV = 3100; // 310.0V under this, discharging further is disabled
|
||||
datalayer.battery.info.max_design_voltage_dV = 4040; // 404.0V
|
||||
datalayer.battery.info.min_design_voltage_dV = 3100; // 310.0V
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -9,5 +9,6 @@
|
|||
|
||||
void setup_battery(void);
|
||||
void update_number_of_cells();
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef KIA_HYUNDAI_HYBRID_BATTERY
|
||||
#include "../datalayer/datalayer.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-HYBRID-BATTERY.h"
|
||||
|
||||
/* TODO:
|
||||
|
@ -124,7 +122,7 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
switch (rx_frame.data.u8[0]) {
|
||||
case 0x10: //"PID Header"
|
||||
if (rx_frame.data.u8[3] == poll_data_pid) {
|
||||
ESP32Can.CANWriteFrame(&KIA_7E4_ack); //Send ack to BMS if the same frame is sent as polled
|
||||
transmit_can(&KIA_7E4_ack, can_config.battery); //Send ack to BMS if the same frame is sent as polled
|
||||
}
|
||||
break;
|
||||
case 0x21: //First frame in PID group
|
||||
|
@ -259,15 +257,15 @@ void send_can_battery() {
|
|||
}
|
||||
poll_data_pid++;
|
||||
if (poll_data_pid == 1) {
|
||||
ESP32Can.CANWriteFrame(&KIA_7E4_id1);
|
||||
transmit_can(&KIA_7E4_id1, can_config.battery);
|
||||
} else if (poll_data_pid == 2) {
|
||||
ESP32Can.CANWriteFrame(&KIA_7E4_id2);
|
||||
transmit_can(&KIA_7E4_id2, can_config.battery);
|
||||
} else if (poll_data_pid == 3) {
|
||||
ESP32Can.CANWriteFrame(&KIA_7E4_id3);
|
||||
transmit_can(&KIA_7E4_id3, can_config.battery);
|
||||
} else if (poll_data_pid == 4) {
|
||||
|
||||
} else if (poll_data_pid == 5) {
|
||||
ESP32Can.CANWriteFrame(&KIA_7E4_id5);
|
||||
transmit_can(&KIA_7E4_id5, can_config.battery);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
#define MAX_CELL_DEVIATION_MV 100
|
||||
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef MG_5_BATTERY_H
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "MG-5-BATTERY.h"
|
||||
|
||||
/* TODO:
|
||||
|
@ -130,13 +128,13 @@ void send_can_battery() {
|
|||
}
|
||||
previousMillis10 = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&MG_5_100);
|
||||
transmit_can(&MG_5_100, can_config.battery);
|
||||
}
|
||||
// Send 100ms CAN Message
|
||||
if (currentMillis - previousMillis100 >= INTERVAL_100_MS) {
|
||||
previousMillis100 = currentMillis;
|
||||
|
||||
//ESP32Can.CANWriteFrame(&MG_5_100);
|
||||
//transmit_can(&MG_5_100, can_config.battery);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
#define MAX_CELL_DEVIATION_MV 150
|
||||
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
#endif
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.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
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "../lib/pierremolinaro-acan2515/ACAN2515.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
#define MAX_CELL_DEVIATION_MV 500
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef PYLON_BATTERY
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "PYLON-BATTERY.h"
|
||||
|
||||
/* Do not change code below unless you are sure what you are doing */
|
||||
|
@ -173,10 +171,10 @@ void send_can_battery() {
|
|||
|
||||
previousMillis1000 = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&PYLON_3010); // Heartbeat
|
||||
ESP32Can.CANWriteFrame(&PYLON_4200); // Ensemble OR System equipment info, depends on frame0
|
||||
ESP32Can.CANWriteFrame(&PYLON_8200); // Control device quit sleep status
|
||||
ESP32Can.CANWriteFrame(&PYLON_8210); // Charge command
|
||||
transmit_can(&PYLON_3010, can_config.battery); // Heartbeat
|
||||
transmit_can(&PYLON_4200, can_config.battery); // Ensemble OR System equipment info, depends on frame0
|
||||
transmit_can(&PYLON_8200, can_config.battery); // Control device quit sleep status
|
||||
transmit_can(&PYLON_8210, can_config.battery); // Charge command
|
||||
|
||||
if (ensemble_info_ack) {
|
||||
PYLON_4200.data.u8[0] = 0x00; //Request system equipment info
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
#define MAX_CELL_DEVIATION_MV 9999
|
||||
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef RENAULT_KANGOO_BATTERY
|
||||
#include "../datalayer/datalayer.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"
|
||||
|
||||
/* TODO:
|
||||
|
@ -233,7 +231,7 @@ void send_can_battery() {
|
|||
// Send 100ms CAN Message (for 2.4s, then pause 10s)
|
||||
if ((currentMillis - previousMillis100) >= (INTERVAL_100_MS + GVL_pause)) {
|
||||
previousMillis100 = currentMillis;
|
||||
ESP32Can.CANWriteFrame(&KANGOO_423);
|
||||
transmit_can(&KANGOO_423, can_config.battery);
|
||||
GVI_Pollcounter++;
|
||||
GVL_pause = 0;
|
||||
if (GVI_Pollcounter >= 24) {
|
||||
|
@ -245,9 +243,9 @@ void send_can_battery() {
|
|||
if (currentMillis - previousMillis1000 >= INTERVAL_1_S) {
|
||||
previousMillis1000 = currentMillis;
|
||||
if (GVB_79B_Continue)
|
||||
ESP32Can.CANWriteFrame(&KANGOO_79B_Continue);
|
||||
transmit_can(&KANGOO_79B_Continue, can_config.battery);
|
||||
} else {
|
||||
ESP32Can.CANWriteFrame(&KANGOO_79B);
|
||||
transmit_can(&KANGOO_79B, can_config.battery);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,5 +12,6 @@
|
|||
#define MAX_CHARGE_POWER_W 5000 // Battery can be charged with this amount of power
|
||||
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef RENAULT_ZOE_GEN1_BATTERY
|
||||
#include "../datalayer/datalayer.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-GEN1-BATTERY.h"
|
||||
|
||||
/* Information in this file is based of the OVMS V3 vehicle_renaultzoe.cpp component
|
||||
|
@ -114,7 +112,7 @@ void send_can_battery() {
|
|||
set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis100));
|
||||
}
|
||||
previousMillis100 = currentMillis;
|
||||
ESP32Can.CANWriteFrame(&ZOE_423);
|
||||
transmit_can(&ZOE_423, can_config.battery);
|
||||
|
||||
if ((counter_423 / 5) % 2 == 0) { // Alternate every 5 messages between these two
|
||||
ZOE_423.data.u8[4] = 0xB2;
|
||||
|
@ -128,7 +126,7 @@ void send_can_battery() {
|
|||
// 5000ms CAN handling
|
||||
if (currentMillis - previousMillis5000 >= INTERVAL_5_S) {
|
||||
previousMillis5000 = currentMillis;
|
||||
ESP32Can.CANWriteFrame(&ZOE_POLL_79B);
|
||||
transmit_can(&ZOE_POLL_79B, can_config.battery);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,5 +10,6 @@
|
|||
#define MAX_CELL_DEVIATION_MV 500
|
||||
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef RENAULT_ZOE_GEN2_BATTERY
|
||||
#include "../datalayer/datalayer.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-GEN2-BATTERY.h"
|
||||
|
||||
/* Information in this file is based of the OVMS V3 vehicle_renaultzoe.cpp component
|
||||
|
@ -96,8 +94,8 @@ void send_can_battery() {
|
|||
set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis200));
|
||||
}
|
||||
previousMillis200 = currentMillis;
|
||||
ESP32Can.CANWriteFrame(&ZOE_373);
|
||||
ESP32Can.CANWriteFrame(&ZOE_POLL_18DADBF1);
|
||||
transmit_can(&ZOE_373, can_config.battery);
|
||||
transmit_can(&ZOE_POLL_18DADBF1, can_config.battery);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,5 +10,6 @@
|
|||
#define MAX_CELL_DEVIATION_MV 500
|
||||
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef SANTA_FE_PHEV_BATTERY
|
||||
#include "../datalayer/datalayer.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!
|
||||
|
@ -175,7 +173,7 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
switch (rx_frame.data.u8[0]) {
|
||||
case 0x10: //"PID Header"
|
||||
if (rx_frame.data.u8[4] == poll_data_pid) {
|
||||
ESP32Can.CANWriteFrame(&SANTAFE_7E4_ack); //Send ack to BMS if the same frame is sent as polled
|
||||
transmit_can(&SANTAFE_7E4_ack, can_config.battery); //Send ack to BMS if the same frame is sent as polled
|
||||
}
|
||||
break;
|
||||
case 0x21: //First frame in PID group
|
||||
|
@ -355,11 +353,11 @@ void send_can_battery() {
|
|||
|
||||
SANTAFE_200.data.u8[7] = checksum_200;
|
||||
|
||||
ESP32Can.CANWriteFrame(&SANTAFE_200);
|
||||
transmit_can(&SANTAFE_200, can_config.battery);
|
||||
|
||||
ESP32Can.CANWriteFrame(&SANTAFE_2A1);
|
||||
transmit_can(&SANTAFE_2A1, can_config.battery);
|
||||
|
||||
ESP32Can.CANWriteFrame(&SANTAFE_2F0);
|
||||
transmit_can(&SANTAFE_2F0, can_config.battery);
|
||||
|
||||
counter_200++;
|
||||
if (counter_200 > 0xF) {
|
||||
|
@ -371,7 +369,7 @@ void send_can_battery() {
|
|||
if (currentMillis - previousMillis100 >= INTERVAL_100_MS) {
|
||||
previousMillis100 = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&SANTAFE_523);
|
||||
transmit_can(&SANTAFE_523, can_config.battery);
|
||||
}
|
||||
|
||||
// Send 500ms CAN Message
|
||||
|
@ -385,19 +383,19 @@ void send_can_battery() {
|
|||
poll_data_pid++;
|
||||
if (poll_data_pid == 1) {
|
||||
SANTAFE_7E4_poll.data.u8[3] = 0x01;
|
||||
ESP32Can.CANWriteFrame(&SANTAFE_7E4_poll);
|
||||
transmit_can(&SANTAFE_7E4_poll, can_config.battery);
|
||||
} else if (poll_data_pid == 2) {
|
||||
SANTAFE_7E4_poll.data.u8[3] = 0x02;
|
||||
ESP32Can.CANWriteFrame(&SANTAFE_7E4_poll);
|
||||
transmit_can(&SANTAFE_7E4_poll, can_config.battery);
|
||||
} else if (poll_data_pid == 3) {
|
||||
SANTAFE_7E4_poll.data.u8[3] = 0x03;
|
||||
ESP32Can.CANWriteFrame(&SANTAFE_7E4_poll);
|
||||
transmit_can(&SANTAFE_7E4_poll, can_config.battery);
|
||||
} else if (poll_data_pid == 4) {
|
||||
SANTAFE_7E4_poll.data.u8[3] = 0x04;
|
||||
ESP32Can.CANWriteFrame(&SANTAFE_7E4_poll);
|
||||
transmit_can(&SANTAFE_7E4_poll, can_config.battery);
|
||||
} else if (poll_data_pid == 5) {
|
||||
SANTAFE_7E4_poll.data.u8[3] = 0x05;
|
||||
ESP32Can.CANWriteFrame(&SANTAFE_7E4_poll);
|
||||
transmit_can(&SANTAFE_7E4_poll, can_config.battery);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,5 +9,6 @@
|
|||
|
||||
uint8_t CalculateCRC8(CAN_frame_t rx_frame);
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef TESLA_MODEL_3_BATTERY
|
||||
#include "../datalayer/datalayer.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 */
|
||||
|
@ -650,17 +648,6 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
|
||||
#ifdef DOUBLE_BATTERY
|
||||
|
||||
void CAN_WriteFrame(CAN_frame_t* tx_frame) {
|
||||
CANMessage MCP2515Frame; //Struct with ACAN2515 library format, needed to use the MCP2515 library for CAN2
|
||||
MCP2515Frame.id = tx_frame->MsgID;
|
||||
//MCP2515Frame.ext = tx_frame->FIR.B.FF;
|
||||
MCP2515Frame.len = tx_frame->FIR.B.DLC;
|
||||
for (uint8_t i = 0; i < MCP2515Frame.len; i++) {
|
||||
MCP2515Frame.data[i] = tx_frame->data.u8[i];
|
||||
}
|
||||
can.tryToSend(MCP2515Frame);
|
||||
}
|
||||
|
||||
void receive_can_battery2(CAN_frame_t rx_frame) {
|
||||
static uint8_t mux = 0;
|
||||
static uint16_t temp = 0;
|
||||
|
@ -1067,12 +1054,12 @@ the first, for a few cycles, then stop all messages which causes the contactor
|
|||
previousMillis30 = currentMillis;
|
||||
|
||||
if (datalayer.system.status.inverter_allows_contactor_closing) {
|
||||
ESP32Can.CANWriteFrame(&TESLA_221_1);
|
||||
ESP32Can.CANWriteFrame(&TESLA_221_2);
|
||||
transmit_can(&TESLA_221_1, can_config.battery);
|
||||
transmit_can(&TESLA_221_2, can_config.battery);
|
||||
#ifdef DOUBLE_BATTERY
|
||||
if (datalayer.system.status.battery2_allows_contactor_closing) {
|
||||
CAN_WriteFrame(&TESLA_221_1); // CAN2 connected to battery 2
|
||||
CAN_WriteFrame(&TESLA_221_2);
|
||||
transmit_can(&TESLA_221_1, can_config.battery_double); // CAN2 connected to battery 2
|
||||
transmit_can(&TESLA_221_2, can_config.battery_double);
|
||||
}
|
||||
#endif //DOUBLE_BATTERY
|
||||
}
|
||||
|
|
|
@ -24,9 +24,8 @@ 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);
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
#ifdef DOUBLE_BATTERY
|
||||
#include "../lib/pierremolinaro-acan2515/ACAN2515.h"
|
||||
extern ACAN2515 can;
|
||||
void printFaultCodesIfActive_battery2();
|
||||
#endif //DOUBLE_BATTERY
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef VOLVO_SPA_BATTERY
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "VOLVO-SPA-BATTERY.h"
|
||||
|
||||
/* Do not change code below unless you are sure what you are doing */
|
||||
|
@ -279,7 +277,7 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
{
|
||||
cell_voltages[battery_request_idx++] = ((rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6]);
|
||||
cell_voltages[battery_request_idx] = (rx_frame.data.u8[7] << 8);
|
||||
ESP32Can.CANWriteFrame(&VOLVO_FlowControl); // Send flow control
|
||||
transmit_can(&VOLVO_FlowControl, can_config.battery); // Send flow control
|
||||
rxConsecutiveFrames = 1;
|
||||
} else if ((rx_frame.data.u8[0] == 0x21) && (rxConsecutiveFrames == 1)) {
|
||||
cell_voltages[battery_request_idx++] = cell_voltages[battery_request_idx] | rx_frame.data.u8[1];
|
||||
|
@ -289,7 +287,7 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
if (batteryModuleNumber <= 0x2A) // Run until last pack is read
|
||||
{
|
||||
VOLVO_CELL_U_Req.data.u8[3] = batteryModuleNumber++;
|
||||
ESP32Can.CANWriteFrame(&VOLVO_CELL_U_Req); //Send cell voltage read request for next module
|
||||
transmit_can(&VOLVO_CELL_U_Req, can_config.battery); //Send cell voltage read request for next module
|
||||
} else {
|
||||
min_max_voltage[0] = 9999;
|
||||
min_max_voltage[1] = 0;
|
||||
|
@ -306,7 +304,7 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
if (min_max_voltage[0] <= MIN_CELL_VOLTAGE) {
|
||||
set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
|
||||
}
|
||||
ESP32Can.CANWriteFrame(&VOLVO_SOH_Req); //Send SOH read request
|
||||
transmit_can(&VOLVO_SOH_Req, can_config.battery); //Send SOH read request
|
||||
}
|
||||
rxConsecutiveFrames = 0;
|
||||
}
|
||||
|
@ -321,7 +319,7 @@ void readCellVoltages() {
|
|||
batteryModuleNumber = 0x10;
|
||||
rxConsecutiveFrames = 0;
|
||||
VOLVO_CELL_U_Req.data.u8[3] = batteryModuleNumber++;
|
||||
ESP32Can.CANWriteFrame(&VOLVO_CELL_U_Req); //Send cell voltage read request for first module
|
||||
transmit_can(&VOLVO_CELL_U_Req, can_config.battery); //Send cell voltage read request for first module
|
||||
}
|
||||
|
||||
void send_can_battery() {
|
||||
|
@ -336,8 +334,8 @@ void send_can_battery() {
|
|||
}
|
||||
previousMillis100 = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&VOLVO_536); //Send 0x536 Network managing frame to keep BMS alive
|
||||
ESP32Can.CANWriteFrame(&VOLVO_372); //Send 0x372 ECMAmbientTempCalculated
|
||||
transmit_can(&VOLVO_536, can_config.battery); //Send 0x536 Network managing frame to keep BMS alive
|
||||
transmit_can(&VOLVO_372, can_config.battery); //Send 0x372 ECMAmbientTempCalculated
|
||||
|
||||
if (datalayer.battery.status.bms_status == ACTIVE) {
|
||||
datalayer.system.status.battery_allows_contactor_closing = true;
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
#define MAX_CELL_DEVIATION_MV 250
|
||||
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef CHEVYVOLT_CHARGER
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "CHEVY-VOLT-CHARGER.h"
|
||||
|
||||
/* This implements Chevy Volt / Ampera charger support (2011-2015 model years).
|
||||
|
@ -145,7 +143,7 @@ void send_can_charger() {
|
|||
|
||||
charger_keepalive_frame.data.u8[0] = charger_mode;
|
||||
|
||||
ESP32Can.CANWriteFrame(&charger_keepalive_frame);
|
||||
transmit_can(&charger_keepalive_frame, can_config.charger);
|
||||
}
|
||||
|
||||
/* Send current targets every 200ms */
|
||||
|
@ -182,7 +180,7 @@ void send_can_charger() {
|
|||
/* LSB of the voltage command. Then MSB LSB is divided by 2 */
|
||||
charger_set_targets.data.u8[3] = lowByte(Vol_temp);
|
||||
|
||||
ESP32Can.CANWriteFrame(&charger_set_targets);
|
||||
transmit_can(&charger_set_targets, can_config.charger);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_VIA_USB
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define CHEVYVOLT_CHARGER_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define CHARGER_SELECTED
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef NISSANLEAF_CHARGER
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "NISSAN-LEAF-CHARGER.h"
|
||||
|
||||
/* This implements Nissan LEAF PDM charger support. 2013-2024 Gen2/3 PDMs are supported
|
||||
|
@ -198,13 +196,13 @@ void send_can_charger() {
|
|||
#ifndef NISSAN_LEAF_BATTERY
|
||||
|
||||
// VCM message, containing info if battery should sleep or stay awake
|
||||
ESP32Can.CANWriteFrame(&LEAF_50B); // HCM_WakeUpSleepCommand == 11b == WakeUp, and CANMASK = 1
|
||||
transmit_can(&LEAF_50B, can_config.charger); // HCM_WakeUpSleepCommand == 11b == WakeUp, and CANMASK = 1
|
||||
|
||||
LEAF_1DB.data.u8[7] = calculate_CRC_Nissan(&LEAF_1DB);
|
||||
ESP32Can.CANWriteFrame(&LEAF_1DB);
|
||||
transmit_can(&LEAF_1DB, can_config.charger);
|
||||
|
||||
LEAF_1DC.data.u8[7] = calculate_CRC_Nissan(&LEAF_1DC);
|
||||
ESP32Can.CANWriteFrame(&LEAF_1DC);
|
||||
transmit_can(&LEAF_1DC, can_config.charger);
|
||||
#endif
|
||||
|
||||
OBCpowerSetpoint = ((charger_setpoint_HV_IDC * 4) + 0x64);
|
||||
|
@ -249,8 +247,8 @@ void send_can_charger() {
|
|||
LEAF_1F2.data.u8[6] = mprun10;
|
||||
LEAF_1F2.data.u8[7] = calculate_checksum_nibble(&LEAF_1F2);
|
||||
|
||||
ESP32Can.CANWriteFrame(
|
||||
&LEAF_1F2); // Sending of 1F2 message is halted in LEAF-BATTERY function incase charger is used!
|
||||
transmit_can(&LEAF_1F2,
|
||||
can_config.charger); // Sending of 1F2 message is halted in LEAF-BATTERY function incase used here
|
||||
}
|
||||
|
||||
/* Send messages every 100ms here */
|
||||
|
@ -268,11 +266,11 @@ void send_can_charger() {
|
|||
LEAF_55B.data.u8[6] = ((0x1 << 4) | (mprun100));
|
||||
|
||||
LEAF_55B.data.u8[7] = calculate_CRC_Nissan(&LEAF_55B);
|
||||
ESP32Can.CANWriteFrame(&LEAF_55B);
|
||||
transmit_can(&LEAF_55B, can_config.charger);
|
||||
|
||||
ESP32Can.CANWriteFrame(&LEAF_59E);
|
||||
transmit_can(&LEAF_59E, can_config.charger);
|
||||
|
||||
ESP32Can.CANWriteFrame(&LEAF_5BC);
|
||||
transmit_can(&LEAF_5BC, can_config.charger);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define NISSANLEAF_CHARGER_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define CHARGER_SELECTED
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#include "../include.h"
|
||||
#ifdef BYD_CAN
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "BYD-CAN.h"
|
||||
|
||||
/* Do not change code below unless you are sure what you are doing */
|
||||
|
@ -18,7 +16,7 @@ static uint8_t char6_151 = 0;
|
|||
static uint8_t char7_151 = 0;
|
||||
|
||||
//Startup messages
|
||||
const CAN_frame_t BYD_250 = {
|
||||
CAN_frame_t BYD_250 = {
|
||||
.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
|
@ -27,42 +25,42 @@ const CAN_frame_t BYD_250 = {
|
|||
.MsgID = 0x250,
|
||||
.data = {0x03, 0x16, 0x00, 0x66, (uint8_t)((BATTERY_WH_MAX / 100) >> 8), (uint8_t)(BATTERY_WH_MAX / 100), 0x02,
|
||||
0x09}}; //3.16 FW , Capacity kWh byte4&5 (example 24kWh = 240)
|
||||
const CAN_frame_t BYD_290 = {.FIR = {.B =
|
||||
CAN_frame_t BYD_290 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x290,
|
||||
.data = {0x06, 0x37, 0x10, 0xD9, 0x00, 0x00, 0x00, 0x00}};
|
||||
const CAN_frame_t BYD_2D0 = {.FIR = {.B =
|
||||
CAN_frame_t BYD_2D0 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x2D0,
|
||||
.data = {0x00, 0x42, 0x59, 0x44, 0x00, 0x00, 0x00, 0x00}}; //BYD
|
||||
const CAN_frame_t BYD_3D0_0 = {.FIR = {.B =
|
||||
CAN_frame_t BYD_3D0_0 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x3D0,
|
||||
.data = {0x00, 0x42, 0x61, 0x74, 0x74, 0x65, 0x72, 0x79}}; //Battery
|
||||
const CAN_frame_t BYD_3D0_1 = {.FIR = {.B =
|
||||
CAN_frame_t BYD_3D0_1 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x3D0,
|
||||
.data = {0x01, 0x2D, 0x42, 0x6F, 0x78, 0x20, 0x50, 0x72}}; //-Box Pr
|
||||
const CAN_frame_t BYD_3D0_2 = {.FIR = {.B =
|
||||
CAN_frame_t BYD_3D0_2 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x3D0,
|
||||
.data = {0x02, 0x65, 0x6D, 0x69, 0x75, 0x6D, 0x20, 0x48}}; //emium H
|
||||
const CAN_frame_t BYD_3D0_3 = {.FIR = {.B =
|
||||
CAN_frame_t BYD_3D0_3 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
|
@ -246,31 +244,31 @@ void send_can_inverter() {
|
|||
if (currentMillis - previousMillis2s >= INTERVAL_2_S) {
|
||||
previousMillis2s = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&BYD_110);
|
||||
transmit_can(&BYD_110, can_config.inverter);
|
||||
}
|
||||
// Send 10s CAN Message
|
||||
if (currentMillis - previousMillis10s >= INTERVAL_10_S) {
|
||||
previousMillis10s = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&BYD_150);
|
||||
ESP32Can.CANWriteFrame(&BYD_1D0);
|
||||
ESP32Can.CANWriteFrame(&BYD_210);
|
||||
transmit_can(&BYD_150, can_config.inverter);
|
||||
transmit_can(&BYD_1D0, can_config.inverter);
|
||||
transmit_can(&BYD_210, can_config.inverter);
|
||||
}
|
||||
//Send 60s message
|
||||
if (currentMillis - previousMillis60s >= INTERVAL_60_S) {
|
||||
previousMillis60s = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&BYD_190);
|
||||
transmit_can(&BYD_190, can_config.inverter);
|
||||
}
|
||||
}
|
||||
|
||||
void send_intial_data() {
|
||||
ESP32Can.CANWriteFrame(&BYD_250);
|
||||
ESP32Can.CANWriteFrame(&BYD_290);
|
||||
ESP32Can.CANWriteFrame(&BYD_2D0);
|
||||
ESP32Can.CANWriteFrame(&BYD_3D0_0);
|
||||
ESP32Can.CANWriteFrame(&BYD_3D0_1);
|
||||
ESP32Can.CANWriteFrame(&BYD_3D0_2);
|
||||
ESP32Can.CANWriteFrame(&BYD_3D0_3);
|
||||
transmit_can(&BYD_250, can_config.inverter);
|
||||
transmit_can(&BYD_290, can_config.inverter);
|
||||
transmit_can(&BYD_2D0, can_config.inverter);
|
||||
transmit_can(&BYD_3D0_0, can_config.inverter);
|
||||
transmit_can(&BYD_3D0_1, can_config.inverter);
|
||||
transmit_can(&BYD_3D0_2, can_config.inverter);
|
||||
transmit_can(&BYD_3D0_3, can_config.inverter);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef BYD_CAN_H
|
||||
#define BYD_CAN_H
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define CAN_INVERTER_SELECTED
|
||||
|
||||
void send_intial_data();
|
||||
void transmit_can(CAN_frame_t* tx_frame, int interface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#include "../include.h"
|
||||
#ifdef PYLON_CAN
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "PYLON-CAN.h"
|
||||
|
||||
#define SEND_0 //If defined, the messages will have ID ending with 0 (useful for some inverters)
|
||||
|
@ -511,37 +509,37 @@ void send_setup_info() { //Ensemble information
|
|||
}
|
||||
|
||||
#ifdef SEND_0
|
||||
ESP32Can.CANWriteFrame(&PYLON_7310);
|
||||
ESP32Can.CANWriteFrame(&PYLON_7320);
|
||||
transmit_can(&PYLON_7310, can_config.inverter);
|
||||
transmit_can(&PYLON_7320, can_config.inverter);
|
||||
#endif
|
||||
#ifdef SEND_1
|
||||
ESP32Can.CANWriteFrame(&PYLON_7311);
|
||||
ESP32Can.CANWriteFrame(&PYLON_7321);
|
||||
transmit_can(&PYLON_7311, can_config.inverter);
|
||||
transmit_can(&PYLON_7321, can_config.inverter);
|
||||
#endif
|
||||
}
|
||||
|
||||
void send_system_data() { //System equipment information
|
||||
#ifdef SEND_0
|
||||
ESP32Can.CANWriteFrame(&PYLON_4210);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4220);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4230);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4240);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4250);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4260);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4270);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4280);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4290);
|
||||
transmit_can(&PYLON_4210, can_config.inverter);
|
||||
transmit_can(&PYLON_4220, can_config.inverter);
|
||||
transmit_can(&PYLON_4230, can_config.inverter);
|
||||
transmit_can(&PYLON_4240, can_config.inverter);
|
||||
transmit_can(&PYLON_4250, can_config.inverter);
|
||||
transmit_can(&PYLON_4260, can_config.inverter);
|
||||
transmit_can(&PYLON_4270, can_config.inverter);
|
||||
transmit_can(&PYLON_4280, can_config.inverter);
|
||||
transmit_can(&PYLON_4290, can_config.inverter);
|
||||
#endif
|
||||
#ifdef SEND_1
|
||||
ESP32Can.CANWriteFrame(&PYLON_4211);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4221);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4231);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4241);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4251);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4261);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4271);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4281);
|
||||
ESP32Can.CANWriteFrame(&PYLON_4291);
|
||||
transmit_can(&PYLON_4211, can_config.inverter);
|
||||
transmit_can(&PYLON_4221, can_config.inverter);
|
||||
transmit_can(&PYLON_4231, can_config.inverter);
|
||||
transmit_can(&PYLON_4241, can_config.inverter);
|
||||
transmit_can(&PYLON_4251, can_config.inverter);
|
||||
transmit_can(&PYLON_4261, can_config.inverter);
|
||||
transmit_can(&PYLON_4271, can_config.inverter);
|
||||
transmit_can(&PYLON_4281, can_config.inverter);
|
||||
transmit_can(&PYLON_4291, can_config.inverter);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef PYLON_CAN_H
|
||||
#define PYLON_CAN_H
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define CAN_INVERTER_SELECTED
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#include "../include.h"
|
||||
#ifdef SMA_CAN
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "SMA-CAN.h"
|
||||
|
||||
/* TODO: Map error bits in 0x158 */
|
||||
|
@ -11,7 +9,7 @@
|
|||
static unsigned long previousMillis100ms = 0; // will store last time a 100ms CAN Message was send
|
||||
|
||||
//Actual content messages
|
||||
static const CAN_frame_t SMA_558 = {
|
||||
static CAN_frame_t SMA_558 = {
|
||||
.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
|
@ -19,36 +17,35 @@ static const CAN_frame_t SMA_558 = {
|
|||
}},
|
||||
.MsgID = 0x558,
|
||||
.data = {0x03, 0x12, 0x00, 0x04, 0x00, 0x59, 0x07, 0x07}}; //7x BYD modules, Vendor ID 7 BYD
|
||||
static const CAN_frame_t SMA_598 = {
|
||||
.FIR = {.B =
|
||||
static CAN_frame_t SMA_598 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x598,
|
||||
.data = {0x00, 0x00, 0x12, 0x34, 0x5A, 0xDE, 0x07, 0x4F}}; //B0-4 Serial, rest unknown
|
||||
static const CAN_frame_t SMA_5D8 = {.FIR = {.B =
|
||||
static CAN_frame_t SMA_5D8 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x5D8,
|
||||
.data = {0x00, 0x42, 0x59, 0x44, 0x00, 0x00, 0x00, 0x00}}; //B Y D
|
||||
static const CAN_frame_t SMA_618_1 = {.FIR = {.B =
|
||||
static CAN_frame_t SMA_618_1 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x618,
|
||||
.data = {0x00, 0x42, 0x61, 0x74, 0x74, 0x65, 0x72, 0x79}}; //0 B A T T E R Y
|
||||
static const CAN_frame_t SMA_618_2 = {.FIR = {.B =
|
||||
static CAN_frame_t SMA_618_2 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x618,
|
||||
.data = {0x01, 0x2D, 0x42, 0x6F, 0x78, 0x20, 0x48, 0x39}}; //1 - B O X H
|
||||
static const CAN_frame_t SMA_618_3 = {.FIR = {.B =
|
||||
static CAN_frame_t SMA_618_3 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
|
@ -257,18 +254,18 @@ void send_can_inverter() {
|
|||
if (currentMillis - previousMillis100ms >= INTERVAL_100_MS) {
|
||||
previousMillis100ms = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&SMA_558);
|
||||
ESP32Can.CANWriteFrame(&SMA_598);
|
||||
ESP32Can.CANWriteFrame(&SMA_5D8);
|
||||
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);
|
||||
ESP32Can.CANWriteFrame(&SMA_518);
|
||||
ESP32Can.CANWriteFrame(&SMA_4D8);
|
||||
ESP32Can.CANWriteFrame(&SMA_158);
|
||||
transmit_can(&SMA_558, can_config.inverter);
|
||||
transmit_can(&SMA_598, can_config.inverter);
|
||||
transmit_can(&SMA_5D8, can_config.inverter);
|
||||
transmit_can(&SMA_618_1, can_config.inverter); // TODO, should these 3x
|
||||
transmit_can(&SMA_618_2, can_config.inverter); // be sent as batch?
|
||||
transmit_can(&SMA_618_3, can_config.inverter); // or alternate on each send?
|
||||
transmit_can(&SMA_358, can_config.inverter);
|
||||
transmit_can(&SMA_3D8, can_config.inverter);
|
||||
transmit_can(&SMA_458, can_config.inverter);
|
||||
transmit_can(&SMA_518, can_config.inverter);
|
||||
transmit_can(&SMA_4D8, can_config.inverter);
|
||||
transmit_can(&SMA_158, can_config.inverter);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef SMA_CAN_H
|
||||
#define SMA_CAN_H
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define CAN_INVERTER_SELECTED
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#include "../include.h"
|
||||
#ifdef SMA_TRIPOWER_CAN
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "SMA-TRIPOWER-CAN.h"
|
||||
|
||||
/* TODO:
|
||||
|
@ -356,28 +354,28 @@ void send_can_inverter() {
|
|||
if (currentMillis - previousMillis500ms >= INTERVAL_500_MS) {
|
||||
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
|
||||
transmit_can(&SMA_00D, can_config.inverter); //Battery limits
|
||||
transmit_can(&SMA_00F, can_config.inverter); // Battery state
|
||||
transmit_can(&SMA_011, can_config.inverter); // Battery Energy
|
||||
transmit_can(&SMA_013, can_config.inverter); // Battery Measurements
|
||||
transmit_can(&SMA_014, can_config.inverter); // Battery Temperatures and cellvoltages
|
||||
}
|
||||
|
||||
if (batteryAlarm) { //Non-cyclic
|
||||
ESP32Can.CANWriteFrame(&SMA_005); // Battery Alarms 1
|
||||
ESP32Can.CANWriteFrame(&SMA_007); // Battery Alarms 2
|
||||
transmit_can(&SMA_005, can_config.inverter); // Battery Alarms 1
|
||||
transmit_can(&SMA_007, can_config.inverter); // Battery Alarms 2
|
||||
}
|
||||
|
||||
if (BMSevent) { //Non-cyclic
|
||||
ESP32Can.CANWriteFrame(&SMA_006); // Battery Errorcode
|
||||
ESP32Can.CANWriteFrame(&SMA_008); // Battery Events
|
||||
transmit_can(&SMA_006, can_config.inverter); // Battery Errorcode
|
||||
transmit_can(&SMA_008, can_config.inverter); // 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
|
||||
transmit_can(&SMA_015, can_config.inverter); // Battery Data 1
|
||||
transmit_can(&SMA_016, can_config.inverter); // Battery Data 2
|
||||
transmit_can(&SMA_017, can_config.inverter); // Battery Manufacturer
|
||||
transmit_can(&SMA_018, can_config.inverter); // Battery Name
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef SMA_CAN_TRIPOWER_H
|
||||
#define SMA_CAN_TRIPOWER_H
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define CAN_INVERTER_SELECTED
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#include "../include.h"
|
||||
#ifdef SOFAR_CAN
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "SOFAR-CAN.h"
|
||||
|
||||
/* This implementation of the SOFAR can protocol is halfway done. What's missing is implementing the inverter replies, all the CAN messages are listed, but the can sending is missing. */
|
||||
|
@ -329,14 +327,14 @@ void send_can_inverter() {
|
|||
if (currentMillis - previousMillis100 >= INTERVAL_100_MS) {
|
||||
previousMillis100 = currentMillis;
|
||||
//Frames actively reported by BMS
|
||||
ESP32Can.CANWriteFrame(&SOFAR_351);
|
||||
ESP32Can.CANWriteFrame(&SOFAR_355);
|
||||
ESP32Can.CANWriteFrame(&SOFAR_356);
|
||||
ESP32Can.CANWriteFrame(&SOFAR_30F);
|
||||
ESP32Can.CANWriteFrame(&SOFAR_359);
|
||||
ESP32Can.CANWriteFrame(&SOFAR_35E);
|
||||
ESP32Can.CANWriteFrame(&SOFAR_35F);
|
||||
ESP32Can.CANWriteFrame(&SOFAR_35A);
|
||||
transmit_can(&SOFAR_351, can_config.inverter);
|
||||
transmit_can(&SOFAR_355, can_config.inverter);
|
||||
transmit_can(&SOFAR_356, can_config.inverter);
|
||||
transmit_can(&SOFAR_30F, can_config.inverter);
|
||||
transmit_can(&SOFAR_359, can_config.inverter);
|
||||
transmit_can(&SOFAR_35E, can_config.inverter);
|
||||
transmit_can(&SOFAR_35F, can_config.inverter);
|
||||
transmit_can(&SOFAR_35A, can_config.inverter);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef SOFAR_CAN_H
|
||||
#define SOFAR_CAN_H
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define CAN_INVERTER_SELECTED
|
||||
|
||||
|
|
|
@ -106,21 +106,6 @@ CAN_frame_t SOLAX_100A001 = {.FIR = {.B =
|
|||
#define Contactor_Open_Payload __builtin_bswap64(0x0200010000000000)
|
||||
#define Contactor_Close_Payload __builtin_bswap64(0x0200010001000000)
|
||||
|
||||
void CAN_WriteFrame(CAN_frame_t* tx_frame) {
|
||||
#ifdef DUAL_CAN
|
||||
CANMessage MCP2515Frame; //Struct with ACAN2515 library format, needed to use the MCP2515 library
|
||||
MCP2515Frame.id = tx_frame->MsgID;
|
||||
MCP2515Frame.ext = tx_frame->FIR.B.FF;
|
||||
MCP2515Frame.len = tx_frame->FIR.B.DLC;
|
||||
for (uint8_t i = 0; i < MCP2515Frame.len; i++) {
|
||||
MCP2515Frame.data[i] = tx_frame->data.u8[i];
|
||||
}
|
||||
can.tryToSend(MCP2515Frame);
|
||||
#else
|
||||
ESP32Can.CANWriteFrame(tx_frame);
|
||||
#endif
|
||||
}
|
||||
|
||||
void update_values_can_inverter() { //This function maps all the values fetched from battery CAN to the correct CAN messages
|
||||
// If not receiveing any communication from the inverter, open contactors and return to battery announce state
|
||||
if (millis() - LastFrameTime >= SolaxTimeout) {
|
||||
|
@ -263,15 +248,15 @@ void receive_can_inverter(CAN_frame_t rx_frame) {
|
|||
datalayer.system.status.inverter_allows_contactor_closing = false;
|
||||
SOLAX_1875.data.u8[4] = (0x00); // Inform Inverter: Contactor 0=off, 1=on.
|
||||
for (int i = 0; i <= number_of_batteries; i++) {
|
||||
CAN_WriteFrame(&SOLAX_1872);
|
||||
CAN_WriteFrame(&SOLAX_1873);
|
||||
CAN_WriteFrame(&SOLAX_1874);
|
||||
CAN_WriteFrame(&SOLAX_1875);
|
||||
CAN_WriteFrame(&SOLAX_1876);
|
||||
CAN_WriteFrame(&SOLAX_1877);
|
||||
CAN_WriteFrame(&SOLAX_1878);
|
||||
transmit_can(&SOLAX_1872, can_config.inverter);
|
||||
transmit_can(&SOLAX_1873, can_config.inverter);
|
||||
transmit_can(&SOLAX_1874, can_config.inverter);
|
||||
transmit_can(&SOLAX_1875, can_config.inverter);
|
||||
transmit_can(&SOLAX_1876, can_config.inverter);
|
||||
transmit_can(&SOLAX_1877, can_config.inverter);
|
||||
transmit_can(&SOLAX_1878, can_config.inverter);
|
||||
}
|
||||
CAN_WriteFrame(&SOLAX_100A001); //BMS Announce
|
||||
transmit_can(&SOLAX_100A001, can_config.inverter); //BMS Announce
|
||||
// Message from the inverter to proceed to contactor closing
|
||||
// Byte 4 changes from 0 to 1
|
||||
if (rx_frame.data.u64 == Contactor_Close_Payload)
|
||||
|
@ -280,14 +265,14 @@ void receive_can_inverter(CAN_frame_t rx_frame) {
|
|||
|
||||
case (WAITING_FOR_CONTACTOR):
|
||||
SOLAX_1875.data.u8[4] = (0x00); // Inform Inverter: Contactor 0=off, 1=on.
|
||||
CAN_WriteFrame(&SOLAX_1872);
|
||||
CAN_WriteFrame(&SOLAX_1873);
|
||||
CAN_WriteFrame(&SOLAX_1874);
|
||||
CAN_WriteFrame(&SOLAX_1875);
|
||||
CAN_WriteFrame(&SOLAX_1876);
|
||||
CAN_WriteFrame(&SOLAX_1877);
|
||||
CAN_WriteFrame(&SOLAX_1878);
|
||||
CAN_WriteFrame(&SOLAX_1801); // Announce that the battery will be connected
|
||||
transmit_can(&SOLAX_1872, can_config.inverter);
|
||||
transmit_can(&SOLAX_1873, can_config.inverter);
|
||||
transmit_can(&SOLAX_1874, can_config.inverter);
|
||||
transmit_can(&SOLAX_1875, can_config.inverter);
|
||||
transmit_can(&SOLAX_1876, can_config.inverter);
|
||||
transmit_can(&SOLAX_1877, can_config.inverter);
|
||||
transmit_can(&SOLAX_1878, can_config.inverter);
|
||||
transmit_can(&SOLAX_1801, can_config.inverter); // Announce that the battery will be connected
|
||||
STATE = CONTACTOR_CLOSED; // Jump to Contactor Closed State
|
||||
#ifdef DEBUG_VIA_USB
|
||||
Serial.println("Solax Battery State: Contactor Closed");
|
||||
|
@ -297,13 +282,13 @@ void receive_can_inverter(CAN_frame_t rx_frame) {
|
|||
case (CONTACTOR_CLOSED):
|
||||
datalayer.system.status.inverter_allows_contactor_closing = true;
|
||||
SOLAX_1875.data.u8[4] = (0x01); // Inform Inverter: Contactor 0=off, 1=on.
|
||||
CAN_WriteFrame(&SOLAX_1872);
|
||||
CAN_WriteFrame(&SOLAX_1873);
|
||||
CAN_WriteFrame(&SOLAX_1874);
|
||||
CAN_WriteFrame(&SOLAX_1875);
|
||||
CAN_WriteFrame(&SOLAX_1876);
|
||||
CAN_WriteFrame(&SOLAX_1877);
|
||||
CAN_WriteFrame(&SOLAX_1878);
|
||||
transmit_can(&SOLAX_1872, can_config.inverter);
|
||||
transmit_can(&SOLAX_1873, can_config.inverter);
|
||||
transmit_can(&SOLAX_1874, can_config.inverter);
|
||||
transmit_can(&SOLAX_1875, can_config.inverter);
|
||||
transmit_can(&SOLAX_1876, can_config.inverter);
|
||||
transmit_can(&SOLAX_1877, can_config.inverter);
|
||||
transmit_can(&SOLAX_1878, can_config.inverter);
|
||||
// Message from the inverter to open contactor
|
||||
// Byte 4 changes from 1 to 0
|
||||
if (rx_frame.data.u64 == Contactor_Open_Payload) {
|
||||
|
@ -315,8 +300,8 @@ void receive_can_inverter(CAN_frame_t rx_frame) {
|
|||
}
|
||||
|
||||
if (rx_frame.MsgID == 0x1871 && rx_frame.data.u64 == __builtin_bswap64(0x0500010000000000)) {
|
||||
CAN_WriteFrame(&SOLAX_1881);
|
||||
CAN_WriteFrame(&SOLAX_1882);
|
||||
transmit_can(&SOLAX_1881, can_config.inverter);
|
||||
transmit_can(&SOLAX_1882, can_config.inverter);
|
||||
#ifdef DEBUG_VIA_USB
|
||||
Serial.println("1871 05-frame received from inverter");
|
||||
#endif
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
#ifndef SOLAX_CAN_H
|
||||
#define SOLAX_CAN_H
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "../lib/pierremolinaro-acan2515/ACAN2515.h"
|
||||
|
||||
#define CAN_INVERTER_SELECTED
|
||||
|
||||
extern ACAN2515 can;
|
||||
|
||||
// Timeout in milliseconds
|
||||
#define SolaxTimeout 2000
|
||||
|
||||
|
@ -18,5 +14,4 @@ extern ACAN2515 can;
|
|||
#define FAULT_SOLAX 3
|
||||
#define UPDATING_FW 4
|
||||
|
||||
void receive_can_solax(CAN_frame_t rx_frame);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue