From a0b43b9a95da35f95159f034963ad9726788f4c2 Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 12 May 2020 17:57:51 -0700 Subject: [PATCH] Send "unset" for hwver and swver if they were unset --- src/configuration.h | 4 ++++ src/esp32/main-esp32.cpp | 4 ++-- src/main.cpp | 2 +- src/mesh/NodeDB.cpp | 11 +++++++---- src/sleep.cpp | 3 --- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index ca606c53a..04f9d26a1 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -48,9 +48,13 @@ along with this program. If not, see . #define REQUIRE_RADIO true // If true, we will fail to start if the radio is not found +/// Convert a preprocessor name into a quoted string #define xstr(s) str(s) #define str(s) #s +/// Convert a preprocessor name into a quoted string and if that string is empty use "unset" +#define optstr(s) (xstr(s)[0] ? xstr(s) : "unset") + #ifdef NRF52840_XXAA // All of the NRF52 targets are configured using variant.h, so this section shouldn't need to be // board specific diff --git a/src/esp32/main-esp32.cpp b/src/esp32/main-esp32.cpp index 48af9b998..b0e1406b5 100644 --- a/src/esp32/main-esp32.cpp +++ b/src/esp32/main-esp32.cpp @@ -22,8 +22,8 @@ void reinitBluetooth() powerFSM.trigger(EVENT_BLUETOOTH_PAIR); screen.startBluetoothPinScreen(pin); }, - []() { screen.stopBluetoothPinScreen(); }, getDeviceName(), HW_VENDOR, xstr(APP_VERSION), - xstr(HW_VERSION)); // FIXME, use a real name based on the macaddr + []() { screen.stopBluetoothPinScreen(); }, getDeviceName(), HW_VENDOR, optstr(APP_VERSION), + optstr(HW_VERSION)); // FIXME, use a real name based on the macaddr createMeshBluetoothService(serve); // Start advertising - this must be done _after_ creating all services diff --git a/src/main.cpp b/src/main.cpp index 9ba569947..2378458a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -167,7 +167,7 @@ void setup() ledPeriodic.setup(); // Hello - DEBUG_MSG("Meshtastic swver=%s, hwver=%s\n", xstr(APP_VERSION), xstr(HW_VERSION)); + DEBUG_MSG("Meshtastic swver=%s, hwver=%s\n", optstr(APP_VERSION), optstr(HW_VERSION)); #ifndef NO_ESP32 // Don't init display if we don't have one or we are waking headless due to a timer event diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 5d2e8ecd3..cc83f2f47 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -109,10 +109,6 @@ void NodeDB::init() // default to no GPS, until one has been found by probing myNodeInfo.has_gps = false; - strncpy(myNodeInfo.region, xstr(HW_VERSION), sizeof(myNodeInfo.region)); - strncpy(myNodeInfo.firmware_version, xstr(APP_VERSION), sizeof(myNodeInfo.firmware_version)); - strncpy(myNodeInfo.hw_model, HW_VENDOR, sizeof(myNodeInfo.hw_model)); - // Init our blank owner info to reasonable defaults getMacAddr(ourMacAddr); sprintf(owner.id, "!%02x%02x%02x%02x%02x%02x", ourMacAddr[0], ourMacAddr[1], ourMacAddr[2], ourMacAddr[3], ourMacAddr[4], @@ -135,6 +131,13 @@ void NodeDB::init() // saveToDisk(); loadFromDisk(); + + // We set these _after_ loading from disk - because they come from the build and are more trusted than + // what is stored in flash + strncpy(myNodeInfo.region, optstr(HW_VERSION), sizeof(myNodeInfo.region)); + strncpy(myNodeInfo.firmware_version, optstr(APP_VERSION), sizeof(myNodeInfo.firmware_version)); + strncpy(myNodeInfo.hw_model, HW_VENDOR, sizeof(myNodeInfo.hw_model)); + resetRadioConfig(); // If bogus settings got saved, then fix them DEBUG_MSG("NODENUM=0x%x, dbsize=%d\n", myNodeInfo.my_node_num, *numNodes); diff --git a/src/sleep.cpp b/src/sleep.cpp index 4f5fa2fdc..4b8db06b0 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -35,9 +35,6 @@ Observable notifySleep, notifyDeepSleep; // deep sleep support RTC_DATA_ATTR int bootCount = 0; -#define xstr(s) str(s) -#define str(s) #s - // ----------------------------------------------------------------------------- // Application // -----------------------------------------------------------------------------