Various fixes around Companion trainer mode (#7116)
[opentx.git] / radio / src / tests / conversions.cpp
blob897d5cb59a0486ffb601307ad7279148d9cdb1da
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "gtests.h"
22 #include "storage/conversions/conversions.h"
23 #include "location.h"
25 #if defined(EEPROM_SIZE)
26 void loadEEPROMFile(const char * filename)
28 FILE * f = fopen(filename, "rb");
29 assert(fread(eeprom, 1, EEPROM_SIZE, f) == EEPROM_SIZE);
31 #endif
33 #if defined(PCBX9DP)
34 TEST(Conversions, ConversionX9DPFrom22)
36 loadEEPROMFile(TESTS_PATH "/eeprom_22_x9d+.bin");
38 eepromOpen();
39 eeLoadGeneralSettingsData();
40 convertRadioData_218_to_219(g_eeGeneral);
41 eeConvertModel(0, 218);
42 eeLoadModel(0);
44 EXPECT_EQ(-30, g_eeGeneral.vBatMin);
45 EXPECT_EQ(8, g_eeGeneral.speakerVolume);
46 EXPECT_EQ('e', g_eeGeneral.ttsLanguage[0]);
47 EXPECT_EQ('n', g_eeGeneral.ttsLanguage[1]);
49 EXPECT_EQ(SWSRC_TELEMETRY_STREAMING, g_eeGeneral.customFn[0].swtch);
50 EXPECT_EQ(FUNC_LOGS, g_eeGeneral.customFn[0].func);
51 EXPECT_EQ(20, g_eeGeneral.customFn[0].all.val);
53 EXPECT_ZSTREQ("Tes", g_eeGeneral.switchNames[0]);
54 EXPECT_EQ(SWITCH_3POS, SWITCH_CONFIG(0));
56 EXPECT_ZSTREQ("Test", g_model.header.name);
57 EXPECT_EQ(TMRMODE_COUNT - 1 + SWSRC_SA0, g_model.timers[0].mode);
58 EXPECT_EQ(80, g_model.mixData[0].weight);
59 EXPECT_EQ(-100, g_model.limitData[0].max); // 90.0
60 EXPECT_EQ(80, g_model.expoData[0].weight);
61 EXPECT_EQ(CURVE_REF_CUSTOM, g_model.expoData[0].curve.type);
62 EXPECT_EQ(1, g_model.expoData[0].curve.value);
63 EXPECT_EQ(CURVE_REF_EXPO, g_model.expoData[1].curve.type);
64 EXPECT_EQ(20, g_model.expoData[1].curve.value);
65 EXPECT_EQ(SWASH_TYPE_120X, g_model.swashR.type);
66 EXPECT_EQ(10, g_model.flightModeData[0].gvars[0]);
67 EXPECT_ZSTREQ("Tes", g_model.gvars[0].name);
68 EXPECT_EQ(MODULE_TYPE_R9M_PXX1, g_model.moduleData[EXTERNAL_MODULE].type);
69 EXPECT_EQ(MODULE_SUBTYPE_R9M_FCC, g_model.moduleData[EXTERNAL_MODULE].subType);
70 EXPECT_ZSTREQ("Thr", g_model.inputNames[0]);
71 EXPECT_ZSTREQ("Tes", g_model.telemetrySensors[0].label);
72 EXPECT_EQ(10, g_model.telemetrySensors[0].id);
73 EXPECT_EQ(9, g_model.telemetrySensors[0].frskyInstance.physID);
74 EXPECT_EQ(MIXSRC_FIRST_TELEM, g_model.logicalSw[0].v1);
77 TEST(Conversions, ConversionX9DPFrom23)
79 loadEEPROMFile(TESTS_PATH "/eeprom_23_x9d+.bin");
81 eepromOpen();
82 eeLoadGeneralSettingsData();
83 eeLoadModel(0);
85 EXPECT_EQ(-30, g_eeGeneral.vBatMin);
86 EXPECT_EQ(8, g_eeGeneral.speakerVolume);
87 EXPECT_EQ('e', g_eeGeneral.ttsLanguage[0]);
88 EXPECT_EQ('n', g_eeGeneral.ttsLanguage[1]);
90 EXPECT_EQ(SWSRC_TELEMETRY_STREAMING, g_eeGeneral.customFn[0].swtch);
91 EXPECT_EQ(FUNC_LOGS, g_eeGeneral.customFn[0].func);
92 EXPECT_EQ(20, g_eeGeneral.customFn[0].all.val);
94 EXPECT_ZSTREQ("Tes", g_eeGeneral.switchNames[0]);
95 EXPECT_EQ(SWITCH_3POS, SWITCH_CONFIG(0));
97 EXPECT_ZSTREQ("Test", g_model.header.name);
98 EXPECT_EQ(TMRMODE_COUNT - 1 + SWSRC_SA0, g_model.timers[0].mode);
99 EXPECT_EQ(80, g_model.mixData[0].weight);
100 EXPECT_EQ(-100, g_model.limitData[0].max); // 90.0
101 EXPECT_EQ(80, g_model.expoData[0].weight);
102 EXPECT_EQ(10, g_model.flightModeData[0].gvars[0]);
103 EXPECT_ZSTREQ("Tes", g_model.gvars[0].name);
104 EXPECT_ZSTREQ("Test", g_model.flightModeData[0].name);
106 #if defined(INTERNAL_MODULE_PXX2)
107 EXPECT_EQ(MODULE_TYPE_ISRM_PXX2, g_model.moduleData[INTERNAL_MODULE].type);
108 EXPECT_EQ(MODULE_SUBTYPE_ISRM_PXX2_ACCST_D16, g_model.moduleData[INTERNAL_MODULE].subType);
109 #else
110 EXPECT_EQ(MODULE_TYPE_NONE, g_model.moduleData[INTERNAL_MODULE].type);
111 #endif
113 EXPECT_EQ(MODULE_TYPE_R9M_PXX1, g_model.moduleData[EXTERNAL_MODULE].type);
114 EXPECT_EQ(MODULE_SUBTYPE_R9M_FCC, g_model.moduleData[EXTERNAL_MODULE].subType);
116 EXPECT_ZSTREQ("Rud", g_model.inputNames[0]);
117 EXPECT_ZSTREQ("Tes", g_model.telemetrySensors[0].label);
118 EXPECT_EQ(10, g_model.telemetrySensors[0].id);
119 EXPECT_EQ(10, g_model.telemetrySensors[0].frskyInstance.physID);
120 EXPECT_EQ(MIXSRC_FIRST_TELEM, g_model.logicalSw[0].v1);
122 #endif
124 #if defined(PCBXLITE) && !defined(PCBXLITES)
125 TEST(Conversions, ConversionXLiteFrom22)
127 loadEEPROMFile(TESTS_PATH "/eeprom_22_xlite.bin");
129 eepromOpen();
130 eeLoadGeneralSettingsData();
131 convertRadioData_218_to_219(g_eeGeneral);
132 eeConvertModel(0, 218);
133 eeLoadModel(0);
135 EXPECT_EQ(-30, g_eeGeneral.vBatMin);
136 EXPECT_EQ(8, g_eeGeneral.speakerVolume);
137 EXPECT_EQ('e', g_eeGeneral.ttsLanguage[0]);
138 EXPECT_EQ('n', g_eeGeneral.ttsLanguage[1]);
140 EXPECT_EQ(SWSRC_TELEMETRY_STREAMING, g_eeGeneral.customFn[0].swtch);
141 EXPECT_EQ(FUNC_LOGS, g_eeGeneral.customFn[0].func);
142 EXPECT_EQ(20, g_eeGeneral.customFn[0].all.val);
144 EXPECT_ZSTREQ("Tes", g_eeGeneral.switchNames[0]);
145 EXPECT_EQ(SWITCH_3POS, SWITCH_CONFIG(0));
147 EXPECT_ZSTREQ("Test", g_model.header.name);
148 EXPECT_EQ(MODULE_TYPE_R9M_PXX1, g_model.moduleData[EXTERNAL_MODULE].type);
149 EXPECT_EQ(MODULE_SUBTYPE_R9M_EU, g_model.moduleData[EXTERNAL_MODULE].subType);
150 EXPECT_EQ(80, g_model.mixData[0].weight);
151 EXPECT_EQ(80, g_model.expoData[0].weight);
152 EXPECT_EQ(MIXSRC_FIRST_TRAINER, g_model.mixData[4].srcRaw);
153 EXPECT_EQ(SWSRC_TELEMETRY_STREAMING, g_model.mixData[4].swtch);
154 EXPECT_EQ(SWASH_TYPE_120X, g_model.swashR.type);
155 EXPECT_ZSTREQ("Thr", g_model.inputNames[0]);
157 EXPECT_ZSTREQ("Tes", g_model.telemetrySensors[0].label);
158 EXPECT_EQ(10, g_model.telemetrySensors[0].id);
159 EXPECT_EQ(8, g_model.telemetrySensors[0].frskyInstance.physID);
160 EXPECT_EQ(-100, g_model.limitData[0].max); // 90.0
162 EXPECT_EQ(LS_FUNC_VPOS, g_model.logicalSw[0].func);
163 EXPECT_EQ(MIXSRC_FIRST_TRAINER, g_model.logicalSw[0].v1);
164 EXPECT_EQ(0, g_model.logicalSw[0].v2);
166 EXPECT_EQ(TELEMETRY_SCREEN_TYPE_VALUES, g_model.screensType & 0x03);
167 EXPECT_EQ(MIXSRC_FIRST_TRAINER, g_model.screens[0].lines[0].sources[0]);
168 EXPECT_EQ(MIXSRC_TIMER3, g_model.screens[0].lines[0].sources[1]);
170 #endif
172 #if defined(PCBX7)
173 TEST(Conversions, ConversionX7From22)
175 loadEEPROMFile(TESTS_PATH "/eeprom_22_x7.bin");
177 eepromOpen();
178 eeLoadGeneralSettingsData();
179 convertRadioData_218_to_219(g_eeGeneral);
180 eeConvertModel(0, 218);
181 eeLoadModel(0);
183 EXPECT_EQ(-30, g_eeGeneral.vBatMin);
184 EXPECT_EQ(8, g_eeGeneral.speakerVolume);
185 EXPECT_EQ('e', g_eeGeneral.ttsLanguage[0]);
186 EXPECT_EQ('n', g_eeGeneral.ttsLanguage[1]);
188 EXPECT_EQ(SWSRC_TELEMETRY_STREAMING, g_eeGeneral.customFn[0].swtch);
189 EXPECT_EQ(FUNC_LOGS, g_eeGeneral.customFn[0].func);
190 EXPECT_EQ(20, g_eeGeneral.customFn[0].all.val);
192 EXPECT_ZSTREQ("Tes", g_eeGeneral.switchNames[0]);
193 EXPECT_EQ(SWITCH_3POS, SWITCH_CONFIG(0));
195 EXPECT_ZSTREQ("Test", g_model.header.name);
196 EXPECT_EQ(MODULE_TYPE_R9M_PXX1, g_model.moduleData[EXTERNAL_MODULE].type);
197 EXPECT_EQ(MODULE_SUBTYPE_R9M_EU, g_model.moduleData[EXTERNAL_MODULE].subType);
198 EXPECT_EQ(80, g_model.mixData[0].weight);
199 EXPECT_EQ(80, g_model.expoData[0].weight);
200 EXPECT_EQ(MIXSRC_FIRST_TRAINER, g_model.mixData[4].srcRaw);
201 EXPECT_EQ(SWSRC_TELEMETRY_STREAMING, g_model.mixData[4].swtch);
202 EXPECT_EQ(SWASH_TYPE_120X, g_model.swashR.type);
203 EXPECT_ZSTREQ("Thr", g_model.inputNames[0]);
205 EXPECT_ZSTREQ("Tes", g_model.telemetrySensors[0].label);
206 EXPECT_EQ(10, g_model.telemetrySensors[0].id);
207 EXPECT_EQ(9, g_model.telemetrySensors[0].frskyInstance.physID);
208 EXPECT_EQ(-100, g_model.limitData[0].max); // 90.0
210 EXPECT_EQ(10, g_model.flightModeData[0].gvars[0]);
211 EXPECT_ZSTREQ("FMtest", g_model.flightModeData[1].name);
212 EXPECT_EQ(45, g_model.flightModeData[1].swtch);
213 EXPECT_ZSTREQ("Tes", g_model.gvars[0].name);
215 EXPECT_EQ(LS_FUNC_VPOS, g_model.logicalSw[0].func);
216 EXPECT_EQ(MIXSRC_FIRST_TRAINER, g_model.logicalSw[0].v1);
217 EXPECT_EQ(0, g_model.logicalSw[0].v2);
219 EXPECT_EQ(TELEMETRY_SCREEN_TYPE_VALUES, g_model.screensType & 0x03);
220 EXPECT_EQ(MIXSRC_FIRST_TRAINER, g_model.screens[0].lines[0].sources[0]);
221 EXPECT_EQ(MIXSRC_TIMER3, g_model.screens[0].lines[0].sources[1]);
223 #endif
225 #if defined(PCBX10)
226 TEST(Conversions, ConversionX10From22)
228 simuFatfsSetPaths(TESTS_BUILD_PATH "/model_22_x10/", TESTS_BUILD_PATH "/model_22_x10/");
230 loadRadioSettings("/RADIO/radio.bin");
231 loadModel("model1.bin");
233 EXPECT_EQ(219, g_eeGeneral.version);
235 EXPECT_EQ(100, g_eeGeneral.calib[9].spanNeg);
236 EXPECT_EQ(500, g_eeGeneral.calib[9].mid);
237 EXPECT_EQ(900, g_eeGeneral.calib[9].spanPos);
239 EXPECT_EQ(200, g_eeGeneral.calib[10].spanNeg);
240 EXPECT_EQ(400, g_eeGeneral.calib[10].mid);
241 EXPECT_EQ(600, g_eeGeneral.calib[10].spanPos);
243 EXPECT_EQ(-23, g_eeGeneral.vBatMin);
244 EXPECT_EQ(8, g_eeGeneral.speakerVolume);
245 EXPECT_STRNEQ("en", g_eeGeneral.ttsLanguage);
246 EXPECT_STRNEQ("model1.bin", g_eeGeneral.currModelFilename);
248 EXPECT_EQ(SWSRC_TELEMETRY_STREAMING, g_eeGeneral.customFn[0].swtch);
249 EXPECT_EQ(FUNC_LOGS, g_eeGeneral.customFn[0].func);
250 EXPECT_EQ(20, g_eeGeneral.customFn[0].all.val);
252 EXPECT_EQ(SWSRC_ON, g_eeGeneral.customFn[1].swtch);
253 EXPECT_EQ(FUNC_VOLUME, g_eeGeneral.customFn[1].func);
254 EXPECT_EQ(MIXSRC_RS, g_eeGeneral.customFn[1].all.val);
256 EXPECT_ZSTREQ("Tes", g_eeGeneral.switchNames[0]);
257 EXPECT_EQ(SWITCH_3POS, SWITCH_CONFIG(0));
259 EXPECT_ZSTREQ("BT_X10", g_eeGeneral.bluetoothName);
260 EXPECT_STREQ("Default", g_eeGeneral.themeName);
262 EXPECT_EQ(WHITE, g_eeGeneral.themeData.options[0].unsignedValue);
263 EXPECT_EQ(RED, g_eeGeneral.themeData.options[1].unsignedValue);
265 EXPECT_ZSTREQ("Test", g_model.header.name);
266 EXPECT_EQ(0, g_model.noGlobalFunctions);
267 EXPECT_EQ(0, g_model.beepANACenter);
268 EXPECT_EQ(80, g_model.mixData[0].weight);
269 EXPECT_EQ(MIXSRC_MAX, g_model.mixData[2].srcRaw); // MAX
270 EXPECT_EQ(MIXSRC_LS, g_model.mixData[3].srcRaw); // LS
271 EXPECT_EQ(MIXSRC_FIRST_TRAINER, g_model.mixData[5].srcRaw);
272 EXPECT_EQ(SWSRC_TELEMETRY_STREAMING, g_model.mixData[5].swtch);
273 EXPECT_EQ(-100, g_model.limitData[0].max); // 90.0
274 EXPECT_EQ(80, g_model.expoData[0].weight);
275 EXPECT_EQ(LS_FUNC_VPOS, g_model.logicalSw[0].func);
276 EXPECT_EQ(MIXSRC_FIRST_TRAINER, g_model.logicalSw[0].v1);
277 EXPECT_EQ(0, g_model.logicalSw[0].v2);
278 EXPECT_EQ(MIXSRC_FIRST_TELEM+19*3, g_model.logicalSw[1].v1); // TELE:20
279 EXPECT_EQ(20, g_model.logicalSw[1].v2);
280 EXPECT_EQ(SWSRC_FIRST_LOGICAL_SWITCH, g_model.logicalSw[1].andsw);
281 EXPECT_EQ(SWASH_TYPE_120X, g_model.swashR.type);
282 EXPECT_ZSTREQ("Tes", g_model.flightModeData[0].name);
283 EXPECT_EQ(10, g_model.flightModeData[0].gvars[0]);
284 EXPECT_ZSTREQ("Tes", g_model.gvars[0].name);
285 EXPECT_EQ(MODULE_TYPE_R9M_PXX1, g_model.moduleData[EXTERNAL_MODULE].type);
286 EXPECT_EQ(MODULE_SUBTYPE_R9M_EU, g_model.moduleData[EXTERNAL_MODULE].subType);
287 EXPECT_ZSTREQ("Rud", g_model.inputNames[0]);
288 EXPECT_ZSTREQ("Tes", g_model.telemetrySensors[0].label);
289 EXPECT_EQ(10, g_model.telemetrySensors[0].id);
290 EXPECT_EQ(9, g_model.telemetrySensors[0].frskyInstance.physID);
291 EXPECT_EQ((NUM_POTS + NUM_SLIDERS + 3), g_model.thrTraceSrc); // CH3
293 EXPECT_STREQ("Layout2P1", g_model.screenData[0].layoutName);
294 EXPECT_STREQ("ModelBmp", g_model.screenData[0].layoutData.zones[0].widgetName);
295 EXPECT_STREQ("Value", g_model.topbarData.zones[0].widgetName);
296 EXPECT_EQ(MIXSRC_FIRST_TELEM, g_model.topbarData.zones[0].widgetData.options[0].unsignedValue);
297 EXPECT_EQ(MIXSRC_RS, g_model.screenData[0].layoutData.zones[2].widgetData.options[0].unsignedValue);
299 #endif
301 #if defined(PCBX12S)
302 TEST(Conversions, ConversionX12SFrom22)
304 simuFatfsSetPaths(TESTS_BUILD_PATH "/model_22_x12s/", TESTS_BUILD_PATH "/model_22_x12s/");
306 loadRadioSettings("/RADIO/radio.bin");
307 loadModel("model1.bin");
309 EXPECT_EQ(219, g_eeGeneral.version);
310 EXPECT_EQ(-30, g_eeGeneral.vBatMin);
311 EXPECT_EQ(8, g_eeGeneral.speakerVolume);
312 EXPECT_STRNEQ("en", g_eeGeneral.ttsLanguage);
313 EXPECT_STRNEQ("model1.bin", g_eeGeneral.currModelFilename);
315 EXPECT_EQ(SWSRC_TELEMETRY_STREAMING, g_eeGeneral.customFn[0].swtch);
316 EXPECT_EQ(FUNC_LOGS, g_eeGeneral.customFn[0].func);
317 EXPECT_EQ(20, g_eeGeneral.customFn[0].all.val);
319 EXPECT_EQ(SWSRC_ON, g_eeGeneral.customFn[1].swtch);
320 EXPECT_EQ(FUNC_VOLUME, g_eeGeneral.customFn[1].func);
321 EXPECT_EQ(MIXSRC_RS, g_eeGeneral.customFn[1].all.val);
323 EXPECT_ZSTREQ("Tes", g_eeGeneral.switchNames[0]);
324 EXPECT_EQ(SWITCH_3POS, SWITCH_CONFIG(0));
326 EXPECT_ZSTREQ("BT", g_eeGeneral.bluetoothName);
327 EXPECT_STREQ("Default", g_eeGeneral.themeName);
329 EXPECT_EQ(WHITE, g_eeGeneral.themeData.options[0].unsignedValue);
330 EXPECT_EQ(RED, g_eeGeneral.themeData.options[1].unsignedValue);
332 EXPECT_ZSTREQ("Test", g_model.header.name);
333 EXPECT_EQ(0, g_model.noGlobalFunctions);
334 EXPECT_EQ(0, g_model.beepANACenter);
335 EXPECT_EQ(80, g_model.mixData[0].weight);
336 EXPECT_EQ(MIXSRC_MAX, g_model.mixData[2].srcRaw); // MAX
337 EXPECT_EQ(MIXSRC_LS, g_model.mixData[3].srcRaw); // LS
338 EXPECT_EQ(MIXSRC_FIRST_TRAINER, g_model.mixData[5].srcRaw);
339 EXPECT_EQ(SWSRC_TELEMETRY_STREAMING, g_model.mixData[5].swtch);
340 EXPECT_EQ(-100, g_model.limitData[0].max); // 90.0
341 EXPECT_EQ(80, g_model.expoData[0].weight);
342 EXPECT_EQ(LS_FUNC_VPOS, g_model.logicalSw[0].func);
343 EXPECT_EQ(MIXSRC_FIRST_TRAINER, g_model.logicalSw[0].v1);
344 EXPECT_EQ(0, g_model.logicalSw[0].v2);
345 EXPECT_EQ(MIXSRC_FIRST_TELEM+19*3, g_model.logicalSw[1].v1); // TELE:20
346 EXPECT_EQ(20, g_model.logicalSw[1].v2);
347 EXPECT_EQ(SWSRC_FIRST_LOGICAL_SWITCH, g_model.logicalSw[1].andsw);
348 EXPECT_EQ(SWASH_TYPE_120X, g_model.swashR.type);
349 EXPECT_ZSTREQ("Test", g_model.flightModeData[0].name);
350 EXPECT_EQ(10, g_model.flightModeData[0].gvars[0]);
351 EXPECT_ZSTREQ("Tes", g_model.gvars[0].name);
352 EXPECT_EQ(MODULE_TYPE_R9M_PXX1, g_model.moduleData[EXTERNAL_MODULE].type);
353 EXPECT_EQ(MODULE_SUBTYPE_R9M_EU, g_model.moduleData[EXTERNAL_MODULE].subType);
354 EXPECT_ZSTREQ("Rud", g_model.inputNames[0]);
355 EXPECT_ZSTREQ("Tes", g_model.telemetrySensors[0].label);
356 EXPECT_EQ(10, g_model.telemetrySensors[0].id);
357 EXPECT_EQ(9, g_model.telemetrySensors[0].frskyInstance.physID);
358 EXPECT_EQ((NUM_POTS + NUM_SLIDERS + 3), g_model.thrTraceSrc); // CH3
360 EXPECT_STREQ("Layout2P1", g_model.screenData[0].layoutName);
361 EXPECT_STREQ("ModelBmp", g_model.screenData[0].layoutData.zones[0].widgetName);
362 EXPECT_STREQ("Value", g_model.topbarData.zones[0].widgetName);
363 EXPECT_EQ(MIXSRC_FIRST_TELEM, g_model.topbarData.zones[0].widgetData.options[0].unsignedValue);
364 EXPECT_EQ(MIXSRC_RS, g_model.screenData[0].layoutData.zones[2].widgetData.options[0].unsignedValue);
366 #endif