implemented can_hanlde_recieve_command correctly
changed can_handle_send_status
This commit is contained in:
@ -1,24 +1,23 @@
|
||||
#include "state_machine.h"
|
||||
#include "ADBMS_LL_Driver.h"
|
||||
#include "TMP1075.h"
|
||||
#include "common_defs.h"
|
||||
#include <math.h>
|
||||
|
||||
StateHandle state;
|
||||
static bool relay_closed = 0;
|
||||
static bool precharge_closed = 0;
|
||||
static int16_t RELAY_BAT_SIDE_VOLTAGE = 0;
|
||||
static int16_t RELAY_ESC_SIDE_VOLTAGE = 0;
|
||||
static int16_t CURRENT_MEASUREMENT_VOLTAGE = 0;
|
||||
static int16_t timestamp;
|
||||
|
||||
void sm_init(){
|
||||
state.current_state = STATE_INACTIVE;
|
||||
state.target_state = STATE_INACTIVE;
|
||||
state.error_source = 0;
|
||||
RELAY_BAT_SIDE_VOLTAGE = module.auxVoltages[0];
|
||||
RELAY_ESC_SIDE_VOLTAGE = module.auxVoltages[1];
|
||||
CURRENT_MEASUREMENT_VOLTAGE = module.auxVoltages[2];
|
||||
}
|
||||
|
||||
void sm_update(){
|
||||
sm_handle_ams_in();
|
||||
RELAY_BAT_SIDE_VOLTAGE = module.auxVoltages[0];
|
||||
RELAY_ESC_SIDE_VOLTAGE = module.auxVoltages[1];
|
||||
CURRENT_MEASUREMENT_VOLTAGE = module.auxVoltages[2];
|
||||
|
||||
switch (state.current_state) {
|
||||
case STATE_INACTIVE:
|
||||
state.current_state = sm_update_inactive(); // monitor only
|
||||
@ -65,7 +64,7 @@ State sm_update_precharge(){
|
||||
case STATE_INACTIVE: // if CAN Signal 0000 0000 then immidiete shutdown
|
||||
return STATE_DISCHARGE;
|
||||
case STATE_READY:
|
||||
if (RELAY_BAT_SIDE_VOLTAGE == RELAY_ESC_SIDE_VOLTAGE)
|
||||
if (roundf(RELAY_BAT_SIDE_VOLTAGE) == roundf(RELAY_ESC_SIDE_VOLTAGE))
|
||||
return STATE_READY;
|
||||
default:
|
||||
return STATE_PRECHARGE;
|
||||
@ -97,7 +96,7 @@ State sm_update_active(){
|
||||
State sm_update_discharge(){
|
||||
switch (state.target_state) {
|
||||
case STATE_INACTIVE:
|
||||
if (RELAY_ESC_SIDE_VOLTAGE == 0)
|
||||
if (RELAY_ESC_SIDE_VOLTAGE < 12)
|
||||
return STATE_INACTIVE;
|
||||
case STATE_PRECHARGE: // if CAN Signal 1000 0000 then get ready
|
||||
return STATE_PRECHARGE;
|
||||
@ -182,9 +181,23 @@ void sm_set_relay(Relay relay, bool closed){
|
||||
}
|
||||
}
|
||||
|
||||
void sm_handle_ams_in(){
|
||||
uint8_t data[2] = {};
|
||||
can_handle_recieve_command(&data);
|
||||
|
||||
void sm_check_charging(){
|
||||
if (RELAY_BAT_SIDE_VOLTAGE < RELAY_ESC_SIDE_VOLTAGE && timestamp == 0)
|
||||
timestamp = HAL_GetTick() + 5000;
|
||||
if (timestamp < HAL_GetTick())
|
||||
state.target_state = STATE_CHARGING_PRECHARGE;
|
||||
}
|
||||
|
||||
void sm_check_cell_temps(int8_t *id, int16_t *temp){
|
||||
for (int i = 0; i < N_TEMP_SENSORS; i++) {
|
||||
if (tmp1075_temps[i] > *temp){
|
||||
*id = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sm_handle_ams_in(const uint8_t *data){
|
||||
switch (data[0]) {
|
||||
case 0b00000000:
|
||||
if (state.current_state != STATE_INACTIVE){
|
||||
@ -210,6 +223,7 @@ void sm_handle_ams_in(){
|
||||
|
||||
void sm_set_error(ErrorKind error_kind, bool is_errored){}
|
||||
|
||||
#warning TODO: add error checking for everything here
|
||||
void sm_check_errors(){
|
||||
if (module.status.THSD == 1) {
|
||||
state.error_type.bms_overtemp = 1;
|
||||
@ -218,10 +232,3 @@ void sm_check_errors(){
|
||||
state.error_source = (1 << 10);
|
||||
}
|
||||
}
|
||||
|
||||
void sm_charging_check(){
|
||||
if (RELAY_BAT_SIDE_VOLTAGE < RELAY_ESC_SIDE_VOLTAGE && timestamp == 0)
|
||||
timestamp = HAL_GetTick() + 5000;
|
||||
if (timestamp < HAL_GetTick())
|
||||
state.target_state = STATE_CHARGING_PRECHARGE;
|
||||
}
|
||||
Reference in New Issue
Block a user