Skip to content

Commit

Permalink
Added inputOverflow flag so that when we get behind executing GCode c…
Browse files Browse the repository at this point in the history
…ommands, and stop reading serial input, when we come back we resynchronize with serial to ensure nothing got missed. Might address seemecnc#16.
  • Loading branch information
teejaydub committed Mar 2, 2019
1 parent 024439f commit 5f81b94
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
27 changes: 24 additions & 3 deletions Repetier Firmware/Repetier/gcode.cpp
Expand Up @@ -37,6 +37,7 @@ uint8_t GCode::wasLastCommandReceivedAsBinary = 0; ///< Was the last successful
uint8_t GCode::commentDetected = false; ///< Flags true if we are reading the comment part of a command.
uint8_t GCode::binaryCommandSize; ///< Expected size of the incoming binary command.
bool GCode::waitUntilAllCommandsAreParsed = false; ///< Don't read until all commands are parsed. Needed if gcode_buffer is misused as storage for strings.
bool GCode::inputOverflow = false; ///< After exiting waitUntilAllCommandsAreParsed, purge the serial port.
uint32_t GCode::lastLineNumber = 0; ///< Last line number received.
uint32_t GCode::actLineNumber; ///< Line number of current command.
int8_t GCode::waitingForResend = -1; ///< Waiting for line to be resend. -1 = no wait.
Expand Down Expand Up @@ -329,9 +330,29 @@ It must be called frequently to empty the incoming buffer.
*/
void GCode::readFromSerial()
{
if(bufferLength >= GCODE_BUFFER_SIZE) return; // all buffers full
if(waitUntilAllCommandsAreParsed && bufferLength) return;
waitUntilAllCommandsAreParsed = false;
if(bufferLength >= GCODE_BUFFER_SIZE) {
// The command buffer is full. Can't accept any new commands, so wait until we've popped at least one.
// But, while we're not reading from the serial port, we can't know how long it's been or whether we've missed input.
// So, drain all the commands, then ask the controller to start over.
waitUntilAllCommandsAreParsed = true;
inputOverflow = true;
return;
}
if (waitUntilAllCommandsAreParsed) {
if (bufferLength) {
// There are still commands to execute, so finish them.
return;
} else {
// We're out of commands. Now start parsing again.
waitUntilAllCommandsAreParsed = false;
if (inputOverflow) {
// And, let the controller know that we might have missed serial input since the last command processed.
requestResend();
inputOverflow = false;
}
}
}

millis_t time = HAL::timeInMilliseconds();
if(!HAL::serialByteAvailable())
{
Expand Down
1 change: 1 addition & 0 deletions Repetier Firmware/Repetier/gcode.h
Expand Up @@ -213,6 +213,7 @@ class GCode // 52 uint8_ts per command needed
static uint8_t commentDetected; ///< Flags true if we are reading the comment part of a command.
static uint8_t binaryCommandSize; ///< Expected size of the incoming binary command.
static bool waitUntilAllCommandsAreParsed; ///< Don't read until all commands are parsed. Needed if gcode_buffer is misused as storage for strings.
static bool inputOverflow; ///< After exiting waitUntilAllCommandsAreParsed, purge the serial port.
static uint32_t lastLineNumber; ///< Last line number received.
static uint32_t actLineNumber; ///< Line number of current command.
static int8_t waitingForResend; ///< Waiting for line to be resend. -1 = no wait.
Expand Down

0 comments on commit 5f81b94

Please sign in to comment.