Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gcode_parser.h « GcodeProcessorLib - github.com/FormerLurker/ArcWelderLib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 22d5d9d85a80d18bde688b332e8d932ac183aa0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Gcode Processor Library
//
// Tools for parsing gcode and calculating printer state from parsed gcode commands.
//
// Copyright(C) 2021 - Brad Hochgesang
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 Affero General Public License for more details.
//
//
// You can contact the author at the following email address: 
// FormerLurker@pm.me
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef GCODE_PARSER_H
#define GCODE_PARSER_H
#include <string>
#include <vector>
#include <set>
#include "parsed_command.h"
#include "parsed_command_parameter.h"
static const std::string GCODE_WORDS = "GMT";

class gcode_parser
{
public:
	gcode_parser();
	~gcode_parser();
	bool try_parse_gcode(const char * gcode, parsed_command & command);
	bool try_parse_gcode(const char* gcode, parsed_command& command, bool preserve_format);
	parsed_command parse_gcode(const char * gcode);
	parsed_command parse_gcode(const char* gcode, bool preserve_format);
private:
	gcode_parser(const gcode_parser &source);
	// Variables and lookups
	std::set<std::string> text_only_functions_;
	std::set<std::string> parsable_commands_;
	// Functions
	bool try_extract_double(char ** p_p_gcode, double * p_double, unsigned char * p_precision) const;
	static bool try_extract_gcode_command(char ** p_p_gcode, std::string * p_command);
	static bool try_extract_text_parameter(char ** p_p_gcode, std::string * p_parameter);
	bool try_extract_parameter(char ** p_p_gcode, parsed_command_parameter * parameter) const;
	static bool try_extract_t_parameter(char ** p_p_gcode, parsed_command_parameter * parameter);
	static bool try_extract_unsigned_long(char ** p_p_gcode, unsigned long * p_value);
	double static ten_pow(unsigned short n);
	bool try_extract_comment(char ** p_p_gcode, std::string * p_comment);
	static bool try_extract_at_command(char ** p_p_gcode, std::string * p_command);
	bool try_extract_octolapse_parameter(char ** p_p_gcode, parsed_command_parameter * p_parameter);
};
#endif