From 37eca63e584cd4bf70ddbc8bac78c707837ab2cb Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 4 Feb 2020 13:47:42 -0800 Subject: [PATCH] fix bt reads of owner etc --- TODO.md | 1 - platformio.ini | 2 +- src/MeshBluetoothService.cpp | 2 +- src/NodeDB.cpp | 5 ++--- src/NodeDB.h | 10 +++++----- src/mesh-pb-constants.cpp | 4 ++-- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/TODO.md b/TODO.md index f38cdca0f..29ccb9e0f 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,6 @@ # High priority * implement regen user and radio prefs -* figure out why protobuf reads of Owner fail - debug with jtag * have meshservice send location data on mesh (if device has a GPS) * implement getCurrentTime() - set based off gps but then updated locally * confirm second device receives that gps message and updates device db diff --git a/platformio.ini b/platformio.ini index f3f63be08..fc7d0e2c2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,7 +20,7 @@ framework = arduino board_build.partitions = partition-table.csv ; note: we add src to our include search path so that lmic_project_config can override -build_flags = -Wall -Wextra -Wno-missing-field-initializers -Isrc -O3 -Wl,-Map,.pio/build/esp32/output.map -DAXP_DEBUG_PORT=Serial -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG +build_flags = -Wall -Wextra -Wno-missing-field-initializers -Isrc -O3 -Wl,-Map,.pio/build/esp32/output.map -DAXP_DEBUG_PORT=Serial ; -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG upload_speed = 921600 diff --git a/src/MeshBluetoothService.cpp b/src/MeshBluetoothService.cpp index d105a5779..7416351c3 100644 --- a/src/MeshBluetoothService.cpp +++ b/src/MeshBluetoothService.cpp @@ -229,7 +229,7 @@ When the esp32 advances fromnum, it will delay doing the notify by 100ms, in the Note: that if the phone ever sees this number decrease, it means the esp32 has rebooted. meshMyNodeCharacteristic("ea9f3f82-8dc4-4733-9452-1f6da28892a2", BLECharacteristic::PROPERTY_READ) -mynode - read/write this to access a MyNodeInfo protobuf +mynode - read this to access a MyNodeInfo protobuf meshNodeInfoCharacteristic("d31e02e0-c8ab-4d3f-9cc9-0b8466bdabe8", BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ), nodeinfo - read this to get a series of node infos (ending with a null empty record), write to this to restart the read statemachine that returns all the node infos diff --git a/src/NodeDB.cpp b/src/NodeDB.cpp index 388be804b..9debc47cf 100644 --- a/src/NodeDB.cpp +++ b/src/NodeDB.cpp @@ -43,12 +43,11 @@ uint64_t getCurrentTime() NodeDB::NodeDB() { - } void NodeDB::init() { - ourNodeNum = getDesiredNodeNum(); + myNodeInfo.my_node_num = getDesiredNodeNum(); // Init our blank owner info to reasonable defaults sprintf(owner.id, "!%02x%02x%02x%02x%02x%02x", ourMacAddr[0], @@ -58,7 +57,7 @@ void NodeDB::init() { // FIXME, read owner info from flash // Include our owner in the node db under our nodenum - NodeInfo *info = getOrCreateNode(ourNodeNum); + NodeInfo *info = getOrCreateNode(getNodeNum()); info->user = owner; info->has_user = true; info->last_seen = getCurrentTime(); diff --git a/src/NodeDB.h b/src/NodeDB.h index 4881aff9a..671086581 100644 --- a/src/NodeDB.h +++ b/src/NodeDB.h @@ -6,12 +6,13 @@ #include "mesh-pb-constants.h" #include "MeshTypes.h" +extern MyNodeInfo myNodeInfo; +extern User owner; + class NodeDB { // NodeNum provisionalNodeNum; // if we are trying to find a node num this is our current attempt - NodeNum ourNodeNum = 0; - // A NodeInfo for every node we've seen // Eventually use a smarter datastructure // HashMap nodes; @@ -35,7 +36,7 @@ public: /// we updateGUI and updateGUIforNode if we think our this change is big enough for a redraw void updateFrom(const MeshPacket &p); - NodeNum getNodeNum() { return ourNodeNum; } + NodeNum getNodeNum() { return myNodeInfo.my_node_num; } /// if returns false, that means our node should send a DenyNodeNum response. If true, we think the number is okay for use // bool handleWantNodeNum(NodeNum n); @@ -62,5 +63,4 @@ private: }; extern NodeDB nodeDB; -extern MyNodeInfo myNodeInfo; -extern User owner; + diff --git a/src/mesh-pb-constants.cpp b/src/mesh-pb-constants.cpp index f8c76aa1e..88c156ddf 100644 --- a/src/mesh-pb-constants.cpp +++ b/src/mesh-pb-constants.cpp @@ -11,7 +11,7 @@ size_t pb_encode_to_bytes(uint8_t *destbuf, size_t destbufsize, const pb_msgdesc { pb_ostream_t stream = pb_ostream_from_buffer(destbuf, destbufsize); - if (!pb_encode(&stream, fields, &src_struct)) + if (!pb_encode(&stream, fields, src_struct)) { DEBUG_MSG("Error: can't encode protobuf %s\n", PB_GET_ERROR(&stream)); assert(0); // FIXME - panic @@ -27,7 +27,7 @@ size_t pb_encode_to_bytes(uint8_t *destbuf, size_t destbufsize, const pb_msgdesc bool pb_decode_from_bytes(const uint8_t *srcbuf, size_t srcbufsize, const pb_msgdesc_t *fields, void *dest_struct) { pb_istream_t stream = pb_istream_from_buffer(srcbuf, srcbufsize); - if (!pb_decode(&stream, fields, &dest_struct)) + if (!pb_decode(&stream, fields, dest_struct)) { DEBUG_MSG("Error: can't decode protobuf %s\n", PB_GET_ERROR(&stream)); return false;