Wouter van Kleunen / X_NUCLEO_IDB0XA1

Fork of X_NUCLEO_IDB0XA1 by ST

Files at this revision

API Documentation at this revision

Comitter:
Andrea Palmieri
Date:
Thu Mar 31 11:06:20 2016 +0200
Parent:
216:7aa807180321
Child:
218:48776140c30d
Commit message:
Fix GAP role and scanning procedure

Observer is only supported by X-NUCLEO-IDB05A1;
Minor change

Signed-off-by: Andrea Palmieri <andrea.palmieri@st.com>

Changed in this revision

source/BlueNRGGap.cpp Show annotated file Show diff for this revision Revisions of this file
x-nucleo-idb0xa1/BlueNRGGap.h Show annotated file Show diff for this revision Revisions of this file
--- a/source/BlueNRGGap.cpp	Thu Mar 31 10:17:31 2016 +0200
+++ b/source/BlueNRGGap.cpp	Thu Mar 31 11:06:20 2016 +0200
@@ -975,7 +975,7 @@
         return BLE_ERROR_NONE;
     }
 
-    PRINTF("setAppearance failed (ret=0x%x)!!\n\r", ret) ;
+    PRINTF("setAppearance failed (ret=0x%x)!!\n\r", ret);
     switch (ret) {
       case BLE_STATUS_INVALID_HANDLE:
       case BLE_STATUS_INVALID_PARAMETER:
@@ -1129,8 +1129,8 @@
         type = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED;
       }
     
-      PRINTF("adv peerAddr[%02x %02x %02x %02x %02x %02x] \r\n",
-           addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
+      PRINTF("data_length=%d adv peerAddr[%02x %02x %02x %02x %02x %02x] \r\n",
+             *data_length, addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
       processAdvertisementReport(addr, *RSSI, isScanResponse, type, *data_length, data);
       PRINTF("!!!After processAdvertisementReport\n\r");
     }
@@ -1147,11 +1147,20 @@
     // we need to delay the starting of connection or re-scanning procedures
     uint16_t delay = 2*(_scanningParams.getInterval());
 
+#ifdef AST_FOR_MBED_OS
     if(_connecting) {
       minar::Scheduler::postCallback(makeConnection).delay(minar::milliseconds(delay));
     } else {
       minar::Scheduler::postCallback(radioScanning).delay(minar::milliseconds(delay));
     }
+#else
+    Clock_Wait(delay);
+    if(_connecting) {
+      makeConnection();
+    } else {
+      radioScanning();
+    }
+#endif /* AST_FOR_MBED_OS */
 
     break;
   }
@@ -1163,36 +1172,35 @@
   tBleStatus ret = BLE_STATUS_SUCCESS;
   
   PRINTF("Scanning...\n\r");
-  
-  // We received a start scan request from the application level.
-  // If we are on X-NUCLEO-IDB04A1 (playing a single role at time),
-  // we need to re-init our expansion board to specify the GAP CENTRAL ROLE
-  if(!btle_reinited) {
-    btle_init(isSetAddress, GAP_CENTRAL_ROLE_IDB04A1);
-    btle_reinited = true;
-    
-    PRINTF("BTLE re-init\n\r");
+
+  ret = btleStartRadioScan(scanningParams.getActiveScanning(),
+                           scanningParams.getInterval(),
+                           scanningParams.getWindow(),
+                           addr_type);
+
+
+  if (BLE_STATUS_SUCCESS == ret){
+    PRINTF("Observation Procedure Started\n");
+    _scanning = true;
+    return BLE_ERROR_NONE;
   }
-  
-  ret = aci_gap_start_general_discovery_proc(scanningParams.getInterval(),
-					     scanningParams.getWindow(),
-					     addr_type,
-					     1); // 1 to filter duplicates
-  
-  if (ret != BLE_STATUS_SUCCESS) {
-    printf("Start Discovery Procedure failed (0x%02X)\n\r", ret);
-    return BLE_ERROR_UNSPECIFIED; 
-  } else {
-    PRINTF("Discovery Procedure Started\n");
-    _scanning = true;
-    return BLE_ERROR_NONE; 
+
+  // Observer role is not supported by X-NUCLEO-IDB04A1, return BLE_ERROR_NOT_IMPLEMENTED
+  switch (ret) {
+    case BLE_STATUS_INVALID_CID:
+      printf("Observation Procedure not implemented!!!\n\r");
+      return BLE_ERROR_NOT_IMPLEMENTED;
+    default:
+      printf("Observation Procedure failed (0x%02X)\n\r", ret);
+      return BLE_ERROR_UNSPECIFIED;
   }
+
 }
 
 ble_error_t BlueNRGGap::stopScan() {
   tBleStatus ret = BLE_STATUS_SUCCESS;
   
-  ret = aci_gap_terminate_gap_procedure(GENERAL_DISCOVERY_PROCEDURE);
+  ret = aci_gap_terminate_gap_procedure(GAP_OBSERVATION_PROC);
   
   if (ret != BLE_STATUS_SUCCESS) {
     printf("GAP Terminate Gap Procedure failed\n");
@@ -1287,7 +1295,7 @@
   (void)connectionParams;
   (void)scanParams;
 
-    // Save the peer address
+  // Save the peer address
   for(int i=0; i<BDADDR_SIZE; i++) {
     _peerAddr[i] = peerAddr[i];
   }
--- a/x-nucleo-idb0xa1/BlueNRGGap.h	Thu Mar 31 10:17:31 2016 +0200
+++ b/x-nucleo-idb0xa1/BlueNRGGap.h	Thu Mar 31 11:06:20 2016 +0200
@@ -50,8 +50,7 @@
 #define BLE_GAP_ADV_NONCON_INTERVAL_MIN (0)
 
 // Scanning and Connection Params used by Central for creating connection
-#define LIMITED_DISCOVERY_PROCEDURE 0x01
-#define GENERAL_DISCOVERY_PROCEDURE 0x02
+#define GAP_OBSERVATION_PROC (0x80)
 
 #define SCAN_P         (0x4000)
 #define SCAN_L         (0x4000)
@@ -160,7 +159,6 @@
     bool _scanning;
     bool _connecting;
     bool isSetAddress;
-    bool btle_reinited;
     uint8_t *DeviceName;
     uint8_t deviceAppearance[2];
 
@@ -180,7 +178,6 @@
         m_connectionHandle = BLE_CONN_HANDLE_INVALID;
         addr_type = BLEProtocol::AddressType::PUBLIC;
         isSetAddress = false;
-        btle_reinited = false;
         DeviceName = NULL;     
     }