From 9c014489cb5f9d7a3f7230a4916e198a5b166676 Mon Sep 17 00:00:00 2001 From: Jye <14170229+JyeSmith@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:36:02 +1000 Subject: [PATCH] update tx and rx config versions This needs a close review and more testing at release!!! --- src/lib/CONFIG/config.cpp | 78 +++++++++++++++++++++++++++++++++++++++--- src/lib/CONFIG/config.h | 11 +++--- src/lib/CONFIG/config_legacy.h | 46 +++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 10 deletions(-) diff --git a/src/lib/CONFIG/config.cpp b/src/lib/CONFIG/config.cpp index ce209acd..6cb0388b 100644 --- a/src/lib/CONFIG/config.cpp +++ b/src/lib/CONFIG/config.cpp @@ -98,6 +98,21 @@ static void ModelV6toV7(v6_model_config_t const * const v6, model_config_t * con v7->boostChannel = v6->boostChannel; } +static void ModelV7toV8(v7_model_config_t const * const v7, model_config_t * const v8) +{ + v8->rate = v7->rate; + v8->tlm = v7->tlm; + v8->power = v7->power; + v8->switchMode = v7->switchMode; + v8->boostChannel = v7->boostChannel; + v8->dynamicPower = v7->dynamicPower; + v8->modelMatch = v7->modelMatch; + v8->txAntenna = v7->txAntenna; + v8->ptrStartChannel = v7->ptrStartChannel; + v8->ptrEnableChannel = v7->ptrEnableChannel; + v8->linkMode = v7->linkMode; +} + TxConfig::TxConfig() : m_model(m_config.model_config) { @@ -189,11 +204,7 @@ void TxConfig::Load() itoa(i, model+5, 10); if (nvs_get_u32(handle, model, &value) == ESP_OK) { - if (version >= 7) - { - U32_to_Model(value, &m_config.model_config[i]); - } - else + if (version == 6) { // Upgrade v6 to v7 directly writing to nvs instead of calling Commit() over and over v6_model_config_t v6model; @@ -202,6 +213,21 @@ void TxConfig::Load() ModelV6toV7(&v6model, newModel); nvs_set_u32(handle, model, Model_to_U32(newModel)); } + + if (version <= 7) + { + // Upgrade v7 to v8 directly writing to nvs instead of calling Commit() over and over + v7_model_config_t v7model; + U32_to_Model(value, &v7model); + model_config_t * const newModel = &m_config.model_config[i]; + ModelV7toV8(&v7model, newModel); + nvs_set_u32(handle, model, Model_to_U32(newModel)); + } + + if (version == TX_CONFIG_VERSION) + { + U32_to_Model(value, &m_config.model_config[i]); + } } } // for each model @@ -244,6 +270,12 @@ void TxConfig::Load() if (version == 6) { UpgradeEepromV6ToV7(); + version = 7; + } + + if (version == 7) + { + UpgradeEepromV7ToV8(); } } @@ -296,6 +328,25 @@ void TxConfig::UpgradeEepromV6ToV7() m_config.version = 7U | TX_CONFIG_MAGIC; Commit(); } + +void TxConfig::UpgradeEepromV7ToV8() +{ + v7_tx_config_t v7Config; + + // Populate the prev version struct from eeprom + m_eeprom->Get(0, v7Config); + + for (unsigned i=0; iGet(0, v9Config); + + if ((v9Config.version & ~CONFIG_MAGIC_MASK) == 9) + { + m_config.powerOnCounter = v9Config.powerOnCounter; + m_config.forceTlmOff = v9Config.forceTlmOff; + m_config.rateInitialIdx = v9Config.rateInitialIdx; + } +} + void RxConfig::UpgradeUid(uint8_t *onLoanUid, uint8_t *boundUid) { // Convert to traditional binding diff --git a/src/lib/CONFIG/config.h b/src/lib/CONFIG/config.h index 32b31250..bf861b6b 100644 --- a/src/lib/CONFIG/config.h +++ b/src/lib/CONFIG/config.h @@ -15,8 +15,8 @@ #define TX_CONFIG_MAGIC (0b01U << 30) #define RX_CONFIG_MAGIC (0b10U << 30) -#define TX_CONFIG_VERSION 7U -#define RX_CONFIG_VERSION 9U +#define TX_CONFIG_VERSION 8U +#define RX_CONFIG_VERSION 10U #if defined(TARGET_TX) @@ -170,6 +170,7 @@ private: #if !defined(PLATFORM_ESP32) void UpgradeEepromV5ToV6(); void UpgradeEepromV6ToV7(); + void UpgradeEepromV7ToV8(); #endif tx_config_t m_config; @@ -224,10 +225,9 @@ typedef struct __attribute__((packed)) { uint8_t bindStorage:2, // rx_config_bindstorage_t power:4, antennaMode:2; // 0=0, 1=1, 2=Diversity - uint8_t powerOnCounter:3, + uint8_t powerOnCounter:2, forceTlmOff:1, - free:4; - uint8_t rateInitialIdx; // Rate to start rateCycling at on boot + rateInitialIdx:5; // Rate to start rateCycling at on boot uint8_t modelId; uint8_t serialProtocol:4, failsafeMode:2, @@ -310,6 +310,7 @@ private: void UpgradeEepromV5(); void UpgradeEepromV6(); void UpgradeEepromV7V8(); + void UpgradeEepromV9(); rx_config_t m_config; ELRS_EEPROM *m_eeprom; diff --git a/src/lib/CONFIG/config_legacy.h b/src/lib/CONFIG/config_legacy.h index 91ccd5e9..372da5c9 100644 --- a/src/lib/CONFIG/config_legacy.h +++ b/src/lib/CONFIG/config_legacy.h @@ -53,6 +53,23 @@ typedef struct { uint8_t dvrStopDelay:3; } v6_tx_config_t; +// V7 +typedef v6_tx_config_t v7_tx_config_t; + +typedef struct { + uint32_t rate:4, + tlm:4, + power:3, + switchMode:2, + boostChannel:3, + dynamicPower:1, + modelMatch:1, + txAntenna:2, + ptrStartChannel:4, + ptrEnableChannel:5, + linkMode:3; +} v7_model_config_t; + /*** * RX config ***/ @@ -157,3 +174,32 @@ typedef struct { } v7_rx_config_t; // V8 is just V7 except PWM config inserted 10khz PWM in the middle + +typedef struct { + uint32_t version; + uint8_t uid[UID_LEN]; + uint8_t unused_padding; + uint8_t serial1Protocol:4, // secondary serial protocol + serial1Protocol_unused:4; + uint32_t flash_discriminator; + struct { + uint16_t scale; // FUTURE: Override compiled vbat scale + int16_t offset; // FUTURE: Override comiled vbat offset + } vbat; + uint8_t bindStorage:2, // rx_config_bindstorage_t + power:4, + antennaMode:2; // 0=0, 1=1, 2=Diversity + uint8_t powerOnCounter:3, + forceTlmOff:1, + rateInitialIdx:4; // Rate to start rateCycling at on boot + uint8_t modelId; + uint8_t serialProtocol:4, + failsafeMode:2, + unused:2; + v6_rx_config_pwm_t pwmChannels[16]; + uint8_t teamraceChannel:4, + teamracePosition:3, + teamracePitMode:1; // FUTURE: Enable pit mode when disabling model + uint8_t targetSysId; + uint8_t sourceSysId; +} v9_rx_config_t; \ No newline at end of file -- 2.11.4.GIT