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,17 +211,21 @@ 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) {
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) {
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;
osi_mutex_global_unlock();

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");
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,6 +149,7 @@ 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);
@ -150,7 +160,10 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
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;