Finish config transition

This commit is contained in:
Sacha Weatherstone
2022-05-07 20:31:21 +10:00
parent c07976438b
commit 6b0ce6b729
55 changed files with 1417 additions and 2027 deletions

View File

@@ -1,9 +1,9 @@
#include "configuration.h"
#include "SerialModule.h"
#include "MeshService.h"
#include "NodeDB.h"
#include "RTC.h"
#include "Router.h"
#include "configuration.h"
#include <Arduino.h>
#include <assert.h>
@@ -20,18 +20,18 @@
Basic Usage:
1) Enable the module by setting serial_module_enabled to 1.
2) Set the pins (serial_module_rxd / serial_module_rxd) for your preferred RX and TX GPIO pins.
1) Enable the module by setting enabled to 1.
2) Set the pins (rxd / rxd) for your preferred RX and TX GPIO pins.
On tbeam, recommend to use:
RXD 35
TXD 15
3) Set serial_module_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".
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.
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 serial_module_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
to your device.
TODO (in this order):
@@ -48,11 +48,11 @@
#define RXD2 16
#define TXD2 17
#define SERIAL_MODULE_RX_BUFFER 128
#define SERIAL_MODULE_STRING_MAX Constants_DATA_PAYLOAD_LEN
#define SERIAL_MODULE_TIMEOUT 250
#define SERIAL_MODULE_BAUD 38400
#define SERIAL_MODULE_ACK 1
#define RX_BUFFER 128
#define STRING_MAX Constants_DATA_PAYLOAD_LEN
#define TIMEOUT 250
#define BAUD 38400
#define ACK 1
SerialModule *serialModule;
SerialModuleRadio *serialModuleRadio;
@@ -76,89 +76,86 @@ int32_t SerialModule::runOnce()
without having to configure it from the PythonAPI or WebUI.
*/
// radioConfig.preferences.serial_module_enabled = 1;
// radioConfig.preferences.serial_module_rxd = 35;
// radioConfig.preferences.serial_module_txd = 15;
// radioConfig.preferences.serial_module_timeout = 1000;
// radioConfig.preferences.serial_module_echo = 1;
// moduleConfig.payloadVariant.serial.enabled = 1;
// moduleConfig.payloadVariant.serial.rxd = 35;
// moduleConfig.payloadVariant.serial.txd = 15;
// moduleConfig.payloadVariant.serial.timeout = 1000;
// moduleConfig.payloadVariant.serial.echo = 1;
if (radioConfig.preferences.serial_module_enabled) {
if (moduleConfig.payloadVariant.serial.enabled) {
if (firstTime) {
// Interface with the serial peripheral from in here.
DEBUG_MSG("Initializing serial peripheral interface\n");
uint32_t baud = 0;
if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_Default) {
if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_Default) {
baud = 38400;
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_110) {
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_110) {
baud = 110;
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_300) {
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_300) {
baud = 300;
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_600) {
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_600) {
baud = 600;
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_1200) {
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_1200) {
baud = 1200;
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_2400) {
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_2400) {
baud = 2400;
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_4800) {
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_4800) {
baud = 4800;
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_9600) {
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_9600) {
baud = 9600;
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_19200) {
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_19200) {
baud = 19200;
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_38400) {
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_38400) {
baud = 38400;
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_57600) {
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_57600) {
baud = 57600;
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_115200) {
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_115200) {
baud = 115200;
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_230400) {
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_230400) {
baud = 230400;
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_460800) {
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_460800) {
baud = 460800;
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_576000) {
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_576000) {
baud = 576000;
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_921600) {
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_921600) {
baud = 921600;
}
if (radioConfig.preferences.serial_module_rxd && radioConfig.preferences.serial_module_txd) {
Serial2.begin(baud, SERIAL_8N1, radioConfig.preferences.serial_module_rxd,
radioConfig.preferences.serial_module_txd);
if (moduleConfig.payloadVariant.serial.rxd && moduleConfig.payloadVariant.serial.txd) {
Serial2.begin(baud, SERIAL_8N1, moduleConfig.payloadVariant.serial.rxd, moduleConfig.payloadVariant.serial.txd);
} else {
Serial2.begin(baud, SERIAL_8N1, RXD2, TXD2);
}
if (radioConfig.preferences.serial_module_timeout) {
if (moduleConfig.payloadVariant.serial.timeout) {
Serial2.setTimeout(
radioConfig.preferences.serial_module_timeout); // Number of MS to wait to set the timeout for the string.
moduleConfig.payloadVariant.serial.timeout); // Number of MS to wait to set the timeout for the string.
} else {
Serial2.setTimeout(SERIAL_MODULE_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.
}
Serial2.setRxBufferSize(SERIAL_MODULE_RX_BUFFER);
Serial2.setRxBufferSize(RX_BUFFER);
serialModuleRadio = new SerialModuleRadio();
@@ -202,7 +199,7 @@ void SerialModuleRadio::sendPayload(NodeNum dest, bool wantReplies)
p->to = dest;
p->decoded.want_response = wantReplies;
p->want_ack = SERIAL_MODULE_ACK;
p->want_ack = ACK;
p->decoded.payload.size = strlen(serialStringChar); // You must specify how many bytes are in the reply
memcpy(p->decoded.payload.bytes, serialStringChar, p->decoded.payload.size);
@@ -214,7 +211,7 @@ ProcessMessage SerialModuleRadio::handleReceived(const MeshPacket &mp)
{
#ifndef NO_ESP32
if (radioConfig.preferences.serial_module_enabled) {
if (moduleConfig.payloadVariant.serial.enabled) {
auto &p = mp.decoded;
// DEBUG_MSG("Received text msg self=0x%0x, from=0x%0x, to=0x%0x, id=%d, msg=%.*s\n",
@@ -223,10 +220,10 @@ ProcessMessage SerialModuleRadio::handleReceived(const MeshPacket &mp)
if (getFrom(&mp) == nodeDB.getNodeNum()) {
/*
* If radioConfig.preferences.serial_module_echo is true, then echo the packets that are sent out back to the TX
* of the serial interface.
* If moduleConfig.payloadVariant.serial.echo is true, then echo the packets that are sent out
* back to the TX of the serial interface.
*/
if (radioConfig.preferences.serial_module_echo) {
if (moduleConfig.payloadVariant.serial.echo) {
// For some reason, we get the packet back twice when we send out of the radio.
// TODO: need to find out why.
@@ -240,13 +237,13 @@ ProcessMessage SerialModuleRadio::handleReceived(const MeshPacket &mp)
} else {
if (radioConfig.preferences.serial_module_mode == RadioConfig_UserPreferences_Serial_Mode_MODE_Default || radioConfig.preferences.serial_module_mode == RadioConfig_UserPreferences_Serial_Mode_MODE_SIMPLE) {
if (moduleConfig.payloadVariant.serial.mode == ModuleConfig_SerialConfig_Serial_Mode_MODE_Default ||
moduleConfig.payloadVariant.serial.mode == ModuleConfig_SerialConfig_Serial_Mode_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 (radioConfig.preferences.serial_module_mode == RadioConfig_UserPreferences_Serial_Mode_MODE_PROTO) {
} else if (moduleConfig.payloadVariant.serial.mode == ModuleConfig_SerialConfig_Serial_Mode_MODE_PROTO) {
}
}