mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 13:25:30 +03:00
fix error of unittest
This commit is contained in:
parent
ba53fbddd5
commit
6bc6c36116
4 changed files with 39 additions and 10 deletions
|
@ -91,7 +91,7 @@ static rcdeviceResponseParseContext_t* rcdeviceRespCtxQueuePeekFront(rcdeviceWai
|
|||
return ctx;
|
||||
}
|
||||
|
||||
static rcdeviceResponseParseContext_t* rcdeviceRespCtxQueueShift(rcdeviceWaitingResponseQueue *queue)
|
||||
rcdeviceResponseParseContext_t* rcdeviceRespCtxQueueShift(rcdeviceWaitingResponseQueue *queue)
|
||||
{
|
||||
if (queue == NULL || queue->itemCount == 0) {
|
||||
return NULL;
|
||||
|
@ -387,6 +387,7 @@ void rcdeviceReceive(timeUs_t currentTimeUs)
|
|||
for (int i = 0; i < respCtx->recvRespLen; i++) {
|
||||
crc = crc8_dvb_s2(crc, respCtx->recvBuf[i]);
|
||||
}
|
||||
|
||||
respCtx->result = (crc == 0) ? RCDEVICE_RESP_SUCCESS : RCDEVICE_RESP_INCORRECT_CRC;
|
||||
} else if (respCtx->protocolVer == RCDEVICE_PROTOCOL_RCSPLIT_VERSION) {
|
||||
// do nothing, just call parserFunc
|
||||
|
|
|
@ -160,4 +160,6 @@ bool runcamDeviceSimulateCameraButton(runcamDevice_t *device, uint8_t operation)
|
|||
void runcamDeviceOpen5KeyOSDCableConnection(runcamDevice_t *device, rcdeviceRespParseFunc parseFunc);
|
||||
void runcamDeviceClose5KeyOSDCableConnection(runcamDevice_t *device, rcdeviceRespParseFunc parseFunc);
|
||||
void runcamDeviceSimulate5KeyOSDCableButtonPress(runcamDevice_t *device, uint8_t operation, rcdeviceRespParseFunc parseFunc);
|
||||
void runcamDeviceSimulate5KeyOSDCableButtonRelease(runcamDevice_t *device, rcdeviceRespParseFunc parseFunc);
|
||||
void runcamDeviceSimulate5KeyOSDCableButtonRelease(runcamDevice_t *device, rcdeviceRespParseFunc parseFunc);
|
||||
|
||||
rcdeviceResponseParseContext_t* rcdeviceRespCtxQueueShift(rcdeviceWaitingResponseQueue *queue);
|
|
@ -129,16 +129,13 @@ static void rcdeviceCameraControlProcess(void)
|
|||
|
||||
static void rcdeviceSimulationOSDCableFailed(rcdeviceResponseParseContext_t *ctx)
|
||||
{
|
||||
waitingDeviceResponse = false;
|
||||
if (ctx->command == RCDEVICE_PROTOCOL_COMMAND_5KEY_CONNECTION) {
|
||||
uint8_t operationID = ctx->paramData[0];
|
||||
if (operationID == RCDEVICE_PROTOCOL_5KEY_CONNECTION_CLOSE) {
|
||||
waitingDeviceResponse = false;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
rcdeviceInMenu = false;
|
||||
waitingDeviceResponse = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void rcdeviceSimulationRespHandle(rcdeviceResponseParseContext_t *ctx)
|
||||
|
@ -165,7 +162,6 @@ static void rcdeviceSimulationRespHandle(rcdeviceResponseParseContext_t *ctx)
|
|||
rcdeviceInMenu = true;
|
||||
beeper(BEEPER_CAM_CONNECTION_OPEN);
|
||||
} else {
|
||||
rcdeviceInMenu = false;
|
||||
beeper(BEEPER_CAM_CONNECTION_CLOSE);
|
||||
}
|
||||
} else if (operationID == RCDEVICE_PROTOCOL_5KEY_CONNECTION_CLOSE) {
|
||||
|
|
|
@ -97,6 +97,13 @@ typedef struct testData_s {
|
|||
} testData_t;
|
||||
|
||||
static testData_t testData;
|
||||
extern rcdeviceWaitingResponseQueue watingResponseQueue;
|
||||
|
||||
static void resetRCDeviceStatus()
|
||||
{
|
||||
isButtonPressed = false;
|
||||
rcdeviceInMenu = false;
|
||||
}
|
||||
|
||||
static void clearResponseBuff()
|
||||
{
|
||||
|
@ -104,6 +111,10 @@ static void clearResponseBuff()
|
|||
testData.responseBufCount = 0;
|
||||
memset(testData.responseBufsLen, 0, MAX_RESPONSES_COUNT);
|
||||
memset(testData.responesBufs, 0, MAX_RESPONSES_COUNT * 60);
|
||||
|
||||
while (rcdeviceRespCtxQueueShift(&watingResponseQueue)) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void addResponseData(uint8_t *data, uint8_t dataLen, bool withDataForFlushSerial)
|
||||
|
@ -117,6 +128,9 @@ static void addResponseData(uint8_t *data, uint8_t dataLen, bool withDataForFlus
|
|||
TEST(RCDeviceTest, TestRCSplitInitWithoutPortConfigurated)
|
||||
{
|
||||
runcamDevice_t device;
|
||||
|
||||
resetRCDeviceStatus();
|
||||
|
||||
watingResponseQueue.headPos = 0;
|
||||
watingResponseQueue.tailPos = 0;
|
||||
watingResponseQueue.itemCount = 0;
|
||||
|
@ -129,6 +143,8 @@ TEST(RCDeviceTest, TestRCSplitInitWithoutOpenPortConfigurated)
|
|||
{
|
||||
runcamDevice_t device;
|
||||
|
||||
resetRCDeviceStatus();
|
||||
|
||||
watingResponseQueue.headPos = 0;
|
||||
watingResponseQueue.tailPos = 0;
|
||||
watingResponseQueue.itemCount = 0;
|
||||
|
@ -144,6 +160,8 @@ TEST(RCDeviceTest, TestInitDevice)
|
|||
{
|
||||
runcamDevice_t device;
|
||||
|
||||
resetRCDeviceStatus();
|
||||
|
||||
// test correct response
|
||||
watingResponseQueue.headPos = 0;
|
||||
watingResponseQueue.tailPos = 0;
|
||||
|
@ -169,6 +187,8 @@ TEST(RCDeviceTest, TestInitDeviceWithInvalidResponse)
|
|||
{
|
||||
runcamDevice_t device;
|
||||
|
||||
resetRCDeviceStatus();
|
||||
|
||||
// test correct response data with incorrect len
|
||||
watingResponseQueue.headPos = 0;
|
||||
watingResponseQueue.tailPos = 0;
|
||||
|
@ -235,6 +255,8 @@ TEST(RCDeviceTest, TestInitDeviceWithInvalidResponse)
|
|||
|
||||
TEST(RCDeviceTest, TestWifiModeChangeWithDeviceUnready)
|
||||
{
|
||||
resetRCDeviceStatus();
|
||||
|
||||
// test correct response
|
||||
watingResponseQueue.headPos = 0;
|
||||
watingResponseQueue.tailPos = 0;
|
||||
|
@ -295,6 +317,8 @@ TEST(RCDeviceTest, TestWifiModeChangeWithDeviceUnready)
|
|||
|
||||
TEST(RCDeviceTest, TestWifiModeChangeWithDeviceReady)
|
||||
{
|
||||
resetRCDeviceStatus();
|
||||
|
||||
// test correct response
|
||||
memset(&testData, 0, sizeof(testData));
|
||||
testData.isRunCamSplitOpenPortSupported = true;
|
||||
|
@ -355,6 +379,8 @@ TEST(RCDeviceTest, TestWifiModeChangeWithDeviceReady)
|
|||
|
||||
TEST(RCDeviceTest, TestWifiModeChangeCombine)
|
||||
{
|
||||
resetRCDeviceStatus();
|
||||
|
||||
memset(&testData, 0, sizeof(testData));
|
||||
testData.isRunCamSplitOpenPortSupported = true;
|
||||
testData.isRunCamSplitPortConfigurated = true;
|
||||
|
@ -437,6 +463,8 @@ TEST(RCDeviceTest, TestWifiModeChangeCombine)
|
|||
|
||||
TEST(RCDeviceTest, Test5KeyOSDCableSimulationProtocol)
|
||||
{
|
||||
resetRCDeviceStatus();
|
||||
|
||||
memset(&testData, 0, sizeof(testData));
|
||||
testData.isRunCamSplitOpenPortSupported = true;
|
||||
testData.isRunCamSplitPortConfigurated = true;
|
||||
|
@ -627,12 +655,14 @@ TEST(RCDeviceTest, Test5KeyOSDCableSimulationProtocol)
|
|||
|
||||
TEST(RCDeviceTest, Test5KeyOSDCableSimulationWithout5KeyFeatureSupport)
|
||||
{
|
||||
resetRCDeviceStatus();
|
||||
|
||||
// test simulation without device init
|
||||
rcData[THROTTLE] = FIVE_KEY_JOYSTICK_MID; // THROTTLE Mid
|
||||
rcData[ROLL] = FIVE_KEY_JOYSTICK_MID; // ROLL Mid
|
||||
rcData[PITCH] = FIVE_KEY_JOYSTICK_MID; // PITCH Mid
|
||||
rcData[YAW] = FIVE_KEY_JOYSTICK_MAX; // Yaw High
|
||||
rcdeviceUpdate(0);
|
||||
rcdeviceUpdate(millis() * 1000);
|
||||
EXPECT_EQ(false, rcdeviceInMenu);
|
||||
|
||||
// init device that have not 5 key OSD cable simulation feature
|
||||
|
@ -656,7 +686,7 @@ TEST(RCDeviceTest, Test5KeyOSDCableSimulationWithout5KeyFeatureSupport)
|
|||
// open connection, rcdeviceInMenu will be false if the codes is right
|
||||
uint8_t responseDataOfOpenConnection[] = { 0xCC, 0x11, 0xe7 };
|
||||
addResponseData(responseDataOfOpenConnection, sizeof(responseDataOfOpenConnection), false);
|
||||
rcdeviceUpdate(0);
|
||||
rcdeviceUpdate(millis() * 1000);
|
||||
EXPECT_EQ(false, rcdeviceInMenu);
|
||||
clearResponseBuff();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue