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/>.
27 #include "build/debug.h"
28 #include "drivers/io.h"
29 #include "fc/rc_controls.h"
31 #include "fc/rc_modes.h"
32 #include "common/maths.h"
33 #include "common/utils.h"
34 #include "config/feature.h"
36 #include "pg/pg_ids.h"
37 #include "io/beeper.h"
39 boxBitmask_t rcModeActivationMask
;
40 int16_t debug
[DEBUG16_VALUE_COUNT
];
41 uint8_t debugMode
= 0;
43 bool isPulseValid(uint16_t pulseDuration
);
45 PG_RESET_TEMPLATE(featureConfig_t
, featureConfig
,
49 PG_REGISTER(flight3DConfig_t
, flight3DConfig
, PG_MOTOR_3D_CONFIG
, 0);
52 #include "unittest_macros.h"
53 #include "gtest/gtest.h"
55 #define DE_ACTIVATE_ALL_BOXES 0
57 typedef struct testData_s
{
58 bool isPPMDataBeingReceived
;
59 bool isPWMDataBeingReceived
;
62 static testData_t testData
;
64 #if 0 //!! valid pulse handling has changed so these test now test removed functions
65 TEST(RxTest
, TestValidFlightChannels
)
68 memset(&testData
, 0, sizeof(testData
));
69 memset(&rcModeActivationMask
, 0, sizeof(rcModeActivationMask
)); // BOXFAILSAFE must be OFF
72 rxConfigMutable()->rx_min_usec
= 1000;
73 rxConfigMutable()->rx_max_usec
= 2000;
76 modeActivationConditionsMutable(0)->auxChannelIndex
= 0;
77 modeActivationConditionsMutable(0)->modeId
= BOXARM
;
78 modeActivationConditionsMutable(0)->range
.startStep
= CHANNEL_VALUE_TO_STEP(CHANNEL_RANGE_MIN
);
79 modeActivationConditionsMutable(0)->range
.endStep
= CHANNEL_VALUE_TO_STEP(1600);
81 analyzeModeActivationConditions();
86 // then (ARM channel should be positioned just 1 step above active range to init to OFF)
87 EXPECT_EQ(1625, rcData
[modeActivationConditions(0)->auxChannelIndex
+ NON_AUX_CHANNEL_COUNT
]);
90 rxResetFlightChannelStatus();
93 for (uint8_t channelIndex
= 0; channelIndex
< MAX_SUPPORTED_RC_CHANNEL_COUNT
; channelIndex
++) {
94 bool validPulse
= isPulseValid(1500);
95 rxUpdateFlightChannelStatus(channelIndex
, validPulse
);
99 EXPECT_TRUE(rxHaveValidFlightChannels());
102 TEST(RxTest
, TestValidFlightChannelsHighArm
)
105 memset(&testData
, 0, sizeof(testData
));
106 memset(&rcModeActivationMask
, 0, sizeof(rcModeActivationMask
)); // BOXFAILSAFE must be OFF
109 rxConfigMutable()->rx_min_usec
= 1000;
110 rxConfigMutable()->rx_max_usec
= 2000;
113 modeActivationConditionsMutable(0)->auxChannelIndex
= 0;
114 modeActivationConditionsMutable(0)->modeId
= BOXARM
;
115 modeActivationConditionsMutable(0)->range
.startStep
= CHANNEL_VALUE_TO_STEP(1400);
116 modeActivationConditionsMutable(0)->range
.endStep
= CHANNEL_VALUE_TO_STEP(CHANNEL_RANGE_MAX
);
118 analyzeModeActivationConditions();
123 // then (ARM channel should be positioned just 1 step below active range to init to OFF)
124 EXPECT_EQ(1375, rcData
[modeActivationConditions(0)->auxChannelIndex
+ NON_AUX_CHANNEL_COUNT
]);
127 rxResetFlightChannelStatus();
130 for (uint8_t channelIndex
= 0; channelIndex
< MAX_SUPPORTED_RC_CHANNEL_COUNT
; channelIndex
++) {
131 bool validPulse
= isPulseValid(1500);
132 rxUpdateFlightChannelStatus(channelIndex
, validPulse
);
136 EXPECT_TRUE(rxHaveValidFlightChannels());
139 TEST(RxTest
, TestInvalidFlightChannels
)
142 memset(&testData
, 0, sizeof(testData
));
145 rxConfigMutable()->rx_min_usec
= 1000;
146 rxConfigMutable()->rx_max_usec
= 2000;
149 modeActivationConditionsMutable(0)->auxChannelIndex
= 0;
150 modeActivationConditionsMutable(0)->modeId
= BOXARM
;
151 modeActivationConditionsMutable(0)->range
.startStep
= CHANNEL_VALUE_TO_STEP(1400);
152 modeActivationConditionsMutable(0)->range
.endStep
= CHANNEL_VALUE_TO_STEP(CHANNEL_RANGE_MAX
);
154 analyzeModeActivationConditions();
157 uint16_t channelPulses
[MAX_SUPPORTED_RC_CHANNEL_COUNT
];
158 memset(&channelPulses
, 1500, sizeof(channelPulses
));
163 // then (ARM channel should be positioned just 1 step below active range to init to OFF)
164 EXPECT_EQ(1375, rcData
[modeActivationConditions(0)->auxChannelIndex
+ NON_AUX_CHANNEL_COUNT
]);
167 for (uint8_t stickChannelIndex
= 0; stickChannelIndex
< STICK_CHANNEL_COUNT
; stickChannelIndex
++) {
169 rxResetFlightChannelStatus();
171 for (uint8_t otherStickChannelIndex
= 0; otherStickChannelIndex
< STICK_CHANNEL_COUNT
; otherStickChannelIndex
++) {
172 channelPulses
[otherStickChannelIndex
] = rxConfig()->rx_min_usec
;
174 channelPulses
[stickChannelIndex
] = rxConfig()->rx_min_usec
- 1;
177 for (uint8_t channelIndex
= 0; channelIndex
< MAX_SUPPORTED_RC_CHANNEL_COUNT
; channelIndex
++) {
178 bool validPulse
= isPulseValid(channelPulses
[channelIndex
]);
179 rxUpdateFlightChannelStatus(channelIndex
, validPulse
);
183 EXPECT_FALSE(rxHaveValidFlightChannels());
186 rxResetFlightChannelStatus();
188 for (uint8_t otherStickChannelIndex
= 0; otherStickChannelIndex
< STICK_CHANNEL_COUNT
; otherStickChannelIndex
++) {
189 channelPulses
[otherStickChannelIndex
] = rxConfig()->rx_max_usec
;
191 channelPulses
[stickChannelIndex
] = rxConfig()->rx_max_usec
+ 1;
194 for (uint8_t channelIndex
= 0; channelIndex
< MAX_SUPPORTED_RC_CHANNEL_COUNT
; channelIndex
++) {
195 bool validPulse
= isPulseValid(channelPulses
[channelIndex
]);
196 rxUpdateFlightChannelStatus(channelIndex
, validPulse
);
200 EXPECT_FALSE(rxHaveValidFlightChannels());
208 void failsafeOnValidDataFailed() {}
209 void failsafeOnValidDataReceived() {}
211 void failsafeOnRxSuspend(uint32_t ) {}
212 void failsafeOnRxResume(void) {}
213 bool failsafeIsReceivingRxData(void) { return true; }
215 uint32_t micros(void) { return 0; }
216 uint32_t millis(void) { return 0; }
218 bool isPPMDataBeingReceived(void) {
219 return testData
.isPPMDataBeingReceived
;
222 bool isPWMDataBeingReceived(void) {
223 return testData
.isPWMDataBeingReceived
;
226 void resetPPMDataReceivedState(void) {}
227 bool rxMspFrameComplete(void) { return false; }
229 void crsfRxInit(const rxConfig_t
*, rxRuntimeState_t
*) {}
230 void ibusInit(const rxConfig_t
*, rxRuntimeState_t
*) {}
231 void jetiExBusInit(const rxConfig_t
*, rxRuntimeState_t
*) {}
232 void sbusInit(const rxConfig_t
*, rxRuntimeState_t
*) {}
233 void spektrumInit(const rxConfig_t
*, rxRuntimeState_t
*) {}
234 void sumdInit(const rxConfig_t
*, rxRuntimeState_t
*) {}
235 void sumhInit(const rxConfig_t
*, rxRuntimeState_t
*) {}
236 void xBusInit(const rxConfig_t
*, rxRuntimeState_t
*) {}
237 void rxMspInit(const rxConfig_t
*, rxRuntimeState_t
*) {}
238 void rxPwmInit(const rxConfig_t
*, rxRuntimeState_t
*) {}
239 bool taskUpdateRxMainInProgress() { return true; }
240 float pt1FilterGain(float f_cut
, float dT
)
247 void pt1FilterInit(pt1Filter_t
*filter
, float k
)
253 float pt1FilterApply(pt1Filter_t
*filter
, float input
)
260 void pinioBoxTaskControl(void) {}