Aegle / Mbed 2 deprecated Nucleo_BC127_DEBUG

Dependencies:   mbed

Revision:
2:38b75c9771fc
Parent:
1:9468a44a1815
Child:
3:ec621d656d40
--- a/main.cpp	Sun Apr 26 22:49:31 2015 +0000
+++ b/main.cpp	Tue Apr 28 16:21:36 2015 +0000
@@ -1,6 +1,8 @@
 #include "mbed.h"
 #include<string>
 /*
+Consider adding:
+
 DEV_INFO =
 ACCESSORY_NAME=Arc Chest Strap
 MANUFACTURER_NAME=Aegle
@@ -8,52 +10,37 @@
 SERIAL_NO=0000000000
 HARDWARE_VER=0 5 2 
 FIRMWARE_VER=0 5 2
-
-ENABLE_A2DP=(value)
-ENABLE_AVRCP=(value)
-ENABLE_HFP=(value)
-ENABLE_HFP_WBS=(value)
-ENABLE_IAP=(value)
-ENABLE_IAP_V2=(value)
-ENABLE_MAP=(value)
-ENABLE_SPP=(value)
 */
-const string protocolCommands[9]={"ENABLE_A2DP",
-        "ENABLE_AVRCP",
-        "ENABLE_HFP",
-        "ENABLE_HFP_WBS",
-        "ENABLE_IAP",
-        "ENABLE_IAP_V2",
-        "ENABLE_MAP",
-        "ENABLE_SPP"
-        };
 
 //LED
 PwmOut stm_led(LED1);
 //Bluetooth
-Serial bluetooth(PB_6,PA_10);//pc(USBTX,USBRX); //tx,rx 
-Serial pc(SERIAL_TX, SERIAL_RX);//pc(USBTX,USBRX); //tx,rx 
+Serial bluetooth(PB_6,PA_10);
+Serial pc(SERIAL_TX, SERIAL_RX);
 
-// consider using "RawSerial" instead of "Serial" if/when transmitting char's
 DigitalOut bt_pair(PA_7);
 DigitalOut bt_reset(PA_9);
-DigitalOut rts(PA_8); //Bug, nets are swapped on the 5.02
-DigitalIn cts(PB_10); //Bug, nets are swapped on the 5.02
+DigitalOut rts(PA_8); 
+DigitalIn cts(PB_10);
 Timer timeout;
 char responseBuff[4];
 char responseOk[4] = {'\r','\n','K','O'};
 bool BC127_confirm = false;
 
-
 bool bluetooth_command(string command){
-    BC127_confirm=false;
+    bluetooth.printf("%s\r",command);
     timeout.reset();
     timeout.start();
-    bluetooth.printf("%s\r",command);
-    while(timeout.read_ms()<2000){
+    while(timeout.read_ms()<500){
         if(memcmp(&responseOk[0],&responseBuff[0],4) == 0){
-            pc.printf("%dms/r",timeout.read_ms());
+            pc.printf("%d ms\r",timeout.read_ms());
             timeout.stop();
+            //Shift buffer by one to insure previous responses don't interfere
+            for(int z=2;z>0;z--){
+                responseBuff[z+1]=responseBuff[z];
+            }
+            responseBuff[1]=responseBuff[0];
+            responseBuff[0]=0;
             return true;
         }    
     }
@@ -103,36 +90,48 @@
     //wait(2);
 }
 void readResponse(){
-    stm_led=!stm_led;
     for(int z=2;z>0;z--){
         responseBuff[z+1]=responseBuff[z];
     }
     responseBuff[1]=responseBuff[0];
     responseBuff[0]=bluetooth.getc();
     pc.putc(responseBuff[0]);
-    if(memcmp(&responseOk[0],&responseBuff[0],4) == 0){
-        pc.printf("YA/r/r");
-        BC127_confirm=true;
-    }    
+}
+
+void writeResponse(){
+    bluetooth.putc(pc.getc());
 }
 int main() {
     bluetoothInitializer();
     bluetooth.attach(&readResponse);
+    pc.attach(&writeResponse);
     wait(5);
     pc.printf("Starting\r");
     bool debug=true;
     stm_led=1;
     wait(1);
     pc.printf("Atempting to send command\r");
-    debug&=bluetooth_command("SET ENABLE_SPP=OFF");
-    //bluetooth.printf("SET ENABLE_SPP=OFF\r");
-    wait(2);
-    //debug&=bluetooth_command("WRITE");
-    //debug&=bluetooth_command("RESET");
-    pc.printf("Finished sending command\r");
+    bluetooth_command("RESTORE");
+    debug&=bluetooth_command("SET NAME=BC127 BLE");
+    debug&=bluetooth_command("SET NAME_SHORT=BCBLE");
+    debug&=bluetooth_command("SET ENABLE_SPP=ON");
+
+    debug&=bluetooth_command("SET ENABLE_IAP=OFF");
+    debug&=bluetooth_command("SET ENABLE_IAP_V2=OFF");
+    debug&=bluetooth_command("SET ENABLE_MAP=OFF");
+    debug&=bluetooth_command("SET BLE_ROLE=1");
+    debug&=bluetooth_command("ADVERTISING ON");
+    debug&=bluetooth_command("WRITE");
+    bluetooth_command("RESET");
+    wait(.1);
+    pc.printf("Finished sending commands\r");
+    bluetooth.printf("config\r");
     while(1) {
-        if(debug){
+        if(debug==true){
         stm_led=!stm_led;
+        wait(2);
+        //bluetooth.printf("SEND BLE HelloWorld\r");
+        //Results in "ERROR" from BC127
         }
     }
 }
\ No newline at end of file