Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit d74e562
Merge: a81ad68 5d35d76
Author: Scott Mudge <[email protected]>
Date:   Fri May 21 09:40:20 2021 -0400

    Merge branch 'MK3_sm_MeatPack' into sm_gcode_meatpacking

commit a81ad68
Merge: e276e53 f5ca799
Author: Scott Mudge <[email protected]>
Date:   Fri May 21 09:35:45 2021 -0400

    Merge remote-tracking branch 'prusa3d/MK3' into sm_gcode_meatpacking

commit 5d35d76
Author: Scott Mudge <[email protected]>
Date:   Tue Jan 26 13:06:19 2021 -0500

    * Fix strtod() -> strtod_noE() after merge.

commit c8b9d3d
Merge: 5f69ec5 c28e5a9
Author: Scott Mudge <[email protected]>
Date:   Tue Jan 26 10:04:40 2021 -0500

    Merge remote-tracking branch 'prusa3d/MK3' into MK3_sm_MeatPack

    Merge, fix conflict.

commit 5f69ec5
Author: Scott Mudge <[email protected]>
Date:   Mon Jan 25 12:00:06 2021 -0500

    Remove unused toggle command.

commit 820d67b
Author: Scott Mudge <[email protected]>
Date:   Sat Jan 23 03:21:03 2021 -0500

    Fixed filename case sensitivity... issue with Windows being case insensitive.

commit e276e53
Author: Scott Mudge <[email protected]>
Date:   Wed Jan 20 22:10:51 2021 -0500

    Update README.md

commit ce8fb56
Author: Scott Mudge <[email protected]>
Date:   Wed Jan 20 18:33:13 2021 -0500

    - remove volatile from lookup table.

commit 70dab3f
Merge: 18112f9 2a16ac3
Author: Scott Mudge <[email protected]>
Date:   Wed Jan 20 18:25:12 2021 -0500

    Merge branch 'MK3_sm_MeatPack' into sm_gcode_meatpacking

commit 18112f9
Author: Scott Mudge <[email protected]>
Date:   Wed Jan 20 15:00:29 2021 -0500

    Update README.md

commit 2a16ac3
Merge: b45d0ec ebf039c
Author: Scott Mudge <[email protected]>
Date:   Wed Jan 20 14:34:54 2021 -0500

    Merge branch 'MK3_sm_MeatPack_WhiteSpace' into MK3_sm_MeatPack

commit ebf039c
Author: Scott Mudge <[email protected]>
Date:   Sun Jan 17 18:36:23 2021 -0500

    Added custom strtod() method which excludes "E", to prevent errors parsing "E" commands in G1 codes.

commit f701f19
Merge: 3fb29f2 b71f1be
Author: Scott Mudge <[email protected]>
Date:   Sun Jan 17 11:02:39 2021 -0500

    Merge branch 'MK3' into MK3_sm_MeatPack_WhiteSpace

commit 3fb29f2
Author: Scott Mudge <[email protected]>
Date:   Sun Jan 17 11:02:06 2021 -0500

    testing.

commit 55d1141
Author: Scott Mudge <[email protected]>
Date:   Sat Jan 16 18:03:59 2021 -0500

    debugging.

commit b45d0ec
Author: Scott Mudge <[email protected]>
Date:   Fri Jan 15 08:47:13 2021 -0500

    Refactoring for whitespace omission and using 'E' instead of ' ' in lookup table.

commit 4bd80c6
Author: Scott Mudge <[email protected]>
Date:   Thu Jan 14 11:01:44 2021 -0500

    - Compatibility fix for older plugin version.

commit 4c2040c
Author: Scott Mudge <[email protected]>
Date:   Thu Jan 14 10:59:21 2021 -0500

    - Refactored configuration bytes.
    - Refactored config sync output.
    - Added support for whitespace omission.
    - Removed debug output unless preprocessor directive is enabled.

commit ef5922e
Author: Scott Mudge <[email protected]>
Date:   Tue Jan 12 10:53:56 2021 -0500

    General refactoring

    - Removed unneeded 'volatile' qualifiers.
    - Removed unused public interfaces.
    - Moved ENABLE_MEATPACK to Configuration.h
    - Corrected inlining with AVR-specific macro.

commit 567dfec
Author: Scott Mudge <[email protected]>
Date:   Sat Jan 9 18:48:11 2021 -0500

    * Fixed compiler switch/pre-processor directive to disable MeatPack.

commit 4e48717
Author: Scott Mudge <[email protected]>
Date:   Sat Jan 9 01:51:11 2021 -0500

    Reverting change to fix compiler warning. According to PR prusa3d#2901, this shouldn't be touched.

commit 9a66278
Author: Scott Mudge <[email protected]>
Date:   Sat Jan 9 00:01:29 2021 -0500

    * Revert formatting change.

commit 35ca6f4
Author: Scott Mudge <[email protected]>
Date:   Sat Jan 9 00:00:07 2021 -0500

    * Revert formatting back to that used by Prusa.

commit e562018
Author: Scott Mudge <[email protected]>
Date:   Thu Jan 7 22:08:52 2021 -0500

    Update README.md

commit 900bd41
Author: Scott Mudge <[email protected]>
Date:   Thu Jan 7 22:04:08 2021 -0500

    Update README.md

commit a76fdaa
Author: Scott Mudge <[email protected]>
Date:   Thu Jan 7 21:54:26 2021 -0500

    Update README.md

commit 62c3a45
Author: Scott Mudge <[email protected]>
Date:   Thu Jan 7 21:52:53 2021 -0500

    Update README.md

commit beece1d
Author: Scott Mudge <[email protected]>
Date:   Thu Jan 7 13:29:30 2021 -0500

    Only send appropriate M73 response depending on what is active.

commit 061da4a
Author: Scott Mudge <[email protected]>
Date:   Thu Jan 7 13:25:05 2021 -0500

    a

commit 705b3b8
Author: Scott Mudge <[email protected]>
Date:   Thu Jan 7 13:24:38 2021 -0500

    .

commit 8a7f46b
Author: Scott Mudge <[email protected]>
Date:   Thu Jan 7 13:20:21 2021 -0500

    Undoing old changes.

commit f46fa15
Merge: 3efa1cb 0ed6b53
Author: Scott Mudge <[email protected]>
Date:   Thu Jan 7 13:17:06 2021 -0500

    Merge remote-tracking branch 'prusa3d/MK3_3.9.3' into sm_gcode_meatpacking

commit 3efa1cb
Author: Scott Mudge <[email protected]>
Date:   Tue Jan 5 02:22:51 2021 -0500

    Finished.

commit 4c8f13c
Author: Scott Mudge <[email protected]>
Date:   Sun Jan 3 00:03:14 2021 -0500

    First implementation.

    * Fixed pre-existing compiler warning.
    * Implemented meat-pack.
    * Added code to properly handle file seek in SD file check.
    * Added proper control code elsewhere.
  • Loading branch information
erik434 committed Feb 10, 2022
1 parent caca7bb commit e4de782
Show file tree
Hide file tree
Showing 8 changed files with 818 additions and 143 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ Firmware/Doc
/lang/text.sym
/lang/textaddr.txt
/build-env/
/Firmware/Firmware.vcxproj
/Firmware/Firmware.vcxproj*
/Firmware/Configuration_prusa_bckp.h
/Firmware/variants/printers.h
Firmware/.vs/
Configuration.tmp
config.tmp
3 changes: 3 additions & 0 deletions Firmware/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ extern PGM_P sPrinterName;
// This determines the communication speed of the printer
#define BAUDRATE 115200

// Enable g-code compression (see https://github.com/scottmudge/OctoPrint-MeatPack)
#define ENABLE_MEATPACK

// This enables the serial port associated to the Bluetooth interface
//#define BTENABLED // Enable BT interface on AT90USB devices

Expand Down
288 changes: 154 additions & 134 deletions Firmware/cmdqueue.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "cmdqueue.h"
#include "cardreader.h"
#include "ultralcd.h"
#include "meatpack.h"

extern bool Stopped;

Expand Down Expand Up @@ -394,147 +395,166 @@ void get_command()

// start of serial line processing loop
while (((MYSERIAL.available() > 0 && !saved_printing) || (MYSERIAL.available() > 0 && isPrintPaused)) && !cmdqueue_serial_disabled) { //is print is saved (crash detection or filament detection), dont process data from serial line

#ifdef ENABLE_MEATPACK
// MeatPack Changes
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const int rec = MYSERIAL.read();
if (rec < 0) continue;

mp_handle_rx_char((uint8_t)rec);
char c_res[2] = {0, 0};
const uint8_t char_count = mp_get_result_char(c_res);

for (uint8_t i = 0; i < char_count; ++i) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
char serial_char = c_res[i];
#else
char serial_char = MYSERIAL.read();
#endif

/* if (selectedSerialPort == 1)
{
selectedSerialPort = 0;
MYSERIAL.write(serial_char); // for debuging serial line 2 in farm_mode
selectedSerialPort = 1;
} */ //RP - removed
TimeSent = _millis();
TimeNow = _millis();

char serial_char = MYSERIAL.read();
/* if (selectedSerialPort == 1)
{
selectedSerialPort = 0;
MYSERIAL.write(serial_char); // for debuging serial line 2 in farm_mode
selectedSerialPort = 1;
} */ //RP - removed
TimeSent = _millis();
TimeNow = _millis();

if (serial_char < 0)
// Ignore extended ASCII characters. These characters have no meaning in the G-code apart from the file names
// and Marlin does not support such file names anyway.
// Serial characters with a highest bit set to 1 are generated when the USB cable is unplugged, leading
// to a hang-up of the print process from an SD card.
continue;
if(serial_char == '\n' ||
serial_char == '\r' ||
serial_count >= (MAX_CMD_SIZE - 1) )
{
if(!serial_count) { //if empty line
comment_mode = false; //for new command
return;
}
cmdbuffer[bufindw+serial_count+CMDHDRSIZE] = 0; //terminate string
if(!comment_mode){

gcode_N = 0;

// Line numbers must be first in buffer

if ((strstr(cmdbuffer+bufindw+CMDHDRSIZE, "PRUSA") == NULL) &&
(cmdbuffer[bufindw+CMDHDRSIZE] == 'N')) {

// Line number met. When sending a G-code over a serial line, each line may be stamped with its index,
// and Marlin tests, whether the successive lines are stamped with an increasing line number ID
gcode_N = (strtol(cmdbuffer+bufindw+CMDHDRSIZE+1, NULL, 10));
if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer+bufindw+CMDHDRSIZE, PSTR("M110")) == NULL) ) {
// M110 - set current line number.
// Line numbers not sent in succession.
SERIAL_ERROR_START;
SERIAL_ERRORRPGM(_n("Line Number is not Last Line Number+1, Last Line: "));////MSG_ERR_LINE_NO
SERIAL_ERRORLN(gcode_LastN);
//Serial.println(gcode_N);
FlushSerialRequestResend();
serial_count = 0;
return;
}

if((strchr_pointer = strchr(cmdbuffer+bufindw+CMDHDRSIZE, '*')) != NULL)
{
byte checksum = 0;
char *p = cmdbuffer+bufindw+CMDHDRSIZE;
while (p != strchr_pointer)
checksum = checksum^(*p++);
if (int(strtol(strchr_pointer+1, NULL, 10)) != int(checksum)) {
if (serial_char < 0)
// Ignore extended ASCII characters. These characters have no meaning in the G-code apart from the file names
// and Marlin does not support such file names anyway.
// Serial characters with a highest bit set to 1 are generated when the USB cable is unplugged, leading
// to a hang-up of the print process from an SD card.
continue;
if(serial_char == '\n' ||
serial_char == '\r' ||
serial_count >= (MAX_CMD_SIZE - 1) )
{
if(!serial_count) { //if empty line
comment_mode = false; //for new command
return;
}
cmdbuffer[bufindw+serial_count+CMDHDRSIZE] = 0; //terminate string
if(!comment_mode){

gcode_N = 0;

// Line numbers must be first in buffer

if ((strstr(cmdbuffer+bufindw+CMDHDRSIZE, "PRUSA") == NULL) &&
(cmdbuffer[bufindw+CMDHDRSIZE] == 'N')) {

// Line number met. When sending a G-code over a serial line, each line may be stamped with its index,
// and Marlin tests, whether the successive lines are stamped with an increasing line number ID
gcode_N = (strtol(cmdbuffer+bufindw+CMDHDRSIZE+1, NULL, 10));
if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer+bufindw+CMDHDRSIZE, PSTR("M110")) == NULL) ) {
// M110 - set current line number.
// Line numbers not sent in succession.
SERIAL_ERROR_START;
SERIAL_ERRORRPGM(_n("checksum mismatch, Last Line: "));////MSG_ERR_CHECKSUM_MISMATCH
SERIAL_ERRORRPGM(_n("Line Number is not Last Line Number+1, Last Line: "));////MSG_ERR_LINE_NO
SERIAL_ERRORLN(gcode_LastN);
//Serial.println(gcode_N);
FlushSerialRequestResend();
serial_count = 0;
return;
}
// If no errors, remove the checksum and continue parsing.
*strchr_pointer = 0;
}
else
{
SERIAL_ERROR_START;
SERIAL_ERRORRPGM(_n("No Checksum with line number, Last Line: "));////MSG_ERR_NO_CHECKSUM
SERIAL_ERRORLN(gcode_LastN);
FlushSerialRequestResend();
serial_count = 0;
return;
}

// Don't parse N again with code_seen('N')
cmdbuffer[bufindw + CMDHDRSIZE] = '$';
//if no errors, continue parsing
gcode_LastN = gcode_N;
}
// if we don't receive 'N' but still see '*'
if ((cmdbuffer[bufindw + CMDHDRSIZE] != 'N') && (cmdbuffer[bufindw + CMDHDRSIZE] != '$') && (strchr(cmdbuffer+bufindw+CMDHDRSIZE, '*') != NULL))
{

SERIAL_ERROR_START;
SERIAL_ERRORRPGM(_n("No Line Number with checksum, Last Line: "));////MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM
SERIAL_ERRORLN(gcode_LastN);
FlushSerialRequestResend();
serial_count = 0;
return;
}
if ((strchr_pointer = strchr(cmdbuffer+bufindw+CMDHDRSIZE, 'G')) != NULL) {
if (! IS_SD_PRINTING) {
usb_printing_counter = 10;
is_usb_printing = true;
}
if (Stopped == true) {
int gcode = strtol(strchr_pointer+1, NULL, 10);
if (gcode >= 0 && gcode <= 3) {
SERIAL_ERRORLNRPGM(MSG_ERR_STOPPED);
LCD_MESSAGERPGM(_T(MSG_STOPPED));
}
}
} // end of 'G' command

//If command was e-stop process now
if(strcmp(cmdbuffer+bufindw+CMDHDRSIZE, "M112") == 0)
kill(MSG_M112_KILL, 2);

// Store the current line into buffer, move to the next line.
// Store type of entry
cmdbuffer[bufindw] = gcode_N ? CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR : CMDBUFFER_CURRENT_TYPE_USB;
#ifdef CMDBUFFER_DEBUG
SERIAL_ECHO_START;
SERIAL_ECHOPGM("Storing a command line to buffer: ");
SERIAL_ECHO(cmdbuffer+bufindw+CMDHDRSIZE);
SERIAL_ECHOLNPGM("");
#endif /* CMDBUFFER_DEBUG */
bufindw += strlen(cmdbuffer+bufindw+CMDHDRSIZE) + (1 + CMDHDRSIZE);
if (bufindw == sizeof(cmdbuffer))
bufindw = 0;
++ buflen;
#ifdef CMDBUFFER_DEBUG
SERIAL_ECHOPGM("Number of commands in the buffer: ");
SERIAL_ECHO(buflen);
SERIAL_ECHOLNPGM("");
#endif /* CMDBUFFER_DEBUG */
} // end of 'not comment mode'
serial_count = 0; //clear buffer
// Don't call cmdqueue_could_enqueue_back if there are no characters waiting
// in the queue, as this function will reserve the memory.
if (MYSERIAL.available() == 0 || ! cmdqueue_could_enqueue_back(MAX_CMD_SIZE-1, true))
return;
} // end of "end of line" processing
else {
// Not an "end of line" symbol. Store the new character into a buffer.
if(serial_char == ';') comment_mode = true;
if(!comment_mode) cmdbuffer[bufindw+CMDHDRSIZE+serial_count++] = serial_char;
}

if((strchr_pointer = strchr(cmdbuffer+bufindw+CMDHDRSIZE, '*')) != NULL)
{
byte checksum = 0;
char *p = cmdbuffer+bufindw+CMDHDRSIZE;
while (p != strchr_pointer)
checksum = checksum^(*p++);
if (int(strtol(strchr_pointer+1, NULL, 10)) != int(checksum)) {
SERIAL_ERROR_START;
SERIAL_ERRORRPGM(_n("checksum mismatch, Last Line: "));////MSG_ERR_CHECKSUM_MISMATCH
SERIAL_ERRORLN(gcode_LastN);
FlushSerialRequestResend();
serial_count = 0;
return;
}
// If no errors, remove the checksum and continue parsing.
*strchr_pointer = 0;
}
else
{
SERIAL_ERROR_START;
SERIAL_ERRORRPGM(_n("No Checksum with line number, Last Line: "));////MSG_ERR_NO_CHECKSUM
SERIAL_ERRORLN(gcode_LastN);
FlushSerialRequestResend();
serial_count = 0;
return;
}

// Don't parse N again with code_seen('N')
cmdbuffer[bufindw + CMDHDRSIZE] = '$';
//if no errors, continue parsing
gcode_LastN = gcode_N;
}
// if we don't receive 'N' but still see '*'
if ((cmdbuffer[bufindw + CMDHDRSIZE] != 'N') && (cmdbuffer[bufindw + CMDHDRSIZE] != '$') && (strchr(cmdbuffer+bufindw+CMDHDRSIZE, '*') != NULL))
{

SERIAL_ERROR_START;
SERIAL_ERRORRPGM(_n("No Line Number with checksum, Last Line: "));////MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM
SERIAL_ERRORLN(gcode_LastN);
FlushSerialRequestResend();
serial_count = 0;
return;
}
if ((strchr_pointer = strchr(cmdbuffer+bufindw+CMDHDRSIZE, 'G')) != NULL) {
if (! IS_SD_PRINTING) {
usb_printing_counter = 10;
is_usb_printing = true;
}
if (Stopped == true) {
int gcode = strtol(strchr_pointer+1, NULL, 10);
if (gcode >= 0 && gcode <= 3) {
SERIAL_ERRORLNRPGM(MSG_ERR_STOPPED);
LCD_MESSAGERPGM(_T(MSG_STOPPED));
}
}
} // end of 'G' command

//If command was e-stop process now
if(strcmp(cmdbuffer+bufindw+CMDHDRSIZE, "M112") == 0)
kill(MSG_M112_KILL, 2);

// Store the current line into buffer, move to the next line.
// Store type of entry
cmdbuffer[bufindw] = gcode_N ? CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR : CMDBUFFER_CURRENT_TYPE_USB;
#ifdef CMDBUFFER_DEBUG
SERIAL_ECHO_START;
SERIAL_ECHOPGM("Storing a command line to buffer: ");
SERIAL_ECHO(cmdbuffer+bufindw+CMDHDRSIZE);
SERIAL_ECHOLNPGM("");
#endif /* CMDBUFFER_DEBUG */
bufindw += strlen(cmdbuffer+bufindw+CMDHDRSIZE) + (1 + CMDHDRSIZE);
if (bufindw == sizeof(cmdbuffer))
bufindw = 0;
++ buflen;
#ifdef CMDBUFFER_DEBUG
SERIAL_ECHOPGM("Number of commands in the buffer: ");
SERIAL_ECHO(buflen);
SERIAL_ECHOLNPGM("");
#endif /* CMDBUFFER_DEBUG */
} // end of 'not comment mode'
serial_count = 0; //clear buffer
// Don't call cmdqueue_could_enqueue_back if there are no characters waiting
// in the queue, as this function will reserve the memory.
if (MYSERIAL.available() == 0 || ! cmdqueue_could_enqueue_back(MAX_CMD_SIZE-1, true))
return;
} // end of "end of line" processing
else {
// Not an "end of line" symbol. Store the new character into a buffer.
if(serial_char == ';') comment_mode = true;
if(!comment_mode) cmdbuffer[bufindw+CMDHDRSIZE+serial_count++] = serial_char;
}
#ifdef ENABLE_MEATPACK
}
#endif
} // end of serial line processing loop

if(farm_mode){
Expand Down
24 changes: 17 additions & 7 deletions Firmware/cmdqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,32 @@ extern void repeatcommand_front();
extern void get_command();
extern uint16_t cmdqueue_calc_sd_length();


#if defined(__cplusplus)
extern "C" {
#endif
extern double strtod_noE(const char* nptr, char** endptr);
#if defined(__cplusplus)
}
#endif

// Return True if a character was found
static inline bool code_seen(char code) { return (strchr_pointer = strchr(CMDBUFFER_CURRENT_STRING, code)) != NULL; }
static inline bool code_seen_P(const char *code_PROGMEM) { return (strchr_pointer = strstr_P(CMDBUFFER_CURRENT_STRING, code_PROGMEM)) != NULL; }
static inline float code_value() { return strtod(strchr_pointer+1, NULL);}
static inline float code_value() { return strtod_noE(strchr_pointer+1, NULL);}
static inline long code_value_long() { return strtol(strchr_pointer+1, NULL, 10); }
static inline int16_t code_value_short() { return int16_t(strtol(strchr_pointer+1, NULL, 10)); };
static inline uint8_t code_value_uint8() { return uint8_t(strtol(strchr_pointer+1, NULL, 10)); };

static inline float code_value_float()
{
char* e = strchr(strchr_pointer, 'E');
if (!e) return strtod(strchr_pointer + 1, NULL);
*e = 0;
float ret = strtod(strchr_pointer + 1, NULL);
*e = 'E';
return ret;
// A correct version of strtod() has been implemented, this hack is unnecessary.
//char* e = strchr(strchr_pointer, 'E');
//if (!e) return strtod(strchr_pointer + 1, NULL);
//*e = 0;
//float ret = strtod(strchr_pointer + 1, NULL);
//*e = 'E';
return strtod_noE(strchr_pointer + 1, NULL);
}


Expand Down
Loading

0 comments on commit e4de782

Please sign in to comment.