From c9f2318e78602cd4a8887af343201bc2725f08b6 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Tue, 15 Dec 2020 13:14:36 +0800 Subject: [PATCH] Use simpler names for standard channels --- docs/software/TODO.md | 3 ++- proto | 2 +- src/mesh/NodeDB.cpp | 44 +++++++++++++++++++++++++++++++++---------- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/docs/software/TODO.md b/docs/software/TODO.md index ac5c2d337..e1133ee7c 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -9,7 +9,8 @@ For app cleanup: * DONE check build guide * DONE write devapi user guide * DONE update android code: https://developer.android.com/topic/libraries/view-binding/migration -* test GPIO watch +* DONE test GPIO watch +* set --set-chan-fast, --set-chan-default * writeup docs on gpio * DONE make python ping command * DONE make hello world example service diff --git a/proto b/proto index b1e1a5433..5f580041b 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit b1e1a54330d1a7f74f097dbf27cdba9cfb739473 +Subproject commit 5f580041beeb593d48eabacd2b959df04558c383 diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index bc38ad563..eb8c8cc3d 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -70,10 +70,11 @@ static uint8_t activePSKSize; their nodes * aren't talking to each other. * - * This string is of the form "#name-XY". + * This string is of the form "#name-X". * - * Where X is a letter from A to Z (base26), and formed by xoring all the bytes of the PSK together. - * Y is not yet used but should eventually indicate 'speed/range' of the link + * Where X is either: + * (for custom PSKS) a letter from A to Z (base26), and formed by xoring all the bytes of the PSK together, + * OR (for the standard minimially secure PSKs) a number from 0 to 9. * * This function will also need to be implemented in GUI apps that talk to the radio. * @@ -83,11 +84,19 @@ const char *getChannelName() { static char buf[32]; - uint8_t code = 0; - for (int i = 0; i < activePSKSize; i++) - code ^= activePSK[i]; + char suffix; + if(channelSettings.psk.size != 1) { + // We have a standard PSK, so generate a letter based hash. + uint8_t code = 0; + for (int i = 0; i < activePSKSize; i++) + code ^= activePSK[i]; - snprintf(buf, sizeof(buf), "#%s-%c", channelName, 'A' + (code % 26)); + suffix = 'A' + (code % 26); + } else { + suffix = '0' + channelSettings.psk.bytes[0]; + } + + snprintf(buf, sizeof(buf), "#%s-%c", channelName, suffix); return buf; } @@ -123,14 +132,29 @@ bool NodeDB::resetRadioConfig() strcpy(channelSettings.name, ""); } - // Convert "Default" to our new short representation + // Convert the old string "Default" to our new short representation if(strcmp(channelSettings.name, "Default") == 0) *channelSettings.name = '\0'; // Convert the short "" representation for Default into a usable string channelName = channelSettings.name; - if(!*channelName) // emptystring - channelName = "Default"; + if(!*channelName) { // emptystring + // Per mesh.proto spec, if bandwidth is specified we must ignore modemConfig enum, we assume that in that case + // the app fucked up and forgot to set channelSettings.name + channelName = "Unset"; + if(channelSettings.bandwidth == 0) switch(channelSettings.modem_config) { + case ChannelSettings_ModemConfig_Bw125Cr45Sf128: + channelName = "MediumRange"; break; + case ChannelSettings_ModemConfig_Bw500Cr45Sf128: + channelName = "Fast"; break; + case ChannelSettings_ModemConfig_Bw31_25Cr48Sf512: + channelName = "LongAlt"; break; + case ChannelSettings_ModemConfig_Bw125Cr48Sf4096: + channelName = "LongSlow"; break; + default: + channelName = "Invalid"; break; + } + } // Convert any old usage of the defaultpsk into our new short representation. if(channelSettings.psk.size == sizeof(defaultpsk) &&