From a2c5b928408daec8d5a938fc6cc0f9512ce57475 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 17 Jun 2023 09:10:09 -0500 Subject: [PATCH] NodeDB Lite migration (#2554) * Skadoosh * Removing deprecated fields * Remove remaining deprecations * Macro * Macro * WIP conversion * Lots of type conversions between Lite versions and new NodeDB methods * Trunk * Conversion * NULL * Init * Rename * Position * Reworked conversion to NodeInfo for PhoneAPI --- src/ButtonThread.h | 4 +- src/GPSStatus.h | 8 +- src/gps/NMEAWPL.cpp | 17 ++- src/gps/NMEAWPL.h | 3 +- src/graphics/Screen.cpp | 30 +++--- src/mesh/MeshService.cpp | 21 ++-- src/mesh/MeshService.h | 4 +- src/mesh/NodeDB.cpp | 162 ++++++++++++++++++++++------ src/mesh/NodeDB.h | 61 +++++++---- src/mesh/PhoneAPI.cpp | 26 +++-- src/mesh/PhoneAPI.h | 2 +- src/mesh/ProtobufModule.h | 4 +- src/mesh/Router.cpp | 4 +- src/mesh/TypeConversions.h | 54 ++++++++++ src/modules/CannedMessageModule.cpp | 20 ++-- src/modules/PositionModule.cpp | 47 ++++---- src/modules/RangeTestModule.cpp | 6 +- src/modules/SerialModule.cpp | 12 +-- 18 files changed, 339 insertions(+), 146 deletions(-) create mode 100644 src/mesh/TypeConversions.h diff --git a/src/ButtonThread.h b/src/ButtonThread.h index 173566f938..135d727c27 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -157,7 +157,7 @@ class ButtonThread : public concurrency::OSThread digitalWrite(PIN_EINK_EN, digitalRead(PIN_EINK_EN) == LOW); #endif screen->print("Sent ad-hoc ping\n"); - service.refreshLocalNodeInfo(); + service.refreshLocalMeshNode(); service.sendNetworkPing(NODENUM_BROADCAST, true); } @@ -196,4 +196,4 @@ class ButtonThread : public concurrency::OSThread } }; -} // namespace concurrency +} // namespace concurrency \ No newline at end of file diff --git a/src/GPSStatus.h b/src/GPSStatus.h index 6b760385fc..ed3b3fc143 100644 --- a/src/GPSStatus.h +++ b/src/GPSStatus.h @@ -55,7 +55,7 @@ class GPSStatus : public Status #ifdef GPS_EXTRAVERBOSE LOG_WARN("Using fixed latitude\n"); #endif - meshtastic_NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); + meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); return node->position.latitude_i; } else { return p.latitude_i; @@ -68,7 +68,7 @@ class GPSStatus : public Status #ifdef GPS_EXTRAVERBOSE LOG_WARN("Using fixed longitude\n"); #endif - meshtastic_NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); + meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); return node->position.longitude_i; } else { return p.longitude_i; @@ -81,7 +81,7 @@ class GPSStatus : public Status #ifdef GPS_EXTRAVERBOSE LOG_WARN("Using fixed altitude\n"); #endif - meshtastic_NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); + meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); return node->position.altitude; } else { return p.altitude; @@ -149,4 +149,4 @@ class GPSStatus : public Status } // namespace meshtastic -extern meshtastic::GPSStatus *gpsStatus; +extern meshtastic::GPSStatus *gpsStatus; \ No newline at end of file diff --git a/src/gps/NMEAWPL.cpp b/src/gps/NMEAWPL.cpp index 784ecac5d6..9eff4d00e2 100644 --- a/src/gps/NMEAWPL.cpp +++ b/src/gps/NMEAWPL.cpp @@ -18,7 +18,7 @@ * ------------------------------------------- */ -uint32_t printWPL(char *buf, size_t bufsz, const meshtastic_Position &pos, const char *name, bool isCaltopoMode) +uint32_t printWPL(char *buf, size_t bufsz, const meshtastic_PositionLite &pos, const char *name, bool isCaltopoMode) { GeoCoord geoCoord(pos.latitude_i, pos.longitude_i, pos.altitude); char type = isCaltopoMode ? 'P' : 'N'; @@ -34,6 +34,21 @@ uint32_t printWPL(char *buf, size_t bufsz, const meshtastic_Position &pos, const return len; } +uint32_t printWPL(char *buf, size_t bufsz, const meshtastic_Position &pos, const char *name, bool isCaltopoMode) +{ + GeoCoord geoCoord(pos.latitude_i, pos.longitude_i, pos.altitude); + char type = isCaltopoMode ? 'P' : 'N'; + uint32_t len = snprintf(buf, bufsz, "$G%cWPL,%02d%07.4f,%c,%03d%07.4f,%c,%s", type, geoCoord.getDMSLatDeg(), + (abs(geoCoord.getLatitude()) - geoCoord.getDMSLatDeg() * 1e+7) * 6e-6, geoCoord.getDMSLatCP(), + geoCoord.getDMSLonDeg(), (abs(geoCoord.getLongitude()) - geoCoord.getDMSLonDeg() * 1e+7) * 6e-6, + geoCoord.getDMSLonCP(), name); + uint32_t chk = 0; + for (uint32_t i = 1; i < len; i++) { + chk ^= buf[i]; + } + len += snprintf(buf + len, bufsz - len, "*%02X\r\n", chk); + return len; +} /* ------------------------------------------- * 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 * | | | | | | | | | | | | | | | diff --git a/src/gps/NMEAWPL.h b/src/gps/NMEAWPL.h index d597b7ea68..5821624c68 100644 --- a/src/gps/NMEAWPL.h +++ b/src/gps/NMEAWPL.h @@ -4,4 +4,5 @@ #include uint32_t printWPL(char *buf, size_t bufsz, const meshtastic_Position &pos, const char *name, bool isCaltopoMode = false); -uint32_t printGGA(char *buf, size_t bufsz, const meshtastic_Position &pos); +uint32_t printWPL(char *buf, size_t bufsz, const meshtastic_PositionLite &pos, const char *name, bool isCaltopoMode = false); +uint32_t printGGA(char *buf, size_t bufsz, const meshtastic_Position &pos); \ No newline at end of file diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 6b72a5d7d3..f2c5da4e20 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -373,7 +373,7 @@ static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state static char tempBuf[237]; meshtastic_MeshPacket &mp = devicestate.rx_text_message; - meshtastic_NodeInfo *node = nodeDB.getNode(getFrom(&mp)); + meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(getFrom(&mp)); // LOG_DEBUG("drawing text message from 0x%x: %s\n", mp.from, // mp.decoded.variant.data.decoded.bytes); @@ -411,7 +411,7 @@ static void drawWaypointFrame(OLEDDisplay *display, OLEDDisplayUiState *state, i static char tempBuf[237]; meshtastic_MeshPacket &mp = devicestate.rx_waypoint; - meshtastic_NodeInfo *node = nodeDB.getNode(getFrom(&mp)); + meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(getFrom(&mp)); display->setTextAlignment(TEXT_ALIGN_LEFT); display->setFont(FONT_SMALL); @@ -793,16 +793,16 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ if (state->currentFrame != prevFrame) { prevFrame = state->currentFrame; - nodeIndex = (nodeIndex + 1) % nodeDB.getNumNodes(); - meshtastic_NodeInfo *n = nodeDB.getNodeByIndex(nodeIndex); + nodeIndex = (nodeIndex + 1) % nodeDB.getNumMeshNodes(); + meshtastic_NodeInfoLite *n = nodeDB.getMeshNodeByIndex(nodeIndex); if (n->num == nodeDB.getNodeNum()) { // Don't show our node, just skip to next - nodeIndex = (nodeIndex + 1) % nodeDB.getNumNodes(); - n = nodeDB.getNodeByIndex(nodeIndex); + nodeIndex = (nodeIndex + 1) % nodeDB.getNumMeshNodes(); + n = nodeDB.getMeshNodeByIndex(nodeIndex); } } - meshtastic_NodeInfo *node = nodeDB.getNodeByIndex(nodeIndex); + meshtastic_NodeInfoLite *node = nodeDB.getMeshNodeByIndex(nodeIndex); display->setFont(FONT_SMALL); @@ -836,7 +836,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ static char distStr[20]; strncpy(distStr, "? km", sizeof(distStr)); // might not have location data - meshtastic_NodeInfo *ourNode = nodeDB.getNode(nodeDB.getNodeNum()); + meshtastic_NodeInfoLite *ourNode = nodeDB.getMeshNode(nodeDB.getNodeNum()); const char *fields[] = {username, distStr, signalStr, lastStr, NULL}; int16_t compassX = 0, compassY = 0; @@ -851,14 +851,14 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ bool hasNodeHeading = false; if (ourNode && hasValidPosition(ourNode)) { - meshtastic_Position &op = ourNode->position; + meshtastic_PositionLite &op = ourNode->position; float myHeading = estimatedHeading(DegD(op.latitude_i), DegD(op.longitude_i)); drawCompassNorth(display, compassX, compassY, myHeading); if (hasValidPosition(node)) { // display direction toward node hasNodeHeading = true; - meshtastic_Position &p = node->position; + meshtastic_PositionLite &p = node->position; float d = GeoCoord::latLongToMeter(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i)); @@ -1240,9 +1240,9 @@ void Screen::setFrames() #endif // We don't show the node info our our node (if we have it yet - we should) - size_t numnodes = nodeDB.getNumNodes(); - if (numnodes > 0) - numnodes--; + size_t numMeshNodes = nodeDB.getNumMeshNodes(); + if (numMeshNodes > 0) + numMeshNodes--; size_t numframes = 0; @@ -1273,7 +1273,7 @@ void Screen::setFrames() // then all the nodes // We only show a few nodes in our scrolling list - because meshes with many nodes would have too many screens - size_t numToShow = min(numnodes, 4U); + size_t numToShow = min(numMeshNodes, 4U); for (size_t i = 0; i < numToShow; i++) normalFrames[numframes++] = drawNodeInfo; @@ -1850,4 +1850,4 @@ int Screen::handleUIFrameEvent(const UIFrameEvent *event) } // namespace graphics #else graphics::Screen::Screen(ScanI2C::DeviceAddress, meshtastic_Config_DisplayConfig_OledType, OLEDDISPLAY_GEOMETRY) {} -#endif // HAS_SCREEN +#endif // HAS_SCREEN \ No newline at end of file diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 06d30db4e8..2ad46a6b72 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -9,6 +9,7 @@ #include "NodeDB.h" #include "PowerFSM.h" #include "RTC.h" +#include "TypeConversions.h" #include "main.h" #include "mesh-pb-constants.h" #include "modules/NodeInfoModule.h" @@ -76,7 +77,8 @@ int MeshService::handleFromRadio(const meshtastic_MeshPacket *mp) powerFSM.trigger(EVENT_PACKET_FOR_PHONE); // Possibly keep the node from sleeping nodeDB.updateFrom(*mp); // update our DB state based off sniffing every RX packet from the radio - if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag && !nodeDB.getNode(mp->from)->has_user && nodeInfoModule) { + if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag && !nodeDB.getMeshNode(mp->from)->has_user && + nodeInfoModule) { LOG_INFO("Heard a node on channel %d we don't know, sending NodeInfo and asking for a response.\n", mp->channel); nodeInfoModule->sendOurNodeInfo(mp->from, true, mp->channel); } @@ -236,7 +238,8 @@ void MeshService::sendToMesh(meshtastic_MeshPacket *p, RxSource src, bool ccToPh void MeshService::sendNetworkPing(NodeNum dest, bool wantReplies) { - meshtastic_NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); + meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); + assert(node); if (hasValidPosition(node)) { @@ -266,9 +269,9 @@ void MeshService::sendToPhone(meshtastic_MeshPacket *p) fromNum++; } -meshtastic_NodeInfo *MeshService::refreshLocalNodeInfo() +meshtastic_NodeInfoLite *MeshService::refreshLocalMeshNode() { - meshtastic_NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); + meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); assert(node); // We might not have a position yet for our local node, in that case, at least try to send the time @@ -277,7 +280,7 @@ meshtastic_NodeInfo *MeshService::refreshLocalNodeInfo() node->has_position = true; } - meshtastic_Position &position = node->position; + meshtastic_PositionLite &position = node->position; // Update our local node info with our time (even if we don't decide to update anyone else) node->last_heard = @@ -293,7 +296,7 @@ meshtastic_NodeInfo *MeshService::refreshLocalNodeInfo() int MeshService::onGPSChanged(const meshtastic::GPSStatus *newStatus) { // Update our local node info with our position (even if we don't decide to update anyone else) - meshtastic_NodeInfo *node = refreshLocalNodeInfo(); + meshtastic_NodeInfoLite *node = refreshLocalMeshNode(); meshtastic_Position pos = meshtastic_Position_init_default; if (newStatus->getHasLock()) { @@ -307,12 +310,12 @@ int MeshService::onGPSChanged(const meshtastic::GPSStatus *newStatus) #endif if (config.position.fixed_position) { LOG_WARN("Using fixed position\n"); - pos = node->position; + pos = ConvertToPosition(node->position); } } // Finally add a fresh timestamp and battery level reading - // I KNOW this is redundant with refreshLocalNodeInfo() above, but these are + // I KNOW this is redundant with refreshLocalMeshNode() above, but these are // inexpensive nonblocking calls and can be refactored in due course pos.time = getValidTime(RTCQualityGPS); @@ -329,4 +332,4 @@ int MeshService::onGPSChanged(const meshtastic::GPSStatus *newStatus) bool MeshService::isToPhoneQueueEmpty() { return toPhoneQueue.isEmpty(); -} +} \ No newline at end of file diff --git a/src/mesh/MeshService.h b/src/mesh/MeshService.h index 96878492be..d14db71391 100644 --- a/src/mesh/MeshService.h +++ b/src/mesh/MeshService.h @@ -98,7 +98,7 @@ class MeshService bool cancelSending(PacketId id); /// Pull the latest power and time info into my nodeinfo - meshtastic_NodeInfo *refreshLocalNodeInfo(); + meshtastic_NodeInfoLite *refreshLocalMeshNode(); /// Send a packet to the phone void sendToPhone(meshtastic_MeshPacket *p); @@ -118,4 +118,4 @@ class MeshService ErrorCode sendQueueStatusToPhone(const meshtastic_QueueStatus &qs, ErrorCode res, uint32_t mesh_packet_id); }; -extern MeshService service; +extern MeshService service; \ No newline at end of file diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index a18d0a7b4d..0d95d2cbfc 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -11,6 +11,7 @@ #include "PowerFSM.h" #include "RTC.h" #include "Router.h" +#include "TypeConversions.h" #include "error.h" #include "main.h" #include "mesh-pb-constants.h" @@ -55,14 +56,18 @@ extern void getMacAddr(uint8_t *dmac); * we use !macaddr (no colons). */ meshtastic_User &owner = devicestate.owner; - +meshtastic_Position localPosition = meshtastic_Position_init_default; meshtastic_CriticalErrorCode error_code = meshtastic_CriticalErrorCode_NONE; // For the error code, only show values from this boot (discard value from flash) uint32_t error_address = 0; static uint8_t ourMacAddr[6]; -NodeDB::NodeDB() : nodes(devicestate.node_db), numNodes(&devicestate.node_db_count) {} +NodeDB::NodeDB() + : nodes(devicestate.node_db), numNodes(&devicestate.node_db_count), meshNodes(devicestate.node_db_lite), + numMeshNodes(&devicestate.node_db_lite_count) +{ +} /** * Most (but not always) of the time we want to treat packets 'from' the local phone (where from == 0), as if they originated on @@ -262,6 +267,9 @@ void NodeDB::resetNodes() { devicestate.node_db_count = 0; memset(devicestate.node_db, 0, sizeof(devicestate.node_db)); + + devicestate.node_db_lite_count = 0; + memset(devicestate.node_db_lite, 0, sizeof(devicestate.node_db_lite)); saveDeviceStateToDisk(); } @@ -276,6 +284,7 @@ void NodeDB::installDefaultDeviceState() devicestate.has_my_node = true; devicestate.has_owner = true; devicestate.node_db_count = 0; + devicestate.node_db_lite_count = 0; devicestate.version = DEVICESTATE_CUR_VER; devicestate.receive_queue_count = 0; // Not yet implemented FIXME @@ -315,10 +324,23 @@ void NodeDB::init() owner.hw_model = HW_VENDOR; // Include our owner in the node db under our nodenum - meshtastic_NodeInfo *info = getOrCreateNode(getNodeNum()); + meshtastic_NodeInfoLite *info = getOrCreateMeshNode(getNodeNum()); info->user = owner; info->has_user = true; + if (*numNodes > 0) { + LOG_DEBUG("Legacy NodeDB detected... Migrating to NodeDBLite\n"); + uint32_t readIndex = 0; + const meshtastic_NodeInfo *oldNodeInfo = nodeDB.readNextNodeInfo(readIndex); + while (oldNodeInfo != NULL) { + migrateToNodeInfoLite(oldNodeInfo); + oldNodeInfo = nodeDB.readNextNodeInfo(readIndex); + } + LOG_DEBUG("Migration complete! Clearing out legacy NodeDB...\n"); + devicestate.node_db_count = 0; + memset(devicestate.node_db, 0, sizeof(devicestate.node_db)); + } + #ifdef ARCH_ESP32 Preferences preferences; preferences.begin("meshtastic", false); @@ -362,8 +384,8 @@ void NodeDB::pickNewNodeNum() if (r == NODENUM_BROADCAST || r < NUM_RESERVED) r = NUM_RESERVED; // don't pick a reserved node number - meshtastic_NodeInfo *found; - while ((found = getNode(r)) && memcmp(found->user.macaddr, owner.macaddr, sizeof(owner.macaddr))) { + meshtastic_NodeInfoLite *found; + while ((found = getMeshNode(r)) && memcmp(found->user.macaddr, owner.macaddr, sizeof(owner.macaddr))) { NodeNum n = random(NUM_RESERVED, NODENUM_BROADCAST); // try a new random choice LOG_DEBUG("NOTE! Our desired nodenum 0x%x is in use, so trying for 0x%x\n", r, n); r = n; @@ -572,7 +594,7 @@ void NodeDB::saveToDisk(int saveWhat) } } -const meshtastic_NodeInfo *NodeDB::readNextInfo(uint32_t &readIndex) +const meshtastic_NodeInfo *NodeDB::readNextNodeInfo(uint32_t &readIndex) { if (readIndex < *numNodes) return &nodes[readIndex++]; @@ -580,8 +602,16 @@ const meshtastic_NodeInfo *NodeDB::readNextInfo(uint32_t &readIndex) return NULL; } +const meshtastic_NodeInfoLite *NodeDB::readNextMeshNode(uint32_t &readIndex) +{ + if (readIndex < *numMeshNodes) + return &meshNodes[readIndex++]; + else + return NULL; +} + /// Given a node, return how many seconds in the past (vs now) that we last heard from it -uint32_t sinceLastSeen(const meshtastic_NodeInfo *n) +uint32_t sinceLastSeen(const meshtastic_NodeInfoLite *n) { uint32_t now = getTime(); @@ -605,13 +635,13 @@ uint32_t sinceReceived(const meshtastic_MeshPacket *p) #define NUM_ONLINE_SECS (60 * 60 * 2) // 2 hrs to consider someone offline -size_t NodeDB::getNumOnlineNodes() +size_t NodeDB::getNumOnlineMeshNodes() { size_t numseen = 0; // FIXME this implementation is kinda expensive - for (int i = 0; i < *numNodes; i++) - if (sinceLastSeen(&nodes[i]) < NUM_ONLINE_SECS) + for (int i = 0; i < *numMeshNodes; i++) + if (sinceLastSeen(&meshNodes[i]) < NUM_ONLINE_SECS) numseen++; return numseen; @@ -623,7 +653,7 @@ size_t NodeDB::getNumOnlineNodes() */ void NodeDB::updatePosition(uint32_t nodeId, const meshtastic_Position &p, RxSource src) { - meshtastic_NodeInfo *info = getOrCreateNode(nodeId); + meshtastic_NodeInfoLite *info = getOrCreateMeshNode(nodeId); if (!info) { return; } @@ -632,7 +662,9 @@ void NodeDB::updatePosition(uint32_t nodeId, const meshtastic_Position &p, RxSou // Local packet, fully authoritative LOG_INFO("updatePosition LOCAL pos@%x, time=%u, latI=%d, lonI=%d, alt=%d\n", p.timestamp, p.time, p.latitude_i, p.longitude_i, p.altitude); - info->position = p; + + info->position = ConvertToPositionLite(p); + localPosition = p; } else if ((p.time > 0) && !p.latitude_i && !p.longitude_i && !p.timestamp && !p.location_source) { // FIXME SPECIAL TIME SETTING PACKET FROM EUD TO RADIO // (stop-gap fix for issue #900) @@ -650,7 +682,7 @@ void NodeDB::updatePosition(uint32_t nodeId, const meshtastic_Position &p, RxSou uint32_t tmp_time = info->position.time; // Next, update atomically - info->position = p; + info->position = ConvertToPositionLite(p); // Last, restore any fields that may have been overwritten if (!info->position.time) @@ -666,7 +698,7 @@ void NodeDB::updatePosition(uint32_t nodeId, const meshtastic_Position &p, RxSou */ void NodeDB::updateTelemetry(uint32_t nodeId, const meshtastic_Telemetry &t, RxSource src) { - meshtastic_NodeInfo *info = getOrCreateNode(nodeId); + meshtastic_NodeInfoLite *info = getOrCreateMeshNode(nodeId); // Environment metrics should never go to NodeDb but we'll safegaurd anyway if (!info || t.which_variant != meshtastic_Telemetry_device_metrics_tag) { return; @@ -688,7 +720,7 @@ void NodeDB::updateTelemetry(uint32_t nodeId, const meshtastic_Telemetry &t, RxS */ bool NodeDB::updateUser(uint32_t nodeId, const meshtastic_User &p) { - meshtastic_NodeInfo *info = getOrCreateNode(nodeId); + meshtastic_NodeInfoLite *info = getOrCreateMeshNode(nodeId); if (!info) { return false; } @@ -721,7 +753,7 @@ void NodeDB::updateFrom(const meshtastic_MeshPacket &mp) if (mp.which_payload_variant == meshtastic_MeshPacket_decoded_tag && mp.from) { LOG_DEBUG("Update DB node 0x%x, rx_time=%u, channel=%d\n", mp.from, mp.rx_time, mp.channel); - meshtastic_NodeInfo *info = getOrCreateNode(getFrom(&mp)); + meshtastic_NodeInfoLite *info = getOrCreateMeshNode(getFrom(&mp)); if (!info) { return; } @@ -738,9 +770,9 @@ void NodeDB::updateFrom(const meshtastic_MeshPacket &mp) } } -uint8_t NodeDB::getNodeChannel(NodeNum n) +uint8_t NodeDB::getMeshNodeChannel(NodeNum n) { - meshtastic_NodeInfo *info = getNode(n); + meshtastic_NodeInfoLite *info = getMeshNode(n); if (!info) { return 0; // defaults to PRIMARY } @@ -749,7 +781,7 @@ uint8_t NodeDB::getNodeChannel(NodeNum n) /// Find a node in our DB, return null for missing /// NOTE: This function might be called from an ISR -meshtastic_NodeInfo *NodeDB::getNode(NodeNum n) +meshtastic_NodeInfo *NodeDB::getNodeInfo(NodeNum n) { for (int i = 0; i < *numNodes; i++) if (nodes[i].num == n) @@ -758,38 +790,100 @@ meshtastic_NodeInfo *NodeDB::getNode(NodeNum n) return NULL; } +/// Find a node in our DB, return null for missing +/// NOTE: This function might be called from an ISR +meshtastic_NodeInfoLite *NodeDB::getMeshNode(NodeNum n) +{ + for (int i = 0; i < *numMeshNodes; i++) + if (meshNodes[i].num == n) + return &meshNodes[i]; + + return NULL; +} + /// Find a node in our DB, create an empty NodeInfo if missing -meshtastic_NodeInfo *NodeDB::getOrCreateNode(NodeNum n) +meshtastic_NodeInfoLite *NodeDB::getOrCreateMeshNode(NodeNum n) { - meshtastic_NodeInfo *info = getNode(n); + meshtastic_NodeInfoLite *lite = getMeshNode(n); - if (!info) { - if ((*numNodes >= MAX_NUM_NODES) || (memGet.getFreeHeap() < meshtastic_NodeInfo_size * 3)) { - screen->print("warning: node_db full! erasing oldest entry\n"); + if (!lite) { + if ((*numMeshNodes >= MAX_NUM_NODES) || (memGet.getFreeHeap() < meshtastic_NodeInfoLite_size * 3)) { + screen->print("warning: node_db_lite full! erasing oldest entry\n"); // look for oldest node and erase it uint32_t oldest = UINT32_MAX; int oldestIndex = -1; - for (int i = 0; i < *numNodes; i++) { - if (nodes[i].last_heard < oldest) { - oldest = nodes[i].last_heard; + for (int i = 0; i < *numMeshNodes; i++) { + if (meshNodes[i].last_heard < oldest) { + oldest = meshNodes[i].last_heard; oldestIndex = i; } } // Shove the remaining nodes down the chain - for (int i = oldestIndex; i < *numNodes - 1; i++) { - nodes[i] = nodes[i + 1]; + for (int i = oldestIndex; i < *numMeshNodes - 1; i++) { + meshNodes[i] = meshNodes[i + 1]; } - (*numNodes)--; + (*numMeshNodes)--; } // add the node at the end - info = &nodes[(*numNodes)++]; + lite = &meshNodes[(*numMeshNodes)++]; // everything is missing except the nodenum - memset(info, 0, sizeof(*info)); - info->num = n; + memset(lite, 0, sizeof(*lite)); + lite->num = n; } - return info; + return lite; +} + +void NodeDB::migrateToNodeInfoLite(const meshtastic_NodeInfo *node) +{ + meshtastic_NodeInfoLite *lite = getMeshNode(node->num); + + if (!lite) { + if ((*numMeshNodes >= MAX_NUM_NODES) || (memGet.getFreeHeap() < meshtastic_NodeInfoLite_size * 3)) { + screen->print("warning: node_db_lite full! erasing oldest entry\n"); + // look for oldest node and erase it + uint32_t oldest = UINT32_MAX; + int oldestIndex = -1; + for (int i = 0; i < *numMeshNodes; i++) { + if (meshNodes[i].last_heard < oldest) { + oldest = meshNodes[i].last_heard; + oldestIndex = i; + } + } + // Shove the remaining nodes down the chain + for (int i = oldestIndex; i < *numMeshNodes - 1; i++) { + meshNodes[i] = meshNodes[i + 1]; + } + (*numMeshNodes)--; + } + // add the node at the end + lite = &meshNodes[(*numMeshNodes)++]; + + // everything is missing except the nodenum + memset(lite, 0, sizeof(*lite)); + lite->num = node->num; + lite->snr = node->snr; + lite->last_heard = node->last_heard; + lite->channel = node->channel; + + if (node->has_position) { + lite->has_position = true; + lite->position.latitude_i = node->position.latitude_i; + lite->position.longitude_i = node->position.longitude_i; + lite->position.altitude = node->position.altitude; + lite->position.location_source = node->position.location_source; + lite->position.time = node->position.time; + } + if (node->has_user) { + lite->has_user = true; + lite->user = node->user; + } + if (node->has_device_metrics) { + lite->has_device_metrics = true; + lite->device_metrics = node->device_metrics; + } + } } /// Record an error that should be reported via analytics diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index e0744865f6..83d9e252fe 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -29,9 +29,10 @@ extern meshtastic_LocalConfig config; extern meshtastic_LocalModuleConfig moduleConfig; extern meshtastic_OEMStore oemStore; extern meshtastic_User &owner; +extern meshtastic_Position localPosition; /// Given a node, return how many seconds in the past (vs now) that we last heard from it -uint32_t sinceLastSeen(const meshtastic_NodeInfo *n); +uint32_t sinceLastSeen(const meshtastic_NodeInfoLite *n); /// Given a packet, return how many seconds in the past (vs now) it was received uint32_t sinceReceived(const meshtastic_MeshPacket *p); @@ -47,9 +48,12 @@ class NodeDB meshtastic_NodeInfo *nodes; pb_size_t *numNodes; + meshtastic_NodeInfoLite *meshNodes; + pb_size_t *numMeshNodes; + public: bool updateGUI = false; // we think the gui should definitely be redrawn, screen will clear this once handled - meshtastic_NodeInfo *updateGUIforNode = NULL; // if currently showing this node, we think you should update the GUI + meshtastic_NodeInfoLite *updateGUIforNode = NULL; // if currently showing this node, we think you should update the GUI Observable newStatus; /// don't do mesh based algoritm for node id assignment (initially) @@ -90,8 +94,6 @@ class NodeDB /// @return our node number NodeNum getNodeNum() { return myNodeInfo.my_node_num; } - size_t getNumNodes() { return *numNodes; } - /// 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); @@ -103,26 +105,14 @@ class NodeDB their denial?) */ - /// Allow the bluetooth layer to read our next nodeinfo record, or NULL if done reading - const meshtastic_NodeInfo *readNextInfo(uint32_t &readIndex); - /// pick a provisional nodenum we hope no one is using void pickNewNodeNum(); // get channel channel index we heard a nodeNum on, defaults to 0 if not found - uint8_t getNodeChannel(NodeNum n); - - /// Find a node in our DB, return null for missing - meshtastic_NodeInfo *getNode(NodeNum n); - - meshtastic_NodeInfo *getNodeByIndex(size_t x) - { - assert(x < *numNodes); - return &nodes[x]; - } + uint8_t getMeshNodeChannel(NodeNum n); /// Return the number of nodes we've heard from recently (within the last 2 hrs?) - size_t getNumOnlineNodes(); + size_t getNumOnlineMeshNodes(); void initConfigIntervals(), initModuleConfigIntervals(), resetNodes(); @@ -133,15 +123,38 @@ class NodeDB void installRoleDefaults(meshtastic_Config_DeviceConfig_Role role); + const meshtastic_NodeInfoLite *readNextMeshNode(uint32_t &readIndex); + + meshtastic_NodeInfoLite *getMeshNodeByIndex(size_t x) + { + assert(x < *numMeshNodes); + return &meshNodes[x]; + } + + meshtastic_NodeInfoLite *getMeshNode(NodeNum n); + size_t getNumMeshNodes() { return *numMeshNodes; } + private: - /// Find a node in our DB, create an empty NodeInfo if missing - meshtastic_NodeInfo *getOrCreateNode(NodeNum n); + /// Find a node in our DB, create an empty NodeInfoLite if missing + meshtastic_NodeInfoLite *getOrCreateMeshNode(NodeNum n); + void migrateToNodeInfoLite(const meshtastic_NodeInfo *node); + /// Find a node in our DB, return null for missing + meshtastic_NodeInfo *getNodeInfo(NodeNum n); + /// Allow the bluetooth layer to read our next nodeinfo record, or NULL if done reading + const meshtastic_NodeInfo *readNextNodeInfo(uint32_t &readIndex); + size_t getNumNodes() { return *numNodes; } + + meshtastic_NodeInfo *getNodeByIndex(size_t x) + { + assert(x < *numNodes); + return &nodes[x]; + } /// Notify observers of changes to the DB void notifyObservers(bool forceUpdate = false) { // Notify observers of the current node state - const meshtastic::NodeStatus status = meshtastic::NodeStatus(getNumOnlineNodes(), getNumNodes(), forceUpdate); + const meshtastic::NodeStatus status = meshtastic::NodeStatus(getNumOnlineMeshNodes(), getNumMeshNodes(), forceUpdate); newStatus.notifyObservers(&status); } @@ -219,6 +232,10 @@ static inline bool hasValidPosition(const meshtastic_NodeInfo *n) { return n->has_position && (n->position.latitude_i != 0 || n->position.longitude_i != 0); } +static inline bool hasValidPosition(const meshtastic_NodeInfoLite *n) +{ + return n->has_position && (n->position.latitude_i != 0 || n->position.longitude_i != 0); +} /** The current change # for radio settings. Starts at 0 on boot and any time the radio settings * might have changed is incremented. Allows others to detect they might now be on a new channel. @@ -235,4 +252,4 @@ extern uint32_t error_address; #define Module_Config_size \ (ModuleConfig_CannedMessageConfig_size + ModuleConfig_ExternalNotificationConfig_size + ModuleConfig_MQTTConfig_size + \ ModuleConfig_RangeTestConfig_size + ModuleConfig_SerialConfig_size + ModuleConfig_StoreForwardConfig_size + \ - ModuleConfig_TelemetryConfig_size + ModuleConfig_size) + ModuleConfig_TelemetryConfig_size + ModuleConfig_size) \ No newline at end of file diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 5fc27a2b5a..ebc8863018 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -5,6 +5,7 @@ #include "NodeDB.h" #include "PowerFSM.h" #include "RadioInterface.h" +#include "TypeConversions.h" #include "configuration.h" #include "main.h" #include "xmodem.h" @@ -40,7 +41,7 @@ void PhoneAPI::handleStartConfig() state = STATE_SEND_MY_INFO; LOG_INFO("Starting API client config\n"); - nodeInfoForPhone = NULL; // Don't keep returning old nodeinfos + nodeInfoForPhone.num = 0; // Don't keep returning old nodeinfos resetReadIndex(); } @@ -147,20 +148,19 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) fromRadioScratch.my_info = myNodeInfo; state = STATE_SEND_NODEINFO; - service.refreshLocalNodeInfo(); // Update my NodeInfo because the client will be asking for it soon. + service.refreshLocalMeshNode(); // Update my NodeInfo because the client will be asking for it soon. break; case STATE_SEND_NODEINFO: { LOG_INFO("getFromRadio=STATE_SEND_NODEINFO\n"); - const meshtastic_NodeInfo *info = nodeInfoForPhone; - nodeInfoForPhone = NULL; // We just consumed a nodeinfo, will need a new one next time - if (info) { - LOG_INFO("Sending nodeinfo: num=0x%x, lastseen=%u, id=%s, name=%s\n", info->num, info->last_heard, info->user.id, - info->user.long_name); + if (nodeInfoForPhone.num != 0) { + LOG_INFO("nodeinfo: num=0x%x, lastseen=%u, id=%s, name=%s\n", nodeInfoForPhone.num, nodeInfoForPhone.last_heard, + nodeInfoForPhone.user.id, nodeInfoForPhone.user.long_name); fromRadioScratch.which_payload_variant = meshtastic_FromRadio_node_info_tag; - fromRadioScratch.node_info = *info; + fromRadioScratch.node_info = nodeInfoForPhone; // Stay in current state until done sending nodeinfos + nodeInfoForPhone.num = 0; // We just consumed a nodeinfo, will need a new one next time } else { LOG_INFO("Done sending nodeinfos\n"); state = STATE_SEND_CHANNELS; @@ -370,8 +370,12 @@ bool PhoneAPI::available() return true; case STATE_SEND_NODEINFO: - if (!nodeInfoForPhone) - nodeInfoForPhone = nodeDB.readNextInfo(readIndex); + if (nodeInfoForPhone.num == 0) { + auto nextNode = nodeDB.readNextMeshNode(readIndex); + if (nextNode) { + nodeInfoForPhone = ConvertToNodeInfo(nextNode); + } + } return true; // Always say we have something, because we might need to advance our state machine case STATE_SEND_PACKETS: { @@ -426,4 +430,4 @@ int PhoneAPI::onNotify(uint32_t newValue) } return 0; -} +} \ No newline at end of file diff --git a/src/mesh/PhoneAPI.h b/src/mesh/PhoneAPI.h index 2ea4d3a0cf..8097ad34b5 100644 --- a/src/mesh/PhoneAPI.h +++ b/src/mesh/PhoneAPI.h @@ -51,7 +51,7 @@ class PhoneAPI meshtastic_QueueStatus *queueStatusPacketForPhone = NULL; /// We temporarily keep the nodeInfo here between the call to available and getFromRadio - const meshtastic_NodeInfo *nodeInfoForPhone = NULL; + meshtastic_NodeInfo nodeInfoForPhone = meshtastic_NodeInfo_init_default; meshtastic_ToRadio toRadioScratch = { 0}; // this is a static scratch object, any data must be copied elsewhere before returning diff --git a/src/mesh/ProtobufModule.h b/src/mesh/ProtobufModule.h index bdfdea9adc..1771f4322f 100644 --- a/src/mesh/ProtobufModule.h +++ b/src/mesh/ProtobufModule.h @@ -52,7 +52,7 @@ template class ProtobufModule : protected SinglePortModule */ const char *getSenderShortName(const meshtastic_MeshPacket &mp) { - auto node = nodeDB.getNode(getFrom(&mp)); + auto node = nodeDB.getMeshNode(getFrom(&mp)); const char *sender = (node) ? node->user.short_name : "???"; return sender; } @@ -86,4 +86,4 @@ template class ProtobufModule : protected SinglePortModule return handleReceivedProtobuf(mp, decoded) ? ProcessMessage::STOP : ProcessMessage::CONTINUE; } -}; +}; \ No newline at end of file diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 156b482093..6f020d7392 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -178,7 +178,7 @@ ErrorCode Router::sendLocal(meshtastic_MeshPacket *p, RxSource src) } if (!p->channel) { // don't override if a channel was requested - p->channel = nodeDB.getNodeChannel(p->to); + p->channel = nodeDB.getMeshNodeChannel(p->to); LOG_DEBUG("localSend to channel %d\n", p->channel); } @@ -493,4 +493,4 @@ void Router::perhapsHandleReceived(meshtastic_MeshPacket *p) handleReceived(p); packetPool.release(p); -} +} \ No newline at end of file diff --git a/src/mesh/TypeConversions.h b/src/mesh/TypeConversions.h new file mode 100644 index 0000000000..bfc87102bf --- /dev/null +++ b/src/mesh/TypeConversions.h @@ -0,0 +1,54 @@ +#include "mesh/generated/meshtastic/deviceonly.pb.h" +#include "mesh/generated/meshtastic/mesh.pb.h" + +inline static meshtastic_NodeInfo ConvertToNodeInfo(const meshtastic_NodeInfoLite *lite) +{ + meshtastic_NodeInfo info = meshtastic_NodeInfo_init_default; + + info.num = lite->num; + info.snr = lite->snr; + info.last_heard = lite->last_heard; + info.channel = lite->channel; + + if (lite->has_position) { + info.has_position = true; + info.position.latitude_i = lite->position.latitude_i; + info.position.longitude_i = lite->position.longitude_i; + info.position.altitude = lite->position.altitude; + info.position.location_source = lite->position.location_source; + info.position.time = lite->position.time; + } + if (lite->has_user) { + info.has_user = true; + info.user = lite->user; + } + if (lite->has_device_metrics) { + info.has_device_metrics = true; + info.device_metrics = lite->device_metrics; + } + return info; +} + +inline static meshtastic_PositionLite ConvertToPositionLite(meshtastic_Position position) +{ + meshtastic_PositionLite lite = meshtastic_PositionLite_init_default; + lite.latitude_i = position.latitude_i; + lite.longitude_i = position.longitude_i; + lite.altitude = position.altitude; + lite.location_source = position.location_source; + lite.time = position.time; + + return lite; +} + +inline static meshtastic_Position ConvertToPosition(meshtastic_PositionLite lite) +{ + meshtastic_Position position = meshtastic_Position_init_default; + position.latitude_i = lite.latitude_i; + position.longitude_i = lite.longitude_i; + position.altitude = lite.altitude; + position.location_source = lite.location_source; + position.time = lite.time; + + return position; +} \ No newline at end of file diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 5fba2b5de5..bbd39f696b 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -305,13 +305,14 @@ int32_t CannedMessageModule::runOnce() switch (this->payload) { case 0xb4: // left if (this->destSelect) { - size_t numNodes = nodeDB.getNumNodes(); + size_t numMeshNodes = nodeDB.getNumMeshNodes(); if (this->dest == NODENUM_BROADCAST) { this->dest = nodeDB.getNodeNum(); } - for (unsigned int i = 0; i < numNodes; i++) { - if (nodeDB.getNodeByIndex(i)->num == this->dest) { - this->dest = (i > 0) ? nodeDB.getNodeByIndex(i - 1)->num : nodeDB.getNodeByIndex(numNodes - 1)->num; + for (unsigned int i = 0; i < numMeshNodes; i++) { + if (nodeDB.getMeshNodeByIndex(i)->num == this->dest) { + this->dest = + (i > 0) ? nodeDB.getMeshNodeByIndex(i - 1)->num : nodeDB.getMeshNodeByIndex(numMeshNodes - 1)->num; break; } } @@ -326,13 +327,14 @@ int32_t CannedMessageModule::runOnce() break; case 0xb7: // right if (this->destSelect) { - size_t numNodes = nodeDB.getNumNodes(); + size_t numMeshNodes = nodeDB.getNumMeshNodes(); if (this->dest == NODENUM_BROADCAST) { this->dest = nodeDB.getNodeNum(); } - for (unsigned int i = 0; i < numNodes; i++) { - if (nodeDB.getNodeByIndex(i)->num == this->dest) { - this->dest = (i < numNodes - 1) ? nodeDB.getNodeByIndex(i + 1)->num : nodeDB.getNodeByIndex(0)->num; + for (unsigned int i = 0; i < numMeshNodes; i++) { + if (nodeDB.getMeshNodeByIndex(i)->num == this->dest) { + this->dest = + (i < numMeshNodes - 1) ? nodeDB.getMeshNodeByIndex(i + 1)->num : nodeDB.getMeshNodeByIndex(0)->num; break; } } @@ -409,7 +411,7 @@ const char *CannedMessageModule::getNodeName(NodeNum node) if (node == NODENUM_BROADCAST) { return "Broadcast"; } else { - meshtastic_NodeInfo *info = nodeDB.getNode(node); + meshtastic_NodeInfoLite *info = nodeDB.getMeshNode(node); if (info != NULL) { return info->user.long_name; } else { diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index 42066ad5b9..35457a23e6 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -3,6 +3,7 @@ #include "NodeDB.h" #include "RTC.h" #include "Router.h" +#include "TypeConversions.h" #include "airtime.h" #include "configuration.h" #include "gps/GeoCoord.h" @@ -56,55 +57,57 @@ bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes meshtastic_MeshPacket *PositionModule::allocReply() { - meshtastic_NodeInfo *node = service.refreshLocalNodeInfo(); // should guarantee there is now a position + meshtastic_NodeInfoLite *node = service.refreshLocalMeshNode(); // should guarantee there is now a position assert(node->has_position); - node->position.seq_number++; - // configuration of POSITION packet // consider making this a function argument? uint32_t pos_flags = config.position.position_flags; // Populate a Position struct with ONLY the requested fields meshtastic_Position p = meshtastic_Position_init_default; // Start with an empty structure + if (localPosition.latitude_i == 0 && localPosition.longitude_i == 0) { + localPosition = ConvertToPosition(node->position); + } + localPosition.seq_number++; // lat/lon are unconditionally included - IF AVAILABLE! - p.latitude_i = node->position.latitude_i; - p.longitude_i = node->position.longitude_i; - p.time = node->position.time; + p.latitude_i = localPosition.latitude_i; + p.longitude_i = localPosition.longitude_i; + p.time = localPosition.time; if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE) { if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE_MSL) - p.altitude = node->position.altitude; + p.altitude = localPosition.altitude; else - p.altitude_hae = node->position.altitude_hae; + p.altitude_hae = localPosition.altitude_hae; if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_GEOIDAL_SEPARATION) - p.altitude_geoidal_separation = node->position.altitude_geoidal_separation; + p.altitude_geoidal_separation = localPosition.altitude_geoidal_separation; } if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_DOP) { if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_HVDOP) { - p.HDOP = node->position.HDOP; - p.VDOP = node->position.VDOP; + p.HDOP = localPosition.HDOP; + p.VDOP = localPosition.VDOP; } else - p.PDOP = node->position.PDOP; + p.PDOP = localPosition.PDOP; } if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_SATINVIEW) - p.sats_in_view = node->position.sats_in_view; + p.sats_in_view = localPosition.sats_in_view; if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_TIMESTAMP) - p.timestamp = node->position.timestamp; + p.timestamp = localPosition.timestamp; if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_SEQ_NO) - p.seq_number = node->position.seq_number; + p.seq_number = localPosition.seq_number; if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_HEADING) - p.ground_track = node->position.ground_track; + p.ground_track = localPosition.ground_track; if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_SPEED) - p.ground_speed = node->position.ground_speed; + p.ground_speed = localPosition.ground_speed; // Strip out any time information before sending packets to other nodes - to keep the wire size small (and because other // nodes shouldn't trust it anyways) Note: we allow a device with a local GPS to include the time, so that gpsless @@ -144,7 +147,7 @@ void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t cha int32_t PositionModule::runOnce() { - meshtastic_NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); + meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); // We limit our GPS broadcasts to a max rate uint32_t now = millis(); @@ -164,14 +167,14 @@ int32_t PositionModule::runOnce() bool requestReplies = currentGeneration != radioGeneration; currentGeneration = radioGeneration; - LOG_INFO("Sending pos@%x:6 to mesh (wantReplies=%d)\n", node->position.timestamp, requestReplies); + LOG_INFO("Sending pos@%x:6 to mesh (wantReplies=%d)\n", localPosition.timestamp, requestReplies); sendOurPosition(NODENUM_BROADCAST, requestReplies); } } } else if (config.position.position_broadcast_smart_enabled) { // Only send packets if the channel is less than 25% utilized or we're a tracker. if (airTime->isTxAllowedChannelUtil(config.device.role != meshtastic_Config_DeviceConfig_Role_TRACKER)) { - meshtastic_NodeInfo *node2 = service.refreshLocalNodeInfo(); // should guarantee there is now a position + meshtastic_NodeInfoLite *node2 = service.refreshLocalMeshNode(); // should guarantee there is now a position if (hasValidPosition(node2)) { // The minimum distance to travel before we are able to send a new position packet. @@ -193,7 +196,7 @@ int32_t PositionModule::runOnce() LOG_INFO("Sending smart pos@%x:6 to mesh (distanceTraveled=%fm, minDistanceThreshold=%im, timeElapsed=%ims, " "minTimeInterval=%ims)\n", - node2->position.timestamp, abs(distanceTraveledSinceLastSend), distanceTravelThreshold, + localPosition.timestamp, abs(distanceTraveledSinceLastSend), distanceTravelThreshold, msSinceLastSend, minimumTimeThreshold); sendOurPosition(NODENUM_BROADCAST, requestReplies); @@ -211,4 +214,4 @@ int32_t PositionModule::runOnce() } return 5000; // to save power only wake for our callback occasionally -} +} \ No newline at end of file diff --git a/src/modules/RangeTestModule.cpp b/src/modules/RangeTestModule.cpp index c1b1e48001..783fbd7587 100644 --- a/src/modules/RangeTestModule.cpp +++ b/src/modules/RangeTestModule.cpp @@ -138,7 +138,7 @@ ProcessMessage RangeTestModuleRadio::handleReceived(const meshtastic_MeshPacket } /* - NodeInfo *n = nodeDB.getNode(getFrom(&mp)); + NodeInfoLite *n = nodeDB.getMeshNode(getFrom(&mp)); LOG_DEBUG("-----------------------------------------\n"); LOG_DEBUG("p.payload.bytes \"%s\"\n", p.payload.bytes); @@ -177,7 +177,7 @@ bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp) #ifdef ARCH_ESP32 auto &p = mp.decoded; - meshtastic_NodeInfo *n = nodeDB.getNode(getFrom(&mp)); + meshtastic_NodeInfoLite *n = nodeDB.getMeshNode(getFrom(&mp)); /* LOG_DEBUG("-----------------------------------------\n"); LOG_DEBUG("p.payload.bytes \"%s\"\n", p.payload.bytes); @@ -284,4 +284,4 @@ bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp) #endif return 1; -} +} \ No newline at end of file diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index b76f9de486..af7ba1381b 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -161,18 +161,18 @@ int32_t SerialModule::runOnce() // in NMEA mode send out GGA every 2 seconds, Don't read from Port if (millis() - lastNmeaTime > 2000) { lastNmeaTime = millis(); - printGGA(outbuf, sizeof(outbuf), nodeDB.getNode(myNodeInfo.my_node_num)->position); + printGGA(outbuf, sizeof(outbuf), localPosition); serialPrint->printf("%s", outbuf); } } else if (moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_CALTOPO) { if (millis() - lastNmeaTime > 10000) { lastNmeaTime = millis(); uint32_t readIndex = 0; - const meshtastic_NodeInfo *tempNodeInfo = nodeDB.readNextInfo(readIndex); + const meshtastic_NodeInfoLite *tempNodeInfo = nodeDB.readNextMeshNode(readIndex); while (tempNodeInfo != NULL && tempNodeInfo->has_user && hasValidPosition(tempNodeInfo)) { printWPL(outbuf, sizeof(outbuf), tempNodeInfo->position, tempNodeInfo->user.long_name, true); serialPrint->printf("%s", outbuf); - tempNodeInfo = nodeDB.readNextInfo(readIndex); + tempNodeInfo = nodeDB.readNextMeshNode(readIndex); } } } @@ -251,7 +251,7 @@ ProcessMessage SerialModuleRadio::handleReceived(const meshtastic_MeshPacket &mp moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_SIMPLE) { serialPrint->printf("%s", p.payload.bytes); } else if (moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_TEXTMSG) { - meshtastic_NodeInfo *node = nodeDB.getNode(getFrom(&mp)); + meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(getFrom(&mp)); String sender = (node && node->has_user) ? node->user.short_name : "???"; serialPrint->println(); serialPrint->printf("%s: %s", sender, p.payload.bytes); @@ -267,7 +267,7 @@ ProcessMessage SerialModuleRadio::handleReceived(const meshtastic_MeshPacket &mp decoded = &scratch; } // send position packet as WPL to the serial port - printWPL(outbuf, sizeof(outbuf), *decoded, nodeDB.getNode(getFrom(&mp))->user.long_name, + printWPL(outbuf, sizeof(outbuf), *decoded, nodeDB.getMeshNode(getFrom(&mp))->user.long_name, moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_CALTOPO); serialPrint->printf("%s", outbuf); } @@ -312,4 +312,4 @@ uint32_t SerialModule::getBaudRate() } return BAUD; } -#endif +#endif \ No newline at end of file