| 66 | // The checksum "cs" for a GCode string "cmd" (including its line number) is computed |
| 67 | // by exor-ing the bytes in the string up to and not including the * character. |
| 68 | const computeChecksum = (s) => { |
| 69 | s = s || ''; |
| 70 | if (s.lastIndexOf('*') >= 0) { |
| 71 | s = s.substr(0, s.lastIndexOf('*')); |
| 72 | } |
| 73 | |
| 74 | let cs = 0; |
| 75 | for (let i = 0; i < s.length; ++i) { |
| 76 | const c = s[i].charCodeAt(0); |
| 77 | cs ^= c; |
| 78 | } |
| 79 | return cs; |
| 80 | }; |
| 81 | // http://linuxcnc.org/docs/html/gcode/overview.html#gcode:comments |
| 82 | // Comments can be embedded in a line using parentheses () or for the remainder of a lineusing a semi-colon. |
| 83 | // The semi-colon is not treated as the start of a comment when enclosed in parentheses. |