From fc12c869be1d52248f832fdaae9cf4d43f7b54a4 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 5 Jun 2021 09:44:01 +0200 Subject: [PATCH] WiP: Binary storage format conversion Storage format version is now 220. --- radio/src/dataconstants.h | 42 +---- radio/src/myeeprom.h | 4 +- radio/src/storage/conversions/CMakeLists.txt | 31 +--- .../conversions/conversions_219_220.cpp | 136 +++++++++++++++ .../src/storage/conversions/datastructs_219.h | 155 ++++++++++++++++++ 5 files changed, 296 insertions(+), 72 deletions(-) create mode 100644 radio/src/storage/conversions/conversions_219_220.cpp create mode 100644 radio/src/storage/conversions/datastructs_219.h diff --git a/radio/src/dataconstants.h b/radio/src/dataconstants.h index f7bee9f85..26a4b56d5 100644 --- a/radio/src/dataconstants.h +++ b/radio/src/dataconstants.h @@ -73,17 +73,6 @@ #define MAX_INPUTS 32 #define MAX_TRAINER_CHANNELS 16 #define MAX_TELEMETRY_SENSORS 40 -#elif defined(PCBSKY9X) - #define MAX_MODELS 60 - #define MAX_OUTPUT_CHANNELS 32 // number of real output channels CH1-CH32 - #define MAX_FLIGHT_MODES 9 - #define MAX_MIXERS 64 - #define MAX_EXPOS 32 - #define MAX_LOGICAL_SWITCHES 64 - #define MAX_SPECIAL_FUNCTIONS 64 // number of functions assigned to switches - #define MAX_INPUTS 32 - #define MAX_TRAINER_CHANNELS 16 - #define MAX_TELEMETRY_SENSORS 40 #else #warning "Unknown board!" #endif @@ -137,7 +126,7 @@ enum CurveType { #define MAX_CURVE_POINTS 512 #endif -#if defined(PCBFRSKY) || defined(PCBSKY9X) || defined(PCBNV14) +#if defined(PCBFRSKY) || defined(PCBNV14) #define NUM_MODULES 2 #else #define NUM_MODULES 1 @@ -205,12 +194,6 @@ enum TrainerMode { TRAINER_MODE_SLAVE_BLUETOOTH, TRAINER_MODE_MULTI, }; -#elif defined(PCBSKY9X) -enum ModuleIndex { - EXTERNAL_MODULE, - EXTRA_MODULE, - SPORT_MODULE - }; #endif #define TRAINER_MODE_MIN() TRAINER_MODE_MASTER_TRAINER_JACK @@ -515,21 +498,7 @@ enum SwitchSources { SWSRC_SR2, #endif -#if defined(PCBSKY9X) - SWSRC_ID0 = SWSRC_FIRST_SWITCH, - SWSRC_ID1, - SWSRC_ID2, - SWSRC_THR, - SWSRC_RUD, - SWSRC_ELE, - SWSRC_AIL, - SWSRC_GEA, - SWSRC_TRN, - SWSRC_TRAINER SKIP = SWSRC_TRN, - SWSRC_LAST_SWITCH SKIP = SWSRC_TRN, -#else SWSRC_LAST_SWITCH SKIP = SWSRC_FIRST_SWITCH + STORAGE_NUM_SWITCHES_POSITIONS - 1, -#endif #if NUM_XPOTS > 0 SWSRC_FIRST_MULTIPOS_SWITCH SKIP, @@ -756,15 +725,6 @@ enum MixSources { MIXSRC_SP, LUA_EXPORT("sp", "Switch P") MIXSRC_SQ, LUA_EXPORT("sq", "Switch Q") MIXSRC_SR, LUA_EXPORT("sr", "Switch R") -#endif -#if defined(PCBSKY9X) - MIXSRC_3POS = MIXSRC_FIRST_SWITCH, - MIXSRC_THR, - MIXSRC_RUD, - MIXSRC_ELE, - MIXSRC_AIL, - MIXSRC_GEA, - MIXSRC_TRN, #endif MIXSRC_FIRST_LOGICAL_SWITCH SKIP, MIXSRC_SW1 = MIXSRC_FIRST_LOGICAL_SWITCH, LUA_EXPORT_MULTIPLE("ls", "Logical switch L%d", MAX_LOGICAL_SWITCHES) diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index 6733fc17f..bbf93de8a 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -24,8 +24,8 @@ #include "datastructs.h" #include "libopenui/src/bitfield.h" -#define EEPROM_VER 219 -#define FIRST_CONV_EEPROM_VER 216 +#define EEPROM_VER 220 +#define FIRST_CONV_EEPROM_VER 219 #define GET_MODULE_PPM_POLARITY(idx) g_model.moduleData[idx].ppm.pulsePol #define GET_TRAINER_PPM_POLARITY() g_model.trainerData.pulsePol diff --git a/radio/src/storage/conversions/CMakeLists.txt b/radio/src/storage/conversions/CMakeLists.txt index ac912cd5b..bf49d73c9 100644 --- a/radio/src/storage/conversions/CMakeLists.txt +++ b/radio/src/storage/conversions/CMakeLists.txt @@ -1,37 +1,10 @@ -if(PCB STREQUAL X9D OR PCB STREQUAL X9D+ OR PCB STREQUAL SKY9X OR PCB STREQUAL AR9X) - set(STORAGE_CONVERSIONS 216) -endif() - -if(PCB STREQUAL SKY9X OR PCB STREQUAL AR9X OR PCB STREQUAL 9XRPRO) - set(STORAGE_CONVERSIONS 216) -endif() - -if(PCB STREQUAL X7 OR PCB STREQUAL XLITE OR PCB STREQUAL X9E) - set(STORAGE_CONVERSIONS 218) -endif() - -if(PCB STREQUAL X12S OR PCB STREQUAL X10) - set(STORAGE_CONVERSIONS 218) -endif() +set(STORAGE_CONVERSIONS 219) if(STORAGE_CONVERSIONS) add_definitions(-DSTORAGE_CONVERSIONS=${STORAGE_CONVERSIONS}) set(SRC ${SRC} storage/conversions/conversions.cpp + storage/conversions/conversions_219_220.cpp ) endif() - -if(STORAGE_CONVERSIONS LESS 218) - set(SRC - ${SRC} - storage/conversions/conversions_216_218.cpp - ) -endif() - -if(STORAGE_CONVERSIONS LESS 219) - set(SRC - ${SRC} - storage/conversions/conversions_218_219.cpp - ) -endif() diff --git a/radio/src/storage/conversions/conversions_219_220.cpp b/radio/src/storage/conversions/conversions_219_220.cpp new file mode 100644 index 000000000..e13c74d86 --- /dev/null +++ b/radio/src/storage/conversions/conversions_219_220.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (C) EdgeTX + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "opentx.h" +#include "datastructs_219.h" + +#if defined(COLORLCD) +#include "theme.h" +#endif + +// +// Summary of all changes between 219 & 220 +// +// All Radios: +// =========== +// +// PACK(struct TimerData { +// - int32_t mode:9; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw +// - uint32_t start:23; +// - int32_t value:24; +// + uint32_t start:22; +// + int32_t swtch:10; +// + int32_t value:22; +// + uint32_t mode:3; // timer mode (OFF, ON, Start, THs, TH%, THt) +// uint32_t countdownBeep:2; +// uint32_t minuteBeep:1; +// uint32_t persistent:2; +// int32_t countdownStart:2; +// - uint32_t direction:1; +// NOBACKUP(char name[LEN_TIMER_NAME]); +// }); +// +// +// COLORLCD: +// ========= +// +// - CHKSIZE(CustomScreenData, 610); +// - CHKSIZE(Topbar::PersistentData, 216); +// + CHKSIZE(CustomScreenData, 850); +// + CHKTYPE(TopBarPersistentData, 300); +// +// - CHKSIZE(RadioData, 881); +// - CHKSIZE(ModelData, 9736); +// + CHKSIZE(RadioData, 901); +// + CHKSIZE(ModelData, 11020); +// +// -> RadioData change probably comes from THEME_DATA (added parameter types) +// -> ModelData: +1284 (CustomScreenData x 5 = 1200; TopBar::PersistentData: +84) +// + +typedef TimerData TimerData_v220; + +void convertModelData_219_to_220(ModelData &model) +{ + ModelData* oldModelAllocated = (ModelData*)malloc(sizeof(ModelData)); + ModelData& oldModel = *oldModelAllocated; + + memcpy(&oldModel, &model, sizeof(ModelData)); + ModelData& newModel = (ModelData&)model; + + for (uint8_t i=0; igetName()); + defaultTheme->init(); +#endif + + // + // TODO: convert all names from zchar to "normal" chars + // + // g_model.telemetrySensors[i].label + // g_model.header.name + // g_model.header.bitmap // ???? really ???? + // timer.name + // fm->name + // expo->name + // g_model.inputNames[chn] + // mix->name + // CurveHeader.name + // cfn->play.name + // limit->name + + free(oldSettingsAllocated); +} diff --git a/radio/src/storage/conversions/datastructs_219.h b/radio/src/storage/conversions/datastructs_219.h new file mode 100644 index 000000000..5509b82be --- /dev/null +++ b/radio/src/storage/conversions/datastructs_219.h @@ -0,0 +1,155 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#pragma once + +#define MAX_TIMERS_219 3 +#define MAX_GVARS_219 9 + +#if defined(PCBHORUS) + #define NUM_SWITCHES_219 10 +#elif defined(PCBXLITE) ||defined(PCBXLITES) + #define NUM_SWITCHES_219 6 +#elif defined(RADIO_TLITE) || defined(RADIO_FAMILY_JUMPER_T12) || defined(RADIO_T8) + #define NUM_SWITCHES_219 8 +#elif defined(PCBX7) || defined(PCBX7ACCESS) + #define NUM_SWITCHES_219 8 +#elif defined(PCBX9LITES) + #define NUM_SWITCHES_219 7 +#elif defined(PCBX9LITE) + #define NUM_SWITCHES_219 5 +#elif defined(PCBX9E) + #define NUM_SWITCHES_219 18 +#elif defined(RADIO_X9DP2019) || defined(PCBX9D) || defined(PCBX9DP) + #define NUM_SWITCHES_219 9 +#else + #error "Unsupported Conversion for Radio" +#endif + +#if defined(PCBHORUS) + #define LEN_SWITCH_NAME_219 3 + #define LEN_ANA_NAME_219 3 + #define LEN_MODEL_FILENAME_219 16 + #define LEN_BLUETOOTH_NAME_219 10 +#else + #define LEN_SWITCH_NAME_219 3 + #define LEN_ANA_NAME_219 3 + #define LEN_BLUETOOTH_NAME_219 10 +#endif + +#define LEN_GVAR_NAME_219 3 + +#if defined(PCBHORUS) + #define LEN_MODEL_NAME_219 15 + #define LEN_TIMER_NAME_219 8 + #define LEN_FLIGHT_MODE_NAME_219 10 + #define LEN_BITMAP_NAME_219 14 + #define LEN_EXPOMIX_NAME_219 6 + #define LEN_CHANNEL_NAME_219 6 + #define LEN_INPUT_NAME_219 4 + #define LEN_CURVE_NAME_219 3 + #define LEN_FUNCTION_NAME_219 6 + #define MAX_CURVES_219 32 + #define MAX_CURVE_POINTS_219 512 +#elif LCD_W == 212 + #define LEN_MODEL_NAME_219 12 + #define LEN_TIMER_NAME_219 8 + #define LEN_FLIGHT_MODE_NAME_219 10 + #define LEN_BITMAP_NAME_219 10 + #define LEN_EXPOMIX_NAME_219 6 + #define LEN_CHANNEL_NAME_219 6 + #define LEN_INPUT_NAME_219 4 + #define LEN_CURVE_NAME_219 3 + #define LEN_FUNCTION_NAME_219 8 + #define MAX_CURVES_219 32 + #define MAX_CURVE_POINTS_219 512 +#else + #define LEN_MODEL_NAME_219 10 + #define LEN_TIMER_NAME_219 3 + #define LEN_FLIGHT_MODE_NAME_219 6 + #define LEN_EXPOMIX_NAME_219 6 + #define LEN_CHANNEL_NAME_219 4 + #define LEN_INPUT_NAME_219 3 + #define LEN_CURVE_NAME_219 3 + #define LEN_FUNCTION_NAME_219 6 + #define MAX_CURVES_219 32 + #define MAX_CURVE_POINTS_219 512 +#endif + +#if defined(PCBHORUS) + #define MAX_MODELS_219 60 + #define MAX_OUTPUT_CHANNELS_219 32 // number of real output channels CH1-CH32 + #define MAX_FLIGHT_MODES_219 9 + #define MAX_MIXERS_219 64 + #define MAX_EXPOS_219 64 + #define MAX_LOGICAL_SWITCHES_219 64 + #define MAX_SPECIAL_FUNCTIONS_219 64 // number of functions assigned to switches + #define MAX_SCRIPTS_219 9 + #define MAX_INPUTS_219 32 + #define MAX_TRAINER_CHANNELS_219 16 + #define MAX_TELEMETRY_SENSORS_219 60 + #define MAX_CUSTOM_SCREENS_219 5 +#elif defined(PCBTARANIS) + #define MAX_MODELS_219 60 + #define MAX_OUTPUT_CHANNELS_219 32 // number of real output channels CH1-CH32 + #define MAX_FLIGHT_MODES_219 9 + #define MAX_MIXERS_219 64 + #define MAX_EXPOS_219 64 + #define MAX_LOGICAL_SWITCHES_219 64 + #define MAX_SPECIAL_FUNCTIONS_219 64 // number of functions assigned to switches + #define MAX_SCRIPTS_219 7 + #define MAX_INPUTS_219 32 + #define MAX_TRAINER_CHANNELS_219 16 + #if defined(PCBX9D) || defined(PCBX9DP) || defined(PCBX9E) + #define MAX_TELEMETRY_SENSORS_219 60 + #else + #define MAX_TELEMETRY_SENSORS_219 40 + #endif +#endif + +PACK(typedef struct { + int32_t mode:9; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw + uint32_t start:23; + int32_t value:24; + uint32_t countdownBeep:2; + uint32_t minuteBeep:1; + uint32_t persistent:2; + int32_t countdownStart:2; + uint32_t direction:1; + char name[LEN_TIMER_NAME_219]; +}) TimerData_v219; + +// #include "chksize.h" + +// #define CHKSIZE(x, y) check_size() + +// static inline void check_struct_219() +// { +// #if defined(PCBHORUS) +// CHKSIZE(ModelData_v219, 10664); +// #elif defined(PCBX9E) +// CHKSIZE(ModelData_v219, 6520); +// #elif defined(PCBX9D) +// CHKSIZE(RadioData_v219, 872); +// #endif +// } + +// #undef CHKSIZE +