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
43 changes: 28 additions & 15 deletions lib/interfaces/include/CCUInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@
#include "SharedFirmwareTypes.h"
#include "shared_types.h"


namespace ccu_interface_defaults{
constexpr const uint16_t MIN_CHARGING_ENABLE_THRESHOLD_MS = 1000;
constexpr const size_t NUM_CELLS = 126;
constexpr const size_t NUM_CELLTEMPS = 48;
constexpr const size_t NUM_CHIPS = 12;
constexpr const size_t VOLTAGE_CELLS_PER_GROUP = 3;
constexpr const size_t TEMP_CELLS_PER_GROUP = 2;
constexpr const size_t GROUPS_PER_IC_EVEN = 4;
constexpr const size_t GROUPS_PER_IC_ODD = 3;
};

struct CCUCANInterfaceData_s
Expand All @@ -26,20 +31,24 @@ struct CCUCANInterfaceData_s
unsigned long prev_ccu_msg_recv_ms;
bool charging_requested;
bool is_connected_to_CCU;
size_t detailed_voltages_ic_id;
size_t detailed_voltages_group_id;
size_t detailed_voltages_cell_id;
size_t detailed_temps_ic_id;
size_t detailed_temps_group_id;
size_t detailed_temps_cell_id;
size_t detailed_temps_board_id;
size_t voltage_group_chip_id;
size_t voltage_cell_group_id;
size_t voltage_cell_id;
size_t temp_group_chip_id;
size_t temp_group_id;
size_t temp_cell_id;
size_t temp_board_id;
};

struct CCUInterfaceParams_s {
unsigned long min_charging_enable_threshold;
size_t num_cells;
size_t num_celltemps;
size_t num_chips;
size_t voltage_cells_per_group;
size_t temp_cells_per_group;
size_t groups_per_ic_even;
size_t groups_per_ic_odd;
};

class CCUInterface
Expand All @@ -52,21 +61,25 @@ class CCUInterface
.min_charging_enable_threshold = ccu_interface_defaults::MIN_CHARGING_ENABLE_THRESHOLD_MS,
.num_cells = ccu_interface_defaults::NUM_CELLS,
.num_celltemps = ccu_interface_defaults::NUM_CELLTEMPS,
.num_chips = ccu_interface_defaults::NUM_CHIPS
.num_chips = ccu_interface_defaults::NUM_CHIPS,
.voltage_cells_per_group = ccu_interface_defaults::VOLTAGE_CELLS_PER_GROUP,
.temp_cells_per_group = ccu_interface_defaults::TEMP_CELLS_PER_GROUP,
.groups_per_ic_even = ccu_interface_defaults::GROUPS_PER_IC_EVEN,
.groups_per_ic_odd = ccu_interface_defaults::GROUPS_PER_IC_ODD
}
) : _ccu_params{params}
{
_curr_data.last_time_charging_requested = 0;
_curr_data.prev_ccu_msg_recv_ms = 0;
_curr_data.charging_requested = false;
_curr_data.is_connected_to_CCU = false;
_curr_data.detailed_voltages_group_id = 0;
_curr_data.detailed_voltages_ic_id = 0;
_curr_data.detailed_voltages_cell_id = 0;
_curr_data.detailed_temps_group_id = 0;
_curr_data.detailed_temps_ic_id = 0;
_curr_data.detailed_temps_cell_id = 0;
_curr_data.detailed_temps_board_id = 0;
_curr_data.voltage_cell_group_id = 0;
_curr_data.voltage_group_chip_id = 0;
_curr_data.voltage_cell_id = 0;
_curr_data.temp_group_id = 0;
_curr_data.temp_group_chip_id = 0;
_curr_data.temp_cell_id = 0;
_curr_data.temp_board_id = 0;
};

bool is_charging_requested() { return _curr_data.charging_requested; }
Expand Down
71 changes: 35 additions & 36 deletions lib/interfaces/src/CCUInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,70 +16,69 @@ void CCUInterface::receive_CCU_status_message(const CAN_message_t& msg, unsigned
void CCUInterface::handle_enqueue_acu_status_CAN_message() {
BMS_STATUS_t msg = {};
if (_curr_data.charging_requested) {
msg.state = 2; // charging
msg.charging_state = true;
} else {
msg.state = 1; // discharging
msg.charging_state = false;
}

CAN_util::enqueue_msg(&msg, &Pack_BMS_STATUS_hytech, ACUCANInterfaceImpl::ccu_can_tx_buffer);
}

void CCUInterface::handle_enqueue_acu_core_voltages_CAN_message() {
BMS_VOLTAGES_t msg = {};
msg.high_voltage_ro = HYTECH_high_voltage_ro_toS(_acu_core_data.max_cell_voltage);
msg.low_voltage_ro = HYTECH_low_voltage_ro_toS(_acu_core_data.min_cell_voltage);
msg.max_cell_voltage_ro = HYTECH_max_cell_voltage_ro_toS(_acu_core_data.max_cell_voltage);
msg.min_cell_voltage_ro = HYTECH_min_cell_voltage_ro_toS(_acu_core_data.min_cell_voltage);
msg.total_voltage_ro = HYTECH_total_voltage_ro_toS(_acu_core_data.pack_voltage);
msg.average_voltage_ro = HYTECH_average_voltage_ro_toS(_acu_core_data.avg_cell_voltage);
CAN_util::enqueue_msg(&msg, &Pack_BMS_VOLTAGES_hytech, ACUCANInterfaceImpl::ccu_can_tx_buffer);
}

void CCUInterface::handle_enqueue_acu_voltages_CAN_message() {
BMS_DETAILED_VOLTAGES_t detailed_msg = {};
detailed_msg.ic_id = static_cast<uint8_t>(_curr_data.detailed_voltages_ic_id);
detailed_msg.group_id = static_cast<uint8_t>(_curr_data.detailed_voltages_group_id);
detailed_msg.voltage_0_ro = HYTECH_voltage_0_ro_toS(_acu_all_data.cell_voltages[_curr_data.detailed_voltages_cell_id]);
detailed_msg.voltage_1_ro = HYTECH_voltage_1_ro_toS(_acu_all_data.cell_voltages[_curr_data.detailed_voltages_cell_id+1]);
detailed_msg.voltage_2_ro = HYTECH_voltage_2_ro_toS(_acu_all_data.cell_voltages[_curr_data.detailed_voltages_cell_id+2]);
BMS_CELL_VOLTAGES_t msg = {};
msg.chip_id = static_cast<uint8_t>(_curr_data.voltage_group_chip_id);
msg.cell_group_id = static_cast<uint8_t>(_curr_data.voltage_cell_group_id);
msg.cell_group_voltage_0_ro = HYTECH_cell_group_voltage_0_ro_toS(_acu_all_data.cell_voltages[_curr_data.voltage_cell_id]);
msg.cell_group_voltage_1_ro = HYTECH_cell_group_voltage_1_ro_toS(_acu_all_data.cell_voltages[_curr_data.voltage_cell_id+1]);
msg.cell_group_voltage_2_ro = HYTECH_cell_group_voltage_2_ro_toS(_acu_all_data.cell_voltages[_curr_data.voltage_cell_id+2]);

if (_curr_data.detailed_voltages_ic_id % 2 == 0) {
_curr_data.detailed_voltages_group_id = (_curr_data.detailed_voltages_group_id == 3) ? 0 : _curr_data.detailed_voltages_group_id+1;
if (_curr_data.voltage_group_chip_id % 2 == 0) {
_curr_data.voltage_cell_group_id = (_curr_data.voltage_cell_group_id == _ccu_params.groups_per_ic_even - 1) ? 0 : _curr_data.voltage_cell_group_id+1;
} else {
_curr_data.detailed_voltages_group_id = (_curr_data.detailed_voltages_group_id == 2) ? 0 : _curr_data.detailed_voltages_group_id+1;
_curr_data.voltage_cell_group_id = (_curr_data.voltage_cell_group_id == _ccu_params.groups_per_ic_odd - 1) ? 0 : _curr_data.voltage_cell_group_id+1;
}
if (_curr_data.detailed_voltages_group_id == 0) {
_curr_data.detailed_voltages_ic_id = (_curr_data.detailed_voltages_ic_id == (ccu_interface_defaults::NUM_CHIPS - 1)) ? 0 : _curr_data.detailed_voltages_ic_id+1;
if (_curr_data.voltage_cell_group_id == 0) {
_curr_data.voltage_group_chip_id = (_curr_data.voltage_group_chip_id == (_ccu_params.num_chips - 1)) ? 0 : _curr_data.voltage_group_chip_id+1;
}
_curr_data.detailed_voltages_cell_id = (_curr_data.detailed_voltages_cell_id == ccu_interface_defaults::NUM_CELLS - 3) ? 0 : _curr_data.detailed_voltages_cell_id+3;
_curr_data.voltage_cell_id= (_curr_data.voltage_cell_id == _ccu_params.num_cells - _ccu_params.voltage_cells_per_group) ? 0 : _curr_data.voltage_cell_id+_ccu_params.voltage_cells_per_group;

CAN_util::enqueue_msg(&detailed_msg, &Pack_BMS_DETAILED_VOLTAGES_hytech, ACUCANInterfaceImpl::ccu_can_tx_buffer);
CAN_util::enqueue_msg(&msg, &Pack_BMS_CELL_VOLTAGES_hytech, ACUCANInterfaceImpl::ccu_can_tx_buffer);
}

void CCUInterface::handle_enqueue_acu_temps_CAN_message() {
BMS_DETAILED_TEMPS_t detailed_msg = {};
detailed_msg.ic_id = static_cast<uint8_t>(_curr_data.detailed_temps_ic_id);
detailed_msg.group_id = static_cast<uint8_t>(_curr_data.detailed_temps_group_id);
detailed_msg.thermistor_id_0_ro = HYTECH_thermistor_id_0_ro_toS(_acu_all_data.cell_temps[_curr_data.detailed_temps_cell_id]);
detailed_msg.thermistor_id_1_ro = HYTECH_thermistor_id_1_ro_toS(_acu_all_data.cell_temps[_curr_data.detailed_temps_cell_id+1]);
detailed_msg.thermistor_id_2_ro = HYTECH_thermistor_id_2_ro_toS(_acu_all_data.cell_temps[_curr_data.detailed_temps_cell_id+2]);

_curr_data.detailed_temps_group_id = (_curr_data.detailed_temps_group_id == 1) ? 0 : _curr_data.detailed_temps_group_id+1;
if (_curr_data.detailed_temps_group_id == 0) {
_curr_data.detailed_temps_ic_id = (_curr_data.detailed_temps_ic_id == (ccu_interface_defaults::NUM_CHIPS - 1)) ? 0 : _curr_data.detailed_temps_ic_id+1;
BMS_CHIP_TEMPS_t chip_temps_msg = {};
chip_temps_msg.chip_id = static_cast<uint8_t>(_curr_data.temp_group_chip_id);
chip_temps_msg.thermistor_group_id = static_cast<uint8_t>(_curr_data.temp_group_id);
chip_temps_msg.thermistor_cell_group_temp_0_ro = HYTECH_thermistor_cell_group_temp_0_ro_toS(_acu_all_data.cell_temps[_curr_data.temp_cell_id]);
chip_temps_msg.thermistor_cell_group_temp_1_ro = HYTECH_thermistor_cell_group_temp_1_ro_toS(_acu_all_data.cell_temps[_curr_data.temp_cell_id+1]);

_curr_data.temp_group_id = (_curr_data.temp_group_id == 1) ? 0 : _curr_data.temp_group_id+1;
if (_curr_data.temp_group_id == 0) {
_curr_data.temp_group_chip_id = (_curr_data.temp_group_chip_id == (_ccu_params.num_chips - 1)) ? 0 : _curr_data.temp_group_chip_id+1;
}
_curr_data.detailed_temps_cell_id = (_curr_data.detailed_temps_cell_id == (ccu_interface_defaults::NUM_CELLTEMPS - 3)) ? 0 : _curr_data.detailed_temps_cell_id+3;
CAN_util::enqueue_msg(&detailed_msg, &Pack_BMS_DETAILED_TEMPS_hytech, ACUCANInterfaceImpl::ccu_can_tx_buffer);
_curr_data.temp_cell_id = (_curr_data.temp_cell_id == (_ccu_params.num_celltemps - _ccu_params.temp_cells_per_group)) ? 0 : _curr_data.temp_cell_id+_ccu_params.temp_cells_per_group;
CAN_util::enqueue_msg(&chip_temps_msg, &Pack_BMS_CHIP_TEMPS_hytech, ACUCANInterfaceImpl::ccu_can_tx_buffer);

BMS_ONBOARD_TEMPS_t board_temp_msg = {};
board_temp_msg.max_board_temp_ro = HYTECH_max_board_temp_ro_toS(_acu_all_data.core_data.max_board_temp);
board_temp_msg.high_cell_temp_ro = HYTECH_high_cell_temp_ro_toS(_acu_all_data.core_data.max_cell_temp);
board_temp_msg.low_cell_temp_ro = HYTECH_low_cell_temp_ro_toS(_acu_all_data.core_data.min_cell_temp);
board_temp_msg.max_cell_temp_ro = HYTECH_max_cell_temp_ro_toS(_acu_all_data.core_data.max_cell_temp);
board_temp_msg.min_cell_temp_ro = HYTECH_min_cell_temp_ro_toS(_acu_all_data.core_data.min_cell_temp);
CAN_util::enqueue_msg(&board_temp_msg, &Pack_BMS_ONBOARD_TEMPS_hytech, ACUCANInterfaceImpl::ccu_can_tx_buffer);

BMS_ONBOARD_DETAILED_TEMPS_t detailed_board_temp_msg = {};
detailed_board_temp_msg.ic_id = _curr_data.detailed_temps_board_id;
detailed_board_temp_msg.temp_0_ro = HYTECH_temp_0_ro_toS(_acu_all_data.board_temps[_curr_data.detailed_temps_board_id]);
_curr_data.detailed_temps_board_id = (_curr_data.detailed_temps_board_id == (ccu_interface_defaults::NUM_CHIPS - 1)) ? 0 : _curr_data.detailed_temps_board_id+1;
CAN_util::enqueue_msg(&detailed_board_temp_msg, &Pack_BMS_ONBOARD_DETAILED_TEMPS_hytech, ACUCANInterfaceImpl::ccu_can_tx_buffer);
BMS_ONBOARD_CURRENT_TEMP_t current_board_temp_msg = {};
current_board_temp_msg.chip_id = _curr_data.temp_board_id;
current_board_temp_msg.temp_0_ro = HYTECH_temp_0_ro_toS(_acu_all_data.board_temps[_curr_data.temp_board_id]);
_curr_data.temp_board_id = (_curr_data.temp_board_id == (_ccu_params.num_chips - 1)) ? 0 : _curr_data.temp_board_id+1;
CAN_util::enqueue_msg(&current_board_temp_msg, &Pack_BMS_ONBOARD_CURRENT_TEMP_hytech, ACUCANInterfaceImpl::ccu_can_tx_buffer);
}

void CCUInterface::set_system_latch_state(unsigned long curr_millis, bool is_latched) {
Expand Down
6 changes: 3 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ test_ignore =
lib_deps=
${common.lib_deps_shared}
https://github.com/ssilverman/QNEthernet#v0.26.0
https://github.com/hytech-racing/HT_CAN/releases/download/192/can_lib.tar.gz
https://github.com/hytech-racing/HT_CAN/releases/download/209/can_lib.tar.gz
https://github.com/hytech-racing/HT_SCHED.git
https://github.com/hytech-racing/HT_proto/releases/download/2025-08-27T15_34_50/hytech_msgs_pb_lib.tar.gz
https://github.com/hytech-racing/shared_firmware_interfaces.git#5baf17a0f6d83d0a9d571d6bf56f409d2c8ad98a
Expand Down Expand Up @@ -113,10 +113,10 @@ test_ignore =
lib_deps=
${common.lib_deps_shared}
https://github.com/ssilverman/QNEthernet#v0.26.0
https://github.com/hytech-racing/HT_CAN/releases/download/192/can_lib.tar.gz
https://github.com/hytech-racing/HT_CAN/releases/download/209/can_lib.tar.gz
https://github.com/hytech-racing/HT_SCHED.git
https://github.com/hytech-racing/HT_proto/releases/download/2025-08-27T15_34_50/hytech_msgs_pb_lib.tar.gz
https://github.com/hytech-racing/shared_firmware_interfaces.git
https://github.com/hytech-racing/shared_firmware_interfaces.git#5baf17a0f6d83d0a9d571d6bf56f409d2c8ad98a
https://github.com/KSU-MS/pio-git-hash-gen#7998b5b3f8a2464209b0e73338717998bcf511ee
Nanopb
arkhipenko/TaskScheduler@^3.8.5
Expand Down
40 changes: 20 additions & 20 deletions src/ACU_InterfaceTasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,26 +359,26 @@ HT_TASK::TaskResponse debug_print(const unsigned long &sysMicros, const HT_TASK:

Serial.print("Number of Global Faults: ");
Serial.println(BMSFaultDataManager_t::instance().get_fault_data().max_consecutive_invalid_packet_count);
// Serial.println("Number of Consecutive Faults Per Chip: ");
// for (size_t c = 0; c < ACUConstants::NUM_CHIPS; c++) {
// Serial.print("CHIP ");
// Serial.print(c);
// Serial.print(": ");
// Serial.print(ACUFaultDataInstance::instance().consecutive_invalid_packet_counts[c]);
// Serial.print("\t");
// Serial.print(ACUFaultDataInstance::instance().chip_invalid_cmd_counts[c].invalid_cell_1_to_3_count);
// Serial.print(" ");
// Serial.print(ACUFaultDataInstance::instance().chip_invalid_cmd_counts[c].invalid_cell_4_to_6_count);
// Serial.print(" ");
// Serial.print(ACUFaultDataInstance::instance().chip_invalid_cmd_counts[c].invalid_cell_7_to_9_count);
// Serial.print(" ");
// Serial.print(ACUFaultDataInstance::instance().chip_invalid_cmd_counts[c].invalid_cell_10_to_12_count);
// Serial.print(" ");
// Serial.print(ACUFaultDataInstance::instance().chip_invalid_cmd_counts[c].invalid_gpio_1_to_3_count);
// Serial.print(" ");
// Serial.print(ACUFaultDataInstance::instance().chip_invalid_cmd_counts[c].invalid_gpio_4_to_6_count);
// Serial.print(" ");
// }
Serial.println("Number of Consecutive Faults Per Chip: ");
for (size_t c = 0; c < ACUConstants::NUM_CHIPS; c++) {
Serial.print("CHIP ");
Serial.print(c);
Serial.print(": ");
Serial.print(BMSFaultDataManager_t::instance().get_fault_data().consecutive_invalid_packet_counts[c]);
Serial.print("\t");
Serial.print(BMSFaultDataManager_t::instance().get_fault_data().chip_invalid_cmd_counts[c].invalid_cell_1_to_3_count);
Serial.print(" ");
Serial.print(BMSFaultDataManager_t::instance().get_fault_data().chip_invalid_cmd_counts[c].invalid_cell_4_to_6_count);
Serial.print(" ");
Serial.print(BMSFaultDataManager_t::instance().get_fault_data().chip_invalid_cmd_counts[c].invalid_cell_7_to_9_count);
Serial.print(" ");
Serial.print(BMSFaultDataManager_t::instance().get_fault_data().chip_invalid_cmd_counts[c].invalid_cell_10_to_12_count);
Serial.print(" ");
Serial.print(BMSFaultDataManager_t::instance().get_fault_data().chip_invalid_cmd_counts[c].invalid_gpio_1_to_3_count);
Serial.print(" ");
Serial.print(BMSFaultDataManager_t::instance().get_fault_data().chip_invalid_cmd_counts[c].invalid_gpio_4_to_6_count);
Serial.print(" ");
}
// Serial.println();

return HT_TASK::TaskResponse::YIELD;
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void setup()
scheduler.schedule(sample_CAN_task);
scheduler.schedule(idle_sample_task);

//scheduler.schedule(debug_prints_task);
// scheduler.schedule(debug_prints_task);

handle_CAN_setup(ACUCANInterfaceImpl::CCU_CAN, ACUConstants::Veh_CAN_baudrate, &ACUCANInterfaceImpl::on_ccu_can_receive);
handle_CAN_setup(ACUCANInterfaceImpl::EM_CAN, ACUConstants::EM_CAN_baudrate, &ACUCANInterfaceImpl::on_em_can_receive);
Expand Down