Add BLEConnection's setTxPower()

This commit is contained in:
hathach committed 2019-01-24 15:17:26 +07:00
1 parent 3730a7dd89
commit ee360d43b1
3 files changed
+27 -3

No files matched your search

@@ -46,6 +46,7 @@ BLEConnection::BLEConnection(uint16_t conn_hdl, ble_gap_evt_connected_t const* e
_connected = true;
_mtu = BLE_GATT_ATT_MTU_DEFAULT;
_conn_interval = 0;
_addr = evt_connected->peer_addr;
_role = evt_connected->role;
@@ -103,6 +104,29 @@ ble_gap_addr_t BLEConnection::getPeerAddr (void)
return _addr;
}
static inline bool is_tx_power_valid(int8_t power)
{
#if defined(NRF52832_XXAA)
int8_t const accepted[] = { -40, -20, -16, -12, -8, -4, 0, 3, 4 };
#elif defined( NRF52840_XXAA)
int8_t const accepted[] = { -40, -20, -16, -12, -8, -4, 0, 2, 3, 4, 5, 6, 7, 8 };
#endif
for (uint32_t i=0; i<sizeof(accepted); i++)
{
if (accepted[i] == power) return true;
}
return false;
}
bool BLEConnection::setTxPower(int8_t power)
{
VERIFY(is_tx_power_valid(power));
VERIFY_STATUS(sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_CONN, _conn_hdl, power), false);
return true;
}
bool BLEConnection::disconnect(void)
{
return ERROR_NONE == sd_ble_gap_disconnect(_conn_hdl, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
+3 -1
View File
@@ -49,6 +49,7 @@ class BLEConnection
uint16_t _conn_interval;
uint16_t _ediv;
uint8_t _role;
bool _connected;
bool _paired;
bool _hvc_received;
@@ -75,11 +76,12 @@ class BLEConnection
uint8_t getRole(void);
uint16_t getMtu (void);
uint16_t getConnInterval(void);
ble_gap_addr_t getPeerAddr(void);
bool disconnect(void);
bool setTxPower(int8_t power);
bool monitorRssi(uint8_t threshold = BLE_GAP_RSSI_THRESHOLD_INVALID);
int8_t getRssi(void);
void stopRssi(void);
-2
View File
@@ -160,8 +160,6 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
_connection[conn_hdl] = new BLEConnection(conn_hdl, para, hvn_qsize, wrcmd_qsize);
conn = _connection[conn_hdl];
LOG_LV2("GAP", "Conn Interval= %f", para->conn_params.min_conn_interval*1.25f);
// Invoke connect callback
if ( conn->getRole() == BLE_GAP_ROLE_PERIPH )
{