Just a simple Python API server for parsing Gcode files to retrieve the metadata and slicer config settings from the Gcode source. Can be used to just retrieve the meta data, or compared with other gcode files to assess any slicer changes made between prints.
This is intended to be installed on a RaspberryPi with Klipper. It currently only looks at local files, but the logic is implemented in such a way that gcode files retrieved via HTTP can easily be parsed as well (it's just not necessary right now).
Right now it only parses out Prusa sliced Gcode files, though I am working on setting up a slicer base class to be used as an interface for slicer-specific classes, which will make comparing gcode files generated from different slicers possible (similar to how the metadata is handled in MoonRaker)
uvicorn server:app --reload
Parse header via http://127.0.0.1:8000/gcode/prusa-sliced-2.gcode/header/parse
Full parsed header output here
Parse footer via http://127.0.0.1:8000/gcode/prusa-sliced-2.gcode/footer/parse?cast=true
Full parsed footer output here
Compare two gcode configs via http://127.0.0.1:8000/gcode/compare/prusa-sliced.gcode/prusa-sliced-2.gcode?cast=true
Full comparison output here
- Properly setup a base class parser that can be inherited and used when creating parsers for other slicers, similar to how Moonraker handles the slicer parser classes (metadata.py)
- Modify the routes to use search/query params for the filenames (or POST data) instead of
/gcode/compare/{left_filename}/{right_filename}
, so gcode files nested in other directories won't throw any errors. - Add a feature to allow diffing of more than 2 files.
- The functions used to read and parse the gcode files (gcode_utils.py) need to be updated to use generators. And for parsing the footer, it will see a great improvement if the file is just parsed in reverse order, instead of grabbing a specific amount of data from the end of the file to parse line by line.
POC Of this improved method is here, with a screenshot of the comparison below:
(Using a generator is more than 1.6 seconds faster with test files)