解释代码#define TP_PRIO configMAX_PRIORITIES - 5 static void ble_tp_connected(struct bt_conn *conn, u8_t err); static void ble_tp_disconnected(struct bt_conn *conn, u8_t reason); static int bl_tp_send_indicate(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *data, u16_t len); struct bt_conn *ble_tp_conn; struct bt_gatt_exchange_params exchg_mtu; TaskHandle_t ble_tp_task_h; int tx_mtu_size = 20; u8_t tp_start = 0; static u8_t created_tp_task = 0; static u8_t isRegister = 0; static struct bt_conn_cb ble_tp_conn_callbacks = { .connected = ble_tp_connected, .disconnected = ble_tp_disconnected, }; static void ble_tp_tx_mtu_size(struct bt_conn *conn, u8_t err, struct bt_gatt_exchange_params *params) { if(!err) { tx_mtu_size = bt_gatt_get_mtu(ble_tp_conn); BT_WARN("ble tp echange mtu size success, mtu size: %d", tx_mtu_size); } else { BT_WARN("ble tp echange mtu size failure, err: %d", err); } } static void ble_tp_connected(struct bt_conn *conn, u8_t err) { if(err || conn->type != BT_CONN_TYPE_LE) { return; } int tx_octets = 0x00fb; int tx_time = 0x0848; int ret = -1; BT_INFO("%s",__func__); ble_tp_conn = conn; . ret = bt_le_set_data_len(ble_tp_conn, tx_octets, tx_time); if(!ret) { BT_WARN("ble tp set data length success."); } else { BT_WARN("ble tp set data length failure, err: %d\n", ret); } exchg_mtu.func = ble_tp_tx_mtu_size; ret = bt_gatt_exchange_mtu(ble_tp_conn, &exchg_mtu); if (!ret) { BT_WARN("ble tp exchange mtu size pending."); } else { BT_WARN("ble tp exchange mtu size failure, err: %d", ret); } } static void ble_tp_disconnected(struct bt_conn *conn, u8_t reason) { if(conn->type != BT_CONN_TYPE_LE) { return; } BT_INFO("%s",__func__); ble_tp_conn = NULL; } static int ble_tp_recv_rd(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset) { int size = 9; char data[9] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}; memcpy(buf, data, size); return size; }
时间: 2023-06-26 14:08:16 浏览: 149
C++ 中pragma once 与 #ifndef _XXX_H_ #define _XXX_H_的区别
5星 · 资源好评率100%
这段代码实现了一个 BLE(蓝牙低功耗)传输协议中的数据交互过程。其中,定义了一些回调函数,比如连接成功和断开连接的回调函数,以及一个接收数据的回调函数 ble_tp_recv_rd。同时也定义了一些变量和结构体,如 ble_tp_conn 表示当前连接的设备,exchg_mtu 表示传输数据的最大字节数,tx_mtu_size 表示当前传输的 MTU 大小等等。整个过程中,通过 BLE 的 API 函数实现数据传输和协议交互的功能。
阅读全文