WS刚连接成功可以进行 对话,超过30sWS断开后,语音上行停止,需要修复
This commit is contained in:
@@ -30,6 +30,10 @@
|
||||
#define CONFIG_TQ_SYSTEM_EVENT_TASK_STACK 4096
|
||||
#endif
|
||||
|
||||
#define CONTROL_PLANE_PTT_HOLD_STEP_MS 80
|
||||
#define CONTROL_PLANE_PTT_HOLD_TASK_STACK 4096
|
||||
#define CONTROL_PLANE_PTT_HOLD_TASK_PRIORITY 4
|
||||
|
||||
#ifndef CONFIG_TQ_LOCAL_TASK_CORE
|
||||
#define CONFIG_TQ_LOCAL_TASK_CORE 1
|
||||
#endif
|
||||
@@ -44,7 +48,9 @@ static const char *TAG = "cp_system_event";
|
||||
|
||||
static QueueHandle_t s_system_event_queue;
|
||||
static TaskHandle_t s_system_event_task;
|
||||
static TaskHandle_t s_ptt_hold_task;
|
||||
static volatile bool s_stop_requested;
|
||||
static volatile bool s_ptt_hold_active;
|
||||
|
||||
static const char *control_plane_event_family_name(control_plane_event_family_t family)
|
||||
{
|
||||
@@ -106,6 +112,80 @@ const char *control_plane_key_event_type_name(control_plane_key_event_type_t typ
|
||||
}
|
||||
}
|
||||
|
||||
static void control_plane_ptt_hold_task(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
ESP_LOGI(TAG, "PTT hold task started");
|
||||
bool start_requested = false;
|
||||
|
||||
while (s_ptt_hold_active && !s_stop_requested) {
|
||||
if (!control_plane_is_sta_connected()) {
|
||||
vTaskDelay(pdMS_TO_TICKS(CONTROL_PLANE_PTT_HOLD_STEP_MS));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!control_plane_multimodal_is_connected() && !start_requested) {
|
||||
esp_err_t schedule_err = control_plane_schedule_websocket_wait_task();
|
||||
if (schedule_err != ESP_OK && schedule_err != ESP_ERR_INVALID_STATE) {
|
||||
ESP_LOGW(TAG,
|
||||
"PTT multimodal start schedule failed: %s",
|
||||
esp_err_to_name(schedule_err));
|
||||
} else {
|
||||
start_requested = true;
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t press_err = control_plane_multimodal_handle_ptt_press_step();
|
||||
if (press_err != ESP_OK &&
|
||||
press_err != ESP_ERR_INVALID_STATE &&
|
||||
press_err != ESP_ERR_NOT_SUPPORTED) {
|
||||
ESP_LOGW(TAG, "PTT press step failed: %s", esp_err_to_name(press_err));
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(CONTROL_PLANE_PTT_HOLD_STEP_MS));
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "PTT hold task stopped");
|
||||
s_ptt_hold_task = NULL;
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
static esp_err_t control_plane_start_ptt_hold_task(void)
|
||||
{
|
||||
s_ptt_hold_active = true;
|
||||
if (s_ptt_hold_task != NULL) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
BaseType_t created = xTaskCreatePinnedToCore(control_plane_ptt_hold_task,
|
||||
"cp_ptt_hold",
|
||||
CONTROL_PLANE_PTT_HOLD_TASK_STACK,
|
||||
NULL,
|
||||
CONTROL_PLANE_PTT_HOLD_TASK_PRIORITY,
|
||||
&s_ptt_hold_task,
|
||||
CONTROL_PLANE_SYSTEM_EVENT_TASK_CORE);
|
||||
if (created != pdPASS) {
|
||||
s_ptt_hold_task = NULL;
|
||||
s_ptt_hold_active = false;
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void control_plane_stop_ptt_hold_task(void)
|
||||
{
|
||||
s_ptt_hold_active = false;
|
||||
|
||||
for (int i = 0; i < 10 && s_ptt_hold_task != NULL; ++i) {
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
}
|
||||
if (s_ptt_hold_task != NULL) {
|
||||
vTaskDelete(s_ptt_hold_task);
|
||||
s_ptt_hold_task = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void control_plane_dispatch_key_event(const control_plane_key_event_t *event)
|
||||
{
|
||||
if (event == NULL) {
|
||||
@@ -120,6 +200,32 @@ static void control_plane_dispatch_key_event(const control_plane_key_event_t *ev
|
||||
event->level,
|
||||
event->press_duration_ms,
|
||||
event->click_count);
|
||||
|
||||
if (event->key_id != CONTROL_PLANE_KEY_ID_PTT) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event->type) {
|
||||
case CONTROL_PLANE_KEY_EVENT_PRESSED: {
|
||||
esp_err_t start_err = control_plane_start_ptt_hold_task();
|
||||
if (start_err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "PTT hold task start failed: %s", esp_err_to_name(start_err));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CONTROL_PLANE_KEY_EVENT_RELEASED: {
|
||||
control_plane_stop_ptt_hold_task();
|
||||
esp_err_t release_err = control_plane_multimodal_handle_ptt_release();
|
||||
if (release_err != ESP_OK && release_err != ESP_ERR_INVALID_STATE) {
|
||||
ESP_LOGW(TAG, "PTT release failed: %s", esp_err_to_name(release_err));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void control_plane_dispatch_system_event(const control_plane_system_event_t *event)
|
||||
@@ -225,6 +331,7 @@ void control_plane_stop_system_event_task(void)
|
||||
{
|
||||
#if CONFIG_TQ_SYSTEM_EVENT_ENABLE
|
||||
s_stop_requested = true;
|
||||
control_plane_stop_ptt_hold_task();
|
||||
|
||||
for (int i = 0; i < 20 && s_system_event_task != NULL; ++i) {
|
||||
vTaskDelay(pdMS_TO_TICKS(50));
|
||||
|
||||
Reference in New Issue
Block a user