Multi-host support
This commit is contained in:
committed by
Scott Lahteine
parent
dabb75034c
commit
f7efac57b7
@ -24,25 +24,41 @@
|
||||
#include "../../module/configuration_store.h"
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#if NUM_SERIAL > 1
|
||||
#include "../../gcode/queue.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* M500: Store settings in EEPROM
|
||||
*/
|
||||
void GcodeSuite::M500() {
|
||||
(void)settings.save();
|
||||
(void)settings.save(
|
||||
#if ENABLED(EEPROM_CHITCHAT) && NUM_SERIAL > 1
|
||||
command_queue_port[cmd_queue_index_r]
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* M501: Read settings from EEPROM
|
||||
*/
|
||||
void GcodeSuite::M501() {
|
||||
(void)settings.load();
|
||||
(void)settings.load(
|
||||
#if ENABLED(EEPROM_SETTINGS) && ENABLED(EEPROM_CHITCHAT) && NUM_SERIAL > 1
|
||||
command_queue_port[cmd_queue_index_r]
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* M502: Revert to default settings
|
||||
*/
|
||||
void GcodeSuite::M502() {
|
||||
(void)settings.reset();
|
||||
(void)settings.reset(
|
||||
#if ENABLED(EEPROM_CHITCHAT) && NUM_SERIAL > 1
|
||||
command_queue_port[cmd_queue_index_r]
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
#if DISABLED(DISABLE_M503)
|
||||
@ -51,7 +67,11 @@ void GcodeSuite::M502() {
|
||||
* M503: print settings currently in memory
|
||||
*/
|
||||
void GcodeSuite::M503() {
|
||||
(void)settings.report(parser.seen('S') && !parser.value_bool());
|
||||
(void)settings.report(parser.seen('S') && !parser.value_bool()
|
||||
#if NUM_SERIAL > 1
|
||||
, command_queue_port[cmd_queue_index_r]
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
#endif // !DISABLE_M503
|
||||
|
@ -79,21 +79,21 @@ static void drv_status_print_hex(const char name[], const uint32_t drv_status) {
|
||||
SERIAL_ECHO(name);
|
||||
SERIAL_ECHOPGM(" = 0x");
|
||||
for(int B=24; B>=8; B-=8){
|
||||
MYSERIAL.print((drv_status>>(B+4))&0xF, HEX);
|
||||
MYSERIAL.print((drv_status>>B)&0xF, HEX);
|
||||
MYSERIAL.print(':');
|
||||
SERIAL_PRINT((drv_status>>(B+4))&0xF, HEX);
|
||||
SERIAL_PRINT((drv_status>>B)&0xF, HEX);
|
||||
SERIAL_CHAR(':');
|
||||
}
|
||||
MYSERIAL.print((drv_status>>4)&0xF, HEX);
|
||||
MYSERIAL.print((drv_status)&0xF, HEX);
|
||||
SERIAL_PRINT((drv_status>>4)&0xF, HEX);
|
||||
SERIAL_PRINT((drv_status)&0xF, HEX);
|
||||
SERIAL_EOL();
|
||||
}
|
||||
|
||||
#if ENABLED(HAVE_TMC2130)
|
||||
static void tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) {
|
||||
switch(i) {
|
||||
case TMC_PWM_SCALE: MYSERIAL.print(st.PWM_SCALE(), DEC); break;
|
||||
case TMC_PWM_SCALE: SERIAL_PRINT(st.PWM_SCALE(), DEC); break;
|
||||
case TMC_TSTEP: SERIAL_ECHO(st.TSTEP()); break;
|
||||
case TMC_SGT: MYSERIAL.print(st.sgt(), DEC); break;
|
||||
case TMC_SGT: SERIAL_PRINT(st.sgt(), DEC); break;
|
||||
case TMC_STEALTHCHOP: serialprintPGM(st.stealthChop() ? PSTR("true") : PSTR("false")); break;
|
||||
default: break;
|
||||
}
|
||||
@ -101,7 +101,7 @@ static void drv_status_print_hex(const char name[], const uint32_t drv_status) {
|
||||
static void tmc_parse_drv_status(TMC2130Stepper &st, const TMC_drv_status_enum i) {
|
||||
switch(i) {
|
||||
case TMC_STALLGUARD: if (st.stallguard()) SERIAL_ECHOPGM("X"); break;
|
||||
case TMC_SG_RESULT: MYSERIAL.print(st.sg_result(), DEC); break;
|
||||
case TMC_SG_RESULT: SERIAL_PRINT(st.sg_result(), DEC); break;
|
||||
case TMC_FSACTIVE: if (st.fsactive()) SERIAL_ECHOPGM("X"); break;
|
||||
default: break;
|
||||
}
|
||||
@ -113,10 +113,10 @@ static void drv_status_print_hex(const char name[], const uint32_t drv_status) {
|
||||
case TMC_TSTEP: {
|
||||
uint32_t data = 0;
|
||||
st.TSTEP(&data);
|
||||
MYSERIAL.print(data);
|
||||
SERIAL_PROTOCOL(data);
|
||||
break;
|
||||
}
|
||||
case TMC_PWM_SCALE: MYSERIAL.print(st.pwm_scale_sum(), DEC); break;
|
||||
case TMC_PWM_SCALE: SERIAL_PRINT(st.pwm_scale_sum(), DEC); break;
|
||||
case TMC_STEALTHCHOP: serialprintPGM(st.stealth() ? PSTR("true") : PSTR("false")); break;
|
||||
case TMC_S2VSA: if (st.s2vsa()) SERIAL_ECHOPGM("X"); break;
|
||||
case TMC_S2VSB: if (st.s2vsb()) SERIAL_ECHOPGM("X"); break;
|
||||
@ -140,18 +140,18 @@ static void tmc_status(TMC &st, TMC_AxisEnum axis, const TMC_debug_enum i, const
|
||||
case TMC_CODES: SERIAL_ECHO(extended_axis_codes[axis]); break;
|
||||
case TMC_ENABLED: serialprintPGM(st.isEnabled() ? PSTR("true") : PSTR("false")); break;
|
||||
case TMC_CURRENT: SERIAL_ECHO(st.getCurrent()); break;
|
||||
case TMC_RMS_CURRENT: MYSERIAL.print(st.rms_current()); break;
|
||||
case TMC_MAX_CURRENT: MYSERIAL.print((float)st.rms_current()*1.41, 0); break;
|
||||
case TMC_RMS_CURRENT: SERIAL_PROTOCOL(st.rms_current()); break;
|
||||
case TMC_MAX_CURRENT: SERIAL_PRINT((float)st.rms_current()*1.41, 0); break;
|
||||
case TMC_IRUN:
|
||||
MYSERIAL.print(st.irun(), DEC);
|
||||
SERIAL_PRINT(st.irun(), DEC);
|
||||
SERIAL_ECHOPGM("/31");
|
||||
break;
|
||||
case TMC_IHOLD:
|
||||
MYSERIAL.print(st.ihold(), DEC);
|
||||
SERIAL_PRINT(st.ihold(), DEC);
|
||||
SERIAL_ECHOPGM("/31");
|
||||
break;
|
||||
case TMC_CS_ACTUAL:
|
||||
MYSERIAL.print(st.cs_actual(), DEC);
|
||||
SERIAL_PRINT(st.cs_actual(), DEC);
|
||||
SERIAL_ECHOPGM("/31");
|
||||
break;
|
||||
|
||||
@ -170,10 +170,10 @@ static void tmc_status(TMC &st, TMC_AxisEnum axis, const TMC_debug_enum i, const
|
||||
break;
|
||||
case TMC_OTPW: serialprintPGM(st.otpw() ? PSTR("true") : PSTR("false")); break;
|
||||
case TMC_OTPW_TRIGGERED: serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false")); break;
|
||||
case TMC_TOFF: MYSERIAL.print(st.toff(), DEC); break;
|
||||
case TMC_TBL: MYSERIAL.print(st.blank_time(), DEC); break;
|
||||
case TMC_HEND: MYSERIAL.print(st.hysterisis_end(), DEC); break;
|
||||
case TMC_HSTRT: MYSERIAL.print(st.hysterisis_start(), DEC); break;
|
||||
case TMC_TOFF: SERIAL_PRINT(st.toff(), DEC); break;
|
||||
case TMC_TBL: SERIAL_PRINT(st.blank_time(), DEC); break;
|
||||
case TMC_HEND: SERIAL_PRINT(st.hysterisis_end(), DEC); break;
|
||||
case TMC_HSTRT: SERIAL_PRINT(st.hysterisis_start(), DEC); break;
|
||||
default: tmc_status(st, i); break;
|
||||
}
|
||||
}
|
||||
@ -189,7 +189,7 @@ static void tmc_parse_drv_status(TMC &st, TMC_AxisEnum axis, const TMC_drv_statu
|
||||
case TMC_S2GA: if (st.s2ga()) SERIAL_ECHOPGM("X"); break;
|
||||
case TMC_DRV_OTPW: if (st.otpw()) SERIAL_ECHOPGM("X"); break;
|
||||
case TMC_OT: if (st.ot()) SERIAL_ECHOPGM("X"); break;
|
||||
case TMC_DRV_CS_ACTUAL: MYSERIAL.print(st.cs_actual(), DEC); break;
|
||||
case TMC_DRV_CS_ACTUAL: SERIAL_PRINT(st.cs_actual(), DEC); break;
|
||||
case TMC_DRV_STATUS_HEX:drv_status_print_hex(extended_axis_codes[axis], st.DRV_STATUS()); break;
|
||||
default: tmc_parse_drv_status(st, i); break;
|
||||
}
|
||||
|
@ -23,6 +23,10 @@
|
||||
#include "../gcode.h"
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#if NUM_SERIAL > 1
|
||||
#include "../../gcode/queue.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(EXTENDED_CAPABILITIES_REPORT)
|
||||
static void cap_line(const char * const name, bool ena=false) {
|
||||
SERIAL_PROTOCOLPGM("Cap:");
|
||||
@ -36,7 +40,14 @@
|
||||
* M115: Capabilities string
|
||||
*/
|
||||
void GcodeSuite::M115() {
|
||||
SERIAL_PROTOCOLLNPGM(MSG_M115_REPORT);
|
||||
#if NUM_SERIAL > 1
|
||||
const int8_t port = command_queue_port[cmd_queue_index_r];
|
||||
#define CAPLINE(STR,...) cap_line(PSTR(STR), port, __VA_ARGS__)
|
||||
#else
|
||||
#define CAPLINE(STR,...) cap_line(PSTR(STR), __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
SERIAL_PROTOCOLLNPGM_P(port, MSG_M115_REPORT);
|
||||
|
||||
#if ENABLED(EXTENDED_CAPABILITIES_REPORT)
|
||||
|
||||
|
@ -32,6 +32,10 @@
|
||||
#include "../libs/hex_print_routines.h"
|
||||
#endif
|
||||
|
||||
#if NUM_SERIAL > 1
|
||||
#include "queue.h"
|
||||
#endif
|
||||
|
||||
// Must be declared for allocation and to satisfy the linker
|
||||
// Zero values need no initialization.
|
||||
|
||||
@ -265,10 +269,13 @@ void GCodeParser::parse(char *p) {
|
||||
#endif // CNC_COORDINATE_SYSTEMS
|
||||
|
||||
void GCodeParser::unknown_command_error() {
|
||||
SERIAL_ECHO_START();
|
||||
SERIAL_ECHOPAIR(MSG_UNKNOWN_COMMAND, command_ptr);
|
||||
SERIAL_CHAR('"');
|
||||
SERIAL_EOL();
|
||||
#if NUM_SERIAL > 1
|
||||
const int16_t port = command_queue_port[cmd_queue_index_r];
|
||||
#endif
|
||||
SERIAL_ECHO_START_P(port);
|
||||
SERIAL_ECHOPAIR_P(port, MSG_UNKNOWN_COMMAND, command_ptr);
|
||||
SERIAL_CHAR_P(port, '"');
|
||||
SERIAL_EOL_P(port);
|
||||
}
|
||||
|
||||
#if ENABLED(DEBUG_GCODE_PARSER)
|
||||
|
@ -58,12 +58,19 @@ uint8_t commands_in_queue = 0, // Count of commands in the queue
|
||||
|
||||
char command_queue[BUFSIZE][MAX_CMD_SIZE];
|
||||
|
||||
/*
|
||||
* The port that the command was received on
|
||||
*/
|
||||
#if NUM_SERIAL > 1
|
||||
int16_t command_queue_port[BUFSIZE];
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Serial command injection
|
||||
*/
|
||||
|
||||
// Number of characters read in the current line of serial input
|
||||
static int serial_count = 0;
|
||||
static int serial_count[NUM_SERIAL] = { 0 };
|
||||
|
||||
bool send_ok[BUFSIZE];
|
||||
|
||||
@ -90,8 +97,15 @@ void clear_command_queue() {
|
||||
/**
|
||||
* Once a new command is in the ring buffer, call this to commit it
|
||||
*/
|
||||
inline void _commit_command(bool say_ok) {
|
||||
inline void _commit_command(bool say_ok
|
||||
#if NUM_SERIAL > 1
|
||||
, int16_t port = -1
|
||||
#endif
|
||||
) {
|
||||
send_ok[cmd_queue_index_w] = say_ok;
|
||||
#if NUM_SERIAL > 1
|
||||
command_queue_port[cmd_queue_index_w] = port;
|
||||
#endif
|
||||
if (++cmd_queue_index_w >= BUFSIZE) cmd_queue_index_w = 0;
|
||||
commands_in_queue++;
|
||||
}
|
||||
@ -101,10 +115,18 @@ inline void _commit_command(bool say_ok) {
|
||||
* Return true if the command was successfully added.
|
||||
* Return false for a full buffer, or if the 'command' is a comment.
|
||||
*/
|
||||
inline bool _enqueuecommand(const char* cmd, bool say_ok/*=false*/) {
|
||||
inline bool _enqueuecommand(const char* cmd, bool say_ok
|
||||
#if NUM_SERIAL > 1
|
||||
, int16_t port = -1
|
||||
#endif
|
||||
) {
|
||||
if (*cmd == ';' || commands_in_queue >= BUFSIZE) return false;
|
||||
strcpy(command_queue[cmd_queue_index_w], cmd);
|
||||
_commit_command(say_ok);
|
||||
_commit_command(say_ok
|
||||
#if NUM_SERIAL > 1
|
||||
, port
|
||||
#endif
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -178,21 +200,25 @@ void enqueue_and_echo_commands_P(const char * const pgcode) {
|
||||
* B<int> Block queue space remaining
|
||||
*/
|
||||
void ok_to_send() {
|
||||
#if NUM_SERIAL > 1
|
||||
const int16_t port = command_queue_port[cmd_queue_index_r];
|
||||
if (port < 0) return;
|
||||
#endif
|
||||
gcode.refresh_cmd_timeout();
|
||||
if (!send_ok[cmd_queue_index_r]) return;
|
||||
SERIAL_PROTOCOLPGM(MSG_OK);
|
||||
SERIAL_PROTOCOLPGM_P(port, MSG_OK);
|
||||
#if ENABLED(ADVANCED_OK)
|
||||
char* p = command_queue[cmd_queue_index_r];
|
||||
if (*p == 'N') {
|
||||
SERIAL_PROTOCOL(' ');
|
||||
SERIAL_ECHO(*p++);
|
||||
SERIAL_PROTOCOL_P(port, ' ');
|
||||
SERIAL_ECHO_P(port, *p++);
|
||||
while (NUMERIC_SIGNED(*p))
|
||||
SERIAL_ECHO(*p++);
|
||||
SERIAL_ECHO_P(port, *p++);
|
||||
}
|
||||
SERIAL_PROTOCOLPGM(" P"); SERIAL_PROTOCOL(int(BLOCK_BUFFER_SIZE - planner.movesplanned() - 1));
|
||||
SERIAL_PROTOCOLPGM(" B"); SERIAL_PROTOCOL(BUFSIZE - commands_in_queue);
|
||||
SERIAL_PROTOCOLPGM_P(port, " P"); SERIAL_PROTOCOL_P(port, int(BLOCK_BUFFER_SIZE - planner.movesplanned() - 1));
|
||||
SERIAL_PROTOCOLPGM_P(port, " B"); SERIAL_PROTOCOL_P(port, BUFSIZE - commands_in_queue);
|
||||
#endif
|
||||
SERIAL_EOL();
|
||||
SERIAL_EOL_P(port);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -200,20 +226,39 @@ void ok_to_send() {
|
||||
* indicate that a command needs to be re-sent.
|
||||
*/
|
||||
void flush_and_request_resend() {
|
||||
//char command_queue[cmd_queue_index_r][100]="Resend:";
|
||||
MYSERIAL.flush();
|
||||
SERIAL_PROTOCOLPGM(MSG_RESEND);
|
||||
SERIAL_PROTOCOLLN(gcode_LastN + 1);
|
||||
ok_to_send();
|
||||
#if NUM_SERIAL > 1
|
||||
const int16_t port = command_queue_port[cmd_queue_index_r];
|
||||
if (port < 0) return;
|
||||
#endif
|
||||
SERIAL_FLUSH_P(port);
|
||||
SERIAL_PROTOCOLPGM_P(port, MSG_RESEND);
|
||||
SERIAL_PROTOCOLLN_P(port, gcode_LastN + 1);
|
||||
}
|
||||
|
||||
void gcode_line_error(const char* err, bool doFlush = true) {
|
||||
SERIAL_ERROR_START();
|
||||
serialprintPGM(err);
|
||||
SERIAL_ERRORLN(gcode_LastN);
|
||||
//Serial.println(gcode_N);
|
||||
if (doFlush) flush_and_request_resend();
|
||||
serial_count = 0;
|
||||
void gcode_line_error(const char* err, uint8_t port) {
|
||||
SERIAL_ERROR_START_P(port);
|
||||
serialprintPGM_P(port, err);
|
||||
SERIAL_ERRORLN_P(port, gcode_LastN);
|
||||
flush_and_request_resend();
|
||||
serial_count[port] = 0;
|
||||
}
|
||||
|
||||
static bool serial_data_available() {
|
||||
return (MYSERIAL0.available() ? true :
|
||||
#if NUM_SERIAL > 1
|
||||
MYSERIAL1.available() ? true :
|
||||
#endif
|
||||
false);
|
||||
}
|
||||
|
||||
static int read_serial(const int index) {
|
||||
switch (index) {
|
||||
case 0: return MYSERIAL0.read();
|
||||
#if NUM_SERIAL > 1
|
||||
case 1: return MYSERIAL1.read();
|
||||
#endif
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -222,15 +267,15 @@ void gcode_line_error(const char* err, bool doFlush = true) {
|
||||
* left on the serial port.
|
||||
*/
|
||||
inline void get_serial_commands() {
|
||||
static char serial_line_buffer[MAX_CMD_SIZE];
|
||||
static bool serial_comment_mode = false;
|
||||
static char serial_line_buffer[NUM_SERIAL][MAX_CMD_SIZE];
|
||||
static bool serial_comment_mode[NUM_SERIAL] = { false };
|
||||
|
||||
// If the command buffer is empty for too long,
|
||||
// send "wait" to indicate Marlin is still waiting.
|
||||
#if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
|
||||
static millis_t last_command_time = 0;
|
||||
const millis_t ms = millis();
|
||||
if (commands_in_queue == 0 && !MYSERIAL.available() && ELAPSED(ms, last_command_time + NO_TIMEOUTS)) {
|
||||
if (commands_in_queue == 0 && !serial_data_available() && ELAPSED(ms, last_command_time + NO_TIMEOUTS)) {
|
||||
SERIAL_ECHOLNPGM(MSG_WAIT);
|
||||
last_command_time = ms;
|
||||
}
|
||||
@ -239,110 +284,117 @@ inline void get_serial_commands() {
|
||||
/**
|
||||
* Loop while serial characters are incoming and the queue is not full
|
||||
*/
|
||||
int c;
|
||||
while (commands_in_queue < BUFSIZE && (c = MYSERIAL.read()) >= 0) {
|
||||
char serial_char = c;
|
||||
while (commands_in_queue < BUFSIZE && serial_data_available()) {
|
||||
for (uint8_t i = 0; i < NUM_SERIAL; ++i) {
|
||||
int c;
|
||||
if ((c = read_serial(i)) < 0) continue;
|
||||
|
||||
/**
|
||||
* If the character ends the line
|
||||
*/
|
||||
if (serial_char == '\n' || serial_char == '\r') {
|
||||
char serial_char = c;
|
||||
|
||||
serial_comment_mode = false; // end of line == end of comment
|
||||
/**
|
||||
* If the character ends the line
|
||||
*/
|
||||
if (serial_char == '\n' || serial_char == '\r') {
|
||||
|
||||
if (!serial_count) continue; // Skip empty lines
|
||||
serial_comment_mode[i] = false; // end of line == end of comment
|
||||
|
||||
serial_line_buffer[serial_count] = 0; // Terminate string
|
||||
serial_count = 0; // Reset buffer
|
||||
if (!serial_count[i]) continue; // Skip empty lines
|
||||
|
||||
char* command = serial_line_buffer;
|
||||
serial_line_buffer[i][serial_count[i]] = 0; // Terminate string
|
||||
serial_count[i] = 0; // Reset buffer
|
||||
|
||||
while (*command == ' ') command++; // Skip leading spaces
|
||||
char *npos = (*command == 'N') ? command : NULL; // 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 : NULL; // Require the N parameter to start the line
|
||||
|
||||
bool M110 = strstr_P(command, PSTR("M110")) != NULL;
|
||||
if (npos) {
|
||||
|
||||
if (M110) {
|
||||
char* n2pos = strchr(command + 4, 'N');
|
||||
if (n2pos) npos = n2pos;
|
||||
}
|
||||
bool M110 = strstr_P(command, PSTR("M110")) != NULL;
|
||||
|
||||
gcode_N = strtol(npos + 1, NULL, 10);
|
||||
if (M110) {
|
||||
char* n2pos = strchr(command + 4, 'N');
|
||||
if (n2pos) npos = n2pos;
|
||||
}
|
||||
|
||||
if (gcode_N != gcode_LastN + 1 && !M110) {
|
||||
gcode_line_error(PSTR(MSG_ERR_LINE_NO));
|
||||
return;
|
||||
}
|
||||
gcode_N = strtol(npos + 1, NULL, 10);
|
||||
|
||||
char *apos = strrchr(command, '*');
|
||||
if (apos) {
|
||||
uint8_t checksum = 0, count = uint8_t(apos - command);
|
||||
while (count) checksum ^= command[--count];
|
||||
if (strtol(apos + 1, NULL, 10) != checksum) {
|
||||
gcode_line_error(PSTR(MSG_ERR_CHECKSUM_MISMATCH));
|
||||
if (gcode_N != gcode_LastN + 1 && !M110) {
|
||||
gcode_line_error(PSTR(MSG_ERR_LINE_NO), i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
gcode_line_error(PSTR(MSG_ERR_NO_CHECKSUM));
|
||||
return;
|
||||
|
||||
char *apos = strrchr(command, '*');
|
||||
if (apos) {
|
||||
uint8_t checksum = 0, count = uint8_t(apos - command);
|
||||
while (count) checksum ^= command[--count];
|
||||
if (strtol(apos + 1, NULL, 10) != checksum) {
|
||||
gcode_line_error(PSTR(MSG_ERR_CHECKSUM_MISMATCH), i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
gcode_line_error(PSTR(MSG_ERR_NO_CHECKSUM), i);
|
||||
return;
|
||||
}
|
||||
|
||||
gcode_LastN = gcode_N;
|
||||
}
|
||||
|
||||
gcode_LastN = gcode_N;
|
||||
}
|
||||
|
||||
// Movement commands alert when stopped
|
||||
if (IsStopped()) {
|
||||
char* gpos = strchr(command, 'G');
|
||||
if (gpos) {
|
||||
const int codenum = strtol(gpos + 1, NULL, 10);
|
||||
switch (codenum) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
|
||||
LCD_MESSAGEPGM(MSG_STOPPED);
|
||||
break;
|
||||
// Movement commands alert when stopped
|
||||
if (IsStopped()) {
|
||||
char* gpos = strchr(command, 'G');
|
||||
if (gpos) {
|
||||
const int codenum = strtol(gpos + 1, NULL, 10);
|
||||
switch (codenum) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
SERIAL_ERRORLNPGM_P(i, MSG_ERR_STOPPED);
|
||||
LCD_MESSAGEPGM(MSG_STOPPED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if DISABLED(EMERGENCY_PARSER)
|
||||
// If command was e-stop process now
|
||||
if (strcmp(command, "M108") == 0) {
|
||||
wait_for_heatup = false;
|
||||
#if ENABLED(ULTIPANEL)
|
||||
wait_for_user = false;
|
||||
#if DISABLED(EMERGENCY_PARSER)
|
||||
// If command was e-stop process now
|
||||
if (strcmp(command, "M108") == 0) {
|
||||
wait_for_heatup = false;
|
||||
#if ENABLED(ULTIPANEL)
|
||||
wait_for_user = false;
|
||||
#endif
|
||||
}
|
||||
if (strcmp(command, "M112") == 0) kill(PSTR(MSG_KILLED));
|
||||
if (strcmp(command, "M410") == 0) { quickstop_stepper(); }
|
||||
#endif
|
||||
|
||||
#if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
|
||||
last_command_time = ms;
|
||||
#endif
|
||||
|
||||
// Add the command to the queue
|
||||
_enqueuecommand(serial_line_buffer[i], true
|
||||
#if NUM_SERIAL > 1
|
||||
, i
|
||||
#endif
|
||||
}
|
||||
if (strcmp(command, "M112") == 0) kill(PSTR(MSG_KILLED));
|
||||
if (strcmp(command, "M410") == 0) { quickstop_stepper(); }
|
||||
#endif
|
||||
|
||||
#if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0
|
||||
last_command_time = ms;
|
||||
#endif
|
||||
|
||||
// Add the command to the queue
|
||||
_enqueuecommand(serial_line_buffer, true);
|
||||
}
|
||||
else if (serial_count >= MAX_CMD_SIZE - 1) {
|
||||
// Keep fetching, but ignore normal characters beyond the max length
|
||||
// The command will be injected when EOL is reached
|
||||
}
|
||||
else if (serial_char == '\\') { // Handle escapes
|
||||
// if we have one more character, copy it over
|
||||
if ((c = MYSERIAL.read()) >= 0 && !serial_comment_mode)
|
||||
serial_line_buffer[serial_count++] = serial_char;
|
||||
}
|
||||
else { // it's not a newline, carriage return or escape char
|
||||
if (serial_char == ';') serial_comment_mode = true;
|
||||
if (!serial_comment_mode) serial_line_buffer[serial_count++] = serial_char;
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
else if (serial_count[i] >= MAX_CMD_SIZE - 1) {
|
||||
// Keep fetching, but ignore normal characters beyond the max length
|
||||
// The command will be injected when EOL is reached
|
||||
}
|
||||
else if (serial_char == '\\') { // Handle escapes
|
||||
// if we have one more character, copy it over
|
||||
if ((c = read_serial(i)) >= 0 && !serial_comment_mode[i])
|
||||
serial_line_buffer[i][serial_count[i]++] = serial_char;
|
||||
}
|
||||
else { // it's not a newline, carriage return or escape char
|
||||
if (serial_char == ';') serial_comment_mode[i] = true;
|
||||
if (!serial_comment_mode[i]) serial_line_buffer[i][serial_count[i]++] = serial_char;
|
||||
}
|
||||
} // for NUM_SERIAL
|
||||
} // queue has space, serial has data
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,13 @@ extern uint8_t commands_in_queue, // Count of commands in the queue
|
||||
|
||||
extern char command_queue[BUFSIZE][MAX_CMD_SIZE];
|
||||
|
||||
/*
|
||||
* The port that the command was received on
|
||||
*/
|
||||
#if NUM_SERIAL > 1
|
||||
extern int16_t command_queue_port[BUFSIZE];
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initialization of queue for setup()
|
||||
*/
|
||||
|
@ -34,13 +34,25 @@
|
||||
#include "../queue.h"
|
||||
#endif
|
||||
|
||||
#if NUM_SERIAL > 1
|
||||
#include "../../gcode/queue.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* M20: List SD card to serial output
|
||||
*/
|
||||
void GcodeSuite::M20() {
|
||||
SERIAL_PROTOCOLLNPGM(MSG_BEGIN_FILE_LIST);
|
||||
card.ls();
|
||||
SERIAL_PROTOCOLLNPGM(MSG_END_FILE_LIST);
|
||||
#if NUM_SERIAL > 1
|
||||
const int16_t port = command_queue_port[cmd_queue_index_r];
|
||||
#endif
|
||||
|
||||
SERIAL_PROTOCOLLNPGM_P(port, MSG_BEGIN_FILE_LIST);
|
||||
card.ls(
|
||||
#if NUM_SERIAL > 1
|
||||
port
|
||||
#endif
|
||||
);
|
||||
SERIAL_PROTOCOLLNPGM_P(port, MSG_END_FILE_LIST);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,7 +109,13 @@ void GcodeSuite::M26() {
|
||||
/**
|
||||
* M27: Get SD Card status
|
||||
*/
|
||||
void GcodeSuite::M27() { card.getStatus(); }
|
||||
void GcodeSuite::M27() {
|
||||
card.getStatus(
|
||||
#if NUM_SERIAL > 1
|
||||
command_queue_port[cmd_queue_index_r]
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* M28: Start SD Write
|
||||
@ -164,7 +182,11 @@ void GcodeSuite::M32() {
|
||||
* /Miscellaneous/Armchair/Armchair.gcode
|
||||
*/
|
||||
void GcodeSuite::M33() {
|
||||
card.printLongPath(parser.string_arg);
|
||||
card.printLongPath(parser.string_arg
|
||||
#if NUM_SERIAL > 1
|
||||
, command_queue_port[cmd_queue_index_r]
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
#endif // LONG_FILENAME_HOST_SUPPORT
|
||||
|
@ -26,15 +26,22 @@
|
||||
#include "../../libs/duration_t.h"
|
||||
#include "../../lcd/ultralcd.h"
|
||||
|
||||
#if NUM_SERIAL > 1
|
||||
#include "../../gcode/queue.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* M31: Get the time since the start of SD Print (or last M109)
|
||||
*/
|
||||
void GcodeSuite::M31() {
|
||||
#if NUM_SERIAL > 1
|
||||
const int16_t port = command_queue_port[cmd_queue_index_r];
|
||||
#endif
|
||||
char buffer[21];
|
||||
duration_t elapsed = print_job_timer.duration();
|
||||
elapsed.toString(buffer);
|
||||
lcd_setstatus(buffer);
|
||||
|
||||
SERIAL_ECHO_START();
|
||||
SERIAL_ECHOLNPAIR("Print time: ", buffer);
|
||||
SERIAL_ECHO_START_P(port);
|
||||
SERIAL_ECHOLNPAIR_P(port, "Print time: ", buffer);
|
||||
}
|
||||
|
@ -23,19 +23,31 @@
|
||||
#include "../gcode.h"
|
||||
#include "../../module/temperature.h"
|
||||
|
||||
#if NUM_SERIAL > 1
|
||||
#include "../../gcode/queue.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* M105: Read hot end and bed temperature
|
||||
*/
|
||||
void GcodeSuite::M105() {
|
||||
if (get_target_extruder_from_command()) return;
|
||||
|
||||
#if HAS_TEMP_HOTEND || HAS_TEMP_BED
|
||||
SERIAL_PROTOCOLPGM(MSG_OK);
|
||||
thermalManager.print_heaterstates();
|
||||
#else // !HAS_TEMP_HOTEND && !HAS_TEMP_BED
|
||||
SERIAL_ERROR_START();
|
||||
SERIAL_ERRORLNPGM(MSG_ERR_NO_THERMISTORS);
|
||||
#if NUM_SERIAL > 1
|
||||
const int16_t port = command_queue_port[cmd_queue_index_r];
|
||||
#endif
|
||||
|
||||
SERIAL_EOL();
|
||||
#if HAS_TEMP_HOTEND || HAS_TEMP_BED
|
||||
SERIAL_PROTOCOLPGM_P(port, MSG_OK);
|
||||
thermalManager.print_heaterstates(
|
||||
#if NUM_SERIAL > 1
|
||||
port
|
||||
#endif
|
||||
);
|
||||
#else // !HAS_TEMP_HOTEND && !HAS_TEMP_BED
|
||||
SERIAL_ERROR_START_P(port);
|
||||
SERIAL_ERRORLNPGM_P(port, MSG_ERR_NO_THERMISTORS);
|
||||
#endif
|
||||
|
||||
SERIAL_EOL_P(port);
|
||||
}
|
||||
|
Reference in New Issue
Block a user