Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions include/CCUTasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <ht_sched.hpp>
#include "CANInterface.h"
#include "CCUCANInterfaceImpl.h"
#include "CCUCANInterface.h"
#include "ACUInterface.h"
#include "CCUEthernetInterface.h"
#include "ChargerInterface.h"
Expand All @@ -17,7 +17,6 @@
#include "MainChargeSystem.h"
#include "DisplayInterface.h"


HT_TASK::TaskResponse intitialize_all_interfaces();

HT_TASK::TaskResponse init_update_display_task(const unsigned long& sysMicros, const HT_TASK::TaskInfo& taskInfo);
Expand Down
1 change: 1 addition & 0 deletions include/CCU_Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ constexpr int WATCHDOG_PIN = 26;
constexpr int SOFTWARE_OK_PIN = 27; // Watchdog's !RESET pin
constexpr unsigned long WATCHDOG_KICK_INTERVAL_MS = 10UL;


#endif
77 changes: 32 additions & 45 deletions lib/interfaces/include/ACUInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,41 @@
#include "etl/singleton.h"
#include <etl/delegate.h>
#include "CANInterface.h"
#include "ACUData.h"
#include "CCUData.h"


struct ACUInterfaceData_s
{
/* ACU Status Message */
unsigned long last_recv_status_millis;
uint16_t acu_state;
bool acu_shdn_out_voltage_high;
bool heartbeat_ok;

/* BMS Voltages */
volt average_voltage;
volt low_voltage;
volt high_voltage;
volt min_cell_voltage;
volt max_cell_voltage;
volt total_voltage;


/* BMS Onboard Temps Data */
/* BMS Onboard Current Temps Message */
celsius max_board_temp;
celsius max_cell_temp;
celsius min_cell_temp;

/* BMS Detailed Data for Comp */

/* BMS Onboard Detailed Temps Data */
size_t ic_id;
float temp_0;
float temp_1;


/* BMS Detailed Temps Data */
int group_id;
int ic_detailed_id;
float therm_id_0;
float therm_id_1;
float therm_id_2;
size_t cell_voltage_current_chip;
volt cell_voltage_1;
volt cell_voltage_2;
volt cell_voltage_3;

float max_cell_temp;
float min_cell_temp;
float avg_cell_temp;
float cell_temps[12][3];
size_t cell_group_temp_current_chip;
celsius cell_group_temp_1;
celsius cell_group_temp_2;

size_t board_temp_current_chip;
celsius board_temp;

};

Expand All @@ -56,46 +53,36 @@ class ACUInterface
{
_curr_data.last_recv_status_millis = 0;
_curr_data.heartbeat_ok = false; // start out false
_curr_data.acu_state = 0;
_curr_data.acu_shdn_out_voltage_high = false;

_curr_data.average_voltage = 0;
_curr_data.low_voltage = 0;
_curr_data.high_voltage = 0;
_curr_data.min_cell_voltage = 0;
_curr_data.max_cell_voltage = 0;
_curr_data.total_voltage = 0;

_curr_data.max_board_temp = 0;

_curr_data.ic_id = 0;
_curr_data.temp_0 = 0;
_curr_data.temp_1 = 0;

_curr_data.group_id = 0;
_curr_data.ic_detailed_id = 0;
_curr_data.therm_id_0 = 0;
_curr_data.therm_id_1 = 0;
_curr_data.therm_id_2 = 0;

_curr_data.max_board_temp = 0;
_curr_data.max_cell_temp = 0;
_curr_data.min_cell_temp = 100;
_curr_data.avg_cell_temp = 0;
_curr_data.min_cell_temp = 0;

};


bool is_acu_heartbeat_not_ok() {return !_curr_data.heartbeat_ok; }
void reset_acu_heartbeat();

void receive_status_message(const CAN_message_t& msg, unsigned long curr_millis);
void receive_voltages_message(const CAN_message_t& msg, unsigned long curr_millis); //BMS_VOLTAGES and BMS_DETAILED_VOLTAGES
void receive_onboard_temps_message(const CAN_message_t& msg, unsigned long curr_millis);
void receive_detailed_temps_message(const CAN_message_t& msg, unsigned long curr_millis);
void receive_onboard_detailed_temps(const CAN_message_t& msg, unsigned long curr_millis);


void receive_voltage_statistics_message(const CAN_message_t& msg, unsigned long curr_millis); //BMS_VOLTAGES and BMS_DETAILED_VOLTAGES
void receive_temp_statistics_message(const CAN_message_t& msg, unsigned long curr_millis);
void receive_cell_group_temps_message(const CAN_message_t& msg, unsigned long curr_millis);
void receive_cell_voltages(const CAN_message_t& msg, unsigned long curr_millis);
void receive_board_temps(const CAN_message_t& msg, unsigned long curr_millis);


ACUInterfaceData_s get_latest_data() {return _curr_data;};

void enqueue_ccu_status_data();

private:

ACUInterfaceData_s _curr_data;
CCUData &_ccu_data;

Expand Down
19 changes: 19 additions & 0 deletions lib/interfaces/include/CCUCANBuffers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef CCUCANBUFFERS_H
#define CCUCANBUFFERS_H

#include "FlexCAN_T4.h"

// Buffer type aliases for CAN RX/TX queues
using CANRXBufferType = Circular_Buffer<uint8_t, (uint32_t)16, sizeof(CAN_message_t)>;
using CANTXBufferType = Circular_Buffer<uint8_t, (uint32_t)128, sizeof(CAN_message_t)>;

// Extern declarations for shared CAN buffers
namespace CCUCANInterface {
extern CANRXBufferType charger_can_rx_buffer;
extern CANRXBufferType acu_can_rx_buffer;

extern CANTXBufferType charger_can_tx_buffer;
extern CANTXBufferType acu_can_tx_buffer;
}

#endif // CCUCANBUFFERS_H
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
#ifndef CCUCANINTERFACEIMPL
#define CCUCANINTERFACEIMPL
#ifndef CCUCANINTERFACE
#define CCUCANINTERFACE

#include "CANInterface.h"

#include "ACUInterface.h"
#include "CCUCANBuffers.h"
#include "ChargerInterface.h"

#include "EMInterface.h"
#include "ACUInterface.h"
#include "etl/singleton.h"
#include <etl/delegate.h>
#include "FlexCAN_T4.h"

#include "hytech.h" // generated CAN library

using CANRXBufferType = Circular_Buffer<uint8_t, (uint32_t)16, sizeof(CAN_message_t)>;
using CANTXBufferType = Circular_Buffer<uint8_t, (uint32_t)128, sizeof(CAN_message_t)>;

// Provide a convenient alias for FlexCAN types used across the project
template <CAN_DEV_TABLE CAN_DEV> using FlexCAN_Type = FlexCAN_T4<CAN_DEV, RX_SIZE_256, TX_SIZE_16>;

struct CANInterfaces
{
explicit CANInterfaces(ACUInterface &acu_int, ChargerInterface &charger_int, EnergyMeterInterface & em_int) :
acu_interface(acu_int),
acu_interface(acu_int),
charger_interface(charger_int),
em_interface(em_int) {}

Expand All @@ -33,17 +30,11 @@ struct CANInterfaces
using CANInterfacesInstance = etl::singleton<CANInterfaces>;

extern FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> CHARGER_CAN; // gets defined in main as of right now
extern FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> ACU_CAN; // gets defined in main as of right now
extern FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> ACU_CAN; // gets defined in main as of right now

namespace CCUCANInterfaceImpl
namespace CCUCANInterface
{
extern CANRXBufferType charger_can_rx_buffer;
extern CANRXBufferType acu_can_rx_buffer;

/* TX buffer for Charger CAN */
extern CANTXBufferType charger_can_tx_buffer;
/* TX buffer for ACU CAN */
extern CANTXBufferType acu_can_tx_buffer;
// Buffer externs are declared in CCUCANBuffers.h

void on_acu_can_receive(const CAN_message_t &msg);
void on_charger_can_receive(const CAN_message_t &msg);
Expand All @@ -52,6 +43,6 @@ namespace CCUCANInterfaceImpl

void send_all_CAN_msgs(CANTXBufferType &buffer, FlexCAN_T4_Base *can_interface);

}; // namespace CCUCANInterfaceImpl
}; // namespace CCUCANInterface

#endif // CCUCANINTERFACEIMPL
#endif // CCUCANINTERFACE
2 changes: 1 addition & 1 deletion lib/interfaces/include/CCUEthernetInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ struct CCUOutput_s

namespace CCUEthernetInterface
{
void recieve_pb_msg_acu_all_data(const hytech_msgs_ACUAllData_s &msg_in, ACUAllData_s &acu_all_data);
void recieve_pb_msg_acu_all_data(const hytech_msgs_ACUAllData_s &msg_in, ACUAllDataType_s &acu_all_data);
};
#endif
63 changes: 38 additions & 25 deletions lib/interfaces/src/ACUInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include "ACUInterface.h"

#include "CCUCANInterfaceImpl.h"
#include "CCUCANBuffers.h"
#include "hytech.h"



void ACUInterface::reset_acu_heartbeat()
{
_curr_data.heartbeat_ok = true;
Expand All @@ -13,7 +11,7 @@ void ACUInterface::reset_acu_heartbeat()
void ACUInterface::receive_status_message(const CAN_message_t &msg, unsigned long curr_millis) {
BMS_STATUS_t bms_status_msg;
Unpack_BMS_STATUS_hytech(&bms_status_msg, &msg.buf[0], msg.len);
_curr_data.acu_state = bms_status_msg.state;
_curr_data.acu_shdn_out_voltage_high = bms_status_msg.shdn_out_voltage_state;

// As long as we're using millis() function, loop overrun not a concern

Expand All @@ -26,55 +24,70 @@ void ACUInterface::receive_status_message(const CAN_message_t &msg, unsigned lon

}

void ACUInterface::receive_voltages_message(const CAN_message_t& msg, unsigned long curr_millis)

void ACUInterface::receive_voltage_statistics_message(const CAN_message_t& msg, unsigned long curr_millis)
{
BMS_VOLTAGES_t voltages_msg;
Unpack_BMS_VOLTAGES_hytech(&voltages_msg, &msg.buf[0], msg.len);
_curr_data.average_voltage = HYTECH_average_voltage_ro_fromS(static_cast<float>(voltages_msg.average_voltage_ro));
_curr_data.low_voltage = HYTECH_low_voltage_ro_fromS(static_cast<float>(voltages_msg.low_voltage_ro));
_curr_data.high_voltage = HYTECH_high_voltage_ro_fromS(static_cast<float>(voltages_msg.high_voltage_ro));
_curr_data.min_cell_voltage = HYTECH_min_cell_voltage_ro_fromS(static_cast<float>(voltages_msg.min_cell_voltage_ro));
_curr_data.max_cell_voltage = HYTECH_max_cell_voltage_ro_fromS(static_cast<float>(voltages_msg.max_cell_voltage_ro));
_curr_data.total_voltage = HYTECH_total_voltage_ro_fromS(static_cast<float>(voltages_msg.total_voltage_ro));

}

void ACUInterface::receive_onboard_temps_message(const CAN_message_t& msg, unsigned long curr_millis)

void ACUInterface::receive_temp_statistics_message(const CAN_message_t& msg, unsigned long curr_millis)
{
BMS_ONBOARD_TEMPS_t board_temps = {};
Unpack_BMS_ONBOARD_TEMPS_hytech(&board_temps, &msg.buf[0], msg.len);
_curr_data.max_board_temp = HYTECH_max_board_temp_ro_fromS(board_temps.max_board_temp_ro);
_curr_data.min_cell_temp = HYTECH_low_cell_temp_ro_fromS(board_temps.low_cell_temp_ro);
_curr_data.max_cell_temp = HYTECH_high_cell_temp_ro_fromS(board_temps.high_cell_temp_ro);
_curr_data.min_cell_temp = HYTECH_min_cell_temp_ro_fromS(board_temps.min_cell_temp_ro);
_curr_data.max_cell_temp = HYTECH_max_cell_temp_ro_fromS(board_temps.max_cell_temp_ro);


_ccu_data.max_board_temp = _curr_data.max_board_temp;
_ccu_data.min_cell_temp = _curr_data.min_cell_temp;
_ccu_data.max_cell_temp = _curr_data.max_cell_temp;
}

void ACUInterface::receive_detailed_temps_message(const CAN_message_t& msg, unsigned long curr_millis)

void ACUInterface::receive_cell_group_temps_message(const CAN_message_t& msg, unsigned long curr_millis)
{
BMS_DETAILED_TEMPS_t detailed_temps{};
Unpack_BMS_DETAILED_TEMPS_hytech(&detailed_temps, &msg.buf[0], msg.len);
_curr_data.group_id = detailed_temps.group_id; //size of uint8_t
_curr_data.ic_detailed_id = detailed_temps.ic_id; //size of uint8_t
_curr_data.therm_id_0 = HYTECH_thermistor_id_0_ro_fromS(static_cast<float>(detailed_temps.thermistor_id_0_ro));
_curr_data.therm_id_1 = HYTECH_thermistor_id_1_ro_fromS(static_cast<float>(detailed_temps.thermistor_id_1_ro));
_curr_data.therm_id_2 = HYTECH_thermistor_id_2_ro_fromS(static_cast<float>(detailed_temps.thermistor_id_2_ro));
BMS_CHIP_TEMPS_t chip_temps{};
Unpack_BMS_CHIP_TEMPS_hytech(&chip_temps, &msg.buf[0], msg.len);
_curr_data.cell_group_temp_current_chip = chip_temps.chip_id;

_curr_data.cell_group_temp_1 = HYTECH_thermistor_cell_group_temp_0_ro_fromS(static_cast<float>(chip_temps.thermistor_cell_group_temp_0_ro));
_curr_data.cell_group_temp_2 = HYTECH_thermistor_cell_group_temp_1_ro_fromS(static_cast<float>(chip_temps.thermistor_cell_group_temp_1_ro));

}

void ACUInterface::receive_onboard_detailed_temps(const CAN_message_t& msg, unsigned long curr_millis)

void ACUInterface::receive_board_temps(const CAN_message_t& msg, unsigned long curr_millis)
{
BMS_ONBOARD_DETAILED_TEMPS_t onboard_detailed_temps{};
Unpack_BMS_ONBOARD_DETAILED_TEMPS_hytech(&onboard_detailed_temps, &msg.buf[0], msg.len);
_curr_data.ic_id = onboard_detailed_temps.ic_id;
_curr_data.temp_0 = HYTECH_temp_0_ro_fromS(static_cast<float>(onboard_detailed_temps.temp_0_ro));
_curr_data.temp_1 = HYTECH_temp_1_ro_fromS(static_cast<float>(onboard_detailed_temps.temp_1_ro));
BMS_ONBOARD_CURRENT_TEMP_t onboard_current_temps{};
Unpack_BMS_ONBOARD_CURRENT_TEMP_hytech(&onboard_current_temps, &msg.buf[0], msg.len);

_curr_data.board_temp_current_chip = onboard_current_temps.chip_id;
_curr_data.board_temp = HYTECH_temp_0_ro_fromS(static_cast<float>(onboard_current_temps.temp_0_ro));
}


void ACUInterface::enqueue_ccu_status_data()
{
CCU_STATUS_t ccu_status = {};
ccu_status.charger_enabled = _ccu_data.balancing_enabled; // Treat this as a balancing_enabled boolean
CAN_util::enqueue_msg(&ccu_status, &Pack_CCU_STATUS_hytech, CCUCANInterfaceImpl::acu_can_tx_buffer);
CAN_util::enqueue_msg(&ccu_status, &Pack_CCU_STATUS_hytech, CCUCANInterface::acu_can_tx_buffer);
}

void ACUInterface::receive_cell_voltages(const CAN_message_t& msg, unsigned long curr_millis)
{
BMS_CELL_VOLTAGES_t cell_voltages_msg{};
Unpack_BMS_CELL_VOLTAGES_hytech(&cell_voltages_msg, &msg.buf[0], msg.len);

_curr_data.cell_voltage_current_chip = cell_voltages_msg.chip_id;
_curr_data.cell_voltage_1 = HYTECH_cell_group_voltage_0_ro_fromS(static_cast<float>(cell_voltages_msg.cell_group_voltage_0_ro));
_curr_data.cell_voltage_2 = HYTECH_cell_group_voltage_1_ro_fromS(static_cast<float>(cell_voltages_msg.cell_group_voltage_1_ro));
_curr_data.cell_voltage_3 = HYTECH_cell_group_voltage_2_ro_fromS(static_cast<float>(cell_voltages_msg.cell_group_voltage_2_ro));
}
Loading