typedef void (*on_ws_packet_callback)(uint8_t* data, size_t datalen, WebSocketMessageType type);
/* WebSocket消息队列系统 */
-#define WS_QUEUE_SIZE 4
+#define WS_QUEUE_SIZE 48
#define WS_MESSAGE_MAX_SIZE 1024
typedef struct {
- uint8_t data[WS_MESSAGE_MAX_SIZE];
+ uint8_t *data;//data[WS_MESSAGE_MAX_SIZE];
uint16_t length;
WebSocketMessageType type;
uint32_t timestamp;
/* 添加消息到队列 */
ws_message_item_t* item = &queue->messages[queue->tail];
+ if (item->data==NULL)
+ {
+ item->data=(uint8_t*)malloc(WS_MESSAGE_MAX_SIZE);
+ if (item->data==NULL)
+ {
+ osMutexRelease(queue->mutex);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to malloc ws_message_item_t");
+ return -1;
+ }
+ }
memset(item->data,0,WS_MESSAGE_MAX_SIZE);
memcpy(item->data, data, length);
item->length = length;
uint16_t copy_len = (item->length > max_length) ? max_length : item->length;
memcpy(data, item->data, copy_len);
*type = item->type;
+ if (item->data)
+ {
+ free(item->data);
+ item->data=NULL;
+ }
/* 标记为已使用 */
item->in_use = false;
queue->head = (queue->head + 1) % WS_QUEUE_SIZE;
queue->count--;
-
osMutexRelease(queue->mutex);
return copy_len;
{
recv_buf[len] = '\0';
}
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bk_websocket_demo len %d\n",len);
if (len == -1 || type == WS_CLOSE) {
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WebSocket connection closed");
break;
#ifdef ASR_HODE
memcpy_s(&result_str_asr[strlen(result_str_asr)],AI_RESULT_STR_LEN/2,result_str,strlen(result_str));
- if(asr_is_stop==1 && strlen(result_str_asr))
- {
- send_ai_txt(0,result_str_asr);
- ble_set_ai_Question_str(result_str_asr);
+ // if(asr_is_stop==1 && strlen(result_str_asr))
+ // {
+ // send_ai_txt(0,result_str_asr);
+ // ble_set_ai_Question_str(result_str_asr);
- memset_s(result_str_asr,AI_RESULT_STR_LEN,0,AI_RESULT_STR_LEN);
- }
+ // memset_s(result_str_asr,AI_RESULT_STR_LEN,0,AI_RESULT_STR_LEN);
+ // }
#else