Tue, 11 Oct 2016 21:49:43 +0200
[hp34comm] fix key stroke reception code
was not correct
5 | 1 | #ifndef HP34COMM_H |
2 | #define HP34COMM_H | |
3 | ||
4 | #include "mbed.h" | |
5 | #include "CircularBuffer.h" | |
6 | ||
7 | /***** HP 34970A communication class ***/ | |
8 | ||
9 | #define MAX_ERRS 10 | |
8 | 10 | #define MAX_BUFF 16 |
11 | #define BUF_SIZE 16 | |
5 | 12 | |
13 | class HPSerial { | |
14 | ||
15 | public: | |
16 | enum TrState { | |
17 | Idle = 0, | |
18 | Tx, | |
19 | Rx, | |
20 | }; | |
21 | typedef struct _CMD | |
22 | { | |
23 | TrState direction; | |
24 | uint8_t cmd; | |
25 | uint8_t size; | |
26 | char value[MAX_BUFF+1]; | |
27 | unsigned long id; | |
28 | } CMD; | |
29 | ||
30 | ||
31 | ||
10 | 32 | HPSerial(PinName rx); |
5 | 33 | |
34 | bool cmd_available(void); | |
35 | bool pop(CMD& cmd); | |
36 | bool cmd_buf_full(void); | |
37 | unsigned int nerrors(uint8_t errorno); | |
38 | ||
39 | ||
40 | private: | |
41 | void reset(uint8_t errorno=0xFF); | |
42 | void handleAck(uint8_t val); | |
43 | void pushCmd(TrState direction, uint8_t cmd, uint8_t size, char *payload); | |
44 | void handleChar(uint8_t val); | |
45 | void setstatedbg(void); | |
46 | void rxIrq(void); | |
47 | void timeout(void); | |
48 | ||
49 | private: | |
50 | RawSerial serial_rx; | |
51 | uint8_t buf[BUF_SIZE]; | |
52 | uint8_t head; | |
53 | uint8_t tx_state; | |
54 | uint8_t tx_cmd; | |
55 | uint8_t tx_len; | |
56 | bool tx_ack; | |
57 | CircularBuffer<CMD, 32> cmdbuf; | |
58 | unsigned long ncmd; | |
59 | unsigned int errs[MAX_ERRS]; | |
60 | Ticker timeouter; | |
61 | }; | |
62 | ||
63 | #endif |