LPC824

Dependencies:   mbed

Fork of CubeFine by wu le

Committer:
lixianyu
Date:
Thu Jun 02 04:03:31 2016 +0000
Revision:
0:362c1482232c
Child:
1:54a2d380f8c7
work fine.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lixianyu 0:362c1482232c 1 #include "Microduino_Protocol_HardSer.h"
lixianyu 0:362c1482232c 2
lixianyu 0:362c1482232c 3 //BLE//////////////////////
lixianyu 0:362c1482232c 4 Serial pc(P0_4,P0_0);
lixianyu 0:362c1482232c 5 //Serial pc(P0_0, P0_4);
lixianyu 0:362c1482232c 6 Protocol bleProtocol(&pc, TYPE_NUM); //软串口,校验数据类
lixianyu 0:362c1482232c 7
lixianyu 0:362c1482232c 8 #define this_node 1 //设置本机ID
lixianyu 0:362c1482232c 9 #define other_node 0
lixianyu 0:362c1482232c 10 struct send_a { //发送
lixianyu 0:362c1482232c 11 uint32_t node_ms; //节点运行时间
lixianyu 0:362c1482232c 12 };
lixianyu 0:362c1482232c 13 struct receive_a { //接收
lixianyu 0:362c1482232c 14 uint32_t ms;
lixianyu 0:362c1482232c 15 uint16_t rf_CH[CHANNEL_NUM];
lixianyu 0:362c1482232c 16 };
lixianyu 0:362c1482232c 17
lixianyu 0:362c1482232c 18 //Mode//////////////////////
lixianyu 0:362c1482232c 19 enum _Mode {
lixianyu 0:362c1482232c 20 NRF,
lixianyu 0:362c1482232c 21 BLE
lixianyu 0:362c1482232c 22 };
lixianyu 0:362c1482232c 23
lixianyu 0:362c1482232c 24 bool protocolSetup(void)
lixianyu 0:362c1482232c 25 {
lixianyu 0:362c1482232c 26 bleProtocol.begin(BLE_SPEED);
lixianyu 0:362c1482232c 27 return BLE;
lixianyu 0:362c1482232c 28 }
lixianyu 0:362c1482232c 29
lixianyu 0:362c1482232c 30 bool protocolRead(uint16_t *_channel, bool _mode)
lixianyu 0:362c1482232c 31 {
lixianyu 0:362c1482232c 32 switch (bleProtocol.parse(_channel, MODE_WHILE)) {
lixianyu 0:362c1482232c 33 case P_NONE: //DATA NONE
lixianyu 0:362c1482232c 34 break;
lixianyu 0:362c1482232c 35 case P_FINE: //DATA OK
lixianyu 0:362c1482232c 36 return true;
lixianyu 0:362c1482232c 37 break;
lixianyu 0:362c1482232c 38 case P_ERROR: //DATA ERROR
lixianyu 0:362c1482232c 39 #ifdef BLE_SoftSerial
lixianyu 0:362c1482232c 40 mySerial.stopListening();
lixianyu 0:362c1482232c 41 mySerial.listen();
lixianyu 0:362c1482232c 42 #endif
lixianyu 0:362c1482232c 43 break;
lixianyu 0:362c1482232c 44 case P_TIMEOUT: //DATA TIMEOUT
lixianyu 0:362c1482232c 45 #ifdef BLE_SoftSerial
lixianyu 0:362c1482232c 46 mySerial.stopListening();
lixianyu 0:362c1482232c 47 mySerial.listen();
lixianyu 0:362c1482232c 48 #endif
lixianyu 0:362c1482232c 49 break;
lixianyu 0:362c1482232c 50 }
lixianyu 0:362c1482232c 51 return false;
lixianyu 0:362c1482232c 52 }