mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 09:49:32 +02:00
Make CAN-FD work with refactor
This commit is contained in:
parent
e92f35e50b
commit
28c4bf1c7f
4 changed files with 23 additions and 34 deletions
|
@ -917,7 +917,7 @@ void transmit_can(CAN_frame_t* tx_frame, int interface) {
|
|||
#ifdef CAN_FD
|
||||
CANFDMessage MCP2518Frame;
|
||||
MCP2518Frame.id = tx_frame->MsgID;
|
||||
//MCP2518Frame.ext = false; //TODO: Howto handle this?
|
||||
MCP2518Frame.ext = tx_frame->FIR.B.FF;
|
||||
MCP2518Frame.len = tx_frame->FIR.B.DLC;
|
||||
for (uint8_t i = 0; i < MCP2518Frame.len; i++) {
|
||||
MCP2518Frame.data[i] = tx_frame->data.u8[i];
|
||||
|
|
|
@ -12,7 +12,7 @@ CAN_ADDON_FD_MCP2518 = Add-on CAN-FD MCP2518 connected to GPIO pins
|
|||
*/
|
||||
|
||||
volatile CAN_Configuration can_config = {
|
||||
.battery = CAN_ADDON_FD_MCP2518, // Which CAN is your battery connected to?
|
||||
.battery = CAN_NATIVE, // Which CAN is your battery connected to?
|
||||
.inverter = CAN_NATIVE, // Which CAN is your inverter connected to? (No need to configure incase you use RS485)
|
||||
.battery_double = CAN_ADDON_MCP2515, // (OPTIONAL) Which CAN is your second battery connected to?
|
||||
.charger = CAN_NATIVE // (OPTIONAL) Which CAN is your charger connected to?
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
//#define IMIEV_CZERO_ION_BATTERY
|
||||
//#define JAGUAR_IPACE_BATTERY
|
||||
//#define KIA_HYUNDAI_64_BATTERY
|
||||
#define KIA_E_GMP_BATTERY
|
||||
//#define KIA_E_GMP_BATTERY
|
||||
//#define KIA_HYUNDAI_HYBRID_BATTERY
|
||||
//#define MG_5_BATTERY
|
||||
//#define NISSAN_LEAF_BATTERY
|
||||
|
@ -43,13 +43,13 @@
|
|||
//#define HW_STARK
|
||||
|
||||
/* Other options */
|
||||
//#define DEBUG_VIA_USB //Enable this line to have the USB port output serial diagnostic data while program runs (WARNING, raises CPU load, do not use for production)
|
||||
#define DEBUG_VIA_USB //Enable this line to have the USB port output serial diagnostic data while program runs (WARNING, raises CPU load, do not use for production)
|
||||
//#define DEBUG_CANFD_DATA //Enable this line to have the USB port output CAN-FD data while program runs (WARNING, raises CPU load, do not use for production)
|
||||
//#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 CAN_FD //Enable this line to activate an isolated secondary CAN-FD bus using add-on MCP2517FD controller (Needed for some batteries)
|
||||
//#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)
|
||||
#define WEBSERVER //Enable this line to enable WiFi, and to run the webserver. See USER_SETTINGS.cpp for the Wifi settings.
|
||||
|
|
|
@ -43,8 +43,21 @@ static int8_t temperature_water_inlet = 0;
|
|||
static int8_t powerRelayTemperature = 0;
|
||||
static int8_t heatertemp = 0;
|
||||
|
||||
CANFDMessage EGMP_7E4;
|
||||
CANFDMessage EGMP_7E4_ack;
|
||||
CAN_frame_t EGMP_7E4 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std, // Converted to CAN-FD when sent
|
||||
}},
|
||||
.MsgID = 0x7E4,
|
||||
.data = {0x03, 0x22, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00}}; //Poll PID 03 22 01 01
|
||||
CAN_frame_t EGMP_7E4_ack = {
|
||||
.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std, // Converted to CAN-FD when sent
|
||||
}},
|
||||
.MsgID = 0x7E4,
|
||||
.data = {0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; //Ack frame, correct PID is returned
|
||||
|
||||
void set_cell_voltages(CANFDMessage frame, int start, int length, int startCell) {
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
|
@ -173,18 +186,6 @@ void update_values_battery() { //This function maps all the values fetched via
|
|||
#endif
|
||||
}
|
||||
|
||||
void send_canfd_frame(CANFDMessage frame) {
|
||||
#ifdef DEBUG_VIA_USB
|
||||
const bool ok = canfd.tryToSend(frame);
|
||||
if (ok) {
|
||||
} else {
|
||||
Serial.println("Send canfd failure.");
|
||||
}
|
||||
#else
|
||||
canfd.tryToSend(frame);
|
||||
#endif
|
||||
}
|
||||
|
||||
void receive_canfd_battery(CANFDMessage frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (frame.id) {
|
||||
|
@ -195,7 +196,7 @@ void receive_canfd_battery(CANFDMessage frame) {
|
|||
// Serial.println ("Send ack");
|
||||
poll_data_pid = frame.data[4];
|
||||
// if (frame.data[4] == poll_data_pid) {
|
||||
send_canfd_frame(EGMP_7E4_ack); //Send ack to BMS if the same frame is sent as polled
|
||||
transmit_can(&EGMP_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
|
||||
|
@ -388,8 +389,8 @@ void send_can_battery() {
|
|||
datalayer.system.status.battery_allows_contactor_closing = false;
|
||||
}
|
||||
// Section end
|
||||
EGMP_7E4.data[3] = KIA_7E4_COUNTER;
|
||||
send_canfd_frame(EGMP_7E4);
|
||||
EGMP_7E4.data.u8[3] = KIA_7E4_COUNTER;
|
||||
transmit_can(&EGMP_7E4, can_config.battery);
|
||||
|
||||
KIA_7E4_COUNTER++;
|
||||
if (KIA_7E4_COUNTER > 0x0D) { // gets up to 0x010C before repeating
|
||||
|
@ -409,18 +410,6 @@ void setup_battery(void) { // Performs one time setup at startup
|
|||
8064; // TODO: define when battery is known, charging is not possible (goes into forced discharge)
|
||||
datalayer.battery.info.min_design_voltage_dV =
|
||||
4320; // TODO: define when battery is known. discharging further is disabled
|
||||
|
||||
EGMP_7E4.id = 0x7E4;
|
||||
EGMP_7E4.ext = false;
|
||||
EGMP_7E4.len = 8;
|
||||
uint8_t dataEGMP_7E4[8] = {0x03, 0x22, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00}; //Poll PID 03 22 01 01
|
||||
memcpy(EGMP_7E4.data, dataEGMP_7E4, sizeof(dataEGMP_7E4));
|
||||
|
||||
EGMP_7E4_ack.id = 0x7E4;
|
||||
EGMP_7E4_ack.ext = false;
|
||||
EGMP_7E4_ack.len = 8;
|
||||
uint8_t dataEGMP_7E4_ack[8] = {0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; //Ack frame, correct PID is returned
|
||||
memcpy(EGMP_7E4_ack.data, dataEGMP_7E4_ack, sizeof(dataEGMP_7E4_ack));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue