add assertIsSetup() and use it from OSThread constructor

fixes nasty bug @mc-hamster discovered with plugin order of operations
This commit is contained in:
Kevin Hester
2021-01-08 13:15:49 +08:00
parent 3636b87db0
commit 7aacfd66ef
16 changed files with 108 additions and 28 deletions

View File

@@ -6,7 +6,7 @@
#include "configuration.h"
#include "main.h"
NodeInfoPlugin nodeInfoPlugin;
NodeInfoPlugin *nodeInfoPlugin;
bool NodeInfoPlugin::handleReceivedProtobuf(const MeshPacket &mp, const User &p)
{

View File

@@ -29,4 +29,4 @@ class NodeInfoPlugin : public ProtobufPlugin<User>
virtual MeshPacket *allocReply();
};
extern NodeInfoPlugin nodeInfoPlugin;
extern NodeInfoPlugin *nodeInfoPlugin;

20
src/plugins/Plugins.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include "plugins/NodeInfoPlugin.h"
#include "plugins/PositionPlugin.h"
#include "plugins/ReplyPlugin.h"
#include "plugins/RemoteHardwarePlugin.h"
#include "plugins/TextMessagePlugin.h"
/**
* Create plugin instances here. If you are adding a new plugin, you must 'new' it here (or somewhere else)
*/
void setupPlugins() {
nodeInfoPlugin = new NodeInfoPlugin();
positionPlugin = new PositionPlugin();
textMessagePlugin = new TextMessagePlugin();
// Note: if the rest of meshtastic doesn't need to explicitly use your plugin, you do not need to assign the instance
// to a global variable.
new RemoteHardwarePlugin();
new ReplyPlugin();
}

6
src/plugins/Plugins.h Normal file
View File

@@ -0,0 +1,6 @@
#pragma once
/**
* Create plugin instances here. If you are adding a new plugin, you must 'new' it here (or somewhere else)
*/
void setupPlugins();

View File

@@ -5,7 +5,7 @@
#include "Router.h"
#include "configuration.h"
PositionPlugin positionPlugin;
PositionPlugin *positionPlugin;
bool PositionPlugin::handleReceivedProtobuf(const MeshPacket &mp, const Position &p)
{

View File

@@ -30,4 +30,4 @@ class PositionPlugin : public ProtobufPlugin<Position>
virtual MeshPacket *allocReply();
};
extern PositionPlugin positionPlugin;
extern PositionPlugin *positionPlugin;

View File

@@ -6,8 +6,6 @@
#include "configuration.h"
#include "main.h"
RemoteHardwarePlugin remoteHardwarePlugin;
#define NUM_GPIOS 64
// Because (FIXME) we currently don't tell API clients status on sent messages

View File

@@ -5,9 +5,6 @@
#include <assert.h>
// Create an a static instance of our plugin - this registers with the plugin system
ReplyPlugin replyPlugin;
MeshPacket *ReplyPlugin::allocReply()
{
assert(currentRequest); // should always be !NULL

View File

@@ -3,7 +3,7 @@
#include "NodeDB.h"
#include "PowerFSM.h"
TextMessagePlugin textMessagePlugin;
TextMessagePlugin *textMessagePlugin;
bool TextMessagePlugin::handleReceived(const MeshPacket &mp)
{

View File

@@ -22,4 +22,4 @@ class TextMessagePlugin : public SinglePortPlugin, public Observable<const MeshP
virtual bool handleReceived(const MeshPacket &mp);
};
extern TextMessagePlugin textMessagePlugin;
extern TextMessagePlugin *textMessagePlugin;