Skip to content

feat: Add advanced serial options, MeatPack and Advanced OK - #1578

Open
ellensp wants to merge 1 commit into
kliment:masterfrom
ellensp:advanced-serial-options
Open

ellensp wants to merge 1 commit into
kliment:masterfrom
ellensp:advanced-serial-options

Conversation

@ellensp

@ellensp ellensp commented Nov 5, 2026

Copy link
Copy Markdown

Description

Adds two options that speed up the serial connection to the printer. Both are under Printer Settings, off by default, and take effect on the next connection. They work separately or together, and each only applies if the firmware supports it.

Closes #1143.

MeatPack

MeatPack packs two characters from a 15 character alphabet into one byte, so G-code takes fewer bytes on the connection.

  • With the option on, printcore sends M115 once online and only starts packing if the firmware reports Cap:MEATPACK:1.
  • It uses the protocol's no-spaces mode, which removes the spaces from G0 to G3 before the checksum is worked out. Other commands keep theirs, since they may carry text. Moves uploaded to SD are stored without spaces.
  • M108, M112, M410 and M876 are sent unpacked, because Marlin's emergency parser reads the serial data before it is unpacked.
  • Connecting and disconnecting return the firmware to plain text. A start line from the firmware returns the host to plain text and negotiates again.
  • Before resending, the host resets the firmware's unpacking. Marlin discards unread serial data when it asks for a resend, which can leave its unpacking waiting for a byte that was thrown away.
  • The packing is in the new printrun/meatpack.py.

Advanced OK

Printrun normally sends one line and waits for its ok. With this option on, and on serial connections only, it sends ahead while earlier lines are still being handled, using the queue space reported by Marlin's ADVANCED_OK (ok N12 P15 B3).

  • It starts at one line at a time, and stays there if the firmware never reports B.
  • While printing, at most B + 1 lines are outstanding, using the highest B seen, since Marlin reports B while still holding the line it just finished.
  • Outstanding bytes, allowing for another line as long as the longest so far, are kept within Marlin's default 128 byte serial buffer, as the firmware may not read from it for some time.
  • On a resend request, Printrun waits for the replies to lines already sent, then resends from the first line requested. Marlin discards unread lines when it asks for a resend, so 0.5 s of silence also ends the wait. A line Marlin has since confirmed isn't resent.
  • An ok with a line number also covers earlier lines, so a lost ok corrects itself. After 30 s of silence, Printrun assumes one was lost.
  • ok lines with these fields no longer fill the console.

Showing the state

  • Pronterface: a dot left of the send field, hidden with both options off. It is grey for normal, blue for MeatPack, amber for Advanced OK and green for both, with the same in a tooltip.
  • Console: the new meatpack command shows the host's state and asks the firmware for its own.
  • printcore: new meatpack and advancedok callbacks and events.

Testing

Tested at 250000 baud on Marlin bugfix-2.1.x with the default BUFSIZE 4, on an MKS TinyBee (ESP32) and on a RAMPS 1.4 (ATmega2560) with a REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER and its SD card.

Uploading to SD, a 290047 line PrusaSlicer file. Stock used firmware with neither feature, and each other row used firmware with what it needs:

TinyBee Lines per second Total time
Stock 175 27 min 38 s
MeatPack 186 25 min 56 s
Advanced OK 332 14 min 33 s
MeatPack and Advanced OK 528 9 min 10 s
RAMPS Lines per second Total time
Stock 142 33 min 59 s
MeatPack 162 29 min 47 s
Advanced OK 471 10 min 15 s
MeatPack and Advanced OK 498 9 min 42 s

Every upload finished with no errors and the expected file size. After each row, a second uploaded file was run from SD and ended at the expected position.

Printing, 3000 lines with E moves at 100 mm/s and 0.4 mm per line, so at most 250 lines per second, with firmware that has both features. Every row ended at the expected X, Y and E:

Options TinyBee, lines per second RAMPS, lines per second
Neither 138 98
MeatPack 164 99
Advanced OK 251 153
MeatPack and Advanced OK 252 156

On both boards, in all four combinations, each with the expected result:

Test Result
Corrupted line during a print Resend: 200, recovered, correct end position
M105 every second during a print Temperatures reported, no errors, correct end position
Pause, then resume Correct end position
Cancel, then a new print No errors, correct end position
Upload to SD No errors, the expected file size
Commands typed during an upload Rejected by the firmware, upload continues, the expected file size
M410 with the emergency parser, during a long move Stopped at X17 of 200

Other checks:

Test Result
Advanced OK on, firmware without ADVANCED_OK, TinyBee One line at a time
Advanced OK, with and without MeatPack, BUFSIZE 16, TinyBee 6 to 7 lines outstanding, no errors, correct file sizes and end positions
Pronterface dot, TinyBee Hidden, then the right state in each combination
Upload through Pronterface with both options, TinyBee The expected file size, no ok lines in the console
M118 with spaces and punctuation, with MeatPack, TinyBee Text unchanged
M112 during a 20 s dwell, both options, RAMPS Killed in 0.005 s
Reconnecting after a host left the firmware packed, TinyBee Online and packing
meatpack command, idle and mid-print, TinyBee Reports ON NSP, and OFF ESP with the option off

tests/test_meatpack.py and tests/test_advanced_ok.py are new. They check packed lines against a Python copy of Marlin's decoder, and both features against a mocked printer, including a firmware restart, which was not run on hardware. All tests in tests/ pass.

AI disclosure

Full disclosure: I don't know your policy on AI, so please treat this PR accordingly.

AI used: Claude Opus 5.5 (Anthropic), via Claude Code. It wrote the code and this description, and ran the tests above on @ellensp's board. @ellensp requested these features, directed the work and verified the result.

Add two Printer Settings options to speed up the serial connection, both
off by default and applied on the next connection. Each only takes effect
if the firmware supports it.

MeatPack compresses G-code on the wire. Advanced OK uses the planner and
command buffer space reported in Marlin's ok replies to send more than one
line at a time, limited so the firmware's receive buffer can't overflow.

A dot left of the send box shows which of the two are active, and a new
meatpack command queries the firmware's state.

Closes kliment#1143

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] Add meatpack serial packing support

1 participant