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:
Tue Apr 05 11:23:33 2016 +0200
Parent:
219:d8e8cd4d4521
Child:
221:7896e6d8b652
Commit message:
Fix setting of ADV and CONN intervals

- Introduce STACK MODE 3 allowing a central to advertize while a connection is ongoing
- Cosmetics

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
source/platform/btle.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 11:16:47 2016 +0200
+++ b/source/BlueNRGGap.cpp	Tue Apr 05 11:23:33 2016 +0200
@@ -372,7 +372,7 @@
 
     /* Make sure we support the advertising type */
     if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) {
-        /* ToDo: This requires a propery security implementation, etc. */
+        /* ToDo: This requires a proper security implementation, etc. */
         return BLE_ERROR_NOT_IMPLEMENTED;
     }
 
@@ -415,44 +415,25 @@
         }
     }
 
-    /*aci_gap_set_discoverable(Advertising_Event_Type, Adv_min_intvl, Adv_Max_Intvl, Addr_Type, Adv_Filter_Policy,
-                        Local_Name_Length, local_name, service_uuid_length, service_uuid_list, Slave_conn_intvl_min, Slave_conn_intvl_max);*/
-    /*LINK_LAYER.H DESCRIBES THE ADVERTISING TYPES*/ 
+    advtInterval = params.getIntervalInADVUnits();
+    PRINTF("advtInterval=%ld\n\r", advtInterval);
 
-    // Enable the else branch if you want to set default device name
-    char* name = NULL;
-    uint8_t nameLen = 0; 
-    if(local_name!=NULL) {
-        name = (char*)local_name;
-        PRINTF("name=%s\n\r", name); 
-        nameLen = local_name_length;
-    } /*else {
-        char str[] = "ST_BLE_DEV";
-        name = new char[strlen(str)+1];
-        name[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
-        strcpy(name+1, str);
-        nameLen = strlen(name);
-        PRINTF("nameLen=%d\n\r", nameLen);
-        PRINTF("name=%s\n\r", name);      
-    }*/
-
-    advtInterval = params.getIntervalInADVUnits(); // set advtInterval in case it is not already set by user application  
-    ret = aci_gap_set_discoverable(params.getAdvertisingType(), // Advertising_Event_Type                                
-        advtInterval,   // Adv_Interval_Min
-        advtInterval,   // Adv_Interval_Max
-        PUBLIC_ADDR, // Address_Type 
-        NO_WHITE_LIST_USE,  // Adv_Filter_Policy
-        nameLen, //local_name_length, // Local_Name_Length
-        (const char*)name, //local_name, // Local_Name
-        servUuidlength,  //Service_Uuid_Length
-        servUuidData, //Service_Uuid_List
-        0, // Slave_Conn_Interval_Min
-        0);  // Slave_Conn_Interval_Max
+    ret = aci_gap_set_discoverable(params.getAdvertisingType(), // AdvType
+                                   advtInterval,                // AdvIntervMin
+                                   advtInterval,                // AdvIntervMax
+                                   PUBLIC_ADDR,                 // OwnAddrType
+                                   NO_WHITE_LIST_USE,           // AdvFilterPolicy
+                                   local_name_length,           // LocalNameLen
+                                   (const char*)local_name,     // LocalName
+                                   servUuidlength,              // ServiceUUIDLen
+                                   servUuidData,                // ServiceUUIDList
+                                   0,                           // SlaveConnIntervMin
+                                   0);                          // SlaveConnIntervMax
 
     
-    PRINTF("!!!setting discoverable (servUuidlength=0x%x)\n", servUuidlength);
+    PRINTF("!!!setting discoverable (servUuidlength=0x%x)\n\r", servUuidlength);
     if(BLE_STATUS_SUCCESS!=ret) {
-       PRINTF("error occurred while setting discoverable (ret=0x%x)\n", ret);
+       PRINTF("error occurred while setting discoverable (ret=0x%x)\n\r", ret);
        switch (ret) {
          case BLE_STATUS_INVALID_PARAMS:
            return BLE_ERROR_INVALID_PARAM;
@@ -469,7 +450,7 @@
 
     // Before updating the ADV data, delete COMPLETE_LOCAL_NAME and TX_POWER_LEVEL fields (if present)
     if(AdvLen>0) {
-      if(name!=NULL) {
+      if(local_name!=NULL) {
         PRINTF("!!!calling aci_gap_delete_ad_type AD_TYPE_COMPLETE_LOCAL_NAME!!!\n");
         ret = aci_gap_delete_ad_type(AD_TYPE_COMPLETE_LOCAL_NAME);
         if (BLE_STATUS_SUCCESS!=ret){
@@ -1266,13 +1247,13 @@
     Scan_Interval, Scan_Window, Peer_Address_Type, Peer_Address, Own_Address_Type, Conn_Interval_Min, 
     Conn_Interval_Max, Conn_Latency, Supervision_Timeout, Conn_Len_Min, Conn_Len_Max    
   */
-  ret = aci_gap_create_connection(SCAN_P,
-				  SCAN_L,
+  ret = aci_gap_create_connection(_scanningParams.getInterval(),
+				  _scanningParams.getWindow(),
 				  PUBLIC_ADDR,
 				  (unsigned char*)_peerAddr,
 				  PUBLIC_ADDR,
 				  CONN_P1, CONN_P2, 0,
-				  SUPERV_TIMEOUT, CONN_L1 , CONN_L2);
+				  SUPERV_TIMEOUT, CONN_L1 , CONN_L1);
 
   _connecting = false;
   
--- a/source/platform/btle.cpp	Thu Mar 31 11:16:47 2016 +0200
+++ b/source/platform/btle.cpp	Tue Apr 05 11:23:33 2016 +0200
@@ -72,6 +72,9 @@
 #define IDB04A1 0
 #define IDB05A1 1
 
+// Mode 0x03 allows a central to advertise while a connection is ongoing
+#define STACK_MODE (0x03)
+
 void HCI_Input(tHciDataPacket * hciReadPacket);
 
 uint16_t g_gap_service_handle = 0;
@@ -134,6 +137,13 @@
     /* set BLE version string */
     setVersionString(hwVersion, fwVersion);
 
+    if (bnrg_expansion_board == IDB05A1) {
+        uint8_t stackMode = STACK_MODE;
+        ret = aci_hal_write_config_data(CONFIG_DATA_ROLE,
+                                        CONFIG_DATA_ROLE_LEN,
+                                        &stackMode);
+    }
+
     /* The Nucleo board must be configured as SERVER */
     //check if isSetAddress is set then set address.
     // ANDREA
@@ -246,10 +256,11 @@
 
   // Observer role is not supported by X-NUCLEO-IDB04A1, return BLE_ERROR_NOT_IMPLEMENTED
   if(bnrg_expansion_board == IDB05A1) {
+      PRINTF("scan_interval=%d scan_window=%d\n\r", scan_interval, scan_window);
       ret = aci_gap_start_observation_procedure(scan_interval,
-	                                        scan_window,
+                                                scan_window,
                                                 scan_type,
-		                                own_address_type,
+                                                own_address_type,
                                                 1); // 1 to filter duplicates
   } else {
       ret = BLE_STATUS_INVALID_CID;
--- a/x-nucleo-idb0xa1/BlueNRGGap.h	Thu Mar 31 11:16:47 2016 +0200
+++ b/x-nucleo-idb0xa1/BlueNRGGap.h	Tue Apr 05 11:23:33 2016 +0200
@@ -52,15 +52,15 @@
 // Scanning and Connection Params used by Central for creating connection
 #define GAP_OBSERVATION_PROC (0x80)
 
-#define SCAN_P         (0x4000)
-#define SCAN_L         (0x4000)
-#define SUPERV_TIMEOUT (600)
+#define SCAN_P         (0x0010)
+#define SCAN_L         (0x0010)
+#define SUPERV_TIMEOUT (0xC80)
 #define CONN_P(x)      ((int)((x)/1.25f))
 #define CONN_L(x)      ((int)((x)/0.625f))
-#define CONN_P1        (CONN_P(50))//(CONN_P(1000))
-#define CONN_P2        (CONN_P(50))//(CONN_P(1000))
-#define CONN_L1        (CONN_L(5)) 
-#define CONN_L2        (CONN_L(5))
+#define CONN_P1        ((int)(_advParams.getInterval()+5)/1.25f)//(0x4C)//(0x6C)
+#define CONN_P2        ((int)(_advParams.getInterval()+5)/1.25f)//(0x4C)//(0x6C)
+#define CONN_L1        (0x000C)
+#define CONN_L2        (0x000C)
 
 #define UUID_BUFFER_SIZE 17 //Either 8*2(16-bit UUIDs) or 4*4(32-bit UUIDs) or 1*16(128-bit UUIDs) +1
 #define ADV_DATA_MAX_SIZE 31