Improved fixed wing detection. (#9186)
[betaflight.git] / src / test / unit / vtx_unittest.cc
blob62662b4e17aee5cae6f4490971c9cd2cd34307bb
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdint.h>
20 extern "C" {
21 #include "blackbox/blackbox.h"
22 #include "build/debug.h"
23 #include "common/maths.h"
24 #include "config/feature.h"
25 #include "pg/pg.h"
26 #include "pg/pg_ids.h"
27 #include "pg/rx.h"
28 #include "config/config.h"
29 #include "fc/controlrate_profile.h"
30 #include "fc/core.h"
31 #include "fc/rc_controls.h"
32 #include "fc/rc_modes.h"
33 #include "fc/runtime_config.h"
34 #include "flight/failsafe.h"
35 #include "flight/imu.h"
36 #include "flight/mixer.h"
37 #include "flight/pid.h"
38 #include "flight/servos.h"
39 #include "io/beeper.h"
40 #include "io/gps.h"
41 #include "io/vtx.h"
42 #include "rx/rx.h"
43 #include "scheduler/scheduler.h"
44 #include "sensors/acceleration.h"
45 #include "sensors/gyro.h"
46 #include "telemetry/telemetry.h"
48 vtxSettingsConfig_t vtxGetSettings(void);
50 PG_REGISTER(accelerometerConfig_t, accelerometerConfig, PG_ACCELEROMETER_CONFIG, 0);
51 PG_REGISTER(blackboxConfig_t, blackboxConfig, PG_BLACKBOX_CONFIG, 0);
52 PG_REGISTER(gyroConfig_t, gyroConfig, PG_GYRO_CONFIG, 0);
53 PG_REGISTER(mixerConfig_t, mixerConfig, PG_MIXER_CONFIG, 0);
54 PG_REGISTER(pidConfig_t, pidConfig, PG_PID_CONFIG, 0);
55 PG_REGISTER(rxConfig_t, rxConfig, PG_RX_CONFIG, 0);
56 PG_REGISTER(servoConfig_t, servoConfig, PG_SERVO_CONFIG, 0);
57 PG_REGISTER(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG, 0);
58 PG_REGISTER(telemetryConfig_t, telemetryConfig, PG_TELEMETRY_CONFIG, 0);
59 PG_REGISTER(failsafeConfig_t, failsafeConfig, PG_FAILSAFE_CONFIG, 0);
61 float rcCommand[4];
62 int16_t rcData[MAX_SUPPORTED_RC_CHANNEL_COUNT];
63 uint16_t averageSystemLoadPercent = 0;
64 uint8_t cliMode = 0;
65 uint8_t debugMode = 0;
66 int16_t debug[DEBUG16_VALUE_COUNT];
67 pidProfile_t *currentPidProfile;
68 controlRateConfig_t *currentControlRateProfile;
69 attitudeEulerAngles_t attitude;
70 gpsSolutionData_t gpsSol;
71 uint32_t targetPidLooptime;
72 bool cmsInMenu = false;
73 float axisPID_P[3], axisPID_I[3], axisPID_D[3], axisPIDSum[3];
74 rxRuntimeState_t rxRuntimeState = {};
77 uint32_t simulationFeatureFlags = 0;
78 uint32_t simulationTime = 0;
79 bool gyroCalibDone = false;
80 bool simulationHaveRx = false;
82 #include "gtest/gtest.h"
84 TEST(VtxTest, PitMode)
86 // given
87 modeActivationConditionsMutable(0)->auxChannelIndex = 0;
88 modeActivationConditionsMutable(0)->modeId = BOXVTXPITMODE;
89 modeActivationConditionsMutable(0)->range.startStep = CHANNEL_VALUE_TO_STEP(1750);
90 modeActivationConditionsMutable(0)->range.endStep = CHANNEL_VALUE_TO_STEP(CHANNEL_RANGE_MAX);
92 analyzeModeActivationConditions();
94 // and
95 vtxSettingsConfigMutable()->band = 0;
96 vtxSettingsConfigMutable()->freq = 5800;
97 vtxSettingsConfigMutable()->pitModeFreq = 5300;
99 // expect
100 EXPECT_EQ(5800, vtxGetSettings().freq);
102 // and
103 // enable vtx pit mode
104 rcData[AUX1] = 1800;
106 // when
107 updateActivatedModes();
109 // expect
110 EXPECT_TRUE(IS_RC_MODE_ACTIVE(BOXVTXPITMODE));
111 EXPECT_EQ(5300, vtxGetSettings().freq);
114 // STUBS
115 extern "C" {
116 uint32_t micros(void) { return simulationTime; }
117 uint32_t millis(void) { return micros() / 1000; }
118 bool rxIsReceivingSignal(void) { return simulationHaveRx; }
120 bool featureIsEnabled(uint32_t f) { return simulationFeatureFlags & f; }
121 void warningLedFlash(void) {}
122 void warningLedDisable(void) {}
123 void warningLedUpdate(void) {}
124 void beeper(beeperMode_e) {}
125 void beeperConfirmationBeeps(uint8_t) {}
126 void beeperWarningBeeps(uint8_t) {}
127 void beeperSilence(void) {}
128 void systemBeep(bool) {}
129 void saveConfigAndNotify(void) {}
130 void blackboxFinish(void) {}
131 bool accIsCalibrationComplete(void) { return true; }
132 bool isBaroCalibrationComplete(void) { return true; }
133 bool isGyroCalibrationComplete(void) { return gyroCalibDone; }
134 void gyroStartCalibration(bool) {}
135 bool isFirstArmingGyroCalibrationRunning(void) { return false; }
136 void pidController(const pidProfile_t *, timeUs_t) {}
137 void pidStabilisationState(pidStabilisationState_e) {}
138 void mixTable(timeUs_t , uint8_t) {};
139 void writeMotors(void) {};
140 void writeServos(void) {};
141 bool calculateRxChannelsAndUpdateFailsafe(timeUs_t) { return true; }
142 bool isMixerUsingServos(void) { return false; }
143 void gyroUpdate(timeUs_t) {}
144 timeDelta_t getTaskDeltaTime(cfTaskId_e) { return 0; }
145 void updateRSSI(timeUs_t) {}
146 bool failsafeIsMonitoring(void) { return false; }
147 void failsafeStartMonitoring(void) {}
148 void failsafeUpdateState(void) {}
149 bool failsafeIsActive(void) { return false; }
150 void pidResetIterm(void) {}
151 void updateAdjustmentStates(void) {}
152 void processRcAdjustments(controlRateConfig_t *) {}
153 void updateGpsWaypointsAndMode(void) {}
154 void mspSerialReleaseSharedTelemetryPorts(void) {}
155 void telemetryCheckState(void) {}
156 void mspSerialAllocatePorts(void) {}
157 void gyroReadTemperature(void) {}
158 void updateRcCommands(void) {}
159 void applyAltHold(void) {}
160 void resetYawAxis(void) {}
161 int16_t calculateThrottleAngleCorrection(uint8_t) { return 0; }
162 void processRcCommand(void) {}
163 void updateGpsStateForHomeAndHoldMode(void) {}
164 void blackboxUpdate(timeUs_t) {}
165 void transponderUpdate(timeUs_t) {}
166 void GPS_reset_home_position(void) {}
167 void accStartCalibration(void) {}
168 void baroSetGroundLevel(void) {}
169 void changePidProfile(uint8_t) {}
170 void changeControlRateProfile(uint8_t) {}
171 void dashboardEnablePageCycling(void) {}
172 void dashboardDisablePageCycling(void) {}
173 bool imuQuaternionHeadfreeOffsetSet(void) { return true; }
174 void rescheduleTask(cfTaskId_e, uint32_t) {}
175 bool usbCableIsInserted(void) { return false; }
176 bool usbVcpIsConnected(void) { return false; }
177 void pidSetAntiGravityState(bool newState) { UNUSED(newState); }
178 void osdSuppressStats(bool) {}
179 void pidSetItermReset(bool) {}
180 void applyAccelerometerTrimsDelta(rollAndPitchTrims_t*) {}
181 bool isFixedWing(void) { return false; }