Remove now dead/useless code draft

Tue, 10 Nov 2020 22:21:35 +0100

author
David Douard <david.douard@sdf3.org>
date
Tue, 10 Nov 2020 22:21:35 +0100
changeset 50
279868684eb3
parent 49
c146d19101a3
child 51
d8042bff0e00

Remove now dead/useless code

src/hp34comm.cpp file | annotate | diff | comparison | revisions
src/hp34comm.h file | annotate | diff | comparison | revisions
--- a/src/hp34comm.cpp	Mon Nov 09 23:05:24 2020 +0100
+++ b/src/hp34comm.cpp	Tue Nov 10 22:21:35 2020 +0100
@@ -8,13 +8,6 @@
 #define RXTIMEOUT 50ms
 #define STARTUPRETRY 0.5
 
-uint8_t startup_seq[] = {
-  0x33,
-  0x02,  // 0x02?
-  0x00,
-  0x00,
-};
-
 HPSerial::statemethod HPSerial::state_table[NUM_STATES] = {
   &HPSerial::do_state_initial,      // STATE_IDLE
   &HPSerial::do_state_command,      // STATE_COMMAND
@@ -36,34 +29,8 @@
   serial.attach(callback(this, &HPSerial::rx_irq), SerialBase::RxIrq);
 }
 
-void HPSerial::startup(uint8_t keycode) {
-  cur_gstate = GSTATE_STARTING;
 
-  if (keycode != 0xFF) {
-	  printf("Set startup keycode to %X\n", keycode);
-      startup_seq[2] = 0xFF;
-      startup_seq[3] = keycode;
-  }
-  else
-      startup_seq[2] = 0x00;
-  set_timer(10ms); // launch the startup in 10ms
-}
-
-void HPSerial::_startup(void)
-{
-  cur_gstate = GSTATE_STARTING;
-  tr_data.cmd = 0xFF;
-  tr_data.pos = 0;
-
-  if (startup_seq[2] == 0xFF)
-      tr_data.size = 4;
-  else
-      tr_data.size = 3; // sizeof(startup_seq);
-  for(uint8_t i=0; i<tr_data.size; i++)
-    tr_data.payload[i] = startup_seq[i];
-  cur_state = do_state_sending();
-}
-
+// SEND related methods
 void HPSerial::sendkey(uint8_t keycode)
 {
   if (!sendbuf.full())
@@ -72,14 +39,13 @@
 
 
 bool HPSerial::wait_for(uint8_t value)
-{
+{  // wait for an expected character in the serial port
   char c;
 
   for(uint8_t i=0; i<2; i++)
   {
     while(!serial.readable())
 		wait_us(10);
-	//ThisThread::sleep_for(0.1ms);
 	serial.read(&c, 1);
 	if (value == c)
 		return true;
@@ -87,6 +53,7 @@
   return false;
 }
 
+
 void HPSerial::send_pending_key() {
   uint8_t c;
 
@@ -119,6 +86,7 @@
   }
 }
 
+
 void HPSerial::send_startup_seq(uint8_t keycode) {
   uint8_t c;
 
@@ -153,6 +121,7 @@
 
 }
 
+
 void HPSerial::send_startup_seq() {
   uint8_t c;
 
@@ -182,41 +151,33 @@
   serial.attach(callback(this, &HPSerial::rx_irq), SerialBase::RxIrq);
 }
 
-void HPSerial::send_key_when_idle() {
-  if (!sendbuf.empty() && cur_gstate == GSTATE_IDLE)
-  {
-    uint8_t keycode;
-	cur_gstate = GSTATE_TX;
-	sendbuf.pop(keycode);
-	tr_data.size = 2;
-	tr_data.cmd = 0xFF;
-	tr_data.pos = 0;
-	tr_data.payload[0] = 0x66;
-	tr_data.payload[1] = keycode;
-	cur_state = do_state_sending();
-  }
-}
+
+// RECV related methods
 
 bool HPSerial::cmd_available(void)
 {
   return !cmdbuf.empty();
 }
 
+
 bool HPSerial::pop(CMD& cmd)
 {
   return cmdbuf.pop(cmd);
 }
 
+
 bool HPSerial::cmd_buf_full(void)
 {
   return cmdbuf.full();
 }
 
+
 unsigned int HPSerial::nerrors(uint8_t errorno)
 {
   return errs[errorno];
 }
 
+
 void HPSerial::pushCmd(uint8_t cmd, uint8_t size, char *payload) {
   CMD val;
   uint8_t i;
@@ -229,11 +190,13 @@
   cmdbuf.push(val);
 }
 
+
 void HPSerial::send_ack(uint8_t c) {
   serial.write(&c, 1);
   set_timer(RXTIMEOUT); // if nothing else happen in the next RXTIMEOUT ms, reset
 }
 
+
 HPSerial::state_t HPSerial::do_state_initial(uint8_t c)
 {
   // we are idle, incoming char is a handcheck
@@ -259,6 +222,7 @@
   }
 }
 
+
 HPSerial::state_t HPSerial::do_state_command(uint8_t c)
 {
   if (c == 0x55) { // EoT
@@ -277,6 +241,7 @@
   return STATE_PAYLOAD_SIZE;
 }
 
+
 HPSerial::state_t HPSerial::do_state_payload_size(uint8_t c)
 {
   tr_data.size = c;
@@ -285,6 +250,7 @@
   return STATE_PAYLOAD;
 }
 
+
 HPSerial::state_t HPSerial::do_state_payload(uint8_t c)
 {
   tr_data.payload[tr_data.pos++] = c;
@@ -296,6 +262,7 @@
   return STATE_PAYLOAD;
 }
 
+
 HPSerial::state_t HPSerial::do_state_sending(uint8_t c)
 {
   // check the ack value returned by the main unit
@@ -304,7 +271,6 @@
   {
 	  if (c != 0x99)
 	  {
-		  //::printf("ACK ERROR %X [exp. %X]\n", c, ~(tr_data.payload[0]));
           // did not received the expected ack
 		  if (c == 0x66)
 		  {
@@ -344,12 +310,14 @@
   }
 }
 
+
 HPSerial::state_t HPSerial::run_state(HPSerial::state_t cur_state,
 									  uint8_t c)
 {
   return (this->*(HPSerial::state_table[cur_state]))(c);
 };
 
+
 void HPSerial::rx_irq(void) {
   uint8_t val;
   if(serial.readable())
@@ -367,11 +335,6 @@
 
 void HPSerial::timeout(void) {
   set_timer(); // detach the timeouter
-  if (cur_gstate == GSTATE_STARTING)
-    _startup();
-  else // CPU took too long to reply, reset
-    {
-    cur_gstate = GSTATE_IDLE;
-    cur_state = STATE_IDLE;
-    }
+  cur_gstate = GSTATE_IDLE;
+  cur_state = STATE_IDLE;
 }
--- a/src/hp34comm.h	Mon Nov 09 23:05:24 2020 +0100
+++ b/src/hp34comm.h	Tue Nov 10 22:21:35 2020 +0100
@@ -30,9 +30,7 @@
   bool cmd_buf_full(void);
   unsigned int nerrors(uint8_t errorno);
 
-  void startup(uint8_t keycode=0xFF);
   void sendkey(uint8_t keycode);
-  void send_key_when_idle();
   void send_startup_seq();
   void send_startup_seq(uint8_t keycode);
 
@@ -104,7 +102,6 @@
     char payload[MAX_BUFF];
   } state_data_t;
 
-  void _startup(void);
   state_t do_state_initial(uint8_t c=0x00);
   state_t do_state_command(uint8_t c);
   state_t do_state_payload_size(uint8_t c);

mercurial