BLE 多从机通知注册成功时,无法区分是哪个设备的回调。
Posted: Thu Apr 13, 2023 1:46 am
IDF注册通知代码如下:
esp_err_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,esp_bd_addr_t server_bda, uint16_t handle)
{
btc_msg_t msg = {0};
btc_ble_gattc_args_t arg;
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_REG_FOR_NOTIFY;
arg.reg_for_notify.gattc_if = gattc_if;
memcpy(arg.reg_for_notify.remote_bda, server_bda, sizeof(esp_bd_addr_t));
arg.reg_for_notify.handle = handle;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
注册结果进入回调前如下:
static void btc_gattc_reg_for_notify(btc_ble_gattc_args_t *arg)
{
tBTA_GATT_STATUS status;
esp_ble_gattc_cb_param_t param;
status = BTA_GATTC_RegisterForNotifications(arg->reg_for_notify.gattc_if,
arg->reg_for_notify.remote_bda,
arg->reg_for_notify.handle);
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
param.reg_for_notify.status = status;
param.reg_for_notify.handle = arg->reg_for_notify.handle;
btc_gattc_cb_to_app(ESP_GATTC_REG_FOR_NOTIFY_EVT, arg->reg_for_notify.gattc_if, ¶m);
}
我就搞不明白,明明底层带了对等设备地址,为啥传给上层时就给丢掉了。这是逼我自己改底层?开发人员出来挨打!
esp_err_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,esp_bd_addr_t server_bda, uint16_t handle)
{
btc_msg_t msg = {0};
btc_ble_gattc_args_t arg;
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_REG_FOR_NOTIFY;
arg.reg_for_notify.gattc_if = gattc_if;
memcpy(arg.reg_for_notify.remote_bda, server_bda, sizeof(esp_bd_addr_t));
arg.reg_for_notify.handle = handle;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
注册结果进入回调前如下:
static void btc_gattc_reg_for_notify(btc_ble_gattc_args_t *arg)
{
tBTA_GATT_STATUS status;
esp_ble_gattc_cb_param_t param;
status = BTA_GATTC_RegisterForNotifications(arg->reg_for_notify.gattc_if,
arg->reg_for_notify.remote_bda,
arg->reg_for_notify.handle);
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
param.reg_for_notify.status = status;
param.reg_for_notify.handle = arg->reg_for_notify.handle;
btc_gattc_cb_to_app(ESP_GATTC_REG_FOR_NOTIFY_EVT, arg->reg_for_notify.gattc_if, ¶m);
}
我就搞不明白,明明底层带了对等设备地址,为啥传给上层时就给丢掉了。这是逼我自己改底层?开发人员出来挨打!