cmdqueue.h 3.6 KB

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