Skip to content

Commit

Permalink
WIP Used for debugging the issue (will be reverted in a later step), …
Browse files Browse the repository at this point in the history
…don't pull this.
  • Loading branch information
X-Ryl669 committed Feb 18, 2021
1 parent b679069 commit 9f9b82e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Marlin/src/gcode/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ void GCodeQueue::ok_to_send() {
SERIAL_EOL();
}

// WIP: TTTTTTTTTTTTT REMOVE THIS WHEN IT'S VALIDATED TTTTTTTTTTTTTTTT
static bool dumpUponError = false;
extern MarlinSerial _MSerial;

/**
* Send a "Resend: nnn" message to the host to
* indicate that a command needs to be re-sent.
Expand All @@ -317,6 +321,7 @@ void GCodeQueue::flush_and_request_resend() {
SERIAL_FLUSH();
SERIAL_ECHOPGM(STR_RESEND);
SERIAL_ECHOLN(last_N[serial_ind] + 1);
dumpUponError = true;
}

// Multiserial already handle the dispatch to/from multiple port by itself
Expand Down Expand Up @@ -420,6 +425,9 @@ inline bool process_line_done(uint8_t &sis, char (&buff)[MAX_CMD_SIZE], int &ind
return is_empty; // Inform the caller
}




/**
* Get all commands waiting on the serial port and queue them.
* Exit when the buffer is full or when no more characters are
Expand Down Expand Up @@ -465,6 +473,13 @@ void GCodeQueue::get_serial_commands() {
// No data for this port ? Skip it
if (!serial_data_available(p)) continue;

if (dumpUponError) {
SERIAL_ECHO_START();
// On LPC1768, available is returning the number of bytes that are available
if (p == 1) SERIAL_ECHOPAIR("A:", (int)_MSerial.available());
else SERIAL_ECHOPAIR("A:", (int)MYSERIAL0.available());
}

// Ok, we have some data to process, let's make progress here
hadData = true;

Expand All @@ -483,6 +498,10 @@ void GCodeQueue::get_serial_commands() {
#endif
}

if (dumpUponError) {
SERIAL_ECHOPAIR(" L", length, " R", p, " C", ISEOL(c) ? AS_CHAR('$') : AS_CHAR(c));
}

const char serial_char = (char)c;

if (ISEOL(serial_char)) {
Expand All @@ -493,6 +512,10 @@ void GCodeQueue::get_serial_commands() {

char* command = serial_line_buffer[p];

if (dumpUponError) {
SERIAL_ECHOPAIR(" CMD:", command);
}

while (*command == ' ') command++; // Skip leading spaces
char *npos = (*command == 'N') ? command : nullptr; // Require the N parameter to start the line

Expand All @@ -506,6 +529,9 @@ void GCodeQueue::get_serial_commands() {
}

const long gcode_N = strtol(npos + 1, nullptr, 10);
if (dumpUponError) {
SERIAL_ECHOPAIR(" N:", gcode_N, " n:", npos+1, " lN:", last_N[p]);
}

if (gcode_N != last_N[p] + 1 && !M110) {
// In case of error on a serial port, don't prevent other serial port from making progress
Expand Down Expand Up @@ -582,10 +608,18 @@ void GCodeQueue::get_serial_commands() {
, p
#endif
);
if (dumpUponError) {
SERIAL_ECHOPAIR(" El:", length);
}

}
else
process_stream_char(serial_char, serial_input_state[p], serial_line_buffer[p], serial_count[p]);

if (dumpUponError) {
SERIAL_ECHOLNPAIR(" SiS:", serial_input_state[p], " SLB:", serial_line_buffer[p], " SC:", serial_count[p]);
}

} // NUM_SERIAL loop
} // queue has space, serial has data
}
Expand Down

0 comments on commit 9f9b82e

Please sign in to comment.