mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 16:25:31 +03:00
Cleanup PWM rx loss detection.
This commit is contained in:
parent
490268d2fc
commit
1ef2d8ea4d
2 changed files with 48 additions and 56 deletions
|
@ -26,35 +26,23 @@ extern "C" {
|
|||
#include "rx/rx.h"
|
||||
|
||||
void rxInit(rxConfig_t *rxConfig);
|
||||
void rxCheckPulse(uint8_t channel, uint16_t pulseDuration);
|
||||
void rxResetFlightChannelStatus(void);
|
||||
bool rxHaveValidFlightChannels(void);
|
||||
void rxUpdateFlightChannelStatus(uint8_t channel, uint16_t pulseDuration);
|
||||
}
|
||||
|
||||
#include "unittest_macros.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
enum {
|
||||
COUNTER_FAILSAFE_ON_VALID_DATA_RECEIVED = 0,
|
||||
};
|
||||
#define CALL_COUNT_ITEM_COUNT 1
|
||||
|
||||
static int callCounts[CALL_COUNT_ITEM_COUNT];
|
||||
|
||||
#define CALL_COUNTER(item) (callCounts[item])
|
||||
|
||||
void resetCallCounters(void) {
|
||||
memset(&callCounts, 0, sizeof(callCounts));
|
||||
}
|
||||
|
||||
typedef struct testData_s {
|
||||
bool isPPMDataBeingReceived;
|
||||
} testData_t;
|
||||
|
||||
static testData_t testData;
|
||||
|
||||
TEST(RxTest, TestFailsafeInformedOfValidData)
|
||||
TEST(RxTest, TestValidFlightChannels)
|
||||
{
|
||||
// given
|
||||
resetCallCounters();
|
||||
memset(&testData, 0, sizeof(testData));
|
||||
|
||||
// and
|
||||
|
@ -67,15 +55,17 @@ TEST(RxTest, TestFailsafeInformedOfValidData)
|
|||
// when
|
||||
rxInit(&rxConfig);
|
||||
|
||||
rxResetFlightChannelStatus();
|
||||
|
||||
for (uint8_t channelIndex = 0; channelIndex < MAX_SUPPORTED_RC_CHANNEL_COUNT; channelIndex++) {
|
||||
rxCheckPulse(channelIndex, 1500);
|
||||
rxUpdateFlightChannelStatus(channelIndex, 1500);
|
||||
}
|
||||
|
||||
// then
|
||||
EXPECT_EQ(1, CALL_COUNTER(COUNTER_FAILSAFE_ON_VALID_DATA_RECEIVED));
|
||||
EXPECT_TRUE(rxHaveValidFlightChannels());
|
||||
}
|
||||
|
||||
TEST(RxTest, TestFailsafeNotInformedOfValidDataWhenStickChannelsAreBad)
|
||||
TEST(RxTest, TestInvalidFlightChannels)
|
||||
{
|
||||
// given
|
||||
memset(&testData, 0, sizeof(testData));
|
||||
|
@ -99,36 +89,36 @@ TEST(RxTest, TestFailsafeNotInformedOfValidDataWhenStickChannelsAreBad)
|
|||
for (uint8_t stickChannelIndex = 0; stickChannelIndex < STICK_CHANNEL_COUNT; stickChannelIndex++) {
|
||||
|
||||
// given
|
||||
resetCallCounters();
|
||||
rxResetFlightChannelStatus();
|
||||
|
||||
for (uint8_t channelIndex = 0; channelIndex < STICK_CHANNEL_COUNT; channelIndex++) {
|
||||
channelPulses[stickChannelIndex] = rxConfig.rx_min_usec;
|
||||
for (uint8_t otherStickChannelIndex = 0; otherStickChannelIndex < STICK_CHANNEL_COUNT; otherStickChannelIndex++) {
|
||||
channelPulses[otherStickChannelIndex] = rxConfig.rx_min_usec;
|
||||
}
|
||||
channelPulses[stickChannelIndex] = rxConfig.rx_min_usec - 1;
|
||||
|
||||
// when
|
||||
for (uint8_t channelIndex = 0; channelIndex < MAX_SUPPORTED_RC_CHANNEL_COUNT; channelIndex++) {
|
||||
rxCheckPulse(channelIndex, channelPulses[channelIndex]);
|
||||
rxUpdateFlightChannelStatus(channelIndex, channelPulses[channelIndex]);
|
||||
}
|
||||
|
||||
// then
|
||||
EXPECT_EQ(0, CALL_COUNTER(COUNTER_FAILSAFE_ON_VALID_DATA_RECEIVED));
|
||||
EXPECT_FALSE(rxHaveValidFlightChannels());
|
||||
|
||||
// given
|
||||
resetCallCounters();
|
||||
rxResetFlightChannelStatus();
|
||||
|
||||
for (uint8_t channelIndex = 0; channelIndex < STICK_CHANNEL_COUNT; channelIndex++) {
|
||||
channelPulses[stickChannelIndex] = rxConfig.rx_max_usec;
|
||||
for (uint8_t otherStickChannelIndex = 0; otherStickChannelIndex < STICK_CHANNEL_COUNT; otherStickChannelIndex++) {
|
||||
channelPulses[otherStickChannelIndex] = rxConfig.rx_max_usec;
|
||||
}
|
||||
channelPulses[stickChannelIndex] = rxConfig.rx_max_usec + 1;
|
||||
|
||||
// when
|
||||
for (uint8_t channelIndex = 0; channelIndex < MAX_SUPPORTED_RC_CHANNEL_COUNT; channelIndex++) {
|
||||
rxCheckPulse(channelIndex, channelPulses[channelIndex]);
|
||||
rxUpdateFlightChannelStatus(channelIndex, channelPulses[channelIndex]);
|
||||
}
|
||||
|
||||
// then
|
||||
EXPECT_EQ(0, CALL_COUNTER(COUNTER_FAILSAFE_ON_VALID_DATA_RECEIVED));
|
||||
EXPECT_FALSE(rxHaveValidFlightChannels());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,9 +127,7 @@ TEST(RxTest, TestFailsafeNotInformedOfValidDataWhenStickChannelsAreBad)
|
|||
|
||||
extern "C" {
|
||||
void failsafeOnRxCycleStarted() {}
|
||||
void failsafeOnValidDataReceived() {
|
||||
callCounts[COUNTER_FAILSAFE_ON_VALID_DATA_RECEIVED]++;
|
||||
}
|
||||
void failsafeOnValidDataReceived() {}
|
||||
|
||||
bool feature(uint32_t mask) {
|
||||
UNUSED(mask);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue