Li Weiyi
/
BalanceCar
虽然移植完毕,但是不work。需要细调……
Protocol.h@3:c6caae712d5d, 2016-06-07 (annotated)
- Committer:
- lixianyu
- Date:
- Tue Jun 07 08:14:15 2016 +0000
- Revision:
- 3:c6caae712d5d
- Parent:
- 0:a4d8f5b3c546
??????????work? ?????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lixianyu | 0:a4d8f5b3c546 | 1 | #include "Microduino_Protocol_HardSer.h" |
lixianyu | 0:a4d8f5b3c546 | 2 | |
lixianyu | 0:a4d8f5b3c546 | 3 | //BLE////////////////////// |
lixianyu | 0:a4d8f5b3c546 | 4 | Serial pc(P0_4,P0_0); |
lixianyu | 0:a4d8f5b3c546 | 5 | //Serial pc(P0_0, P0_4); |
lixianyu | 0:a4d8f5b3c546 | 6 | Protocol bleProtocol(&pc, TYPE_NUM); //软串口,校验数据类 |
lixianyu | 0:a4d8f5b3c546 | 7 | |
lixianyu | 0:a4d8f5b3c546 | 8 | #define this_node 1 //设置本机ID |
lixianyu | 0:a4d8f5b3c546 | 9 | #define other_node 0 |
lixianyu | 0:a4d8f5b3c546 | 10 | struct send_a { //发送 |
lixianyu | 0:a4d8f5b3c546 | 11 | uint32_t node_ms; //节点运行时间 |
lixianyu | 0:a4d8f5b3c546 | 12 | }; |
lixianyu | 0:a4d8f5b3c546 | 13 | struct receive_a { //接收 |
lixianyu | 0:a4d8f5b3c546 | 14 | uint32_t ms; |
lixianyu | 0:a4d8f5b3c546 | 15 | uint16_t rf_CH[CHANNEL_NUM]; |
lixianyu | 0:a4d8f5b3c546 | 16 | }; |
lixianyu | 0:a4d8f5b3c546 | 17 | |
lixianyu | 0:a4d8f5b3c546 | 18 | //Mode////////////////////// |
lixianyu | 0:a4d8f5b3c546 | 19 | enum _Mode { |
lixianyu | 0:a4d8f5b3c546 | 20 | NRF, |
lixianyu | 0:a4d8f5b3c546 | 21 | BLE |
lixianyu | 0:a4d8f5b3c546 | 22 | }; |
lixianyu | 0:a4d8f5b3c546 | 23 | |
lixianyu | 0:a4d8f5b3c546 | 24 | bool protocolSetup(void) |
lixianyu | 0:a4d8f5b3c546 | 25 | { |
lixianyu | 0:a4d8f5b3c546 | 26 | bleProtocol.begin(BLE_SPEED); |
lixianyu | 0:a4d8f5b3c546 | 27 | return BLE; |
lixianyu | 0:a4d8f5b3c546 | 28 | } |
lixianyu | 0:a4d8f5b3c546 | 29 | |
lixianyu | 0:a4d8f5b3c546 | 30 | bool protocolRead(uint16_t *_channel, bool _mode) |
lixianyu | 0:a4d8f5b3c546 | 31 | { |
lixianyu | 0:a4d8f5b3c546 | 32 | switch (bleProtocol.parse(_channel, MODE_WHILE)) { |
lixianyu | 0:a4d8f5b3c546 | 33 | case P_NONE: //DATA NONE |
lixianyu | 0:a4d8f5b3c546 | 34 | break; |
lixianyu | 0:a4d8f5b3c546 | 35 | case P_FINE: //DATA OK |
lixianyu | 0:a4d8f5b3c546 | 36 | return true; |
lixianyu | 0:a4d8f5b3c546 | 37 | break; |
lixianyu | 0:a4d8f5b3c546 | 38 | case P_ERROR: //DATA ERROR |
lixianyu | 0:a4d8f5b3c546 | 39 | #ifdef BLE_SoftSerial |
lixianyu | 0:a4d8f5b3c546 | 40 | mySerial.stopListening(); |
lixianyu | 0:a4d8f5b3c546 | 41 | mySerial.listen(); |
lixianyu | 0:a4d8f5b3c546 | 42 | #endif |
lixianyu | 0:a4d8f5b3c546 | 43 | break; |
lixianyu | 0:a4d8f5b3c546 | 44 | case P_TIMEOUT: //DATA TIMEOUT |
lixianyu | 0:a4d8f5b3c546 | 45 | #ifdef BLE_SoftSerial |
lixianyu | 0:a4d8f5b3c546 | 46 | mySerial.stopListening(); |
lixianyu | 0:a4d8f5b3c546 | 47 | mySerial.listen(); |
lixianyu | 0:a4d8f5b3c546 | 48 | #endif |
lixianyu | 0:a4d8f5b3c546 | 49 | break; |
lixianyu | 0:a4d8f5b3c546 | 50 | } |
lixianyu | 0:a4d8f5b3c546 | 51 | return false; |
lixianyu | 0:a4d8f5b3c546 | 52 | } |