diff -r 5cf4034ba4e0 -r 55021f3f1929 src/hp34comm.cpp~ --- a/src/hp34comm.cpp~ Fri Sep 23 21:12:43 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,241 +0,0 @@ - -#include "hp34comm.h" - -/***** HP 34970A communication class ***/ - - - - -HPSerial::HPSerial(): - ncmd(0), - serial_tx(NC, HP_SERIAL_TX), serial_rx(NC, HP_SERIAL_RX) { - - //pc.printf("HPSerial init\n"); - - for(uint8_t i=0; i 0) { - // a payload char - buf[head++] = val; - tx_len--; - tx_ack = false; - } - else { // end of payload, manage sent content - uint8_t cur_state = tx_state; - pushCmd(tx_state, tx_cmd, head, buf); - - switch(val) { - case 0x66: // a new transmisson - reset(); - tx_state = cur_state; - setstatedbg(); - break; - case 0x55: - reset(); - break; - default: - reset(6); - break; - } - } -} - - - -void HPSerial::setstatedbg(void) { - /* - if (tx_state == Rx) - staterx = 1; - else - staterx = 0; - if (tx_state == Tx) - statetx = 1; - else - statetx = 0; - */ -} - -void HPSerial::rxIrq(void) { - uint8_t val; - if(serial_rx.readable()) { // no reason why we would end here without this condition, but hey -#ifdef DEBUG - inrx=1; -#endif - val = serial_rx.getc(); - - timeouter.attach(this, &HPSerial::timeout, 0.001); // if nothing else happen in the next ms, reset - - if (tx_state == Idle) - if (val == 0x66) { - // no transmission in progress, expect a start of transmission - tx_state = Rx; - tx_ack = false; - setstatedbg(); - } - else - reset(4); - - else if (tx_state == Tx) // manage the acks - handleAck(val); - - else - handleChar(val); -#ifdef DEBUG - inrx=0; -#endif - } -} - -void HPSerial::txIrq(void) { - uint8_t val; - if(serial_tx.readable()) { // no reason why we would end here without this condition, but hey -#ifdef DEBUG - intx=1; -#endif - val = serial_tx.getc(); - - timeouter.attach(this, &HPSerial::timeout, 0.001); // if nothing else happen in the next ms, reset - - if (tx_state == Idle) - if (val == 0x66) { - // no transmission in progress, expect a start of transmission - tx_state = Tx; - tx_ack = false; - setstatedbg(); - } - else - reset(5); - - else if (tx_state == Rx) // manage the acks - handleAck(val); - - else - handleChar(val); - } -#ifdef DEBUG - intx=0; -#endif -} - -void HPSerial::timeout(void) { - if (tx_state != Idle) { - reset(7); - } -}