diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index d804aa8e..47b9d0bc 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -146,6 +146,13 @@ bool NodeDB::resetRadioConfig() void NodeDB::installDefaultConfig() { memset(&config, 0, sizeof(LocalConfig)); + config.has_device = true; + config.has_display = true; + config.has_lora = true; + config.has_position = true; + config.has_power = true; + config.has_wifi = true; + config.lora.region = Config_LoRaConfig_RegionCode_Unset; config.lora.modem_preset = Config_LoRaConfig_ModemPreset_LongFast; resetRadioConfig(); @@ -158,6 +165,13 @@ void NodeDB::installDefaultConfig() void NodeDB::installDefaultModuleConfig() { memset(&moduleConfig, 0, sizeof(ModuleConfig)); + moduleConfig.has_canned_message = true; + moduleConfig.has_external_notification = true; + moduleConfig.has_mqtt = true; + moduleConfig.has_range_test = true; + moduleConfig.has_serial = true; + moduleConfig.has_store_forward = true; + moduleConfig.has_telemetry = true; } // void NodeDB::installDefaultRadioConfig() @@ -341,7 +355,7 @@ void NodeDB::loadFromDisk() installDefaultConfig(); // Our in RAM copy might now be corrupt } - if (!loadProto(moduleConfigfile, ModuleConfig_size, sizeof(ModuleConfig), ModuleConfig_fields, &moduleConfig)) { + if (!loadProto(moduleConfigfile, LocalModuleConfig_size, sizeof(LocalModuleConfig), LocalModuleConfig_fields, &moduleConfig)) { installDefaultModuleConfig(); // Our in RAM copy might now be corrupt } @@ -402,6 +416,7 @@ void NodeDB::saveToDisk() FSCom.mkdir("/prefs"); #endif saveProto(preffile, DeviceState_size, sizeof(devicestate), DeviceState_fields, &devicestate); + // save all config segments config.has_device = true; config.has_display = true; @@ -410,7 +425,16 @@ void NodeDB::saveToDisk() config.has_power = true; config.has_wifi = true; saveProto(configfile, LocalConfig_size, sizeof(LocalConfig), LocalConfig_fields, &config); - saveProto(moduleConfigfile, Module_Config_size, sizeof(ModuleConfig), ModuleConfig_fields, &moduleConfig); + + moduleConfig.has_canned_message = true; + moduleConfig.has_external_notification = true; + moduleConfig.has_mqtt = true; + moduleConfig.has_range_test = true; + moduleConfig.has_serial = true; + moduleConfig.has_store_forward = true; + moduleConfig.has_telemetry = true; + saveProto(moduleConfigfile, LocalModuleConfig_size, sizeof(LocalModuleConfig), LocalModuleConfig_fields, &moduleConfig); + saveChannelsToDisk(); } else { diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index decce029..9f6f55fe 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -176,26 +176,32 @@ void AdminModule::handleSetConfig(const Config &c) switch (c.which_payloadVariant) { case Config_device_tag: DEBUG_MSG("Setting config: Device\n"); + config.has_device = true; config.device = c.payloadVariant.device; break; case Config_position_tag: DEBUG_MSG("Setting config: Position\n"); + config.has_position = true; config.position = c.payloadVariant.position; break; case Config_power_tag: DEBUG_MSG("Setting config: Power\n"); + config.has_power = true; config.power = c.payloadVariant.power; break; case Config_wifi_tag: DEBUG_MSG("Setting config: WiFi\n"); + config.has_wifi = true; config.wifi = c.payloadVariant.wifi; break; case Config_display_tag: DEBUG_MSG("Setting config: Display\n"); + config.has_display = true; config.display = c.payloadVariant.display; break; case Config_lora_tag: DEBUG_MSG("Setting config: LoRa\n"); + config.has_lora = true; config.lora = c.payloadVariant.lora; break; } @@ -208,30 +214,37 @@ void AdminModule::handleSetModuleConfig(const ModuleConfig &c) switch (c.which_payloadVariant) { case ModuleConfig_mqtt_tag: DEBUG_MSG("Setting module config: MQTT\n"); + moduleConfig.has_mqtt = true; moduleConfig.mqtt = c.payloadVariant.mqtt; break; case ModuleConfig_serial_tag: DEBUG_MSG("Setting module config: Serial\n"); + moduleConfig.has_serial = true; moduleConfig.serial = c.payloadVariant.serial; break; case ModuleConfig_external_notification_tag: DEBUG_MSG("Setting module config: External Notification\n"); + moduleConfig.has_external_notification = true; moduleConfig.external_notification = c.payloadVariant.external_notification; break; case ModuleConfig_store_forward_tag: DEBUG_MSG("Setting module config: Store & Forward\n"); + moduleConfig.has_store_forward = true; moduleConfig.store_forward = c.payloadVariant.store_forward; break; case ModuleConfig_range_test_tag: DEBUG_MSG("Setting module config: Range Test\n"); + moduleConfig.has_range_test = true; moduleConfig.range_test = c.payloadVariant.range_test; break; case ModuleConfig_telemetry_tag: DEBUG_MSG("Setting module config: Telemetry\n"); + moduleConfig.has_telemetry = true; moduleConfig.telemetry = c.payloadVariant.telemetry; break; case ModuleConfig_canned_message_tag: DEBUG_MSG("Setting module config: Canned Message\n"); + moduleConfig.has_canned_message = true; moduleConfig.canned_message = c.payloadVariant.canned_message; break; }