Update to SerialPlugin to take advantage of the configs

This commit is contained in:
Jm 2021-01-16 22:27:33 -08:00
parent b9d025dd58
commit d7f26493a5
2 changed files with 64 additions and 55 deletions

View File

@ -1,14 +1,15 @@
#include "plugins/NodeInfoPlugin.h" #include "plugins/NodeInfoPlugin.h"
#include "plugins/PositionPlugin.h" #include "plugins/PositionPlugin.h"
#include "plugins/RemoteHardwarePlugin.h"
#include "plugins/ReplyPlugin.h" #include "plugins/ReplyPlugin.h"
#include "plugins/SerialPlugin.h" #include "plugins/SerialPlugin.h"
#include "plugins/RemoteHardwarePlugin.h"
#include "plugins/TextMessagePlugin.h" #include "plugins/TextMessagePlugin.h"
/** /**
* Create plugin instances here. If you are adding a new plugin, you must 'new' it here (or somewhere else) * Create plugin instances here. If you are adding a new plugin, you must 'new' it here (or somewhere else)
*/ */
void setupPlugins() { void setupPlugins()
{
nodeInfoPlugin = new NodeInfoPlugin(); nodeInfoPlugin = new NodeInfoPlugin();
positionPlugin = new PositionPlugin(); positionPlugin = new PositionPlugin();
textMessagePlugin = new TextMessagePlugin(); textMessagePlugin = new TextMessagePlugin();
@ -18,5 +19,11 @@ void setupPlugins() {
new RemoteHardwarePlugin(); new RemoteHardwarePlugin();
new ReplyPlugin(); new ReplyPlugin();
#ifndef NO_ESP32
// Only run on an esp32 based device.
new SerialPlugin(); // Maintained by MC Hamster (Jm Casler) jm@casler.org new SerialPlugin(); // Maintained by MC Hamster (Jm Casler) jm@casler.org
#endif
} }

View File

@ -25,7 +25,7 @@
Basic Usage: Basic Usage:
1) Enable the plugin by setting SERIALPLUGIN_ENABLED to 1. 1) Enable the plugin by setting serialplugin_enabled in the device configuration to 1.
2) Set the pins (RXD2 / TXD2) for your preferred RX and TX GPIO pins. 2) Set the pins (RXD2 / TXD2) for your preferred RX and TX GPIO pins.
3) Set SERIALPLUGIN_TIMEOUT to the amount of time to wait before we consider 3) Set SERIALPLUGIN_TIMEOUT to the amount of time to wait before we consider
your packet as "done". your packet as "done".
@ -57,8 +57,6 @@
#define SERIALPLUGIN_STRING_MAX Constants_DATA_PAYLOAD_LEN #define SERIALPLUGIN_STRING_MAX Constants_DATA_PAYLOAD_LEN
#define SERIALPLUGIN_TIMEOUT 250 #define SERIALPLUGIN_TIMEOUT 250
#define SERIALPLUGIN_BAUD 38400 #define SERIALPLUGIN_BAUD 38400
#define SERIALPLUGIN_ENABLED 0
#define SERIALPLUGIN_ECHO 0
#define SERIALPLUGIN_ACK 1 #define SERIALPLUGIN_ACK 1
SerialPlugin *serialPlugin; SerialPlugin *serialPlugin;
@ -70,16 +68,21 @@ char serialStringChar[Constants_DATA_PAYLOAD_LEN];
int32_t SerialPlugin::runOnce() int32_t SerialPlugin::runOnce()
{ {
#ifdef NO_ESP32 #ifndef NO_ESP32
if (radioConfig.preferences.serialplugin_enabled) {
#if SERIALPLUGIN_ENABLED == 1
if (firstTime) { if (firstTime) {
// Interface with the serial peripheral from in here. // Interface with the serial peripheral from in here.
DEBUG_MSG("Initilizing serial peripheral interface\n"); DEBUG_MSG("Initilizing serial peripheral interface\n");
if (radioConfig.preferences.serialplugin_rxd && radioConfig.preferences.serialplugin_txd) {
Serial2.begin(SERIALPLUGIN_BAUD, SERIAL_8N1, radioConfig.preferences.serialplugin_rxd,
radioConfig.preferences.serialplugin_txd);
} else {
Serial2.begin(SERIALPLUGIN_BAUD, SERIAL_8N1, RXD2, TXD2); Serial2.begin(SERIALPLUGIN_BAUD, SERIAL_8N1, RXD2, TXD2);
}
Serial2.setTimeout(SERIALPLUGIN_TIMEOUT); // Number of MS to wait to set the timeout for the string. Serial2.setTimeout(SERIALPLUGIN_TIMEOUT); // Number of MS to wait to set the timeout for the string.
Serial2.setRxBufferSize(SERIALPLUGIN_RX_BUFFER); Serial2.setRxBufferSize(SERIALPLUGIN_RX_BUFFER);
@ -101,11 +104,11 @@ int32_t SerialPlugin::runOnce()
} }
return (10); return (10);
#else } else {
DEBUG_MSG("Serial Plugin Disabled\n"); DEBUG_MSG("Serial Plugin Disabled\n");
return (INT32_MAX); return (INT32_MAX);
#endif }
#endif #endif
} }
@ -135,9 +138,9 @@ void SerialPluginRadio::sendPayload(NodeNum dest, bool wantReplies)
bool SerialPluginRadio::handleReceived(const MeshPacket &mp) bool SerialPluginRadio::handleReceived(const MeshPacket &mp)
{ {
#ifdef NO_ESP32 #ifndef NO_ESP32
#if SERIALPLUGIN_ENABLED == 1 if (radioConfig.preferences.serialplugin_enabled) {
auto &p = mp.decoded.data; auto &p = mp.decoded.data;
// DEBUG_MSG("Received text msg self=0x%0x, from=0x%0x, to=0x%0x, id=%d, msg=%.*s\n", nodeDB.getNodeNum(), // DEBUG_MSG("Received text msg self=0x%0x, from=0x%0x, to=0x%0x, id=%d, msg=%.*s\n", nodeDB.getNodeNum(),
@ -146,10 +149,10 @@ bool SerialPluginRadio::handleReceived(const MeshPacket &mp)
if (mp.from == nodeDB.getNodeNum()) { if (mp.from == nodeDB.getNodeNum()) {
/* /*
* If SERIALPLUGIN_ECHO is true, then echo the packets that are sent out back to the TX * If radioConfig.preferences.serialplugin_echo is true, then echo the packets that are sent out back to the TX
* of the serial interface. * of the serial interface.
*/ */
if (SERIALPLUGIN_ECHO) { if (radioConfig.preferences.serialplugin_echo) {
// For some reason, we get the packet back twice when we send out of the radio. // For some reason, we get the packet back twice when we send out of the radio.
// TODO: need to find out why. // TODO: need to find out why.
@ -167,10 +170,9 @@ bool SerialPluginRadio::handleReceived(const MeshPacket &mp)
Serial2.printf("%s", p.payload.bytes); Serial2.printf("%s", p.payload.bytes);
} }
#else } else {
DEBUG_MSG("Serial Plugin Disabled\n"); DEBUG_MSG("Serial Plugin Disabled\n");
}
#endif
#endif #endif