From 1fcec8ce3b25748693e2e733a427deb3fb6456c8 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Tue, 23 Mar 2021 11:54:53 +0800 Subject: [PATCH] always fix up channel list, even if we just did factory reset --- proto | 2 +- src/mesh/Channels.cpp | 12 ++++++------ src/mesh/NodeDB.cpp | 15 +++++++++------ src/plugins/AdminPlugin.cpp | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/proto b/proto index 8a39bac88..820fa497d 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 8a39bac88206a8aa9305ac380d150946c1796ac5 +Subproject commit 820fa497dfde07e129cad6955bf2f4b2b9cecebc diff --git a/src/mesh/Channels.cpp b/src/mesh/Channels.cpp index 135ff4329..1e49d9319 100644 --- a/src/mesh/Channels.cpp +++ b/src/mesh/Channels.cpp @@ -33,7 +33,7 @@ int16_t Channels::generateHash(ChannelIndex channelNum) return -1; // invalid else { const char *name = getName(channelNum); - uint8_t h = xorHash((const uint8_t *) name, strlen(name)); + uint8_t h = xorHash((const uint8_t *)name, strlen(name)); h ^= xorHash(k.bytes, k.length); @@ -184,7 +184,7 @@ void Channels::onConfigChanged() Channel &Channels::getByIndex(ChannelIndex chIndex) { - assert(chIndex < channelFile.channels_count); + assert(chIndex < channelFile.channels_count); // This should be equal to MAX_NUM_CHANNELS Channel *ch = channelFile.channels + chIndex; return *ch; } @@ -278,11 +278,11 @@ const char *Channels::getPrimaryName() */ bool Channels::decryptForHash(ChannelIndex chIndex, ChannelHash channelHash) { - if(chIndex > getNumChannels() || getHash(chIndex) != channelHash) { - // DEBUG_MSG("Skipping channel %d (hash %x) due to invalid hash/index, want=%x\n", chIndex, getHash(chIndex), channelHash); + if (chIndex > getNumChannels() || getHash(chIndex) != channelHash) { + // DEBUG_MSG("Skipping channel %d (hash %x) due to invalid hash/index, want=%x\n", chIndex, getHash(chIndex), + // channelHash); return false; - } - else { + } else { DEBUG_MSG("Using channel %d (hash 0x%x)\n", chIndex, channelHash); setCrypto(chIndex); return true; diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 35f54fa72..37e1e9f02 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -86,7 +86,9 @@ bool NodeDB::resetRadioConfig() DEBUG_MSG("Performing factory reset!\n"); installDefaultDeviceState(); didFactoryReset = true; - } else if (channelFile.channels_count == 0) { + } + + if (channelFile.channels_count != MAX_NUM_CHANNELS) { DEBUG_MSG("Setting default channel and radio preferences!\n"); channels.initDefaults(); @@ -206,12 +208,13 @@ void NodeDB::init() // removed from 1.2 (though we do use old values if found) // We set these _after_ loading from disk - because they come from the build and are more trusted than // what is stored in flash - //if (xstr(HW_VERSION)[0]) + // if (xstr(HW_VERSION)[0]) // strncpy(myNodeInfo.region, optstr(HW_VERSION), sizeof(myNodeInfo.region)); - // else DEBUG_MSG("This build does not specify a HW_VERSION\n"); // Eventually new builds will no longer include this build flag + // else DEBUG_MSG("This build does not specify a HW_VERSION\n"); // Eventually new builds will no longer include this build + // flag // DEBUG_MSG("legacy region %d\n", devicestate.legacyRadio.preferences.region); - if(radioConfig.preferences.region == RegionCode_Unset) + if (radioConfig.preferences.region == RegionCode_Unset) radioConfig.preferences.region = devicestate.legacyRadio.preferences.region; // Check for the old style of region code strings, if found, convert to the new enum. @@ -226,7 +229,7 @@ void NodeDB::init() } strncpy(myNodeInfo.firmware_version, optstr(APP_VERSION), sizeof(myNodeInfo.firmware_version)); - + // hw_model is no longer stored in myNodeInfo (as of 1.2.11) - we now store it as an enum in nodeinfo myNodeInfo.hw_model_deprecated[0] = '\0'; // strncpy(myNodeInfo.hw_model, HW_VENDOR, sizeof(myNodeInfo.hw_model)); @@ -373,7 +376,7 @@ void NodeDB::saveChannelsToDisk() FS.mkdir("/prefs"); #endif saveProto(channelfile, ChannelFile_size, sizeof(ChannelFile), ChannelFile_fields, &channelFile); - } + } } void NodeDB::saveToDisk() diff --git a/src/plugins/AdminPlugin.cpp b/src/plugins/AdminPlugin.cpp index ae09d5af8..69e96875c 100644 --- a/src/plugins/AdminPlugin.cpp +++ b/src/plugins/AdminPlugin.cpp @@ -64,7 +64,7 @@ bool AdminPlugin::handleReceivedProtobuf(const MeshPacket &mp, const AdminMessag case AdminMessage_get_channel_request_tag: { uint32_t i = r->get_channel_request - 1; - DEBUG_MSG("Client is getting channel %d\n", i); + DEBUG_MSG("Client is getting channel %u\n", i); if (i >= MAX_NUM_CHANNELS) reply = allocErrorResponse(Routing_Error_BAD_REQUEST, &mp); else