From 3b914a6eb40768a4bf7e8f829f715b98d8beb333 Mon Sep 17 00:00:00 2001 From: walkermburns Date: Fri, 9 Feb 2024 18:53:41 -0500 Subject: [PATCH] Tests and comments --- lib/interfaces/include/MCUInterface.h | 27 ++++++++++--------- lib/interfaces/src/MCUInterface.cpp | 2 +- src/main.cpp | 18 ++++++++++--- test/test_interfaces/AMS_interface_test.h | 7 +++++ test/test_interfaces/MCU_interface_test.h | 16 +++++++++++ .../dashboard_interface_test.h | 10 +++---- test/test_interfaces/run_embedded_tests.cpp | 13 +++++---- 7 files changed, 65 insertions(+), 28 deletions(-) diff --git a/lib/interfaces/include/MCUInterface.h b/lib/interfaces/include/MCUInterface.h index 058022acf..93c6987a7 100644 --- a/lib/interfaces/include/MCUInterface.h +++ b/lib/interfaces/include/MCUInterface.h @@ -33,7 +33,6 @@ class MCUInterface /* Outbound CAN message */ MCU_status mcu_status_; - /* CAN Tx buffer */ /* Shutdown circuit input */ bool bms_ok_high; @@ -50,21 +49,24 @@ class MCUInterface public: - MCUInterface(CANBufferType *msg_output_queue, int bms_pin, int imd_pin, int bspd_pin, int sw_ok_pin, int bots_ok_pin, int brake_light_pin): - - - msg_queue_(msg_output_queue), - pin_bms_ok_read_(bms_pin), - pin_imd_ok_read_(imd_pin), - pin_bspd_ok_read_(bspd_pin), - pin_software_ok_read_(sw_ok_pin), - pin_bots_ok_read_(bots_ok_pin), + // PLEASE replace these long lists of parameters with structs + // and put initialization in constructor body instead of initializer list + // my retinas are in pain + MCUInterface(CANBufferType *msg_output_queue, int bms_pin, int imd_pin, + int bspd_pin, int sw_ok_pin, int bots_ok_pin,int brake_light_pin) + // Member initialization list + : msg_queue_(msg_output_queue), pin_bms_ok_read_(bms_pin), pin_imd_ok_read_(imd_pin), + pin_bspd_ok_read_(bspd_pin), pin_software_ok_read_(sw_ok_pin), pin_bots_ok_read_(bots_ok_pin), pin_brake_light_ctrl_(brake_light_pin) { // Set pin mode pinMode(pin_brake_light_ctrl_, OUTPUT); }; - MCUInterface(CANBufferType *msg_output_queue) : MCUInterface(msg_output_queue, DEFAULT_BMS_OK_READ, DEFAULT_IMD_OK_READ, DEFAULT_BSPD_OK_READ, DEFAULT_SOFTWARE_OK_READ, DEFAULT_BOTS_OK_READ, DEFAULT_BRAKE_LIGHT_CTRL){}; + + MCUInterface(CANBufferType *msg_output_queue) + // Overloading constructor + : MCUInterface(msg_output_queue, DEFAULT_BMS_OK_READ, DEFAULT_IMD_OK_READ, + DEFAULT_BSPD_OK_READ, DEFAULT_SOFTWARE_OK_READ, DEFAULT_BOTS_OK_READ, DEFAULT_BRAKE_LIGHT_CTRL){}; /* Initialize shutdown circuit input readings */ void init(); @@ -102,8 +104,7 @@ class MCUInterface bool software_is_ok, bool buzzer_is_on, bool pack_charge_is_critical, - bool button_is_pressed - ); + bool button_is_pressed); }; #endif /* __MCU_INTERFACE_H__ */ diff --git a/lib/interfaces/src/MCUInterface.cpp b/lib/interfaces/src/MCUInterface.cpp index 10812612c..2819bfd6c 100644 --- a/lib/interfaces/src/MCUInterface.cpp +++ b/lib/interfaces/src/MCUInterface.cpp @@ -13,7 +13,7 @@ void MCUInterface::init() { // Should be called from drivetrain } -/* Read shutdown system values */ +/* Read shutdown system values (Not ticked, just in main loop)*/ void MCUInterface::read_mcu_status() { measure_shutdown_circuit_input(); diff --git a/src/main.cpp b/src/main.cpp index 1012a9e6c..9d8d8dfec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,20 +29,27 @@ /* State machine */ #include "MCUStateMachine.h" -/* External info sources */ +/* + DATA SOURCES +*/ + /* Two CAN lines on Main ECU rev15 */ FlexCAN_T4 INV_CAN; // Inverter CAN (now both are on same line) FlexCAN_T4 TELEM_CAN; // telemetry CAN (basically everything except inverters) /* Set up CAN circular buffer */ using CircularBufferType = Circular_Buffer; + /* Sensors */ MCP_ADC<8> ADC1(ADC1_CS); MCP_ADC<4> ADC2(ADC2_CS); MCP_ADC<4> ADC3(ADC3_CS); OrbisBR10 steering1(STEERING_SERIAL); -/* Declare interfaces */ +/* + INTERFACES +*/ + DashboardInterface dashboard(&CAN2_txBuffer); AMSInterface ams_interface(SOFTWARE_OK); WatchdogInterface wd_interface(WATCHDOG_INPUT); @@ -55,12 +62,15 @@ InverterInterfaceType fr_inv(&CAN2_txBuffer, ID_MC2_SETPOINTS_COMMAND, 9, 8); InverterInterfaceType rl_inv(&CAN2_txBuffer, ID_MC3_SETPOINTS_COMMAND, 9, 8); InverterInterfaceType rr_inv(&CAN2_txBuffer, ID_MC4_SETPOINTS_COMMAND, 9, 8); -/* Declare systems */ +/* + SYSTEMS +*/ + SysClock sys_clock; +SteeringSystem steering_system(&steering1); // Unify member reference and pointers? tied by reference in this case BuzzerController buzzer(BUZZER_ON_INTERVAL); SafetySystem safety_system(&ams_interface, &wd_interface); // Tie ams and wd interface to safety system (by pointers) PedalsSystem pedals_system({100, 100, 3000, 3000, 0.1}, {100, 100, 3000, 3000, 0.05}); -SteeringSystem steering_system(&steering1); // Unify member reference and pointers? tied by reference in this case using DrivetrainSystemType = DrivetrainSystem; auto drivetrain = DrivetrainSystemType({&fl_inv, &fr_inv, &rl_inv, &rr_inv}, INVERTER_ENABLING_TIMEOUT_INTERVAL); // Tie inverter interfaces to drivetrain system (by pointers) /* diff --git a/test/test_interfaces/AMS_interface_test.h b/test/test_interfaces/AMS_interface_test.h index 80ffb0e18..a3c157650 100644 --- a/test/test_interfaces/AMS_interface_test.h +++ b/test/test_interfaces/AMS_interface_test.h @@ -43,4 +43,11 @@ void test_AMS_heartbeat() TEST_ASSERT_EQUAL(true, ams_interface.heartbeat_received(millis())); delay(20); TEST_ASSERT_EQUAL(false, ams_interface.heartbeat_received(millis())); + + ams_interface.set_heartbeat(millis()); + TEST_ASSERT_EQUAL(true, ams_interface.heartbeat_received(millis())); + delay(19); + TEST_ASSERT_EQUAL(true, ams_interface.heartbeat_received(millis())); + delay(1); + TEST_ASSERT_EQUAL(false, ams_interface.heartbeat_received(millis())); } \ No newline at end of file diff --git a/test/test_interfaces/MCU_interface_test.h b/test/test_interfaces/MCU_interface_test.h index 1f8209c2c..9857337e9 100644 --- a/test/test_interfaces/MCU_interface_test.h +++ b/test/test_interfaces/MCU_interface_test.h @@ -3,3 +3,19 @@ #include "MCUInterface.h" +Circular_Buffer mcu_CAN_buffer; + +MCUInterface mcu_interface(&mcu_CAN_buffer); + +void test_set_brake_light(void) +{ + mcu_interface.set_brake_light(true); + TEST_ASSERT_EQUAL(HIGH, digitalRead(7)); + mcu_interface.set_brake_light(false); + TEST_ASSERT_EQUAL(LOW, digitalRead(7)); +} + +void test_mcu_circular_buffer(void) +{ + +} \ No newline at end of file diff --git a/test/test_interfaces/dashboard_interface_test.h b/test/test_interfaces/dashboard_interface_test.h index b50d11957..5d361df83 100644 --- a/test/test_interfaces/dashboard_interface_test.h +++ b/test/test_interfaces/dashboard_interface_test.h @@ -4,7 +4,7 @@ #include "hytech.h" #include "DashboardInterface.h" -Circular_Buffer CAN_buffer; +Circular_Buffer dash_CAN_buffer; /* CHAT GPT FUNCTIONS */ void printMemoryHex(void* ptr, size_t length) { @@ -22,7 +22,7 @@ void printMemoryHex(void* ptr, size_t length) { void test_dashboard_unpacking_can_message(void) { - DashboardInterface dash_interface(&CAN_buffer); + DashboardInterface dash_interface(&dash_CAN_buffer); // Chat GPT code that iterates through a truth table for (int i = 0; i < (1 << 10); ++i) { // 2^10 possible combinations @@ -63,8 +63,8 @@ void test_dashboard_unpacking_can_message(void) void test_dashboard_circular_buffer(void) { - Circular_Buffer CAN_buffer_2; - DashboardInterface dash_interface(&CAN_buffer_2); + Circular_Buffer dash_CAN_buffer_2; + DashboardInterface dash_interface(&dash_CAN_buffer_2); uint8_t LED[12] = {}; @@ -110,7 +110,7 @@ void test_dashboard_circular_buffer(void) CAN_message_t packed_message = dash_interface.write(); uint8_t buffer[sizeof(CAN_message_t)]; - CAN_buffer_2.pop_front(buffer, sizeof(CAN_message_t)); + dash_CAN_buffer_2.pop_front(buffer, sizeof(CAN_message_t)); delay(1000); diff --git a/test/test_interfaces/run_embedded_tests.cpp b/test/test_interfaces/run_embedded_tests.cpp index 6d052734d..3bff51ab5 100644 --- a/test/test_interfaces/run_embedded_tests.cpp +++ b/test/test_interfaces/run_embedded_tests.cpp @@ -4,11 +4,12 @@ #include "AMS_interface_test.h" #include "dashboard_interface_test.h" #include "Watchdog_interface_test.h" -#include "can_interface_test.h" +#include "MCU_interface_test.h" +// #include "can_interface_test.h" void setUp(void) { - init_can_interface(); + // init_can_interface(); } void tearDown(void) @@ -26,9 +27,11 @@ int runUnityTests(void) RUN_TEST(test_AMS_heartbeat); /* TEST WATCHDOG */ RUN_TEST(test_watchdog_kick); - // testing can interface - RUN_TEST(test_can_interface_send) - RUN_TEST(test_can_interface_send_and_receive_raw) + /* TEST CAN INTERFACE */ + // RUN_TEST(test_can_interface_send) + // RUN_TEST(test_can_interface_send_and_receive_raw) + /* TEST MCU */ + RUN_TEST(test_set_brake_light); return UNITY_END(); }