added sm_get_state_code(), added more ErrorKinds

This commit is contained in:
Hamza
2024-05-24 15:20:23 +02:00
parent fe3bcb6ebb
commit 6f26e46e51
2 changed files with 46 additions and 17 deletions

View File

@ -16,7 +16,7 @@
// Time to wait between closing relays
#define RELAY_CLOSE_WAIT 10 // ms
typedef enum { // valid transitions: (all could transition to error)
typedef enum { // 7 states -> 3 bit. valid transitions: (all could transition to error)
STATE_INACTIVE, // INACTIVE -> PRECHARGE, CHARGING, ERROR
STATE_PRECHARGE, // PRECHARGE -> INACTIVE, READY, DISCHARGE, ERROR
STATE_READY, // READY -> ACTIVE, DISCHARGE, ERROR
@ -26,16 +26,23 @@ typedef enum { // valid transitions: (all could transition to error)
STATE_ERROR, // ERROR -> INACTIVE, DISCHARGE, ERROR
} State;
typedef struct {
typedef struct { // 13 errors -> 4 bit
uint16_t bms_timeout : 1;
uint16_t overtemp : 1;
uint16_t overcurrent : 1;
uint16_t overvoltage : 1;
uint16_t missing_current_reading : 1;
uint16_t missing_voltage_reading : 1;
uint16_t missing_temp_reading : 1;
uint16_t precharge_fail : 1;
uint16_t powerground_fail : 1;
uint16_t bms_checksum_fail : 1;
uint16_t bms_overtemp : 1;
uint16_t bms_fault : 1;
uint16_t temperature_error : 1;
uint16_t current_error : 1;
uint16_t voltage_error : 1;
uint16_t temperature_sensor_missing : 1;
uint16_t current_sensor_missing : 1;
uint16_t voltage_missing : 1;
uint16_t relay_missing : 1;
uint16_t state_fail : 1;
uint16_t state_transition_fail : 1;
} ErrorKind;
//typedef enum {} WarningKind;
@ -51,6 +58,7 @@ extern StateHandle state;
void sm_init();
void sm_update();
int sm_get_state_code();
State sm_update_inactive();
State sm_update_precharge();
@ -65,6 +73,8 @@ void sm_set_relay_positions(State state);
void sm_set_relay(Relay relay, bool closed);
void sm_check_precharge_discharge(int *is_closed, int should_close);
void sm_check_errors();
void sm_handle_ams_in(const uint8_t *data);
void sm_set_error(ErrorKind error_kind, bool is_errored);