MCPcopy Index your code
hub / github.com/cncjs/gcode-parser / computeChecksum

Function computeChecksum

src/index.js:68–80  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

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.

Callers 1

index.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected