MeatPack serial encoding (#20802)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
ellensp
2021-01-24 19:43:23 +13:00
committed by GitHub
parent a243996aca
commit 3921369f98
8 changed files with 487 additions and 78 deletions

View File

@ -141,6 +141,9 @@ void GcodeSuite::M115() {
// CHAMBER_TEMPERATURE (M141, M191)
cap_line(PSTR("CHAMBER_TEMPERATURE"), ENABLED(HAS_HEATED_CHAMBER));
// MEATPACK Compresson
cap_line(PSTR("MEATPACK"), ENABLED(MEATPACK));
// Machine Geometry
#if ENABLED(M115_GEOMETRY_REPORT)
const xyz_pos_t dmin = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS },

View File

@ -48,6 +48,10 @@ GCodeQueue queue;
#include "../feature/binary_stream.h"
#endif
#if ENABLED(MEATPACK)
#include "../feature/meatpack.h"
#endif
#if ENABLED(POWER_LOSS_RECOVERY)
#include "../feature/powerloss.h"
#endif
@ -474,98 +478,109 @@ void GCodeQueue::get_serial_commands() {
const int c = read_serial(i);
if (c < 0) continue;
const char serial_char = c;
#if ENABLED(MEATPACK)
meatpack.handle_rx_char(uint8_t(c));
char c_res[2] = { 0, 0 };
const uint8_t char_count = meatpack.get_result_char(c_res);
#else
constexpr uint8_t char_count = 1;
#endif
if (ISEOL(serial_char)) {
LOOP_L_N(char_index, char_count) {
const char serial_char = TERN(MEATPACK, c_res[char_index], c);
// Reset our state, continue if the line was empty
if (process_line_done(serial_input_state[i], serial_line_buffer[i], serial_count[i]))
continue;
if (ISEOL(serial_char)) {
char* command = serial_line_buffer[i];
// Reset our state, continue if the line was empty
if (process_line_done(serial_input_state[i], serial_line_buffer[i], serial_count[i]))
continue;
while (*command == ' ') command++; // Skip leading spaces
char *npos = (*command == 'N') ? command : nullptr; // Require the N parameter to start the line
char* command = serial_line_buffer[i];
if (npos) {
while (*command == ' ') command++; // Skip leading spaces
char *npos = (*command == 'N') ? command : nullptr; // Require the N parameter to start the line
const bool M110 = !!strstr_P(command, PSTR("M110"));
if (npos) {
if (M110) {
char* n2pos = strchr(command + 4, 'N');
if (n2pos) npos = n2pos;
const bool M110 = !!strstr_P(command, PSTR("M110"));
if (M110) {
char* n2pos = strchr(command + 4, 'N');
if (n2pos) npos = n2pos;
}
const long gcode_N = strtol(npos + 1, nullptr, 10);
if (gcode_N != last_N[i] + 1 && !M110)
return gcode_line_error(PSTR(STR_ERR_LINE_NO), i);
char *apos = strrchr(command, '*');
if (apos) {
uint8_t checksum = 0, count = uint8_t(apos - command);
while (count) checksum ^= command[--count];
if (strtol(apos + 1, nullptr, 10) != checksum)
return gcode_line_error(PSTR(STR_ERR_CHECKSUM_MISMATCH), i);
}
else
return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), i);
last_N[i] = gcode_N;
}
#if ENABLED(SDSUPPORT)
// Pronterface "M29" and "M29 " has no line number
else if (card.flag.saving && !is_M29(command))
return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), i);
#endif
const long gcode_N = strtol(npos + 1, nullptr, 10);
//
// Movement commands give an alert when the machine is stopped
//
if (gcode_N != last_N[i] + 1 && !M110)
return gcode_line_error(PSTR(STR_ERR_LINE_NO), i);
char *apos = strrchr(command, '*');
if (apos) {
uint8_t checksum = 0, count = uint8_t(apos - command);
while (count) checksum ^= command[--count];
if (strtol(apos + 1, nullptr, 10) != checksum)
return gcode_line_error(PSTR(STR_ERR_CHECKSUM_MISMATCH), i);
}
else
return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), i);
last_N[i] = gcode_N;
}
#if ENABLED(SDSUPPORT)
// Pronterface "M29" and "M29 " has no line number
else if (card.flag.saving && !is_M29(command))
return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), i);
#endif
//
// Movement commands give an alert when the machine is stopped
//
if (IsStopped()) {
char* gpos = strchr(command, 'G');
if (gpos) {
switch (strtol(gpos + 1, nullptr, 10)) {
case 0: case 1:
#if ENABLED(ARC_SUPPORT)
case 2: case 3:
#endif
#if ENABLED(BEZIER_CURVE_SUPPORT)
case 5:
#endif
PORT_REDIRECT(i); // Reply to the serial port that sent the command
SERIAL_ECHOLNPGM(STR_ERR_STOPPED);
LCD_MESSAGEPGM(MSG_STOPPED);
break;
if (IsStopped()) {
char* gpos = strchr(command, 'G');
if (gpos) {
switch (strtol(gpos + 1, nullptr, 10)) {
case 0: case 1:
#if ENABLED(ARC_SUPPORT)
case 2: case 3:
#endif
#if ENABLED(BEZIER_CURVE_SUPPORT)
case 5:
#endif
PORT_REDIRECT(i); // Reply to the serial port that sent the command
SERIAL_ECHOLNPGM(STR_ERR_STOPPED);
LCD_MESSAGEPGM(MSG_STOPPED);
break;
}
}
}
}
#if DISABLED(EMERGENCY_PARSER)
// Process critical commands early
if (command[0] == 'M') switch (command[3]) {
case '8': if (command[2] == '0' && command[1] == '1') { wait_for_heatup = false; TERN_(HAS_LCD_MENU, wait_for_user = false); } break;
case '2': if (command[2] == '1' && command[1] == '1') kill(M112_KILL_STR, nullptr, true); break;
case '0': if (command[1] == '4' && command[2] == '1') quickstop_stepper(); break;
}
#endif
#if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
last_command_time = ms;
#endif
// Add the command to the queue
_enqueue(serial_line_buffer[i], true
#if HAS_MULTI_SERIAL
, i
#if DISABLED(EMERGENCY_PARSER)
// Process critical commands early
if (command[0] == 'M') switch (command[3]) {
case '8': if (command[2] == '0' && command[1] == '1') { wait_for_heatup = false; TERN_(HAS_LCD_MENU, wait_for_user = false); } break;
case '2': if (command[2] == '1' && command[1] == '1') kill(M112_KILL_STR, nullptr, true); break;
case '0': if (command[1] == '4' && command[2] == '1') quickstop_stepper(); break;
}
#endif
);
}
else
process_stream_char(serial_char, serial_input_state[i], serial_line_buffer[i], serial_count[i]);
} // for NUM_SERIAL
#if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
last_command_time = ms;
#endif
// Add the command to the queue
_enqueue(serial_line_buffer[i], true
#if HAS_MULTI_SERIAL
, i
#endif
);
}
else
process_stream_char(serial_char, serial_input_state[i], serial_line_buffer[i], serial_count[i]);
} // char_count loop
} // NUM_SERIAL loop
} // queue has space, serial has data
}