From caac2ecb83b058194e9d7cf7f2aaa96706819573 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 1 May 2022 20:30:19 -0500 Subject: [PATCH] Compute config size and account for reloadconfig (#1428) * Compute config size and account for reloadconfig * Reload config and config_size --- src/mesh/NodeDB.cpp | 11 +++++++++++ src/mesh/NodeDB.h | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index c40849213..e9b88bf63 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -143,6 +143,11 @@ bool NodeDB::resetRadioConfig() return didFactoryReset; } +void NodeDB::installDefaultConfig() +{ + memset(&config, 0, sizeof(config)); +} + void NodeDB::installDefaultRadioConfig() { memset(&radioConfig, 0, sizeof(radioConfig)); @@ -281,6 +286,7 @@ void NodeDB::pickNewNodeNum() static const char *preffile = "/prefs/db.proto"; static const char *radiofile = "/prefs/radio.proto"; +static const char *configfile = "/prefs/config.proto"; static const char *channelfile = "/prefs/channels.proto"; /** Load a protobuf from a file, return true for success */ @@ -333,6 +339,10 @@ void NodeDB::loadFromDisk() installDefaultRadioConfig(); // Our in RAM copy might now be corrupt } + if (!loadProto(configfile, Config_size, sizeof(Config), Config_fields, &config)) { + installDefaultConfig(); // Our in RAM copy might now be corrupt + } + if (!loadProto(channelfile, ChannelFile_size, sizeof(ChannelFile), ChannelFile_fields, &channelFile)) { installDefaultChannels(); // Our in RAM copy might now be corrupt } @@ -391,6 +401,7 @@ void NodeDB::saveToDisk() #endif saveProto(preffile, DeviceState_size, sizeof(devicestate), DeviceState_fields, &devicestate); saveProto(radiofile, RadioConfig_size, sizeof(RadioConfig), RadioConfig_fields, &radioConfig); + saveProto(configfile, Config_size, sizeof(Config), Config_fields, &config); saveChannelsToDisk(); } else { diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index d7cc44e85..793c4e73a 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -123,7 +123,7 @@ class NodeDB void loadFromDisk(); /// Reinit device state from scratch (not loading from disk) - void installDefaultDeviceState(), installDefaultRadioConfig(), installDefaultChannels(); + void installDefaultDeviceState(), installDefaultRadioConfig(), installDefaultChannels(), installDefaultConfig(); }; /** @@ -194,3 +194,5 @@ PREF_GET(min_wake_secs, 10) */ extern uint32_t radioGeneration; +// Config doesn't have a nanopb generated full size constant +#define Config_size (Config_DeviceConfig_size + Config_DisplayConfig_size + Config_GpsConfig_size + Config_LoRaConfig_size + Config_ModuleConfig_CannedMessageConfig_size + Config_ModuleConfig_ExternalNotificationConfig_size + Config_ModuleConfig_MQTTConfig_size + Config_ModuleConfig_RangeTestConfig_size + Config_ModuleConfig_SerialConfig_size + Config_ModuleConfig_StoreForwardConfig_size + Config_ModuleConfig_TelemetryConfig_size + Config_ModuleConfig_size + Config_PowerConfig_size) \ No newline at end of file