Loading files
b6d6e761eThis file is pinned to the selected release. Download the original to open it in your design tool.
/*
* Copyright (C) 2021 Sienci Labs Inc.
*
* This file is part of gSender.
*
* gSender is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, under version 3 of the License.
*
* gSender is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gSender. If not, see <https://www.gnu.org/licenses/>.
*
* Contact for information regarding this program and its license
* can be sent through gSender@sienci.com or mailed to the main office
* of Sienci Labs Inc. in Waterloo, Ontario, Canada.
*
*/
import _ from "lodash";
import LineParserResultAlarm from "../shared/LineParserResultAlarm";
import LineParserResultEcho from "../shared/LineParserResultEcho";
import LineParserResultError from "../shared/LineParserResultError";
import LineParserResultFeedback from "../shared/LineParserResultFeedback";
import LineParserResultHelp from "../shared/LineParserResultHelp";
import GrblLineParserResultOk from "./GrblLineParserResultOk";
import LineParserResultOption from "../shared/LineParserResultOption";
import GrblLineParserResultParameters from "./GrblLineParserResultParameters";
import GrblLineParserResultParserState from "./GrblLineParserResultParserState";
import LineParserResultSettings from "../shared/LineParserResultSettings";
import GrblLineParserResultStartup from "./GrblLineParserResultStartup";
import GrblLineParserResultStatus from "./GrblLineParserResultStatus";
import GrblLineParserResultVersion from "./GrblLineParserResultVersion";
// Grbl v1.1
// https://github.com/gnea/grbl/blob/edge/doc/markdown/interface.md
class GrblLineParser {
parse(line) {
const parsers = [
// <>
GrblLineParserResultStatus,
// ok
GrblLineParserResultOk,
// error:x
LineParserResultError,
// ALARM:
LineParserResultAlarm,
// [G38.2 G54 G17 G21 G91 G94 M0 M5 M9 T0 F20. S0.] (v0.9)
// [GC:G38.2 G54 G17 G21 G91 G94 M0 M5 M9 T0 F20. S0.] (v1.1)
GrblLineParserResultParserState,
// [G54:0.000,0.000,0.000]
// [G55:0.000,0.000,0.000]
// [G56:0.000,0.000,0.000]
// [G57:0.000,0.000,0.000]
// [G58:0.000,0.000,0.000]
// [G59:0.000,0.000,0.000]
// [G28:0.000,0.000,0.000]
// [G30:0.000,0.000,0.000]
// [G92:0.000,0.000,0.000]
// [TLO:0.000]
// [PRB:0.000,0.000,0.000:0]
GrblLineParserResultParameters,
// [HLP:] (v1.1)
LineParserResultHelp,
// [VER:] (v1.1)
GrblLineParserResultVersion,
// [OPT:] (v1.1)
LineParserResultOption,
// [echo:] (v1.1)
LineParserResultEcho,
// [] (v0.9)
// [MSG:] (v1.1)
LineParserResultFeedback,
// $xx
LineParserResultSettings,
// Grbl X.Xx ['$' for help]
GrblLineParserResultStartup,
];
for (const parser of parsers) {
const result = parser.parse(line);
if (result) {
_.set(result, "payload.raw", line);
return result;
}
}
return {
type: null,
payload: {
raw: line,
},
};
}
}
export default GrblLineParser;