mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 20:24:32 +02:00
fix spp connect failed or discovery failed after the first connection release
This commit is contained in:
@@ -211,17 +211,21 @@ void port_release_port (tPORT *p_port)
|
|||||||
osi_mutex_global_lock();
|
osi_mutex_global_lock();
|
||||||
RFCOMM_TRACE_DEBUG("port_release_port, p_port:%p", p_port);
|
RFCOMM_TRACE_DEBUG("port_release_port, p_port:%p", p_port);
|
||||||
if (p_port->rx.queue != NULL) {
|
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);
|
osi_free(p_buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
p_port->rx.queue_size = 0;
|
p_port->rx.queue_size = 0;
|
||||||
|
|
||||||
if (p_port->tx.queue != NULL) {
|
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);
|
osi_free(p_buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
p_port->tx.queue_size = 0;
|
p_port->tx.queue_size = 0;
|
||||||
|
|
||||||
osi_mutex_global_unlock();
|
osi_mutex_global_unlock();
|
||||||
|
@@ -115,12 +115,21 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ESP_SPP_OPEN_EVT:
|
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);
|
esp_spp_write(param->open.handle, SPP_DATA_LEN, spp_data);
|
||||||
gettimeofday(&time_old, NULL);
|
gettimeofday(&time_old, NULL);
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(SPP_TAG, "ESP_SPP_OPEN_EVT Failed!, status:%d", param->open.status);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ESP_SPP_CLOSE_EVT:
|
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;
|
break;
|
||||||
case ESP_SPP_START_EVT:
|
case ESP_SPP_START_EVT:
|
||||||
ESP_LOGI(SPP_TAG, "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;
|
break;
|
||||||
case ESP_SPP_WRITE_EVT:
|
case ESP_SPP_WRITE_EVT:
|
||||||
|
if (param->write.status == ESP_SPP_SUCCESS) {
|
||||||
#if (SPP_SHOW_MODE == SPP_SHOW_DATA)
|
#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_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_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();
|
print_speed();
|
||||||
}
|
}
|
||||||
#endif
|
#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);
|
esp_spp_write(param->write.handle, SPP_DATA_LEN, spp_data);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user