From 911650f9c9b55ec60859dcf59e16844a8b7a01e0 Mon Sep 17 00:00:00 2001 From: walkermburns Date: Thu, 8 Feb 2024 23:34:39 -0500 Subject: [PATCH] Pushing some fixes --- lib/interfaces/include/AMSInterface.h | 8 ++++---- lib/interfaces/include/HytechCANInterface.h | 2 +- lib/interfaces/src/AMSInterface.cpp | 6 +++--- lib/systems/src/SafetySystem.cpp | 3 ++- src/main.cpp | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/interfaces/include/AMSInterface.h b/lib/interfaces/include/AMSInterface.h index 5b05a4c9f..1ac625cd9 100644 --- a/lib/interfaces/include/AMSInterface.h +++ b/lib/interfaces/include/AMSInterface.h @@ -40,7 +40,7 @@ class AMSInterface AMSInterface(sw_ok_pin, DEFAULT_INIT_TEMP, DEFAULT_INIT_VOLTAGE, DEFAULT_TEMP_ALPHA, DEFAULT_VOLTAGE_ALPHA) {}; /* Initialize the heartbeat timer */ - void init(); + void init(unsigned long curr_millis); /* Write to Main ECU */ @@ -51,8 +51,8 @@ class AMSInterface void set_state_ok_high(bool ok_high); /* Monitor AMS state */ - void set_heartbeat(); - bool heartbeat_received(); + void set_heartbeat(unsigned long curr_millis); + bool heartbeat_received(unsigned long curr_millis); bool is_below_pack_charge_critical_low_thresh(); bool is_below_pack_charge_critical_total_thresh(); bool pack_charge_is_critical(); @@ -62,7 +62,7 @@ class AMSInterface float get_filtered_min_cell_voltage(); /* Retrieve CAN */ - void retrieve_status_CAN(CAN_message_t &recvd_msg, unsigned long cur_millis); + void retrieve_status_CAN(unsigned long millis, CAN_message_t &recvd_msg); void retrieve_temp_CAN(CAN_message_t &recvd_msg); void retrieve_voltage_CAN(CAN_message_t &recvd_msg); diff --git a/lib/interfaces/include/HytechCANInterface.h b/lib/interfaces/include/HytechCANInterface.h index 7a4a9aeab..402d0e346 100644 --- a/lib/interfaces/include/HytechCANInterface.h +++ b/lib/interfaces/include/HytechCANInterface.h @@ -72,7 +72,7 @@ void process_ring_buffer(BufferType &rx_buffer, const InterfaceType &interfaces, // AMS msg receives case ID_BMS_STATUS: - interfaces.ams_interface->retrieve_status_CAN(recvd_msg, curr_millis); + interfaces.ams_interface->retrieve_status_CAN(curr_millis, recvd_msg); break; case ID_BMS_TEMPERATURES: interfaces.ams_interface->retrieve_temp_CAN(recvd_msg); diff --git a/lib/interfaces/src/AMSInterface.cpp b/lib/interfaces/src/AMSInterface.cpp index 8ec74d509..2078a342e 100644 --- a/lib/interfaces/src/AMSInterface.cpp +++ b/lib/interfaces/src/AMSInterface.cpp @@ -1,9 +1,9 @@ #include "AMSInterface.h" /* Pin mode output to watchdog reset */ -void AMSInterface::init() { +void AMSInterface::init(unsigned long curr_millis) { - set_heartbeat(); + set_heartbeat(curr_millis); } @@ -68,7 +68,7 @@ float AMSInterface::get_filtered_min_cell_voltage() { } /* Retrieve CAN messages */ -void AMSInterface::retrieve_status_CAN(CAN_message_t &recvd_msg, unsigned long curr_millis) { +void AMSInterface::retrieve_status_CAN(unsigned long curr_millis, CAN_message_t &recvd_msg) { bms_status_.load(recvd_msg.buf); set_heartbeat(curr_millis); } diff --git a/lib/systems/src/SafetySystem.cpp b/lib/systems/src/SafetySystem.cpp index 7f23b741d..a68f366eb 100644 --- a/lib/systems/src/SafetySystem.cpp +++ b/lib/systems/src/SafetySystem.cpp @@ -15,7 +15,8 @@ void SafetySystem::software_shutdown(const SysTick_s &tick) { // If AMS heartbeat is not received within reasonable interval // Set software is not ok - if (!ams_->heartbeat_received()) { + unsigned long millis = (unsigned long) tick.millis; + if (!ams_->heartbeat_received(millis)) { software_is_ok = false; } if (software_is_ok) diff --git a/src/main.cpp b/src/main.cpp index 1982b2605..638b4e2db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -114,7 +114,7 @@ void setup() { /* Initialize interface */ main_ecu.init(); // initial shutdown circuit readings, wd_interface.init(curr_tick); // initialize wd kick time - ams_interface.init(); // initialize last heartbeat time + ams_interface.init(curr_tick.millis); // initialize last heartbeat time /* Initialize system */ safety_system.init(); // write software_ok high, write wd_input high, set software ok state true @@ -179,7 +179,7 @@ void tick_all_interfaces(const SysTick_s& current_system_tick) { } void tick_all_systems(const SysTick_s& current_system_tick) { - + // tick pedals system pedals_system.tick( current_system_tick,