add GAP getAddr and setAddr
add Bluefruit.printInfo()
This commit is contained in:
1 parent
27ef26024b
commit
673f1821ac
9 files changed
+133
-6
No files matched your search
+11
-2
@@ -2,11 +2,20 @@
|
||||
|
||||
## 0.7.0
|
||||
|
||||
### BLE
|
||||
### Bluefruit
|
||||
|
||||
- Renamed `Bluefruit.peerAddr()` to `Bluefruit.getPeerAddr()`
|
||||
- Changed BLEClientUart's RX callback
|
||||
- Added connection handle to the connect and disconnect callback prototypes
|
||||
- Change signature of Bluefruit.getName()
|
||||
- Add printInfo() for configuration summary
|
||||
|
||||
### BLEGap
|
||||
|
||||
- Add getAddr() and setAddr()
|
||||
|
||||
### BLE Service
|
||||
|
||||
- Add BLEClientUart& reference pointer BLEClientUart's RX callback
|
||||
|
||||
### BLEAdvertising
|
||||
|
||||
|
||||
+3
-1
@@ -44,7 +44,9 @@ class Uart : public HardwareSerial
|
||||
|
||||
void IrqHandler();
|
||||
|
||||
operator bool() { return _begun; }
|
||||
bool started(void) { return _begun; }
|
||||
|
||||
operator bool() { return true; }
|
||||
|
||||
private:
|
||||
NRF_UART_Type *nrfUart;
|
||||
|
||||
+10
-1
@@ -20,6 +20,13 @@
|
||||
#include "SEGGER_SYSVIEW.h"
|
||||
#endif
|
||||
|
||||
#if CFG_DEBUG
|
||||
// weak function to avoid compilation error with
|
||||
// non-Bluefruit library sketch such as ADC read test
|
||||
void Bluefruit_printInfo() __attribute__((weak));
|
||||
void Bluefruit_printInfo() {}
|
||||
#endif
|
||||
|
||||
#define MEMINFO_INTERVAL 60000
|
||||
|
||||
// Weak empty variant initialization function.
|
||||
@@ -39,8 +46,10 @@ static void loop_task(void* arg)
|
||||
|
||||
#if CFG_DEBUG
|
||||
// If Serial is not begin(), call it to avoid hard fault
|
||||
if (!Serial) Serial.begin(115200);
|
||||
if ( !Serial.started() ) Serial.begin(115200);
|
||||
dbgPrintVersion();
|
||||
|
||||
Bluefruit_printInfo();
|
||||
#endif
|
||||
|
||||
while (1)
|
||||
|
||||
+3
-2
@@ -14,8 +14,9 @@
|
||||
|
||||
#include <bluefruit.h>
|
||||
|
||||
/* For a list of EIR data types see: https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile */
|
||||
/* Matching enum: cores/nRF5/SDK/components/softdevice/s132/headers/ble_gap.h */
|
||||
/* For a list of EIR data types see:
|
||||
* https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile
|
||||
* Matching enum: cores/nRF5/SDK/components/softdevice/s132/headers/ble_gap.h */
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
@@ -25,6 +25,7 @@ void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println("Bluefruit52 BLEUART Example");
|
||||
Serial.println("---------------------------\n");
|
||||
|
||||
// Initialize blinkTimer for 1000 ms and start it
|
||||
blinkTimer.begin(1000, blink_timer_callback);
|
||||
|
||||
@@ -42,6 +42,49 @@ BLEGap::BLEGap(void)
|
||||
varclr(&_peers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current Mac address and its type
|
||||
* @param mac address
|
||||
* @return Address type e.g BLE_GAP_ADDR_TYPE_RANDOM_STATIC
|
||||
*/
|
||||
uint8_t BLEGap::getAddr(uint8_t mac[6])
|
||||
{
|
||||
ble_gap_addr_t addr;
|
||||
|
||||
sd_ble_gap_address_get(&addr);
|
||||
memcpy(mac, addr.addr, 6);
|
||||
|
||||
return addr.addr_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the MAC address
|
||||
* @param mac Address for PUBLIC and RANDOM_STATIC and should be NULL
|
||||
* if RANDOM_PRIVATE_* since it is ignored
|
||||
* @param type Type e.g BLE_GAP_ADDR_TYPE_RANDOM_STATIC
|
||||
* @return
|
||||
*/
|
||||
bool BLEGap::setAddr(uint8_t mac[6], uint8_t type)
|
||||
{
|
||||
ble_gap_addr_t addr;
|
||||
addr.addr_type = type;
|
||||
|
||||
uint8_t mode = BLE_GAP_ADDR_CYCLE_MODE_NONE;
|
||||
|
||||
if ( (type == BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE) || (type == BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE) )
|
||||
{
|
||||
// Private address require cycling mode
|
||||
// Input Mac is also ignored, user can pass NULL
|
||||
mode = BLE_GAP_ADDR_CYCLE_MODE_AUTO;
|
||||
}else
|
||||
{
|
||||
memcpy(addr.addr, mac, 6);
|
||||
}
|
||||
|
||||
VERIFY_STATUS( sd_ble_gap_address_set(mode, &addr), false );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BLEGap::connected(uint16_t conn_handle)
|
||||
{
|
||||
return _peers[conn_handle].connected;
|
||||
|
||||
@@ -48,6 +48,9 @@ class BLEGap
|
||||
|
||||
BLEGap(void);
|
||||
|
||||
uint8_t getAddr(uint8_t mac[6]);
|
||||
bool setAddr(uint8_t mac[6], uint8_t type);
|
||||
|
||||
bool connected(uint16_t conn_handle);
|
||||
|
||||
uint8_t getRole(uint16_t conn_handle);
|
||||
|
||||
@@ -366,6 +366,63 @@ bool AdafruitBluefruit::setPIN(const char* pin)
|
||||
}
|
||||
)
|
||||
|
||||
void Bluefruit_printInfo(void)
|
||||
{
|
||||
Bluefruit.printInfo();
|
||||
}
|
||||
|
||||
void AdafruitBluefruit::printInfo(void)
|
||||
{
|
||||
// Skip if Serial is not initialised
|
||||
if ( !Serial.started() ) return;
|
||||
|
||||
// Skip if Bluefruit.begin() is not called
|
||||
if ( _ble_event_sem == NULL ) return;
|
||||
|
||||
// Name
|
||||
Serial.printf("%-15s ", "Name");
|
||||
{
|
||||
char name[32];
|
||||
memclr(name, sizeof(name));
|
||||
getName(name, sizeof(name));
|
||||
Serial.printf(name);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
// Max Connections
|
||||
Serial.printf("%-15s ", "Max Connection");
|
||||
Serial.printf("Peripheral = %d, ", _prph_enabled ? 1 : 0);
|
||||
Serial.printf("Central = %d, ", _central_enabled ? BLE_CENTRAL_MAX_CONN : 0);
|
||||
Serial.println();
|
||||
|
||||
// Address
|
||||
Serial.printf("%-15s ", "Address");
|
||||
{
|
||||
const char* type_str[] = { "Public", "Static", "Private Resolvable", "Private Non Resolvable" };
|
||||
uint8_t mac[6];
|
||||
uint8_t type = Gap.getAddr(mac);
|
||||
Serial.printBuffer(mac, 6, ':');
|
||||
Serial.printf(" (%s)", type_str[type]);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
Serial.printf("%-15s ", "TX Power");
|
||||
Serial.printf("%d dBm", _tx_power);
|
||||
Serial.println();
|
||||
|
||||
Serial.printf("%-15s ", "Conn Intervals");
|
||||
// TODO enable newlib nano float format
|
||||
Serial.print("min = "); Serial.print( ((double) _ppcp_min_conn)*0.625, 3); Serial.print(" ms, ");
|
||||
Serial.print("max = "); Serial.print( ((double) _ppcp_max_conn)*0.625, 3); Serial.print(" ms");
|
||||
Serial.println();
|
||||
|
||||
Serial.printf("%-15s ", "Paired Devices");
|
||||
Serial.printf("TODO");
|
||||
Serial.println();
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Thread & SoftDevice Event handler
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
@@ -134,6 +134,8 @@ class AdafruitBluefruit
|
||||
ble_gap_addr_t getPeerAddr(void);
|
||||
uint8_t getPeerAddr(uint8_t addr[6]);
|
||||
|
||||
void printInfo(void);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Callbacks
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
Reference in new issue
Block a user