src/hp34comm.cpp

changeset 47
11c57010e4f9
parent 44
b3c3d54d2c7c
child 49
c146d19101a3
--- a/src/hp34comm.cpp	Sat Nov 07 19:22:04 2020 +0100
+++ b/src/hp34comm.cpp	Sat Nov 07 19:23:21 2020 +0100
@@ -185,11 +185,35 @@
 
 HPSerial::state_t HPSerial::do_state_sending(uint8_t c)
 {
-  // ghee
-  if (c == 0xFF)
+  // check the ack value returned by the main unit
+
+  if ((tr_data.pos == 1) && (tr_data.payload[0] == 0x66))
+  {
+	  if (c != 0x99)
+	  {
+		  //::printf("ACK ERROR %X [exp. %X]\n", c, ~(tr_data.payload[0]));
+          // did not received the expected ack
+		  if (c == 0x66)
+		  {
+			  // we received a start of transmission while trying to emit something,
+			  // ignore it, the correct ack should be sent but the main unit just behind...
+			  set_timer(RXTIMEOUT);
+			  return cur_state;
+		  }
+		  else
+		  {
+			  // not sure how this may happen, in doubt, try again
+			  tr_data.pos--;
+		  }
+	  }
+  }
+  /*
+  else if (c != 0x00)
   { // resend current char
-    tr_data.pos--;
+	  tr_data.pos--;
   }
+  */
+
   // TODO: check ACK values (c is the received ack)
   if (tr_data.pos >= tr_data.size)
   {

mercurial