Skip to content

Commit

Permalink
Migrate to new defaults (#4294)
Browse files Browse the repository at this point in the history
* Upgrade module config state version but don't blow everything away

* ModuleConfig version intervals roll forward

* Be specific about version migration criteria

* initModuleConfigIntervals fix

* Don't forget power!
  • Loading branch information
thebentern authored Jul 16, 2024
1 parent 9db3552 commit 46d7b82
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
32 changes: 28 additions & 4 deletions src/mesh/NodeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,14 @@ void NodeDB::installRoleDefaults(meshtastic_Config_DeviceConfig_Role role)

void NodeDB::initModuleConfigIntervals()
{
moduleConfig.telemetry.device_update_interval = default_broadcast_interval_secs;
moduleConfig.telemetry.environment_update_interval = default_broadcast_interval_secs;
moduleConfig.telemetry.air_quality_interval = default_broadcast_interval_secs;
moduleConfig.neighbor_info.update_interval = default_broadcast_interval_secs;
// Zero out telemetry intervals so that they coalesce to defaults in Default.h
moduleConfig.telemetry.device_update_interval = 0;
moduleConfig.telemetry.environment_update_interval = 0;
moduleConfig.telemetry.air_quality_interval = 0;
moduleConfig.telemetry.power_update_interval = 0;
moduleConfig.neighbor_info.update_interval = 0;
moduleConfig.paxcounter.paxcounter_update_interval = 0;
moduleConfig.neighbor_info.update_interval = 0;
}

void NodeDB::installDefaultChannels()
Expand Down Expand Up @@ -648,6 +652,26 @@ void NodeDB::loadFromDisk()
if (state == LoadFileResult::SUCCESS) {
LOG_INFO("Loaded OEMStore\n");
}

// 2.4.X - configuration migration to update new default intervals
if (moduleConfig.version < 23) {
LOG_DEBUG("ModuleConfig version %d is stale, upgrading to new default intervals\n", moduleConfig.version);
moduleConfig.version = DEVICESTATE_CUR_VER;
if (moduleConfig.telemetry.device_update_interval == 900)
moduleConfig.telemetry.device_update_interval = 0;
if (moduleConfig.telemetry.environment_update_interval == 900)
moduleConfig.telemetry.environment_update_interval = 0;
if (moduleConfig.telemetry.air_quality_interval == 900)
moduleConfig.telemetry.air_quality_interval = 0;
if (moduleConfig.telemetry.power_update_interval == 900)
moduleConfig.telemetry.power_update_interval = 0;
if (moduleConfig.neighbor_info.update_interval == 900)
moduleConfig.neighbor_info.update_interval = 0;
if (moduleConfig.paxcounter.paxcounter_update_interval == 900)
moduleConfig.paxcounter.paxcounter_update_interval = 0;

saveToDisk(SEGMENT_MODULECONFIG);
}
}

/** Save a protobuf from a file, return true for success */
Expand Down
4 changes: 2 additions & 2 deletions src/mesh/NodeDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ DeviceState versions used to be defined in the .proto file but really only this
#define SEGMENT_DEVICESTATE 4
#define SEGMENT_CHANNELS 8

#define DEVICESTATE_CUR_VER 22
#define DEVICESTATE_MIN_VER DEVICESTATE_CUR_VER
#define DEVICESTATE_CUR_VER 23
#define DEVICESTATE_MIN_VER 22

extern meshtastic_DeviceState devicestate;
extern meshtastic_ChannelFile channelFile;
Expand Down

0 comments on commit 46d7b82

Please sign in to comment.