Add BLEConnection event handler
This commit is contained in:
4 files changed
+28
-26
No files matched your search
@@ -66,16 +66,6 @@ BLEConnection::~BLEConnection()
|
||||
vSemaphoreDelete( _wrcmd_sem );
|
||||
}
|
||||
|
||||
void BLEConnection::giveHvnPacket(uint8_t count)
|
||||
{
|
||||
for(uint8_t i=0; i<count; i++) xSemaphoreGive(_hvn_sem);
|
||||
}
|
||||
|
||||
void BLEConnection::giveWriteCmdPacket(uint8_t count)
|
||||
{
|
||||
for(uint8_t i=0; i<count; i++) xSemaphoreGive(_wrcmd_sem);
|
||||
}
|
||||
|
||||
uint16_t BLEConnection::handle (void)
|
||||
{
|
||||
return _conn_hdl;
|
||||
@@ -121,3 +111,19 @@ bool BLEConnection::getWriteCmdPacket (void)
|
||||
{
|
||||
return xSemaphoreTake(_wrcmd_sem, ms2tick(BLE_GENERIC_TIMEOUT));
|
||||
}
|
||||
|
||||
void BLEConnection::_eventHandler(ble_evt_t* evt)
|
||||
{
|
||||
switch(evt->header.evt_id)
|
||||
{
|
||||
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
|
||||
for(uint8_t i=0; i<evt->evt.gatts_evt.params.hvn_tx_complete.count; i++) xSemaphoreGive(_hvn_sem);
|
||||
break;
|
||||
|
||||
case BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE:
|
||||
for(uint8_t i=0; i<evt->evt.gattc_evt.params.write_cmd_tx_complete.count; i++) xSemaphoreGive(_wrcmd_sem);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -79,10 +79,13 @@ class BLEConnection
|
||||
uint8_t getPeerAddr(uint8_t addr[6]);
|
||||
|
||||
bool getHvnPacket(void);
|
||||
void giveHvnPacket(uint8_t count);
|
||||
|
||||
bool getWriteCmdPacket(void);
|
||||
void giveWriteCmdPacket(uint8_t count);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* INTERNAL USAGE ONLY
|
||||
* Although declare as public, it is meant to be invoked by internal code.
|
||||
*------------------------------------------------------------------*/
|
||||
void _eventHandler(ble_evt_t* evt);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -219,10 +219,11 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
|
||||
{
|
||||
// conn handle has fixed offset regardless of event type
|
||||
const uint16_t conn_hdl = evt->evt.common_evt.conn_handle;
|
||||
|
||||
gap_peer_t* peer = (conn_hdl == BLE_CONN_HANDLE_INVALID) ? NULL : &_peers[conn_hdl];
|
||||
BLEConnection* conn = (conn_hdl == BLE_CONN_HANDLE_INVALID) ? NULL : _connection[conn_hdl];
|
||||
|
||||
// Connection handler
|
||||
if ( conn ) conn->_eventHandler(evt);
|
||||
|
||||
switch(evt->header.evt_id)
|
||||
{
|
||||
case BLE_GAP_EVT_CONNECTED:
|
||||
@@ -247,7 +248,8 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
|
||||
_connection[conn_hdl] = new BLEConnection(conn_hdl, para, hvn_qsize, wrcmd_qsize);
|
||||
conn = _connection[conn_hdl];
|
||||
|
||||
peer->role = para->role;
|
||||
// FIXME to remove
|
||||
_peers[conn_hdl].role = para->role;
|
||||
|
||||
LOG_LV2("GAP", "Conn Interval= %f", para->conn_params.min_conn_interval*1.25f);
|
||||
|
||||
@@ -430,14 +432,6 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
|
||||
}
|
||||
break;
|
||||
|
||||
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
|
||||
if ( conn ) conn->giveHvnPacket(evt->evt.gatts_evt.params.hvn_tx_complete.count);
|
||||
break;
|
||||
|
||||
case BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE:
|
||||
if ( conn ) conn->giveWriteCmdPacket(evt->evt.gattc_evt.params.write_cmd_tx_complete.count);
|
||||
break;
|
||||
|
||||
case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST:
|
||||
{
|
||||
ble_gap_data_length_params_t* param = &evt->evt.gap_evt.params.data_length_update_request.peer_params;
|
||||
|
||||
@@ -83,8 +83,7 @@ class BLEGap
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* INTERNAL USAGE ONLY
|
||||
* Although declare as public, it is meant to be invoked by internal
|
||||
* code. User should not call these directly
|
||||
* Although declare as public, it is meant to be invoked by internal code.
|
||||
*------------------------------------------------------------------*/
|
||||
void _eventHandler(ble_evt_t* evt);
|
||||
|
||||
|
||||
Reference in new issue
Block a user