Add BLEConnection event handler

This commit is contained in:
hathach committed 2019-01-18 16:04:15 +07:00
1 parent b0ea12a467
commit d451759441
4 files changed
+28 -26

No files matched your search

+16 -10
View File
@@ -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;
}
}
+6 -3
View File
@@ -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);
};
+5 -11
View File
@@ -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;
+1 -2
View File
@@ -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);