Aegle / Mbed 2 deprecated Nucleo_BC127_DEBUG

Dependencies:   mbed

Committer:
Dot
Date:
Fri May 01 16:13:20 2015 +0000
Revision:
4:51abc140d5d2
Parent:
3:ec621d656d40
Child:
5:ee564e17915b
Increased timeout time.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Dot 0:7df0c8b20953 1 #include "mbed.h"
Dot 0:7df0c8b20953 2 #include<string>
Dot 0:7df0c8b20953 3 /*
Dot 2:38b75c9771fc 4 Consider adding:
Dot 2:38b75c9771fc 5
Dot 0:7df0c8b20953 6 DEV_INFO =
Dot 0:7df0c8b20953 7 ACCESSORY_NAME=Arc Chest Strap
Dot 0:7df0c8b20953 8 MANUFACTURER_NAME=Aegle
Dot 0:7df0c8b20953 9 MODEL_NAME=Arc CS1
Dot 0:7df0c8b20953 10 SERIAL_NO=0000000000
Dot 0:7df0c8b20953 11 HARDWARE_VER=0 5 2
Dot 0:7df0c8b20953 12 FIRMWARE_VER=0 5 2
Dot 0:7df0c8b20953 13 */
Dot 0:7df0c8b20953 14
Dot 0:7df0c8b20953 15 //LED
Dot 0:7df0c8b20953 16 PwmOut stm_led(LED1);
Dot 0:7df0c8b20953 17 //Bluetooth
Dot 2:38b75c9771fc 18 Serial bluetooth(PB_6,PA_10);
Dot 2:38b75c9771fc 19 Serial pc(SERIAL_TX, SERIAL_RX);
Dot 0:7df0c8b20953 20
Dot 1:9468a44a1815 21 DigitalOut bt_pair(PA_7);
Dot 4:51abc140d5d2 22 DigitalOut bt_reset(PC_7);
Dot 3:ec621d656d40 23
Dot 0:7df0c8b20953 24 Timer timeout;
Dot 0:7df0c8b20953 25 char responseBuff[4];
Dot 0:7df0c8b20953 26 char responseOk[4] = {'\r','\n','K','O'};
Dot 1:9468a44a1815 27
Dot 0:7df0c8b20953 28 bool bluetooth_command(string command){
Dot 2:38b75c9771fc 29 bluetooth.printf("%s\r",command);
Dot 3:ec621d656d40 30 pc.printf("SENDING {%s}\r",command);
Dot 0:7df0c8b20953 31 timeout.reset();
Dot 0:7df0c8b20953 32 timeout.start();
Dot 4:51abc140d5d2 33 while(timeout.read_ms()<2000){
Dot 1:9468a44a1815 34 if(memcmp(&responseOk[0],&responseBuff[0],4) == 0){
Dot 2:38b75c9771fc 35 pc.printf("%d ms\r",timeout.read_ms());
Dot 0:7df0c8b20953 36 timeout.stop();
Dot 2:38b75c9771fc 37 //Shift buffer by one to insure previous responses don't interfere
Dot 2:38b75c9771fc 38 for(int z=2;z>0;z--){
Dot 2:38b75c9771fc 39 responseBuff[z+1]=responseBuff[z];
Dot 2:38b75c9771fc 40 }
Dot 2:38b75c9771fc 41 responseBuff[1]=responseBuff[0];
Dot 2:38b75c9771fc 42 responseBuff[0]=0;
Dot 1:9468a44a1815 43 return true;
Dot 0:7df0c8b20953 44 }
Dot 0:7df0c8b20953 45 }
Dot 0:7df0c8b20953 46 timeout.stop();
Dot 0:7df0c8b20953 47 return false;
Dot 0:7df0c8b20953 48 }
Dot 0:7df0c8b20953 49
Dot 0:7df0c8b20953 50 void ledBlink(int blinks,int delay){
Dot 0:7df0c8b20953 51 for(int i=2*blinks; i>0; i--){
Dot 0:7df0c8b20953 52 stm_led = !stm_led;
Dot 0:7df0c8b20953 53 wait_ms(delay);
Dot 0:7df0c8b20953 54 }
Dot 0:7df0c8b20953 55 }
Dot 0:7df0c8b20953 56
Dot 0:7df0c8b20953 57 void bluetoothInitializer(){
Dot 0:7df0c8b20953 58 bt_reset = 0;
Dot 0:7df0c8b20953 59 wait(0.5);
Dot 0:7df0c8b20953 60 bt_reset = 1;
Dot 0:7df0c8b20953 61 wait(0.5);
Dot 1:9468a44a1815 62 bt_pair =1;
Dot 1:9468a44a1815 63 wait(0.5);
Dot 1:9468a44a1815 64 bt_pair =0;
Dot 1:9468a44a1815 65 wait(0.5);
Dot 0:7df0c8b20953 66 }
Dot 0:7df0c8b20953 67 void readResponse(){
Dot 1:9468a44a1815 68 for(int z=2;z>0;z--){
Dot 1:9468a44a1815 69 responseBuff[z+1]=responseBuff[z];
Dot 1:9468a44a1815 70 }
Dot 1:9468a44a1815 71 responseBuff[1]=responseBuff[0];
Dot 1:9468a44a1815 72 responseBuff[0]=bluetooth.getc();
Dot 1:9468a44a1815 73 pc.putc(responseBuff[0]);
Dot 2:38b75c9771fc 74 }
Dot 2:38b75c9771fc 75
Dot 2:38b75c9771fc 76 void writeResponse(){
Dot 2:38b75c9771fc 77 bluetooth.putc(pc.getc());
Dot 0:7df0c8b20953 78 }
Dot 0:7df0c8b20953 79 int main() {
Dot 0:7df0c8b20953 80 bluetoothInitializer();
Dot 0:7df0c8b20953 81 bluetooth.attach(&readResponse);
Dot 2:38b75c9771fc 82 pc.attach(&writeResponse);
Dot 1:9468a44a1815 83 wait(5);
Dot 1:9468a44a1815 84 pc.printf("Starting\r");
Dot 1:9468a44a1815 85 bool debug=true;
Dot 1:9468a44a1815 86 stm_led=1;
Dot 0:7df0c8b20953 87 wait(1);
Dot 1:9468a44a1815 88 pc.printf("Atempting to send command\r");
Dot 4:51abc140d5d2 89
Dot 4:51abc140d5d2 90 bluetooth.printf("$$$$\r");
Dot 4:51abc140d5d2 91 wait(1);
Dot 4:51abc140d5d2 92
Dot 2:38b75c9771fc 93 bluetooth_command("RESTORE");
Dot 2:38b75c9771fc 94 debug&=bluetooth_command("SET NAME=BC127 BLE");
Dot 2:38b75c9771fc 95 debug&=bluetooth_command("SET NAME_SHORT=BCBLE");
Dot 2:38b75c9771fc 96 debug&=bluetooth_command("SET ENABLE_SPP=ON");
Dot 2:38b75c9771fc 97 debug&=bluetooth_command("SET ENABLE_IAP=OFF");
Dot 2:38b75c9771fc 98 debug&=bluetooth_command("SET ENABLE_IAP_V2=OFF");
Dot 2:38b75c9771fc 99 debug&=bluetooth_command("SET ENABLE_MAP=OFF");
Dot 2:38b75c9771fc 100 debug&=bluetooth_command("SET BLE_ROLE=1");
Dot 2:38b75c9771fc 101 debug&=bluetooth_command("ADVERTISING ON");
Dot 2:38b75c9771fc 102 debug&=bluetooth_command("WRITE");
Dot 2:38b75c9771fc 103 bluetooth_command("RESET");
Dot 2:38b75c9771fc 104 wait(.1);
Dot 2:38b75c9771fc 105 pc.printf("Finished sending commands\r");
Dot 2:38b75c9771fc 106 bluetooth.printf("config\r");
Dot 0:7df0c8b20953 107 while(1) {
Dot 2:38b75c9771fc 108 if(debug==true){
Dot 1:9468a44a1815 109 stm_led=!stm_led;
Dot 2:38b75c9771fc 110 wait(2);
Dot 2:38b75c9771fc 111 //bluetooth.printf("SEND BLE HelloWorld\r");
Dot 2:38b75c9771fc 112 //Results in "ERROR" from BC127
Dot 1:9468a44a1815 113 }
Dot 0:7df0c8b20953 114 }
Dot 0:7df0c8b20953 115 }