always fix up channel list, even if we just did factory reset

This commit is contained in:
Kevin Hester 2021-03-23 11:54:53 +08:00
parent d32386a027
commit 1fcec8ce3b
4 changed files with 17 additions and 14 deletions

2
proto

@ -1 +1 @@
Subproject commit 8a39bac88206a8aa9305ac380d150946c1796ac5 Subproject commit 820fa497dfde07e129cad6955bf2f4b2b9cecebc

View File

@ -184,7 +184,7 @@ void Channels::onConfigChanged()
Channel &Channels::getByIndex(ChannelIndex chIndex) 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; Channel *ch = channelFile.channels + chIndex;
return *ch; return *ch;
} }
@ -279,10 +279,10 @@ const char *Channels::getPrimaryName()
bool Channels::decryptForHash(ChannelIndex chIndex, ChannelHash channelHash) bool Channels::decryptForHash(ChannelIndex chIndex, ChannelHash channelHash)
{ {
if (chIndex > getNumChannels() || 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); // DEBUG_MSG("Skipping channel %d (hash %x) due to invalid hash/index, want=%x\n", chIndex, getHash(chIndex),
// channelHash);
return false; return false;
} } else {
else {
DEBUG_MSG("Using channel %d (hash 0x%x)\n", chIndex, channelHash); DEBUG_MSG("Using channel %d (hash 0x%x)\n", chIndex, channelHash);
setCrypto(chIndex); setCrypto(chIndex);
return true; return true;

View File

@ -86,7 +86,9 @@ bool NodeDB::resetRadioConfig()
DEBUG_MSG("Performing factory reset!\n"); DEBUG_MSG("Performing factory reset!\n");
installDefaultDeviceState(); installDefaultDeviceState();
didFactoryReset = true; didFactoryReset = true;
} else if (channelFile.channels_count == 0) { }
if (channelFile.channels_count != MAX_NUM_CHANNELS) {
DEBUG_MSG("Setting default channel and radio preferences!\n"); DEBUG_MSG("Setting default channel and radio preferences!\n");
channels.initDefaults(); channels.initDefaults();
@ -208,7 +210,8 @@ void NodeDB::init()
// what is stored in flash // what is stored in flash
// if (xstr(HW_VERSION)[0]) // if (xstr(HW_VERSION)[0])
// strncpy(myNodeInfo.region, optstr(HW_VERSION), sizeof(myNodeInfo.region)); // 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); // DEBUG_MSG("legacy region %d\n", devicestate.legacyRadio.preferences.region);
if (radioConfig.preferences.region == RegionCode_Unset) if (radioConfig.preferences.region == RegionCode_Unset)

View File

@ -64,7 +64,7 @@ bool AdminPlugin::handleReceivedProtobuf(const MeshPacket &mp, const AdminMessag
case AdminMessage_get_channel_request_tag: { case AdminMessage_get_channel_request_tag: {
uint32_t i = r->get_channel_request - 1; 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) if (i >= MAX_NUM_CHANNELS)
reply = allocErrorResponse(Routing_Error_BAD_REQUEST, &mp); reply = allocErrorResponse(Routing_Error_BAD_REQUEST, &mp);
else else