diff --git a/Firmware/LoRaSerial/Commands.ino b/Firmware/LoRaSerial/Commands.ino index 6cd2d3f8..688e59cd 100644 --- a/Firmware/LoRaSerial/Commands.ino +++ b/Firmware/LoRaSerial/Commands.ino @@ -1188,6 +1188,8 @@ const COMMAND_ENTRY commands[] = {'S', 0, 0, 0, 1, 0, TYPE_BOOL, valInt, "FlowControl", &tempSettings.flowControl}, {'S', 0, 0, 0, 1, 0, TYPE_BOOL, valInt, "InvertCts", &tempSettings.invertCts}, {'S', 0, 0, 0, 1, 0, TYPE_BOOL, valInt, "InvertRts", &tempSettings.invertRts}, + {'S', 0, 0, 0, SERIAL_RX_BUFFER_SIZE, 0, TYPE_U16, valInt, "RTSOffBytes", &tempSettings.rtsOffBytes}, + {'S', 0, 0, 0, SERIAL_RX_BUFFER_SIZE, 0, TYPE_U16, valInt, "RTSOnBytes", &tempSettings.rtsOnBytes}, {'S', 0, 0, 10, 2000, 0, TYPE_U16, valInt, "SerialDelay", &tempSettings.serialTimeoutBeforeSendingFrame_ms}, {'S', 0, 0, 0, 0, 0, TYPE_SPEED_SERIAL, valSpeedSerial, "SerialSpeed", &tempSettings.serialSpeed}, {'S', 0, 0, 0, 1, 0, TYPE_BOOL, valInt, "UsbSerialWait", &tempSettings.usbSerialWait}, diff --git a/Firmware/LoRaSerial/LoRaSerial.ino b/Firmware/LoRaSerial/LoRaSerial.ino index 6a33749f..4d398a40 100644 --- a/Firmware/LoRaSerial/LoRaSerial.ino +++ b/Firmware/LoRaSerial/LoRaSerial.ino @@ -82,6 +82,9 @@ const int FIRMWARE_VERSION_MINOR = 0; #define ENABLE_DEVELOPER false #endif //ENABLE_DEVELOPER +#define SERIAL_RX_BUFFER_SIZE 1024 +#define RTS_ON_BYTES (SERIAL_RX_BUFFER_SIZE / 4) + #include "settings.h" //Hardware connections @@ -195,7 +198,7 @@ const uint8_t responseDelayDivisor = 4; //Add on to max response time after pack //Buffer to receive serial data from the USB or serial ports uint16_t rxHead = 0; uint16_t rxTail = 0; -uint8_t serialReceiveBuffer[1024]; +uint8_t serialReceiveBuffer[SERIAL_RX_BUFFER_SIZE]; //Buffer to store bytes for transmission via the long range radio uint16_t radioTxHead = 0; diff --git a/Firmware/LoRaSerial/Serial.ino b/Firmware/LoRaSerial/Serial.ino index e4c0ceeb..997b76ff 100644 --- a/Firmware/LoRaSerial/Serial.ino +++ b/Firmware/LoRaSerial/Serial.ino @@ -291,12 +291,13 @@ uint8_t readyOutgoingCommandPacket(uint16_t offset) //Scan for escape characters void updateSerial() { + int bufferSpace; uint16_t previousHead; int x; //Assert RTS when there is enough space in the receive buffer if ((!rtsAsserted) && (availableRXBytes() < (sizeof(serialReceiveBuffer) / 2)) - && (availableTXBytes() < (sizeof(serialTransmitBuffer) / 4))) + && (availableTXBytes() <= RTS_ON_BYTES)) updateRTS(true); //Attempt to empty the serialTransmitBuffer @@ -304,7 +305,8 @@ void updateSerial() //Look for local incoming serial previousHead = rxHead; - while (rtsAsserted && arch.serialAvailable() && (transactionComplete == false)) + bufferSpace = sizeof(serialReceiveBuffer) - 1 - availableRXBytes(); + while (bufferSpace-- && arch.serialAvailable() && (transactionComplete == false)) { blinkSerialRxLed(true); //Turn on LED during serial reception @@ -312,14 +314,14 @@ void updateSerial() petWDT(); if (timeToHop == true) hopChannel(); - //Deassert RTS when the buffer gets full - if (rtsAsserted && (sizeof(serialReceiveBuffer) - availableRXBytes()) < 32) - updateRTS(false); - byte incoming = systemRead(); serialReceiveBuffer[rxHead++] = incoming; //Push char to holding buffer rxHead %= sizeof(serialReceiveBuffer); + + //Deassert RTS when the buffer gets full + if (rtsAsserted && (sizeof(serialReceiveBuffer) - availableRXBytes()) <= settings.rtsOffBytes) + updateRTS(false); } //End Serial.available() blinkSerialRxLed(false); //Turn off LED diff --git a/Firmware/LoRaSerial/settings.h b/Firmware/LoRaSerial/settings.h index 64f628af..6246c208 100644 --- a/Firmware/LoRaSerial/settings.h +++ b/Firmware/LoRaSerial/settings.h @@ -445,6 +445,10 @@ typedef struct struct_settings { uint16_t serialTimeoutBeforeSendingFrame_ms = 50; //Send partial buffer if time expires bool echo = false; //Print locally inputted serial bool flowControl = false; //Enable the use of CTS/RTS flow control signals + + uint16_t rtsOffBytes = 32; //Number of free bytes in serialReceiveBuffer when RTS is deasserted + uint16_t rtsOnBytes = RTS_ON_BYTES; //Number of free bytes in serialReceiveBuffer when RTS is asserted + #if (ENABLE_DEVELOPER == true) #define WAIT_SERIAL_DEFAULT true #else //ENABLE_DEVELOPER diff --git a/Firmware/Tools/Command_Validation_Script.txt b/Firmware/Tools/Command_Validation_Script.txt index f5be132a..f524d3b8 100644 --- a/Firmware/Tools/Command_Validation_Script.txt +++ b/Firmware/Tools/Command_Validation_Script.txt @@ -358,6 +358,16 @@ at-InvertCts=2 at-InvertCts=1 at-InvertCts +at-RTSOffBytes=0 +at-RTSOffBytes=1025 +at-RTSOffBytes=1024 +at-RTSOffBytes=32 + +at-RTSOnBytes=0 +at-RTSOnBytes=1025 +at-RTSOnBytes=1024 +at-RTSOnBytes=256 + at-InvertRts=0 at-InvertRts=2 at-InvertRts=1