init

Dependencies:   BLE_API mbed nRF51822

Revision:
2:2a2b4781cd8a
Parent:
1:30f1232e4c17
Child:
3:88f7aa6c2a75
--- a/main.cpp	Mon Jul 27 07:30:59 2015 +0000
+++ b/main.cpp	Mon Jul 27 13:30:01 2015 +0000
@@ -23,16 +23,15 @@
 #define BLE_CHECK(X)  (X == BLE_ERROR_NONE) ? (printf("{{success}}\r\n")) : printf("{{failure}} %s at line %u ERROR CODE: %u\r\n", #X, __LINE__, (X));
 #define BLE_EQUAL(X,Y) ((X)==(Y)) ? (printf("{{sucess}}\n")) : printf("{{failure}}\n");
 
-BLE        ble;
-Gap::Address_t address;
+BLE                 ble;
+Gap::Address_t      address;
 Gap::AddressType_t *addressType;
-DigitalOut myled(p21);
-Ticker tick;
+
 DiscoveredCharacteristic HRMCharacteristic;
-bool HRMFound = false;
+bool HRMFound =          false;
 DiscoveredCharacteristic LEDCharacteristic;
-bool LEDFound = false;
-Gap::Handle_t aHandle;
+bool LEDFound =          false;
+Gap::Handle_t            deviceAHandle;
 
 void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) {
     for (int i = 0; i < 5; i++){
@@ -40,7 +39,6 @@
             return;    
         }
     }
-    //BLE_CHECK(ble.gap().connect(params->peerAddr,Gap::ADDR_TYPE_RANDOM_STATIC,NULL,NULL));
 }
 
 void serviceDiscoveryCallback(const DiscoveredService *service) {
@@ -71,7 +69,7 @@
     printf("Connected to: %d:%d:%d:%d:%d:%d\n", params->peerAddr[0], params->peerAddr[1], params->peerAddr[2], params->peerAddr[3], params->peerAddr[4], params->peerAddr[5]); 
     if (params->role == Gap::CENTRAL) {
 //        ble.gattClient().onServiceDiscoveryTermination(discoveryTerminationCallback);
-        aHandle = params->handle;
+        deviceAHandle = params->handle;
         BLE_CHECK(ble.gattClient().launchServiceDiscovery(params->handle, serviceDiscoveryCallback, characteristicDiscoveryCallback));
         //BLE_CHECK(ble.gattClient().launchServiceDiscovery(params->handle, serviceDiscoveryCallback, characteristicDiscoveryCallback, 0x180d, 0x2a37));
         //BLE_CHECK(ble.gattClient().launchServiceDiscovery(params->handle, serviceDiscoveryCallback, characteristicDiscoveryCallback, 0xA000, 0xA001));
@@ -96,6 +94,7 @@
 }
 
 void readTest(){
+    myled = 0;
     if (!(ble.gap().getState().connected)){
         printf("Devices must be connected before this test can be run\n");
         return;
@@ -119,7 +118,7 @@
 
 void disconnectTest(){
     if ((ble.gap().getState().connected)){
-        BLE_CHECK(ble.gap().disconnect(aHandle, Gap::REMOTE_USER_TERMINATED_CONNECTION));
+        BLE_CHECK(ble.gap().disconnect(deviceAHandle, Gap::REMOTE_USER_TERMINATED_CONNECTION));
     }
     else printf("Devices not connected\n");        
 }
@@ -130,8 +129,8 @@
         scanf("%s", command);
         if (!strcmp(command, "connect")) connectTest();
         else if (!strcmp(command, "disconnect")) disconnectTest();
-        else if (!strcmp(command, "read characteristics")) readTest();
-        else if (!strcmp(command, "write characteristics")) writeTest();
+        else if (!strcmp(command, "read")) readTest();
+        else if (!strcmp(command, "write")) writeTest();
     }    
 }
 
@@ -140,7 +139,6 @@
     myled = 1;
     printf("{{success}}" "\n" "{{end}}" "\n");
     ble.init();
-    
     scanf("%hhu",&address[0]);
     scanf("%hhu",&address[1]);
     scanf("%hhu",&address[2]);