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
This commit is contained in:
Ben Meadors
2023-06-17 09:10:09 -05:00
committed by GitHub
parent 685d27f566
commit a2c5b92840
18 changed files with 340 additions and 147 deletions

View File

@@ -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();
}
}