diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index a1a6f885..ae53e802 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -51,22 +51,7 @@ MeshService service; #include "Router.h" -static int32_t sendOwnerCb() -{ - 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); - assert(nodeInfoPlugin); - nodeInfoPlugin->sendOurNodeInfo(NODENUM_BROADCAST, requestReplies); // Send our info (don't request replies) - - return getPref_send_owner_interval() * getPref_position_broadcast_secs() * 1000; -} - -static concurrency::Periodic *sendOwnerPeriod; MeshService::MeshService() : toPhoneQueue(MAX_RX_TOPHONE) { @@ -75,9 +60,6 @@ MeshService::MeshService() : toPhoneQueue(MAX_RX_TOPHONE) void MeshService::init() { - sendOwnerPeriod = new concurrency::Periodic("SendOwner", sendOwnerCb); - sendOwnerPeriod->setIntervalFromNow(30 * 1000); // Send our initial owner announcement 30 seconds after we start (to give network time to setup) - // moved much earlier in boot (called from setup()) // nodeDB.init(); diff --git a/src/plugins/NodeInfoPlugin.cpp b/src/plugins/NodeInfoPlugin.cpp index 6c236ed3..a04ec415 100644 --- a/src/plugins/NodeInfoPlugin.cpp +++ b/src/plugins/NodeInfoPlugin.cpp @@ -29,7 +29,7 @@ bool NodeInfoPlugin::handleReceivedProtobuf(const MeshPacket &mp, const User &p) void NodeInfoPlugin::sendOurNodeInfo(NodeNum dest, bool wantReplies) { // 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) + if (prevPacketId) // if we wrap around to zero, we'll simply fail to cancel in that rare case (no big deal) service.cancelSending(prevPacketId); MeshPacket *p = allocReply(); @@ -48,3 +48,26 @@ MeshPacket *NodeInfoPlugin::allocReply() DEBUG_MSG("sending owner %s/%s/%s\n", u.id, u.long_name, u.short_name); return allocDataProtobuf(u); } + +NodeInfoPlugin::NodeInfoPlugin() + : ProtobufPlugin("nodeinfo", PortNum_NODEINFO_APP, User_fields), concurrency::OSThread("NodeInfoPlugin") +{ + 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); + assert(nodeInfoPlugin); + nodeInfoPlugin->sendOurNodeInfo(NODENUM_BROADCAST, requestReplies); // Send our info (don't request replies) + + return getPref_position_broadcast_secs() * 1000; +} + diff --git a/src/plugins/NodeInfoPlugin.h b/src/plugins/NodeInfoPlugin.h index 8b01ea25..f0a7efeb 100644 --- a/src/plugins/NodeInfoPlugin.h +++ b/src/plugins/NodeInfoPlugin.h @@ -4,17 +4,18 @@ /** * NodeInfo plugin for sending/receiving NodeInfos into the mesh */ -class NodeInfoPlugin : public ProtobufPlugin +class NodeInfoPlugin : public ProtobufPlugin, private concurrency::OSThread { /// The id of the last packet we sent, to allow us to cancel it if we make something fresher PacketId prevPacketId = 0; - + + uint32_t currentGeneration = 0; public: /** Constructor * name is for debugging output */ - NodeInfoPlugin() : ProtobufPlugin("nodeinfo", PortNum_NODEINFO_APP, User_fields) {} - + NodeInfoPlugin(); + /** * Send our NodeInfo into the mesh */ @@ -30,6 +31,9 @@ class NodeInfoPlugin : public ProtobufPlugin /** Messages can be received that have the want_response bit set. If set, this callback will be invoked * so that subclasses can (optionally) send a response back to the original sender. */ virtual MeshPacket *allocReply(); + + /** Does our periodic broadcast */ + virtual int32_t runOnce(); }; extern NodeInfoPlugin *nodeInfoPlugin; \ No newline at end of file