ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
gcode_host.h
Go to the documentation of this file.
1 /*
2  gcode_host.h - gcode host functions class
3 
4  Copyright (c) 2014 Luc Lebosse. All rights reserved.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 
22 
23 #ifndef _GCODE_HOST_H
24 #define _GCODE_HOST_H
25 
26 #include <Arduino.h>
27 #include "../authentication/authentication_service.h"
28 class ESP3DOutput;
29 
30 #define DEFAULT_TIMOUT 2000
31 #define MAX_TRY_2_SEND 5
32 #define ERROR_NO_ERROR 0
33 #define ERROR_TIME_OUT 1
34 #define ERROR_CANNOT_SEND_DATA 2
35 #define ERROR_LINE_NUMBER 3
36 #define ERROR_ACK_NUMBER 4
37 #define ERROR_MEMORY_PROBLEM 5
38 #define ERROR_RESEND 6
39 #define ERROR_NUMBER_MISMATCH 7
40 #define ERROR_LINE_IGNORED 8
41 
42 class GcodeHost
43 {
44 public:
45  GcodeHost();
46  ~GcodeHost();
47  bool begin(bool waitwhenidle = false);
48  void end();
49  void handle();
50  bool sendCommand(const char* command, bool checksum = false, bool wait4ack = true, const char * ack=nullptr);
52  {
53  return _commandnumber;
54  }
55  void setCommandNumber(uint32_t n)
56  {
57  _commandnumber = n;
58  }
59  bool resetCommandNumbering();
60  uint8_t Checksum(const char * command, uint32_t commandSize);
61  String CheckSumCommand(const char* command, uint32_t commandnb);
62  size_t wait_for_data(uint32_t timeout = DEFAULT_TIMOUT);
63  bool wait_for_ack(uint32_t timeout = DEFAULT_TIMOUT, bool checksum=false, const char * ack=nullptr);
64  bool purge(uint32_t timeout = DEFAULT_TIMOUT);
65  uint32_t Get_commandNumber(String & response);
66  bool waitWhenIdle()
67  {
68  return _waitwhenidle;
69  }
70  uint8_t getErrorNum()
71  {
72  return _error;
73  }
74  bool processFile(const char * filename, level_authenticate_type auth_type, ESP3DOutput * output);
75  bool processFSFile(const char * filename, level_authenticate_type auth_type, ESP3DOutput * output);
76  bool processLine(const char * line, level_authenticate_type auth_type, ESP3DOutput * output);
77  bool processscript(const char * line);
78 private:
79  uint32_t _commandnumber;
80  uint32_t _needcommandnumber;
81  bool _waitwhenidle;
82  uint8_t _error;
83 };
84 
86 
87 #endif //_GCODE_HOST_H
88 
GcodeHost::purge
bool purge(uint32_t timeout=DEFAULT_TIMOUT)
Definition: gcode_host.cpp:235
GcodeHost::Get_commandNumber
uint32_t Get_commandNumber(String &response)
Definition: gcode_host.cpp:264
esp3d_gcode_host
GcodeHost esp3d_gcode_host
Definition: gcode_host.cpp:30
GcodeHost::processFile
bool processFile(const char *filename, level_authenticate_type auth_type, ESP3DOutput *output)
Definition: gcode_host.cpp:389
GcodeHost::end
void end()
Definition: gcode_host.cpp:51
GcodeHost::processFSFile
bool processFSFile(const char *filename, level_authenticate_type auth_type, ESP3DOutput *output)
Definition: gcode_host.cpp:286
GcodeHost::wait_for_data
size_t wait_for_data(uint32_t timeout=DEFAULT_TIMOUT)
Definition: gcode_host.cpp:80
GcodeHost::~GcodeHost
~GcodeHost()
Definition: gcode_host.cpp:39
GcodeHost::setCommandNumber
void setCommandNumber(uint32_t n)
Definition: gcode_host.h:55
GcodeHost::getErrorNum
uint8_t getErrorNum()
Definition: gcode_host.h:70
GcodeHost::processLine
bool processLine(const char *line, level_authenticate_type auth_type, ESP3DOutput *output)
Definition: gcode_host.cpp:355
GcodeHost::CheckSumCommand
String CheckSumCommand(const char *command, uint32_t commandnb)
Definition: gcode_host.cpp:72
level_authenticate_type
level_authenticate_type
Definition: authentication_service.h:25
GcodeHost::wait_for_ack
bool wait_for_ack(uint32_t timeout=DEFAULT_TIMOUT, bool checksum=false, const char *ack=nullptr)
Definition: gcode_host.cpp:106
GcodeHost::Checksum
uint8_t Checksum(const char *command, uint32_t commandSize)
Definition: gcode_host.cpp:60
GcodeHost
Definition: gcode_host.h:42
GcodeHost::processscript
bool processscript(const char *line)
Definition: gcode_host.cpp:340
GcodeHost::currentCommandNumber
uint32_t currentCommandNumber()
Definition: gcode_host.h:51
GcodeHost::GcodeHost
GcodeHost()
Definition: gcode_host.cpp:32
GcodeHost::resetCommandNumbering
bool resetCommandNumbering()
Definition: gcode_host.cpp:89
GcodeHost::sendCommand
bool sendCommand(const char *command, bool checksum=false, bool wait4ack=true, const char *ack=nullptr)
Definition: gcode_host.cpp:174
GcodeHost::waitWhenIdle
bool waitWhenIdle()
Definition: gcode_host.h:66
DEFAULT_TIMOUT
#define DEFAULT_TIMOUT
Definition: gcode_host.h:30
ESP3DOutput
Definition: esp3doutput.h:48
GcodeHost::handle
void handle()
Definition: gcode_host.cpp:56
GcodeHost::begin
bool begin(bool waitwhenidle=false)
Definition: gcode_host.cpp:44