From 50fb4ab22ac412f7aec766e7cad2313109f9510a Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 17 Sep 2024 12:08:04 -0500 Subject: [PATCH] Implement optional hops_away on NodeInfo/Lite (#4747) * Implement optional hops_away on NodeInfo/Lite * Trunk --- src/mesh/NodeDB.cpp | 4 +++- src/mesh/PhoneAPI.cpp | 2 +- src/mesh/TypeConversions.cpp | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 7e8abb747..dca639070 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -1112,8 +1112,10 @@ void NodeDB::updateFrom(const meshtastic_MeshPacket &mp) info->via_mqtt = mp.via_mqtt; // Store if we received this packet via MQTT // If hopStart was set and there wasn't someone messing with the limit in the middle, add hopsAway - if (mp.hop_start != 0 && mp.hop_limit <= mp.hop_start) + if (mp.hop_start != 0 && mp.hop_limit <= mp.hop_start) { + info->has_hops_away = true; info->hops_away = mp.hop_start - mp.hop_limit; + } } } diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 30af9d7b0..742bdbf34 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -194,7 +194,7 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) auto us = nodeDB->readNextMeshNode(readIndex); if (us) { nodeInfoForPhone = TypeConversions::ConvertToNodeInfo(us); - nodeInfoForPhone.hops_away = 0; + nodeInfoForPhone.has_hops_away = false; nodeInfoForPhone.is_favorite = true; fromRadioScratch.which_payload_variant = meshtastic_FromRadio_node_info_tag; fromRadioScratch.node_info = nodeInfoForPhone; diff --git a/src/mesh/TypeConversions.cpp b/src/mesh/TypeConversions.cpp index 6a90ac703..550f87021 100644 --- a/src/mesh/TypeConversions.cpp +++ b/src/mesh/TypeConversions.cpp @@ -11,9 +11,13 @@ meshtastic_NodeInfo TypeConversions::ConvertToNodeInfo(const meshtastic_NodeInfo info.last_heard = lite->last_heard; info.channel = lite->channel; info.via_mqtt = lite->via_mqtt; - info.hops_away = lite->hops_away; info.is_favorite = lite->is_favorite; + if (lite->has_hops_away) { + info.has_hops_away = true; + info.hops_away = lite->hops_away; + } + if (lite->has_position) { info.has_position = true; if (lite->position.latitude_i != 0)