p kj
/
MKS22-CubeFine
LPC824
Fork of CubeFine by
Microduino_Protocol_HardSer.h@2:7964622fb5a5, 2016-07-04 (annotated)
- Committer:
- beian10
- Date:
- Mon Jul 04 07:17:39 2016 +0000
- Revision:
- 2:7964622fb5a5
- Parent:
- 0:362c1482232c
V2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lixianyu | 0:362c1482232c | 1 | #ifndef _MICRODUINO_PROTOCOL_HARDSER_H |
lixianyu | 0:362c1482232c | 2 | #define _MICRODUINO_PROTOCOL_HARDSER_H |
lixianyu | 0:362c1482232c | 3 | |
lixianyu | 0:362c1482232c | 4 | #include "mbed.h" |
lixianyu | 0:362c1482232c | 5 | |
lixianyu | 0:362c1482232c | 6 | #define PRO_PORT Serial |
lixianyu | 0:362c1482232c | 7 | |
lixianyu | 0:362c1482232c | 8 | enum p_sta { |
lixianyu | 0:362c1482232c | 9 | P_ERROR, |
lixianyu | 0:362c1482232c | 10 | P_BUSY, |
lixianyu | 0:362c1482232c | 11 | P_NONE, |
lixianyu | 0:362c1482232c | 12 | P_FINE, |
lixianyu | 0:362c1482232c | 13 | P_TIMEOUT, |
lixianyu | 0:362c1482232c | 14 | }; |
lixianyu | 0:362c1482232c | 15 | |
lixianyu | 0:362c1482232c | 16 | #define MODE_WHILE 1 |
lixianyu | 0:362c1482232c | 17 | #define MODE_LOOP 0 |
lixianyu | 0:362c1482232c | 18 | |
lixianyu | 0:362c1482232c | 19 | #define BUFFER_MAX 256 |
lixianyu | 0:362c1482232c | 20 | #define CHANNEL_NUM 8 |
lixianyu | 0:362c1482232c | 21 | #define TYPE_NUM 0xC8 |
lixianyu | 0:362c1482232c | 22 | |
lixianyu | 0:362c1482232c | 23 | class Protocol { |
lixianyu | 0:362c1482232c | 24 | public: |
lixianyu | 0:362c1482232c | 25 | Protocol(PRO_PORT *ser , uint8_t _channel) : num(0),time(0),sta(false),error(false){ // Constructor when using HardwareSerial |
lixianyu | 0:362c1482232c | 26 | // common_init(); // Set everything to common state, then... |
lixianyu | 0:362c1482232c | 27 | channel = _channel; |
lixianyu | 0:362c1482232c | 28 | num = 0; |
lixianyu | 0:362c1482232c | 29 | sta = false; |
lixianyu | 0:362c1482232c | 30 | error = false; |
lixianyu | 0:362c1482232c | 31 | P_Serial = ser; // ...override P_Serial with value passed. |
lixianyu | 0:362c1482232c | 32 | //_timer.start(); |
lixianyu | 0:362c1482232c | 33 | } |
lixianyu | 0:362c1482232c | 34 | void begin(uint16_t _baud); |
lixianyu | 0:362c1482232c | 35 | uint8_t parse(uint16_t* _data, bool _mod); |
lixianyu | 0:362c1482232c | 36 | |
lixianyu | 0:362c1482232c | 37 | private: |
lixianyu | 0:362c1482232c | 38 | uint8_t inChar, inCache; |
lixianyu | 0:362c1482232c | 39 | uint8_t buffer[BUFFER_MAX]; |
lixianyu | 0:362c1482232c | 40 | uint8_t channel; |
lixianyu | 0:362c1482232c | 41 | uint32_t num ; |
lixianyu | 0:362c1482232c | 42 | uint32_t time; |
lixianyu | 0:362c1482232c | 43 | bool sta; |
lixianyu | 0:362c1482232c | 44 | bool error; |
lixianyu | 0:362c1482232c | 45 | |
lixianyu | 0:362c1482232c | 46 | bool available(bool _sta); |
lixianyu | 0:362c1482232c | 47 | PRO_PORT *P_Serial; |
lixianyu | 0:362c1482232c | 48 | |
lixianyu | 0:362c1482232c | 49 | |
lixianyu | 0:362c1482232c | 50 | }; |
lixianyu | 0:362c1482232c | 51 | |
lixianyu | 0:362c1482232c | 52 | |
lixianyu | 0:362c1482232c | 53 | #endif |