Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Firmware/LoRaSerial/Commands.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
5 changes: 4 additions & 1 deletion Firmware/LoRaSerial/LoRaSerial.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 8 additions & 6 deletions Firmware/LoRaSerial/Serial.ino
Original file line number Diff line number Diff line change
Expand Up @@ -291,35 +291,37 @@ 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
outputSerialData(false);

//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

//Take a break if there are ISRs to attend to
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

Expand Down
4 changes: 4 additions & 0 deletions Firmware/LoRaSerial/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions Firmware/Tools/Command_Validation_Script.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down