Rename MeshPlugin, SinglePortPlugin and ProtobufPlugin

This commit is contained in:
Sacha Weatherstone 2022-03-09 19:01:43 +11:00
parent 46b8b61b7f
commit 6bee95d6b2
33 changed files with 80 additions and 80 deletions

View File

@ -69,7 +69,7 @@ uint32_t dopThresholds[5] = {2000, 1000, 500, 200, 100};
// At some point, we're going to ask all of the modules if they would like to display a screen frame
// we'll need to hold onto pointers for the modules that can draw a frame.
std::vector<MeshPlugin *> moduleFrames;
std::vector<MeshModule *> moduleFrames;
// Stores the last 4 of our hardware ID, to make finding the device for pairing easier
static char ourId[5];
@ -194,7 +194,7 @@ static void drawModuleFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int
// DEBUG_MSG("Screen is not in transition. Frame: %d\n\n", module_frame);
}
// DEBUG_MSG("Drawing Module Frame %d\n\n", module_frame);
MeshPlugin &pi = *moduleFrames.at(module_frame);
MeshModule &pi = *moduleFrames.at(module_frame);
pi.drawFrame(display, state, x, y);
}
@ -828,7 +828,7 @@ void Screen::setup()
textMessageObserver.observe(textMessageModule);
// Modules can notify screen about refresh
MeshPlugin::observeUIEvents(&uiFrameEventObserver);
MeshModule::observeUIEvents(&uiFrameEventObserver);
}
void Screen::forceDisplay()
@ -976,7 +976,7 @@ void Screen::setFrames()
DEBUG_MSG("showing standard frames\n");
showingNormalScreen = true;
moduleFrames = MeshPlugin::GetMeshModulesWithUIFrames();
moduleFrames = MeshModule::GetMeshModulesWithUIFrames();
DEBUG_MSG("Showing %d module frames\n", moduleFrames.size());
int totalFrameCount = MAX_NUM_NODES + NUM_EXTRA_FRAMES + moduleFrames.size();
DEBUG_MSG("Total frame count: %d\n", totalFrameCount);

View File

@ -40,7 +40,7 @@ class Screen
#include "concurrency/OSThread.h"
#include "power.h"
#include <string>
#include "mesh/MeshPlugin.h"
#include "mesh/MeshModule.h"
// 0 to 255, though particular variants might define different defaults
#ifndef BRIGHTNESS_DEFAULT

View File

@ -1,6 +1,6 @@
#pragma once
#include "SinglePortPlugin.h" // TODO: what header file to include?
#include "SinglePortModule.h" // TODO: what header file to include?
#include "InputBroker.h"
enum RotaryEncoderInterruptBaseStateType

View File

@ -1,38 +1,38 @@
#include "configuration.h"
#include "MeshPlugin.h"
#include "MeshModule.h"
#include "Channels.h"
#include "MeshService.h"
#include "NodeDB.h"
#include "modules/RoutingModule.h"
#include <assert.h>
std::vector<MeshPlugin *> *MeshPlugin::modules;
std::vector<MeshModule *> *MeshModule::modules;
const MeshPacket *MeshPlugin::currentRequest;
const MeshPacket *MeshModule::currentRequest;
/**
* If any of the current chain of modules has already sent a reply, it will be here. This is useful to allow
* the RoutingPlugin to avoid sending redundant acks
*/
MeshPacket *MeshPlugin::currentReply;
MeshPacket *MeshModule::currentReply;
MeshPlugin::MeshPlugin(const char *_name) : name(_name)
MeshModule::MeshModule(const char *_name) : name(_name)
{
// Can't trust static initalizer order, so we check each time
if (!modules)
modules = new std::vector<MeshPlugin *>();
modules = new std::vector<MeshModule *>();
modules->push_back(this);
}
void MeshPlugin::setup() {}
void MeshModule::setup() {}
MeshPlugin::~MeshPlugin()
MeshModule::~MeshModule()
{
assert(0); // FIXME - remove from list of modules once someone needs this feature
}
MeshPacket *MeshPlugin::allocAckNak(Routing_Error err, NodeNum to, PacketId idFrom, ChannelIndex chIndex)
MeshPacket *MeshModule::allocAckNak(Routing_Error err, NodeNum to, PacketId idFrom, ChannelIndex chIndex)
{
Routing c = Routing_init_default;
@ -57,7 +57,7 @@ MeshPacket *MeshPlugin::allocAckNak(Routing_Error err, NodeNum to, PacketId idFr
return p;
}
MeshPacket *MeshPlugin::allocErrorResponse(Routing_Error err, const MeshPacket *p)
MeshPacket *MeshModule::allocErrorResponse(Routing_Error err, const MeshPacket *p)
{
auto r = allocAckNak(err, getFrom(p), p->id, p->channel);
@ -66,7 +66,7 @@ MeshPacket *MeshPlugin::allocErrorResponse(Routing_Error err, const MeshPacket *
return r;
}
void MeshPlugin::callPlugins(const MeshPacket &mp, RxSource src)
void MeshModule::callPlugins(const MeshPacket &mp, RxSource src)
{
// DEBUG_MSG("In call modules\n");
bool moduleFound = false;
@ -183,7 +183,7 @@ void MeshPlugin::callPlugins(const MeshPacket &mp, RxSource src)
(src == RX_SRC_LOCAL) ? "LOCAL":"REMOTE");
}
MeshPacket *MeshPlugin::allocReply()
MeshPacket *MeshModule::allocReply()
{
auto r = myReply;
myReply = NULL; // Only use each reply once
@ -194,7 +194,7 @@ MeshPacket *MeshPlugin::allocReply()
* so that subclasses can (optionally) send a response back to the original sender. Implementing this method
* is optional
*/
void MeshPlugin::sendResponse(const MeshPacket &req)
void MeshModule::sendResponse(const MeshPacket &req)
{
auto r = allocReply();
if (r) {
@ -222,10 +222,10 @@ void setReplyTo(MeshPacket *p, const MeshPacket &to)
p->decoded.request_id = to.id;
}
std::vector<MeshPlugin *> MeshPlugin::GetMeshModulesWithUIFrames()
std::vector<MeshModule *> MeshModule::GetMeshModulesWithUIFrames()
{
std::vector<MeshPlugin *> modulesWithUIFrames;
std::vector<MeshModule *> modulesWithUIFrames;
if (modules) {
for (auto i = modules->begin(); i != modules->end(); ++i) {
auto &pi = **i;
@ -238,7 +238,7 @@ std::vector<MeshPlugin *> MeshPlugin::GetMeshModulesWithUIFrames()
return modulesWithUIFrames;
}
void MeshPlugin::observeUIEvents(
void MeshModule::observeUIEvents(
Observer<const UIFrameEvent *> *observer)
{
if (modules) {
@ -254,7 +254,7 @@ void MeshPlugin::observeUIEvents(
}
}
AdminMessageHandleResult MeshPlugin::handleAdminMessageForAllPlugins(const MeshPacket &mp, AdminMessage *request, AdminMessage *response)
AdminMessageHandleResult MeshModule::handleAdminMessageForAllPlugins(const MeshPacket &mp, AdminMessage *request, AdminMessage *response)
{
AdminMessageHandleResult handled = AdminMessageHandleResult::NOT_HANDLED;
if (modules) {

View File

@ -52,23 +52,23 @@ typedef struct _UIFrameEvent {
* Interally we use modules 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 module. See here: (FIXME)
*/
class MeshPlugin
class MeshModule
{
static std::vector<MeshPlugin *> *modules;
static std::vector<MeshModule *> *modules;
public:
/** Constructor
* name is for debugging output
*/
MeshPlugin(const char *_name);
MeshModule(const char *_name);
virtual ~MeshPlugin();
virtual ~MeshModule();
/** For use only by MeshService
*/
static void callPlugins(const MeshPacket &mp, RxSource src = RX_SRC_RADIO);
static std::vector<MeshPlugin *> GetMeshModulesWithUIFrames();
static std::vector<MeshModule *> GetMeshModulesWithUIFrames();
static void observeUIEvents(Observer<const UIFrameEvent *> *observer);
static AdminMessageHandleResult handleAdminMessageForAllPlugins(
const MeshPacket &mp, AdminMessage *request, AdminMessage *response);

View File

@ -438,7 +438,7 @@ size_t NodeDB::getNumOnlineNodes()
return numseen;
}
#include "MeshPlugin.h"
#include "MeshModule.h"
/** Update position info for this node based on received position data
*/

View File

@ -1,4 +1,4 @@
#include "configuration.h"
#include "ProtobufPlugin.h"
#include "ProtobufModule.h"

View File

@ -1,5 +1,5 @@
#pragma once
#include "SinglePortPlugin.h"
#include "SinglePortModule.h"
/**
* A base class for mesh modules that assume that they are sending/receiving one particular protobuf based
@ -8,7 +8,7 @@
* If you are using protobufs to encode your packets (recommended) you can use this as a baseclass for your module
* and avoid a bunch of boilerplate code.
*/
template <class T> class ProtobufPlugin : protected SinglePortPlugin
template <class T> class ProtobufModule : protected SinglePortModule
{
const pb_msgdesc_t *fields;
@ -16,8 +16,8 @@ template <class T> class ProtobufPlugin : protected SinglePortPlugin
/** Constructor
* name is for debugging output
*/
ProtobufPlugin(const char *_name, PortNum _ourPortNum, const pb_msgdesc_t *_fields)
: SinglePortPlugin(_name, _ourPortNum), fields(_fields)
ProtobufModule(const char *_name, PortNum _ourPortNum, const pb_msgdesc_t *_fields)
: SinglePortModule(_name, _ourPortNum), fields(_fields)
{
}

View File

@ -1,6 +1,6 @@
#include "configuration.h"
#include "ReliableRouter.h"
#include "MeshPlugin.h"
#include "MeshModule.h"
#include "MeshTypes.h"
#include "mesh-pb-constants.h"
@ -92,7 +92,7 @@ void ReliableRouter::sniffReceived(const MeshPacket *p, const Routing *c)
if (p->to == ourNode) { // ignore ack/nak/want_ack packets that are not address to us (we only handle 0 hop reliability
// - not DSR routing)
if (p->want_ack) {
if (MeshPlugin::currentReply)
if (MeshModule::currentReply)
DEBUG_MSG("Someone else has replied to this message, no need for a 2nd ack\n");
else
sendAckNak(Routing_Error_NONE, getFrom(p), p->id, p->channel);

View File

@ -377,7 +377,7 @@ void Router::handleReceived(MeshPacket *p, RxSource src)
}
// call modules here
MeshPlugin::callPlugins(*p, src);
MeshModule::callPlugins(*p, src);
}
void Router::perhapsHandleReceived(MeshPacket *p)

View File

@ -1,12 +1,12 @@
#pragma once
#include "MeshPlugin.h"
#include "MeshModule.h"
#include "Router.h"
/**
* Most modules are only interested in sending/receving one particular portnum. This baseclass simplifies that common
* case.
*/
class SinglePortPlugin : public MeshPlugin
class SinglePortModule : public MeshModule
{
protected:
PortNum ourPortNum;
@ -15,7 +15,7 @@ class SinglePortPlugin : public MeshPlugin
/** Constructor
* name is for debugging output
*/
SinglePortPlugin(const char *_name, PortNum _ourPortNum) : MeshPlugin(_name), ourPortNum(_ourPortNum) {}
SinglePortModule(const char *_name, PortNum _ourPortNum) : MeshModule(_name), ourPortNum(_ourPortNum) {}
protected:
/**

View File

@ -123,7 +123,7 @@ bool AdminModule::handleReceivedProtobuf(const MeshPacket &mp, AdminMessage *r)
default:
AdminMessage response = AdminMessage_init_default;
AdminMessageHandleResult handleResult = MeshPlugin::handleAdminMessageForAllPlugins(mp, r, &response);
AdminMessageHandleResult handleResult = MeshModule::handleAdminMessageForAllPlugins(mp, r, &response);
if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE)
{
@ -195,7 +195,7 @@ void AdminModule::handleSetRadio(RadioConfig &r)
service.reloadConfig();
}
AdminModule::AdminModule() : ProtobufPlugin("Admin", PortNum_ADMIN_APP, AdminMessage_fields)
AdminModule::AdminModule() : ProtobufModule("Admin", PortNum_ADMIN_APP, AdminMessage_fields)
{
// restrict to the admin channel for rx
boundChannel = Channels::adminChannel;

View File

@ -1,10 +1,10 @@
#pragma once
#include "ProtobufPlugin.h"
#include "ProtobufModule.h"
/**
* Routing module for router control messages
*/
class AdminModule : public ProtobufPlugin<AdminMessage>
class AdminModule : public ProtobufModule<AdminMessage>
{
public:
/** Constructor

View File

@ -23,7 +23,7 @@ extern bool loadProto(const char *filename, size_t protoSize, size_t objSize, co
extern bool saveProto(const char *filename, size_t protoSize, size_t objSize, const pb_msgdesc_t *fields, const void *dest_struct);
CannedMessageModule::CannedMessageModule()
: SinglePortPlugin("canned", PortNum_TEXT_MESSAGE_APP),
: SinglePortModule("canned", PortNum_TEXT_MESSAGE_APP),
concurrency::OSThread("CannedMessageModule")
{
if (radioConfig.preferences.canned_message_module_enabled)

View File

@ -1,5 +1,5 @@
#pragma once
#include "ProtobufPlugin.h"
#include "ProtobufModule.h"
#include "input/InputBroker.h"
enum cannedMessageModuleRunState
@ -21,7 +21,7 @@ enum cannedMessageModuleRunState
#define CANNED_MESSAGE_MODULE_MESSAGES_SIZE 800
class CannedMessageModule :
public SinglePortPlugin,
public SinglePortModule,
public Observable<const UIFrameEvent *>,
private concurrency::OSThread
{

View File

@ -108,7 +108,7 @@ void ExternalNotificationModule::setExternalOff()
// --------
ExternalNotificationModule::ExternalNotificationModule()
: SinglePortPlugin("ExternalNotificationModule", PortNum_TEXT_MESSAGE_APP), concurrency::OSThread(
: SinglePortModule("ExternalNotificationModule", PortNum_TEXT_MESSAGE_APP), concurrency::OSThread(
"ExternalNotificationModule")
{
// restrict to the admin channel for rx

View File

@ -1,6 +1,6 @@
#pragma once
#include "SinglePortPlugin.h"
#include "SinglePortModule.h"
#include "concurrency/OSThread.h"
#include "configuration.h"
#include <Arduino.h>
@ -10,7 +10,7 @@
* Radio interface for ExternalNotificationModule
*
*/
class ExternalNotificationModule : public SinglePortPlugin, private concurrency::OSThread
class ExternalNotificationModule : public SinglePortModule, private concurrency::OSThread
{
public:
ExternalNotificationModule();

View File

@ -51,7 +51,7 @@ MeshPacket *NodeInfoModule::allocReply()
}
NodeInfoModule::NodeInfoModule()
: ProtobufPlugin("nodeinfo", PortNum_NODEINFO_APP, User_fields), concurrency::OSThread("NodeInfoModule")
: ProtobufModule("nodeinfo", PortNum_NODEINFO_APP, User_fields), concurrency::OSThread("NodeInfoModule")
{
isPromiscuous = true; // We always want to update our nodedb, even if we are sniffing on others
setIntervalFromNow(30 *

View File

@ -1,10 +1,10 @@
#pragma once
#include "ProtobufPlugin.h"
#include "ProtobufModule.h"
/**
* NodeInfo module for sending/receiving NodeInfos into the mesh
*/
class NodeInfoModule : public ProtobufPlugin<User>, private concurrency::OSThread
class NodeInfoModule : public ProtobufModule<User>, 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;

View File

@ -10,7 +10,7 @@
PositionModule *positionModule;
PositionModule::PositionModule()
: ProtobufPlugin("position", PortNum_POSITION_APP, Position_fields), concurrency::OSThread("PositionModule")
: ProtobufModule("position", PortNum_POSITION_APP, Position_fields), concurrency::OSThread("PositionModule")
{
isPromiscuous = true; // We always want to update our nodedb, even if we are sniffing on others
setIntervalFromNow(60 * 1000); // Send our initial position 60 seconds after we start (to give GPS time to setup)

View File

@ -1,11 +1,11 @@
#pragma once
#include "ProtobufPlugin.h"
#include "ProtobufModule.h"
#include "concurrency/OSThread.h"
/**
* Position module for sending/receiving positions into the mesh
*/
class PositionModule : public ProtobufPlugin<Position>, private concurrency::OSThread
class PositionModule : public ProtobufModule<Position>, 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;

View File

@ -47,7 +47,7 @@ static uint64_t digitalReads(uint64_t mask)
}
RemoteHardwareModule::RemoteHardwareModule()
: ProtobufPlugin("remotehardware", PortNum_REMOTE_HARDWARE_APP, HardwareMessage_fields), concurrency::OSThread(
: ProtobufModule("remotehardware", PortNum_REMOTE_HARDWARE_APP, HardwareMessage_fields), concurrency::OSThread(
"remotehardware")
{
}

View File

@ -1,12 +1,12 @@
#pragma once
#include "ProtobufPlugin.h"
#include "ProtobufModule.h"
#include "mesh/generated/remote_hardware.pb.h"
#include "concurrency/OSThread.h"
/**
* A module that provides easy low-level remote access to device hardware.
*/
class RemoteHardwareModule : public ProtobufPlugin<HardwareMessage>, private concurrency::OSThread
class RemoteHardwareModule : public ProtobufModule<HardwareMessage>, private concurrency::OSThread
{
/// The current set of GPIOs we've been asked to watch for changes
uint64_t watchGpios = 0;

View File

@ -1,17 +1,17 @@
#pragma once
#include "SinglePortPlugin.h"
#include "SinglePortModule.h"
/**
* A simple example module that just replies with "Message received" to any message it receives.
*/
class ReplyModule : public SinglePortPlugin
class ReplyModule : public SinglePortModule
{
public:
/** Constructor
* name is for debugging output
*/
ReplyModule() : SinglePortPlugin("reply", PortNum_REPLY_APP) {}
ReplyModule() : SinglePortModule("reply", PortNum_REPLY_APP) {}
protected:

View File

@ -41,7 +41,7 @@ void RoutingModule::sendAckNak(Routing_Error err, NodeNum to, PacketId idFrom, C
router->sendLocal(p); // we sometimes send directly to the local node
}
RoutingModule::RoutingModule() : ProtobufPlugin("routing", PortNum_ROUTING_APP, Routing_fields)
RoutingModule::RoutingModule() : ProtobufModule("routing", PortNum_ROUTING_APP, Routing_fields)
{
isPromiscuous = true;
}

View File

@ -1,11 +1,11 @@
#pragma once
#include "ProtobufPlugin.h"
#include "ProtobufModule.h"
#include "Channels.h"
/**
* Routing module for router control messages
*/
class RoutingModule : public ProtobufPlugin<Routing>
class RoutingModule : public ProtobufModule<Routing>
{
public:
/** Constructor

View File

@ -1,15 +1,15 @@
#pragma once
#include "../mesh/generated/telemetry.pb.h"
#include "ProtobufPlugin.h"
#include "ProtobufModule.h"
#include <OLEDDisplay.h>
#include <OLEDDisplayUi.h>
class TelemetryModule : private concurrency::OSThread, public ProtobufPlugin<Telemetry>
class TelemetryModule : private concurrency::OSThread, public ProtobufModule<Telemetry>
{
public:
TelemetryModule()
: concurrency::OSThread("TelemetryModule"),
ProtobufPlugin("Telemetry", PortNum_TELEMETRY_APP, &Telemetry_msg)
ProtobufModule("Telemetry", PortNum_TELEMETRY_APP, &Telemetry_msg)
{
lastMeasurementPacket = nullptr;
}

View File

@ -1,17 +1,17 @@
#pragma once
#include "SinglePortPlugin.h"
#include "SinglePortModule.h"
#include "Observer.h"
/**
* Text message handling for meshtastic - draws on the OLED display the most recent received message
*/
class TextMessageModule : public SinglePortPlugin, public Observable<const MeshPacket *>
class TextMessageModule : public SinglePortModule, public Observable<const MeshPacket *>
{
public:
/** Constructor
* name is for debugging output
*/
TextMessageModule() : SinglePortPlugin("text", PortNum_TEXT_MESSAGE_APP) {}
TextMessageModule() : SinglePortModule("text", PortNum_TEXT_MESSAGE_APP) {}
protected:

View File

@ -1,6 +1,6 @@
#pragma once
#include "SinglePortPlugin.h"
#include "SinglePortModule.h"
#include "concurrency/OSThread.h"
#include "configuration.h"
#include <Arduino.h>
@ -23,12 +23,12 @@ extern RangeTestModule *rangeTestModule;
* Radio interface for RangeTestModule
*
*/
class RangeTestModuleRadio : public SinglePortPlugin
class RangeTestModuleRadio : public SinglePortModule
{
uint32_t lastRxID = 0;
public:
RangeTestModuleRadio() : SinglePortPlugin("RangeTestModuleRadio", PortNum_TEXT_MESSAGE_APP) {}
RangeTestModuleRadio() : SinglePortModule("RangeTestModuleRadio", PortNum_TEXT_MESSAGE_APP) {}
/**
* Send our payload into the mesh

View File

@ -61,7 +61,7 @@ SerialModule::SerialModule() : concurrency::OSThread("SerialModule") {}
char serialStringChar[Constants_DATA_PAYLOAD_LEN];
SerialModuleRadio::SerialModuleRadio() : SinglePortPlugin("SerialModuleRadio", PortNum_SERIAL_APP)
SerialModuleRadio::SerialModuleRadio() : SinglePortModule("SerialModuleRadio", PortNum_SERIAL_APP)
{
// restrict to the admin channel for rx
boundChannel = Channels::serialChannel;

View File

@ -1,6 +1,6 @@
#pragma once
#include "SinglePortPlugin.h"
#include "SinglePortModule.h"
#include "concurrency/OSThread.h"
#include "configuration.h"
#include <Arduino.h>
@ -23,7 +23,7 @@ extern SerialModule *serialModule;
* Radio interface for SerialModule
*
*/
class SerialModuleRadio : public SinglePortPlugin
class SerialModuleRadio : public SinglePortModule
{
uint32_t lastRxID = 0;

View File

@ -378,7 +378,7 @@ ProcessMessage StoreForwardModule::handleReceivedProtobuf(const MeshPacket &mp,
}
StoreForwardModule::StoreForwardModule()
: SinglePortPlugin("StoreForwardModule", PortNum_TEXT_MESSAGE_APP), concurrency::OSThread("StoreForwardModule")
: SinglePortModule("StoreForwardModule", PortNum_TEXT_MESSAGE_APP), concurrency::OSThread("StoreForwardModule")
{
#ifndef NO_ESP32

View File

@ -1,6 +1,6 @@
#pragma once
#include "SinglePortPlugin.h"
#include "SinglePortModule.h"
#include "concurrency/OSThread.h"
#include "mesh/generated/storeforward.pb.h"
@ -18,7 +18,7 @@ struct PacketHistoryStruct {
pb_size_t payload_size;
};
class StoreForwardModule : public SinglePortPlugin, private concurrency::OSThread
class StoreForwardModule : public SinglePortModule, private concurrency::OSThread
{
// bool firstTime = 1;
bool busy = 0;