Merge branch 'bugfix/fix_spp_can_not_connect_twice' into 'release/v3.3'

Bugfix/Fix SPP Reconnect Failed after Disconnet

See merge request espressif/esp-idf!12241
This commit is contained in:
Jiang Jiang Jian 2021-03-04 03:37:21 +00:00
commit c8915cd157
2 changed files with 33 additions and 16 deletions

View File

@ -211,15 +211,19 @@ void port_release_port (tPORT *p_port)
osi_mutex_global_lock();
RFCOMM_TRACE_DEBUG("port_release_port, p_port:%p", p_port);
if (p_port->rx.queue != NULL) {
while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_port->rx.queue)) != NULL) {
osi_free(p_buf);
while (fixed_queue_length(p_port->rx.queue) > 0) {
if((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->rx.queue)) != NULL){
osi_free(p_buf);
}
}
}
p_port->rx.queue_size = 0;
if (p_port->tx.queue != NULL) {
while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_port->tx.queue)) != NULL) {
osi_free(p_buf);
while (fixed_queue_length(p_port->tx.queue) > 0) {
if((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->tx.queue)) != NULL){
osi_free(p_buf);
}
}
}
p_port->tx.queue_size = 0;

View File

@ -115,12 +115,21 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
}
break;
case ESP_SPP_OPEN_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_OPEN_EVT");
esp_spp_write(param->open.handle, SPP_DATA_LEN, spp_data);
gettimeofday(&time_old, NULL);
if (param->open.status == ESP_SPP_SUCCESS) {
ESP_LOGI(SPP_TAG, "ESP_SPP_OPEN_EVT OK hdl:0x%x", param->open.handle);
esp_spp_write(param->open.handle, SPP_DATA_LEN, spp_data);
gettimeofday(&time_old, NULL);
} else {
ESP_LOGI(SPP_TAG, "ESP_SPP_OPEN_EVT Failed!, status:%d", param->open.status);
}
break;
case ESP_SPP_CLOSE_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_CLOSE_EVT");
if ((param->close.async == false && param->close.status == ESP_SPP_SUCCESS) || param->close.async) {
ESP_LOGI(SPP_TAG, "ESP_SPP_CLOSE_EVT OK, async:%d", param->close.async);
esp_spp_start_discovery(peer_bd_addr);
} else {
ESP_LOGI(SPP_TAG, "ESP_SPP_CLOSE_EVT failed!");
}
break;
case ESP_SPP_START_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_START_EVT");
@ -140,17 +149,21 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
}
break;
case ESP_SPP_WRITE_EVT:
if (param->write.status == ESP_SPP_SUCCESS) {
#if (SPP_SHOW_MODE == SPP_SHOW_DATA)
ESP_LOGI(SPP_TAG, "ESP_SPP_WRITE_EVT len=%d cong=%d", param->write.len , param->write.cong);
esp_log_buffer_hex("",spp_data,SPP_DATA_LEN);
ESP_LOGI(SPP_TAG, "ESP_SPP_WRITE_EVT len=%d cong=%d", param->write.len, param->write.cong);
esp_log_buffer_hex("", spp_data, SPP_DATA_LEN);
#else
gettimeofday(&time_new, NULL);
data_num += param->write.len;
if (time_new.tv_sec - time_old.tv_sec >= 3) {
print_speed();
}
gettimeofday(&time_new, NULL);
data_num += param->write.len;
if (time_new.tv_sec - time_old.tv_sec >= 3) {
print_speed();
}
#endif
if (param->write.cong == 0) {
} else {
ESP_LOGE(SPP_TAG, "ESP_SPP_WRITE_EVT failed(%d)!", param->write.status);
}
if (param->write.cong == 0 && param->write.handle > 0) {
esp_spp_write(param->write.handle, SPP_DATA_LEN, spp_data);
}
break;