Skip to content

Commit

Permalink
Fix bms_status handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dalathegreat committed Sep 15, 2023
1 parent bcde54c commit b1ee3ae
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions Software/TESLA-MODEL-3-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
#include "CAN_config.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
static unsigned long previousMillis30 = 0; // will store last time a 30ms CAN Message was send
static unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was send
static const int interval10 = 10; // interval (ms) at which send CAN Messages
static const int interval30 = 30; // interval (ms) at which send CAN Messages
static const int interval100 = 100; // interval (ms) at which send CAN Messages
static uint8_t stillAliveCAN = 6; //counter for checking if CAN is still alive

CAN_frame_t TESLA_221_1 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_std,}},.MsgID = 0x221,.data = {0x41, 0x11, 0x01, 0x00, 0x00, 0x00, 0x20, 0x96}};
CAN_frame_t TESLA_221_2 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_std,}},.MsgID = 0x221,.data = {0x61, 0x15, 0x01, 0x00, 0x00, 0x00, 0x20, 0xBA}};
static uint8_t alternate221 = 0;

static uint32_t total_discharge = 0;
static uint32_t total_charge = 0;
Expand Down Expand Up @@ -98,6 +93,8 @@ void update_values_tesla_model_3_battery()
max_temp = (max_temp * 10);
temperature_max = convert2unsignedint16(max_temp);

bms_status = ACTIVE; //Startout in active mode before checking if we have any faults

/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
if(!stillAliveCAN)
{
Expand Down Expand Up @@ -291,29 +288,13 @@ void receive_can_tesla_model_3_battery(CAN_frame_t rx_frame)
void send_can_tesla_model_3_battery()
{
unsigned long currentMillis = millis();
// Send 100ms CAN Message
if (currentMillis - previousMillis100 >= interval100)
{
previousMillis100 = currentMillis;

//ESP32Can.CANWriteFrame(&message100);

}
//Send 30ms message
if (currentMillis - previousMillis30 >= interval30)
{
previousMillis30 = currentMillis;

if(bms_status != FAULT){
ESP32Can.CANWriteFrame(&TESLA_221_1);

ESP32Can.CANWriteFrame(&TESLA_221_2);

}
//Send 10ms message
if (currentMillis - previousMillis10 >= interval10)
{
previousMillis10 = currentMillis;

//ESP32Can.CANWriteFrame(&message10);
}
}
}

0 comments on commit b1ee3ae

Please sign in to comment.