Rx buffer overflow behavior improved

This commit is contained in:
PavelSindler 2017-03-22 18:43:19 +01:00
parent 04f8e6d61e
commit ed5842d1d1
3 changed files with 25 additions and 17 deletions

View file

@ -722,8 +722,4 @@ enum CalibrationStatus
#include "Configuration_adv.h" #include "Configuration_adv.h"
#include "thermistortables.h" #include "thermistortables.h"
#endif //__CONFIGURATION_H #endif //__CONFIGURATION_H

View file

@ -429,7 +429,7 @@ static bool cmdbuffer_front_already_processed = false;
// Debugging information will be sent to serial line. // Debugging information will be sent to serial line.
// #define CMDBUFFER_DEBUG // #define CMDBUFFER_DEBUG
static int serial_count = 0; static int serial_count = 0; //index of character read from serial line
static boolean comment_mode = false; static boolean comment_mode = false;
static char *strchr_pointer; // just a pointer to find chars in the command string like X, Y, Z, E, etc static char *strchr_pointer; // just a pointer to find chars in the command string like X, Y, Z, E, etc
@ -1323,10 +1323,16 @@ void loop()
void get_command() void get_command()
{ {
// Test and reserve space for the new command string. // Test and reserve space for the new command string.
if (! cmdqueue_could_enqueue_back(MAX_CMD_SIZE-1)) if (!cmdqueue_could_enqueue_back(MAX_CMD_SIZE - 1))
return; return;
bool rx_buffer_full = false; //flag that serial rx buffer is full
while (MYSERIAL.available() > 0) { while (MYSERIAL.available() > 0) {
if (MYSERIAL.available() == RX_BUFFER_SIZE - 1) { //compare number of chars buffered in rx buffer with rx buffer size
SERIAL_ECHOLNPGM("Full RX Buffer"); //if buffer was full, there is danger that reading of last gcode will not be completed
rx_buffer_full = true; //sets flag that buffer was full
}
char serial_char = MYSERIAL.read(); char serial_char = MYSERIAL.read();
TimeSent = millis(); TimeSent = millis();
TimeNow = millis(); TimeNow = millis();
@ -1476,6 +1482,13 @@ void get_command()
} }
} }
//add comment
if (rx_buffer_full == true && serial_count > 0) { //if rx buffer was full and string was not properly terminated
rx_buffer_full = false;
bufindw = bufindw - serial_count; //adjust tail of the buffer to prepare buffer for writing new command
serial_count = 0;
}
#ifdef SDSUPPORT #ifdef SDSUPPORT
if(!card.sdprinting || serial_count!=0){ if(!card.sdprinting || serial_count!=0){
// If there is a half filled buffer from serial line, wait until return before // If there is a half filled buffer from serial line, wait until return before
@ -3878,7 +3891,6 @@ Sigma_Exit:
SERIAL_PROTOCOL_F(rawHotendTemp(cur_extruder)/OVERSAMPLENR,0); SERIAL_PROTOCOL_F(rawHotendTemp(cur_extruder)/OVERSAMPLENR,0);
} }
#endif #endif
SERIAL_PROTOCOLLN(""); SERIAL_PROTOCOLLN("");
return; return;
break; break;

View file

@ -4637,7 +4637,7 @@ void lcd_buttons_update()
button_pressed = true; button_pressed = true;
} }
else { else {
if (millis() - long_press_timer > 500) { //long press activated if (millis() - long_press_timer > 1000) { //long press activated
long_press_active = true; long_press_active = true;
move_menu_scale = 1.0; move_menu_scale = 1.0;
savedMenu = currentMenu; savedMenu = currentMenu;
@ -4651,7 +4651,7 @@ void lcd_buttons_update()
if (currentMenu == lcd_move_z) { if (currentMenu == lcd_move_z) {
//return to previously active menu //return to previously active menu
//lcd_goto_menu(savedMenu); //lcd_goto_menu(savedMenu);
lcd_goto_menu(lcd_main_menu); //lcd_goto_menu(lcd_main_menu);
lcd_return_to_status(); lcd_return_to_status();
} }
else { else {