@@ -68,22 +68,8 @@ GCodeQueue::RingBuffer GCodeQueue::ring_buffer = { 0 };
6868#endif
6969
7070/* *
71- * Track buffer underruns
71+ * Serial command injection
7272 */
73- #if ENABLED(BUFFER_MONITORING)
74- uint32_t GCodeQueue::command_buffer_underruns = 0 ;
75- bool GCodeQueue::command_buffer_empty = false ;
76- millis_t GCodeQueue::max_command_buffer_empty_duration = 0 ;
77- millis_t GCodeQueue::command_buffer_empty_at = 0 ;
78-
79- uint32_t GCodeQueue::planner_buffer_underruns = 0 ;
80- bool GCodeQueue::planner_buffer_empty = false ;
81- millis_t GCodeQueue::max_planner_buffer_empty_duration = 0 ;
82- millis_t GCodeQueue::planner_buffer_empty_at = 0 ;
83-
84- uint8_t GCodeQueue::auto_buffer_report_interval;
85- millis_t GCodeQueue::next_buffer_report_ms;
86- #endif
8773
8874/* *
8975 * Next Injected PROGMEM Command pointer. (nullptr == empty)
@@ -635,27 +621,7 @@ void GCodeQueue::advance() {
635621 if (process_injected_command_P () || process_injected_command ()) return ;
636622
637623 // Return if the G-code buffer is empty
638- if (ring_buffer.empty ()) {
639- #if ENABLED(BUFFER_MONITORING)
640- if (!command_buffer_empty) {
641- command_buffer_empty = true ;
642- command_buffer_underruns++;
643- command_buffer_empty_at = millis ();
644- }
645- #endif
646- return ;
647- }
648-
649- #if ENABLED(BUFFER_MONITORING)
650- if (command_buffer_empty) {
651- static millis_t command_buffer_empty_duration;
652- command_buffer_empty_duration = millis () - command_buffer_empty_at;
653- if (command_buffer_empty_duration > max_command_buffer_empty_duration) {
654- max_command_buffer_empty_duration = command_buffer_empty_duration;
655- }
656- command_buffer_empty = false ;
657- }
658- #endif
624+ if (ring_buffer.empty ()) return ;
659625
660626 #if ENABLED(SDSUPPORT)
661627
@@ -698,52 +664,3 @@ void GCodeQueue::advance() {
698664 // The queue may be reset by a command handler or by code invoked by idle() within a handler
699665 ring_buffer.advance_pos (ring_buffer.index_r , -1 );
700666}
701-
702- #if ENABLED(BUFFER_MONITORING)
703- void GCodeQueue::report_buffer_statistics () {
704- SERIAL_ECHO (" M576" );
705- SERIAL_ECHOLNPAIR (SP_P_STR, int (planner.moves_free ()),
706- SP_B_STR, int (BUFSIZE - length),
707- " PU" , queue.planner_buffer_underruns ,
708- " PD" , queue.max_planner_buffer_empty_duration ,
709- " BU" , queue.command_buffer_underruns ,
710- " BD" , queue.max_command_buffer_empty_duration ,
711- );
712-
713- command_buffer_underruns = 0 ;
714- max_command_buffer_empty_duration = 0 ;
715-
716- planner_buffer_underruns = 0 ;
717- max_planner_buffer_empty_duration = 0 ;
718- }
719-
720- void GCodeQueue::auto_report_buffer_statistics () {
721- // Bit of a hack to try to catch planner buffer underruns without having logic
722- // running inside Stepper::block_phase_isr
723- if (planner.movesplanned () == 0 ) {
724- if (!planner_buffer_empty) { // if the planner buffer wasn't empty, but now it is
725- planner_buffer_empty = true ;
726- planner_buffer_underruns++;
727- planner_buffer_empty_at = millis ();
728- }
729- } else if (planner_buffer_empty) { // if the planner buffer was empty, but now it ain't
730- static millis_t planner_buffer_empty_duration;
731- planner_buffer_empty_duration = millis () - planner_buffer_empty_at;
732-
733- // if it's longer than the currently tracked max duration, replace it
734- if (planner_buffer_empty_duration > max_planner_buffer_empty_duration) {
735- max_planner_buffer_empty_duration = planner_buffer_empty_duration;
736- }
737-
738- planner_buffer_empty = false ;
739- }
740-
741- if (queue.auto_buffer_report_interval && ELAPSED (millis (), queue.next_buffer_report_ms )) {
742- queue.next_buffer_report_ms = millis () + 1000UL * queue.auto_buffer_report_interval ;
743- PORT_REDIRECT (SERIAL_BOTH);
744- report_buffer_statistics ();
745- PORT_RESTORE ();
746- }
747- }
748-
749- #endif
0 commit comments