diff --git a/firmware/drivers/communicator/communicator.cpp b/firmware/drivers/communicator/communicator.cpp index 1fdde41c2faaf5e6aa0b1a9bf7139d1b0ad0abb2..46ac787f68203d421af0179fb1dceb6e15a44dbc 100644 --- a/firmware/drivers/communicator/communicator.cpp +++ b/firmware/drivers/communicator/communicator.cpp @@ -30,6 +30,10 @@ double checkFreeMemory() { bool Communicator::communicate(){ + if (SERCHAN.available() >= SERIAL_BUFFER_SIZE) { + Serial.println("Warning: Serial buffer overflow!"); + flushSerialBuffer_(); // Clear it to prevent overflow issues + } if(!serialCharAvailable_()){ //no communication if(msElapsedSinceLastTransaction_() > interval_assume_eow_ms_){ //no sign of supervision for 30 minutes, shut down @@ -255,3 +259,9 @@ unsigned long Communicator::msElapsedSinceLastTransaction_(){ } +void Communicator::flushSerialBuffer_(){ + while (SERCHAN.available()) { + SERCHAN.read(); // Dump any remaining data + } +} +