2020-11-28 04:10:19 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "mesh/MeshTypes.h"
|
|
|
|
#include <vector>
|
|
|
|
/** A baseclass for any mesh "plugin".
|
|
|
|
*
|
|
|
|
* A plugin allows you to add new features to meshtastic device code, without needing to know messaging details.
|
|
|
|
*
|
|
|
|
* A key concept for this is that your plugin should use a particular "portnum" for each message type you want to receive
|
|
|
|
* and handle.
|
|
|
|
*
|
|
|
|
* Interally we use plugins to implement the core meshtastic text messaging and gps position sharing features. You
|
|
|
|
* can use these classes as examples for how to write your own custom plugin. See here: (FIXME)
|
|
|
|
*/
|
|
|
|
class MeshPlugin
|
|
|
|
{
|
2020-11-28 05:25:03 +00:00
|
|
|
static std::vector<MeshPlugin *> *plugins;
|
2020-11-28 04:10:19 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/** Constructor
|
|
|
|
* name is for debugging output
|
|
|
|
*/
|
|
|
|
MeshPlugin(const char *_name);
|
|
|
|
|
|
|
|
virtual ~MeshPlugin();
|
|
|
|
|
2020-11-28 05:51:51 +00:00
|
|
|
/** For use only by MeshService
|
|
|
|
*/
|
|
|
|
static void callPlugins(const MeshPacket &mp);
|
|
|
|
|
|
|
|
protected:
|
2020-12-03 08:48:44 +00:00
|
|
|
const char *name;
|
|
|
|
|
2020-11-28 04:10:19 +00:00
|
|
|
/**
|
|
|
|
* Initialize your plugin. This setup function is called once after all hardware and mesh protocol layers have
|
|
|
|
* been initialized
|
|
|
|
*/
|
2020-11-28 05:25:03 +00:00
|
|
|
virtual void setup();
|
2020-11-28 04:10:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if you want to receive the specified portnum
|
|
|
|
*/
|
|
|
|
virtual bool wantPortnum(PortNum p) = 0;
|
|
|
|
|
|
|
|
/** Called to handle a particular incoming message
|
|
|
|
|
|
|
|
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
|
|
|
|
*/
|
|
|
|
virtual bool handleReceived(const MeshPacket &mp) { return false; }
|
2020-12-05 03:15:06 +00:00
|
|
|
|
|
|
|
/** 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. Implementing this method
|
|
|
|
* is optional
|
|
|
|
*/
|
|
|
|
virtual void sendResponse(NodeNum to) {}
|
2020-11-28 04:10:19 +00:00
|
|
|
};
|