From 55a623efd55a070a840fec0b25cb0808f0677147 Mon Sep 17 00:00:00 2001 From: Akashem06 Date: Tue, 12 Mar 2024 17:57:01 +0000 Subject: [PATCH] small changes in syntax --- projects/bms_carrier/src/main.c | 4 ++-- projects/bms_carrier/src/relays_fsm.c | 21 +++++++++------------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/projects/bms_carrier/src/main.c b/projects/bms_carrier/src/main.c index 5079d77c0..1ae5863bb 100644 --- a/projects/bms_carrier/src/main.c +++ b/projects/bms_carrier/src/main.c @@ -35,7 +35,7 @@ static const CanSettings can_settings = { void pre_loop_init() { LOG_DEBUG("Welcome to BMS \n"); init_bms_relays(); - bms_fan_init(); + // bms_fan_init(); } void run_fast_cycle() {} @@ -47,7 +47,7 @@ void run_medium_cycle() { fsm_run_cycle(bms_relays); wait_tasks(1); - bms_run_fan(); + // bms_run_fan(); run_can_tx_cycle(); wait_tasks(1); diff --git a/projects/bms_carrier/src/relays_fsm.c b/projects/bms_carrier/src/relays_fsm.c index 7ab9e5689..cff96c006 100644 --- a/projects/bms_carrier/src/relays_fsm.c +++ b/projects/bms_carrier/src/relays_fsm.c @@ -20,7 +20,7 @@ static const LtcAfeSettings s_afe_settings = { .cell_bitset = { 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF }, .aux_bitset = { 0 }, - .num_devices = 2, + .num_devices = 3, .num_cells = 12, .num_thermistors = 12, }; @@ -86,7 +86,7 @@ static void prv_bms_fault_ok_or_transition(Fsm *fsm) { status |= run_current_sense_cycle(); if (status != STATUS_CODE_OK) { LOG_DEBUG("status (current sense cycle failed): %d\n", status); - set_battery_status_fault(BMS_FAULT_COMMS_LOSS_CURRENT_SENSE); + set_battery_status_fault(BMS_FAULT_COMMS_LOSS_CURR_SENSE); set_battery_status_status(1); fsm_transition(fsm, RELAYS_FAULT); } @@ -136,19 +136,16 @@ static void prv_bms_fault_ok_or_transition(Fsm *fsm) { set_battery_status_status(1); } - switch (min_voltage) { - case min_voltage >= AFE_BALANCING_UPPER_THRESHOLD: - min_voltage += 20; - break; - case min_voltage < AFE_BALANCING_UPPER_THRESHOLD &&min_voltage >= AFE_BALANCING_LOWER_THRESHOLD: + if (min_voltage >= AFE_BALANCING_UPPER_THRESHOLD) { + min_voltage += 20; + } else if (min_voltage < AFE_BALANCING_UPPER_THRESHOLD && min_voltage >= AFE_BALANCING_LOWER_THRESHOLD) { min_voltage += 100; - break; - default: + } else { min_voltage += 250; - break; } + for (size_t cell = 0; cell < (s_afe_settings.num_devices * s_afe_settings.num_cells); cell++) { - if (s_ltc_store.cell_voltages[s_ltc_store.cell_result_lookup[cell]] > min_cell) { + if (s_ltc_store.cell_voltages[s_ltc_store.cell_result_lookup[cell]] > min_voltage) { ltc_afe_impl_toggle_cell_discharge(&s_ltc_store, cell, true); LOG_DEBUG("Cell %d unbalanced \n", cell); delay_ms(1); @@ -222,7 +219,7 @@ static FsmState s_relays_state_list[NUM_RELAY_STATES] = { static bool s_relays_transitions[NUM_RELAY_STATES][NUM_RELAY_STATES] = { TRANSITION(RELAYS_OPEN, RELAYS_CLOSED), TRANSITION(RELAYS_OPEN, RELAYS_FAULT), TRANSITION(RELAYS_CLOSED, RELAYS_OPEN), TRANSITION(RELAYS_CLOSED, RELAYS_FAULT), - TRANSITION(RELAYS_FAULT, RELAYS_FAULT); + TRANSITION(RELAYS_FAULT, RELAYS_FAULT), }; StatusCode init_bms_relays(void) {