forked from meshtastic/firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for external Plugin file. (test-lib/ is out of the reposi…
…tory, so this will crash)
- Loading branch information
1 parent
b2524ce
commit 6f8b2b6
Showing
4 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |