From 85aac3afa6d84f3dc40ba6daae0e6e3e78d24d59 Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Wed, 23 Nov 2016 15:34:21 +0800 Subject: [PATCH] component/bt : decrease callback cb param size 1. decrease callback cb param size 2. add write in gatt server demo --- .../bt/bluedroid/api/include/esp_gatts_api.h | 2 +- .../btc/profile/std/gatt/btc_gatts.c | 31 ++++++++++++------- examples/09_gatt_server/main/gatts_demo.c | 7 ++++- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/components/bt/bluedroid/api/include/esp_gatts_api.h b/components/bt/bluedroid/api/include/esp_gatts_api.h index c87931d92..b48d5ebb0 100644 --- a/components/bt/bluedroid/api/include/esp_gatts_api.h +++ b/components/bt/bluedroid/api/include/esp_gatts_api.h @@ -60,7 +60,7 @@ typedef union { bool need_rsp; bool is_prep; uint16_t len; - uint8_t value[ESP_GATT_MAX_ATTR_LEN]; + uint8_t *value; } write; // param for ESP_GATTS_EXEC_WRITE_EVT struct gatts_exec_write_evt_param { diff --git a/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c index 99a2624fc..147b037f7 100644 --- a/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c +++ b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c @@ -44,11 +44,13 @@ void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) break; } case BTC_GATTS_ACT_SEND_RESPONSE: { - dst->send_rsp.rsp = (esp_gatt_rsp_t *)GKI_getbuf(sizeof(esp_gatt_rsp_t)); - if (dst->send_rsp.rsp) { - memcpy(dst->send_rsp.rsp, src->send_rsp.rsp, sizeof(esp_gatt_rsp_t)); - } else { - LOG_ERROR("%s %d no mem\n", __func__, msg->act); + if (src->send_rsp.rsp) { + dst->send_rsp.rsp = (esp_gatt_rsp_t *)GKI_getbuf(sizeof(esp_gatt_rsp_t)); + if (dst->send_rsp.rsp) { + memcpy(dst->send_rsp.rsp, src->send_rsp.rsp, sizeof(esp_gatt_rsp_t)); + } else { + LOG_ERROR("%s %d no mem\n", __func__, msg->act); + } } break; } @@ -212,15 +214,20 @@ void btc_gatts_call_handler(btc_msg_t *msg) break; case BTC_GATTS_ACT_SEND_RESPONSE: { esp_ble_gatts_cb_param_t param; - tBTA_GATTS_RSP rsp_struct; esp_gatt_rsp_t *p_rsp = arg->send_rsp.rsp; - btc_to_bta_response(&rsp_struct, p_rsp); - BTA_GATTS_SendRsp(arg->send_rsp.conn_id, arg->send_rsp.trans_id, + if (p_rsp) { + tBTA_GATTS_RSP rsp_struct; + btc_to_bta_response(&rsp_struct, p_rsp); + BTA_GATTS_SendRsp(arg->send_rsp.conn_id, arg->send_rsp.trans_id, arg->send_rsp.status, &rsp_struct); + param.rsp.handle = rsp_struct.attr_value.handle; + } else { + BTA_GATTS_SendRsp(arg->send_rsp.conn_id, arg->send_rsp.trans_id, + arg->send_rsp.status, NULL); + } param.rsp.status = 0; - param.rsp.handle = rsp_struct.attr_value.handle; BTC_GATTS_CB_TO_APP(ESP_GATTS_RESPONSE_EVT, ¶m); break; } @@ -272,7 +279,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg) { esp_ble_gatts_cb_param_t param; - tBTA_GATTS *p_data = (tBTA_GATTS *)msg->arg; + tBTA_GATTS *p_data = (tBTA_GATTS *)msg->arg; switch (msg->act) { case BTA_GATTS_REG_EVT: { @@ -306,7 +313,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg) param.write.need_rsp = p_data->req_data.p_data->write_req.need_rsp; param.write.is_prep = p_data->req_data.p_data->write_req.is_prep; param.write.len = p_data->req_data.p_data->write_req.len; - memcpy(param.write.value, p_data->req_data.p_data->write_req.value, param.write.len); + param.write.value = p_data->req_data.p_data->write_req.value; BTC_GATTS_CB_TO_APP(ESP_GATTS_WRITE_EVT, ¶m); @@ -425,6 +432,8 @@ void btc_gatts_cb_handler(btc_msg_t *msg) } btc_gatts_cb_param_copy_free(msg, p_data); + + //ets_printf("yyy\n"); } diff --git a/examples/09_gatt_server/main/gatts_demo.c b/examples/09_gatt_server/main/gatts_demo.c index 6f092202f..b5091d12a 100644 --- a/examples/09_gatt_server/main/gatts_demo.c +++ b/examples/09_gatt_server/main/gatts_demo.c @@ -134,7 +134,12 @@ static void gatts_event_handler(uint32_t event, void *param) ESP_GATT_OK, &rsp); break; } - case ESP_GATTS_WRITE_EVT: + case ESP_GATTS_WRITE_EVT:{ + LOG_INFO("GATT_WRITE_EVT, conn_id %d, trans_id %d, handle %d\n", p->write.conn_id, p->write.trans_id, p->write.handle); + LOG_INFO("GATT_WRITE_EVT, value len %d, value %08x\n", p->write.len, *(uint32_t *)p->write.value); + esp_ble_gatts_send_response(p->write.conn_id, p->write.trans_id, ESP_GATT_OK, NULL); + break; + } case ESP_GATTS_EXEC_WRITE_EVT: case ESP_GATTS_MTU_EVT: case ESP_GATTS_CONF_EVT: