Bump clang version to 18 (#14116)
[betaflight.git] / src / test / unit / vtx_msp_unittest.cc
blob99a5816419b24af38c17475920f2ebe5b6b746a7
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"
26 #include "io/vtx.h"
27 #include "io/vtx_msp.h"
28 #include "pg/vtx_table.h"
30 static uint8_t mspFrame[15];
31 extern mspVtxStatus_e mspVtxStatus;
34 #include "unittest_macros.h"
35 #include "gtest/gtest.h"
37 //make clean test_vtx_msp_unittest
38 TEST(VtxMspUnitTest, TestVtxMspPacket)
40 vtxSettingsConfigMutable()->band = 1;
41 vtxSettingsConfigMutable()->channel = 2;
42 vtxSettingsConfigMutable()->power = 3;
43 vtxSettingsConfigMutable()->freq = 5800;
44 vtxSettingsConfigMutable()->pitModeFreq = 5300;
45 vtxSettingsConfigMutable()->lowPowerDisarm = VTX_LOW_POWER_DISARM_ALWAYS;
47 vtxTableConfigMutable()->bands = 4;
48 vtxTableConfigMutable()->channels = 5;
49 vtxTableConfigMutable()->powerLevels = 6;
51 uint8_t expectedFrame[15] = {5, 1, 2, 1, 0, 168, 22, 0, 1, 180, 20, 1, 4, 5, 6};
53 prepareMspFrame(mspFrame);
55 for (int i = 0; i < 15; i++) {
56 EXPECT_EQ(expectedFrame[i], mspFrame[i]);
60 TEST(VtxMspUnitTest, TestVtxMspReady)
62 mspVtxStatus = MSP_VTX_STATUS_OFFLINE;
63 vtxTableConfigMutable()->bands = 0;
64 vtxTableConfigMutable()->channels = 0;
65 vtxTableConfigMutable()->powerLevels = 0;
67 setMspVtxDeviceStatusReady(0);
69 EXPECT_EQ(MSP_VTX_STATUS_OFFLINE, mspVtxStatus);
71 vtxTableConfigMutable()->bands = 1;
72 vtxTableConfigMutable()->channels = 1;
73 vtxTableConfigMutable()->powerLevels = 1;
75 setMspVtxDeviceStatusReady(1); // testing wrong descriptor
77 EXPECT_EQ(MSP_VTX_STATUS_OFFLINE, mspVtxStatus);
79 setMspVtxDeviceStatusReady(0);
81 EXPECT_EQ(MSP_VTX_STATUS_READY, mspVtxStatus);
84 // STUBS
86 extern "C" {
88 #include "build/debug.h"
89 #include "fc/rc_modes.h"
90 #include "rx/rx.h"
91 #include "io/serial.h"
92 #include "msp/msp.h"
94 uint8_t debugMode = 0;
95 int16_t debug[DEBUG16_VALUE_COUNT];
97 uint8_t cliMode = 0;
98 rxRuntimeState_t rxRuntimeState = rxRuntimeState_t();
99 static serialPortConfig_t *findSerialPortConfig_stub_retval;
101 bool IS_RC_MODE_ACTIVE(boxId_e) {return false;}
102 void beeperConfirmationBeeps(uint8_t) {}
103 void saveConfigAndNotify(void) {}
104 void crsfRxSendTelemetryData(void) {}
105 void crsfRxWriteTelemetryData(const void *, int) {}
106 bool failsafeIsActive(void) {return false;}
107 const serialPortConfig_t *findSerialPortConfig(serialPortFunction_e) {return findSerialPortConfig_stub_retval;}
108 bool isRangeActive(uint8_t , const channelRange_t *) {return true;}
109 int mspSerialPush(serialPortIdentifier_e, uint8_t, uint8_t *, int, mspDirection_e, mspVersion_e) {return 0;}
110 void tfp_sprintf(char *, char*, ...) {}
112 mspDescriptor_t getMspSerialPortDescriptor(const uint8_t ) {return 0;}
113 mspDescriptor_t getMspTelemetryDescriptor(void) {return 0;}
115 void mspCmsUpdateStatusString(void) {}