如图:
HCI注册的函数指针,方便把数据交由BCSP的上层处理
typedef struct
{
void (*bcsp_link_cb)(uint8_t *data,uint32_t data_len);
void (*bccmd_cb)(uint8_t *data,uint32_t data_len);
void (*hq_cmd_cb)(uint8_t *data,uint32_t data_len);
void (*hci_cmd_evt_cb)(uint8_t *data,uint32_t data_len);
void (*hci_acl_cb)(uint8_t *data,uint32_t data_len);
}bcsp_callback_t;
针对BCSP的Header进行处理
/* BCSP flags 域解析 */
#define get_flag_ptype(x) (((x) & 0x80) >> 7)
#define get_flag_crc(x) (((x) & 0x40) >> 6)
#define get_flag_ack(x) (((x) & 0x38) >> 3)
#define get_flag_seq(x) ((x) & 0x07)
/* BCSP protocol ID 解析 */
#define get_protocol_id(x) ((x) & 0x0f)
/* BCSP payload legth解析 */
#define get_payload_length(x,y) ((y * 16) (((x) & 0xf0) >> 4))
/* 0xdb,0xdc转换为0xc0 */和/* 0xdb,0xdd转换为0xdb */
if(tmp_ptr[index] == SLIP_ESCAPE)
{
if(tmp_ptr[index 1] == SLIP_ESCAPE_FRAME)/* 0xdb,0xdc转换为0xc0 */
{
bcsp_parse_buf.buf[bcsp_parse_buf.index] = 0xc0;
bcsp_parse_buf.index = 1;
index ;
}
else if(tmp_ptr[index 1] == SLIP_ESCAPE_ESCAPE)/* 0xdb,0xdd转换为0xdb */
{
bcsp_parse_buf.buf[bcsp_parse_buf.index] = 0xdb;
bcsp_parse_buf.index = 1;
index ;
}
else/* 仅仅0xdb不做转换 */
{
bcsp_parse_buf.buf[bcsp_parse_buf.index] = tmp_ptr[index];
bcsp_parse_buf.index = 1;
}
}
#define SLIP_FRAME 0xC0
#define SLIP_ESCAPE 0xDB
#define SLIP_ESCAPE_FRAME 0xDC
#define SLIP_ESCAPE_ESCAPE 0xDD
BCSP测试API
void bcsp_test()
{
/* BCSP LINK EATABLISH DATA */
uint8_t test1[] = {0xC0,0x40,0x41,0x00,0x7E,0xDA,0xDC,0xED,0xED,0xA9,0x7A,0xC0};
uint8_t test3[] = {0xC0,0x40,0x41,0x00,0x7E,0xAC,0xAF,0xEF,0xEE,0xBB,0x84,0xC0};
uint8_t test4[] = {0xC0,0x40,0x41,0x00,0x7E,0xAD,0xEF,0xAC,0xED,0xA1,0xA6,0xC0};
uint8_t test5[] = {0xC0,0x40,0x41,0x00,0x7E,0xDE,0xAD,0xD0,0xD0,0x83,0x58,0xC0};
/* HCI reset command test */
uint8_t test2[] = {0xC0,0xDB,0xDC,0x35,0x00,0x0A,0x03,0x0C,0x00,0x95,0xDE,0xC0};
/* ACL data test */
uint8_t test6[] = {0xC0,0xF1,0xC6,0x00,0x48,0x4B,0x20,0x08,0x00,0x04,0x00,0x40,0x00,0x4B,0x3F,0x01,0x32,0xE1,0x01,0xC0};
bcsp_callback_t test_cb;
test_cb.bccmd_cb = TEST_bccmd_cb;
test_cb.bcsp_link_cb = TEST_bcsp_link_cb;
test_cb.hci_acl_cb = TEST_hci_acl_cb;
test_cb.hci_cmd_evt_cb = TEST_hci_cmd_evt_cb;
test_cb.hq_cmd_cb = TEST_hq_cmd_cb;
bcsp_init(&test_cb);
bcsp_pkt_parse(test1,sizeof(test1));
bcsp_pkt_parse(test3,sizeof(test3));
bcsp_pkt_parse(test4,sizeof(test4));
bcsp_pkt_parse(test5,sizeof(test5));
bcsp_pkt_parse(test2,sizeof(test2));
bcsp_pkt_parse(test6,sizeof(test6));
}
效果图:
整份代码会在完成后发出,或者有兴趣的可以中途像我索要