Skip to content

Commit 5ee16af

Browse files
committed
Fix wrap-around on debugSerial prints
1 parent 16038f2 commit 5ee16af

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Firmware/LoRaSerial/Serial.ino

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ uint8_t readyOutgoingCommandPacket(uint16_t offset)
235235
//OK if the entire VC_COMMAND_COMPLETE_MESSAGE is in the buffer. Start
236236
//the search one byte into the VC_COMMAND_COMPLETE_MESSAGE position.
237237
for (length = bytesToSend - VC_SERIAL_HEADER_BYTES
238-
- sizeof(VC_COMMAND_COMPLETE_MESSAGE) + 1;
238+
- sizeof(VC_COMMAND_COMPLETE_MESSAGE) + 1;
239239
length < bytesToSend; length++)
240240
if (commandTXBuffer[NEXT_COMMAND_TX_TAIL(length)] == START_OF_VC_SERIAL)
241241
{
@@ -319,7 +319,10 @@ void updateSerial()
319319
if (settings.debugSerial && (rxHead - previousHead))
320320
{
321321
systemPrint("updateSerial moved ");
322-
systemPrint(rxHead - previousHead);
322+
if (rxHead > previousHead)
323+
systemPrint(rxHead - previousHead);
324+
else
325+
systemPrint(sizeof(serialReceiveBuffer) - previousHead + rxHead);
323326
systemPrintln(" bytes into serialReceiveBuffer");
324327
outputSerialData(true);
325328
petWDT();
@@ -501,7 +504,10 @@ void processSerialInput()
501504
if (settings.debugSerial && (radioTxHead != radioHead))
502505
{
503506
systemPrint("processSerialInput moved ");
504-
systemPrint((radioTxHead - radioHead) % sizeof(radioTxBuffer));
507+
if (radioTxHead > radioHead)
508+
systemPrint(radioTxHead - radioHead);
509+
else
510+
systemPrint(sizeof(radioTxBuffer) - radioHead + radioTxHead);
505511
systemPrintln(" bytes from serialReceiveBuffer into radioTxBuffer");
506512
outputSerialData(true);
507513
}

0 commit comments

Comments
 (0)