From d15b196fe6161c6053d2e9efcf0d2c0916628e5d Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 21 Jan 2019 23:13:59 +0700 Subject: [PATCH] increase max connections to 20 (central + prph) --- .../central_bleuart_multi.ino | 28 +++++++++---------- libraries/Bluefruit52Lib/keywords.txt | 4 +-- libraries/Bluefruit52Lib/src/BLECentral.cpp | 2 +- libraries/Bluefruit52Lib/src/BLEGap.cpp | 2 +- libraries/Bluefruit52Lib/src/BLEGap.h | 2 +- libraries/Bluefruit52Lib/src/bluefruit.cpp | 10 +++---- libraries/Bluefruit52Lib/src/bluefruit.h | 10 ++----- 7 files changed, 26 insertions(+), 32 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Central/central_bleuart_multi/central_bleuart_multi.ino b/libraries/Bluefruit52Lib/examples/Central/central_bleuart_multi/central_bleuart_multi.ino index 4796c4ec..bed390e1 100644 --- a/libraries/Bluefruit52Lib/examples/Central/central_bleuart_multi/central_bleuart_multi.ino +++ b/libraries/Bluefruit52Lib/examples/Central/central_bleuart_multi/central_bleuart_multi.ino @@ -31,17 +31,17 @@ * * Connection Handle Explanation * ----------------------------- - * The total number of connections is BLE_MAX_CONN = BLE_PRPH_MAX_CONN + BLE_CENTRAL_MAX_CONN. + * The total number of connections is BLE_MAX_CONNECTION (20) * * The 'connection handle' is an integer number assigned by the SoftDevice * (Nordic's proprietary BLE stack). Each connection will receive it's own - * numeric 'handle' starting from 0 to BLE_MAX_CONN-1, depending on the order + * numeric 'handle' starting from 0 to BLE_MAX_CONNECTION-1, depending on the order * of connection(s). * * - E.g If our Central board connects to a mobile phone first (running as a peripheral), - * then afterwards connects to another Bluefruit board running in peripheral mode, then - * the connection handle of mobile phone is 0, and the handle for the Bluefruit - * board is 1, and so on. + * then afterwards connects to another Bluefruit board running in peripheral mode, then + * the connection handle of mobile phone is 0, and the handle for the Bluefruit + * board is 1, and so on. */ /* LED PATTERNS @@ -55,7 +55,7 @@ // Struct containing peripheral info typedef struct { - char name[32]; + char name[16+1]; uint16_t conn_handle; @@ -65,16 +65,16 @@ typedef struct /* Peripheral info array (one per peripheral device) * - * There are 'BLE_CENTRAL_MAX_CONN' central connections, but the + * There are 'BLE_MAX_CONNECTION' central connections, but the * the connection handle can be numerically larger (for example if * the peripheral role is also used, such as connecting to a mobile * device). As such, we need to convert connection handles <-> the array * index where appropriate to prevent out of array accesses. * - * Note: One can simply declares the array with BLE_MAX_CONN and use connection + * Note: One can simply declares the array with BLE_MAX_CONNECTION and use connection * handle as index directly with the expense of SRAM. */ -prph_info_t prphs[BLE_CENTRAL_MAX_CONN]; +prph_info_t prphs[BLE_MAX_CONNECTION]; // Software Timer for blinking the RED LED SoftwareTimer blinkTimer; @@ -92,7 +92,7 @@ void setup() Serial.println("Bluefruit52 Central Multi BLEUART Example"); Serial.println("-----------------------------------------\n"); - // Initialize Bluefruit with max concurrent connections as Peripheral = 1, Central = 1 + // Initialize Bluefruit with max concurrent connections as Peripheral = 0, Central = 4 // SRAM usage required by SoftDevice will increase with number of connections Bluefruit.begin(0, 4); @@ -100,7 +100,7 @@ void setup() Bluefruit.setName("Bluefruit52 Central"); // Init peripheral pool - for (uint8_t idx=0; idxconn_handle = conn_handle; - Bluefruit.Gap.getPeerName(conn_handle, peer->name, 32); + Bluefruit.Gap.getPeerName(conn_handle, peer->name, sizeof(peer->name)-1); Serial.print("Connected to "); Serial.println(peer->name); @@ -248,7 +248,7 @@ void sendAll(const char* str) Serial.print("[Send to All]: "); Serial.println(str); - for(uint8_t id=0; id < BLE_CENTRAL_MAX_CONN; id++) + for(uint8_t id=0; id < BLE_MAX_CONNECTION; id++) { prph_info_t* peer = &prphs[id]; @@ -282,7 +282,7 @@ void loop() */ int findConnHandle(uint16_t conn_handle) { - for(int id=0; idconnected(c) ) count++; } diff --git a/libraries/Bluefruit52Lib/src/BLEGap.cpp b/libraries/Bluefruit52Lib/src/BLEGap.cpp index 062ab90e..856cf290 100644 --- a/libraries/Bluefruit52Lib/src/BLEGap.cpp +++ b/libraries/Bluefruit52Lib/src/BLEGap.cpp @@ -241,7 +241,7 @@ void BLEGap::_eventHandler(ble_evt_t* evt) _connection[conn_hdl] = NULL; bool still_connected = false; - for (uint8_t i=0; iconnected(c) ) count++; @@ -977,8 +977,8 @@ void AdafruitBluefruit::printInfo(void) // Max Connections Serial.printf(title_fmt, "Max Connections"); - Serial.printf("Peripheral = %d, ", _prph_count ? 1 : 0); - Serial.printf("Central = %d ", _central_count ? BLE_CENTRAL_MAX_CONN : 0); + Serial.printf("Peripheral = %d, ", _prph_count); + Serial.printf("Central = %d ", _central_count); Serial.println(); // Address diff --git a/libraries/Bluefruit52Lib/src/bluefruit.h b/libraries/Bluefruit52Lib/src/bluefruit.h index 91ac069e..12ff7d77 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.h +++ b/libraries/Bluefruit52Lib/src/bluefruit.h @@ -39,18 +39,14 @@ #include #include "bluefruit_common.h" -#define CFG_ADV_BLINKY_INTERVAL 500 +#define CFG_ADV_BLINKY_INTERVAL 500 /* Note changing these parameters will affect APP_RAM_BASE * --> need to update RAM region in linker file * - BLE_GATT_ATT_MTU_MAX from 23 (default) to 247 */ -#define BLE_GATT_ATT_MTU_MAX 247 -#define BLE_PRPH_MAX_CONN 1 -#define BLE_CENTRAL_MAX_CONN 4 -#define BLE_CENTRAL_MAX_SECURE_CONN 1 // should be enough - -#define BLE_MAX_CONN (BLE_CENTRAL_MAX_CONN+BLE_PRPH_MAX_CONN) +#define BLE_GATT_ATT_MTU_MAX 247 +#define BLE_MAX_CONNECTION 20 // SD support up to 20 connections #include "BLEUuid.h" #include "BLEAdvertising.h"