EEPROM conversions tests added to X12S (COMPANION)

This commit is contained in:
Bertrand Songis
2019-09-03 17:01:25 +02:00
parent b005f5dd6c
commit 6457ad245f
6 changed files with 110 additions and 36 deletions
+11 -11
View File
@@ -94,7 +94,7 @@ uint32_t Boards::getFourCC(Type board)
return 0; return 0;
} }
const int Boards::getEEpromSize(Board::Type board) int Boards::getEEpromSize(Board::Type board)
{ {
switch (board) { switch (board) {
case BOARD_STOCK: case BOARD_STOCK:
@@ -130,7 +130,7 @@ const int Boards::getEEpromSize(Board::Type board)
return 0; return 0;
} }
const int Boards::getFlashSize(Type board) int Boards::getFlashSize(Type board)
{ {
switch (board) { switch (board) {
case BOARD_STOCK: case BOARD_STOCK:
@@ -166,7 +166,7 @@ const int Boards::getFlashSize(Type board)
} }
} }
const SwitchInfo Boards::getSwitchInfo(Board::Type board, int index) SwitchInfo Boards::getSwitchInfo(Board::Type board, int index)
{ {
if (index < 0) if (index < 0)
return {SWITCH_NOT_AVAILABLE, CPN_STR_UNKNOWN_ITEM}; return {SWITCH_NOT_AVAILABLE, CPN_STR_UNKNOWN_ITEM};
@@ -260,7 +260,7 @@ const SwitchInfo Boards::getSwitchInfo(Board::Type board, int index)
return {SWITCH_NOT_AVAILABLE, CPN_STR_UNKNOWN_ITEM}; return {SWITCH_NOT_AVAILABLE, CPN_STR_UNKNOWN_ITEM};
} }
const int Boards::getCapability(Board::Type board, Board::Capability capability) int Boards::getCapability(Board::Type board, Board::Capability capability)
{ {
switch (capability) { switch (capability) {
case Sticks: case Sticks:
@@ -276,7 +276,7 @@ const int Boards::getCapability(Board::Type board, Board::Capability capability)
else if (IS_HORUS_X10(board)) else if (IS_HORUS_X10(board))
return 5; return 5;
else if (IS_HORUS_X12S(board)) else if (IS_HORUS_X12S(board))
return 5; return 3;
else else
return 3; return 3;
@@ -360,7 +360,7 @@ const int Boards::getCapability(Board::Type board, Board::Capability capability)
return 0; return 0;
} }
const QString Boards::getAxisName(int index) QString Boards::getAxisName(int index)
{ {
const QString axes[] = { const QString axes[] = {
tr("Left Horizontal"), tr("Left Horizontal"),
@@ -376,7 +376,7 @@ const QString Boards::getAxisName(int index)
return tr("Unknown"); return tr("Unknown");
} }
const QString Boards::getAnalogInputName(Board::Type board, int index) QString Boards::getAnalogInputName(Board::Type board, int index)
{ {
if (index < 0) if (index < 0)
return CPN_STR_UNKNOWN_ITEM; return CPN_STR_UNKNOWN_ITEM;
@@ -442,8 +442,8 @@ const QString Boards::getAnalogInputName(Board::Type board, int index)
"S1", "S1",
"6P", "6P",
"S2", "S2",
"L1", "S3",
"L2", "S4",
"LS", "LS",
"RS", "RS",
"JSx", "JSx",
@@ -469,12 +469,12 @@ const QString Boards::getAnalogInputName(Board::Type board, int index)
return CPN_STR_UNKNOWN_ITEM; return CPN_STR_UNKNOWN_ITEM;
} }
const bool Boards::isBoardCompatible(Type board1, Type board2) bool Boards::isBoardCompatible(Type board1, Type board2)
{ {
return (getFourCC(board1) == getFourCC(board2)); return (getFourCC(board1) == getFourCC(board2));
} }
const QString Boards::getBoardName(Board::Type board) QString Boards::getBoardName(Board::Type board)
{ {
switch (board) { switch (board) {
case BOARD_STOCK: case BOARD_STOCK:
+8 -8
View File
@@ -170,14 +170,14 @@ class Boards
const bool isBoardCompatible(Board::Type board2) const { return isBoardCompatible(m_boardType, board2); } const bool isBoardCompatible(Board::Type board2) const { return isBoardCompatible(m_boardType, board2); }
static uint32_t getFourCC(Board::Type board); static uint32_t getFourCC(Board::Type board);
static const int getEEpromSize(Board::Type board); static int getEEpromSize(Board::Type board);
static const int getFlashSize(Board::Type board); static int getFlashSize(Board::Type board);
static const Board::SwitchInfo getSwitchInfo(Board::Type board, int index); static Board::SwitchInfo getSwitchInfo(Board::Type board, int index);
static const int getCapability(Board::Type board, Board::Capability capability); static int getCapability(Board::Type board, Board::Capability capability);
static const QString getAxisName(int index); static QString getAxisName(int index);
static const QString getAnalogInputName(Board::Type board, int index); static QString getAnalogInputName(Board::Type board, int index);
static const bool isBoardCompatible(Board::Type board1, Board::Type board2); static bool isBoardCompatible(Board::Type board1, Board::Type board2);
static const QString getBoardName(Board::Type board); static QString getBoardName(Board::Type board);
protected: protected:
+4 -2
View File
@@ -53,13 +53,15 @@ bool GeneralSettings::switchSourceAllowedTaranis(int index) const
bool GeneralSettings::isPotAvailable(int index) const bool GeneralSettings::isPotAvailable(int index) const
{ {
if (index<0 || index>getBoardCapability(getCurrentBoard(), Board::Pots)) return false; if (index < 0 || index > getBoardCapability(getCurrentBoard(), Board::Pots))
return false;
return potConfig[index] != Board::POT_NONE; return potConfig[index] != Board::POT_NONE;
} }
bool GeneralSettings::isSliderAvailable(int index) const bool GeneralSettings::isSliderAvailable(int index) const
{ {
if (index<0 || index>getBoardCapability(getCurrentBoard(), Board::Sliders)) return false; if (index < 0 || index > getBoardCapability(getCurrentBoard(), Board::Sliders))
return false;
return sliderConfig[index] != Board::SLIDER_NONE; return sliderConfig[index] != Board::SLIDER_NONE;
} }
@@ -249,8 +249,7 @@ class SwitchesConversionTable: public ConversionTable {
static SwitchesConversionTable * getInstance(Board::Type board, unsigned int version, unsigned long flags=0) static SwitchesConversionTable * getInstance(Board::Type board, unsigned int version, unsigned long flags=0)
{ {
for (std::list<Cache>::iterator it=internalCache.begin(); it!=internalCache.end(); it++) { for (auto & element : internalCache) {
Cache & element = *it;
if (element.board == board && element.version == version && element.flags == flags) if (element.board == board && element.version == version && element.flags == flags)
return element.table; return element.table;
} }
@@ -261,10 +260,8 @@ class SwitchesConversionTable: public ConversionTable {
} }
static void Cleanup() static void Cleanup()
{ {
for (std::list<Cache>::iterator it=internalCache.begin(); it!=internalCache.end(); it++) { for (auto & element : internalCache) {
Cache & element = *it; delete element.table;
if (element.table)
delete element.table;
} }
internalCache.clear(); internalCache.clear();
} }
@@ -302,7 +299,7 @@ class SourcesConversionTable: public ConversionTable {
for (int i=0; i<CPN_MAX_STICKS + MAX_POTS_SOURCES(board, version) + MAX_SLIDERS_SOURCES(board, version) + Boards::getCapability(board, Board::MouseAnalogs) + MAX_GYRO_ANALOGS(board, version); i++) { for (int i=0; i<CPN_MAX_STICKS + MAX_POTS_SOURCES(board, version) + MAX_SLIDERS_SOURCES(board, version) + Boards::getCapability(board, Board::MouseAnalogs) + MAX_GYRO_ANALOGS(board, version); i++) {
int offset = 0; int offset = 0;
if (version <= 218 && IS_HORUS(board) && i>=CPN_MAX_STICKS+MAX_POTS_STORAGE(board, version)) if (version <= 218 && IS_HORUS_X10(board) && i >= CPN_MAX_STICKS + MAX_POTS_STORAGE(board, version))
offset += 2; offset += 2;
addConversion(RawSource(SOURCE_TYPE_STICK, i + offset), val++); addConversion(RawSource(SOURCE_TYPE_STICK, i + offset), val++);
+82 -7
View File
@@ -101,7 +101,7 @@ TEST(Conversions, ConversionX7From22)
ASSERT_EQ(true, store.load(radioData)); ASSERT_EQ(true, store.load(radioData));
const GeneralSettings& settings = radioData.generalSettings; const GeneralSettings& settings = radioData.generalSettings;
EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY,1), settings.customFn[0].swtch); EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY, 1), settings.customFn[0].swtch);
EXPECT_EQ(FuncLogs, settings.customFn[0].func); EXPECT_EQ(FuncLogs, settings.customFn[0].func);
EXPECT_EQ(20, settings.customFn[0].param); EXPECT_EQ(20, settings.customFn[0].param);
@@ -117,7 +117,7 @@ TEST(Conversions, ConversionX7From22)
EXPECT_EQ(80, model.expoData[0].weight); EXPECT_EQ(80, model.expoData[0].weight);
EXPECT_EQ(RawSource(SOURCE_TYPE_PPM,0), model.mixData[4].srcRaw); EXPECT_EQ(RawSource(SOURCE_TYPE_PPM,0), model.mixData[4].srcRaw);
EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY,1), model.mixData[4].swtch); EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY, 1), model.mixData[4].swtch);
EXPECT_EQ(HELI_SWASH_TYPE_120X, model.swashRingData.type); EXPECT_EQ(HELI_SWASH_TYPE_120X, model.swashRingData.type);
EXPECT_STREQ("Thr", model.inputNames[0]); EXPECT_STREQ("Thr", model.inputNames[0]);
@@ -149,7 +149,7 @@ TEST(Conversions, ConversionXLiteFrom22)
ASSERT_EQ(true, store.load(radioData)); ASSERT_EQ(true, store.load(radioData));
const GeneralSettings& settings = radioData.generalSettings; const GeneralSettings& settings = radioData.generalSettings;
EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY,1), settings.customFn[0].swtch); EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY, 1), settings.customFn[0].swtch);
EXPECT_EQ(FuncLogs, settings.customFn[0].func); EXPECT_EQ(FuncLogs, settings.customFn[0].func);
EXPECT_EQ(20, settings.customFn[0].param); EXPECT_EQ(20, settings.customFn[0].param);
@@ -184,7 +184,6 @@ TEST(Conversions, ConversionXLiteFrom22)
EXPECT_EQ(RawSource(SOURCE_TYPE_SPECIAL,4), screen.body.lines[0].source[1]); EXPECT_EQ(RawSource(SOURCE_TYPE_SPECIAL,4), screen.body.lines[0].source[1]);
} }
bool loadFile(QByteArray & filedata, const QString & filename) bool loadFile(QByteArray & filedata, const QString & filename)
{ {
QFile file(filename); QFile file(filename);
@@ -230,13 +229,13 @@ TEST(Conversions, ConversionX10From22)
EXPECT_STREQ("en", settings.ttsLanguage); EXPECT_STREQ("en", settings.ttsLanguage);
EXPECT_STREQ("model1.bin", settings.currModelFilename); EXPECT_STREQ("model1.bin", settings.currModelFilename);
EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY,1), settings.customFn[0].swtch); EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY, 1), settings.customFn[0].swtch);
EXPECT_EQ(FuncLogs, settings.customFn[0].func); EXPECT_EQ(FuncLogs, settings.customFn[0].func);
EXPECT_EQ(20, settings.customFn[0].param); EXPECT_EQ(20, settings.customFn[0].param);
EXPECT_EQ(RawSwitch(SWITCH_TYPE_ON), settings.customFn[1].swtch); EXPECT_EQ(RawSwitch(SWITCH_TYPE_ON), settings.customFn[1].swtch);
EXPECT_EQ(FuncVolume, settings.customFn[1].func); EXPECT_EQ(FuncVolume, settings.customFn[1].func);
EXPECT_EQ(RawSource(SOURCE_TYPE_STICK,4+5+1).toValue(), settings.customFn[1].param); // RS EXPECT_EQ(RawSource(SOURCE_TYPE_STICK, 4+5+1).toValue(), settings.customFn[1].param); // RS
EXPECT_STREQ("Tes", settings.switchName[0]); EXPECT_STREQ("Tes", settings.switchName[0]);
EXPECT_EQ(Board::SWITCH_3POS, settings.switchConfig[0]); EXPECT_EQ(Board::SWITCH_3POS, settings.switchConfig[0]);
@@ -259,7 +258,7 @@ TEST(Conversions, ConversionX10From22)
EXPECT_EQ(RawSource(SOURCE_TYPE_MAX), model.mixData[2].srcRaw); // MAX EXPECT_EQ(RawSource(SOURCE_TYPE_MAX), model.mixData[2].srcRaw); // MAX
EXPECT_EQ(RawSource(SOURCE_TYPE_STICK, 4+5), model.mixData[3].srcRaw); // LS EXPECT_EQ(RawSource(SOURCE_TYPE_STICK, 4+5), model.mixData[3].srcRaw); // LS
EXPECT_EQ(RawSource(SOURCE_TYPE_PPM, 0), model.mixData[5].srcRaw); EXPECT_EQ(RawSource(SOURCE_TYPE_PPM, 0), model.mixData[5].srcRaw);
EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY,1), model.mixData[5].swtch); EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY, 1), model.mixData[5].swtch);
EXPECT_EQ(900, model.limitData[0].max); // -100 EXPECT_EQ(900, model.limitData[0].max); // -100
EXPECT_EQ(80, model.expoData[0].weight); EXPECT_EQ(80, model.expoData[0].weight);
EXPECT_EQ(LS_FN_VPOS, model.logicalSw[0].func); EXPECT_EQ(LS_FN_VPOS, model.logicalSw[0].func);
@@ -280,3 +279,79 @@ TEST(Conversions, ConversionX10From22)
EXPECT_EQ(9, model.sensorData[0].instance); EXPECT_EQ(9, model.sensorData[0].instance);
EXPECT_EQ(5 + 2 + 3, model.thrTraceSrc); // CH3 EXPECT_EQ(5 + 2 + 3, model.thrTraceSrc); // CH3
} }
TEST(Conversions, ConversionX12SFrom22)
{
QByteArray byteBuffer;
#define USE_OTX
#if defined(USE_OTX)
OtxFormat otx(RADIO_TESTS_PATH "/model_22_x12s.otx");
RadioData radio;
EXPECT_EQ(true, otx.load(radio));
const GeneralSettings& settings = radio.generalSettings;
const ModelData& model = radio.models[0];
#else
ASSERT_EQ(true, loadFile(byteBuffer, RADIO_TESTS_PATH "/model_22_x12s/RADIO/radio.bin"));
GeneralSettings settings;
EXPECT_NE(nullptr, loadRadioSettingsFromByteArray(settings, byteBuffer));
#endif
EXPECT_EQ(-30, settings.vBatMin);
EXPECT_EQ(20, settings.speakerVolume);
EXPECT_STREQ("en", settings.ttsLanguage);
EXPECT_STREQ("model1.bin", settings.currModelFilename);
EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY, 1), settings.customFn[0].swtch);
EXPECT_EQ(FuncLogs, settings.customFn[0].func);
EXPECT_EQ(20, settings.customFn[0].param);
EXPECT_EQ(RawSwitch(SWITCH_TYPE_ON), settings.customFn[1].swtch);
EXPECT_EQ(FuncVolume, settings.customFn[1].func);
EXPECT_EQ(RawSource(SOURCE_TYPE_STICK, 4+5+1).toValue(), settings.customFn[1].param); // RS
EXPECT_STREQ("Tes", settings.switchName[0]);
EXPECT_EQ(Board::SWITCH_3POS, settings.switchConfig[0]);
EXPECT_STREQ("BT", settings.bluetoothName);
EXPECT_STREQ("Default", settings.themeName);
#if !defined(USE_OTX)
byteBuffer.clear();
ASSERT_EQ(true, loadFile(byteBuffer, RADIO_TESTS_PATH "/model_22_x10/MODELS/model1.bin"));
ModelData model;
ASSERT_NE(nullptr, loadModelFromByteArray(model, byteBuffer));
#endif
EXPECT_STREQ("Test", model.name);
EXPECT_EQ(0, model.noGlobalFunctions);
EXPECT_EQ(0, model.beepANACenter);
EXPECT_EQ(80, model.mixData[0].weight);
EXPECT_EQ(RawSource(SOURCE_TYPE_MAX), model.mixData[2].srcRaw); // MAX
EXPECT_EQ(RawSource(SOURCE_TYPE_STICK, 4+5), model.mixData[3].srcRaw); // LS
EXPECT_EQ(RawSource(SOURCE_TYPE_PPM, 0), model.mixData[5].srcRaw);
EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY, 1), model.mixData[5].swtch);
EXPECT_EQ(900, model.limitData[0].max); // -100
EXPECT_EQ(80, model.expoData[0].weight);
EXPECT_EQ(LS_FN_VPOS, model.logicalSw[0].func);
EXPECT_EQ(RawSource(SOURCE_TYPE_PPM,0).toValue(), model.logicalSw[0].val1); // TR1
EXPECT_EQ(0, model.logicalSw[0].val2);
EXPECT_EQ(RawSource(SOURCE_TYPE_TELEMETRY, 19*3).toValue(), model.logicalSw[1].val1); // TELE:20
EXPECT_EQ(20, model.logicalSw[1].val2);
EXPECT_EQ(RawSwitch(SWITCH_TYPE_VIRTUAL,1).toValue(), model.logicalSw[1].andsw);
EXPECT_EQ(HELI_SWASH_TYPE_120X, model.swashRingData.type);
EXPECT_STREQ("Test", model.flightModeData[0].name);
EXPECT_EQ(10, model.flightModeData[0].gvars[0]);
EXPECT_STREQ("Tes", model.gvarData[0].name);
EXPECT_EQ(PULSES_PXX_R9M, model.moduleData[1].protocol);
EXPECT_EQ(MODULE_SUBTYPE_R9M_EU, model.moduleData[1].subType);
EXPECT_STREQ("Rud", model.inputNames[0]);
EXPECT_STREQ("Tes", model.sensorData[0].label);
EXPECT_EQ(10, model.sensorData[0].id);
EXPECT_EQ(9, model.sensorData[0].instance);
EXPECT_EQ(5 + 2 + 3, model.thrTraceSrc); // CH3
}
@@ -59,7 +59,7 @@ int convertSource_218_to_219(int source)
#endif #endif
#if defined(PCBX10) #if defined(PCBX10)
if ((source == MIXSRC_EXT1) || (source == MIXSRC_EXT2)) if (source == MIXSRC_EXT1 || source == MIXSRC_EXT2)
source += 2; source += 2;
#endif #endif