Skip to content

Commit

Permalink
adding in the AMS to the CAN receiving interface
Browse files Browse the repository at this point in the history
  • Loading branch information
RCMast3r committed Feb 8, 2024
1 parent 9f465fa commit 26f7ca3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
10 changes: 5 additions & 5 deletions lib/interfaces/include/AMSInterface.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __AMS_INTERFACE_H__
#define __AMS_INTERFACE_H__
#ifndef AMSINTERFACE
#define AMSINTERFACE

#include "FlexCAN_T4.h"
#include "HyTech_CAN.h"
Expand Down Expand Up @@ -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();
Expand All @@ -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);

Expand All @@ -77,4 +77,4 @@ class AMSInterface
int pin_software_ok_;
};

#endif /* __AMS_INTERFACE_H__ */
#endif /* AMSINTERFACE */
19 changes: 15 additions & 4 deletions lib/interfaces/include/HytechCANInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "InverterInterface.h"
#include "DashboardInterface.h"
#include "AMSInterface.h"

template <typename circular_buffer>
struct CANInterfaces
Expand All @@ -18,6 +19,7 @@ struct CANInterfaces
InverterInterface<circular_buffer> *rear_left_inv;
InverterInterface<circular_buffer> *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
Expand Down Expand Up @@ -51,7 +53,7 @@ void on_can3_receive(const CAN_message_t &msg);
// RL = MC3
// RR = MC4
template <typename BufferType, typename InterfaceType>
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

Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions lib/interfaces/src/AMSInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* Pin mode output to watchdog reset */
void AMSInterface::init(const SysTick_s &tick) {

set_heartbeat(tick);
set_heartbeat(tick.millis);

}

Expand All @@ -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 */
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 26f7ca3

Please sign in to comment.