Aegle / Mbed 2 deprecated Nucleo_BC127_DEBUG

Dependencies:   mbed

Committer:
Dot
Date:
Thu Apr 30 23:53:19 2015 +0000
Revision:
3:ec621d656d40
Parent:
2:38b75c9771fc
Child:
4:51abc140d5d2
k

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 3:ec621d656d40 22 DigitalOut bt_reset(PC_);
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 3:ec621d656d40 33 while(timeout.read_ms()<1000){
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 bluetooth.baud(9600);
Dot 0:7df0c8b20953 67 wait(.1);
Dot 0:7df0c8b20953 68 }
Dot 0:7df0c8b20953 69 void readResponse(){
Dot 1:9468a44a1815 70 for(int z=2;z>0;z--){
Dot 1:9468a44a1815 71 responseBuff[z+1]=responseBuff[z];
Dot 1:9468a44a1815 72 }
Dot 1:9468a44a1815 73 responseBuff[1]=responseBuff[0];
Dot 1:9468a44a1815 74 responseBuff[0]=bluetooth.getc();
Dot 1:9468a44a1815 75 pc.putc(responseBuff[0]);
Dot 2:38b75c9771fc 76 }
Dot 2:38b75c9771fc 77
Dot 2:38b75c9771fc 78 void writeResponse(){
Dot 2:38b75c9771fc 79 bluetooth.putc(pc.getc());
Dot 0:7df0c8b20953 80 }
Dot 0:7df0c8b20953 81 int main() {
Dot 0:7df0c8b20953 82 bluetoothInitializer();
Dot 0:7df0c8b20953 83 bluetooth.attach(&readResponse);
Dot 2:38b75c9771fc 84 pc.attach(&writeResponse);
Dot 1:9468a44a1815 85 wait(5);
Dot 1:9468a44a1815 86 pc.printf("Starting\r");
Dot 1:9468a44a1815 87 bool debug=true;
Dot 1:9468a44a1815 88 stm_led=1;
Dot 0:7df0c8b20953 89 wait(1);
Dot 1:9468a44a1815 90 pc.printf("Atempting to send command\r");
Dot 2:38b75c9771fc 91 bluetooth_command("RESTORE");
Dot 2:38b75c9771fc 92 debug&=bluetooth_command("SET NAME=BC127 BLE");
Dot 2:38b75c9771fc 93 debug&=bluetooth_command("SET NAME_SHORT=BCBLE");
Dot 2:38b75c9771fc 94 debug&=bluetooth_command("SET ENABLE_SPP=ON");
Dot 2:38b75c9771fc 95 debug&=bluetooth_command("SET ENABLE_IAP=OFF");
Dot 2:38b75c9771fc 96 debug&=bluetooth_command("SET ENABLE_IAP_V2=OFF");
Dot 2:38b75c9771fc 97 debug&=bluetooth_command("SET ENABLE_MAP=OFF");
Dot 2:38b75c9771fc 98 debug&=bluetooth_command("SET BLE_ROLE=1");
Dot 2:38b75c9771fc 99 debug&=bluetooth_command("ADVERTISING ON");
Dot 2:38b75c9771fc 100 debug&=bluetooth_command("WRITE");
Dot 2:38b75c9771fc 101 bluetooth_command("RESET");
Dot 2:38b75c9771fc 102 wait(.1);
Dot 2:38b75c9771fc 103 pc.printf("Finished sending commands\r");
Dot 2:38b75c9771fc 104 bluetooth.printf("config\r");
Dot 0:7df0c8b20953 105 while(1) {
Dot 2:38b75c9771fc 106 if(debug==true){
Dot 1:9468a44a1815 107 stm_led=!stm_led;
Dot 2:38b75c9771fc 108 wait(2);
Dot 2:38b75c9771fc 109 //bluetooth.printf("SEND BLE HelloWorld\r");
Dot 2:38b75c9771fc 110 //Results in "ERROR" from BC127
Dot 1:9468a44a1815 111 }
Dot 0:7df0c8b20953 112 }
Dot 0:7df0c8b20953 113 }