From 4d2cb45f9f8e0192ba29ec53c8d60230245caa81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 5 Oct 2022 11:39:50 +0200 Subject: [PATCH] wire in part 1 of serial mode... select if you want textmsg or own portnum via config. --- src/modules/SerialModule.cpp | 25 +++++++++++++++---------- src/modules/SerialModule.h | 23 +++++++++++++++++------ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index 7f07c1bb..59f489d5 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -27,8 +27,7 @@ TXD 15 3) Set timeout to the amount of time to wait before we consider your packet as "done". - 4) (Optional) In SerialModule.h set the port to PortNum_TEXT_MESSAGE_APP if you want to - send messages to/from the general text message channel. + 4) not applicable any more 5) Connect to your device over the serial interface at 38400 8N1. 6) Send a packet up to 240 bytes in length. This will get relayed over the mesh network. 7) (Optional) Set echo to 1 and any message you send out will be echoed back @@ -61,10 +60,20 @@ SerialModule::SerialModule() : concurrency::OSThread("SerialModule") {} char serialStringChar[Constants_DATA_PAYLOAD_LEN]; -SerialModuleRadio::SerialModuleRadio() : SinglePortModule("SerialModuleRadio", PortNum_SERIAL_APP) +SerialModuleRadio::SerialModuleRadio() : MeshModule("SerialModuleRadio") { // restrict to the admin channel for rx boundChannel = Channels::serialChannel; + + switch (moduleConfig.serial.mode) + { + case ModuleConfig_SerialConfig_Serial_Mode_TEXTMSG: + ourPortNum = PortNum_TEXT_MESSAGE_APP; + break; + default: + ourPortNum = PortNum_SERIAL_APP; + break; + } } int32_t SerialModule::runOnce() @@ -139,7 +148,9 @@ int32_t SerialModule::runOnce() baud = 921600; } -#ifdef ARCH_ESP32 +#ifdef ARCH_ESP32 + Serial2.setRxBufferSize(RX_BUFFER); + if (moduleConfig.serial.rxd && moduleConfig.serial.txd) { Serial2.begin(baud, SERIAL_8N1, moduleConfig.serial.rxd, moduleConfig.serial.txd); @@ -159,10 +170,6 @@ int32_t SerialModule::runOnce() Serial2.setTimeout(TIMEOUT); // Number of MS to wait to set the timeout for the string. } -#ifdef ARCH_ESP32 - Serial2.setRxBufferSize(RX_BUFFER); -#endif - serialModuleRadio = new SerialModuleRadio(); firstTime = 0; @@ -244,8 +251,6 @@ ProcessMessage SerialModuleRadio::handleReceived(const MeshPacket &mp) if (moduleConfig.serial.mode == ModuleConfig_SerialConfig_Serial_Mode_DEFAULT || moduleConfig.serial.mode == ModuleConfig_SerialConfig_Serial_Mode_SIMPLE) { - // DEBUG_MSG("* * Message came from the mesh\n"); - // Serial2.println("* * Message came from the mesh"); Serial2.printf("%s", p.payload.bytes); } else if (moduleConfig.serial.mode == ModuleConfig_SerialConfig_Serial_Mode_PROTO) { diff --git a/src/modules/SerialModule.h b/src/modules/SerialModule.h index f92b1342..e93cb595 100644 --- a/src/modules/SerialModule.h +++ b/src/modules/SerialModule.h @@ -4,6 +4,8 @@ #include "concurrency/OSThread.h" #include "configuration.h" #include +#include "MeshModule.h" +#include "Router.h" #include class SerialModule : private concurrency::OSThread @@ -23,16 +25,11 @@ extern SerialModule *serialModule; * Radio interface for SerialModule * */ -class SerialModuleRadio : public SinglePortModule +class SerialModuleRadio : public MeshModule { uint32_t lastRxID = 0; public: - /* - TODO: Switch this to PortNum_SERIAL_APP once the change is able to be merged back here - from the main code. - */ - SerialModuleRadio(); /** @@ -48,6 +45,20 @@ class SerialModuleRadio : public SinglePortModule @return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered for it */ virtual ProcessMessage handleReceived(const MeshPacket &mp) override; + + PortNum ourPortNum; + + virtual bool wantPacket(const MeshPacket *p) override { return p->decoded.portnum == ourPortNum; } + + MeshPacket *allocDataPacket() + { + // Update our local node info with our position (even if we don't decide to update anyone else) + MeshPacket *p = router->allocForSending(); + p->decoded.portnum = ourPortNum; + + return p; + } + }; extern SerialModuleRadio *serialModuleRadio;