sforkowany z mirror/meshtastic-firmware
Merge pull request #1754 from meshtastic/issue-1707
wire in part 2 of serial mode - implements #1228raytac-diy
commit
c70184fbed
|
@ -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) {
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "concurrency/OSThread.h"
|
||||
#include "configuration.h"
|
||||
#include <Arduino.h>
|
||||
#include "MeshModule.h"
|
||||
#include "Router.h"
|
||||
#include <functional>
|
||||
|
||||
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;
|
||||
|
|
Ładowanie…
Reference in New Issue