mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 19:42:08 +02:00
Add RX handlign via struct
This commit is contained in:
parent
08f2c6ee3c
commit
572c9c050b
49 changed files with 171 additions and 211 deletions
|
@ -530,30 +530,21 @@ void receive_canfd() { // This section checks if we have a complete CAN-FD mess
|
|||
#endif
|
||||
|
||||
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) {
|
||||
|
||||
if (can_config.battery == CAN_NATIVE) {
|
||||
#ifndef SERIAL_LINK_RECEIVER
|
||||
receive_can_battery(rx_frame);
|
||||
#endif // SERIAL_LINK_RECEIVER
|
||||
CAN_frame_t rx_frame_native;
|
||||
if (xQueueReceive(CAN_cfg.rx_queue, &rx_frame_native, 0) == pdTRUE) {
|
||||
CAN_frame rx_frame;
|
||||
rx_frame.ID = rx_frame_native.MsgID;
|
||||
if (rx_frame_native.FIR.B.FF == CAN_frame_std) {
|
||||
rx_frame.ext_ID = false;
|
||||
} else { //CAN_frame_ext == 1
|
||||
rx_frame.ext_ID = true;
|
||||
}
|
||||
if (can_config.inverter == CAN_NATIVE) {
|
||||
#ifdef CAN_INVERTER_SELECTED
|
||||
receive_can_inverter(rx_frame);
|
||||
#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 // CHARGER_SELECTED
|
||||
rx_frame.DLC = rx_frame_native.FIR.B.DLC;
|
||||
for (uint8_t i = 0; i < rx_frame.DLC; i++) {
|
||||
rx_frame.data.u8[i] = rx_frame_native.data.u8[i];
|
||||
}
|
||||
//message incoming, pass it on to the handler
|
||||
receive_can(&rx_frame, CAN_NATIVE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -939,3 +930,24 @@ void transmit_can(CAN_frame* tx_frame, int interface) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
void receive_can(CAN_frame* rx_frame, int interface) {
|
||||
|
||||
if (interface == can_config.battery) {
|
||||
receive_can_battery(*rx_frame);
|
||||
}
|
||||
if (interface == can_config.inverter) {
|
||||
#ifdef CAN_INVERTER_SELECTED
|
||||
receive_can_inverter(*rx_frame);
|
||||
#endif
|
||||
}
|
||||
if (interface == can_config.battery_double) {
|
||||
#ifdef DOUBLE_BATTERY
|
||||
receive_can_battery2(*rx_frame);
|
||||
#endif
|
||||
}
|
||||
if (interface == can_config.charger) {
|
||||
#ifdef CHARGER_SELECTED
|
||||
receive_can_charger(*rx_frame);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
|
||||
/* 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 NISSANLEAF_CHARGER //Enable this line to control a Nissan LEAF PDM connected to battery - for example, when generator charging
|
||||
//#define NISSANLEAF_CHARGER //Enable this line to control a Nissan LEAF PDM connected to battery - for example, when generator charging
|
||||
|
||||
/* Battery settings */
|
||||
// Predefined total energy capacity of the battery in Watt-hours
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef BATTERIES_H
|
||||
#define BATTERIES_H
|
||||
#include "../../USER_SETTINGS.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" // This include is annoying, consider defining a frame type in types.h
|
||||
|
||||
#ifdef BMW_I3_BATTERY
|
||||
#include "BMW-I3-BATTERY.h"
|
||||
|
@ -79,7 +78,7 @@
|
|||
#include "SERIAL-LINK-RECEIVER-FROM-BATTERY.h"
|
||||
#endif
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame);
|
||||
void receive_can_battery(CAN_frame rx_frame);
|
||||
#ifdef CAN_FD
|
||||
void receive_canfd_battery(CANFDMessage frame);
|
||||
#endif
|
||||
|
@ -90,7 +89,7 @@ void setup_battery(void);
|
|||
|
||||
#ifdef DOUBLE_BATTERY
|
||||
void update_values_battery2();
|
||||
void receive_can_battery2(CAN_frame_t rx_frame);
|
||||
void receive_can_battery2(CAN_frame rx_frame);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -326,8 +326,7 @@ static uint8_t battery2_soh = 99;
|
|||
static uint8_t message_data[50];
|
||||
static uint8_t next_data = 0;
|
||||
|
||||
template <typename T> // Works on both our own CAN implementation, and on miwagner format
|
||||
static uint8_t calculateCRC(T rx_frame, uint8_t length, uint8_t initial_value) {
|
||||
static uint8_t calculateCRC(CAN_frame rx_frame, uint8_t length, uint8_t initial_value) {
|
||||
uint8_t crc = initial_value;
|
||||
for (uint8_t j = 1; j < length; j++) { //start at 1, since 0 is the CRC
|
||||
crc = crc8_table[(crc ^ static_cast<uint8_t>(rx_frame.data.u8[j])) % 256];
|
||||
|
@ -483,8 +482,8 @@ void update_values_battery() { //This function maps all the values fetched via
|
|||
#endif
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
receive_can_battery(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x112: //BMS [10ms] Status Of High-Voltage Battery - 2
|
||||
battery_awake = true;
|
||||
datalayer.battery.status.CAN_battery_still_alive =
|
||||
|
@ -524,7 +523,7 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
break;
|
||||
case 0x2BD: //BMS [100ms] Status diagnosis high voltage - 1
|
||||
battery_awake = true;
|
||||
if (calculateCRC(rx_frame, rx_frame.FIR.B.DLC, 0x15) != rx_frame.data.u8[0]) {
|
||||
if (calculateCRC(rx_frame, rx_frame.DLC, 0x15) != rx_frame.data.u8[0]) {
|
||||
//If calculated CRC does not match transmitted CRC, increase CANerror counter
|
||||
datalayer.battery.status.CAN_error_counter++;
|
||||
break;
|
||||
|
@ -599,17 +598,17 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
battery_ID2 = rx_frame.data.u8[0];
|
||||
break;
|
||||
case 0x607: //BMS - responses to message requests on 0x615
|
||||
if (rx_frame.FIR.B.DLC > 6 && next_data == 0 && rx_frame.data.u8[0] == 0xf1) {
|
||||
if (rx_frame.DLC > 6 && next_data == 0 && rx_frame.data.u8[0] == 0xf1) {
|
||||
uint8_t count = 6;
|
||||
while (count < rx_frame.FIR.B.DLC && next_data < 49) {
|
||||
while (count < rx_frame.DLC && next_data < 49) {
|
||||
message_data[next_data++] = rx_frame.data.u8[count++];
|
||||
}
|
||||
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 &&
|
||||
} else if (rx_frame.DLC > 3 && next_data > 0 && rx_frame.data.u8[0] == 0xf1 &&
|
||||
((rx_frame.data.u8[1] & 0xF0) == 0x20)) {
|
||||
uint8_t count = 2;
|
||||
while (count < rx_frame.FIR.B.DLC && next_data < 49) {
|
||||
while (count < rx_frame.DLC && next_data < 49) {
|
||||
message_data[next_data++] = rx_frame.data.u8[count++];
|
||||
}
|
||||
|
||||
|
@ -647,7 +646,7 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
}
|
||||
}
|
||||
void receive_can_battery2(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x112: //BMS [10ms] Status Of High-Voltage Battery - 2
|
||||
battery2_awake = true;
|
||||
datalayer.battery2.status.CAN_battery_still_alive =
|
||||
|
@ -688,7 +687,7 @@ void receive_can_battery2(CAN_frame_t rx_frame) {
|
|||
break;
|
||||
case 0x2BD: //BMS [100ms] Status diagnosis high voltage - 1
|
||||
battery2_awake = true;
|
||||
if (calculateCRC(rx_frame, rx_frame.FIR.B.DLC, 0x15) != rx_frame.data.u8[0]) {
|
||||
if (calculateCRC(rx_frame, rx_frame.DLC, 0x15) != rx_frame.data.u8[0]) {
|
||||
//If calculated CRC does not match transmitted CRC, increase CANerror counter
|
||||
datalayer.battery2.status.CAN_error_counter++;
|
||||
break;
|
||||
|
@ -768,17 +767,17 @@ void receive_can_battery2(CAN_frame_t rx_frame) {
|
|||
battery2_ID2 = rx_frame.data.u8[0];
|
||||
break;
|
||||
case 0x607: //BMS - responses to message requests on 0x615
|
||||
if (rx_frame.FIR.B.DLC > 6 && next_data == 0 && rx_frame.data.u8[0] == 0xf1) {
|
||||
if (rx_frame.DLC > 6 && next_data == 0 && rx_frame.data.u8[0] == 0xf1) {
|
||||
uint8_t count2 = 6;
|
||||
while (count2 < rx_frame.FIR.B.DLC && next_data < 49) {
|
||||
while (count2 < rx_frame.DLC && next_data < 49) {
|
||||
message_data[next_data++] = rx_frame.data.u8[count2++];
|
||||
}
|
||||
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 &&
|
||||
} else if (rx_frame.DLC > 3 && next_data > 0 && rx_frame.data.u8[0] == 0xf1 &&
|
||||
((rx_frame.data.u8[1] & 0xF0) == 0x20)) {
|
||||
uint8_t count2 = 2;
|
||||
while (count2 < rx_frame.FIR.B.DLC && next_data < 49) {
|
||||
while (count2 < rx_frame.DLC && next_data < 49) {
|
||||
message_data[next_data++] = rx_frame.data.u8[count2++];
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define BMW_I3_BATTERY_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
|
||||
|
|
|
@ -130,10 +130,10 @@ void update_values_battery() { //This function maps all the values fetched via
|
|||
#endif
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
receive_can_battery(CAN_frame rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.MsgID) { //Log values taken with 422V from battery
|
||||
case 0x244: //00,00,00,04,41,0F,20,8B - Static, values never changes between logs
|
||||
switch (rx_frame.ID) { //Log values taken with 422V from battery
|
||||
case 0x244: //00,00,00,04,41,0F,20,8B - Static, values never changes between logs
|
||||
break;
|
||||
case 0x245: //01,00,02,19,3A,25,90,F4 Seems to have a mux in frame0
|
||||
//02,00,90,01,79,79,90,EA // Point of interest, went from 7E,75 to 7B,7C when discharging
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define ATTO_3_BATTERY_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
#define MAX_CELL_DEVIATION_MV 150
|
||||
|
|
|
@ -367,15 +367,15 @@ inline void process_vehicle_vendor_ID(CAN_frame_t rx_frame) {
|
|||
((rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2]); //Actually more bytes, but not needed for our purpose
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
receive_can_battery(CAN_frame rx_frame) {
|
||||
#ifdef CH_CAN_DEBUG
|
||||
Serial.print(millis()); // Example printout, time, ID, length, data: 7553 1DB 8 FF C0 B9 EA 0 0 2 5D
|
||||
Serial.print(" ");
|
||||
Serial.print(rx_frame.MsgID, HEX);
|
||||
Serial.print(rx_frame.ID, HEX);
|
||||
Serial.print(" ");
|
||||
Serial.print(rx_frame.FIR.B.DLC);
|
||||
Serial.print(rx_frame.DLC);
|
||||
Serial.print(" ");
|
||||
for (int i = 0; i < rx_frame.FIR.B.DLC; ++i) {
|
||||
for (int i = 0; i < rx_frame.DLC; ++i) {
|
||||
Serial.print(rx_frame.data.u8[i], HEX);
|
||||
Serial.print(" ");
|
||||
}
|
||||
|
@ -384,7 +384,7 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
|
||||
// CHADEMO coexists with a CAN-based shunt. Only process CHADEMO-specific IDs
|
||||
// 202 is unknown
|
||||
if (!((rx_frame.MsgID >= 0x100 && rx_frame.MsgID <= 0x202) || rx_frame.MsgID == 0x700)) {
|
||||
if (!((rx_frame.ID >= 0x100 && rx_frame.ID <= 0x202) || rx_frame.ID == 0x700)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -397,7 +397,7 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
datalayer.battery.status.CAN_battery_still_alive =
|
||||
CAN_STILL_ALIVE; //We are getting CAN messages from the vehicle, inform the watchdog
|
||||
|
||||
switch (rx_frame.MsgID) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x100:
|
||||
process_vehicle_charging_minimums(rx_frame);
|
||||
break;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define CHADEMO_BATTERY_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
#define MAX_CELL_DEVIATION_MV 9999
|
||||
|
|
|
@ -133,8 +133,8 @@ void update_values_battery() { //This function maps all the values fetched via
|
|||
#endif
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
receive_can_battery(CAN_frame rx_frame) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x374: //BMU message, 10ms - SOC
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
temp_value = ((rx_frame.data.u8[1] - 10) / 2);
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define IMIEV_CZERO_ION_BATTERY_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
#define MAX_CELL_DEVIATION_MV 500
|
||||
|
|
|
@ -120,7 +120,7 @@ void update_values_battery() {
|
|||
#endif
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
receive_can_battery(CAN_frame rx_frame) {
|
||||
|
||||
// Do not log noisy startup messages - there are many !
|
||||
if (rx_frame.MsgID == 0 && rx_frame.FIR.B.DLC == 8 && rx_frame.data.u8[0] == 0 && rx_frame.data.u8[1] == 0 &&
|
||||
|
@ -129,7 +129,7 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
return;
|
||||
}
|
||||
|
||||
switch (rx_frame.MsgID) { // These messages are periodically transmitted by the battery
|
||||
switch (rx_frame.ID) { // These messages are periodically transmitted by the battery
|
||||
case 0x080:
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
HVBatteryContactorStatus = ((rx_frame.data.u8[0] & 0x80) >> 7);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#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 ?
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#ifdef KIA_E_GMP_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 "../lib/pierremolinaro-ACAN2517FD/ACAN2517FD.h"
|
||||
#include "KIA-E-GMP-BATTERY.h"
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define KIA_E_GMP_BATTERY_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "../lib/pierremolinaro-ACAN2517FD/ACAN2517FD.h"
|
||||
|
||||
extern ACAN2517FD canfd;
|
||||
|
|
|
@ -233,8 +233,8 @@ void update_number_of_cells() {
|
|||
}
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
receive_can_battery(CAN_frame rx_frame) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x4DE:
|
||||
startedUp = true;
|
||||
break;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define KIA_HYUNDAI_64_BATTERY_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
#define MAX_CELL_DEVIATION_MV 150
|
||||
|
|
|
@ -90,9 +90,9 @@ void update_values_battery() { //This function maps all the values fetched via
|
|||
}
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
receive_can_battery(CAN_frame rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.MsgID) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x5F1:
|
||||
break;
|
||||
case 0x51E:
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define KIA_HYUNDAI_HYBRID_BATTERY_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
#define MAX_CELL_DEVIATION_MV 100
|
||||
|
|
|
@ -50,9 +50,9 @@ void update_values_battery() { //This function maps all the values fetched via
|
|||
#endif
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
receive_can_battery(CAN_frame rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.MsgID) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x171: //Following messages were detected on a MG5 battery BMS
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; // Let system know battery is sending CAN
|
||||
break;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define MG_5_BATTERY_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
#define MAX_CELL_DEVIATION_MV 150
|
||||
|
|
|
@ -468,8 +468,8 @@ void update_values_battery2() { // Handle the values coming in from battery #2
|
|||
}
|
||||
}
|
||||
}
|
||||
void receive_can_battery2(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
void receive_can_battery2(CAN_frame rx_frame) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x1DB:
|
||||
if (is_message_corrupt(rx_frame)) {
|
||||
datalayer.battery2.status.CAN_error_counter++;
|
||||
|
@ -720,8 +720,8 @@ void receive_can_battery2(CAN_frame_t rx_frame) {
|
|||
}
|
||||
#endif // DOUBLE_BATTERY
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
void receive_can_battery(CAN_frame rx_frame) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x1DB:
|
||||
if (is_message_corrupt(rx_frame)) {
|
||||
datalayer.battery.status.CAN_error_counter++;
|
||||
|
@ -1176,7 +1176,7 @@ void send_can_battery() {
|
|||
}
|
||||
}
|
||||
|
||||
bool is_message_corrupt(CAN_frame_t rx_frame) {
|
||||
bool is_message_corrupt(CAN_frame rx_frame) {
|
||||
uint8_t crc = 0;
|
||||
for (uint8_t j = 0; j < 7; j++) {
|
||||
crc = crctable[(crc ^ static_cast<uint8_t>(rx_frame.data.u8[j])) % 256];
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
#define NISSAN_LEAF_BATTERY_H
|
||||
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
#define MAX_CELL_DEVIATION_MV 500
|
||||
|
||||
uint16_t Temp_fromRAW_to_F(uint16_t temperature);
|
||||
bool is_message_corrupt(CAN_frame_t rx_frame);
|
||||
bool is_message_corrupt(CAN_frame rx_frame);
|
||||
void setup_battery(void);
|
||||
void transmit_can(CAN_frame* tx_frame, int interface);
|
||||
|
||||
|
|
|
@ -80,9 +80,9 @@ void update_values_battery() {
|
|||
datalayer.battery.info.min_design_voltage_dV = discharge_cutoff_voltage;
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
receive_can_battery(CAN_frame rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.MsgID) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x7310:
|
||||
case 0x7311:
|
||||
ensemble_info_ack = true;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define PYLON_BATTERY_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
#define MAX_CELL_DEVIATION_MV 9999
|
||||
|
|
|
@ -147,9 +147,9 @@ void update_values_battery() { //This function maps all the values fetched via
|
|||
#endif
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
receive_can_battery(CAN_frame rx_frame) {
|
||||
|
||||
switch (rx_frame.MsgID) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x155: //BMS1
|
||||
datalayer.battery.status.CAN_battery_still_alive =
|
||||
CAN_STILL_ALIVE; //Indicate that we are still getting CAN messages from the BMS
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define RENAULT_KANGOO_BATTERY_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
|
||||
|
|
|
@ -73,9 +73,9 @@ void update_values_battery() { //This function maps all the values fetched via
|
|||
#endif
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
receive_can_battery(CAN_frame rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.MsgID) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x427:
|
||||
LB_Charge_Power_W = rx_frame.data.u8[5] * 300;
|
||||
LB_kWh_Remaining = (((((rx_frame.data.u8[6] << 8) | (rx_frame.data.u8[7])) >> 6) & 0x3ff) * 0.1);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef RENAULT_ZOE_GEN1_BATTERY_H
|
||||
#define RENAULT_ZOE_GEN1_BATTERY_H
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
|
||||
|
|
|
@ -71,9 +71,9 @@ void update_values_battery() { //This function maps all the values fetched via
|
|||
#endif
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
receive_can_battery(CAN_frame rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.MsgID) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x18daf1db: // LBC Reply from active polling
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef RENAULT_ZOE_GEN2_BATTERY_H
|
||||
#define RENAULT_ZOE_GEN2_BATTERY_H
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
|
||||
|
|
|
@ -106,8 +106,8 @@ void update_values_battery() { //This function maps all the values fetched via
|
|||
#endif
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
receive_can_battery(CAN_frame rx_frame) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x1FF:
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
StatusBattery = (rx_frame.data.u8[0] & 0x0F);
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define SANTA_FE_PHEV_BATTERY_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
#define MAX_CELL_DEVIATION_MV 250
|
||||
|
|
|
@ -444,11 +444,11 @@ void update_values_battery() { //This function maps all the values fetched via
|
|||
#endif //DEBUG_VIA_USB
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
receive_can_battery(CAN_frame rx_frame) {
|
||||
static uint8_t mux = 0;
|
||||
static uint16_t temp = 0;
|
||||
|
||||
switch (rx_frame.MsgID) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x352:
|
||||
//SOC
|
||||
battery_nominal_full_pack_energy =
|
||||
|
@ -644,11 +644,11 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
|
||||
#ifdef DOUBLE_BATTERY
|
||||
|
||||
void receive_can_battery2(CAN_frame_t rx_frame) {
|
||||
void receive_can_battery2(CAN_frame rx_frame) {
|
||||
static uint8_t mux = 0;
|
||||
static uint16_t temp = 0;
|
||||
|
||||
switch (rx_frame.MsgID) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x352:
|
||||
//SOC
|
||||
battery2_nominal_full_pack_energy =
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef TESLA_MODEL_3_BATTERY_H
|
||||
#define TESLA_MODEL_3_BATTERY_H
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
|
||||
|
|
|
@ -71,16 +71,16 @@ void update_values_battery() { /* This function puts fake values onto the parame
|
|||
#endif
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
receive_can_battery(CAN_frame rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
// All CAN messages recieved will be logged via serial
|
||||
Serial.print(millis()); // Example printout, time, ID, length, data: 7553 1DB 8 FF C0 B9 EA 0 0 2 5D
|
||||
Serial.print(" ");
|
||||
Serial.print(rx_frame.MsgID, HEX);
|
||||
Serial.print(rx_frame.ID, HEX);
|
||||
Serial.print(" ");
|
||||
Serial.print(rx_frame.FIR.B.DLC);
|
||||
Serial.print(rx_frame.DLC);
|
||||
Serial.print(" ");
|
||||
for (int i = 0; i < rx_frame.FIR.B.DLC; ++i) {
|
||||
for (int i = 0; i < rx_frame.DLC; ++i) {
|
||||
Serial.print(rx_frame.data.u8[i], HEX);
|
||||
Serial.print(" ");
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef TEST_FAKE_BATTERY_H
|
||||
#define TEST_FAKE_BATTERY_H
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
#define MAX_CELL_DEVIATION_MV 9999
|
||||
|
|
|
@ -144,9 +144,9 @@ void update_values_battery() { //This function maps all the values fetched via
|
|||
#endif
|
||||
}
|
||||
|
||||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
receive_can_battery(CAN_frame_t rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.MsgID) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x3A:
|
||||
if ((rx_frame.data.u8[6] & 0x80) == 0x80)
|
||||
BATT_I = (0 - ((((rx_frame.data.u8[6] & 0x7F) * 256.0 + rx_frame.data.u8[7]) * 0.1) - 1638));
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define VOLVO_SPA_BATTERY_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define BATTERY_SELECTED
|
||||
#define MAX_CELL_DEVIATION_MV 250
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef CHARGERS_H
|
||||
#define CHARGERS_H
|
||||
#include "../../USER_SETTINGS.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" // This include is annoying, consider defining a frame type in types.h
|
||||
|
||||
#ifdef CHEVYVOLT_CHARGER
|
||||
#include "CHEVY-VOLT-CHARGER.h"
|
||||
|
@ -11,7 +10,7 @@
|
|||
#include "NISSAN-LEAF-CHARGER.h"
|
||||
#endif
|
||||
|
||||
void receive_can_charger(CAN_frame_t rx_frame);
|
||||
void receive_can_charger(CAN_frame rx_frame);
|
||||
void send_can_charger();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -64,7 +64,7 @@ void receive_can_charger(CAN_frame_t rx_frame) {
|
|||
uint16_t charger_stat_ACcur_temp = 0;
|
||||
uint16_t charger_stat_ACvol_temp = 0;
|
||||
|
||||
switch (rx_frame.MsgID) {
|
||||
switch (rx_frame.ID) {
|
||||
//ID 0x212 conveys instantaneous DC charger stats
|
||||
case 0x212:
|
||||
charger_stat_HVcur_temp = (uint16_t)(rx_frame.data.u8[0] << 8 | rx_frame.data.u8[1]);
|
||||
|
|
|
@ -129,9 +129,9 @@ static uint8_t calculate_checksum_nibble(CAN_frame* frame) {
|
|||
return sum;
|
||||
}
|
||||
|
||||
void receive_can_charger(CAN_frame_t rx_frame) {
|
||||
void receive_can_charger(CAN_frame rx_frame) {
|
||||
|
||||
switch (rx_frame.MsgID) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x679: // This message fires once when charging cable is plugged in
|
||||
OBCwakeup = true;
|
||||
charger_aux12V_enabled = true; //Not possible to turn off 12V charging
|
||||
|
|
|
@ -177,8 +177,8 @@ void update_values_can_inverter() { //This function maps all the values fetched
|
|||
#endif
|
||||
}
|
||||
|
||||
void receive_can_inverter(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
void receive_can_inverter(CAN_frame rx_frame) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x151: //Message originating from BYD HVS compatible inverter. Reply with CAN identifier!
|
||||
if (rx_frame.data.u8[0] & 0x01) { //Battery requests identification
|
||||
send_intial_data();
|
||||
|
|
|
@ -40,9 +40,8 @@
|
|||
#endif
|
||||
|
||||
#ifdef CAN_INVERTER_SELECTED
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" // This include is annoying, consider defining a frame type in types.h
|
||||
void update_values_can_inverter();
|
||||
void receive_can_inverter(CAN_frame_t rx_frame);
|
||||
void receive_can_inverter(CAN_frame rx_frame);
|
||||
void send_can_inverter();
|
||||
#endif
|
||||
|
||||
|
|
|
@ -436,7 +436,7 @@ void update_values_can_inverter() { //This function maps all the values fetched
|
|||
}
|
||||
|
||||
void receive_can_inverter(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x4200: //Message originating from inverter. Depending on which data is required, act accordingly
|
||||
if (rx_frame.data.u8[0] == 0x02) {
|
||||
send_setup_info();
|
||||
|
|
|
@ -202,8 +202,8 @@ void update_values_can_inverter() { //This function maps all the values fetched
|
|||
*/
|
||||
}
|
||||
|
||||
void receive_can_inverter(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
void receive_can_inverter(CAN_frame rx_frame) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x360: //Message originating from SMA inverter - Voltage and current
|
||||
//Frame0-1 Voltage
|
||||
//Frame2-3 Current
|
||||
|
|
|
@ -289,8 +289,8 @@ void update_values_can_inverter() { //This function maps all the values fetched
|
|||
//SMA_018.data.u8[7] = BatteryName;
|
||||
}
|
||||
|
||||
void receive_can_inverter(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
void receive_can_inverter(CAN_frame rx_frame) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x00D: //Inverter Measurements
|
||||
break;
|
||||
case 0x00F: //Inverter Feedback
|
||||
|
|
|
@ -230,8 +230,8 @@ void update_values_can_inverter() { //This function maps all the values fetched
|
|||
SOFAR_356.data.u8[3] = (datalayer.battery.status.temperature_max_dC & 0x00FF);
|
||||
}
|
||||
|
||||
void receive_can_inverter(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) { //In here we need to respond to the inverter. TODO: make logic
|
||||
void receive_can_inverter(CAN_frame rx_frame) {
|
||||
switch (rx_frame.ID) { //In here we need to respond to the inverter. TODO: make logic
|
||||
case 0x605:
|
||||
//frame1_605 = rx_frame.data.u8[1];
|
||||
//frame3_605 = rx_frame.data.u8[3];
|
||||
|
|
|
@ -16,90 +16,62 @@ static uint16_t capped_remaining_capacity_Wh;
|
|||
|
||||
//CAN message translations from this amazing repository: https://github.com/rand12345/solax_can_bus
|
||||
|
||||
CAN_frame_t SOLAX_1801 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_ext,
|
||||
}},
|
||||
.MsgID = 0x1801,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}};
|
||||
CAN_frame_t SOLAX_1872 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_ext,
|
||||
}},
|
||||
.MsgID = 0x1872,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; //BMS_Limits
|
||||
CAN_frame_t SOLAX_1873 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_ext,
|
||||
}},
|
||||
.MsgID = 0x1873,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; //BMS_PackData
|
||||
CAN_frame_t SOLAX_1874 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_ext,
|
||||
}},
|
||||
.MsgID = 0x1874,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; //BMS_CellData
|
||||
CAN_frame_t SOLAX_1875 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_ext,
|
||||
}},
|
||||
.MsgID = 0x1875,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; //BMS_Status
|
||||
CAN_frame_t SOLAX_1876 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_ext,
|
||||
}},
|
||||
.MsgID = 0x1876,
|
||||
.data = {0x0, 0x0, 0xE2, 0x0C, 0x0, 0x0, 0xD7, 0x0C}}; //BMS_PackTemps
|
||||
CAN_frame_t SOLAX_1877 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_ext,
|
||||
}},
|
||||
.MsgID = 0x1877,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}};
|
||||
CAN_frame_t SOLAX_1878 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_ext,
|
||||
}},
|
||||
.MsgID = 0x1878,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; //BMS_PackStats
|
||||
CAN_frame_t SOLAX_1879 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_ext,
|
||||
}},
|
||||
.MsgID = 0x1879,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}};
|
||||
CAN_frame_t SOLAX_1881 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_ext,
|
||||
}},
|
||||
.MsgID = 0x1881,
|
||||
.data = {0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; // E.g.: 0 6 S B M S F A
|
||||
CAN_frame_t SOLAX_1882 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_ext,
|
||||
}},
|
||||
.MsgID = 0x1882,
|
||||
.data = {0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; // E.g.: 0 2 3 A B 0 5 2
|
||||
CAN_frame_t SOLAX_100A001 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 0,
|
||||
.FF = CAN_frame_ext,
|
||||
}},
|
||||
.MsgID = 0x100A001,
|
||||
.data = {}};
|
||||
CAN_frame SOLAX_1801 = {.FD = false,
|
||||
.ext_ID = true,
|
||||
.DLC = 8,
|
||||
.ID = 0x1801,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}};
|
||||
CAN_frame SOLAX_1872 = {.FD = false,
|
||||
.ext_ID = true,
|
||||
.DLC = 8,
|
||||
.ID = 0x1872,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; //BMS_Limits
|
||||
CAN_frame SOLAX_1873 = {.FD = false,
|
||||
.ext_ID = true,
|
||||
.DLC = 8,
|
||||
.ID = 0x1873,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; //BMS_PackData
|
||||
CAN_frame SOLAX_1874 = {.FD = false,
|
||||
.ext_ID = true,
|
||||
.DLC = 8,
|
||||
.ID = 0x1874,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; //BMS_CellData
|
||||
CAN_frame SOLAX_1875 = {.FD = false,
|
||||
.ext_ID = true,
|
||||
.DLC = 8,
|
||||
.ID = 0x1875,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; //BMS_Status
|
||||
CAN_frame SOLAX_1876 = {.FD = false,
|
||||
.ext_ID = true,
|
||||
.DLC = 8,
|
||||
.ID = 0x1876,
|
||||
.data = {0x0, 0x0, 0xE2, 0x0C, 0x0, 0x0, 0xD7, 0x0C}}; //BMS_PackTemps
|
||||
CAN_frame SOLAX_1877 = {.FD = false,
|
||||
.ext_ID = true,
|
||||
.DLC = 8,
|
||||
.ID = 0x1877,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}};
|
||||
CAN_frame SOLAX_1878 = {.FD = false,
|
||||
.ext_ID = true,
|
||||
.DLC = 8,
|
||||
.ID = 0x1878,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; //BMS_PackStats
|
||||
CAN_frame SOLAX_1879 = {.FD = false,
|
||||
.ext_ID = true,
|
||||
.DLC = 8,
|
||||
.ID = 0x1879,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}};
|
||||
CAN_frame SOLAX_1881 = {.FD = false,
|
||||
.ext_ID = true,
|
||||
.DLC = 8,
|
||||
.ID = 0x1881,
|
||||
.data = {0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; // E.g.: 0 6 S B M S F A
|
||||
CAN_frame SOLAX_1882 = {.FD = false,
|
||||
.ext_ID = true,
|
||||
.DLC = 8,
|
||||
.ID = 0x1882,
|
||||
.data = {0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; // E.g.: 0 2 3 A B 0 5 2
|
||||
CAN_frame SOLAX_100A001 = {.FD = false, .ext_ID = true, .DLC = 0, .ID = 0x100A001, .data = {}};
|
||||
|
||||
// __builtin_bswap64 needed to convert to ESP32 little endian format
|
||||
// Byte[4] defines the requested contactor state: 1 = Closed , 0 = Open
|
||||
|
@ -236,9 +208,9 @@ void send_can_inverter() {
|
|||
// No periodic sending used on this protocol, we react only on incoming CAN messages!
|
||||
}
|
||||
|
||||
void receive_can_inverter(CAN_frame_t rx_frame) {
|
||||
if (rx_frame.MsgID == 0x1871 && rx_frame.data.u8[0] == (0x01) ||
|
||||
rx_frame.MsgID == 0x1871 && rx_frame.data.u8[0] == (0x02)) {
|
||||
void receive_can_inverter(CAN_frame rx_frame) {
|
||||
if (rx_frame.ID == 0x1871 && rx_frame.data.u8[0] == (0x01) ||
|
||||
rx_frame.ID == 0x1871 && rx_frame.data.u8[0] == (0x02)) {
|
||||
LastFrameTime = millis();
|
||||
switch (STATE) {
|
||||
case (BATTERY_ANNOUNCE):
|
||||
|
@ -299,14 +271,14 @@ void receive_can_inverter(CAN_frame_t rx_frame) {
|
|||
}
|
||||
}
|
||||
|
||||
if (rx_frame.MsgID == 0x1871 && rx_frame.data.u64 == __builtin_bswap64(0x0500010000000000)) {
|
||||
if (rx_frame.ID == 0x1871 && rx_frame.data.u64 == __builtin_bswap64(0x0500010000000000)) {
|
||||
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
|
||||
}
|
||||
if (rx_frame.MsgID == 0x1871 && rx_frame.data.u8[0] == (0x03)) {
|
||||
if (rx_frame.ID == 0x1871 && rx_frame.data.u8[0] == (0x03)) {
|
||||
#ifdef DEBUG_VIA_USB
|
||||
Serial.println("1871 03-frame received from inverter");
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue