minimize radioconfig file writes

This commit is contained in:
Kevin Hester 2021-03-11 18:29:47 +08:00
parent 76e2c39c63
commit a97c2ae6eb
4 changed files with 23 additions and 12 deletions

View File

@ -104,7 +104,7 @@ bool MeshService::reloadConfig()
// This will also update the region as needed // This will also update the region as needed
bool didReset = nodeDB.resetRadioConfig(); // Don't let the phone send us fatally bad settings bool didReset = nodeDB.resetRadioConfig(); // Don't let the phone send us fatally bad settings
configChanged.notifyObservers(NULL); configChanged.notifyObservers(NULL); // This will cause radio hardware to change freqs etc
nodeDB.saveToDisk(); nodeDB.saveToDisk();
return didReset; return didReset;

View File

@ -359,6 +359,16 @@ bool saveProto(const char *filename, size_t protoSize, size_t objSize, const pb_
return okay; return okay;
} }
void NodeDB::saveChannelsToDisk()
{
if (!devicestate.no_save) {
#ifdef FS
FS.mkdir("/prefs");
#endif
saveProto(channelfile, ChannelFile_size, sizeof(ChannelFile), ChannelFile_fields, &channelFile);
}
}
void NodeDB::saveToDisk() void NodeDB::saveToDisk()
{ {
if (!devicestate.no_save) { if (!devicestate.no_save) {
@ -367,7 +377,7 @@ void NodeDB::saveToDisk()
#endif #endif
bool okay = saveProto(preffile, DeviceState_size, sizeof(devicestate), DeviceState_fields, &devicestate); bool okay = saveProto(preffile, DeviceState_size, sizeof(devicestate), DeviceState_fields, &devicestate);
okay &= saveProto(radiofile, RadioConfig_size, sizeof(RadioConfig), RadioConfig_fields, &radioConfig); okay &= saveProto(radiofile, RadioConfig_size, sizeof(RadioConfig), RadioConfig_fields, &radioConfig);
okay &= saveProto(channelfile, ChannelFile_size, sizeof(ChannelFile), ChannelFile_fields, &channelFile); saveChannelsToDisk();
// remove any pre 1.2 pref files, turn on after 1.2 is in beta // remove any pre 1.2 pref files, turn on after 1.2 is in beta
// if(okay) FS.remove(preffileOld); // if(okay) FS.remove(preffileOld);

View File

@ -43,7 +43,7 @@ class NodeDB
void init(); void init();
/// write to flash /// write to flash
void saveToDisk(); void saveToDisk(), saveChannelsToDisk();
/** Reinit radio config if needed, because either: /** Reinit radio config if needed, because either:
* a) sometimes a buggy android app might send us bogus settings or * a) sometimes a buggy android app might send us bogus settings or

View File

@ -96,21 +96,22 @@ void AdminPlugin::handleSetChannel(const Channel &cc)
{ {
channels.setChannel(cc); channels.setChannel(cc);
bool didReset = service.reloadConfig(); // Just update and save the channels - no need to update the radio for ! primary channel changes
/* FIXME - do we need this still? if (cc.index == 0) {
if (didReset) { // FIXME, this updates the user preferences also, which isn't needed - we really just want to notify on configChanged
state = STATE_SEND_MY_INFO; // Squirt a completely new set of configs to the client service.reloadConfig();
} */ }
else {
channels.onConfigChanged(); // tell the radios about this change
nodeDB.saveChannelsToDisk();
}
} }
void AdminPlugin::handleSetRadio(const RadioConfig &r) void AdminPlugin::handleSetRadio(const RadioConfig &r)
{ {
radioConfig = r; radioConfig = r;
bool didReset = service.reloadConfig(); service.reloadConfig();
/* FIXME - do we need this still? if (didReset) {
state = STATE_SEND_MY_INFO; // Squirt a completely new set of configs to the client
} */
} }
MeshPacket *AdminPlugin::allocReply() MeshPacket *AdminPlugin::allocReply()