cmdqueue.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef CMDQUEUE_H
  2. #define CMDQUEUE_H
  3. #include "Marlin.h"
  4. #include "language_all.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. // How much space to reserve for the chained commands
  23. // of type CMDBUFFER_CURRENT_TYPE_CHAINED,
  24. // which are pushed to the front of the queue?
  25. // Maximum 5 commands of max length 20 + null terminator.
  26. #define CMDBUFFER_RESERVE_FRONT (5*21)
  27. extern char cmdbuffer[BUFSIZE * (MAX_CMD_SIZE + 1) + CMDBUFFER_RESERVE_FRONT];
  28. extern int bufindr;
  29. extern int bufindw;
  30. extern int buflen;
  31. extern bool cmdbuffer_front_already_processed;
  32. // Type of a command, which is to be executed right now.
  33. #define CMDBUFFER_CURRENT_TYPE (cmdbuffer[bufindr])
  34. // String of a command, which is to be executed right now.
  35. #define CMDBUFFER_CURRENT_STRING (cmdbuffer+bufindr+CMDHDRSIZE)
  36. // Enable debugging of the command buffer.
  37. // Debugging information will be sent to serial line.
  38. //#define CMDBUFFER_DEBUG
  39. extern int serial_count;
  40. extern boolean comment_mode;
  41. extern char *strchr_pointer;
  42. extern unsigned long TimeSent;
  43. extern unsigned long TimeNow;
  44. extern long gcode_N;
  45. extern long gcode_LastN;
  46. extern long Stopped_gcode_LastN;
  47. extern bool cmdqueue_pop_front();
  48. extern void cmdqueue_reset();
  49. extern bool cmdqueue_could_enqueue_front(int len_asked);
  50. extern bool cmdqueue_could_enqueue_back(int len_asked, bool atomic_update = false);
  51. #ifdef CMDBUFFER_DEBUG
  52. extern void cmdqueue_dump_to_serial_single_line(int nr, const char *p);
  53. extern void cmdqueue_dump_to_serial();
  54. #endif /* CMDBUFFER_DEBUG */
  55. extern bool cmd_buffer_empty();
  56. extern void enquecommand(const char *cmd, bool from_progmem);
  57. extern void enquecommand_front(const char *cmd, bool from_progmem);
  58. extern void repeatcommand_front();
  59. extern bool is_buffer_empty();
  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(const char *code) { return (strchr_pointer = strstr(CMDBUFFER_CURRENT_STRING, code)) != 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