prusa3d / libbgcode

Prusa Block & Binary G-code reader / writer / converter
GNU Affero General Public License v3.0
47 stars 14 forks source link

Document different gcode data block encoding format in specification #36

Open mtreinish opened 10 months ago

mtreinish commented 10 months ago

Right now the G-Code data block just lists the encoding header format and lists the possible values for the header field:

0 = No encoding
1 = MeatPack algorithm
2 = MeatPack algorithm modified to keep comment lines

without defining what MeatPack or the modified MeatPack algorithms are. It would be good if the definition of those encoding types were documented (also assuming no encoding just means the text gcode). While you can look at the source code, documenting the actual specifics of the encoding formats will make the specification more useful for people trying to interoperate with the format.

elfrocampeador commented 10 months ago

I agree that the actual compression algorithm should be documented. This is an error shared by its creator, but considering the core code is only a couple hundred lines long it really shouldn't be difficult to explain.

For proof of concept / preliminary suggestion, here's my attempt based on reading the original Meatpack code: "libbgcode implements the Meatpack gcode binary compression algorithm created by Scott Mudge (https://github.com/scottmudge/". It takes advantage of the small set of approximately 15 characters needed by gcode by assigning each character a 4 bit representation. Each pair of characters in the ASCII gcode can be compressed into a single byte by bitshifting the first character's binary representation left and combining them with a bitwise or operation. Combined with a few other structural details, this results in a nearly 2:1 reduction of space usage."

This is just a crude start, but I hope this illustrates how the effect can be achieved with relatively little text.