From 92575cecca064e18441dc40f3568b4f3706d203c Mon Sep 17 00:00:00 2001
From: Wurstnase <tonnhofer@gmail.com>
Date: Mon, 20 Apr 2015 00:22:40 +0200
Subject: [PATCH] new timout/add adv_ok

---
 Marlin/Configuration_adv.h | 10 +++++++---
 Marlin/Marlin_main.cpp     |  8 ++++++--
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h
index c7a3de5f9a..f2b5c7dd26 100644
--- a/Marlin/Configuration_adv.h
+++ b/Marlin/Configuration_adv.h
@@ -374,9 +374,13 @@ const unsigned int dropsegments=5; //everything with less than this number of st
 #define MAX_CMD_SIZE 96
 #define BUFSIZE 4
 
-// Some Hosts doesn't have a timeout for resend a command.
-// This is a workaround for them. If your printer sometimes stuck and stop printing this could help.
-// #define NO_TIMEOUTS
+// Bad Serial-connections can miss a received command by sending an 'ok'
+// Therefore some clients go after 30 seconds in a timeout. Some other clients start sending commands while receiving a 'wait'.
+// This wait is only send when the buffer is empty. The timeout-length is in milliseconds. 1000 is a good value.
+// #define NO_TIMEOUTS 1000
+
+// Some clients will have this feature soon. This should make the NO_TIMEOUTS unnecessary.
+// #define ADVANCED_OK
 
 // @section fwretract
 
diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp
index 9a9fe6086e..4d915a2c7d 100644
--- a/Marlin/Marlin_main.cpp
+++ b/Marlin/Marlin_main.cpp
@@ -728,7 +728,7 @@ void get_command() {
     static millis_t last_command_time = 0;
     millis_t ms = millis();
   
-    if (!MYSERIAL.available() && commands_in_queue == 0 && ms - last_command_time > 1000) {
+    if (!MYSERIAL.available() && commands_in_queue == 0 && ms - last_command_time > NO_TIMEOUTS) {
       SERIAL_ECHOLNPGM(MSG_WAIT);
       last_command_time = ms;
     }
@@ -5299,7 +5299,11 @@ void ClearToSend() {
   #ifdef SDSUPPORT
     if (fromsd[cmd_queue_index_r]) return;
   #endif
-  SERIAL_PROTOCOLLNPGM(MSG_OK);
+  SERIAL_PROTOCOLPGM(MSG_OK);
+  #ifdef ADVANCED_OK
+    SERIAL_PROTOCOLPGM(" N"); SERIAL_PROTOCOL(gcode_LastN);
+    SERIAL_PROTOCOLPGM(" S"); SERIAL_PROTOCOLLN(commands_in_queue);
+  #endif
 }
 
 void get_coordinates() {