Merge pull request #7163 from pan-/cordio-driver-hook

Cordio driver hook
pull/7151/head
Cruz Monrreal 2018-06-11 08:49:49 -05:00 committed by GitHub
commit 02e90ef469
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View File

@ -58,6 +58,10 @@ struct buf_pool_desc_t {
* - Access to the write function of the underlying HCITransport driver.
*/
class CordioHCIDriver {
// hook for internal tests and passthrough driver
friend class CordioHCIHook;
public:
/**
* Construct a new instance of an HCI driver.

View File

@ -14,6 +14,9 @@
* limitations under the License.
*/
#include <algorithm>
#include <limits>
#include "CordioHCITransportDriver.h"
#include "CordioHCIDriver.h"
@ -23,9 +26,22 @@ namespace ble {
namespace vendor {
namespace cordio {
CordioHCITransportDriver::data_received_handler_t
CordioHCITransportDriver::data_received_handler = hciTrSerialRxIncoming;
void CordioHCITransportDriver::on_data_received(uint8_t* data, uint16_t len)
{
hciTrSerialRxIncoming(data, len);
while (len) {
uint8_t chunk_length = std::min(len, (uint16_t) std::numeric_limits<uint8_t>::max());
data_received_handler(data, chunk_length);
len = len - chunk_length;
data = data + chunk_length;
}
}
void CordioHCITransportDriver::set_data_received_handler(data_received_handler_t handler)
{
data_received_handler = handler;
}
} // namespace cordio

View File

@ -28,6 +28,10 @@ namespace cordio {
* It allow the stack to write data in the HCI channel.
*/
class CordioHCITransportDriver {
// hook for internal tests and passthrough driver
friend class CordioHCIHook;
public:
/**
* Driver destructor.
@ -64,6 +68,13 @@ public:
* @param len Number of bytes received.
*/
static void on_data_received(uint8_t* data, uint16_t len);
private:
typedef void (*data_received_handler_t)(uint8_t* data, uint8_t len);
static data_received_handler_t data_received_handler;
static void set_data_received_handler(data_received_handler_t handler);
};
} // namespace cordio