Andrea Sortino / X_NUCLEO_IDB0XA1

Dependents:   BLE_GENERALE

Fork of X_NUCLEO_IDB0XA1 by ST

Files at this revision

API Documentation at this revision

Comitter:
Andrea Palmieri
Date:
Tue Oct 27 10:18:55 2015 +0100
Parent:
144:bdf5e8432131
Child:
149:1758eaa54309
Commit message:
Fix role (Central/Peripheral) handling and remove warnings

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/BlueNRGGattClient.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
x-nucleo-idb0xa1/bluenrg-hci/debug.h Show annotated file Show diff for this revision Revisions of this file
--- a/source/BlueNRGGap.cpp	Wed Oct 21 11:56:41 2015 +0200
+++ b/source/BlueNRGGap.cpp	Tue Oct 27 10:18:55 2015 +0100
@@ -1018,15 +1018,17 @@
     // The discovery is complete. If this is due to a stop scanning (i.e., the device
     // we are interested in has been found) and a connection has been requested
     // then we start the device connection. Otherwise, we restart the scanning.
+    PRINTF("DISCOVERY_COMPLETE\n\r");
     _scanning = false;
 
     if(_connecting) {
       // We need to wait for a while before creating a connection due to
       // BlueNRG process queue handling
-      Clock_Wait(10);
+      Clock_Wait(100);
       makeConnection();
       
     } else {
+      PRINTF("re-startRadioScan\n\r");
       startRadioScan(_scanningParams);
     }
 
@@ -1039,12 +1041,17 @@
   
   uint8_t 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
-  btle_init(isSetAddress, GAP_CENTRAL_ROLE_IDB04A1);
-  
-  PRINTF("BTLE re-init\n\r");
+  if(!btle_reinited) {
+    btle_init(isSetAddress, GAP_CENTRAL_ROLE_IDB04A1);
+    btle_reinited = true;
+
+    PRINTF("BTLE re-init\n\r");
+  }
   
   ret = aci_gap_start_general_discovery_proc(scanningParams.getInterval(),
                                              scanningParams.getWindow(),
@@ -1090,6 +1097,9 @@
     int8_t paLevel = 0;    
 #ifdef DEBUG
     int8_t dbmActuallySet = getHighPowerAndPALevelValue(txPower, enHighPower, paLevel);
+#else
+    /* avoid compiler warnings about unused variables */
+    (void)txPower;
 #endif
     
     PRINTF("txPower=%d, dbmActuallySet=%d\n\r", txPower, dbmActuallySet);
--- a/source/BlueNRGGattClient.cpp	Wed Oct 21 11:56:41 2015 +0200
+++ b/source/BlueNRGGattClient.cpp	Tue Oct 27 10:18:55 2015 +0100
@@ -105,10 +105,12 @@
       uuid.setupLong(attribute_data_list+offset+4);
       
       PRINTF("S UUID-");
+#ifdef DEBUG
       const uint8_t *longUUIDBytes = uuid.getBaseUUID();
       for (unsigned j = 0; j < UUID::LENGTH_OF_LONG_UUID; j++) {
         PRINTF("%02x", longUUIDBytes[j]);
       }
+#endif
       PRINTF(" attrs[%u %u]\r\n", startHandle, endHandle);
       
     }
@@ -184,11 +186,13 @@
       PRINTF("Char UUID_TYPE_128\n\r");
       uuid.setupLong(handle_value_pair+offset+5);
       PRINTF("C UUID-");
+#ifdef DEBUG
       const uint8_t *longUUIDBytes = uuid.getBaseUUID();
       for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
         PRINTF("%02X", longUUIDBytes[i]);
       }
       PRINTF("\r\n");
+#endif
     }
     
     // Properties
@@ -254,11 +258,13 @@
     PRINTF("Char UUID_TYPE_128\n\r");
     uuid.setupLong(attr_value+3);
     PRINTF("C UUID-");
+#ifdef DEBUG
     const uint8_t *longUUIDBytes = uuid.getBaseUUID();
     for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
       PRINTF("%02X", longUUIDBytes[i]);
     }
     PRINTF("\r\n");
+#endif
   }
 
   // Properties
@@ -538,6 +544,10 @@
   // Save the attribute_handle not provided by evt_att_read_resp    
   gattc->readCBParams.handle = attributeHandle;
   
+  // We need to wait for a while before starting a read due to
+  // BlueNRG process queue handling
+  Clock_Wait(100); //(?)
+
   ret = aci_gatt_read_charac_val(connHandle, attributeHandle);
   
   if(ret == BLE_STATUS_SUCCESS) {
--- a/x-nucleo-idb0xa1/BlueNRGGap.h	Wed Oct 21 11:56:41 2015 +0200
+++ b/x-nucleo-idb0xa1/BlueNRGGap.h	Tue Oct 27 10:18:55 2015 +0100
@@ -157,6 +157,7 @@
     bool _scanning;
     bool _connecting;
     bool isSetAddress;
+    bool btle_reinited;
     tBleStatus ret; // FIXME: delete this
     uint8_t *DeviceName;
     uint8_t deviceAppearance[2];
@@ -179,6 +180,7 @@
         m_connectionHandle = BLE_CONN_HANDLE_INVALID;
         addr_type = Gap::ADDR_TYPE_PUBLIC;
         isSetAddress = false;
+        btle_reinited = false;
         DeviceName = NULL;     
     }
 
--- a/x-nucleo-idb0xa1/bluenrg-hci/debug.h	Wed Oct 21 11:56:41 2015 +0200
+++ b/x-nucleo-idb0xa1/bluenrg-hci/debug.h	Tue Oct 27 10:18:55 2015 +0100
@@ -47,7 +47,7 @@
 #include <string.h>
 
 /* Exported macro ------------------------------------------------------------*/
-#define DEBUG
+//#define DEBUG
 #ifdef DEBUG
 #include <stdio.h>
 #define PRINTF(...) printf(__VA_ARGS__)