From 222fe57915b096c8505838781b56128cd8d12ee1 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sat, 10 Feb 2024 15:38:50 +1100 Subject: [PATCH] AP_Vehicle: move parameter storage formatting up to AP_Vehicle --- libraries/AP_Vehicle/AP_Vehicle.h | 2 ++ libraries/AP_Vehicle/Parameters.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 libraries/AP_Vehicle/Parameters.cpp diff --git a/libraries/AP_Vehicle/AP_Vehicle.h b/libraries/AP_Vehicle/AP_Vehicle.h index fef90644be..c2fb1edfc1 100644 --- a/libraries/AP_Vehicle/AP_Vehicle.h +++ b/libraries/AP_Vehicle/AP_Vehicle.h @@ -287,6 +287,8 @@ protected: virtual void init_ardupilot() = 0; virtual void load_parameters() = 0; + void load_parameters(AP_Int16 &format_version, const uint16_t expected_format_version); + virtual void set_control_channels() {} // board specific config diff --git a/libraries/AP_Vehicle/Parameters.cpp b/libraries/AP_Vehicle/Parameters.cpp new file mode 100644 index 0000000000..328a25bdd7 --- /dev/null +++ b/libraries/AP_Vehicle/Parameters.cpp @@ -0,0 +1,24 @@ +#include "AP_Vehicle.h" + +#include +#include + +void AP_Vehicle::load_parameters(AP_Int16 &format_version, const uint16_t expected_format_version) +{ + if (!format_version.load() || + format_version != expected_format_version) { + + // erase all parameters + hal.console->printf("Firmware change: erasing EEPROM...\n"); + StorageManager::erase(); + AP_Param::erase_all(); + + // save the current format version + format_version.set_and_save(expected_format_version); + hal.console->printf("done.\n"); + } + format_version.set_default(expected_format_version); + + // Load all auto-loaded EEPROM variables + AP_Param::load_all(); +}