Prusa3d Marlin fork
cmdqueue.h
1 #ifndef CMDQUEUE_H
2 #define CMDQUEUE_H
3 
4 #include "Marlin.h"
5 
6 // String circular buffer. Commands may be pushed to the buffer from both sides:
7 // Chained commands will be pushed to the front, interactive (from LCD menu)
8 // and printing commands (from serial line or from SD card) are pushed to the tail.
9 // First character of each entry indicates the type of the entry:
10 #define CMDBUFFER_CURRENT_TYPE_UNKNOWN 0
11 // Command in cmdbuffer was sent over USB.
12 #define CMDBUFFER_CURRENT_TYPE_USB 1
13 // Command in cmdbuffer was read from SDCARD.
14 #define CMDBUFFER_CURRENT_TYPE_SDCARD 2
15 // Command in cmdbuffer was generated by the UI.
16 #define CMDBUFFER_CURRENT_TYPE_UI 3
17 // Command in cmdbuffer was generated by another G-code.
18 #define CMDBUFFER_CURRENT_TYPE_CHAINED 4
19 // Command has been processed and its SD card length has been possibly pushed
20 // to the planner queue, but not yet removed from the cmdqueue.
21 // This is a temporary state to reduce stepper interrupt locking time.
22 #define CMDBUFFER_CURRENT_TYPE_TO_BE_REMOVED 5
23 //Command in cmdbuffer was sent over USB and contains line number
24 #define CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR 6
25 
26 // How much space to reserve for the chained commands
27 // of type CMDBUFFER_CURRENT_TYPE_CHAINED,
28 // which are pushed to the front of the queue?
29 // Maximum 5 commands of max length 20 + null terminator.
30 #define CMDBUFFER_RESERVE_FRONT (5*21)
31 
32 extern char cmdbuffer[BUFSIZE * (MAX_CMD_SIZE + 1) + CMDBUFFER_RESERVE_FRONT];
33 extern size_t bufindr;
34 extern int buflen;
35 extern bool cmdbuffer_front_already_processed;
36 extern bool cmdqueue_serial_disabled;
37 
38 // Type of a command, which is to be executed right now.
39 #define CMDBUFFER_CURRENT_TYPE (cmdbuffer[bufindr])
40 // String of a command, which is to be executed right now.
41 #define CMDBUFFER_CURRENT_STRING (cmdbuffer+bufindr+CMDHDRSIZE)
42 
43 // Enable debugging of the command buffer.
44 // Debugging information will be sent to serial line.
45 //#define CMDBUFFER_DEBUG
46 
47 extern uint32_t sdpos_atomic;
48 
49 extern int serial_count;
50 extern bool comment_mode;
51 extern char *strchr_pointer;
52 
53 extern long gcode_LastN;
54 
55 extern bool cmdqueue_pop_front();
56 extern void cmdqueue_reset();
57 #ifdef CMDBUFFER_DEBUG
58 extern void cmdqueue_dump_to_serial_single_line(int nr, const char *p);
59 extern void cmdqueue_dump_to_serial();
60 #endif /* CMDBUFFER_DEBUG */
61 extern bool cmd_buffer_empty();
62 
65 void enquecommandf_P(const char *fmt, ...);
66 extern void enquecommand(const char *cmd, bool from_progmem = false);
67 extern void enquecommand_front(const char *cmd, bool from_progmem = false);
68 extern void repeatcommand_front();
69 extern void get_command();
70 extern uint16_t cmdqueue_calc_sd_length();
71 
72 
73 #if defined(__cplusplus)
74 extern "C" {
75 #endif
76  extern double strtod_noE(const char* nptr, char** endptr);
77 #if defined(__cplusplus)
78 }
79 #endif
80 
81 // Return True if a character was found
82 static inline bool code_seen(char code) { return (strchr_pointer = strchr(CMDBUFFER_CURRENT_STRING, code)) != NULL; }
83 static inline bool code_seen_P(const char *code_PROGMEM) { return (strchr_pointer = strstr_P(CMDBUFFER_CURRENT_STRING, code_PROGMEM)) != NULL; }
84 static inline float code_value() { return strtod_noE(strchr_pointer+1, NULL);}
85 static inline long code_value_long() { return strtol(strchr_pointer+1, NULL, 10); }
86 static inline int16_t code_value_short() { return int16_t(strtol(strchr_pointer+1, NULL, 10)); };
87 static inline uint8_t code_value_uint8() { return uint8_t(strtol(strchr_pointer+1, NULL, 10)); };
88 
89 #endif //CMDQUEUE_H