initial
This commit is contained in:
26
server/fluidnc/StatusParser.js
Normal file
26
server/fluidnc/StatusParser.js
Normal file
@@ -0,0 +1,26 @@
|
||||
class StatusParser {
|
||||
|
||||
static parse(line){
|
||||
|
||||
if(!line.startsWith("<")) return null;
|
||||
|
||||
const stateMatch = line.match(/^<([^|]+)/);
|
||||
const posMatch = line.match(/MPos:([^|]+)/);
|
||||
|
||||
if(!posMatch) return null;
|
||||
|
||||
const parts = posMatch[1].split(",");
|
||||
|
||||
return {
|
||||
type: "status",
|
||||
state: stateMatch ? stateMatch[1] : "unknown",
|
||||
x: parseFloat(parts[0]),
|
||||
y: parseFloat(parts[1]),
|
||||
z: parseFloat(parts[2])
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = StatusParser;
|
||||
Reference in New Issue
Block a user