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:
Wed Apr 06 18:06:07 2016 +0200
Parent:
221:7896e6d8b652
Child:
223:36df860f7ffc
Commit message:
Fix issue on localName field setting; and 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
x-nucleo-idb0xa1/BlueNRGGap.h Show annotated file Show diff for this revision Revisions of this file
--- a/source/BlueNRGGap.cpp	Wed Apr 06 18:04:02 2016 +0200
+++ b/source/BlueNRGGap.cpp	Wed Apr 06 18:06:07 2016 +0200
@@ -179,13 +179,16 @@
             case GapAdvertisingData::COMPLETE_LOCAL_NAME:                /**< Complete Local Name */
                 {
                 PRINTF("Advertising type: COMPLETE_LOCAL_NAME\n\r");
-                loadPtr.getUnitAtIndex(index).printDataAsString();       
-                local_name_length = *loadPtr.getUnitAtIndex(index).getLenPtr()-1;                        
-                local_name = (uint8_t*)loadPtr.getUnitAtIndex(index).getAdTypePtr();
-                PRINTF("Advertising type: COMPLETE_LOCAL_NAME local_name=%s\n\r", local_name);
-                //COMPLETE_LOCAL_NAME is only advertising device name. Gatt Device Name is not the same.(Must be set right after GAP/GATT init?)
-                
-                PRINTF("device_name length=%d\n\r", local_name_length);                                    
+                loadPtr.getUnitAtIndex(index).printDataAsString();
+                local_name_length = *loadPtr.getUnitAtIndex(index).getLenPtr()-1;
+                // The total lenght should include the Data Type Value
+                if(local_name_length>LOCAL_NAME_MAX_SIZE-1) {
+                    return BLE_ERROR_INVALID_PARAM;
+                }
+                local_name[0] = (uint8_t)(*loadPtr.getUnitAtIndex(index).getAdTypePtr()); //Data Type Value
+                memcpy(local_name+1, (uint8_t*)loadPtr.getUnitAtIndex(index).getDataPtr(), local_name_length-1);
+                PRINTF("Advertising type: COMPLETE_LOCAL_NAME local_name=%s local_name_length=%d\n\r", local_name, local_name_length);
+
                 break;
                 }
             case GapAdvertisingData::TX_POWER_LEVEL:                     /**< TX Power Level (in dBm) */
@@ -860,11 +863,11 @@
     nameLen = strlen((const char*)DeviceName);
     //PRINTF("DeviceName Size=%d\n\r", nameLen); 
     
-    ret = aci_gatt_update_char_value(g_gap_service_handle, 
-    g_device_name_char_handle, 
-    0, 
-    nameLen, 
-    (uint8_t *)DeviceName);
+    ret = aci_gatt_update_char_value(g_gap_service_handle,
+                                     g_device_name_char_handle,
+                                     0,
+                                     nameLen,
+                                     (uint8_t *)DeviceName);
 
     if (BLE_STATUS_SUCCESS != ret){
         PRINTF("device set name failed (ret=0x%x)!!\n\r", ret) ;
@@ -1151,9 +1154,13 @@
 {
   
   tBleStatus ret = BLE_STATUS_SUCCESS;
-  
+
+  // Stop ADV before scanning
+  if (state.advertising == 1) {
+    stopAdvertising();
+  }
+
   PRINTF("Scanning...\n\r");
-
   ret = btleStartRadioScan(scanningParams.getActiveScanning(),
                            scanningParams.getInterval(),
                            scanningParams.getWindow(),
@@ -1242,13 +1249,14 @@
 ble_error_t BlueNRGGap::createConnection ()
 {
   tBleStatus ret;
+  GapScanningParams* scanningParams = getScanningParams();
   
   /*
     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(_scanningParams.getInterval(),
-				  _scanningParams.getWindow(),
+  ret = aci_gap_create_connection(scanningParams->getInterval(),
+				  scanningParams->getWindow(),
 				  PUBLIC_ADDR,
 				  (unsigned char*)_peerAddr,
 				  PUBLIC_ADDR,
--- a/x-nucleo-idb0xa1/BlueNRGGap.h	Wed Apr 06 18:04:02 2016 +0200
+++ b/x-nucleo-idb0xa1/BlueNRGGap.h	Wed Apr 06 18:06:07 2016 +0200
@@ -62,7 +62,8 @@
 #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 LOCAL_NAME_MAX_SIZE 9 //8 + 1(AD_DATA_TYPE)
+#define UUID_BUFFER_SIZE 17 //Either 8*2(16-bit UUIDs) or 4*4(32-bit UUIDs) or 1*16(128-bit UUIDs) +1(AD_DATA_TYPE)
 #define ADV_DATA_MAX_SIZE 31
 
 /**************************************************************************/
@@ -162,8 +163,8 @@
     uint8_t *DeviceName;
     uint8_t deviceAppearance[2];
 
-    uint8_t *local_name;
     uint8_t local_name_length;
+    uint8_t local_name[LOCAL_NAME_MAX_SIZE];
 
     uint8_t servUuidlength;
     uint8_t servUuidData[UUID_BUFFER_SIZE];