src/hp34comm.h

changeset 44
b3c3d54d2c7c
parent 39
63c6a720cb97
child 49
c146d19101a3
equal deleted inserted replaced
43:c850674a3101 44:b3c3d54d2c7c
30 bool cmd_buf_full(void); 30 bool cmd_buf_full(void);
31 unsigned int nerrors(uint8_t errorno); 31 unsigned int nerrors(uint8_t errorno);
32 32
33 void startup(uint8_t keycode=0xFF); 33 void startup(uint8_t keycode=0xFF);
34 void sendkey(uint8_t keycode); 34 void sendkey(uint8_t keycode);
35 void send_key_when_idle();
35 36
36 private: 37 private:
37 void pushCmd(uint8_t cmd, uint8_t size, char *payload); 38 void pushCmd(uint8_t cmd, uint8_t size, char *payload);
38 void rxIrq(void); 39 void rx_irq(void);
39 void timeout(void); 40 void timeout(void);
40 void set_timer(Kernel::Clock::duration_u32 v=0ms) { 41 void set_timer(Kernel::Clock::duration_u32 v=0ms) {
41 timeouter.detach(); 42 timeouter.detach();
42 if (v > 0ms) 43 if (v > 0ms)
43 timeouter.attach(callback(this, &HPSerial::timeout), v); 44 timeouter.attach(callback(this, &HPSerial::timeout), v);
44 } 45 };
45 46
46 private: 47 private:
47 UnbufferedSerial serial; 48 UnbufferedSerial serial;
48 uint8_t buf[BUF_SIZE]; 49 uint8_t buf[BUF_SIZE];
49 uint8_t head; 50 uint8_t head;
50 CircularBuffer<CMD, 32> cmdbuf; 51 CircularBuffer<CMD, 32> cmdbuf;
52 CircularBuffer<uint8_t, 32> sendbuf;
51 unsigned long ncmd; 53 unsigned long ncmd;
52 unsigned int errs[MAX_ERRS]; 54 unsigned int errs[MAX_ERRS];
53 Ticker timeouter; 55 Ticker timeouter;
54 56
55 public: 57 public:
82 STATE_IDLE, 84 STATE_IDLE,
83 STATE_COMMAND, 85 STATE_COMMAND,
84 STATE_PAYLOAD_SIZE, 86 STATE_PAYLOAD_SIZE,
85 STATE_PAYLOAD, 87 STATE_PAYLOAD,
86 STATE_SENDING, 88 STATE_SENDING,
87 STATE_EOT,
88 NUM_STATES} state_t; 89 NUM_STATES} state_t;
89 state_t state() {return cur_state;}; 90 state_t state() {return cur_state;};
90 91
91 private: 92 private:
92 typedef struct state_data { 93 typedef struct state_data {
100 state_t do_state_initial(uint8_t c=0x00); 101 state_t do_state_initial(uint8_t c=0x00);
101 state_t do_state_command(uint8_t c); 102 state_t do_state_command(uint8_t c);
102 state_t do_state_payload_size(uint8_t c); 103 state_t do_state_payload_size(uint8_t c);
103 state_t do_state_payload(uint8_t c); 104 state_t do_state_payload(uint8_t c);
104 state_t do_state_sending(uint8_t c=0x00); 105 state_t do_state_sending(uint8_t c=0x00);
105 state_t do_state_eot(uint8_t c=0x55);
106 106
107 void send_ack(uint8_t c); 107 void send_ack(uint8_t c);
108 108
109 typedef state_t(HPSerial::*statemethod)(uint8_t c); 109 typedef state_t(HPSerial::*statemethod)(uint8_t c);
110 static statemethod state_table[NUM_STATES]; 110 static statemethod state_table[NUM_STATES];

mercurial