Skip to content

Commit 5b5f0c7

Browse files
authored
Merge pull request #521 from LeeLeahy2/rts-on-off-bytes
Add rtsOffBytes & rtsOnBytes settings to support different remote UARTs
2 parents ba6c116 + 238793f commit 5b5f0c7

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
@@ -1191,6 +1191,8 @@ const COMMAND_ENTRY commands[] =
11911191
{'S', 0, 0, 0, 1, 0, TYPE_BOOL, valInt, "FlowControl", &tempSettings.flowControl},
11921192
{'S', 0, 0, 0, 1, 0, TYPE_BOOL, valInt, "InvertCts", &tempSettings.invertCts},
11931193
{'S', 0, 0, 0, 1, 0, TYPE_BOOL, valInt, "InvertRts", &tempSettings.invertRts},
1194+
{'S', 0, 0, 0, SERIAL_RX_BUFFER_SIZE, 0, TYPE_U16, valInt, "RTSOffBytes", &tempSettings.rtsOffBytes},
1195+
{'S', 0, 0, 0, SERIAL_RX_BUFFER_SIZE, 0, TYPE_U16, valInt, "RTSOnBytes", &tempSettings.rtsOnBytes},
11941196
{'S', 0, 0, 10, 2000, 0, TYPE_U16, valInt, "SerialDelay", &tempSettings.serialTimeoutBeforeSendingFrame_ms},
11951197
{'S', 0, 0, 0, 0, 0, TYPE_SPEED_SERIAL, valSpeedSerial, "SerialSpeed", &tempSettings.serialSpeed},
11961198
{'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
@@ -293,35 +293,37 @@ uint8_t readyOutgoingCommandPacket(uint16_t offset)
293293
//Scan for escape characters
294294
void updateSerial()
295295
{
296+
int bufferSpace;
296297
uint16_t previousHead;
297298
int x;
298299

299300
//Assert RTS when there is enough space in the receive buffer
300301
if ((!rtsAsserted) && (availableRXBytes() < (sizeof(serialReceiveBuffer) / 2))
301-
&& (availableTXBytes() < (sizeof(serialTransmitBuffer) / 4)))
302+
&& (availableTXBytes() <= RTS_ON_BYTES))
302303
updateRTS(true);
303304

304305
//Attempt to empty the serialTransmitBuffer
305306
outputSerialData(false);
306307

307308
//Look for local incoming serial
308309
previousHead = rxHead;
309-
while (rtsAsserted && arch.serialAvailable() && (transactionComplete == false))
310+
bufferSpace = sizeof(serialReceiveBuffer) - 1 - availableRXBytes();
311+
while (bufferSpace-- && arch.serialAvailable() && (transactionComplete == false))
310312
{
311313
blinkSerialRxLed(true); //Turn on LED during serial reception
312314

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

317-
//Deassert RTS when the buffer gets full
318-
if (rtsAsserted && (sizeof(serialReceiveBuffer) - availableRXBytes()) < 32)
319-
updateRTS(false);
320-
321319
byte incoming = systemRead();
322320

323321
serialReceiveBuffer[rxHead++] = incoming; //Push char to holding buffer
324322
rxHead %= sizeof(serialReceiveBuffer);
323+
324+
//Deassert RTS when the buffer gets full
325+
if (rtsAsserted && (sizeof(serialReceiveBuffer) - availableRXBytes()) <= settings.rtsOffBytes)
326+
updateRTS(false);
325327
} //End Serial.available()
326328
blinkSerialRxLed(false); //Turn off LED
327329

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)