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
@@ -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