Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / src / test / unit / rx_ranges_unittest.cc
blob0aa95e44c4b28d73398d4516f39713d6b9f87ea4
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>
19 #include <stdbool.h>
21 #include <limits.h>
23 extern "C" {
24 #include "platform.h"
25 #include "build/debug.h"
26 #include "drivers/io.h"
27 #include "common/maths.h"
28 #include "pg/pg.h"
29 #include "pg/pg_ids.h"
30 #include "pg/rx.h"
31 #include "fc/rc_controls.h"
32 #include "fc/rc_modes.h"
33 #include "rx/rx.h"
36 #include "unittest_macros.h"
37 #include "gtest/gtest.h"
39 extern "C" {
41 PG_REGISTER(flight3DConfig_t, flight3DConfig, PG_MOTOR_3D_CONFIG, 0);
43 boxBitmask_t rcModeActivationMask;
44 int16_t debug[DEBUG16_VALUE_COUNT];
45 uint8_t debugMode = 0;
47 extern float applyRxChannelRangeConfiguraton(float sample, const rxChannelRangeConfig_t *range);
50 #define RANGE_CONFIGURATION(min, max) new (rxChannelRangeConfig_t) {min, max}
52 TEST(RxChannelRangeTest, TestRxChannelRanges)
54 memset(&rcModeActivationMask, 0, sizeof(rcModeActivationMask)); // BOXFAILSAFE must be OFF
56 // No signal, special condition
57 EXPECT_EQ(0, applyRxChannelRangeConfiguraton(0, RANGE_CONFIGURATION(1000, 2000)));
58 EXPECT_EQ(0, applyRxChannelRangeConfiguraton(0, RANGE_CONFIGURATION(1300, 1700)));
59 EXPECT_EQ(0, applyRxChannelRangeConfiguraton(0, RANGE_CONFIGURATION(900, 2100)));
61 // Exact mapping
62 EXPECT_EQ(1000, applyRxChannelRangeConfiguraton(1000, RANGE_CONFIGURATION(1000, 2000)));
63 EXPECT_EQ(1500, applyRxChannelRangeConfiguraton(1500, RANGE_CONFIGURATION(1000, 2000)));
64 EXPECT_EQ(2000, applyRxChannelRangeConfiguraton(2000, RANGE_CONFIGURATION(1000, 2000)));
65 EXPECT_EQ(750, applyRxChannelRangeConfiguraton(700, RANGE_CONFIGURATION(1000, 2000)));
66 EXPECT_EQ(2250, applyRxChannelRangeConfiguraton(2500, RANGE_CONFIGURATION(1000, 2000)));
68 // Reversed channel
69 EXPECT_EQ(2000, applyRxChannelRangeConfiguraton(1000, RANGE_CONFIGURATION(2000, 1000)));
70 EXPECT_EQ(1500, applyRxChannelRangeConfiguraton(1500, RANGE_CONFIGURATION(2000, 1000)));
71 EXPECT_EQ(1000, applyRxChannelRangeConfiguraton(2000, RANGE_CONFIGURATION(2000, 1000)));
73 // Shifted range
74 EXPECT_EQ(1000, applyRxChannelRangeConfiguraton(900, RANGE_CONFIGURATION(900, 1900)));
75 EXPECT_EQ(1500, applyRxChannelRangeConfiguraton(1400, RANGE_CONFIGURATION(900, 1900)));
76 EXPECT_EQ(2000, applyRxChannelRangeConfiguraton(1900, RANGE_CONFIGURATION(900, 1900)));
77 EXPECT_EQ(750, applyRxChannelRangeConfiguraton(600, RANGE_CONFIGURATION(900, 1900)));
78 EXPECT_EQ(2250, applyRxChannelRangeConfiguraton(2500, RANGE_CONFIGURATION(900, 1900)));
80 // Narrower range than expected
81 EXPECT_EQ(1000, applyRxChannelRangeConfiguraton(1300, RANGE_CONFIGURATION(1300, 1700)));
82 EXPECT_EQ(1500, applyRxChannelRangeConfiguraton(1500, RANGE_CONFIGURATION(1300, 1700)));
83 EXPECT_EQ(2000, applyRxChannelRangeConfiguraton(1700, RANGE_CONFIGURATION(1300, 1700)));
84 EXPECT_EQ(750, applyRxChannelRangeConfiguraton(700, RANGE_CONFIGURATION(1300, 1700)));
85 EXPECT_EQ(2250, applyRxChannelRangeConfiguraton(2500, RANGE_CONFIGURATION(1300, 1700)));
87 // Wider range than expected
88 EXPECT_EQ(1000, applyRxChannelRangeConfiguraton(900, RANGE_CONFIGURATION(900, 2100)));
89 EXPECT_EQ(1500, applyRxChannelRangeConfiguraton(1500, RANGE_CONFIGURATION(900, 2100)));
90 EXPECT_EQ(2000, applyRxChannelRangeConfiguraton(2100, RANGE_CONFIGURATION(900, 2100)));
91 EXPECT_EQ(750, applyRxChannelRangeConfiguraton(600, RANGE_CONFIGURATION(900, 2100)));
92 EXPECT_EQ(2250, applyRxChannelRangeConfiguraton(2700, RANGE_CONFIGURATION(900, 2100)));
94 // extreme out of range
95 EXPECT_EQ(750, applyRxChannelRangeConfiguraton(1, RANGE_CONFIGURATION(1000, 2000)));
96 EXPECT_EQ(750, applyRxChannelRangeConfiguraton(1, RANGE_CONFIGURATION(1300, 1700)));
97 EXPECT_EQ(750, applyRxChannelRangeConfiguraton(1, RANGE_CONFIGURATION(900, 2100)));
99 EXPECT_EQ(2250, applyRxChannelRangeConfiguraton(10000, RANGE_CONFIGURATION(1000, 2000)));
100 EXPECT_EQ(2250, applyRxChannelRangeConfiguraton(10000, RANGE_CONFIGURATION(1300, 1700)));
101 EXPECT_EQ(2250, applyRxChannelRangeConfiguraton(10000, RANGE_CONFIGURATION(900, 2100)));
105 // stubs
106 extern "C" {
108 void failsafeOnRxSuspend(uint32_t ) {}
109 void failsafeOnRxResume(void) {}
110 bool taskUpdateRxMainInProgress() { return true; }
112 uint32_t micros(void) { return 0; }
113 uint32_t millis(void) { return 0; }
115 void rxPwmInit(rxRuntimeState_t *rxRuntimeState, rcReadRawDataFnPtr *callback)
117 UNUSED(rxRuntimeState);
118 UNUSED(callback);
121 bool sbusInit(rxConfig_t *initialRxConfig, rxRuntimeState_t *rxRuntimeState, rcReadRawDataFnPtr *callback)
123 UNUSED(initialRxConfig);
124 UNUSED(rxRuntimeState);
125 UNUSED(callback);
126 return true;
129 bool spektrumInit(rxConfig_t *rxConfig, rxRuntimeState_t *rxRuntimeState, rcReadRawDataFnPtr *callback)
131 UNUSED(rxConfig);
132 UNUSED(rxRuntimeState);
133 UNUSED(callback);
134 return true;
137 bool sumdInit(rxConfig_t *rxConfig, rxRuntimeState_t *rxRuntimeState, rcReadRawDataFnPtr *callback)
139 UNUSED(rxConfig);
140 UNUSED(rxRuntimeState);
141 UNUSED(callback);
142 return true;
145 bool sumhInit(rxConfig_t *rxConfig, rxRuntimeState_t *rxRuntimeState, rcReadRawDataFnPtr *callback)
147 UNUSED(rxConfig);
148 UNUSED(rxRuntimeState);
149 UNUSED(callback);
150 return true;
153 bool crsfRxInit(rxConfig_t *rxConfig, rxRuntimeState_t *rxRuntimeState, rcReadRawDataFnPtr *callback)
155 UNUSED(rxConfig);
156 UNUSED(rxRuntimeState);
157 UNUSED(callback);
158 return true;
161 bool jetiExBusInit(rxConfig_t *rxConfig, rxRuntimeState_t *rxRuntimeState, rcReadRawDataFnPtr *callback)
163 UNUSED(rxConfig);
164 UNUSED(rxRuntimeState);
165 UNUSED(callback);
166 return true;
169 bool ibusInit(rxConfig_t *rxConfig, rxRuntimeState_t *rxRuntimeState, rcReadRawDataFnPtr *callback)
171 UNUSED(rxConfig);
172 UNUSED(rxRuntimeState);
173 UNUSED(callback);
174 return true;
177 bool xBusInit(rxConfig_t *rxConfig, rxRuntimeState_t *rxRuntimeState, rcReadRawDataFnPtr *callback)
179 UNUSED(rxConfig);
180 UNUSED(rxRuntimeState);
181 UNUSED(callback);
182 return true;
185 bool rxMspInit(rxConfig_t *rxConfig, rxRuntimeState_t *rxRuntimeState, rcReadRawDataFnPtr *callback)
187 UNUSED(rxConfig);
188 UNUSED(rxRuntimeState);
189 UNUSED(callback);
190 return true;
193 bool featureIsEnabled(uint32_t) {
194 return false;
197 void featureDisableImmediate(uint32_t) {
200 bool rxMspFrameComplete(void)
202 return false;
205 bool isPPMDataBeingReceived(void)
207 return false;
210 bool isPWMDataBeingReceived(void)
212 return false;
215 void resetPPMDataReceivedState(void)
219 void failsafeOnValidDataReceived(void)
223 void failsafeOnValidDataFailed(void)
227 float pt1FilterGain(float f_cut, float dT)
229 UNUSED(f_cut);
230 UNUSED(dT);
231 return 0.0;
234 void pt1FilterInit(pt1Filter_t *filter, float k)
236 UNUSED(filter);
237 UNUSED(k);
240 float pt1FilterApply(pt1Filter_t *filter, float input)
242 UNUSED(filter);
243 UNUSED(input);
244 return 0.0;
247 void pinioBoxTaskControl(void) {}