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
|
|
|
|
2021-02-17 11:04:41 +00:00
|
|
|
bool NodeInfoPlugin::handleReceivedProtobuf(const MeshPacket &mp, const User *pptr)
|
2020-12-05 02:00:46 +00:00
|
|
|
{
|
2021-02-17 11:04:41 +00:00
|
|
|
auto p = *pptr;
|
2020-12-05 02:00:46 +00:00
|
|
|
|
2021-03-05 02:19:27 +00:00
|
|
|
nodeDB.updateUser(getFrom(&mp), p);
|
2020-12-05 02:00:46 +00:00
|
|
|
|
|
|
|
bool wasBroadcast = mp.to == NODENUM_BROADCAST;
|
|
|
|
|
|
|
|
// Show new nodes on LCD screen
|
|
|
|
if (wasBroadcast) {
|
|
|
|
String lcd = String("Joined: ") + p.long_name + "\n";
|
2021-03-09 07:07:02 +00:00
|
|
|
if(screen)
|
|
|
|
screen->print(lcd.c_str());
|
2020-12-05 02:00:46 +00:00
|
|
|
}
|
|
|
|
|
2021-03-09 07:07:02 +00:00
|
|
|
// DEBUG_MSG("did handleReceived\n");
|
2020-12-05 02:00:46 +00:00
|
|
|
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
|
2021-02-14 04:27:10 +00:00
|
|
|
if (prevPacketId) // if we wrap around to zero, we'll simply fail to cancel in that rare case (no big deal)
|
2021-02-11 09:39:53 +00:00
|
|
|
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);
|
|
|
|
}
|
2021-02-14 04:27:10 +00:00
|
|
|
|
|
|
|
NodeInfoPlugin::NodeInfoPlugin()
|
|
|
|
: ProtobufPlugin("nodeinfo", PortNum_NODEINFO_APP, User_fields), concurrency::OSThread("NodeInfoPlugin")
|
|
|
|
{
|
2021-02-17 11:04:41 +00:00
|
|
|
isPromiscuous = true; // We always want to update our nodedb, even if we are sniffing on others
|
2021-02-14 04:27:10 +00:00
|
|
|
setIntervalFromNow(30 *
|
|
|
|
1000); // Send our initial owner announcement 30 seconds after we start (to give network time to setup)
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t NodeInfoPlugin::runOnce()
|
|
|
|
{
|
|
|
|
static uint32_t currentGeneration;
|
|
|
|
|
|
|
|
// If we changed channels, ask everyone else for their latest info
|
|
|
|
bool requestReplies = currentGeneration != radioGeneration;
|
|
|
|
currentGeneration = radioGeneration;
|
|
|
|
|
|
|
|
DEBUG_MSG("Sending our nodeinfo to mesh (wantReplies=%d)\n", requestReplies);
|
2021-03-06 02:36:30 +00:00
|
|
|
sendOurNodeInfo(NODENUM_BROADCAST, requestReplies); // Send our info (don't request replies)
|
2021-02-14 04:27:10 +00:00
|
|
|
|
|
|
|
return getPref_position_broadcast_secs() * 1000;
|
|
|
|
}
|
|
|
|
|