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>
4
5#define BAMOCAR_VDC_HIGH 0x11
6#define BAMOCAR_VDC_LOW 0x01
7#define RES_READY_TRUE 0x01
8#define RADIO_QUALITY_0 0x00
9#define RADIO_QUALITY_100 0x64
10#define RES_EMG_0 0x00
11#define RES_EMG_3 0x00
12#define RES_OK_0 0x01
13#define RES_OK_3 0x80
14
17CAN_message_t msg;
18
25 uint8_t msg[5];
27 TEST_ASSERT_EQUAL_HEX8(0x00, msg[1]);
28 TEST_ASSERT_EQUAL_HEX8(0x00, msg[2]);
29 TEST_ASSERT_EQUAL_HEX8(0x00, msg[3]);
30 TEST_ASSERT_EQUAL_HEX8(0x00, msg[4]);
31}
32
39 uint8_t msg[5];
40 create_left_wheel_msg(msg, 1002.1231213);
41 TEST_ASSERT_EQUAL_HEX8(0x74, msg[1]);
42 TEST_ASSERT_EQUAL_HEX8(0x87, msg[2]);
43 TEST_ASSERT_EQUAL_HEX8(0x01, msg[3]);
44 TEST_ASSERT_EQUAL_HEX8(0x00, msg[4]);
45}
46
53 uint8_t msg[5];
54 create_left_wheel_msg(msg, -10.324);
55 TEST_ASSERT_EQUAL_HEX8(0x00, msg[1]);
56 TEST_ASSERT_EQUAL_HEX8(0x00, msg[2]);
57 TEST_ASSERT_EQUAL_HEX8(0x00, msg[3]);
58 TEST_ASSERT_EQUAL_HEX8(0x00, msg[4]);
59}
60
67 uint8_t msg[5];
68 create_left_wheel_msg(msg, 0.324235235);
69 TEST_ASSERT_EQUAL_HEX8(0x20, msg[1]);
70 TEST_ASSERT_EQUAL_HEX8(0x00, msg[2]);
71 TEST_ASSERT_EQUAL_HEX8(0x00, msg[3]);
72 TEST_ASSERT_EQUAL_HEX8(0x00, msg[4]);
73}
74
79void test_c1(void) {
80 msg.id = C1_ID;
81 msg.len = 5;
82 msg.buf[0] = HYDRAULIC_LINE;
83 msg.buf[1] = 0x01;
84 msg.buf[2] = 0x01;
85 msg.buf[3] = 0x00;
86 msg.buf[4] = 0x00;
88 TEST_ASSERT_EQUAL(257, sd.sensors._hydraulic_line_pressure);
89
90 msg.buf[0] = RIGHT_WHEEL_CODE;
91 msg.buf[1] = 0x00;
92 msg.buf[2] = 0x08;
94
95 if (sd.sensors._right_wheel_rpm == 20.48)
96 TEST_PASS();
97 else
98 TEST_FAIL();
99}
100
105void test_bamocar(void) {
106 sd = SystemData(); // reset ready timestamp
108
110 msg.len = 4;
111 msg.buf[0] = BTB_READY;
112 msg.buf[1] = 0x00;
113 msg.buf[2] = 0x00;
114 msg.buf[3] = 0x00;
116 TEST_ASSERT_EQUAL(false, sd.failureDetection.ts_on);
117
118 msg.buf[1] = RES_READY_TRUE;
120 TEST_ASSERT_EQUAL(false, sd.failureDetection.ts_on);
121
122 msg.buf[0] = VDC_BUS;
123 msg.buf[2] = BAMOCAR_VDC_HIGH;
125 TEST_ASSERT_EQUAL(true, sd.failureDetection.ts_on);
126
127 msg.buf[2] = BAMOCAR_VDC_LOW;
129 TEST_ASSERT_EQUAL(false, sd.failureDetection.ts_on);
130}
131
137void test_res_state(void) {
138
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.r2dLogics.r2d);
151 TEST_ASSERT_EQUAL(0, sd.failureDetection.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.r2dLogics.r2d);
161 TEST_ASSERT_EQUAL(100, sd.failureDetection.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.failureDetection.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.failureDetection.emergencySignal);
174}
175
176
177void setUp() {
178
179}
180
181int main(void) {
182 UNITY_BEGIN();
183 RUN_TEST(wss_message_zero_rpm);
184 RUN_TEST(wss_message_high_rpm);
185 RUN_TEST(wss_message_negative_rpm);
186 RUN_TEST(wss_message_small_rpm);
187 RUN_TEST(test_c1);
188 RUN_TEST(test_bamocar);
189 RUN_TEST(test_res_state);
190 return UNITY_END();
191}
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 auto BAMO_RESPONSE_ID
constexpr auto C1_ID
Communicator communicator
Definition main.cpp:10
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.
Sensors sensors
FailureDetection failureDetection
R2DLogics r2dLogics
constexpr unsigned long READY_TIMEOUT_MS
#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.
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)
SystemData sd
#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(uint8_t *msg, double value)
Function to create left wheel msg.
Definition utils.hpp:8