Microduino

Dependencies:   mbed

Fork of BalanceCar by Li Weiyi

Committer:
lixianyu
Date:
Sat Jun 04 03:16:52 2016 +0000
Revision:
0:a4d8f5b3c546
Pass compile!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lixianyu 0:a4d8f5b3c546 1 #ifndef _MICRODUINO_PROTOCOL_HARDSER_H
lixianyu 0:a4d8f5b3c546 2 #define _MICRODUINO_PROTOCOL_HARDSER_H
lixianyu 0:a4d8f5b3c546 3
lixianyu 0:a4d8f5b3c546 4 #include "mbed.h"
lixianyu 0:a4d8f5b3c546 5
lixianyu 0:a4d8f5b3c546 6 #define PRO_PORT Serial
lixianyu 0:a4d8f5b3c546 7
lixianyu 0:a4d8f5b3c546 8 enum p_sta {
lixianyu 0:a4d8f5b3c546 9 P_ERROR,
lixianyu 0:a4d8f5b3c546 10 P_BUSY,
lixianyu 0:a4d8f5b3c546 11 P_NONE,
lixianyu 0:a4d8f5b3c546 12 P_FINE,
lixianyu 0:a4d8f5b3c546 13 P_TIMEOUT,
lixianyu 0:a4d8f5b3c546 14 };
lixianyu 0:a4d8f5b3c546 15
lixianyu 0:a4d8f5b3c546 16 #define MODE_WHILE 1
lixianyu 0:a4d8f5b3c546 17 #define MODE_LOOP 0
lixianyu 0:a4d8f5b3c546 18
lixianyu 0:a4d8f5b3c546 19 #define BUFFER_MAX 256
lixianyu 0:a4d8f5b3c546 20 #define CHANNEL_NUM 8
lixianyu 0:a4d8f5b3c546 21 #define TYPE_NUM 0xC8
lixianyu 0:a4d8f5b3c546 22
lixianyu 0:a4d8f5b3c546 23 class Protocol {
lixianyu 0:a4d8f5b3c546 24 public:
lixianyu 0:a4d8f5b3c546 25 Protocol(PRO_PORT *ser , uint8_t _channel) : num(0),time(0),sta(false),error(false){ // Constructor when using HardwareSerial
lixianyu 0:a4d8f5b3c546 26 // common_init(); // Set everything to common state, then...
lixianyu 0:a4d8f5b3c546 27 channel = _channel;
lixianyu 0:a4d8f5b3c546 28 num = 0;
lixianyu 0:a4d8f5b3c546 29 sta = false;
lixianyu 0:a4d8f5b3c546 30 error = false;
lixianyu 0:a4d8f5b3c546 31 P_Serial = ser; // ...override P_Serial with value passed.
lixianyu 0:a4d8f5b3c546 32 //_timer.start();
lixianyu 0:a4d8f5b3c546 33 }
lixianyu 0:a4d8f5b3c546 34 void begin(uint16_t _baud);
lixianyu 0:a4d8f5b3c546 35 uint8_t parse(uint16_t* _data, bool _mod);
lixianyu 0:a4d8f5b3c546 36
lixianyu 0:a4d8f5b3c546 37 private:
lixianyu 0:a4d8f5b3c546 38 uint8_t inChar, inCache;
lixianyu 0:a4d8f5b3c546 39 uint8_t buffer[BUFFER_MAX];
lixianyu 0:a4d8f5b3c546 40 uint8_t channel;
lixianyu 0:a4d8f5b3c546 41 uint32_t num ;
lixianyu 0:a4d8f5b3c546 42 uint32_t time;
lixianyu 0:a4d8f5b3c546 43 bool sta;
lixianyu 0:a4d8f5b3c546 44 bool error;
lixianyu 0:a4d8f5b3c546 45
lixianyu 0:a4d8f5b3c546 46 bool available(bool _sta);
lixianyu 0:a4d8f5b3c546 47 PRO_PORT *P_Serial;
lixianyu 0:a4d8f5b3c546 48
lixianyu 0:a4d8f5b3c546 49
lixianyu 0:a4d8f5b3c546 50 };
lixianyu 0:a4d8f5b3c546 51
lixianyu 0:a4d8f5b3c546 52
lixianyu 0:a4d8f5b3c546 53 #endif