increase max connections to 20 (central + prph)

This commit is contained in:
hathach committed 2019-01-21 23:13:59 +07:00
1 parent 5cdded82e9
commit d15b196fe6
7 files changed
+26 -32

No files matched your search

@@ -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; idx<BLE_CENTRAL_MAX_CONN; idx++)
for (uint8_t idx=0; idx<BLE_MAX_CONNECTION; idx++)
{
// Invalid all connection handle
prphs[idx].conn_handle = BLE_CONN_HANDLE_INVALID;
@@ -156,7 +156,7 @@ void connect_callback(uint16_t conn_handle)
prph_info_t* peer = &prphs[id];
peer->conn_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; id<BLE_CENTRAL_MAX_CONN; id++)
for(int id=0; id<BLE_MAX_CONNECTION; id++)
{
if (conn_handle == prphs[id].conn_handle)
{
+1 -3
View File
@@ -439,9 +439,7 @@ LED_CONN LITERAL1
#######################################
# BLE Constants (LITERAL1)
#######################################
BLE_MAX_CONN LITERAL1
BLE_CENTRAL_MAX_CONN LITERAL1
BLE_PRPH_MAX_CONN LITERAL1
BLE_MAX_CONNECTION LITERAL1
BLE_CONN_HANDLE_INVALID LITERAL1
+1 -1
View File
@@ -104,7 +104,7 @@ bool BLECentral::connected(uint16_t conn_hdl)
uint8_t BLECentral::connected(void)
{
uint8_t count = 0;
for (uint16_t c=0; c<BLE_MAX_CONN; c++)
for (uint16_t c=0; c<BLE_MAX_CONNECTION; c++)
{
if ( this->connected(c) ) count++;
}
+1 -1
View File
@@ -241,7 +241,7 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
_connection[conn_hdl] = NULL;
bool still_connected = false;
for (uint8_t i=0; i<BLE_MAX_CONN; i++)
for (uint8_t i=0; i<BLE_MAX_CONNECTION; i++)
{
if ( _connection[i] )
{
+1 -1
View File
@@ -114,7 +114,7 @@ class BLEGap
ble_gap_sec_params_t _sec_param;
BLEConnection* _connection[BLE_MAX_CONN];
BLEConnection* _connection[BLE_MAX_CONNECTION];
friend class AdafruitBluefruit;
};
+5 -5
View File
@@ -314,8 +314,8 @@ err_t AdafruitBluefruit::begin(uint8_t prph_count, uint8_t central_count)
// Roles
varclr(&blecfg);
blecfg.gap_cfg.role_count_cfg.periph_role_count = _prph_count;
blecfg.gap_cfg.role_count_cfg.central_role_count = _central_count; // ? BLE_CENTRAL_MAX_CONN : 0);
blecfg.gap_cfg.role_count_cfg.central_sec_count = (_central_count ? 1 : 0); // should be enough
blecfg.gap_cfg.role_count_cfg.central_role_count = _central_count;
blecfg.gap_cfg.role_count_cfg.central_sec_count = (_central_count ? 1 : 0); // 1 should be enough
VERIFY_STATUS( sd_ble_cfg_set(BLE_GAP_CFG_ROLE_COUNT, &blecfg, ram_start) );
// Device Name
@@ -541,7 +541,7 @@ uint8_t AdafruitBluefruit::connected(void)
return ( _conn_hdl != BLE_CONN_HANDLE_INVALID );
uint8_t count = 0;
for (uint16_t c=0; c<BLE_MAX_CONN; c++)
for (uint16_t c=0; c<BLE_MAX_CONNECTION; c++)
{
// skip Peripheral Role handle
if ( this->connected(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
+3 -7
View File
@@ -39,18 +39,14 @@
#include <Arduino.h>
#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"