Skip to content

Commit b7044b9

Browse files
committed
#45: Added application mode fcp test
1 parent d4f10d1 commit b7044b9

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

Src/Application/application.h

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* * In failsave mode: set all three commands to 0
3434
* * Pass the actuator commands to the actuators
3535
* * Every FLIGHTCOMPUTER_SEND_PERIOD frame: pass the current data to flightcomputer_send
36+
* * Call imu_start_sampling
3637
*/
3738
void application_init(void);
3839

Tests/LowLevel/Application/application.cpp

+54-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <Mock/actuators.hpp>
2+
#include <Mock/controller.hpp>
23
#include <Mock/error_handler.hpp>
34
#include <Mock/flightcomputer.hpp>
45
#include <Mock/imu.hpp>
@@ -35,14 +36,15 @@ TEST(TEST_NAME, init) {
3536
EXPECT_TRUE(systemHandle.functionGotCalled<system_post_init>());
3637
}
3738

38-
TEST(TEST_NAME, timer) {
39+
TEST(TEST_NAME, timer_mode_fcp) {
3940
auto actuatorsHandle = mock::actuators.getHandle();
4041
auto errorHandlerHandle = mock::error_handler.getHandle();
4142
auto flighcomputerHandle = mock::flightcomputer.getHandle();
4243
auto imuHandle = mock::imu.getHandle();
4344
auto modeHandlerHandle = mock::mode_handler.getHandle();
4445
auto remoteHandlerHandle = mock::remote.getHandle();
4546
auto systemHandle = mock::system.getHandle();
47+
auto controllerHandle = mock::controller.getHandle();
4648

4749
system_timer_16_384ms_callback timer_callback = nullptr;
4850
systemHandle.overrideFunc<system_pre_init>(
@@ -62,4 +64,55 @@ TEST(TEST_NAME, timer) {
6264
EXPECT_TRUE(systemHandle.functionGotCalled<system_post_init>());
6365

6466
// Actual test
67+
modeHandlerHandle.overrideFunc<mode_handler_handle>(
68+
[](imu_data_t *imu_data, remote_data_t *remote_data, flightcomputer_setpoint_t *flightcomputer_setpoint) {
69+
imu_data->heading_mul_16 = 17;
70+
imu_data->pitch_mul_16 = 18;
71+
imu_data->roll_mul_16 = 19;
72+
imu_data->d_heading_mul_16 = 20;
73+
imu_data->d_pitch_mul_16 = 21;
74+
imu_data->d_roll_mul_16 = 22;
75+
imu_data->acc_x_mul_100 = 23;
76+
imu_data->acc_y_mul_100 = 24;
77+
imu_data->acc_z_mul_100 = 25;
78+
imu_data->imu_ok = true;
79+
remote_data->throttle_mixed = 26;
80+
remote_data->elevon_left_mixed = 27;
81+
remote_data->elevon_right_mixed = 28;
82+
remote_data->remote_ok = true;
83+
remote_data->override_active = false;
84+
remote_data->is_armed = true;
85+
flightcomputer_setpoint->roll = 29;
86+
flightcomputer_setpoint->pitch = 30;
87+
flightcomputer_setpoint->motor = 31;
88+
return MODE_FLIGHTCOMPUTER;
89+
});
90+
91+
controllerHandle.overrideFunc<controller_update>(
92+
[](const imu_data_t *imu_data, int16_t roll_setpoint, int16_t pitch_setpoint) {
93+
EXPECT_EQ(imu_data->heading_mul_16, 17);
94+
EXPECT_EQ(imu_data->pitch_mul_16, 18);
95+
EXPECT_EQ(imu_data->roll_mul_16, 19);
96+
EXPECT_EQ(imu_data->d_heading_mul_16, 20);
97+
EXPECT_EQ(imu_data->d_pitch_mul_16, 21);
98+
EXPECT_EQ(imu_data->d_roll_mul_16, 22);
99+
EXPECT_EQ(imu_data->acc_x_mul_100, 23);
100+
EXPECT_EQ(imu_data->acc_y_mul_100, 24);
101+
EXPECT_EQ(imu_data->acc_z_mul_100, 25);
102+
EXPECT_EQ(imu_data->imu_ok, true);
103+
EXPECT_EQ(roll_setpoint, 29);
104+
EXPECT_EQ(pitch_setpoint, 30);
105+
return controller_result_t{.elevon_left = 32, .elevon_right = 33};
106+
});
107+
108+
actuatorsHandle.overrideFunc<actuators_set>([](const actuator_cmd_t *actuator_cmd) {
109+
EXPECT_EQ(actuator_cmd->elevon_left, 32);
110+
EXPECT_EQ(actuator_cmd->elevon_right, 33);
111+
EXPECT_EQ(actuator_cmd->motor, 31);
112+
});
113+
timer_callback();
114+
EXPECT_TRUE(modeHandlerHandle.functionGotCalled<mode_handler_handle>());
115+
EXPECT_TRUE(controllerHandle.functionGotCalled<controller_update>());
116+
EXPECT_TRUE(actuatorsHandle.functionGotCalled<actuators_set>());
117+
EXPECT_TRUE(imuHandle.functionGotCalled<imu_start_sampling>());
65118
}

0 commit comments

Comments
 (0)