Skip to content

Commit 70c0488

Browse files
committed
Process the command as soon as it fills the command buffer
1 parent a2ef3d1 commit 70c0488

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

Firmware/LoRaSerial/Serial.ino

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ void updateSerial()
354354
{
355355
commandLength = availableRXCommandBytes();
356356

357+
//Don't overflow the command buffer, save space for the zero termination
358+
if (commandLength >= sizeof(commandBuffer))
359+
commandLength = sizeof(commandBuffer) - 1;
360+
357361
for (x = 0 ; x < commandLength ; x++)
358362
{
359363
commandBuffer[x] = commandRXBuffer[commandRXTail++];
@@ -454,7 +458,23 @@ void processSerialInput()
454458
{
455459
//Move this character into the command buffer
456460
commandBuffer[commandLength++] = incoming;
457-
commandLength %= sizeof(commandBuffer);
461+
462+
//Don't allow the command to overflow the command buffer
463+
//Process the long command instead
464+
//Save room for the zero termination
465+
if (commandLength >= (sizeof(commandBuffer) - 1))
466+
{
467+
printerEndpoint = PRINT_TO_SERIAL;
468+
systemPrintln();
469+
if (settings.debugSerial)
470+
{
471+
systemPrint("processSerialInput moved ");
472+
systemPrint(commandLength);
473+
systemPrintln(" from serialReceiveBuffer into commandBuffer");
474+
}
475+
checkCommand(); //Process command buffer
476+
break;
477+
}
458478
}
459479
}
460480
}

0 commit comments

Comments
 (0)