Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
test_callbacks.cpp
Go to the documentation of this file.
1#include <unity.h>
2
5
6#define BAMOCAR_VDC_HIGH 0x11
7#define BAMOCAR_VDC_LOW 0x01
8#define RES_READY_TRUE 0x01
9#define RADIO_QUALITY_0 0x00
10#define RADIO_QUALITY_100 0x64
11#define RES_EMG_0 0x00
12#define RES_EMG_3 0x00
13#define RES_OK_0 0x01
14#define RES_OK_3 0x80
15
18CAN_message_t msg;
19
26 std::array<uint8_t, 5> msg;
28 TEST_ASSERT_EQUAL_HEX8(0x00, msg[1]);
29 TEST_ASSERT_EQUAL_HEX8(0x00, msg[2]);
30 TEST_ASSERT_EQUAL_HEX8(0x00, msg[3]);
31 TEST_ASSERT_EQUAL_HEX8(0x00, msg[4]);
32}
33
40 std::array<uint8_t, 5> msg;
41 create_left_wheel_msg(msg, 1002.1231213);
42 TEST_ASSERT_EQUAL_HEX8(0x74, msg[1]);
43 TEST_ASSERT_EQUAL_HEX8(0x87, msg[2]);
44 TEST_ASSERT_EQUAL_HEX8(0x01, msg[3]);
45 TEST_ASSERT_EQUAL_HEX8(0x00, msg[4]);
46}
47
54 std::array<uint8_t, 5> msg;
55 create_left_wheel_msg(msg, -10.324);
56 TEST_ASSERT_EQUAL_HEX8(0x00, msg[1]);
57 TEST_ASSERT_EQUAL_HEX8(0x00, msg[2]);
58 TEST_ASSERT_EQUAL_HEX8(0x00, msg[3]);
59 TEST_ASSERT_EQUAL_HEX8(0x00, msg[4]);
60}
61
68 std::array<uint8_t, 5> msg;
69 create_left_wheel_msg(msg, 0.324235235);
70 TEST_ASSERT_EQUAL_HEX8(0x20, msg[1]);
71 TEST_ASSERT_EQUAL_HEX8(0x00, msg[2]);
72 TEST_ASSERT_EQUAL_HEX8(0x00, msg[3]);
73 TEST_ASSERT_EQUAL_HEX8(0x00, msg[4]);
74}
75
80void test_c1(void) {
81 msg.id = C1_ID;
82 msg.len = 5;
83 msg.buf[0] = HYDRAULIC_LINE;
84 msg.buf[1] = 0x01;
85 msg.buf[2] = 0x01;
86 msg.buf[3] = 0x00;
87 msg.buf[4] = 0x00;
89 TEST_ASSERT_EQUAL(257, sd.sensors_._hydraulic_line_pressure);
90
91 msg.buf[0] = RIGHT_WHEEL_CODE;
92 msg.buf[1] = 0x00;
93 msg.buf[2] = 0x08;
95
96 if (sd.sensors_._right_wheel_rpm == 20.48)
97 TEST_PASS();
98 else
99 TEST_FAIL();
100}
101
106void test_bamocar(void) {
107 sd = SystemData(); // reset ready timestamp
109
111 msg.len = 4;
112 msg.buf[0] = BTB_READY;
113 msg.buf[1] = 0x00;
114 msg.buf[2] = 0x00;
115 msg.buf[3] = 0x00;
117 TEST_ASSERT_EQUAL(false, sd.failure_detection_.ts_on_);
118
119 msg.buf[1] = RES_READY_TRUE;
121 TEST_ASSERT_EQUAL(false, sd.failure_detection_.ts_on_);
122
123 msg.buf[0] = VDC_BUS;
124 msg.buf[2] = BAMOCAR_VDC_HIGH;
126 TEST_ASSERT_EQUAL(true, sd.failure_detection_.ts_on_);
127
128 msg.buf[2] = BAMOCAR_VDC_LOW;
130 TEST_ASSERT_EQUAL(false, sd.failure_detection_.ts_on_);
131}
132
138void test_res_state(void) {
139 msg.id = RES_STATE;
140 msg.len = 8;
141 msg.buf[0] = 0x02; // Assuming emergency signals are set
142 msg.buf[1] = 0x00;
143 msg.buf[2] = 0x00;
144 msg.buf[3] = 0x80;
145 msg.buf[4] = 0x00;
146 msg.buf[5] = 0x00;
147 msg.buf[6] = RADIO_QUALITY_0; // radio quality
148 msg.buf[7] = 0x00;
150 TEST_ASSERT_EQUAL(false, sd.r2d_logics_.r2d);
151 TEST_ASSERT_EQUAL(0, sd.failure_detection_.radio_quality);
152
153 // wait ready timeout
155 while (!time.check()) {
156 }
157
158 msg.buf[6] = RADIO_QUALITY_100; // def radio quality 100
160 TEST_ASSERT_EQUAL(true, sd.r2d_logics_.r2d);
161 TEST_ASSERT_EQUAL(100, sd.failure_detection_.radio_quality);
162
163 // RES ok
164 msg.buf[0] = RES_OK_0;
165 msg.buf[3] = RES_OK_3; // def emg bits
167 TEST_ASSERT_EQUAL(false, sd.failure_detection_.emergencySignal);
168
169 // RES Emergency
170 msg.buf[0] = RES_EMG_0;
171 msg.buf[3] = RES_EMG_3; // def emg bits
173 TEST_ASSERT_EQUAL(true, sd.failure_detection_.emergencySignal);
174}
175
176void setUp() {}
177
178int main(void) {
179 UNITY_BEGIN();
180 RUN_TEST(wss_message_zero_rpm);
181 RUN_TEST(wss_message_high_rpm);
182 RUN_TEST(wss_message_negative_rpm);
183 RUN_TEST(wss_message_small_rpm);
184 RUN_TEST(test_c1);
185 RUN_TEST(test_bamocar);
186 RUN_TEST(test_res_state);
187 return UNITY_END();
188}
#define C1_ID
Definition main.cpp:30
Class that contains definitions of typical messages to send via CAN It serves only as an example of t...
static void parse_message(const CAN_message_t &msg)
Parses the message received from the CAN bus.
Our own implementation of Metro class.
Definition metro.h:13
constexpr auto RIGHT_WHEEL_CODE
constexpr auto RES_STATE
constexpr auto HYDRAULIC_LINE
constexpr auto VDC_BUS
constexpr auto BTB_READY
constexpr unsigned long READY_TIMEOUT_MS
#define BAMO_RESPONSE_ID
Definition logging.h:22
Communicator communicator
Definition main.cpp:11
int _hydraulic_line_pressure
Definition sensors.hpp:9
double _right_wheel_rpm
Definition sensors.hpp:7
The whole model of the system: holds all the data necessary.
R2DLogics r2d_logics_
FailureDetection failure_detection_
Sensors sensors_
#define BAMOCAR_VDC_LOW
#define RES_EMG_0
void wss_message_negative_rpm(void)
Test if the message wheel rpm message is created correctly for a negative rpm value.
SystemData sd
void test_bamocar(void)
Tests if the messages from Bamocar are correctly parsed and the Tractive System State is matching rec...
#define RADIO_QUALITY_100
void setUp()
CAN_message_t msg
int main(void)
#define RES_OK_0
#define BAMOCAR_VDC_HIGH
#define RES_READY_TRUE
void wss_message_small_rpm(void)
Test if the message wheel rpm message is created correctly for a small rpm value.
void test_c1(void)
Tests if the messages from C1 are correctly parsed for Hydraulic Brake Pressure and Right Wheel Rpm's...
void wss_message_high_rpm(void)
Test if the message wheel rpm message is created correctly for a large rpm value.
#define RES_EMG_3
void test_res_state(void)
Tests if the messages from RES are correctly parsed for R2D and Emergency activations,...
#define RADIO_QUALITY_0
#define RES_OK_3
void wss_message_zero_rpm(void)
Test if the message wheel rpm message is created correctly for a 0.0 rpm value.
void create_left_wheel_msg(std::array< uint8_t, 5 > &msg, double value)
Function to create left wheel msg.
Definition utils.hpp:9