2020-12-05 02:14:15 +00:00
|
|
|
#pragma once
|
|
|
|
#include "MeshPlugin.h"
|
2020-12-07 02:18:11 +00:00
|
|
|
#include "Router.h"
|
2020-12-05 02:14:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Most plugins are only interested in sending/receving one particular portnum. This baseclass simplifies that common
|
|
|
|
* case.
|
|
|
|
*/
|
|
|
|
class SinglePortPlugin : public MeshPlugin
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
PortNum ourPortNum;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/** Constructor
|
|
|
|
* name is for debugging output
|
|
|
|
*/
|
|
|
|
SinglePortPlugin(const char *_name, PortNum _ourPortNum) : MeshPlugin(_name), ourPortNum(_ourPortNum) {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* @return true if you want to receive the specified portnum
|
|
|
|
*/
|
2021-02-17 11:04:41 +00:00
|
|
|
virtual bool wantPacket(const MeshPacket *p) { return p->decoded.portnum == ourPortNum; }
|
2020-12-07 02:18:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a mesh packet which has been preinited as a data packet with a particular port number.
|
|
|
|
* You can then send this packet (after customizing any of the payload fields you might need) with
|
|
|
|
* service.sendToMesh()
|
|
|
|
*/
|
|
|
|
MeshPacket *allocDataPacket()
|
|
|
|
{
|
|
|
|
// Update our local node info with our position (even if we don't decide to update anyone else)
|
|
|
|
MeshPacket *p = router->allocForSending();
|
2021-02-17 05:06:23 +00:00
|
|
|
p->decoded.portnum = ourPortNum;
|
2020-12-07 02:18:11 +00:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
2020-12-05 02:14:15 +00:00
|
|
|
};
|