mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-05 21:24:34 +00:00
Updates and fix lame legacy code paths
This commit is contained in:
parent
c986c4a742
commit
eb3ffc1922
@ -1 +1 @@
|
|||||||
Subproject commit 47ff85bb9c2ab63fd0232f9a0eb6e27896944ef6
|
Subproject commit 79298fcdf04c1e680f5abd875233394f44ddaf7a
|
@ -7,6 +7,9 @@
|
|||||||
#define THIRTY_SECONDS_MS 30 * 1000
|
#define THIRTY_SECONDS_MS 30 * 1000
|
||||||
#define FIVE_SECONDS_MS 5 * 1000
|
#define FIVE_SECONDS_MS 5 * 1000
|
||||||
|
|
||||||
|
// Backup after the first 5 minutes
|
||||||
|
#define AUTOMATIC_BACKUP_MS 5 * 60 * 1000
|
||||||
|
|
||||||
#define min_default_telemetry_interval_secs 30 * 60
|
#define min_default_telemetry_interval_secs 30 * 60
|
||||||
#define default_gps_update_interval IF_ROUTER(ONE_DAY, 2 * 60)
|
#define default_gps_update_interval IF_ROUTER(ONE_DAY, 2 * 60)
|
||||||
#define default_telemetry_broadcast_interval_secs IF_ROUTER(ONE_DAY / 2, 60 * 60)
|
#define default_telemetry_broadcast_interval_secs IF_ROUTER(ONE_DAY / 2, 60 * 60)
|
||||||
|
@ -117,17 +117,13 @@ void MeshService::loop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The radioConfig object just changed, call this to force the hw to change to the new settings
|
/// The radioConfig object just changed, call this to force the hw to change to the new settings
|
||||||
bool MeshService::reloadConfig(int saveWhat)
|
void MeshService::reloadConfig(int saveWhat)
|
||||||
{
|
{
|
||||||
// If we can successfully set this radio to these settings, save them to disk
|
|
||||||
|
|
||||||
// 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
|
nodeDB->resetRadioConfig(); // Don't let the phone send us fatally bad settings
|
||||||
|
|
||||||
configChanged.notifyObservers(NULL); // This will cause radio hardware to change freqs etc
|
configChanged.notifyObservers(NULL); // This will cause radio hardware to change freqs etc
|
||||||
nodeDB->saveToDisk(saveWhat);
|
nodeDB->saveToDisk(saveWhat);
|
||||||
|
|
||||||
return didReset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The owner User record just got updated, update our node DB and broadcast the info into the mesh
|
/// The owner User record just got updated, update our node DB and broadcast the info into the mesh
|
||||||
|
@ -118,7 +118,7 @@ class MeshService
|
|||||||
/** The radioConfig object just changed, call this to force the hw to change to the new settings
|
/** The radioConfig object just changed, call this to force the hw to change to the new settings
|
||||||
* @return true if client devices should be sent a new set of radio configs
|
* @return true if client devices should be sent a new set of radio configs
|
||||||
*/
|
*/
|
||||||
bool reloadConfig(int saveWhat = SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS);
|
void reloadConfig(int saveWhat = SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS);
|
||||||
|
|
||||||
/// The owner User record just got updated, update our node DB and broadcast the info into the mesh
|
/// The owner User record just got updated, update our node DB and broadcast the info into the mesh
|
||||||
void reloadOwner(bool shouldSave = true);
|
void reloadOwner(bool shouldSave = true);
|
||||||
|
@ -400,34 +400,17 @@ bool isBroadcast(uint32_t dest)
|
|||||||
return dest == NODENUM_BROADCAST || dest == NODENUM_BROADCAST_NO_LORA;
|
return dest == NODENUM_BROADCAST || dest == NODENUM_BROADCAST_NO_LORA;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NodeDB::resetRadioConfig(bool factory_reset)
|
void NodeDB::resetRadioConfig()
|
||||||
{
|
{
|
||||||
bool didFactoryReset = false;
|
|
||||||
|
|
||||||
radioGeneration++;
|
radioGeneration++;
|
||||||
|
|
||||||
if (factory_reset) {
|
|
||||||
didFactoryReset = factoryReset();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (channelFile.channels_count != MAX_NUM_CHANNELS) {
|
if (channelFile.channels_count != MAX_NUM_CHANNELS) {
|
||||||
LOG_INFO("Set default channel and radio preferences!");
|
LOG_INFO("Set default channel and radio preferences!");
|
||||||
|
|
||||||
channels.initDefaults();
|
channels.initDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
channels.onConfigChanged();
|
channels.onConfigChanged();
|
||||||
|
|
||||||
// Update the global myRegion
|
// Update the global myRegion
|
||||||
initRegion();
|
initRegion();
|
||||||
|
|
||||||
if (didFactoryReset) {
|
|
||||||
LOG_INFO("Reboot due to factory reset");
|
|
||||||
screen->startAlert("Rebooting...");
|
|
||||||
rebootAtMsec = millis() + (5 * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
return didFactoryReset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NodeDB::factoryReset(bool eraseBleBonds)
|
bool NodeDB::factoryReset(bool eraseBleBonds)
|
||||||
@ -1032,6 +1015,9 @@ void NodeDB::loadFromDisk()
|
|||||||
if (devicestate.version < DEVICESTATE_MIN_VER) {
|
if (devicestate.version < DEVICESTATE_MIN_VER) {
|
||||||
LOG_WARN("Devicestate %d is old, discard", devicestate.version);
|
LOG_WARN("Devicestate %d is old, discard", devicestate.version);
|
||||||
installDefaultDeviceState();
|
installDefaultDeviceState();
|
||||||
|
} else if (state != LoadFileResult::LOAD_SUCCESS) {
|
||||||
|
// If we have an owner in the backup, restore it
|
||||||
|
restorePreferences(meshtastic_AdminMessage_BackupLocation_FLASH, SEGMENT_DEVICESTATE);
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Loaded saved devicestate version %d", devicestate.version);
|
LOG_INFO("Loaded saved devicestate version %d", devicestate.version);
|
||||||
}
|
}
|
||||||
@ -1040,16 +1026,18 @@ void NodeDB::loadFromDisk()
|
|||||||
&config);
|
&config);
|
||||||
if (state != LoadFileResult::LOAD_SUCCESS) {
|
if (state != LoadFileResult::LOAD_SUCCESS) {
|
||||||
installDefaultConfig(); // Our in RAM copy might now be corrupt
|
installDefaultConfig(); // Our in RAM copy might now be corrupt
|
||||||
|
restorePreferences(meshtastic_AdminMessage_BackupLocation_FLASH, SEGMENT_CONFIG);
|
||||||
} else {
|
} else {
|
||||||
if (config.version < DEVICESTATE_MIN_VER) {
|
if (config.version < DEVICESTATE_MIN_VER) {
|
||||||
LOG_WARN("config %d is old, discard", config.version);
|
LOG_WARN("config %d is old, discard", config.version);
|
||||||
installDefaultConfig(true);
|
installDefaultConfig(true);
|
||||||
|
restorePreferences(meshtastic_AdminMessage_BackupLocation_FLASH, SEGMENT_CONFIG);
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Loaded saved config version %d", config.version);
|
LOG_INFO("Loaded saved config version %d", config.version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (backupSecurity.private_key.size > 0) {
|
if (backupSecurity.private_key.size > 0) {
|
||||||
LOG_DEBUG("Restoring backup of security config");
|
LOG_DEBUG("Restoring security config");
|
||||||
config.security = backupSecurity;
|
config.security = backupSecurity;
|
||||||
saveToDisk(SEGMENT_CONFIG);
|
saveToDisk(SEGMENT_CONFIG);
|
||||||
}
|
}
|
||||||
@ -1109,6 +1097,7 @@ void NodeDB::loadFromDisk()
|
|||||||
&meshtastic_LocalModuleConfig_msg, &moduleConfig);
|
&meshtastic_LocalModuleConfig_msg, &moduleConfig);
|
||||||
if (state != LoadFileResult::LOAD_SUCCESS) {
|
if (state != LoadFileResult::LOAD_SUCCESS) {
|
||||||
installDefaultModuleConfig(); // Our in RAM copy might now be corrupt
|
installDefaultModuleConfig(); // Our in RAM copy might now be corrupt
|
||||||
|
restorePreferences(meshtastic_AdminMessage_BackupLocation_FLASH, SEGMENT_MODULECONFIG);
|
||||||
} else {
|
} else {
|
||||||
if (moduleConfig.version < DEVICESTATE_MIN_VER) {
|
if (moduleConfig.version < DEVICESTATE_MIN_VER) {
|
||||||
LOG_WARN("moduleConfig %d is old, discard", moduleConfig.version);
|
LOG_WARN("moduleConfig %d is old, discard", moduleConfig.version);
|
||||||
@ -1122,6 +1111,7 @@ void NodeDB::loadFromDisk()
|
|||||||
&channelFile);
|
&channelFile);
|
||||||
if (state != LoadFileResult::LOAD_SUCCESS) {
|
if (state != LoadFileResult::LOAD_SUCCESS) {
|
||||||
installDefaultChannels(); // Our in RAM copy might now be corrupt
|
installDefaultChannels(); // Our in RAM copy might now be corrupt
|
||||||
|
restorePreferences(meshtastic_AdminMessage_BackupLocation_FLASH, SEGMENT_CHANNELS);
|
||||||
} else {
|
} else {
|
||||||
if (channelFile.version < DEVICESTATE_MIN_VER) {
|
if (channelFile.version < DEVICESTATE_MIN_VER) {
|
||||||
LOG_WARN("channelFile %d is old, discard", channelFile.version);
|
LOG_WARN("channelFile %d is old, discard", channelFile.version);
|
||||||
@ -1597,9 +1587,24 @@ UserLicenseStatus NodeDB::getLicenseStatus(uint32_t nodeNum)
|
|||||||
return info->user.is_licensed ? UserLicenseStatus::Licensed : UserLicenseStatus::NotLicensed;
|
return info->user.is_licensed ? UserLicenseStatus::Licensed : UserLicenseStatus::NotLicensed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bool NodeDB::shouldAutoPerformBackup()
|
||||||
|
// {
|
||||||
|
// // Already backed up
|
||||||
|
// if (lastBackupAttempt > 0)
|
||||||
|
// return false;
|
||||||
|
// // Not enough time has passed
|
||||||
|
// if (millis() - lastBackupAttempt < AUTOMATIC_BACKUP_MS) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // If a LoRa region is set, assume the device is setup
|
||||||
|
// return config.lora.region != meshtastic_Config_LoRaConfig_RegionCode_UNSET;
|
||||||
|
// }
|
||||||
|
|
||||||
bool NodeDB::backupPreferences(meshtastic_AdminMessage_BackupLocation location)
|
bool NodeDB::backupPreferences(meshtastic_AdminMessage_BackupLocation location)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
lastBackupAttempt = millis();
|
||||||
#ifdef FSCom
|
#ifdef FSCom
|
||||||
if (location == meshtastic_AdminMessage_BackupLocation_FLASH) {
|
if (location == meshtastic_AdminMessage_BackupLocation_FLASH) {
|
||||||
meshtastic_BackupPreferences backup = meshtastic_BackupPreferences_init_zero;
|
meshtastic_BackupPreferences backup = meshtastic_BackupPreferences_init_zero;
|
||||||
@ -1634,7 +1639,7 @@ bool NodeDB::backupPreferences(meshtastic_AdminMessage_BackupLocation location)
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NodeDB::restorePreferences(meshtastic_AdminMessage_BackupLocation location)
|
bool NodeDB::restorePreferences(meshtastic_AdminMessage_BackupLocation location, int restoreWhat)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
#ifdef FSCom
|
#ifdef FSCom
|
||||||
@ -1651,11 +1656,24 @@ bool NodeDB::restorePreferences(meshtastic_AdminMessage_BackupLocation location)
|
|||||||
success = loadProto(backupFileName, meshtastic_BackupPreferences_size, sizeof(meshtastic_BackupPreferences),
|
success = loadProto(backupFileName, meshtastic_BackupPreferences_size, sizeof(meshtastic_BackupPreferences),
|
||||||
&meshtastic_BackupPreferences_msg, &backup);
|
&meshtastic_BackupPreferences_msg, &backup);
|
||||||
if (success) {
|
if (success) {
|
||||||
config = backup.config;
|
if (restoreWhat & SEGMENT_CONFIG) {
|
||||||
moduleConfig = backup.module_config;
|
config = backup.config;
|
||||||
channelFile = backup.channels;
|
LOG_DEBUG("Restored config");
|
||||||
owner = backup.owner;
|
}
|
||||||
success = saveToDisk(SEGMENT_DEVICESTATE | SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_CHANNELS);
|
if (restoreWhat & SEGMENT_MODULECONFIG) {
|
||||||
|
moduleConfig = backup.module_config;
|
||||||
|
LOG_DEBUG("Restored module config");
|
||||||
|
}
|
||||||
|
if (restoreWhat & SEGMENT_DEVICESTATE) {
|
||||||
|
devicestate.owner = backup.owner;
|
||||||
|
LOG_DEBUG("Restored device state");
|
||||||
|
}
|
||||||
|
if (restoreWhat & SEGMENT_CHANNELS) {
|
||||||
|
channelFile = backup.channels;
|
||||||
|
LOG_DEBUG("Restored channels");
|
||||||
|
}
|
||||||
|
|
||||||
|
success = saveToDisk(restoreWhat);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
LOG_ERROR("Failed to save restored preferences to flash");
|
LOG_ERROR("Failed to save restored preferences to flash");
|
||||||
} else {
|
} else {
|
||||||
|
@ -97,12 +97,9 @@ class NodeDB
|
|||||||
SEGMENT_NODEDATABASE);
|
SEGMENT_NODEDATABASE);
|
||||||
|
|
||||||
/** 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
|
* sometimes a buggy android app might send us bogus settings
|
||||||
* b) the client set factory_reset
|
|
||||||
*
|
|
||||||
* @return true if the config was completely reset, in that case, we should send it back to the client
|
|
||||||
*/
|
*/
|
||||||
bool resetRadioConfig(bool factory_reset = false);
|
void resetRadioConfig();
|
||||||
|
|
||||||
/// given a subpacket sniffed from the network, update our DB state
|
/// given a subpacket sniffed from the network, update our DB state
|
||||||
/// we updateGUI and updateGUIforNode if we think our this change is big enough for a redraw
|
/// we updateGUI and updateGUIforNode if we think our this change is big enough for a redraw
|
||||||
@ -201,11 +198,14 @@ class NodeDB
|
|||||||
|
|
||||||
bool hasValidPosition(const meshtastic_NodeInfoLite *n);
|
bool hasValidPosition(const meshtastic_NodeInfoLite *n);
|
||||||
|
|
||||||
|
// bool shouldAutoPerformBackup();
|
||||||
bool backupPreferences(meshtastic_AdminMessage_BackupLocation location);
|
bool backupPreferences(meshtastic_AdminMessage_BackupLocation location);
|
||||||
bool restorePreferences(meshtastic_AdminMessage_BackupLocation location);
|
bool restorePreferences(meshtastic_AdminMessage_BackupLocation location,
|
||||||
|
int restoreWhat = SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t lastNodeDbSave = 0; // when we last saved our db to flash
|
uint32_t lastNodeDbSave = 0; // when we last saved our db to flash
|
||||||
|
uint32_t lastBackupAttempt = 0; // when we last tried a backup automatically or manually
|
||||||
/// Find a node in our DB, create an empty NodeInfoLite if missing
|
/// Find a node in our DB, create an empty NodeInfoLite if missing
|
||||||
meshtastic_NodeInfoLite *getOrCreateMeshNode(NodeNum n);
|
meshtastic_NodeInfoLite *getOrCreateMeshNode(NodeNum n);
|
||||||
|
|
||||||
|
@ -384,7 +384,8 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta
|
|||||||
}
|
}
|
||||||
case meshtastic_AdminMessage_restore_preferences_tag: {
|
case meshtastic_AdminMessage_restore_preferences_tag: {
|
||||||
LOG_INFO("Client requesting to restore preferences");
|
LOG_INFO("Client requesting to restore preferences");
|
||||||
if (nodeDB->restorePreferences(r->backup_preferences)) {
|
if (nodeDB->restorePreferences(r->backup_preferences,
|
||||||
|
SEGMENT_DEVICESTATE | SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_CHANNELS)) {
|
||||||
myReply = allocErrorResponse(meshtastic_Routing_Error_NONE, &mp);
|
myReply = allocErrorResponse(meshtastic_Routing_Error_NONE, &mp);
|
||||||
disableBluetooth();
|
disableBluetooth();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user