wallacoloo / gparse Goto Github PK
View Code? Open in Web Editor NEWA simple, dependency-free gcode parser for use in reprap-style 3d printers
License: MIT License
A simple, dependency-free gcode parser for use in reprap-style 3d printers
License: MIT License
M32 ("print from sd card file") can be formatted like so, according to http://reprap.org/wiki/G-code#M23:_Select_SD_file and https://github.com/ErikZalm/Marlin/blob/058e4465313191bf769e00a347ceccb4fbd1112c/Marlin/Marlin_main.cpp (line 105):
M32 filename.gco
M32 /path/to/file
M32 !filename.gcode#
M32 S<startpos bytes> !filename#
First off, it becomes obvious that there are a variety of syntaxes. Secondly these are clearly not float parameters. Also, not all formats identify a variable name for the filename. For example, blending the first and last example, M32 S10 S11
is ambiguous - the file could either be named 'S10', and the offset is 11 bytes OR the file could be named 'S11' and the offset is 10 bytes. "Correctly" parsing this ambigious example is literally impossible.
There are a few ways to fix this:
I vote for #2, as it would be the easiest to implement, and doesn't have any edge-cases.
Some Windows text editors end their lines with "\r\n" instead of just "\n". Need to make sure both line-endings are supported.
Storing each space-separated value into a vector of strings is costly - especially with all that heap allocation. It may be best to just parse the command all in one go and store the float values (eg X**, Y**, Z**), or to preserve the original string and keep a vector of pointers instead (less string allocation).
Command has functions like isG1()
and isM105()
.
Currently, these use inline constants; isG1()
is defined as return isOpcode(0x4731u)
. This 0x4731u is a magic number, but is really the equivalent of "G1" in big-endian. It is equivalent to ('G'<<8) + '1'
, but precalculated. So ideally, these magic numbers should be replaced with either the above, or something like isOpcode(makeStr('G', '1'))
.
Basic tests for gcode parsing & serializing. Not sure what testing framework to use for this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.