component/bt : decrease callback cb param size

1. decrease callback cb param size
2. add write in gatt server demo
This commit is contained in:
Tian Hao 2016-11-23 15:34:21 +08:00
parent 9ec0fea8e1
commit 85aac3afa6
3 changed files with 27 additions and 13 deletions

View file

@ -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 {

View file

@ -44,12 +44,14 @@ void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
break;
}
case BTC_GATTS_ACT_SEND_RESPONSE: {
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;
}
default:
@ -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);
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, &param);
break;
}
@ -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, &param);
@ -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");
}

View file

@ -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: