Skip to content

Commit

Permalink
Add example for external Plugin file. (test-lib/ is out of the reposi…
Browse files Browse the repository at this point in the history
…tory, so this will crash)
  • Loading branch information
MartinNievas committed Aug 11, 2021
1 parent b2524ce commit 6f8b2b6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
8 changes: 6 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = tbeam
; default_envs = tbeam
;default_envs = tbeam0.7
;default_envs = heltec-v2.0
default_envs = heltec-v2.0
;default_envs = tlora-v1
;default_envs = tlora_v1_3
;default_envs = tlora-v2
Expand Down Expand Up @@ -454,3 +454,7 @@ lib_deps =
;board = genieblocks_lora
;build_flags =
; ${esp32_base.build_flags} -D GENIEBLOCKS

[env:pps]
lib_extra_dirs =
../test-lib
4 changes: 3 additions & 1 deletion src/plugins/Plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "plugins/PositionPlugin.h"
#include "plugins/RemoteHardwarePlugin.h"
#include "plugins/ReplyPlugin.h"
#include "../../test-lib/TestPlugin.h"
#include "plugins/TextMessagePlugin.h"
#include "plugins/SerialPlugin.h"
#include "plugins/TextMessagePlugin.h"
Expand All @@ -25,6 +26,7 @@ void setupPlugins()
nodeInfoPlugin = new NodeInfoPlugin();
positionPlugin = new PositionPlugin();
textMessagePlugin = new TextMessagePlugin();
new TestPlugin();

// 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.
Expand All @@ -51,4 +53,4 @@ void setupPlugins()

// NOTE! This plugin must be added LAST because it likes to check for replies from other plugins and avoid sending extra acks
routingPlugin = new RoutingPlugin();
}
}
24 changes: 24 additions & 0 deletions src/plugins/TestPlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "configuration.h"
#include "TestPlugin.h"
#include "MeshService.h"
#include "main.h"

#include <assert.h>

MeshPacket *TestPlugin::allocTest()
{
assert(currentRequest); // should always be !NULL
auto req = *currentRequest;
auto &p = req.decoded;
// The incoming message is in p.payload
DEBUG_MSG("Received message from=0x%0x, id=%d, msg=%.*s\n", req.from, req.id, p.payload.size, p.payload.bytes);

screen->print("Sending reply\n");

const char *replyStr = "Message Received";
auto reply = allocDataPacket(); // Allocate a packet for sending
reply->decoded.payload.size = strlen(replyStr); // You must specify how many bytes are in the reply
memcpy(reply->decoded.payload.bytes, replyStr, reply->decoded.payload.size);

return reply;
}
22 changes: 22 additions & 0 deletions src/plugins/TestPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#include "SinglePortPlugin.h"


/**
* A simple example plugin that just replies with "Message received" to any message it receives.
*/
class TestPlugin : public SinglePortPlugin
{
public:
/** Constructor
* name is for debugging output
*/
TestPlugin() : SinglePortPlugin("test", PortNum_REPLY_APP) {}

protected:

/** For reply plugin we do all of our processing in the (normally optional)
* want_replies handling
*/
virtual MeshPacket *allocTest();
};

0 comments on commit 6f8b2b6

Please sign in to comment.