diff -r b4658776abb6 -r 9ffa9d727d80 src/hp34comm.cpp --- a/src/hp34comm.cpp Tue Dec 05 00:59:57 2017 +0100 +++ b/src/hp34comm.cpp Mon Nov 05 23:18:37 2018 +0100 @@ -10,24 +10,15 @@ #endif -DigitalOut lled(LED1); +DigitalOut lled(LED3); #define RXTIMEOUT 0.05 #define STARTUPRETRY 0.5 + const uint8_t startup_seq[] = { 0x33, - 0x01, - 0x01, - 0x40, - // 0x02, -}; - -const uint8_t startup_seq2[] = { - 0x33, 0x02, 0x00, - 0x00, - // 0x02, }; HPSerial::statemethod HPSerial::state_table[NUM_STATES] = { @@ -44,16 +35,13 @@ cur_gstate(GSTATE_IDLE), ncmd(0) { - serial.baud(187500); + serial.baud(187500); cur_state = STATE_IDLE; serial.attach(callback(this, &HPSerial::rxIrq), Serial::RxIrq); } void HPSerial::startup(void) { - if (cur_gstate != GSTATE_STARTING) { - //_startup(); - cur_gstate = GSTATE_STARTING; - } + cur_gstate = GSTATE_STARTING; set_timer(0.002); // launch the startup in 10ms } @@ -68,17 +56,6 @@ cur_state = do_state_sending(); } -void HPSerial::_startup2(void) -{ - cur_gstate = GSTATE_STARTING2; - tr_data.size = sizeof(startup_seq2); - tr_data.cmd = 0xFF; - tr_data.pos = 0; - for(uint8_t i=0; i @@ -111,7 +88,7 @@ } unsigned int HPSerial::nerrors(uint8_t errorno) -{ +{ return errs[errorno]; } @@ -171,7 +148,7 @@ if (c == 0x86) { // shutdown pushCmd(tr_data.cmd, tr_data.size, tr_data.payload); return HPSerial::STATE_IDLE; - } + } return STATE_PAYLOAD_SIZE; } @@ -198,15 +175,15 @@ { // ghee if (c == 0xFF) - { - tr_data.pos--; - tr_data.payload[tr_data.pos] += 1; - } + { // resend current char + tr_data.pos--; + tr_data.payload[tr_data.pos] += 1; + } // TODO: check ACK values (c is the received ack) if (tr_data.pos >= tr_data.size) - { - return do_state_eot(); - } + { + return do_state_eot(); + } serial.putc(tr_data.payload[tr_data.pos++]); set_timer(RXTIMEOUT); return HPSerial::STATE_SENDING; @@ -214,15 +191,9 @@ HPSerial::state_t HPSerial::do_state_eot(uint8_t c) { - serial.putc(0x55); // EoT - if (cur_gstate == GSTATE_STARTING) { - cur_gstate = GSTATE_STARTING2; - set_timer(0.002); // launch startup2 in 10ms - } - else { - cur_gstate = GSTATE_IDLE; - set_timer(); // We are IDLE, detach the timeouter - } + serial.putc(0x55); // EoT + cur_gstate = GSTATE_IDLE; + set_timer(); // We are IDLE, detach the timeouter return STATE_IDLE; } @@ -234,15 +205,16 @@ void HPSerial::rxIrq(void) { uint8_t val; - if(serial.readable()) { // no reason why we would end here without - // this condition, but hey + if(serial.readable()) + { // no reason why we would end here without + // this condition, but hey #ifdef DEBUG2 inrx=1; #endif - lled = 1; + //lled = 1; val = serial.getc(); cur_state = run_state(cur_state, val); - lled = 0; + //lled = 0; #ifdef DEBUG2 inrx=0; #endif @@ -254,13 +226,9 @@ set_timer(); // detach the timeouter if (cur_gstate == GSTATE_STARTING) _startup(); - else if (cur_gstate == GSTATE_STARTING2) - _startup2(); else // reset { cur_gstate = GSTATE_IDLE; cur_state = STATE_IDLE; } } - -