From 26f7ca30d259076593f23a9a77854224979d2ce9 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Thu, 8 Feb 2024 11:57:21 -0500 Subject: [PATCH] adding in the AMS to the CAN receiving interface --- lib/interfaces/include/AMSInterface.h | 10 +++++----- lib/interfaces/include/HytechCANInterface.h | 19 +++++++++++++++---- lib/interfaces/src/AMSInterface.cpp | 10 +++++----- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/interfaces/include/AMSInterface.h b/lib/interfaces/include/AMSInterface.h index 7c3a50661..5765e0a71 100644 --- a/lib/interfaces/include/AMSInterface.h +++ b/lib/interfaces/include/AMSInterface.h @@ -1,5 +1,5 @@ -#ifndef __AMS_INTERFACE_H__ -#define __AMS_INTERFACE_H__ +#ifndef AMSINTERFACE +#define AMSINTERFACE #include "FlexCAN_T4.h" #include "HyTech_CAN.h" @@ -40,7 +40,7 @@ class AMSInterface void set_state_ok_high(bool ok_high); /* Monitor AMS state */ - void set_heartbeat(const SysTick_s &tick); + void set_heartbeat(unsigned long millis); bool heartbeat_received(const SysTick_s &tick); bool is_below_pack_charge_critical_low_thresh(); bool is_below_pack_charge_critical_total_thresh(); @@ -51,7 +51,7 @@ class AMSInterface float get_filtered_min_cell_voltage(); /* Retrieve CAN */ - void retrieve_status_CAN(CAN_message_t &recvd_msg, const SysTick_s &tick); + void retrieve_status_CAN(CAN_message_t &recvd_msg, unsigned long cur_millis); void retrieve_temp_CAN(CAN_message_t &recvd_msg); void retrieve_voltage_CAN(CAN_message_t &recvd_msg); @@ -77,4 +77,4 @@ class AMSInterface int pin_software_ok_; }; -#endif /* __AMS_INTERFACE_H__ */ +#endif /* AMSINTERFACE */ diff --git a/lib/interfaces/include/HytechCANInterface.h b/lib/interfaces/include/HytechCANInterface.h index b689d00e0..7a4a9aeab 100644 --- a/lib/interfaces/include/HytechCANInterface.h +++ b/lib/interfaces/include/HytechCANInterface.h @@ -9,6 +9,7 @@ #include "InverterInterface.h" #include "DashboardInterface.h" +#include "AMSInterface.h" template struct CANInterfaces @@ -18,6 +19,7 @@ struct CANInterfaces InverterInterface *rear_left_inv; InverterInterface *rear_right_inv; DashboardInterface *dash_interface; + AMSInterface *ams_interface; }; // the goal with the can interface is that there exists a receive call that appends to a circular buffer @@ -51,7 +53,7 @@ void on_can3_receive(const CAN_message_t &msg); // RL = MC3 // RR = MC4 template -void process_ring_buffer(BufferType &rx_buffer, const InterfaceType &interfaces) +void process_ring_buffer(BufferType &rx_buffer, const InterfaceType &interfaces, unsigned long curr_millis) { // TODO switch to using the global CAN receive function from the generated CAN library @@ -67,9 +69,18 @@ void process_ring_buffer(BufferType &rx_buffer, const InterfaceType &interfaces) case DASHBOARD_STATE_CANID: interfaces.dash_interface->read(recvd_msg); break; - - - + + // AMS msg receives + case ID_BMS_STATUS: + interfaces.ams_interface->retrieve_status_CAN(recvd_msg, curr_millis); + break; + case ID_BMS_TEMPERATURES: + interfaces.ams_interface->retrieve_temp_CAN(recvd_msg); + break; + case ID_BMS_VOLTAGES: + interfaces.ams_interface->retrieve_voltage_CAN(recvd_msg); + break; + // MC status msgs case ID_MC1_STATUS: interfaces.front_left_inv->receive_status_msg(recvd_msg); diff --git a/lib/interfaces/src/AMSInterface.cpp b/lib/interfaces/src/AMSInterface.cpp index 456d4d784..36c42e690 100644 --- a/lib/interfaces/src/AMSInterface.cpp +++ b/lib/interfaces/src/AMSInterface.cpp @@ -3,7 +3,7 @@ /* Pin mode output to watchdog reset */ void AMSInterface::init(const SysTick_s &tick) { - set_heartbeat(tick); + set_heartbeat(tick.millis); } @@ -23,8 +23,8 @@ void AMSInterface::set_state_ok_high(bool ok_high) { } /* Set AMS last heartbeat receive time */ -void AMSInterface::set_heartbeat(const SysTick_s &tick) { - last_heartbeat_time = tick.millis; +void AMSInterface::set_heartbeat(unsigned long millis) { + last_heartbeat_time = millis; } /* Check if AMS heartbeat is received */ @@ -68,9 +68,9 @@ float AMSInterface::get_filtered_min_cell_voltage() { } /* Retrieve CAN messages */ -void AMSInterface::retrieve_status_CAN(CAN_message_t &recvd_msg, const SysTick_s &tick) { +void AMSInterface::retrieve_status_CAN(CAN_message_t &recvd_msg, unsigned long cur_millis) { bms_status_.load(recvd_msg.buf); - set_heartbeat(tick); + set_heartbeat(cur_millis); } void AMSInterface::retrieve_temp_CAN(CAN_message_t &recvd_msg) {