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