2020-12-05 02:00:46 +00:00
|
|
|
#include "NodeInfoPlugin.h"
|
|
|
|
#include "MeshService.h"
|
|
|
|
#include "NodeDB.h"
|
|
|
|
#include "RTC.h"
|
|
|
|
#include "Router.h"
|
|
|
|
#include "configuration.h"
|
|
|
|
#include "main.h"
|
|
|
|
|
2021-01-08 05:15:49 +00:00
|
|
|
NodeInfoPlugin *nodeInfoPlugin;
|
2020-12-05 02:00:46 +00:00
|
|
|
|
|
|
|
bool NodeInfoPlugin::handleReceivedProtobuf(const MeshPacket &mp, const User &p)
|
|
|
|
{
|
|
|
|
// FIXME - we currently update NodeInfo data in the DB only if the message was a broadcast or destined to us
|
|
|
|
// it would be better to update even if the message was destined to others.
|
|
|
|
|
|
|
|
nodeDB.updateUser(mp.from, p);
|
|
|
|
|
|
|
|
bool wasBroadcast = mp.to == NODENUM_BROADCAST;
|
|
|
|
|
|
|
|
// Show new nodes on LCD screen
|
|
|
|
if (wasBroadcast) {
|
|
|
|
String lcd = String("Joined: ") + p.long_name + "\n";
|
|
|
|
screen->print(lcd.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return false; // Let others look at this message also if they want
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInfoPlugin::sendOurNodeInfo(NodeNum dest, bool wantReplies)
|
|
|
|
{
|
2021-02-11 09:39:53 +00:00
|
|
|
// cancel any not yet sent (now stale) position packets
|
|
|
|
if(prevPacketId) // if we wrap around to zero, we'll simply fail to cancel in that rare case (no big deal)
|
|
|
|
service.cancelSending(prevPacketId);
|
|
|
|
|
2020-12-07 02:18:11 +00:00
|
|
|
MeshPacket *p = allocReply();
|
2020-12-05 02:00:46 +00:00
|
|
|
p->to = dest;
|
|
|
|
p->decoded.want_response = wantReplies;
|
2021-02-11 11:00:17 +00:00
|
|
|
p->priority = MeshPacket_Priority_BACKGROUND;
|
2021-02-11 09:39:53 +00:00
|
|
|
prevPacketId = p->id;
|
2021-02-11 11:00:17 +00:00
|
|
|
|
2020-12-05 02:00:46 +00:00
|
|
|
service.sendToMesh(p);
|
|
|
|
}
|
2020-12-05 03:15:06 +00:00
|
|
|
|
2020-12-07 02:18:11 +00:00
|
|
|
MeshPacket *NodeInfoPlugin::allocReply()
|
|
|
|
{
|
|
|
|
User &u = owner;
|
2020-12-05 03:15:06 +00:00
|
|
|
|
2020-12-07 02:18:11 +00:00
|
|
|
DEBUG_MSG("sending owner %s/%s/%s\n", u.id, u.long_name, u.short_name);
|
|
|
|
return allocDataProtobuf(u);
|
|
|
|
}
|