Skip to content

Commit 784b8bd

Browse files
authored
Merge pull request #518 from LeeLeahy2/fix-buffer-overrun
Fix serialTransmitBuffer overrun - drain buffer when it gets full
2 parents cfa5c14 + 9482c73 commit 784b8bd

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Firmware/LoRaSerial/Serial.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ void serialBufferOutput(uint8_t * data, uint16_t dataLength)
3535
{
3636
int length;
3737

38+
//Make sure there is enough room in the buffer
39+
if ((sizeof(serialTransmitBuffer) - availableTXBytes()) < (dataLength + 32))
40+
outputSerialData(true);
41+
3842
length = 0;
3943
if ((txHead + dataLength) > sizeof(serialTransmitBuffer))
4044
{
@@ -55,6 +59,10 @@ void serialOutputByte(uint8_t data)
5559
{
5660
if (printerEndpoint == PRINT_TO_SERIAL)
5761
{
62+
//Make sure there is enough room in the buffer
63+
if ((sizeof(serialTransmitBuffer) - availableTXBytes()) < 32)
64+
outputSerialData(true);
65+
5866
//Add this byte to the serial output buffer
5967
serialTransmitBuffer[txHead++] = data;
6068
txHead %= sizeof(serialTransmitBuffer);

0 commit comments

Comments
 (0)