自定义杰理AC63系列BLE数据发送函数

文章介绍了如何自定义BLE数据发送函数,将数据发送、检查和连接处理等步骤封装,以实现在程序任意位置发送数据。关键函数包括`ble_comm_att_send_data`,配合`ble_comm_att_check_send`检查缓存和`ble_gatt_server_characteristic_ccc_get`验证NOTIFY权限。此外,还详细阐述了连接句柄查询和ATT服务特征表的作用。

自定义BLE数据发送函数,就是将数据发送、数据发送前的检查、以及conn_handle查询等封装在一起,脱离SDK中的相关回调函数,在程序任意位置实现发送数据功能。

1. SDK中的BLE数据发送函数

BLE的数据发送函数定义在apps\common\third_party_profile\jieli\gatt_common\le_gatt_common.c文件里。

int ble_comm_att_send_data(u16 conn_handle, u16 att_handle, u8 *data, u16 len, att_op_type_e op_type)
{
   
   
    gatt_op_ret_e ret = GATT_OP_RET_SUCESS;
    u16 tmp_16;

    if (!conn_handle) {
   
   
        return GATT_CMD_PARAM_ERROR;
    }

    switch (op_type) {
   
   
    case ATT_OP_READ:
        tmp_16  = 0x55A1;//fixed
        ret = ble_op_multi_att_send_data(conn_handle, att_handle, &tmp_16, 2, op_type);
        break;

    case ATT_OP_READ_LONG:
        tmp_16  = 0x55A2;//fixed
        ret = ble_op_multi_att_send_data(conn_handle, att_handle, &tmp_16, 2, op_type);
        break;

    default:
        ret = ble_op_multi_att_send_data(conn_handle, att_handle, data, len, op_type);
        break;
    }

    if (ret) {
   
   
        const char *err_string;

        int error_id = (int)0 - (int)GATT_CMD_RET_BUSY + (int)ret;
        if (error_id >= 0 && error_id < sizeof(gatt_op_error_string) / sizeof(char *)) {
   
   
            err_string = gatt_op_error_string[error_id];
        } else {
   
   
            err_string = "UNKNOW GATT_ERROR";
        }

        log_error("att_send_fail: %d!!!,%s", ret, err_string);
        log_error("param:%04x, %04x, %02x,len= %d", conn_handle, att_handle, op_type, len);
        /* put_buf(data,len); */
    }
    return ret;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ydgd118

您的鼓励是我最大的动力!谢赏!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值