Skip to content

Commit 238793f

Browse files
committed
Add rtsOffBytes & rtsOnBytes settings to support different remote UARTs
1 parent e0c533e commit 238793f

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

Firmware/LoRaSerial/Commands.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,8 @@ const COMMAND_ENTRY commands[] =
11881188
{'S', 0, 0, 0, 1, 0, TYPE_BOOL, valInt, "FlowControl", &tempSettings.flowControl},
11891189
{'S', 0, 0, 0, 1, 0, TYPE_BOOL, valInt, "InvertCts", &tempSettings.invertCts},
11901190
{'S', 0, 0, 0, 1, 0, TYPE_BOOL, valInt, "InvertRts", &tempSettings.invertRts},
1191+
{'S', 0, 0, 0, SERIAL_RX_BUFFER_SIZE, 0, TYPE_U16, valInt, "RTSOffBytes", &tempSettings.rtsOffBytes},
1192+
{'S', 0, 0, 0, SERIAL_RX_BUFFER_SIZE, 0, TYPE_U16, valInt, "RTSOnBytes", &tempSettings.rtsOnBytes},
11911193
{'S', 0, 0, 10, 2000, 0, TYPE_U16, valInt, "SerialDelay", &tempSettings.serialTimeoutBeforeSendingFrame_ms},
11921194
{'S', 0, 0, 0, 0, 0, TYPE_SPEED_SERIAL, valSpeedSerial, "SerialSpeed", &tempSettings.serialSpeed},
11931195
{'S', 0, 0, 0, 1, 0, TYPE_BOOL, valInt, "UsbSerialWait", &tempSettings.usbSerialWait},

Firmware/LoRaSerial/LoRaSerial.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ const int FIRMWARE_VERSION_MINOR = 0;
8282
#define ENABLE_DEVELOPER false
8383
#endif //ENABLE_DEVELOPER
8484

85+
#define SERIAL_RX_BUFFER_SIZE 1024
86+
#define RTS_ON_BYTES (SERIAL_RX_BUFFER_SIZE / 4)
87+
8588
#include "settings.h"
8689

8790
//Hardware connections
@@ -195,7 +198,7 @@ const uint8_t responseDelayDivisor = 4; //Add on to max response time after pack
195198
//Buffer to receive serial data from the USB or serial ports
196199
uint16_t rxHead = 0;
197200
uint16_t rxTail = 0;
198-
uint8_t serialReceiveBuffer[1024];
201+
uint8_t serialReceiveBuffer[SERIAL_RX_BUFFER_SIZE];
199202

200203
//Buffer to store bytes for transmission via the long range radio
201204
uint16_t radioTxHead = 0;

Firmware/LoRaSerial/Serial.ino

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,35 +291,37 @@ uint8_t readyOutgoingCommandPacket(uint16_t offset)
291291
//Scan for escape characters
292292
void updateSerial()
293293
{
294+
int bufferSpace;
294295
uint16_t previousHead;
295296
int x;
296297

297298
//Assert RTS when there is enough space in the receive buffer
298299
if ((!rtsAsserted) && (availableRXBytes() < (sizeof(serialReceiveBuffer) / 2))
299-
&& (availableTXBytes() < (sizeof(serialTransmitBuffer) / 4)))
300+
&& (availableTXBytes() <= RTS_ON_BYTES))
300301
updateRTS(true);
301302

302303
//Attempt to empty the serialTransmitBuffer
303304
outputSerialData(false);
304305

305306
//Look for local incoming serial
306307
previousHead = rxHead;
307-
while (rtsAsserted && arch.serialAvailable() && (transactionComplete == false))
308+
bufferSpace = sizeof(serialReceiveBuffer) - 1 - availableRXBytes();
309+
while (bufferSpace-- && arch.serialAvailable() && (transactionComplete == false))
308310
{
309311
blinkSerialRxLed(true); //Turn on LED during serial reception
310312

311313
//Take a break if there are ISRs to attend to
312314
petWDT();
313315
if (timeToHop == true) hopChannel();
314316

315-
//Deassert RTS when the buffer gets full
316-
if (rtsAsserted && (sizeof(serialReceiveBuffer) - availableRXBytes()) < 32)
317-
updateRTS(false);
318-
319317
byte incoming = systemRead();
320318

321319
serialReceiveBuffer[rxHead++] = incoming; //Push char to holding buffer
322320
rxHead %= sizeof(serialReceiveBuffer);
321+
322+
//Deassert RTS when the buffer gets full
323+
if (rtsAsserted && (sizeof(serialReceiveBuffer) - availableRXBytes()) <= settings.rtsOffBytes)
324+
updateRTS(false);
323325
} //End Serial.available()
324326
blinkSerialRxLed(false); //Turn off LED
325327

Firmware/LoRaSerial/settings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,10 @@ typedef struct struct_settings {
445445
uint16_t serialTimeoutBeforeSendingFrame_ms = 50; //Send partial buffer if time expires
446446
bool echo = false; //Print locally inputted serial
447447
bool flowControl = false; //Enable the use of CTS/RTS flow control signals
448+
449+
uint16_t rtsOffBytes = 32; //Number of free bytes in serialReceiveBuffer when RTS is deasserted
450+
uint16_t rtsOnBytes = RTS_ON_BYTES; //Number of free bytes in serialReceiveBuffer when RTS is asserted
451+
448452
#if (ENABLE_DEVELOPER == true)
449453
#define WAIT_SERIAL_DEFAULT true
450454
#else //ENABLE_DEVELOPER

Firmware/Tools/Command_Validation_Script.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,16 @@ at-InvertCts=2
358358
at-InvertCts=1
359359
at-InvertCts
360360

361+
at-RTSOffBytes=0
362+
at-RTSOffBytes=1025
363+
at-RTSOffBytes=1024
364+
at-RTSOffBytes=32
365+
366+
at-RTSOnBytes=0
367+
at-RTSOnBytes=1025
368+
at-RTSOnBytes=1024
369+
at-RTSOnBytes=256
370+
361371
at-InvertRts=0
362372
at-InvertRts=2
363373
at-InvertRts=1

0 commit comments

Comments
 (0)