提交 8ac5c13d 编写于 作者: 徐宪辉's avatar 徐宪辉

aiui: Adapt new server.

* Adapt new server staging-api.iflyos.cn
Signed-off-by: 徐宪辉's avatar徐宪辉 <xhxu@listenai.com>
上级 6b680172
......@@ -42,6 +42,7 @@ CONFIG_LOG_BACKEND_SHOW_COLOR=y
CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP=y
CONFIG_LOG_BACKEND_UART=y
CONFIG_LOG_BACKEND_UART_OUTPUT_TEXT=y
# CONFIG_NET_WEBSOCKET_LOG_LEVEL_INF=y
### NEWLIBC ###
CONFIG_NEWLIB_LIBC=y
......
......@@ -41,12 +41,21 @@ static K_SEM_DEFINE(m_sem_spd_pause_completed, 0, 1);
extern void spd_resume_complete_handle(void);
extern void led_indication_state_set(uint32_t state);
const int max_send_size = 1024;
void wakeup_stream_data_process(uint8_t *data, size_t len)
{
int reminds_size = len;
int send_size = 0;
if (is_wakeup_waiting_done) {
aiui_audio_send_data(aiui_handle, data, len);
k_yield();
uint8_t *ptr = data;
do {
send_size = (reminds_size > max_send_size) ? max_send_size : reminds_size;
// LOG_INF("aiui_audio_send_data, send_size: %d", send_size);
aiui_audio_send_data(aiui_handle, ptr, send_size);
reminds_size -= send_size;
ptr += send_size;
} while (reminds_size > 0);
}
}
......
......@@ -7,6 +7,7 @@ typedef enum {
AIUI_ZBUS_DISCONNECTED = BIT(1),
AIUI_ZBUS_GOT_VAD = BIT(2),
AIUI_ZBUS_TTS_PLAY = BIT(3),
AIUI_ZBUS_AUDIO_STARTED = BIT(4),
AIUI_ZBUS_EVT_MAX = BIT(31),
} aiui_zbus_event_e;
......
......@@ -8,7 +8,7 @@
#include "csk_websocket_client.h"
LOG_MODULE_REGISTER(csk_websocket_client, CONFIG_NET_WEBSOCKET_LOG_LEVEL);
LOG_MODULE_REGISTER(csk_websocket_client, LOG_LEVEL_INF);
#define WS_CHECK_GOTO(cond, label, format, ...) ({ \
if (!(cond)) { \
......@@ -32,6 +32,7 @@ LOG_MODULE_REGISTER(csk_websocket_client, CONFIG_NET_WEBSOCKET_LOG_LEVEL);
#define WS_THREAD_NAME "csk_websocket_client"
typedef struct {
int ws_sockfd;
int http_sockfd;
......@@ -70,6 +71,8 @@ typedef struct ws_client_node {
#define DEFAULT_NET_DELAYTIME_MSEC 10
#define DEFAULT_PING_INTERVAL_SEC 10
#define DEFAULT_DNS_QURRY_CNT 5
#define WS_SEND_MSG_TIMEOUT_MS 1000
#define WS_GET_MUTEX_TIMEOUT_MS 1000
#define WS_CONNECTED_BIT BIT(0)
......@@ -110,7 +113,7 @@ static int create_http_socket(const char *server, int port)
}
char buf[NET_IPV4_ADDR_LEN];
LOG_DBG("host ip address: %s", net_addr_ntop(AF_INET, &addr.sin_addr, buf, sizeof(buf)));
LOG_INF("host ip address: %s", net_addr_ntop(AF_INET, &addr.sin_addr, buf, sizeof(buf)));
int sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
......@@ -140,7 +143,7 @@ fail:
static int connect_cb(int sock, struct http_request *req, void *user_data)
{
ws_client_handle_t *ws_client = user_data;
LOG_DBG("Websocket %d for %p connected.\n", sock, user_data);
LOG_INF("Websocket %d for %p connected.\n", sock, user_data);
if (ws_client->user_cb->connected_handler) {
ws_client->user_cb->connected_handler(ws_client->user_cb->connected_arg);
}
......@@ -169,7 +172,11 @@ static int ws_client_send_raw(int *sockfd, enum websocket_opcode opcode,
int remind = data_len;
int ret;
uint8_t *data_ptr = data;
k_mutex_lock(ws_client->mutex, K_FOREVER);
ret = k_mutex_lock(ws_client->mutex, K_MSEC(WS_GET_MUTEX_TIMEOUT_MS));
if (ret != 0) {
LOG_ERR("get ws_client->mutex failed, ret: %d", ret);
return ret;
}
do {
int send_size = remind > ws_client->max_send_size ? ws_client->max_send_size : remind;
bool is_fin = (send_size == remind) ? true : false;
......@@ -201,11 +208,11 @@ static void ping_work_handler(struct k_work *work)
{
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
ws_client_handle_t *ws_client = CONTAINER_OF(dwork, ws_client_handle_t, ping_work);
LOG_DBG("Send websocket ping");
LOG_INF("Send websocket ping");
k_mutex_lock(ws_client->mutex, K_FOREVER);
int send_ret = websocket_send_msg(ws_client->ws_sockfd, NULL, 0,
WEBSOCKET_OPCODE_PING,
true, true, SYS_FOREVER_MS);
true, true, WS_SEND_MSG_TIMEOUT_MS);
k_mutex_unlock(ws_client->mutex);
if (send_ret != 0) {
csk_ws_client_disconnect(ws_client);
......@@ -247,12 +254,15 @@ static void ws_thread_entry(void *arg1, void *arg2, void *arg3)
ret, ws_client->user_cb->message_arg);
}
} else if (message_type & WEBSOCKET_FLAG_PONG) {
LOG_DBG("Got pong msg with payload");
LOG_INF("Got pong msg with payload");
LOG_HEXDUMP_INF(ws_client->recv_buf, ret, "pong data");
} else if (message_type & WEBSOCKET_FLAG_PING) {
LOG_DBG("Got ping msg with payload");
LOG_INF("Got ping msg with payload");
} else if (message_type & WEBSOCKET_FLAG_CLOSE) {
LOG_INF("Got close msg with payload");
// csk_ws_client_disconnect(ws_client);
} else {
LOG_ERR("unknown msg with payload");
LOG_ERR("unknown msg with payload %d", message_type);
}
} else {
memcpy(&temp_buf[temp_buf_len], ws_client->recv_buf, ret);
......@@ -267,7 +277,7 @@ static void ws_thread_entry(void *arg1, void *arg2, void *arg3)
}
continue;
} else {
LOG_DBG("restruct frame, ret: %d\n", ret);
LOG_INF("restruct frame, ret: %d\n", ret);
if (!is_fragment) { //first frame
__ASSERT(temp_buf == NULL, "invalid pointer");
temp_buf = k_malloc(remaining + ret);
......@@ -289,14 +299,14 @@ static void ws_thread_entry(void *arg1, void *arg2, void *arg3)
csk_ws_client_disconnect(ws_client);
continue;
} else if (message_type & WEBSOCKET_FLAG_PONG) {
LOG_DBG("Got pong msg");
LOG_INF("Got pong msg");
ws_client->wait_for_pong_resp = false;
k_work_reschedule(&ws_client->ping_work, K_SECONDS(ws_client->pingpong_interval_sec));
} else if (message_type & WEBSOCKET_FLAG_PING) {
LOG_DBG("Got ping msg");
LOG_INF("Got ping msg");
} else {
if (message_type & WEBSOCKET_FLAG_CLOSE) {
LOG_DBG("Got close msg, disconnected");
LOG_INF("Got close msg, disconnected");
} else {
LOG_WRN("Got unknown msg, errno: %d", errno); //Fixme: some server has other data type
......@@ -307,8 +317,8 @@ static void ws_thread_entry(void *arg1, void *arg2, void *arg3)
}
} else {
LOG_ERR("recv failed errno %d, ret: %d",-errno, ret);
csk_ws_client_disconnect(ws_client);
LOG_ERR("recv failed errno %d",-errno);
continue;
}
}
......@@ -377,9 +387,9 @@ static int ws_client_config_req(ws_client_handle_t *ws_client, csk_ws_client_con
} else {
ws_client->port = config->port;
}
LOG_DBG("scheme: %s\n", ws_client->scheme);
LOG_DBG("host: %s\n", ws_client->host);
LOG_DBG("path: %s\n", ws_client->path);
LOG_INF("scheme: %s\n", ws_client->scheme);
LOG_INF("host: %s\n", ws_client->host);
LOG_INF("path: %s\n", ws_client->path);
ws_client->ws_req->host = ws_client->host;
ws_client->ws_req->url = ws_client->path ? ws_client->path : "/";
ws_client->ws_req->optional_headers = config->optional_headers;
......@@ -502,7 +512,7 @@ int csk_ws_client_connect(csk_ws_client_handle_t ws_handle)
ws_client->http_sockfd = http_sockfd;
int ws_sockfd = websocket_connect(ws_client->http_sockfd,
ws_client->ws_req,
SYS_FOREVER_MS, ws_client);
WS_SEND_MSG_TIMEOUT_MS, ws_client);
// printk("[%s %d]ws_sockfd %d\n",__FUNCTION__,__LINE__,ws_sockfd);
if (ws_client->ws_sockfd < 0) {
......@@ -543,7 +553,7 @@ int csk_ws_client_send_text(csk_ws_client_handle_t ws_handle, char *text_msg)
}
int ret = ws_client_send_raw(&ws_client->ws_sockfd,
WEBSOCKET_OPCODE_DATA_TEXT, text_msg,
strlen(text_msg), SYS_FOREVER_MS);
strlen(text_msg), WS_SEND_MSG_TIMEOUT_MS);
return ret;
}
......@@ -556,7 +566,7 @@ int csk_ws_client_send_bin(csk_ws_client_handle_t ws_handle, uint8_t *data, int
}
int ret = ws_client_send_raw(&ws_client->ws_sockfd,
WEBSOCKET_OPCODE_DATA_BINARY,
data, data_len, SYS_FOREVER_MS);
data, data_len, WS_SEND_MSG_TIMEOUT_MS);
return ret;
}
......
支持 Markdown
0% or
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册