Skip to content

Commit

Permalink
misc. cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Nov 27, 2022
1 parent 840e0ed commit 5682e34
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
17 changes: 8 additions & 9 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2407,17 +2407,16 @@

/**
* Line Number Error Handler
*
* Add function to delay resend requests for line number
* errors, for Hosts that send N# line number with GCode.
* Prevents resend cycles causing stuttering and failure
* on systems with latency between Host and Printer.
* eg. Octoprint through ESP8266(WIFI) pass-through
*
* Add function to delay resend requests for line number errors, for Hosts that
* send N# line number with G-code. Prevents resend cycles causing stuttering
* and failure on systems with Host <-> Printer latency.
* e.g., Octoprint through ESP8266 (WIFI) pass-through.
*/
#define RESEND_HANDLER
//#define RESEND_HANDLER
#if ENABLED(RESEND_HANDLER)
#define RESEND_HANDLER_DROP_GCODE 1 //Number of GCode lines to drop before resend request sent to Host. Octprint>>ESP3D; Min 5
//#define RESEND_HANDLER_NOTICE //Send additional details to host terminal
#define RESEND_HANDLER_DROP_GCODE 1 // Number of G-code lines to drop before resend request sent to Host. Octprint>>ESP3D; Min 5
//#define RESEND_HANDLER_NOTICE // Send additional details to host terminal
#endif

#if ENABLED(SDSUPPORT)
Expand Down
33 changes: 16 additions & 17 deletions Marlin/src/gcode/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ PGMSTR(G28_STR, "G28");
GCodeQueue::SerialState GCodeQueue::serial_state[NUM_SERIAL] = { 0 };
GCodeQueue::RingBuffer GCodeQueue::ring_buffer = { 0 };
#if ENABLED(RESEND_HANDLER)
GCodeQueue::ResendCtrl GCodeQueue::resend_ctrl = { 0 , 0 , RESEND_HANDLER_DROP_GCODE };
GCodeQueue::ResendCtrl GCodeQueue::resend_ctrl = { 0, 0, RESEND_HANDLER_DROP_GCODE };
#endif

#if NO_TIMEOUTS > 0
Expand Down Expand Up @@ -491,40 +491,39 @@ void GCodeQueue::get_serial_commands() {
if (n2pos) npos = n2pos;
}

const long gcode_N = strtol(npos + 1, nullptr, 10); //Host sent GCode Line# from RX_buffer
const long gcode_N = strtol(npos + 1, nullptr, 10); // Host sent G-code Line# from RX_buffer

/**
* Resend Handler - Received line # != expected line number
*
*
* Standard behaviour - Clear RX_Buffer; resend request to host
* Extended behaviour - Allow ignore_resend_max # of errors to be ignored.
* Required when latency present between Marlin>>Host allowing GCode in-flight to cause comms issue
* Extended behaviour - Allow ignore_resend_max # of errors to be ignored.
* Required when latency present between Marlin>>Host allowing G-code in-flight to cause comms issue
* on resend requests, such as stuttering and print failure.
* Ignore_resend_max should not exceed expected in-flight GCode + RX_Buffer. RX_Buffer is cleared in
* Ignore_resend_max should not exceed expected in-flight G-code + RX_Buffer. RX_Buffer is cleared in
* gcode_line_error, not ln_num_error_notice as next serial in buffer may be the required line.
*/
if (gcode_N != serial.last_N + 1 && !M110) {
// In case of error on a serial port, don't prevent other serial port from making progress
#if ENABLED(RESEND_HANDLER)
const serial_index_t serial_ind = p;

if ((resend_ctrl.ignore_resend_count < resend_ctrl.ignore_resend_max - 1)) { //Threshold eliminated resends
if(serial_state[serial_ind.index].last_N != resend_ctrl.last_error_N){ //Is first error instance
if ((resend_ctrl.ignore_resend_count < resend_ctrl.ignore_resend_max - 1)) { // Threshold eliminated resends
if (serial_state[serial_ind.index].last_N != resend_ctrl.last_error_N) { // Is first error instance
ln_num_error_notice(p, gcode_N);
resend_ctrl.last_error_N = serial_state[serial_ind.index].last_N; //Set last ignored error line
resend_ctrl.ignore_resend_count = 0; //Reset count as first instance
resend_ctrl.last_error_N = serial_state[serial_ind.index].last_N; // Set last ignored error line
resend_ctrl.ignore_resend_count = 0; // Reset count as first instance
}
else {
else
ln_num_error_notice(p, gcode_N);
}
resend_ctrl.ignore_resend_count += 1; //Capture anything that doesn't fall in prev if_stmt. Nothing should miss
resend_ctrl.ignore_resend_count += 1; // Capture anything that doesn't fall in prev if_stmt. Nothing should miss
}
else{ //Exceeded maximum deleted requests or is a new resend request
resend_ctrl.ignore_resend_count = 0; //Reset counter
gcode_line_error(F(STR_ERR_LINE_NO), p); //Send resend request
else { // Exceeded maximum deleted requests or is a new resend request
resend_ctrl.ignore_resend_count = 0; // Reset counter
gcode_line_error(F(STR_ERR_LINE_NO), p); // Send resend request
}
#else
gcode_line_error(F(STR_ERR_LINE_NO), p); //Send resend request
gcode_line_error(F(STR_ERR_LINE_NO), p); // Send resend request
#endif
break;
}
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/gcode/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ class GCodeQueue {

/**
* Resend handler to deal with Host>>Printer latency
*/
*/
#if ENABLED(RESEND_HANDLER)
struct ResendCtrl {
long last_error_N; //Record the last requested resend line number
long last_error_N; // Record the last requested resend line number
uint8_t ignore_resend_count;
const uint8_t ignore_resend_max; //Number of resends requests deleted //LH this can be constant
const uint8_t ignore_resend_max; // Number of resends requests deleted //LH this can be constant
};

static ResendCtrl resend_ctrl; //resend ctrl variables
static ResendCtrl resend_ctrl; // Resend ctrl variables

static void ln_num_error_notice(const serial_index_t serial_ind, const long host_gcode_N);
#endif
Expand Down

0 comments on commit 5682e34

Please sign in to comment.