![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Microduino的cube小车。
Diff: Protocol.h
- Revision:
- 3:e4ac7c1a14de
- Parent:
- 1:758ccab13947
- Child:
- 4:0670023d3f36
--- a/Protocol.h Wed May 25 13:25:09 2016 +0000 +++ b/Protocol.h Fri May 27 01:44:31 2016 +0000 @@ -1,22 +1,9 @@ -//#include "Arduino.h" +#include "Microduino_Protocol_HardSer.h" //BLE////////////////////// -#ifdef BLE_SoftSerial -#include <Microduino_Protocol_SoftSer.h> -#include <SoftwareSerial.h> -SoftwareSerial mySerial(4, -1); // RX, TX (D5与电机冲突 屏蔽 只用RX) -Protocol bleProtocol(&mySerial, TYPE_NUM); //软串口,校验数据类 -#else -#include <Microduino_Protocol_HardSer.h> -Protocol bleProtocol(&BLE_HardSerial, TYPE_NUM); //软串口,校验数据类 -#endif +Serial pc(P0_4,P0_0); +Protocol bleProtocol(&pc, TYPE_NUM); //软串口,校验数据类 -//nRF////////////////////// -#include <RF24Network.h> -#include <RF24.h> -#include <SPI.h> -RF24 radio(9, 10); -RF24Network network(radio); #define this_node 1 //设置本机ID #define other_node 0 struct send_a { //发送 @@ -33,60 +20,32 @@ BLE }; -bool protocolSetup() +bool protocolSetup(void) { - SPI.begin(); //初始化SPI总线 - radio.begin(); - if (radio.isPVariant()) { - network.begin(NRF_CHANNEL, this_node); - return NRF; - } else { - bleProtocol.begin(BLE_SPEED); - return BLE; - } + bleProtocol.begin(BLE_SPEED); + return BLE; } bool protocolRead(uint16_t *_channel, bool _mode) { - if (_mode == NRF) { - network.update(); - while ( network.available() ) { - RF24NetworkHeader header; - receive_a rec; - network.read(header, &rec, sizeof(rec)); - for (int a = 0; a < CHANNEL_NUM; a++) { - _channel[a] = rec.rf_CH[a]; - } - - { - send_a sen = { millis() }; //把这些数据发送出去,对应前面的发送数组 - RF24NetworkHeader header(other_node); - if (network.write(header, &sen, sizeof(sen))) { - return true; - } - } - } - } else { - switch (bleProtocol.parse(_channel, MODE_WHILE)) { - case P_NONE: //DATA NONE - break; - case P_FINE: //DATA OK - return true; - break; - case P_ERROR: //DATA ERROR + switch (bleProtocol.parse(_channel, MODE_WHILE)) { + case P_NONE: //DATA NONE + break; + case P_FINE: //DATA OK + return true; + break; + case P_ERROR: //DATA ERROR #ifdef BLE_SoftSerial - mySerial.stopListening(); - mySerial.listen(); + mySerial.stopListening(); + mySerial.listen(); #endif - break; - case P_TIMEOUT: //DATA TIMEOUT + break; + case P_TIMEOUT: //DATA TIMEOUT #ifdef BLE_SoftSerial - mySerial.stopListening(); - mySerial.listen(); + mySerial.stopListening(); + mySerial.listen(); #endif - break; - } + break; } - return false; }