From 1642627dd2e36a98832478ae16dd69cfb77f9f27 Mon Sep 17 00:00:00 2001 From: hamza Date: Thu, 23 May 2024 19:08:46 +0300 Subject: [PATCH] updated the state machine --- Core/Inc/state_machine.h | 6 +++--- Core/Src/state_machine.c | 23 ++++++++++------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Core/Inc/state_machine.h b/Core/Inc/state_machine.h index 478c6a6..a7d422e 100644 --- a/Core/Inc/state_machine.h +++ b/Core/Inc/state_machine.h @@ -54,12 +54,12 @@ void sm_init(); void sm_update(); State sm_update_inactive(); -State sm_update_active(); State sm_update_precharge(); +State sm_update_ready(); +State sm_update_active(); State sm_update_discharge(); -State sm_update_error(); -State sm_update_charging_check(); State sm_update_charging(); +State sm_update_error(); typedef enum { RELAY_POS, RELAY_PRECHARGE } Relay; void sm_set_relay_positions(State state); diff --git a/Core/Src/state_machine.c b/Core/Src/state_machine.c index 3aa8808..24a48dc 100644 --- a/Core/Src/state_machine.c +++ b/Core/Src/state_machine.c @@ -16,39 +16,35 @@ void sm_update(){ switch (state.current_state) { case INACTIVE: - //state.current_state = sm_update_inactive(); moniter only + state.current_state = sm_update_inactive(); // moniter only break; case PRECHARGE: - //state.current_state = sm_update_precharge(); set PRECHARGE and turn on cooling at 50% or such + state.current_state = sm_update_precharge(); // set PRECHARGE and turn on cooling at 50% or such break; case READY: - //state.current_state = ; keep cooling at 50%, get ready to turn on powerground + state.current_state = sm_update_ready(); // keep cooling at 50%, get ready to turn on powerground break; case ACTIVE: - //state.current_state = sm_update_precharge(); set PRECHARGE and turn on cooling at 50% or such + state.current_state = sm_update_active(); // set PRECHARGE and turn on cooling at 50% or such break; case DISCHARGE: - //state.current_state = sm_update_discharge(); // open the main relay, keep PRECHARGE closed + state.current_state = sm_update_discharge(); // open the main relay, keep PRECHARGE closed break; case CHARGING: - //state.current_state = sm_update_charging(); // turn on cooling if needed, + state.current_state = sm_update_charging(); // turn on cooling if needed, break; case ERROR: - //state.current_state = sm_update_error(); // enter the correct ERROR state - break; - case WARNING: - //state.current_state = sm_update_error(); // send warnings through CAN + state.current_state = sm_update_error(); // enter the correct ERROR state break; } sm_set_relay_positions(state.current_state); - status_led_state(state.current_state, (ErrorKind) state.error_type); + //status_led_state(state.current_state, (ErrorKind) state.error_type); } State sm_update_inactive(){ switch (state.target_state) { case PRECHARGE: - if () break; case CHARGING: break; @@ -121,7 +117,7 @@ State sm_update_error(){ void sm_set_relay_positions(State state){ return; } - +/* void sm_set_relay(Relay relay, int closed){ static int closed = 0; static int precharge_closed = 0; @@ -138,6 +134,7 @@ void sm_set_relay(Relay relay, int closed){ break; } } +*/ //void sm_check_close_wait(int *is_closed, int should_close);