mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-24 17:32:18 +00:00
Merge pull request #1754 from meshtastic/issue-1707
wire in part 2 of serial mode - implements #1228
This commit is contained in:
commit
c70184fbed
@ -27,8 +27,7 @@
|
|||||||
TXD 15
|
TXD 15
|
||||||
3) Set timeout to the amount of time to wait before we consider
|
3) Set timeout to the amount of time to wait before we consider
|
||||||
your packet as "done".
|
your packet as "done".
|
||||||
4) (Optional) In SerialModule.h set the port to PortNum_TEXT_MESSAGE_APP if you want to
|
4) not applicable any more
|
||||||
send messages to/from the general text message channel.
|
|
||||||
5) Connect to your device over the serial interface at 38400 8N1.
|
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.
|
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
|
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];
|
char serialStringChar[Constants_DATA_PAYLOAD_LEN];
|
||||||
|
|
||||||
SerialModuleRadio::SerialModuleRadio() : SinglePortModule("SerialModuleRadio", PortNum_SERIAL_APP)
|
SerialModuleRadio::SerialModuleRadio() : MeshModule("SerialModuleRadio")
|
||||||
{
|
{
|
||||||
// restrict to the admin channel for rx
|
// restrict to the admin channel for rx
|
||||||
boundChannel = Channels::serialChannel;
|
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()
|
int32_t SerialModule::runOnce()
|
||||||
@ -140,6 +149,8 @@ int32_t SerialModule::runOnce()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ARCH_ESP32
|
#ifdef ARCH_ESP32
|
||||||
|
Serial2.setRxBufferSize(RX_BUFFER);
|
||||||
|
|
||||||
if (moduleConfig.serial.rxd && moduleConfig.serial.txd) {
|
if (moduleConfig.serial.rxd && moduleConfig.serial.txd) {
|
||||||
Serial2.begin(baud, SERIAL_8N1, 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.
|
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();
|
serialModuleRadio = new SerialModuleRadio();
|
||||||
|
|
||||||
firstTime = 0;
|
firstTime = 0;
|
||||||
@ -244,8 +251,6 @@ ProcessMessage SerialModuleRadio::handleReceived(const MeshPacket &mp)
|
|||||||
|
|
||||||
if (moduleConfig.serial.mode == ModuleConfig_SerialConfig_Serial_Mode_DEFAULT ||
|
if (moduleConfig.serial.mode == ModuleConfig_SerialConfig_Serial_Mode_DEFAULT ||
|
||||||
moduleConfig.serial.mode == ModuleConfig_SerialConfig_Serial_Mode_SIMPLE) {
|
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);
|
Serial2.printf("%s", p.payload.bytes);
|
||||||
|
|
||||||
} else if (moduleConfig.serial.mode == ModuleConfig_SerialConfig_Serial_Mode_PROTO) {
|
} else if (moduleConfig.serial.mode == ModuleConfig_SerialConfig_Serial_Mode_PROTO) {
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "concurrency/OSThread.h"
|
#include "concurrency/OSThread.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include "MeshModule.h"
|
||||||
|
#include "Router.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
class SerialModule : private concurrency::OSThread
|
class SerialModule : private concurrency::OSThread
|
||||||
@ -23,16 +25,11 @@ extern SerialModule *serialModule;
|
|||||||
* Radio interface for SerialModule
|
* Radio interface for SerialModule
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class SerialModuleRadio : public SinglePortModule
|
class SerialModuleRadio : public MeshModule
|
||||||
{
|
{
|
||||||
uint32_t lastRxID = 0;
|
uint32_t lastRxID = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*
|
|
||||||
TODO: Switch this to PortNum_SERIAL_APP once the change is able to be merged back here
|
|
||||||
from the main code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
SerialModuleRadio();
|
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
|
@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;
|
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;
|
extern SerialModuleRadio *serialModuleRadio;
|
||||||
|
Loading…
Reference in New Issue
Block a user