update code base to Marlin 2.0.9.2

This commit is contained in:
Stefan Kalscheuer
2021-10-03 18:57:12 +02:00
parent b9d7ba838e
commit 7077da3591
2617 changed files with 332093 additions and 103438 deletions

View File

@@ -39,10 +39,9 @@
#include "../inc/MarlinConfig.h"
#if ENABLED(MEATPACK)
#if HAS_MEATPACK
#include "meatpack.h"
MeatPack meatpack;
#define MeatPack_ProtocolVersion "PV01"
//#define MP_DEBUG
@@ -50,30 +49,24 @@ MeatPack meatpack;
#define DEBUG_OUT ENABLED(MP_DEBUG)
#include "../core/debug_out.h"
bool MeatPack::cmd_is_next = false; // A command is pending
uint8_t MeatPack::state = 0; // Configuration state OFF
uint8_t MeatPack::second_char = 0; // The unpacked 2nd character from an out-of-sequence packed pair
uint8_t MeatPack::cmd_count = 0, // Counts how many command bytes are received (need 2)
MeatPack::full_char_count = 0, // Counts how many full-width characters are to be received
MeatPack::char_out_count = 0; // Stores number of characters to be read out.
uint8_t MeatPack::char_out_buf[2]; // Output buffer for caching up to 2 characters
// The 15 most-common characters used in G-code, ~90-95% of all G-code uses these characters
// Stored in SRAM for performance.
uint8_t meatPackLookupTable[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'.', ' ', '\n', 'G', 'X',
'\0' // Unused. 0b1111 indicates a literal character
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'.', ' ', '\n', 'G', 'X',
'\0' // Unused. 0b1111 indicates a literal character
};
TERN_(MP_DEBUG, uint8_t chars_decoded = 0); // Log the first 64 bytes after each reset
#if ENABLED(MP_DEBUG)
uint8_t chars_decoded = 0; // Log the first 64 bytes after each reset
#endif
void MeatPack::reset_state() {
state = 0;
cmd_is_next = false;
second_char = 0;
cmd_count = full_char_count = char_out_count = 0;
TERN_(MP_DEBUG, chars_decoded = 0);
state = 0;
cmd_is_next = false;
second_char = 0;
cmd_count = full_char_count = char_out_count = 0;
TERN_(MP_DEBUG, chars_decoded = 0);
}
/**
@@ -81,25 +74,25 @@ void MeatPack::reset_state() {
* Return flags indicating whether any literal bytes follow.
*/
uint8_t MeatPack::unpack_chars(const uint8_t pk, uint8_t* __restrict const chars_out) {
uint8_t out = 0;
uint8_t out = 0;
// If lower nybble is 1111, the higher nybble is unused, and next char is full.
if ((pk & kFirstNotPacked) == kFirstNotPacked)
out = kFirstCharIsLiteral;
else {
const uint8_t chr = pk & 0x0F;
chars_out[0] = meatPackLookupTable[chr]; // Set the first char
}
// If lower nybble is 1111, the higher nybble is unused, and next char is full.
if ((pk & kFirstNotPacked) == kFirstNotPacked)
out = kFirstCharIsLiteral;
else {
const uint8_t chr = pk & 0x0F;
chars_out[0] = meatPackLookupTable[chr]; // Set the first char
}
// Check if upper nybble is 1111... if so, we don't need the second char.
if ((pk & kSecondNotPacked) == kSecondNotPacked)
out |= kSecondCharIsLiteral;
else {
const uint8_t chr = (pk >> 4) & 0x0F;
chars_out[1] = meatPackLookupTable[chr]; // Set the second char
}
// Check if upper nybble is 1111... if so, we don't need the second char.
if ((pk & kSecondNotPacked) == kSecondNotPacked)
out |= kSecondCharIsLiteral;
else {
const uint8_t chr = (pk >> 4) & 0x0F;
chars_out[1] = meatPackLookupTable[chr]; // Set the second char
}
return out;
return out;
}
/**
@@ -107,33 +100,33 @@ uint8_t MeatPack::unpack_chars(const uint8_t pk, uint8_t* __restrict const chars
* according to the current MeatPack state.
*/
void MeatPack::handle_rx_char_inner(const uint8_t c) {
if (TEST(state, MPConfig_Bit_Active)) { // Is MeatPack active?
if (!full_char_count) { // No literal characters to fetch?
uint8_t buf[2] = { 0, 0 };
register const uint8_t res = unpack_chars(c, buf); // Decode the byte into one or two characters.
if (res & kFirstCharIsLiteral) { // The 1st character couldn't be packed.
++full_char_count; // So the next stream byte is a full character.
if (res & kSecondCharIsLiteral) ++full_char_count; // The 2nd character couldn't be packed. Another stream byte is a full character.
else second_char = buf[1]; // Retain the unpacked second character.
}
else {
handle_output_char(buf[0]); // Send the unpacked first character out.
if (buf[0] != '\n') { // After a newline the next char won't be set
if (res & kSecondCharIsLiteral) ++full_char_count; // The 2nd character couldn't be packed. The next stream byte is a full character.
else handle_output_char(buf[1]); // Send the unpacked second character out.
}
}
}
else {
handle_output_char(c); // Pass through the character that couldn't be packed...
if (second_char) {
handle_output_char(second_char); // ...and send an unpacked 2nd character, if set.
second_char = 0;
}
--full_char_count; // One literal character was consumed
if (TEST(state, MPConfig_Bit_Active)) { // Is MeatPack active?
if (!full_char_count) { // No literal characters to fetch?
uint8_t buf[2] = { 0, 0 };
const uint8_t res = unpack_chars(c, buf); // Decode the byte into one or two characters.
if (res & kFirstCharIsLiteral) { // The 1st character couldn't be packed.
++full_char_count; // So the next stream byte is a full character.
if (res & kSecondCharIsLiteral) ++full_char_count; // The 2nd character couldn't be packed. Another stream byte is a full character.
else second_char = buf[1]; // Retain the unpacked second character.
}
else {
handle_output_char(buf[0]); // Send the unpacked first character out.
if (buf[0] != '\n') { // After a newline the next char won't be set
if (res & kSecondCharIsLiteral) ++full_char_count; // The 2nd character couldn't be packed. The next stream byte is a full character.
else handle_output_char(buf[1]); // Send the unpacked second character out.
}
}
}
else // Packing not enabled, just copy character to output
else {
handle_output_char(c); // Pass through the character that couldn't be packed...
if (second_char) {
handle_output_char(second_char); // ...and send an unpacked 2nd character, if set.
second_char = 0;
}
--full_char_count; // One literal character was consumed
}
}
else // Packing not enabled, just copy character to output
handle_output_char(c);
}
@@ -142,14 +135,12 @@ void MeatPack::handle_rx_char_inner(const uint8_t c) {
* GCodeQueue::get_serial_commands via calls to get_result_char
*/
void MeatPack::handle_output_char(const uint8_t c) {
char_out_buf[char_out_count++] = c;
char_out_buf[char_out_count++] = c;
#if ENABLED(MP_DEBUG)
if (chars_decoded < 1024) {
++chars_decoded;
DEBUG_ECHOPGM("RB: ");
MYSERIAL.print((char)c);
DEBUG_EOL();
++chars_decoded;
DEBUG_ECHOLNPGM("RB: ", AS_CHAR(c));
}
#endif
}
@@ -159,29 +150,29 @@ void MeatPack::handle_output_char(const uint8_t c) {
* Report the new state to serial.
*/
void MeatPack::handle_command(const MeatPack_Command c) {
switch (c) {
case MPCommand_QueryConfig: break;
case MPCommand_EnablePacking: SBI(state, MPConfig_Bit_Active); DEBUG_ECHOLNPGM("[MPDBG] ENA REC"); break;
case MPCommand_DisablePacking: CBI(state, MPConfig_Bit_Active); DEBUG_ECHOLNPGM("[MPDBG] DIS REC"); break;
case MPCommand_ResetAll: reset_state(); DEBUG_ECHOLNPGM("[MPDBG] RESET REC"); break;
case MPCommand_EnableNoSpaces:
SBI(state, MPConfig_Bit_NoSpaces);
meatPackLookupTable[kSpaceCharIdx] = kSpaceCharReplace; DEBUG_ECHOLNPGM("[MPDBG] ENA NSP"); break;
case MPCommand_DisableNoSpaces:
CBI(state, MPConfig_Bit_NoSpaces);
meatPackLookupTable[kSpaceCharIdx] = ' '; DEBUG_ECHOLNPGM("[MPDBG] DIS NSP"); break;
default: DEBUG_ECHOLNPGM("[MPDBG] UNK CMD REC");
}
report_state();
switch (c) {
case MPCommand_QueryConfig: break;
case MPCommand_EnablePacking: SBI(state, MPConfig_Bit_Active); DEBUG_ECHOLNPGM("[MPDBG] ENA REC"); break;
case MPCommand_DisablePacking: CBI(state, MPConfig_Bit_Active); DEBUG_ECHOLNPGM("[MPDBG] DIS REC"); break;
case MPCommand_ResetAll: reset_state(); DEBUG_ECHOLNPGM("[MPDBG] RESET REC"); break;
case MPCommand_EnableNoSpaces:
SBI(state, MPConfig_Bit_NoSpaces);
meatPackLookupTable[kSpaceCharIdx] = kSpaceCharReplace; DEBUG_ECHOLNPGM("[MPDBG] ENA NSP"); break;
case MPCommand_DisableNoSpaces:
CBI(state, MPConfig_Bit_NoSpaces);
meatPackLookupTable[kSpaceCharIdx] = ' '; DEBUG_ECHOLNPGM("[MPDBG] DIS NSP"); break;
default: DEBUG_ECHOLNPGM("[MPDBG] UNK CMD REC");
}
report_state();
}
void MeatPack::report_state() {
// NOTE: if any configuration vars are added below, the outgoing sync text for host plugin
// should not contain the "PV' substring, as this is used to indicate protocol version
SERIAL_ECHOPGM("[MP] ");
SERIAL_ECHOPGM(MeatPack_ProtocolVersion " ");
serialprint_onoff(TEST(state, MPConfig_Bit_Active));
serialprintPGM(TEST(state, MPConfig_Bit_NoSpaces) ? PSTR(" NSP\n") : PSTR(" ESP\n"));
// NOTE: if any configuration vars are added below, the outgoing sync text for host plugin
// should not contain the "PV' substring, as this is used to indicate protocol version
SERIAL_ECHOPGM("[MP] ");
SERIAL_ECHOPGM(MeatPack_ProtocolVersion " ");
serialprint_onoff(TEST(state, MPConfig_Bit_Active));
SERIAL_ECHOPGM_P(TEST(state, MPConfig_Bit_NoSpaces) ? PSTR(" NSP\n") : PSTR(" ESP\n"));
}
/**
@@ -189,40 +180,40 @@ void MeatPack::report_state() {
* according to the current meatpack state.
*/
void MeatPack::handle_rx_char(const uint8_t c, const serial_index_t serial_ind) {
if (c == kCommandByte) { // A command (0xFF) byte?
if (cmd_count) { // In fact, two in a row?
cmd_is_next = true; // Then a MeatPack command follows
cmd_count = 0;
}
else
++cmd_count; // cmd_count = 1 // One command byte received so far...
return;
if (c == kCommandByte) { // A command (0xFF) byte?
if (cmd_count) { // In fact, two in a row?
cmd_is_next = true; // Then a MeatPack command follows
cmd_count = 0;
}
else
++cmd_count; // cmd_count = 1 // One command byte received so far...
return;
}
if (cmd_is_next) { // Were two command bytes received?
PORT_REDIRECT(serial_ind);
handle_command((MeatPack_Command)c); // Then the byte is a MeatPack command
cmd_is_next = false;
return;
}
if (cmd_is_next) { // Were two command bytes received?
PORT_REDIRECT(SERIAL_PORTMASK(serial_ind));
handle_command((MeatPack_Command)c); // Then the byte is a MeatPack command
cmd_is_next = false;
return;
}
if (cmd_count) { // Only a single 0xFF was received
handle_rx_char_inner(kCommandByte); // A single 0xFF is passed on literally so it can be interpreted as kFirstNotPacked|kSecondNotPacked
cmd_count = 0;
}
if (cmd_count) { // Only a single 0xFF was received
handle_rx_char_inner(kCommandByte); // A single 0xFF is passed on literally so it can be interpreted as kFirstNotPacked|kSecondNotPacked
cmd_count = 0;
}
handle_rx_char_inner(c); // Other characters are passed on for MeatPack decoding
handle_rx_char_inner(c); // Other characters are passed on for MeatPack decoding
}
uint8_t MeatPack::get_result_char(char* const __restrict out) {
uint8_t res = 0;
if (char_out_count) {
res = char_out_count;
char_out_count = 0;
for (register uint8_t i = 0; i < res; ++i)
out[i] = (char)char_out_buf[i];
}
return res;
uint8_t MeatPack::get_result_char(char * const __restrict out) {
uint8_t res = 0;
if (char_out_count) {
res = char_out_count;
char_out_count = 0;
for (uint8_t i = 0; i < res; ++i)
out[i] = (char)char_out_buf[i];
}
return res;
}
#endif // MEATPACK
#endif // HAS_MEATPACK