MCU
Loading...
Searching...
No Matches
dashboard_interface_test.h
Go to the documentation of this file.
1#include <Arduino.h>
2#include <unity.h>
3
4#include "hytech.h"
5#include "DashboardInterface.h"
6
8
9/* CHAT GPT FUNCTIONS */
10void printMemoryHex(void* ptr, size_t length) {
11 uint8_t* bytePtr = (uint8_t*)ptr;
12 for (size_t i = 0; i < length; ++i) {
13 if (bytePtr[i] < 0x10) {
14 Serial.print("0"); // Add leading zero for values less than 0x10
15 }
16 Serial.print(bytePtr[i], HEX);
17 Serial.print(' ');
18 }
19 Serial.println();
20}
21
22
24{
25 DashboardInterface dash_interface(&dash_CAN_buffer);
26
27 // Chat GPT code that iterates through a truth table
28 for (int i = 0; i < (1 << 10); ++i) { // 2^10 possible combinations
29 DASHBOARD_STATE_t current_state;
30 current_state.start_button = (uint8_t)((i & (1 << 9)) >> 9);
31 current_state.mark_button = (uint8_t)((i & (1 << 8)) >> 8);
32 current_state.mode_button = (uint8_t)((i & (1 << 7)) >> 7);
33 current_state.motor_controller_cycle_button = (uint8_t)((i & (1 << 6)) >> 6);
34 current_state.launch_ctrl_button = (uint8_t)((i & (1 << 5)) >> 5);
35 current_state.torque_mode_button = (uint8_t)((i & (1 << 4)) >> 4);
36 current_state.led_dimmer_button = (uint8_t)((i & (1 << 3)) >> 3);
37 current_state.left_shifter_button = (uint8_t)((i & (1 << 2)) >> 2);
38 current_state.right_shifter_button = (uint8_t)((i & (1 << 1)) >> 1);
39 current_state.shutdown_h_above_threshold = (uint8_t)(i & 1);
40
41 CAN_message_t msg;
42 msg.id= Pack_DASHBOARD_STATE_hytech(&current_state, msg.buf, &msg.len, (uint8_t*) &msg.flags.extended);
43
44 dash_interface.read(msg);
45
46 TEST_ASSERT_EQUAL(current_state.start_button, dash_interface.startButtonPressed() );
47 TEST_ASSERT_EQUAL(current_state.mark_button, dash_interface.specialButtonPressed() );
48 TEST_ASSERT_EQUAL(current_state.mode_button , dash_interface.torqueModeButtonPressed() );
49 TEST_ASSERT_EQUAL(current_state.motor_controller_cycle_button, dash_interface.inverterResetButtonPressed() );
50 TEST_ASSERT_EQUAL(current_state.launch_ctrl_button , dash_interface.launchControlButtonPressed() );
51 TEST_ASSERT_EQUAL(current_state.torque_mode_button , dash_interface.torqueLoadingButtonPressed() );
52 TEST_ASSERT_EQUAL(current_state.led_dimmer_button , dash_interface.nightModeButtonPressed() );
53 TEST_ASSERT_EQUAL(current_state.left_shifter_button, dash_interface.leftShifterButtonPressed() );
54 TEST_ASSERT_EQUAL(current_state.right_shifter_button , dash_interface.rightShifterButtonPressed() );
55 TEST_ASSERT_EQUAL(current_state.shutdown_h_above_threshold , dash_interface.shutdownHAboveThreshold() );
56
57 }
58
59
60
61}
62
64{
65
66 CANBufferType dash_CAN_buffer_2;
67 DashboardInterface dash_interface(&dash_CAN_buffer_2);
68
69 uint8_t LED[12] = {};
70
71 // for (uint64_t i = 0; i < (1 << 48); ++i) { // 2^48 possible combinations
72 // for (int j = 0; j < 12; ++j) {
73 // int color_index = (i >> (j * 2)) & 0b11; // Extract 2 bits for each LED
74 // switch (color_index) {
75 // case 0:
76 // LED[j] = static_cast<uint8_t>(LEDColors_e::OFF);
77 // break;
78 // case 1:
79 // LED[j] = static_cast<uint8_t>(LEDColors_e::ON);
80 // break;
81 // case 2:
82 // LED[j] = static_cast<uint8_t>(LEDColors_e::YELLOW);
83 // break;
84 // case 3:
85 // LED[j] = static_cast<uint8_t>(LEDColors_e::RED);
86 // break;
87 // }
88 // }
89
90 // // Use LED array as needed
91 // // For example, you can print the LED colors:
92 // for (int k = 0; k < 12; ++k) {
93 // Serial.print(LED[k]);
94 // Serial.print(" ");
95 // }
96 // Serial.println();
97 // }
98
99 LED[0] = static_cast<uint8_t>(LEDColors_e::RED);
100 LED[1] = static_cast<uint8_t>(LEDColors_e::YELLOW);
101
102
105
106 // need to make _data in dash interface public:
107 // TODO: investigate using friend class
108 // TEST_ASSERT_EQUAL_UINT8_ARRAY(LED, dash_interface._data.LED, sizeof(LED));
109
110 CAN_message_t packed_message = dash_interface.write();
111
112 uint8_t buffer[sizeof(CAN_message_t)];
113 dash_CAN_buffer_2.pop_front(buffer, sizeof(CAN_message_t));
114
115 delay(1000);
116
117 Serial.println("Printing packed message:");
118 printMemoryHex(&packed_message, sizeof(CAN_message_t));
119 Serial.println("Printing popped message");
120 printMemoryHex(&buffer, sizeof(CAN_message_t));
121
122 CAN_message_t msg;
123 memmove(&msg, buffer, sizeof(CAN_message_t));
124
125 Serial.println("Printing moved message:");
126 printMemoryHex(&msg, sizeof(CAN_message_t));
127
128 TEST_ASSERT_EQUAL_MEMORY(&packed_message, &msg, sizeof(CAN_message_t));
129
130 DASHBOARD_MCU_STATE_t mcu_state;
131
132 Unpack_DASHBOARD_MCU_STATE_hytech(&mcu_state, msg.buf, NULL);
133
134 TEST_ASSERT_EQUAL(LEDColors_e::RED, mcu_state.bots_led);
135 TEST_ASSERT_EQUAL(LEDColors_e::YELLOW, mcu_state.launch_control_led);
136
137}
Circular_Buffer< uint8_t,(uint32_t) 128, sizeof(CAN_message_t)> CANBufferType
void read(const CAN_message_t &can_msg)
void setLED(DashLED_e led, LEDColors_e color)
bool torqueLoadingButtonPressed()
void test_dashboard_circular_buffer(void)
void printMemoryHex(void *ptr, size_t length)
CANBufferType dash_CAN_buffer
void test_dashboard_unpacking_can_message(void)
@ LAUNCH_CONTROL_LED
CAN_message_t msg