Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-os-example-ble-Advertising
Revision 165:3576598c0889, committed 2015-10-30
- Comitter:
- Wolfgang Betz
- Date:
- Fri Oct 30 16:46:25 2015 +0100
- Parent:
- 164:51bba7d36eb4
- Child:
- 166:63060ad4abd5
- Commit message:
- Enlarge HCI buffer entry number
Changed in this revision
--- a/source/BlueNRGGap.cpp Fri Oct 30 14:08:52 2015 +0100
+++ b/source/BlueNRGGap.cpp Fri Oct 30 16:46:25 2015 +0100
@@ -697,7 +697,7 @@
{
for(int i=0; i<BDADDR_SIZE; i++) {
address[i] = bdaddr[i];
- PRINTF("i[%d]:0x%x\n\r",i,bdaddr[i]);
+ //PRINTF("i[%d]:0x%x\n\r",i,bdaddr[i]);
}
}
@@ -977,16 +977,16 @@
return &_scanningParams;
}
-static void radioScanning()
+static void radioScanning(void)
{
GapScanningParams* scanningParams = BlueNRGGap::getInstance().getScanningParams();
BlueNRGGap::getInstance().startRadioScan(*scanningParams);
}
-static void makeConn()
+static void makeConnection(void)
{
- BlueNRGGap::getInstance().makeConnection();
+ BlueNRGGap::getInstance().createConnection();
}
// ANDREA
@@ -1039,11 +1039,14 @@
PRINTF("DISCOVERY_COMPLETE\n\r");
_scanning = false;
+ // Since the DISCOVERY_COMPLETE event can be received during the scanning interval,
+ // we need to delay the starting of connection or re-scanning procedures
+ uint16_t delay = 2*(_scanningParams.getInterval());
+
if(_connecting) {
- minar::Scheduler::postCallback(makeConn);
+ minar::Scheduler::postCallback(makeConnection).delay(minar::milliseconds(delay));
} else {
- PRINTF("re-startRadioScan\n\r");
- minar::Scheduler::postCallback(radioScanning);
+ minar::Scheduler::postCallback(radioScanning).delay(minar::milliseconds(delay));
}
break;
@@ -1053,7 +1056,7 @@
ble_error_t BlueNRGGap::startRadioScan(const GapScanningParams &scanningParams)
{
- uint8_t ret = BLE_STATUS_SUCCESS;
+ tBleStatus ret = BLE_STATUS_SUCCESS;
PRINTF("Scanning...\n\r");
@@ -1071,13 +1074,10 @@
scanningParams.getWindow(),
addr_type,
1); // 1 to filter duplicates
+
if (ret != BLE_STATUS_SUCCESS) {
- PRINTF("Start Discovery Procedure failed (0x%02X)\n\r", ret);
- // FIXME: We need to wait for a while before starting discovery proc
- // due to BlueNRG process queue handling
- // NOTE: this workaround causes a potential risk for an endless loop!!!
- minar::Scheduler::postCallback(radioScanning).delay(minar::milliseconds(100));
- return BLE_STACK_BUSY;
+ printf("Start Discovery Procedure failed (0x%02X)\n\r", ret);
+ return BLE_ERROR_UNSPECIFIED;
} else {
PRINTF("Discovery Procedure Started\n");
_scanning = true;
@@ -1086,7 +1086,7 @@
}
ble_error_t BlueNRGGap::stopScan() {
- uint8_t ret = BLE_STATUS_SUCCESS;
+ tBleStatus ret = BLE_STATUS_SUCCESS;
ret = aci_gap_terminate_gap_procedure(GENERAL_DISCOVERY_PROCEDURE);
@@ -1146,7 +1146,7 @@
*countP = sizeof(permittedTxValues) / sizeof(int8_t);
}
-ble_error_t BlueNRGGap::makeConnection ()
+ble_error_t BlueNRGGap::createConnection ()
{
tBleStatus ret;
@@ -1161,17 +1161,14 @@
PUBLIC_ADDR,
CONN_P1, CONN_P2, 0,
SUPERV_TIMEOUT, CONN_L1 , CONN_L2);
+
+ _connecting = false;
if (ret != BLE_STATUS_SUCCESS) {
- PRINTF("Error while starting connection (ret=0x%02X).\n\r", ret);
- // FIXME: We need to wait for a while before creating a connection
- // due to BlueNRG process queue handling
- // NOTE: this workaround causes a potential risk for an endless loop!!!
- minar::Scheduler::postCallback(makeConn).delay(minar::milliseconds(100));
- return BLE_STACK_BUSY;
+ printf("Error while starting connection (ret=0x%02X).\n\r", ret);
+ return BLE_ERROR_UNSPECIFIED;
} else {
PRINTF("Connection started.\n");
- _connecting = false;
return BLE_ERROR_NONE;
}
}
@@ -1196,8 +1193,8 @@
if(_scanning) {
stopScan();
} else {
- //PRINTF("Calling makeConnection from connect()\n\r");
- return makeConnection();
+ PRINTF("Calling createConnection from connect()\n\r");
+ return createConnection();
}
return BLE_ERROR_NONE;
--- a/source/bluenrg-hci/hci/hci.c Fri Oct 30 14:08:52 2015 +0100 +++ b/source/bluenrg-hci/hci/hci.c Fri Oct 30 16:46:25 2015 +0100 @@ -32,7 +32,7 @@ #define HCI_LOG_ON 0 -#define HCI_READ_PACKET_NUM_MAX (0x20) +#define HCI_READ_PACKET_NUM_MAX (0x40) #define MIN(a,b) ((a) < (b) )? (a) : (b) #define MAX(a,b) ((a) > (b) )? (a) : (b)
--- a/x-nucleo-idb0xa1/BlueNRGGap.h Fri Oct 30 14:08:52 2015 +0100
+++ b/x-nucleo-idb0xa1/BlueNRGGap.h Fri Oct 30 16:46:25 2015 +0100
@@ -130,7 +130,8 @@
uint8_t *data_length,
uint8_t *data,
uint8_t *RSSI);
- ble_error_t makeConnection(void);
+ ble_error_t createConnection(void);
+
void setConnectionHandle(uint16_t con_handle);
uint16_t getConnectionHandle(void);