From: cheng.chen Date: Fri, 3 Apr 2026 10:37:39 +0000 (+0800) Subject: 解决连续对话模式打断无反应和延时长的问题 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=d035a6d709ceea9123b5c9b1305bd987b1c2c709;p=mirrors%2FFX01.git 解决连续对话模式打断无反应和延时长的问题 --- diff --git a/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.c b/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.c index bd30c6e..d07bd33 100644 --- a/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.c +++ b/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.c @@ -40,12 +40,14 @@ #endif #include "bk_make_time.h" - +static aos_thread_id UI_UART_read_id = 0; // #include "opus/include/opus.h" char FXH01_Version[100]; u8 current_card_id = 0; + +u8 chumo_exp_open = 1; u8 VC_TTS_PLAY_EVENT = 0; typedef enum { @@ -63,7 +65,7 @@ volatile char AI_VC_stata = 0;//VC是否在运行 volatile char app_audio_flag = 0; volatile char audio_stop_flag = 0; int32_t bk_audio_start_callback(void *p_param, uint32_t size); -#define IS_KWS 0 +#define IS_KWS 1 #define IS_VAD 1 #define VAD_RB_LEN 32*1024 @@ -82,12 +84,13 @@ static u32* ai_uart_handle; static u32* ui_uart_handle=NULL; +static u8 is_dialog_status=0; static aos_thread_id AI_VC_send_task_id = 0; char AI_VC_send_task_flag = 0; static aos_thread_id AI_VC_read_task_id = 0; - +static aos_thread_id AI_VC_read_IOT_id = 0; volatile char AI_VC_read_task_flag = 0; static aos_queue_ptr AI_VC_send_queue = NULL; @@ -112,21 +115,30 @@ WebSocketClient* websocket_res[WEBSOCKET_MAX_NUM] = {0}; WebSocketClient *AI_client_VC = NULL; +WebSocketClient *AI_client_IOT = NULL; +static u8 issend_start_up=0; static u32 close_timerout = 0; + +static u32 sleep_chumo_timerout = 0; + static u32 VC_pingping_timerout = 0; static u32 VC_END_play_timerout = 0; static char *AI_TTS_str = NULL; static char *AI_ASR_str = NULL; #define AI_ASR_STR_MAX_LEN 1024*2 static char *AI_ASR_str_tmp = NULL; + +static int has_tmp_result=0; #define AI_ASR_STR_MAX_TMP_LEN 1024 static aos_timer_ptr AI_VC_1S_timer = NULL; static aos_timer_ptr sys_10S_timer = NULL; +static aos_timer_ptr AI_VC_60S_timer = NULL; + //static aos_timer_ptr AI_VC_60S_timer = NULL; static int login_timer_count = 0; @@ -142,6 +154,8 @@ VC_state_type VC_state = VC_State_None; static u8 uid[50]; static int uid_len =0; +//int type_test=1; + //关闭录音 void VC_record_End(void); //打开录音 @@ -175,8 +189,6 @@ int bk_get_iccid(char *iccid) } - - #if (BK_LOG_CFG==BK_LOG_UART) int bk_printf(const char *format, ...) { @@ -315,10 +327,12 @@ void reset_VC_cfg(void) //vc_cfg.dev_type = DEV_ADS;//奥德赛 vc_cfg.dev_type = DEV_JSWM;//金山完美 //vc_cfg.dev_type = DEV_ALY;//阿里云 - strcpy(vc_cfg.server_ip,"amp.raisound.com");//服务器地址 + // strcpy(vc_cfg.server_ip,"amp.raisound.com");//服务器地址 // strcpy(vc_cfg.server_ip,"115.190.94.208:22080");//服务器地址 + strcpy(vc_cfg.server_ip,"118.145.158.207:22080");//服务器地址 + vc_cfg.VC_mode =2;//对话模式 strcpy(vc_cfg.power_on_tone,"你好,请问您有什么需要我帮忙的吗?");//开机提示词 vc_cfg.VC_record_TYPE = VC_record_TYPE_PCM;//录音格式 @@ -328,7 +342,7 @@ void reset_VC_cfg(void) vc_cfg.is_VAD = IS_VAD;//=1打开vad打断 vc_cfg.is_KWS = IS_KWS;//=1打开本地语言打断 vc_cfg.speech_rate = 0;//语速配置 - vc_cfg.vad_silence = 500;//vad断句时间 ms + vc_cfg.vad_silence = 800;//vad断句时间 ms 500 vc_cfg.VC_TTS_volume = 80;//音量 } int init_VC_cfg(void) @@ -409,6 +423,10 @@ static int play_audio_file_event(char *file_name); u8 *save_temp_tts=NULL; +int is_guanji=0; + +void aic_https_demotest(); + int check_text(char *text,int ret_str_len) { //bk_printf("check_text:text:%s",text); @@ -441,8 +459,19 @@ int check_text(char *text,int ret_str_len) tmp_data_len = snprintf(tmp_data,sizeof(tmp_data),"配置成功,当前音量%d。",vc_cfg.VC_TTS_volume); AI_AMP_MSG_put(tmp_data,tmp_data_len,VC_TTS_PLAY); } - // if(vc_cfg.VC_mode != 0) + // if(vc_cfg.VC_mode != 0) app_audio_set_master_volume(15*vc_cfg.VC_TTS_volume/100); + // else{ + + // if(vc_cfg.VC_TTS_volume > 80) + // { + + // app_audio_set_master_volume(15*50/100); + // }else{ + + // app_audio_set_master_volume(15*vc_cfg.VC_TTS_volume/100); + // } + // } is_save_VC_cfg = 1; @@ -462,9 +491,19 @@ int check_text(char *text,int ret_str_len) AI_AMP_MSG_put(tmp_data,tmp_data_len,VC_TTS_PLAY); } - //if(vc_cfg.VC_mode != 0) + // if(vc_cfg.VC_mode != 0) app_audio_set_master_volume(15*vc_cfg.VC_TTS_volume/100); + // else{ + // if(vc_cfg.VC_TTS_volume > 80) + // { + + // app_audio_set_master_volume(15*50/100); + // }else{ + + // app_audio_set_master_volume(15*vc_cfg.VC_TTS_volume/100); + // } + // } is_save_VC_cfg = 1; ret = 0; @@ -509,6 +548,27 @@ int check_text(char *text,int ret_str_len) // status + + if(strstr(text,"关闭显示屏")) + { + + bk_printf("关闭显示屏"); + + aic_gpio_output(GPIO_15,GPIO_OUTPUT_LVL_LOW );//lcd open ldo + ret = 0; + goto RET; + } + + if(strstr(text,"打开显示屏")) + { + + bk_printf("打开显示屏"); + + aic_gpio_output(GPIO_15,GPIO_OUTPUT_LVL_HIGH );//lcd open ldo + ret = 0; + goto RET; + } + if(strstr(text,"升级版本")) { @@ -516,6 +576,21 @@ int check_text(char *text,int ret_str_len) ret = 0; goto RET; } +//aic_gpio_output(GPIO_15,GPIO_OUTPUT_LVL_HIGH );//lcd open ldo + if(strstr(text,"结束对话")||strstr(text,"关闭对话")||strstr(text,"退出对话")) + { + + // AI_AMP_MSG_put("拜拜",strlen("拜拜"),VC_TTS_PLAY); + + // aos_sleep(1000); + + is_dialog_status=1; + + // AI_AMP_MSG_put(0,0,VC_CLOSE); + + // ret = 0; + // goto RET; + } if(strstr(text,"帮我生成语音文件")) { @@ -528,6 +603,18 @@ int check_text(char *text,int ret_str_len) //||strstr(text,"做一个惊讶的表情")||strstr(text,"做一个开心的表情") + if(strstr(text,"做一个")&&strstr(text,"表情")) + { + // need_express_cmd=1; + AI_AMP_MSG_put("开始做表情了",strlen("开始做表情了"),VC_TTS_PLAY); + + send_express_str(text); + + + ret = 0; + goto RET; + } + if(strstr(text,"做一个发怒的表情")) { AI_AMP_MSG_put("开始做表情了",strlen("开始做表情了"),VC_TTS_PLAY); @@ -553,21 +640,285 @@ int check_text(char *text,int ret_str_len) ret = 0; goto RET; } - if(strstr(text,"做一个开心的表情")) + + + if(strstr(text,"做一个搞怪的表情")) { AI_AMP_MSG_put("开始做表情了",strlen("开始做表情了"),VC_TTS_PLAY); if(ui_uart_handle){ - u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x08,0x01,0x0a}; + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x03,0x01,0x05}; + uart_write(ui_uart_handle,cmd_ui, 7); + } + + ret = 0; + goto RET; + } + + if(strstr(text,"做一个卡通的表情")) + { + + AI_AMP_MSG_put("开始做表情了",strlen("开始做表情了"),VC_TTS_PLAY); + + if(ui_uart_handle){ + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x07,0x01,0x09}; + uart_write(ui_uart_handle,cmd_ui, 7); + } + + ret = 0; + goto RET; + } + + if(strstr(text,"做一个花痴的表情")) + { + + AI_AMP_MSG_put("开始做表情了",strlen("开始做表情了"),VC_TTS_PLAY); + + if(ui_uart_handle){ + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x04,0x01,0x06}; + uart_write(ui_uart_handle,cmd_ui, 7); + } + + ret = 0; + goto RET; + } + + if(strstr(text,"做一个惊喜的表情")) + { + + AI_AMP_MSG_put("开始做表情了",strlen("开始做表情了"),VC_TTS_PLAY); + + if(ui_uart_handle){ + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x03,0x01,0x05}; uart_write(ui_uart_handle,cmd_ui, 7); } + #if SUPPORT_MOT + mot_nod_diantou(2); + #endif + ret = 0; + goto RET; + } + + if(strstr(text,"做一个哭泣的表情")) + { + + AI_AMP_MSG_put("开始做表情了",strlen("开始做表情了"),VC_TTS_PLAY); + + if(ui_uart_handle){ + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x05,0x01,0x07}; + uart_write(ui_uart_handle,cmd_ui, 7); + } + #if SUPPORT_MOT + mot_nod_ditou(2); + #endif + ret = 0; + goto RET; + } + + if(strstr(text,"做一个不满的表情")) + { + + AI_AMP_MSG_put("开始做表情了",strlen("开始做表情了"),VC_TTS_PLAY); + + if(ui_uart_handle){ + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x07,0x01,0x09}; + uart_write(ui_uart_handle,cmd_ui, 7); + } + #if SUPPORT_MOT + mot_nod_exp(4,2); + #endif + ret = 0; + goto RET; + } + + if(strstr(text,"做一个坏笑的表情")) + { + + AI_AMP_MSG_put("开始做表情了",strlen("开始做表情了"),VC_TTS_PLAY); + + if(ui_uart_handle){ + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x06,0x01,0x08}; + uart_write(ui_uart_handle,cmd_ui, 7); + } + #if SUPPORT_MOT + mot_nod_exp(5,2); + #endif + ret = 0; + goto RET; + } + if(strstr(text,"做一个生气的表情")) + { + + AI_AMP_MSG_put("开始做表情了",strlen("开始做表情了"),VC_TTS_PLAY); + + if(ui_uart_handle){ + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x04,0x01,0x06}; + uart_write(ui_uart_handle,cmd_ui, 7); + } + #if SUPPORT_MOT + mot_nod_exp(6,2); + #endif + ret = 0; + goto RET; + } + if(strstr(text,"做一个卖萌的表情")) + { + + AI_AMP_MSG_put("开始做表情了",strlen("开始做表情了"),VC_TTS_PLAY); + + if(ui_uart_handle){ + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x02,0x01,0x04}; + uart_write(ui_uart_handle,cmd_ui, 7); + } + #if SUPPORT_MOT + mot_nod_exp(7,2); + #endif + ret = 0; + goto RET; + } + if(strstr(text,"做一个开心的表情")) + { + + AI_AMP_MSG_put("开始做表情了",strlen("开始做表情了"),VC_TTS_PLAY); + + if(ui_uart_handle){ + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x01,0x01,0x03}; + uart_write(ui_uart_handle,cmd_ui, 7); + } + #if SUPPORT_MOT + mot_nod_exp(8,2); + #endif ret = 0; goto RET; } + if(strstr(text,"打开触摸动作")) + { + + chumo_exp_open=1; + AI_AMP_MSG_put("触摸动作已打开",strlen("触摸动作已打开"),VC_TTS_PLAY); + + ret = 0; + goto RET; + + } + + if(strstr(text,"关闭触摸动作")) + { + + chumo_exp_open=0; + AI_AMP_MSG_put("触摸动作已关闭",strlen("触摸动作已关闭"),VC_TTS_PLAY); + + ret = 0; + goto RET; + + } + + // if(strstr(text,"摇头")) + // { + // AI_AMP_MSG_put("开始摇头了",strlen("开始摇头了"),VC_TTS_PLAY); + + // if(ui_uart_handle){ + // u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x01,0x01,0x03}; + // uart_write(ui_uart_handle,cmd_ui, 7); + // } + + // bk_printf("摇头"); + // #if SUPPORT_MOT + // mot_nod_diantou(2); + // #endif + // ret = 0; + // goto RET; + + // } + + // if(strstr(text,"点头")) + // { + // // AI_AMP_MSG_put("开始做动作了",strlen("开始做动作了"),VC_TTS_PLAY); + + // AI_AMP_MSG_put("开始点头了",strlen("开始点头了"),VC_TTS_PLAY); + + // // if(ui_uart_handle){ + // // u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x08,0x01,0x0a}; + // // uart_write(ui_uart_handle,cmd_ui, 7); + // // } + // bk_printf("点头"); + // #if SUPPORT_MOT + // mot_nod_yaotou(2); + // #endif + // ret = 0; + // goto RET; + + // } + + + + + // if(strstr(text,"抬头")) + // { + // AI_AMP_MSG_put("开始抬头了",strlen("开始抬头了"),VC_TTS_PLAY); + + // bk_printf("抬头"); + // #if SUPPORT_MOT + // mot_nod_ditou(2); + // #endif + // ret = 0; + // goto RET; + + // } + + // if(strstr(text,"低头")) + // { + // AI_AMP_MSG_put("开始低头了",strlen("开始低头了"),VC_TTS_PLAY); + + // bk_printf("低头"); + // #if SUPPORT_MOT + // mot_nod_taitou(2); + // #endif + // ret = 0; + // goto RET; + + // } + + // if(strstr(text,"向左转")) + // { + // AI_AMP_MSG_put("开始向左转",strlen("开始向左转"),VC_TTS_PLAY); + + // bk_printf("向左转"); + // #if SUPPORT_MOT + // mot_nod_exp(15,2); + // #endif + // ret = 0; + // goto RET; + + // } + + // if(strstr(text,"向右转")) + // { + // AI_AMP_MSG_put("开始向右转",strlen("开始向右转"),VC_TTS_PLAY); + + // bk_printf("向右转"); + // #if SUPPORT_MOT + // mot_nod_exp(16,2); + // #endif + // ret = 0; + // goto RET; + + // } + + + + if(strstr(text,"查询马达状态")) + { + mot_nod_status(); + + // aic_http_demotest(); + ret = 0; + goto RET; + } // if(strstr(text,"导出文件")) @@ -798,6 +1149,9 @@ int check_text(char *text,int ret_str_len) if(ret_str_len<16 && (strstr(text,"关机") )) { tmp_data_len = snprintf(tmp_data,sizeof(tmp_data),"正在关机。"); + + is_guanji=1; + AI_AMP_MSG_put(tmp_data,tmp_data_len,VC_TTS_PLAY_POWER_OFF); } if(ret_str_len<16 && (strstr(text,"重启") )) @@ -899,14 +1253,20 @@ static void AI_VC_send_satrt(char is_greeting) // 创建 custom_variables 对象 cJSON *custom_variables = cJSON_CreateObject(); + cJSON_AddStringToObject(custom_variables, "name", "食梦貘"); + + // cJSON_AddStringToObject(custom_variables, "coze_current_time", "23:00"); + + // cJSON_AddStringToObject(custom_variables, "coze_current_date", "2025-10-01"); + cJSON_AddItemToObject(dialog_cfg, "custom_variables", custom_variables); // 创建 greeting 对象 cJSON *greeting = cJSON_CreateObject(); if(is_greeting == 1) { - cJSON_AddBoolToObject(greeting, "enabled", TRUE);//是否播放提示词 + cJSON_AddBoolToObject(greeting, "enabled", FALSE);//是否播放提示词 cJSON_AddStringToObject(greeting, "content", "你好"); cJSON_AddItemToObject(dialog_cfg, "greeting", greeting); }else @@ -937,6 +1297,26 @@ static void AI_VC_send_satrt(char is_greeting) cJSON_AddStringToObject(bot_option, "workflow_id", "7508598451564150820"); } cJSON_AddItemToObject(dialog_cfg, "bot_option", bot_option); + + cJSON *dify_option = cJSON_CreateObject(); + + cJSON *inputs_option = cJSON_CreateObject(); + + cJSON_AddStringToObject(inputs_option, "devToken", get_token());//奥德赛 + cJSON_AddStringToObject(inputs_option, "deviceId", vc_cfg.dev_imei); + + // cJSON_AddStringToObject(custom_variables, "coze_current_time", "23:00"); + + // cJSON_AddStringToObject(inputs_option, "coze_current_date", "2025-10-01"); + + if(is_greeting) + cJSON_AddBoolToObject(inputs_option, "start", true);// 是否在打断后拼接前后的ASR结果 + + + cJSON_AddItemToObject(dify_option, "inputs", inputs_option); + + cJSON_AddItemToObject(dialog_cfg, "dify_option", dify_option); + if(vc_cfg.dev_type == DEV_ALY) { // 创建 dialog_attributes对象下cfg对象下 greeting 对象 @@ -964,7 +1344,12 @@ static void AI_VC_send_satrt(char is_greeting) cJSON *outbound_cfg = cJSON_CreateObject(); if(outbound_attributes_format == attributes_format_OPUS) { - cJSON_AddStringToObject(outbound_cfg, "format", "ogg_opus"); + cJSON_AddStringToObject(outbound_cfg, "format", "opus");//ogg_opus opus + + // if(codec_tts==1) + cJSON_AddStringToObject(outbound_cfg, "codec", "raw");// ogg + // else + // cJSON_AddStringToObject(outbound_cfg, "codec", "ogg");// ogg cJSON_AddNumberToObject(outbound_cfg, "compression_rate", 20); } else @@ -974,7 +1359,7 @@ static void AI_VC_send_satrt(char is_greeting) cJSON_AddNumberToObject(outbound_cfg, "channel", 1); cJSON_AddNumberToObject(outbound_cfg, "volume", 100); cJSON_AddNumberToObject(outbound_cfg, "speech_rate", vc_cfg.speech_rate); - cJSON_AddNumberToObject(outbound_cfg, "chunk_interval_ms", 10); + cJSON_AddNumberToObject(outbound_cfg, "chunk_interval_ms", 50); //cJSON_AddStringToObject(outbound_cfg, "voice", "7426720361733013513"); //cJSON_AddStringToObject(outbound_cfg, "voice", "ICL_zh_female_huoponvhai_tob"); @@ -1110,9 +1495,7 @@ static void AI_VC_send_audio_create(void) // } // } - -//Music.Start 开始发送音频 -static void AI_VC_send_music_start(char *urlpath) +static void AI_VC_send_startup(void) { VC_state = VC_State_SpeechStart;//开始说 // 创建根对象 @@ -1123,7 +1506,7 @@ static void AI_VC_send_music_start(char *urlpath) } // 设置 "event" 字段 - cJSON_AddStringToObject(root, "event", "audio.convert"); + cJSON_AddStringToObject(root, "event", "prompt"); // 创建 "payload" 对象 cJSON *payload = cJSON_CreateObject(); @@ -1133,32 +1516,46 @@ static void AI_VC_send_music_start(char *urlpath) return ; } - cJSON *audio_convert_request = cJSON_CreateObject(); + + + cJSON *promat = cJSON_CreateObject(); if (payload == NULL) { bk_printf("Failed to create payload object.\n"); cJSON_Delete(root); return ; } - cJSON_AddStringToObject(audio_convert_request, "audio_url", urlpath); - cJSON_AddNumberToObject(audio_convert_request, "bit_depth", 16); - cJSON_AddNumberToObject(audio_convert_request, "channels", 1); - cJSON_AddNumberToObject(audio_convert_request, "sample_rate", 16000); - if(outbound_attributes_format == attributes_format_OPUS) - { - cJSON_AddStringToObject(audio_convert_request, "target_format", "opus"); - }else{ + cJSON *interrupt_keywords = cJSON_CreateArray(); + // cJSON_AddStringToObject(promat, "event", "startup"); - cJSON_AddStringToObject(audio_convert_request, "target_format", "pcm"); - } + //cJSON_AddItemToArray(interrupt_keywords, cJSON_CreateString("停止")); + //cJSON_AddItemToArray(interrupt_keywords, cJSON_CreateString("打断")); + // cJSON_AddItemToArray(interrupt_keywords, cJSON_CreateString("等一下")); + cJSON *content = cJSON_CreateObject(); - cJSON_AddItemToObject(payload, "audio_convert_request", audio_convert_request); + + cJSON_AddStringToObject(content, "role", "user"); + + cJSON_AddStringToObject(content, "content", "{\"event\":\"startup\"}"); + + cJSON_AddStringToObject(content, "content_type", "text"); + + cJSON_AddItemToArray(interrupt_keywords, content); + + + cJSON_AddItemToObject(payload, "prompt", interrupt_keywords); + + //cJSON_AddItemToObject(inbound_attributes, "interrupt_options", interrupt_options); + + + + + // cJSON_AddItemToObject(payload, "prompt", promat); // 将 "payload" 对象添加到根对象中 cJSON_AddItemToObject(root, "payload", payload); - // 将 JSON 对象转换为字符串 char *json_str = cJSON_Print(root); if (json_str == NULL) { @@ -1168,14 +1565,76 @@ static void AI_VC_send_music_start(char *urlpath) } AI_VC_send_data(json_str,strlen(json_str),AIC_WEBSOCKET_OPCODE_TEXT_FRAME);//发送数据 - // 释放内存 free(json_str); cJSON_Delete(root); } -//Audio.Completed 结束发送音频 -static void AI_VC_send_audio_completed(void) +//Music.Start 开始发送音频 +static void AI_VC_send_music_start(char *urlpath) +{ + VC_state = VC_State_SpeechStart;//开始说 + // 创建根对象 + cJSON *root = cJSON_CreateObject(); + if (root == NULL) { + bk_printf("Failed to create root object.\n"); + return ; + } + + // 设置 "event" 字段 + cJSON_AddStringToObject(root, "event", "audio.convert"); + + // 创建 "payload" 对象 + cJSON *payload = cJSON_CreateObject(); + if (payload == NULL) { + bk_printf("Failed to create payload object.\n"); + cJSON_Delete(root); + return ; + } + + cJSON *audio_convert_request = cJSON_CreateObject(); + if (payload == NULL) { + bk_printf("Failed to create payload object.\n"); + cJSON_Delete(root); + return ; + } + + cJSON_AddStringToObject(audio_convert_request, "audio_url", urlpath); + cJSON_AddNumberToObject(audio_convert_request, "bit_depth", 16); + cJSON_AddNumberToObject(audio_convert_request, "channels", 1); + cJSON_AddNumberToObject(audio_convert_request, "sample_rate", 16000); + + if(outbound_attributes_format == attributes_format_OPUS) + { + cJSON_AddStringToObject(audio_convert_request, "target_format", "opus"); + }else{ + + cJSON_AddStringToObject(audio_convert_request, "target_format", "pcm"); + } + + + cJSON_AddItemToObject(payload, "audio_convert_request", audio_convert_request); + + // 将 "payload" 对象添加到根对象中 + cJSON_AddItemToObject(root, "payload", payload); + + // 将 JSON 对象转换为字符串 + char *json_str = cJSON_Print(root); + if (json_str == NULL) { + bk_printf("Failed to print JSON object.\n"); + cJSON_Delete(root); + + } + AI_VC_send_data(json_str,strlen(json_str),AIC_WEBSOCKET_OPCODE_TEXT_FRAME);//发送数据 + + + // 释放内存 + free(json_str); + cJSON_Delete(root); +} + +//Audio.Completed 结束发送音频 +static void AI_VC_send_audio_completed(void) { VC_state = VC_State_SpeechEnd;//说结束 // 创建根对象 @@ -1266,6 +1725,8 @@ static void VC_TTS_Play(const char *str) //pinpin发送 void AI_VC_send_ping_ping(void) { + + // mot_nod_status(); AI_VC_send_data("ping",strlen("ping"),AIC_WEBSOCKET_OPCODE_TEXT_FRAME);//发送数据 } @@ -1334,7 +1795,7 @@ static void AI_VC_send_task(void *thread_input)//websocket 发送线程 // bk_printf("send_count_pcm: %d len: %d !",send_count_pcm,send_update); - // audio_data(AI_VC_send_queue_data.data,AI_VC_send_queue_data.len,25); + audio_data(AI_VC_send_queue_data.data,AI_VC_send_queue_data.len,25); } if(AI_VC_send_queue_data.data) @@ -1387,12 +1848,536 @@ long getFileSize(char* filename) { + void send_express_str_chumo(int type,int mode){ + + + if(!ui_uart_handle) + return ; + + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x08,0x01,0x0a}; + if(type==1&&mode==0){ + + #if SUPPORT_MOT + mot_nod_exp(11,2); + #endif + + // sleep + cmd_ui[4]=0x07; + cmd_ui[6]=0x09; + + } + + if(type==1&&mode==1){ + + #if SUPPORT_MOT + mot_nod_exp(12,2); + #endif + + cmd_ui[4]=0x06; + cmd_ui[6]=0x08; + + } + + if(type==2&&mode==0){ + + #if SUPPORT_MOT + mot_nod_exp(13,2); + #endif + + cmd_ui[4]=0x01; + cmd_ui[6]=0x03; + + } + + if(type==2&&mode==1){ + + #if SUPPORT_MOT + mot_nod_exp(14,2); + #endif + + cmd_ui[4]=0x01; + cmd_ui[6]=0x03; + + } + + if(type==0&&mode==0){ + + #if SUPPORT_MOT + mot_nod_exp(9,2); + #endif + + cmd_ui[4]=0x06; + cmd_ui[6]=0x08; + + } + + if(type==0&&mode==1){ + + #if SUPPORT_MOT + mot_nod_exp(10,2); + #endif + + cmd_ui[4]=0x03; + cmd_ui[6]=0x05; + + } + + + + uart_write(ui_uart_handle,cmd_ui, 7); + } + +void back_middle_statu_mot(){ + + aos_sleep(1000); + mot_nod_exp(7,2); + +} + + +void send_express_str_xinxinmao(char *exp_str){ + + #if 1 + if(ui_uart_handle){ + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x08,0x01,0x0a}; + + if(strstr(exp_str,"不理解")) + { + cmd_ui[4]=0x01; + cmd_ui[6]=0x03; + }else + if(strstr(exp_str,"发怒")) + { + cmd_ui[4]=0x02; + cmd_ui[6]=0x04; + }else + if(strstr(exp_str,"搞怪")) + { + cmd_ui[4]=0x03; + cmd_ui[6]=0x05; + }else + if(strstr(exp_str,"花痴")) + { + cmd_ui[4]=0x04; + cmd_ui[6]=0x05; + }else + if(strstr(exp_str,"惊喜")) + { + cmd_ui[4]=0x05; + cmd_ui[6]=0x07; + }else + if(strstr(exp_str,"惊讶")) + { + cmd_ui[4]=0x06; + cmd_ui[6]=0x08; + }else + if(strstr(exp_str,"卡通")) + { + cmd_ui[4]=0x07; + cmd_ui[6]=0x09; + }else + if(strstr(exp_str,"开心")||strstr(exp_str,"微笑")) + { + cmd_ui[4]=0x08; + cmd_ui[6]=0x0a; + }else + if(strstr(exp_str,"生气")) + { + cmd_ui[4]=0x09; + cmd_ui[6]=0x0b; + }else + if(strstr(exp_str,"眨眼")) + { + cmd_ui[4]=0x0a; + cmd_ui[6]=0x0c; + }else + if(strstr(exp_str,"很开心")) + { + cmd_ui[4]=0x0b; + cmd_ui[6]=0x0d; + }else + if(strstr(exp_str,"中立")) + { + cmd_ui[4]=0x0c; + cmd_ui[6]=0x0e; + } + + uart_write(ui_uart_handle,cmd_ui, 7); + } + + #else + + // 淡定:Calm + // 尴尬:Embarrass + // 开心:Happy + // 可爱:Cute + + + + // 孝豚 + if(ui_uart_handle){ + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x08,0x01,0x0a}; + + // if(strstr(exp_str,"Calm")) + // { + // cmd_ui[4]=0x01; + // cmd_ui[6]=0x03; + // }else + // if(strstr(exp_str,"Embarrass")) + // { + // cmd_ui[4]=0x02; + // cmd_ui[6]=0x04; + // }else + // if(strstr(exp_str,"Happy")) + // { + // cmd_ui[4]=0x03; + // cmd_ui[6]=0x05; + // }else + // if(strstr(exp_str,"Cute")) + // { + // cmd_ui[4]=0x04; + // cmd_ui[6]=0x06; + // } + + // 01-Afraid 害怕-右 +// 02-Amused 有趣-右 +// 03-Angry 愤怒-右 +// 04-Bored 无聊-右 +// 05-Caring 关爱-右 +// 06-Confused 困惑-右 +// 07-Curious 惊喜-右 +// 08-Disgusted 厌恶-右 +// 09-dizzy 蚊香眼-右 +// 10-Doubtful 存疑-右 +// 11-Frowning 皱眉头-右 +// 12-Grimacing 苦着脸-右 +// 13-Happy 开心-右 +// 14-Neutral 中立-右 +// 15-Pensive 悲伤-右 +// 16-Relaxed 放松-右 +// 17-Sad 伤心-右 +// 18-Smiling 微笑-右 +// 19-Surprised 惊讶-右 +// 20-Tired 疲惫-右 +// 21-Winking 眨眼-右 + +// 01-Afraid 害怕-右 01 +// 02-Amused 有趣-右 02 +// 03-Angry 愤怒-右 15 +// 04-Bored 无聊-右 16 +// 05-Caring 关爱-右 05 +// 06-Confused 困惑-右 17 +// 07-Curious 惊喜-右 19 +// 08-Disgusted 厌恶-右 20 +// 09-dizzy 蚊香眼-右 21 +// 10-Doubtful 存疑-右 18 +// 11-Frowning 皱眉头-右 03 +// 12-Grimacing 苦着脸-右 04 +// 13-Happy 开心-右 12 +// 14-Neutral 中立-右 06 +// 15-Pensive 悲伤-右 07 +// 16-Relaxed 放松-右 08 +// 17-Sad 伤心-右 09 +// 18-Smiling 微笑-右 10 +// 19-Surprised 惊讶-右 11 +// 20-Tired 疲惫-右 13 +// 21-Winking 眨眼-右 14 + + bk_printf("send_express_str:text:%s",exp_str); + + if(strstr(exp_str,"Afraid")||strstr(exp_str,"害怕")) + { + cmd_ui[4]=0x01; + cmd_ui[6]=0x03; + }else + if(strstr(exp_str,"Amused")||strstr(exp_str,"有趣")) + { + cmd_ui[4]=0x02; + cmd_ui[6]=0x04; + }else + if(strstr(exp_str,"Angry")||strstr(exp_str,"愤怒")) + { + cmd_ui[4]=0x0f; + cmd_ui[6]=0x11; + }else + if(strstr(exp_str,"Bored")||strstr(exp_str,"无聊")) + { + cmd_ui[4]=0x10; + cmd_ui[6]=0x12; + }else + if(strstr(exp_str,"Caring")||strstr(exp_str,"关爱")) + { + cmd_ui[4]=0x05; + cmd_ui[6]=0x07; + }else + if(strstr(exp_str,"Confused")||strstr(exp_str,"困惑")) + { + cmd_ui[4]=0x11; + cmd_ui[6]=0x13; + }else + if(strstr(exp_str,"Curious")||strstr(exp_str,"惊喜")) + { + cmd_ui[4]=0x13; + cmd_ui[6]=0x15; + }else + if(strstr(exp_str,"Disgusted")||strstr(exp_str,"厌恶")) + { + cmd_ui[4]=0x14; + cmd_ui[6]=0x16; + }else + if(strstr(exp_str,"dizzy")||strstr(exp_str,"蚊香眼")) + { + cmd_ui[4]=0x15; + cmd_ui[6]=0x17; + }else + if(strstr(exp_str,"Doubtful")||strstr(exp_str,"存疑")) + { + cmd_ui[4]=0x12; + cmd_ui[6]=0x14; + }else + if(strstr(exp_str,"Frowning")||strstr(exp_str,"皱眉头")) + { + cmd_ui[4]=0x03; + cmd_ui[6]=0x05; + }else + if(strstr(exp_str,"Grimacing")||strstr(exp_str,"苦着脸")) + { + cmd_ui[4]=0x04; + cmd_ui[6]=0x06; + }else + if(strstr(exp_str,"Happy")||strstr(exp_str,"开心")) + { + cmd_ui[4]=0x0c; + cmd_ui[6]=0x0e; + }else + if(strstr(exp_str,"Neutral")||strstr(exp_str,"中立")) + { + cmd_ui[4]=0x06; + cmd_ui[6]=0x08; + }else + if(strstr(exp_str,"Pensive")||strstr(exp_str,"悲伤")) + { + cmd_ui[4]=0x07; + cmd_ui[6]=0x09; + }else + if(strstr(exp_str,"Relaxed")||strstr(exp_str,"放松")) + { + cmd_ui[4]=0x08; + cmd_ui[6]=0x0a; + }else + if(strstr(exp_str,"Sad")||strstr(exp_str,"伤心")) + { + cmd_ui[4]=0x09; + cmd_ui[6]=0x0b; + }else + if(strstr(exp_str,"Smiling")||strstr(exp_str,"微笑")) + { + cmd_ui[4]=0x0a; + cmd_ui[6]=0x0c; + }else + if(strstr(exp_str,"Surprised")||strstr(exp_str,"惊讶")) + { + cmd_ui[4]=0x0b; + cmd_ui[6]=0x0d; + }else + if(strstr(exp_str,"Tired")||strstr(exp_str,"疲惫")) + { + cmd_ui[4]=0x0d; + cmd_ui[6]=0x0f; + }else + if(strstr(exp_str,"Winking")||strstr(exp_str,"眨眼")) + { + cmd_ui[4]=0x0c; + cmd_ui[6]=0x0e; + } + + uart_write(ui_uart_handle,cmd_ui, 7); + } + + + #endif + + +} + +void send_express_str(char *exp_str){ + + // texts = ["neutral","happy","laughing","funny","sad","angry", + // "crying","loving","embarrassed","surprised","shocked","thinking", + // "winking","cool","relaxed","","confused",""] + + /// happy 🙂 +//cue 😸 +//surprised 😲 +//angry 😠 +//crying 😭 +//smirk😏 +//dissatisfied😒 + +// 001序列帧 开心002序列帧 卖萌003序列帧 惊喜004序列帧 生气004序列帧 右眼生气005序列帧 哭泣006序列帧 坏笑007序列帧 不满 + #if 1 + if(ui_uart_handle){ + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x01,0x01,0x03}; + + if(strstr(exp_str,"开心")||strstr(exp_str,"happy")) + { + + + #if SUPPORT_MOT + mot_nod_exp(8,2); + #endif + + // sleep + cmd_ui[4]=0x01; + cmd_ui[6]=0x03; + + }else + if(strstr(exp_str,"卖萌")||strstr(exp_str,"cue")) + { + + #if SUPPORT_MOT + mot_nod_exp(7,2); + #endif + + cmd_ui[4]=0x02; + cmd_ui[6]=0x04; + }else + if(strstr(exp_str,"惊喜")||strstr(exp_str,"surprised")) + { + cmd_ui[4]=0x03; + cmd_ui[6]=0x05; + + #if SUPPORT_MOT + mot_nod_diantou(2); + #endif + + }else + if(strstr(exp_str,"生气")||strstr(exp_str,"angry")) + { + cmd_ui[4]=0x04; + cmd_ui[6]=0x06; + #if SUPPORT_MOT + mot_nod_exp(6,2); + #endif + + }else + if(strstr(exp_str,"哭泣")||strstr(exp_str,"crying")) + { + cmd_ui[4]=0x05; + cmd_ui[6]=0x07; + + #if SUPPORT_MOT + mot_nod_taitou(2); + #endif + + }else + if(strstr(exp_str,"坏笑")||strstr(exp_str,"smirk")) + { + cmd_ui[4]=0x06; + cmd_ui[6]=0x08; + + #if SUPPORT_MOT + mot_nod_exp(5,2); + #endif + }else + if(strstr(exp_str,"不满")||strstr(exp_str,"dissatisfied")) + { + cmd_ui[4]=0x07; + cmd_ui[6]=0x09; + + #if SUPPORT_MOT + mot_nod_exp(4,2); + #endif + + }else if(strstr(exp_str,"点头")){ + + mot_nod_yaotou(2); + + }else if(strstr(exp_str,"摇头")){ + + mot_nod_diantou(2); + + }else if(strstr(exp_str,"抬头")){ + + + mot_nod_ditou(2); + + }else if(strstr(exp_str,"低头")){ + + mot_nod_taitou(2); + + }else if(strstr(exp_str,"向左转")){ + + mot_nod_exp(15,2); + + + }else if(strstr(exp_str,"向右转")){ + + mot_nod_exp(16,2); + + + } + + + uart_write(ui_uart_handle,cmd_ui, 7); + } + #else + + if(ui_uart_handle){ + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x08,0x01,0x0a}; + + if(strstr(exp_str,"伤心")||strstr(exp_str,"sad")) + { + cmd_ui[4]=0x01; + cmd_ui[6]=0x03; + }else + if(strstr(exp_str,"生气")||strstr(exp_str,"angry")) + { + cmd_ui[4]=0x03; + cmd_ui[6]=0x05; + }else + if(strstr(exp_str,"困惑")||strstr(exp_str,"confused")||strstr(exp_str,"embarrassed")) + {//embarrassed + cmd_ui[4]=0x06; + cmd_ui[6]=0x08; + }else + if(strstr(exp_str,"失望")||strstr(exp_str,"crying")) + { + cmd_ui[4]=0x08; + cmd_ui[6]=0x0a; + }else + if(strstr(exp_str,"开心")||strstr(exp_str,"happy")||strstr(exp_str,"loving") + ||strstr(exp_str,"funny")||strstr(exp_str,"laughing")||strstr(exp_str,"cool")) //laughing "funny loving + { //cool + cmd_ui[4]=0x0d; + cmd_ui[6]=0x0f; + }else + if(strstr(exp_str,"默认")||strstr(exp_str,"neutral")||strstr(exp_str,"thinking") + ||strstr(exp_str,"winking")||strstr(exp_str,"relaxed")) + {//thinking winking relaxed + cmd_ui[4]=0x0e; + cmd_ui[6]=0x10; + }else + if(strstr(exp_str,"惊恐")||strstr(exp_str,"surprised")||strstr(exp_str,"shocked")) + {//shocked + cmd_ui[4]=0x13; + cmd_ui[6]=0x15; + } + + uart_write(ui_uart_handle,cmd_ui, 7); + } + + #endif + +} + static void AI_VC_read_task(void *thread_input)//websocket 读线程 { int status; static u8 *recv_buff = NULL; + AI_VC_stata=1; if(recv_buff == NULL) { @@ -1422,11 +2407,11 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 u32 timer_ms11 = aos_get_tickcount(); - bk_printf("AI_VC_read_task 12"); + //bk_printf("AI_VC_read_task 12"); status = receive_websocket_message(AI_client_VC,recv_buff,recv_buff_mxa_len,&code); - bk_printf("AI_VC_read_task 13"); + //bk_printf("AI_VC_read_task 13"); u32 timer_ms22 = aos_get_tickcount(); @@ -1440,13 +2425,32 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 if(status>0) { - close_timerout = 60; + + + close_timerout = 300; + + if(is_dialog_status==0){ + + sleep_chumo_timerout=180; + + } + if(code == WS_TEXT)//字符串 { //bk_printf("AI_VC_read_task 3"); bk_printf("read TEXT:status:%d,data:%s",status,recv_buff); if(strstr(recv_buff,"\"started\""))//开始 { + + if(issend_start_up==0){ + + issend_start_up=1; + + AI_VC_send_startup(); + + + } + if(AI_TTS_str) { @@ -1464,10 +2468,21 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 VC_state = VC_State_Listening; else if(vc_cfg.VC_mode == 2 )//连续对话模式,按键打断 VC_state = VC_State_Listening; - + + // back_middle_statu_mot(); + + // AI_AMP_MSG_put(0,0,AI_MOT_BACK_MID); } + }else if(strstr(recv_buff,"\"asr.started\""))//asr开始 { + + // if(AI_ASR_str_tmp) + // { + // memset(AI_ASR_str_tmp,0,AI_ASR_STR_MAX_LEN); + // } + + has_tmp_result=0; if(vc_cfg.VC_mode == 1 || vc_cfg.is_VAD ==1)//长按模式,或开机本地vad模式 VC_state = VC_State_SpeechIng; }else if(strstr(recv_buff,"\"asr.result\"")) @@ -1478,6 +2493,9 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 if(str_tmp) { //bk_printf("content!!"); + + has_tmp_result=1; + str_tmp += strlen("\"content\":\""); int str_tmp_len = str_count(str_tmp,'\"'); //存asr结果 @@ -1494,6 +2512,8 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 }else if(strstr(recv_buff,"\"asr.completed\""))//asr结束 { VC_state = VC_State_ASR_End; + + bk_printf("AI_ASR_str%s AI_ASR_str_tmp %s",AI_ASR_str,AI_ASR_str_tmp); if(AI_ASR_str && AI_ASR_str_tmp) { int ret = check_text(AI_ASR_str_tmp,strlen(AI_ASR_str_tmp)) ; @@ -1504,10 +2524,19 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 break; } - if(VAD_time_count <= VAD_TIMEOUT )//时间间隔短,认为是一次对话,拼接内容 + if(VAD_time_count <= VAD_TIMEOUT)//时间间隔短,认为是一次对话,拼接内容 { - + if(strlen(AI_ASR_str_tmp)==0){ + + + // VC_state=VC_State_Listening; + + bk_printf("没有识别结果"); + + AI_AMP_MSG_put("没听清,请再说一遍",strlen("没听清,请再说一遍"),VC_CONNECT_ERROR); + + } if(strlen(AI_ASR_str) +strlen(AI_ASR_str_tmp)> AI_ASR_STR_MAX_LEN-1)//超出缓存长度,清零 { @@ -1522,13 +2551,50 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 }else//超时,不用拼接 { - strncpy(AI_ASR_str,AI_ASR_str_tmp,AI_ASR_STR_MAX_LEN); + strncpy(AI_ASR_str,AI_ASR_str_tmp,AI_ASR_STR_MAX_LEN); + + if(strlen(AI_ASR_str_tmp)==0){ + + // VC_state=VC_State_Listening; + + bk_printf("没有识别结果"); + + AI_AMP_MSG_put("没听清,请再说一遍",strlen("没听清,请再说一遍"),VC_CONNECT_ERROR); + + } + bk_printf("vad间隔时间长,判断为两次对话:%s",AI_ASR_str); } #if BK_SOCKET_IOT IOT_update_statu(1,"thinking",""); #endif + + } + + + bk_printf("002AI_ASR_str%s AI_ASR_str_tmp %s",AI_ASR_str,AI_ASR_str_tmp); + bk_printf("play_file_stream_data:%d",VC_Play_flag); + + if(has_tmp_result==0) + AI_AMP_MSG_put("没听清,请再说一遍",strlen("没听清,请再说一遍"),VC_CONNECT_ERROR); + else + if(VC_Play_flag==1&&strlen(AI_ASR_str_tmp)!=0)//VC_Play_flag==1&& + play_file_stream_data("C:/vadend.pcm"); + //else{ + + + // if(strlen(AI_ASR_str_tmp)==0){ + + // // VC_state=VC_State_Listening; + + // bk_printf("没有识别结果"); + + // AI_AMP_MSG_put("没听清,请再说一遍",strlen("没听清,请再说一遍"),VC_CONNECT_ERROR); + + // } + // play_audio_file("C:/vadend.mp3"); + // } } else if(strstr(recv_buff,"\"vad.active\""))//vad触发 { @@ -1605,14 +2671,12 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 // startsave_tts=one_receive_bin; - - - - + VC_state = VC_State_End; + // if(fp_tts_save) - // fclose(fp_tts_save); + // fclose(fp_tts_save); - // fp_tts_save=NULL; + // fp_tts_save=NULL; // aos_sleep(500); @@ -1642,7 +2706,7 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 { // str_tmp+=strlen("\"message\":\""); // int count = strlen(str_tmp); - AI_AMP_MSG_put("服务异常了,请重试",strlen("服务异常了,请重试"),VC_CONNECT_ERROR); + AI_AMP_MSG_put("没听清,请再说一遍",strlen("没听清,请再说一遍"),VC_CONNECT_ERROR); } } @@ -1654,6 +2718,9 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 // str_tmp = strstr(recv_buff,"\"param_json\""); char *str_tmp = strstr(recv_buff,"\"https"); + char *str_tmp_motion = strstr(recv_buff,"\"emotion"); + + if(str_tmp) { @@ -1672,6 +2739,29 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 AI_VC_send_music_start(mp3_path); } + + if(str_tmp_motion){ + + char emotion_str[200]; + memset(emotion_str,0,200); + + char *str_tmp1 = strstr(recv_buff,"\"text"); + //bk_printf("content!!"); + // str_tmp += strlen("\"params_json")+6; + int str_tmp_len = str_count(str_tmp1+15,'\"'); + //存asr结果 + + if(str_tmp_len>3){ + memcpy(emotion_str,str_tmp1+15,str_tmp_len-3); + //AI_ASR_str_tmp[str_tmp_len] = 0; + + bk_printf("the emotion text len is %s %d",emotion_str,str_tmp_len); + + send_express_str(emotion_str); + + } + + } } @@ -1694,7 +2784,7 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 // if((one_receive_bin/32)<(timer_ms22-timer_ms21)) - // bk_printf("read BIN status:%d,code:%d!!!!!!",status,code); + // bk_printf("read BIN status:%d,code:%d!!!!!!",status,code); // VC_pingping_timerout = 20; @@ -1716,14 +2806,16 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 one_receive_bin+=status; - bk_printf("ogg_opus_decode_data %d...",one_receive_bin); + // bk_printf("ogg_opus_decode_data %d...",one_receive_bin); // memcpy(save_temp_tts); // audio_data(recv_buff,status,26); - ogg_opus_decode_data(recv_buff,status); + //ogg_opus_decode_data(recv_buff,status); + + my_opus_decode_data(recv_buff,status); // if(fp_tts_save){ // bk_printf("save tts!!!"); @@ -1750,7 +2842,7 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 if(AI_client_VC != NULL) { bk_printf("AI_VC_read_task:vc连接断开了"); - AI_AMP_MSG_put("vc连接断开了",strlen("vc连接断开了"),VC_CONNECT_ERROR); + AI_AMP_MSG_put("没听清,请再说一遍",strlen("没听清,请再说一遍"),VC_CONNECT_ERROR); }else{ bk_printf("AI_VC_read_task:客户端主动断开连接了"); } @@ -1773,6 +2865,8 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 } bk_printf("AI_VC_read_task exit\n"); AI_VC_read_task_flag=3; + + AI_VC_stata=0; } @@ -1811,7 +2905,7 @@ static void AI_VC_record_task(void *thread_input)//录音线程 ret = app_audio_read(APP_AUDIO_TYPE_STREAM_DUPLEX, vrecord_buf, 3200, 1010); - // audio_data(vrecord_buf,ret,23); + audio_data(vrecord_buf,ret,23); // u32 timer_ms = aos_get_tickcount(); // bk_printf("%d:ret=%d",timer_ms,ret); @@ -1823,28 +2917,71 @@ static void AI_VC_record_task(void *thread_input)//录音线程 aos_sleep(1); continue; } - - if((vc_cfg.VC_mode == 0 || vc_cfg.VC_mode == 2)&& vc_cfg.is_VAD == 1)//VAD逻辑:先判断有没有有效数据,触发了有效数据才发送 - { - if(vc_cfg.VC_mode == 2 && VC_state > VC_State_SpeechEnd )//按钮打断模式,tts播放时禁止打断,不输入语音 - continue; - // 每次获得语音后调用, 语音长度最好小于100ms - // wave为u8*或void*指针时需要 / 2 - //int vad_test_time = aos_get_tickcount(); - //bk_printf("run_vad vad_test_time:%d,data_len:%d",vad_test_time,ret); - run_vad((int16_t *)vrecord_buf, ret / 2); - //bk_printf("run_vad 用时:%d",aos_get_tickcount()-vad_test_time); - vad_status_t = vad_detect(); - // bk_printf("VAD:vad_status_t:%d",vad_status_t); - // audio_data(vrecord_buf,ret,23); - if (vad_status_t == 2) {//说话停止 - vad_clear(); - if(VAD_status == 1)//清空buff + if(is_dialog_status==1){ + + if(vc_cfg.is_KWS) { - //VAD_timeout = aos_get_tickcount()-VAD_time; - VAD_time = aos_get_tickcount(); - bk_rb_clear(VAD_rb_data); + int KWS_time = aos_get_tickcount(); + // bk_printf("run_kws1: KWS_time:%d,data_len:%d",KWS_time,ret); + run_kws((int16_t *)vrecord_buf,ret/2); + int kws_status = kws_detect(); + // bk_printf("run_kws2:end_time:%d ,kws_status:%d",aos_get_tickcount() - KWS_time,kws_status); + if (kws_status == 1) { + + is_dialog_status=0; + bk_printf("!!!!!!!!!!!!!!!!!!!!!!离线语音识别打断了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n"); + kws_clear(); + + AI_AMP_MSG_put("我来了。",strlen("我来了。"),VC_TTS_PLAY); + } + } + continue; + + } + + + + if((vc_cfg.VC_mode == 0 || vc_cfg.VC_mode == 2)&& vc_cfg.is_VAD == 1)//VAD逻辑:先判断有没有有效数据,触发了有效数据才发送 + { + if(vc_cfg.VC_mode == 2 && VC_state > VC_State_SpeechEnd )//按钮打断模式,tts播放时禁止打断,不输入语音 + { + + if(vc_cfg.is_KWS) + { + int KWS_time = aos_get_tickcount(); + // bk_printf("run_kws1: KWS_time:%d,data_len:%d",KWS_time,ret); + run_kws((int16_t *)vrecord_buf,ret/2); + int kws_status = kws_detect(); + // bk_printf("run_kws2:end_time:%d ,kws_status:%d",aos_get_tickcount() - KWS_time,kws_status); + if (kws_status == 1) { + + is_dialog_status=0; + bk_printf("!!!!!!!!!!!!!!!!!!!!!!离线语音识别打断了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n"); + kws_clear(); + + AI_AMP_MSG_put("我在呢。",strlen("我在呢。"),VC_TTS_PLAY); + } + } + continue; + } + // 每次获得语音后调用, 语音长度最好小于100ms + // wave为u8*或void*指针时需要 / 2 + //int vad_test_time = aos_get_tickcount(); + //bk_printf("run_vad vad_test_time:%d,data_len:%d",vad_test_time,ret); + run_vad((int16_t *)vrecord_buf, ret / 2); + //bk_printf("run_vad 用时:%d",aos_get_tickcount()-vad_test_time); + vad_status_t = vad_detect(); + // bk_printf("VAD:vad_status_t:%d",vad_status_t); + // audio_data(vrecord_buf,ret,23); + + if (vad_status_t == 2) {//说话停止 + vad_clear(); + if(VAD_status == 1)//清空buff + { + //VAD_timeout = aos_get_tickcount()-VAD_time; + VAD_time = aos_get_tickcount(); + bk_rb_clear(VAD_rb_data); if(inbound_attributes_format == attributes_format_OPUS)//填充更多数据,以免后面丢失 { if(sizeof(vrecord_buf)>ret) @@ -1853,7 +2990,9 @@ static void AI_VC_record_task(void *thread_input)//录音线程 } ret = sizeof(vrecord_buf); } - AI_VC_put_record_data(vrecord_buf,ret); + + + AI_VC_put_record_data(vrecord_buf,ret); } VAD_status = 2; // audio_data(vrecord_buf,ret,21); @@ -1877,21 +3016,25 @@ static void AI_VC_record_task(void *thread_input)//录音线程 { unsigned int r_len = bk_rb_read(VAD_rb_data,vad_r_tmp,2560); - // audio_data(vad_r_tmp,r_len,21); + audio_data(vad_r_tmp,r_len,21); //AI_VC_send_data(vad_r_tmp,r_len,AIC_WEBSOCKET_OPCODE_BINARY_FRAME);//发送缓冲数据 - AI_VC_put_record_data(vad_r_tmp,r_len);//入队缓冲数据 - if(vc_cfg.is_KWS) - { - int KWS_time = aos_get_tickcount(); - bk_printf("run_kws1: KWS_time:%d,data_len:%d",KWS_time,r_len); - run_kws((int16_t *)vad_r_tmp,r_len/2); - int kws_status = kws_detect(); - bk_printf("run_kws2:end_time:%d ,kws_status:%d",aos_get_tickcount() - KWS_time,kws_status); - if (kws_status == 1) { - bk_printf("!!!!!!!!!!!!!!!!!!!!!!离线语音识别打断了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n"); - kws_clear(); - } - } + + AI_VC_put_record_data(vad_r_tmp,r_len);//入队缓冲数据 + + // if(vc_cfg.is_KWS) + // { + // int KWS_time = aos_get_tickcount(); + // bk_printf("run_kws1: KWS_time:%d,data_len:%d",KWS_time,r_len); + // run_kws((int16_t *)vad_r_tmp,r_len/2); + // int kws_status = kws_detect(); + // bk_printf("run_kws2:end_time:%d ,kws_status:%d",aos_get_tickcount() - KWS_time,kws_status); + // if (kws_status == 1) { + + + // bk_printf("!!!!!!!!!!!!!!!!!!!!!!离线语音识别打断了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n"); + // kws_clear(); + // } + // } }else @@ -1904,21 +3047,24 @@ static void AI_VC_record_task(void *thread_input)//录音线程 VAD_status = 1; } + + AI_VC_put_record_data(vrecord_buf,ret); - AI_VC_put_record_data(vrecord_buf,ret); - // audio_data(vrecord_buf,ret,21); - if(vc_cfg.is_KWS) - { - int KWS_time = aos_get_tickcount(); - bk_printf("run_kws1: KWS_time:%d,data_len:%d",KWS_time,ret); - run_kws((int16_t *)vrecord_buf,ret/2); - int kws_status = kws_detect(); - bk_printf("run_kws2:end_time:%d ,kws_status:%d",aos_get_tickcount() - KWS_time,kws_status); - if (kws_status == 1) { - bk_printf("!!!!!!!!!!!!!!!!!!!!!!离线语音识别打断了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n"); - kws_clear(); - } - } + audio_data(vrecord_buf,ret,21); + // if(vc_cfg.is_KWS) + // { + // int KWS_time = aos_get_tickcount(); + // bk_printf("run_kws1: KWS_time:%d,data_len:%d",KWS_time,ret); + // run_kws((int16_t *)vrecord_buf,ret/2); + // int kws_status = kws_detect(); + // bk_printf("run_kws2:end_time:%d ,kws_status:%d",aos_get_tickcount() - KWS_time,kws_status); + // if (kws_status == 1) { + + + // bk_printf("!!!!!!!!!!!!!!!!!!!!!!离线语音识别打断了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n"); + // kws_clear(); + // } + // } //bk_printf("VAD:检测到说话了"); }else if(vad_status_t == 0 )//m没有说话 { @@ -1950,12 +3096,36 @@ static void AI_VC_record_task(void *thread_input)//录音线程 if(count_tmp>0)//有有效录音数据 { - if(VC_state >= VC_State_TTSStart)// + if(VC_state >= VC_State_TTSStart) { + char count_tmp12 = count_tmp; + + bk_printf("count_tmp:%d,VC_state:%d",count_tmp,VC_state); + + while(count_tmp12 --) + { + + if(count_tmp12<15) + break; + + if(aos_recv_from_queue(AI_VC_record_tmp_queue,&AI_VC_play_record_data,AOS_NO_WAIT) == AOS_SUCCESS)//有有效录音数据 + { + // audio_data(AI_VC_play_record_data.data,AI_VC_play_record_data.len,22); + + // AI_VC_send_data(AI_VC_play_record_data.data,AI_VC_play_record_data.len,AIC_WEBSOCKET_OPCODE_BINARY_FRAME); + if(AI_VC_play_record_data.data) + aic_free(AI_VC_play_record_data.data); + }else + break; + } + VC_state = VC_State_None; bk_printf("VAD:vad_status_t:%d",vad_status_t); bk_printf("VAD:发送打断对话"); AI_AMP_MSG_put(0,0,VC_Cancel);//发送打断 + + AI_AMP_MSG_put(0,0,AI_MOT_BACK_MID); + } else if(VC_state == VC_State_SpeechIng )//可以发数据了 { @@ -1973,17 +3143,25 @@ static void AI_VC_record_task(void *thread_input)//录音线程 break; } } - else if(VC_state == VC_State_Listening || (VC_state >= VC_State_ASR_End && VC_state < VC_State_TTSStart)) + else if(VC_state == VC_State_Listening) //|| (VC_state >= VC_State_ASR_End && VC_state < VC_State_TTSStart) { AI_VC_send_audio_create();//发送开始音频 + bk_printf("VAD:发送开始音频"); + }else { - if(VC_state > VC_State_SpeechStart) + if(VC_state > VC_State_SpeechStart){ bk_printf("VAD:有数据还没发:VC_state:%d\r\n\r\n",VC_state); - // AI_VC_send_audio_create();//发送开始音频 - // bk_printf("VAD:发送开始音频"); + + AI_AMP_MSG_put("没听清,请再说一遍",strlen("没听清,请再说一遍"),VC_CONNECT_ERROR); + } + // AI_VC_send_audio_create();//发送开始音频 + // bk_printf("VAD:发送开始音频"); + + // char count_tmp = 200; + } vad_end_flag = 1; }else//没录音数据 @@ -2009,7 +3187,7 @@ static void AI_VC_record_task(void *thread_input)//录音线程 } - //AI_VC_put_play_data(vrecord_buf,ret);//音频调试0 + // AI_VC_put_play_data(vrecord_buf,ret);//音频调试0 if(AI_VC_record_tmp_queue == NULL) continue; @@ -2081,6 +3259,9 @@ static void AI_VC_play_task(void *thread_input)//音频播放线程 bk_printf("app_audio_start ret=%d",ret); app_logi("AI_VC_play_task app_audio_start ret=%d",ret); } + + aos_sleep(200); + while(1) { if(AI_VC_play_task_flag >=2) @@ -2103,7 +3284,7 @@ static void AI_VC_play_task(void *thread_input)//音频播放线程 { ret = app_audio_write(APP_AUDIO_TYPE_STREAM_DUPLEX, AI_VC_play_queue_data.data, AI_VC_play_queue_data.len, 2000); - //bk_printf("app_audio_write len=%d\n", ret); + // bk_printf("app_audio_write len=%d\n", ret); if (ret <= 0) { aos_sleep(1); @@ -2118,10 +3299,13 @@ static void AI_VC_play_task(void *thread_input)//音频播放线程 u32 count_tmp = 0; aos_get_queue_used_count(AI_VC_play_queue,&count_tmp); - bk_printf("VC_State_End:count_tmp = %d",count_tmp); + + // bk_printf("VC_State_End:count_tmp = %d",count_tmp); + if(count_tmp <= 0 )//播放完了 { - VC_END_play_timerout = 1; + bk_printf("VC_State_End:count_tmp = %d",count_tmp); + VC_END_play_timerout = 1; } } continue;//正常有数据就不执行下面写0 @@ -2238,11 +3422,449 @@ uint16_t modbus_crc16(const uint8_t *data, uint16_t length) { } +void deal_iot_receive(char *json_data) +{ + + bk_printf(json_data); + + // vc_cfg.VC_TTS_volume = 100; + // AI_AMP_MSG_put("音量已最大。",strlen("音量已最大。"),VC_TTS_PLAY); + + //{"cmd":"emotion","msg":"AI指令:emotion","data":"Cute","ts":1764914695122,"targetDeviceId":"865530078570777"} + + if(strstr(json_data,"action")){ + + bk_printf("action"); + + char *str_tmp = NULL; + + char action_str[500]={0}; + + str_tmp = strstr(json_data,"\"data\":\""); + + // bk_printf("str_tmp:%p",str_tmp); + + if(str_tmp)//解析password + { + + str_tmp += strlen("\"data\":\""); + int count = str_count(str_tmp,'\"'); + bk_printf("count:%d",count); + if(count < sizeof(action_str)) + { + + + memcpy(action_str,str_tmp,count); + action_str[count] = 0; + bk_printf("action_str:%s",action_str); + if(is_guanji==0) + send_express_str(action_str); + } + + } + + } + + if(strstr(json_data,"emotion")){ + + bk_printf("emotion"); + + char *str_tmp = NULL; + + char emotion_str[500]={0}; + + str_tmp = strstr(json_data,"\"data\":\""); + + // bk_printf("str_tmp:%p",str_tmp); + + if(str_tmp)//解析password + { + + str_tmp += strlen("\"data\":\""); + int count = str_count(str_tmp,'\"'); + bk_printf("count:%d",count); + if(count < sizeof(emotion_str)) + { + + + memcpy(emotion_str,str_tmp,count); + emotion_str[count] = 0; + bk_printf("emotion_str:%s",emotion_str); + + if(is_guanji==0) + send_express_str(emotion_str); + } + + } + + } + + if(strstr(json_data,"tts_audio_url")){ + + bk_printf("tts_audio_url"); + + char *str_tmp = NULL; + + char mp3_path_str[500]={0}; + + str_tmp = strstr(json_data,"\"data\":\""); + + // bk_printf("str_tmp:%p",str_tmp); + + if(str_tmp)//解析password + { + + str_tmp += strlen("\"data\":\""); + int count = str_count(str_tmp,'\"'); + bk_printf("count:%d",count); + if(count < sizeof(mp3_path_str)) + { + + + memcpy(mp3_path_str,str_tmp,count); + mp3_path_str[count] = 0; + bk_printf("mp3_path_str:%s",mp3_path_str); + + //is_music_status=1; + + // AI_AMP_MSG_put("请稍后,现在为你查找音乐",strlen("请稍后,现在为你查找音乐"),VC_TTS_PLAY); + + // aos_sleep(4000); + + AI_VC_send_music_start(mp3_path_str); + + } + } + + // IOT_update_statu(3,"",""); + + // AI_AMP_MSG_put("正在查找设备。",strlen("正在查找设备。"),VC_TTS_PLAY); + + } + + if(strstr(json_data,"get_device_state")){ + + bk_printf("get_device_state"); + + // IOT_update_statu(3,"",""); + + // AI_AMP_MSG_put("正在查找设备。",strlen("正在查找设备。"),VC_TTS_PLAY); + + } + + if(strstr(json_data,"find_device")){ + + bk_printf("find_device"); + + AI_AMP_MSG_put("正在查找设备。",strlen("正在查找设备。"),VC_TTS_PLAY); + + } + + if(strstr(json_data,"renew_device")){ + + bk_printf("renew_device"); + + IOT_update_bargein(); + + if(vc_cfg.VC_mode == 0) + { + AI_AMP_MSG_put("已切换到连续对话模式。",strlen("已切换到连续对话模式。"),VC_TTS_PLAY); + + //app_audio_set_master_volume(15*80/100); + + }else if(vc_cfg.VC_mode == 1) + { + AI_AMP_MSG_put("已切换到单对话模式。长按按钮说话,说完松开即可。",strlen("已切换到单对话模式。长按按钮说话,说完松开即可。"),VC_TTS_PLAY); + + // app_audio_set_master_volume(15*80/100); + }else + { + + // app_audio_set_master_volume(15*80/100); + AI_AMP_MSG_put("已切换到按键打断模式。我说话的时候需要短按按钮打断。",strlen("已切换到按键打断模式。我说话的时候需要短按按钮打断。"),VC_TTS_PLAY); + } + + // IOT_V3_update_statu(3,"",""); + save_VC_cfg(); + + } + + if(strstr(json_data,"switch_volume")) + { + + // bk_printf("switch_volume"); + + char *str_tmp = NULL; + + char volume_str[5]={0}; + + str_tmp = strstr(json_data,"\"target\":\""); + + //bk_printf("str_tmp:%p",str_tmp); + if(str_tmp)//解析password + { + str_tmp += strlen("\"target\":\""); + int count = str_count(str_tmp,'\"'); + bk_printf("count:%d",count); + if(count < sizeof(volume_str)) + { + + + memcpy(volume_str,str_tmp,count); + volume_str[count] = 0; + bk_printf("volume_str:%s",volume_str); + + int temp_vol=atoi(volume_str); + + if(temp_vol>=0&&temp_vol<=100) + { + + vc_cfg.VC_TTS_volume = temp_vol; + + app_audio_set_master_volume(15*vc_cfg.VC_TTS_volume/100); + + char tts_temp[200]={0}; + + + sprintf(tts_temp,"设置音量%d成功。",vc_cfg.VC_TTS_volume); + + AI_AMP_MSG_put(tts_temp,strlen(tts_temp),VC_TTS_PLAY); + + + //is_save_VC_cfg = 1; + + save_VC_cfg(); + } + + + + } + else + { + bk_printf("获取volume失败"); + } + } + } + + +} + + +static void AI_IOT_read_task(void *thread_input)//websocket 读线程 + { + + int status; + static u8 *recv_buff = NULL; + + + if(recv_buff == NULL) + { + recv_buff = aic_malloc(recv_buff_mxa_len); + } + if(recv_buff == NULL) + { + bk_printf("AI_VC_read_task aic_malloc ERROR!!!!!!!!!!!!!!!!!!......"); + return; + } + WebSocketMessageType code; + bk_printf("AI_IOT_read_task go......"); + // AI_VC_read_task_flag = 1; + while (1) { + + if(AI_client_IOT) + { + + memset(recv_buff,0,recv_buff_mxa_len); + // status = aic_websocket_recv(AI_VC_client_websocket_handle, recv_buff, sizeof(recv_buff), + // &code, AOS_WAIT_FOREVER,&result_val); + // bk_printf("AI_VC_read_task 1"); + + // aos_sleep(50); + + // u32 timer_ms11 = aos_get_tickcount(); + + // bk_printf("IOT_read_task...... 12"); + + status = receive_websocket_message_V3(AI_client_IOT,recv_buff,recv_buff_mxa_len,&code); + + if(AI_VC_stata==0) + { + aos_sleep(100); + continue; + + } + + + + // bk_printf("get iot message................................."); + // bk_printf("bytes_received %02X %02X %02X %02X %02X %02X %02X %02X %02X ...\n",recv_buff[0],recv_buff[1],recv_buff[2],recv_buff[3],recv_buff[4],recv_buff[5],recv_buff[6],recv_buff[7],recv_buff[8]); + + + // bk_printf("IOT_read_task...... 13"); + + if(code == WS_TEXT)//字符串 + { + //bk_printf("AI_VC_read_task 3"); + // bk_printf("read TEXT:status:%d,data:%s",status,recv_buff); + + }else{ + + + if(status>8){ + + // bk_printf("read TEXT:status:%d",status); + + char jsonstr[500]={0}; + + memcpy(jsonstr,recv_buff+8,status-8); + + // bk_printf("read json TEXT:status:%s",jsonstr); + + deal_iot_receive(jsonstr); + + } + + } + + if(status>0) + { + + + }else{ + + break; + } + + aos_sleep(100); + }else{ + + break; + } + + } + + if(recv_buff) + { + aic_free(recv_buff); + recv_buff = NULL; + } + + AI_client_IOT=NULL; + + AI_VC_read_IOT_id=0; + bk_printf("AI_IOT_read_task exit\n"); + // AI_VC_read_task_flag=3; + + } + +void IOT_V3_heart() +{ + + // 创建根对象 + cJSON *root = cJSON_CreateObject(); + if (root == NULL) { + bk_printf("Failed to create root object.\n"); + return ; + } + + cJSON *cmd_data = cJSON_CreateObject(); + + if (cmd_data == NULL) { + bk_printf("Failed to create payload object.\n"); + cJSON_Delete(root); + return ; + } + // 设置 "event" + + + + + // if(type==4){ + + struct psy_info psy_info; + get_psy_info(&psy_info); + + long timestamp; + + timestamp = time(NULL); + bk_printf("2时间戳: %ld\n", (long)timestamp); + + cJSON_AddStringToObject(root, "cmd", "post_heart_beat"); + + cJSON_AddNumberToObject(root, "ts", timestamp); + + cJSON_AddStringToObject(root, "msg", "心跳"); + + cJSON_AddNumberToObject(cmd_data, "battery", psy_info.bat_capacity); + + // cJSON_AddStringToObject(cmd_data, "device_id", vc_cfg.dev_imei); + + // } + + + cJSON_AddItemToObject(root, "data", cmd_data); + + + + // 将 JSON 对象转换为字符串 + + //cJSON_PrintUnformatted + + char *json_str = cJSON_PrintUnformatted(root); //cJSON_Print + if (json_str == NULL) { + bk_printf("Failed to print JSON object.\n"); + cJSON_Delete(root); + + } + + + bk_printf(json_str); + + + // if(type==4){ + + // bk_printf("SEND iot_v3 message"); + + unsigned char frame[500]={0}; + frame[0]=0xFF; + frame[1]=0xFE; + frame[2]=0x01; + frame[3]=0x03; + + // AI_VC_send_data(json_str,strlen(json_str),AIC_WEBSOCKET_OPCODE_TEXT_FRAME);//发送数据 + + short temp=strlen(json_str); + // memcpy(frame+3,&temp,2); + + frame[7]=temp; + + memcpy(frame+8,json_str,strlen(json_str)); + + int ret=send_websocket_message(AI_client_IOT,frame,strlen(json_str)+8,AIC_WEBSOCKET_OPCODE_BINARY_FRAME); + + // int ret=send_iot_message(AI_client_IOT,json_str,strlen(json_str)); + + bk_printf("SEND iot_v3 success message: %d",ret); + + // }else{ + + + + // } + + // 释放内存 + free(json_str); + cJSON_Delete(root); +} + +#define IOT //连接websocket static int websocket_connect_VC(void) { char *url = NULL; + + char url_iot[200]={0}; int ret = 0; //连接服务器 if(AI_client_VC == NULL) @@ -2266,6 +3888,10 @@ static int websocket_connect_VC(void) ret = - 1; goto CONNECT_RET; } + + //provider=coze& + //provider=coze& + if(vc_cfg.dev_type == DEV_JSWM) url_len =snprintf(url,511,"ws://%s/vc/agent?is_auth=1&dt=%s",vc_cfg.server_ip,get_token()); else @@ -2275,6 +3901,7 @@ static int websocket_connect_VC(void) bk_printf("连接服务器 url:%s",url); int ws_res_num = get_websocket_res_num(); bk_printf("WS资源剩余量:%d",ws_res_num); + if(ws_res_num<=0)//资源不够,要释放资源 { free_all_websocket_res(); @@ -2284,7 +3911,61 @@ static int websocket_connect_VC(void) AI_client_VC = init_websocket_client(url,NULL); +#ifdef IOT + if(AI_client_IOT==NULL){ + + bk_printf("create AI_client_IOT...\n"); + + bk_printf(url_iot); + + // AI_client_IOT = init_websocket_IOT(url_socket,NULL);// socket_iot + + // wss://wsiot.raisound.com/iot-api/ws-hub/dev/v1?bz-dt=xxx + + // ws(s)://wsiot-nocdn.raisound.com/ws-hub/dev/v1?bz-dt= +#if 0 + sprintf(url_iot,"ws://wsiot-nocdn.raisound.com/ws-hub/dev/v1?bz-dt=%s",get_token()); +#else + + sprintf(url_iot,"ws://dmp-dev.raisound.com/iot-api/ws-hub/dev/v1?bz-dt=%s",get_token()); +#endif + + AI_client_IOT = init_websocket_IOT_V3(url_iot,NULL);// ws_iot + + bk_printf("create AI_client_IOT SUCCESS...\n"); + + if(AI_client_IOT){ + bk_printf("IOT读线程 AI_VC_read_IOT_id:%d",AI_VC_read_IOT_id); + + //创建读线程 + if(AI_VC_read_IOT_id == 0) + { + AI_VC_read_IOT_id = aos_create_thread( + "AI_VC_read", + AI_IOT_read_task,// AI_VC_IOT_task //AI_IOT_read_task + &AI_VC_read_IOT_id, + 4096u, + 0, + NULL, + ai_VC_task_priority, + AOS_AUTO_START); + bk_printf("IOT读线程 AI_VC_read_IOT_id:%d",AI_VC_read_IOT_id); + } + + aos_sleep(20); + + // IOT_login(1); + + + IOT_V3_heart(); + + + // send_iot_message(AI_client_IOT,iotmessage,strlen(iotmessage)); + + } + } + #endif if(!AI_client_VC) { @@ -2356,12 +4037,18 @@ static void websocket_deconnect_VC(void) // aic_websocket_delete(AI_VC_client_websocket_handle,5000); // AI_VC_client_websocket_handle = 0; // } + + // AI_client_IOT if(AI_client_VC)//先断开再关闭读线程 { delete_websocket_res(AI_client_VC);//删除该对象ws资源管控 close_websocket_client(AI_client_VC); AI_client_VC = NULL; + + // AI_client_IOT } + + //销毁发送线程 if(AI_VC_send_task_id != 0) { @@ -2556,7 +4243,7 @@ void AI_VC_put_play_data(char *data,u32 len) return; aos_get_queue_used_count(AI_VC_play_queue,&count_tmp); - bk_printf("AI_VC_put_play_data:count_tmp = %d",count_tmp); + // bk_printf("AI_VC_put_play_data:count_tmp = %d",count_tmp); if(count_tmp>150)//大于100个缓存 { @@ -2657,7 +4344,7 @@ void VC_Play_End(void) // AI_VC_play_queue = NULL; } - //app_audio_stop(APP_AUDIO_TYPE_STREAM_DUPLEX, NULL); + // app_audio_stop(APP_AUDIO_TYPE_STREAM_DUPLEX, NULL); } static void AI_VC_put_record_data(char *data,u32 len) @@ -2690,9 +4377,14 @@ static void AI_VC_put_record_data(char *data,u32 len) return; PUT_RECORD_ERROR: - if(AI_VC_record_queue_data.data) + if(AI_VC_record_queue_data.data){ + aic_free(AI_VC_record_queue_data.data); + // AI_AMP_MSG_put(0,0,VC_Cancel); + + } + } @@ -2702,6 +4394,8 @@ PUT_RECORD_ERROR: void VC_record_Start(void) { bk_printf("VC_record_Start"); + + // is_dialog_status=0; //创建录音线程 if(AI_VC_record_task_id == 0) { @@ -2754,15 +4448,33 @@ void VC_record_End(void) } static void AI_VC_1S_timeout(void *param) { - //bk_msg_printf("AI_VC_1S_timeout 1!!!!!!!!!"); + // bk_msg_printf("AI_VC_1S_timeout 1!!!!!!!!!"); if(close_timerout>0) { close_timerout--; if(close_timerout<=0) { - AI_AMP_MSG_put(0,0,VC_CLOSE); + AI_AMP_MSG_put(0,0,VC_CLOSE); + AI_AMP_MSG_put(0,0,CLOSE_IOT); } } + + if(sleep_chumo_timerout>0) + { + sleep_chumo_timerout--; + + if(sleep_chumo_timerout<=0&&is_dialog_status==0) + { + is_dialog_status=1; + + // VC_state = VC_State_End; + + AI_client_VC_synthesis("你好,我要去休息了,唤醒请说你好小七"); + } + + } + + if(VC_pingping_timerout>0) { VC_pingping_timerout--; @@ -2796,10 +4508,18 @@ static void AI_VC_1S_timeout(void *param) } } - else - AI_AMP_MSG_put(0,0,VC_CLOSE); + else{ + + VAD_status = 0; + // AI_AMP_MSG_put(0,0,VC_CLOSE); + } + //AI_AMP_MSG_put(0,0,VC_RECORD_START);//开启录音 + + // AI_AMP_MSG_put(0,0,AI_MOT_BACK_MID); bk_msg_printf("VC_END_play_timerout=%d",VC_END_play_timerout); + + AI_AMP_MSG_put(0,0,AI_MOT_BACK_MID); } } // if(AI_VC_play_queue) @@ -2822,23 +4542,49 @@ void AI_key_press(void) bk_printf("AI_key_press1"); - play_file_stream_data("C:/chenggong.pcm"); + IOT_V3_heart(); u64 timer_ms_tmp = aos_get_tickcount(); if(timer_ms_tmp-timer_ms<1000)//每次触发小于1000ms关闭对话 { if(vc_cfg.VC_mode ==0 || vc_cfg.VC_mode == 2)//关闭服务 - AI_VC_Close(); + { + + if(is_dialog_status==0){ + + is_dialog_status=1; + + AI_client_VC_synthesis("你好,我要去休息了,唤醒请说你好小七"); + + } + + } + // AI_VC_Close(); return; } timer_ms = timer_ms_tmp; + + + if(vc_cfg.VC_mode == 0&&AI_VC_stata==1&&is_dialog_status==0){ + + return ; + }else{ + + is_dialog_status=0; + + } + + if(vc_cfg.VC_mode == 1) + AI_key_long_flag = 1; + + play_file_stream_data("C:/chenggong.pcm"); + bk_printf("AI_key_press"); + AI_VC_Close(); - - VC_state = VC_State_None; - + VC_state = VC_State_None; VC_record_Start(); @@ -2855,6 +4601,9 @@ void AI_key_press(void) void AI_key_release(void) { + + AI_key_long_flag = 0; + if(vc_cfg.VC_mode ==1) { AI_AMP_MSG_put("请您按住按钮讲话,讲完松开即可。",strlen("请您按住按钮讲话,讲完松开即可。"),VC_TTS_PLAY); @@ -2925,6 +4674,9 @@ int32_t bk_audio_start_callback(void *p_param, uint32_t size) char AI_VC_start_lock = 0; int net_status_count=0; + +extern int dmp_log_level; + //is_greeting,是否播放开场白 int AI_VC_start(char is_greeting) { @@ -2934,6 +4686,8 @@ int AI_VC_start(char is_greeting) goto AI_VC_start_RET; AI_VC_start_lock = 1; + // + bk_printf("AI_VC_start !!!!!!!! "); //play_file_stop();//先关闭一次本地文件音频播放 VC_state = VC_State_None; @@ -2997,9 +4751,10 @@ int AI_VC_start(char is_greeting) // 启用VAD时初始化 + struct VadConfig conf; conf.sil_threshold = 63; - conf.energy_threshold = 10000; + conf.energy_threshold = 10000;//10000 2000; conf.min_speech_length = 240;//240 conf.silence_detect_length = 300; conf.rule1_min_tailing_silence = 480; @@ -3007,6 +4762,9 @@ int AI_VC_start(char is_greeting) conf.rule3_min_tailing_silence = vc_cfg.vad_silence; conf.vad_log_level = 0; int init_vad_ret = 0; + + conf.auth_info.server_addr=2; + strcpy(conf.auth_info.dmp_token, get_token()); static int imsl_nn_init_flag = -1; if (imsl_nn_init_flag != 0) { @@ -3093,8 +4851,13 @@ void AI_VC_Close(void) // aic_gpio_output(MOT_EN_REV,GPIO_OUTPUT_LVL_LOW); // aic_gpio_output(GPIO_20,GPIO_OUTPUT_LVL_LOW ); #if SUPPORT_MOT - MTO_stop(); + // MTO_stop(); + + // MTO_restert(); + // MTO_restert_tb(); + #endif + bk_printf("AI_VC_Close!!!!!!!!!!!!"); websocket_deconnect_VC();//断开连接 //销毁录音线程 @@ -3267,6 +5030,8 @@ void AI_VC_Close(void) //app_logi("app_audio_stop2"); AI_VC_stata = 0; AI_VC_Close_lock = 0; + + // aic_gpio_output(GPIO_15,GPIO_OUTPUT_LVL_HIGH); } int MSG_Type_error = 0; @@ -3317,12 +5082,23 @@ static void sys_60S_timeout(void *param) { // AI_AMP_MSG_put(NULL,0,AI_TIMER_EVENT); + AI_AMP_MSG_put(NULL,0,AI_TIMER_EVENT_IOT); //IOT_heart(); } +static void sys_60S_timeout_even(void) +{ + + // bk_printf("sys_60S_timeout_even"); + + if(AI_client_IOT!=NULL&&close_timerout>0){ + IOT_V3_heart(); + } + +} static void sys_10S_timeout_even(void) { @@ -3396,9 +5172,237 @@ void play_tts_my_local(char *filename) play_audio_file_event(filename); } -// #define exptest + +//void send_express_str(char *exp_str){ + + // texts = ["neutral","happy","laughing","funny","sad","angry", + // "crying","loving","embarrassed","surprised","shocked","thinking", + // "winking","cool","relaxed","","confused",""] + + /// happy 🙂 +//cue 😸 +//surprised 😲 +//angry 😠 +//crying 😭 +//smirk😏 +//dissatisfied😒 + +int random_mada=0; + +int chumo_tickcount=0; + +u8 count_chumo_index[3][2]={0,0,0,0,0,0}; + +char *str_huashu[3][2][5]={ + {{"摸我的头干嘛,是不是觉得我很可爱呀?不过我可是很酷的哦!", + "喂!摸我脑袋干嘛?小心我咬你哦~", + "“嘿嘿,手感是不是很好?限时体验,不退不换~","",""}, + {"行吧行吧,就再让你摸3秒,多一秒都算我输!", + "唔… 别摸啦,头发都要被你弄乱了!","","",""}}, +{{"干嘛?想搭讪啊?可惜本小七可不是这么容易被收买的~", + "干嘛碰我肚子?痒死啦!","“扫描完成!结果是……你对我百分之百上瘾!","",""}, + {"喂喂喂,摸够了没?再摸我可要吐槽你了——你这手法比我奶揉面还粗糙!", + "嗯… 舒服是舒服啦,但别一直摸嘛!","别以为我好哄~只是你刚好摸到舒服的点而已。", + "嘘——别动,我在检测你的‘快乐值’。",""}}, +{{"偷袭?胆子挺肥啊!信不信我反手给你个‘暴击’(口头版)!", + "再戳我一次,我就反击——用笑声攻击你!","","",""}, + {"别挠了别挠了!再挠我可要破功了…(小声)其实也还行啦","唔… 别摸我后背!我可是要去冒险的,别耽误我!","","",""}} +}; + +void random_chumo(int type,int mode){ + + // mot_nod_status(); + + // play_file_stream_data("C:/chumo.pcm"); + // return ; + + + + int currenttick=aos_get_tickcount(); + + if(currenttick-chumo_tickcount<6000){ + + bk_printf("太频繁.....\n"); + + return ; + } + chumo_tickcount=currenttick; + + // is_dialog_status + + // is_dialog_status=0; + + // ||is_dialog_status==1 + + if((VC_state==VC_State_Listening&&VAD_status==0)||VC_state==VC_State_End||VC_state==VC_State_None){ + + + bk_printf("VC_state11 %d.....\n",VC_state); + // aic_gpio_output(GPIO_15,GPIO_OUTPUT_LVL_HIGH); + + if(type==0&&mode==0) + play_file_stream_data("C:/chumo.pcm"); + + + int index_temp=count_chumo_index[type][mode]; + + if(index_temp<5) + { + AI_AMP_MSG_put(str_huashu[type][mode][index_temp],strlen(str_huashu[type][mode][index_temp]),VC_TTS_PLAY); + + } + + // AI_client_VC_synthesis(str_huashu[type][mode][index_temp]); + + count_chumo_index[type][mode]++; + + if(strlen(str_huashu[type][mode][index_temp+1])<5) + count_chumo_index[type][mode]=0; + + // aic_free(AI_TTS_str); + // AI_TTS_str = NULL; + VC_state = VC_State_TTSStart; + // play_audio_file("C:/chumo.mp3"); + + // return ; + }else{ + + bk_printf("VC_state22 %d.....\n",VC_state); + + return ; + } + + // if(VC_Play_flag!=1){ + + // // aic_gpio_output(GPIO_15,GPIO_OUTPUT_LVL_HIGH); + // play_audio_file("C:/chumo.mp3"); + + // bk_printf("chumo.mp3.....\n"); + + + // }else{ + + // // aic_gpio_output(GPIO_15,GPIO_OUTPUT_LVL_HIGH); + // bk_printf("duihuazhong.....\n"); + + // return ; + + // } + + send_express_str_chumo(type,mode); + + return ; + + // if(chumo_exp_open==1){ + + // random_mada++; + + // if(random_mada==1){ + // send_express_str("happy"); + // } + // if(random_mada==2){ + // send_express_str("cue"); + // } + // if(random_mada==3){ + // send_express_str("surprised"); + // } + // if(random_mada==4){ + // send_express_str("angry"); + // } + // if(random_mada==5){ + // send_express_str("crying"); + // } + // if(random_mada==6){ + // send_express_str("smirk"); + // } + // if(random_mada==7){ + // send_express_str("dissatisfied"); + // } + + // if(random_mada==7) + // random_mada=0; + + // } + + // aic_gpio_output(GPIO_15,GPIO_OUTPUT_LVL_HIGH); + +} + #define exptest + + +void bk_task_suspend(void *p) +{ + // bk_printf("idle cpu sleep"); + + aic_gpio_input(GPIO_AGPIO_1, GPIO_INPUT_NOINT, NULL, NULL); + +} + +void bk_task_resume(void *p) +{ + + // bk_printf("cpu work"); + +} + + +extern imsl_nn_printf_func imsl_nn_printf; int auth_vad_status=0; + +static void uart_recv_UI_handel(void *thread_input) +{ + size_t read; + char buf_ui[20]; + //uart_data_t *data; + + /** + * 1.Com number is aic_uart array index, aic_uart at aicos\projects\xxx\config\serial\serial_config.h; + * 2.use aic_uart[index] parameter to set serial. + */ + // serial_handle = uart_open(LOOPBACK_COM); + // aic_assert(serial_handle); + bk_printf("uart_recv_UI_handel start"); + + if(!ui_uart_handle) + return ; + + bk_printf("uart_recv_UI_handel start01"); + /* change baudrate */ + // uart_set_baud_rate(serial_handle, LOOPBACK_BANDRATE); + + while(1) { + /* read data. */ + // buf = aic_malloc(20); + + read = uart_read(ui_uart_handle, buf_ui, 20); + + bk_printf("uart_recv_UI_handel start02 %d",read); + + bk_printf("uart_recv %02X %02X %02X %02X %02X %02X %02X ...\n",buf_ui[0],buf_ui[1],buf_ui[2],buf_ui[3],buf_ui[4],buf_ui[5],buf_ui[6]); + + if (read == 0 || read > 20) { + // drv_logw("uart_recv: err size = (%d)!\n", read); + // aic_dma_free(buf); + // continue; + } + + // drv_logi("uart_recv: read size = (%d)!\n", read); + + // data = aic_malloc(sizeof(*data)); + // data->addr = buf; + // data->size = read; + // aos_send_to_queue(uart_queue_id, (void*)&data, AOS_WAIT_FOREVER); + } + + + bk_printf("uart_recv_UI_handel close "); + + /* close uart. */ + // uart_close(ui_uart_handle); +} + + static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 { char count = 30; @@ -3406,9 +5410,16 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 AI_AMP_MSG_queue_t AI_AMP_msg = {0}; init_VC_cfg(); - + + + imsl_nn_printf = bk_printf; + app_audio_set_master_volume(15*vc_cfg.VC_TTS_volume/100); + aic_gpio_output(GPIO_15,GPIO_OUTPUT_LVL_HIGH );//lcd open ldo + + // GPIO_AGPIO_1 + play_audio_file_event("C:/R_POWER_1.mp3"); // play_audio_file("C:/R_POWER_1.mp3"); @@ -3426,6 +5437,14 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 bk_printf("FXH01_Version:%s",FXH01_Version); bk_printf("FXH01_Version:%s",FXH01_Version); + //slp_register_sleep_hook(bk_task_suspend, AIC_NULL, + // bk_task_resume, AIC_NULL); + + + // snd_soc_component_write(codec, ES8311_ADC_REG17, es8311->adc_volume); + // snd_soc_component_write(codec, ES8311_DAC_REG32, es8311->dac_volume); + + while(count --) { @@ -3463,6 +5482,8 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 // aos_sleep(5000); + + ota_update_version(); // if(strlen(ota_url)>3){ @@ -3483,13 +5504,24 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 if(sys_10S_timer == NULL) { - sys_10S_timer = aos_create_timer("AI_VC_1S_timer", + sys_10S_timer = aos_create_timer("AI_VC_10S_timer", sys_10S_timeout, &sys_10S_timer, 10000, AOS_AUTO_ACTIVATE, AOS_BE_PERIOD); aic_assert(sys_10S_timer); } + // AI_VC_60S_timer + if(AI_VC_60S_timer == NULL) + { + AI_VC_60S_timer = aos_create_timer("AI_VC_60S_timer", + sys_60S_timeout, &AI_VC_60S_timer, + 50000, + AOS_AUTO_ACTIVATE, AOS_BE_PERIOD); + aic_assert(AI_VC_60S_timer); + } + + // AI_VC_60S_timer // if(AI_VC_60S_timer == NULL) // { @@ -3503,6 +5535,10 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 bk_printf("auth_vad token0: %s..... \n",get_token()); struct AuthInfo auth_info; + // dmp_log_level = 10086; + + auth_info.server_addr=2; + strcpy(auth_info.dmp_token, get_token()); if(strlen(auth_info.dmp_token)>0){ @@ -3526,7 +5562,7 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 } }else{ - play_audio_file_event("C:/xinhaoruo1.mp3"); + play_audio_file_event("C:/xinhaoruo1.mp3"); } if(auth_vad_status==0){ @@ -3538,7 +5574,7 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 #ifdef exptest - aos_sleep(5000); + aos_sleep(500); ui_uart_handle = uart_open(2); @@ -3550,7 +5586,7 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 // uart_write(ui_uart_handle,"123", strlen("123")); - u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x02,0x01,0x04}; + u8 cmd_ui[7]={0xAA,0x55,0xFF,0x02,0x01,0x01,0x03}; uart_write(ui_uart_handle,cmd_ui, 7); @@ -3560,6 +5596,21 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 } + if(UI_UART_read_id == 0) + { + UI_UART_read_id = aos_create_thread( + "UI_UART_read", + uart_recv_UI_handel,// AI_VC_IOT_task,//AI_IOT_read_task + &UI_UART_read_id, + 4096u, + 0, + NULL, + ai_VC_task_priority, + AOS_AUTO_START); + bk_printf("uart 读线程 UI_UART_read_id:%d",UI_UART_read_id); + } + + #endif #if BK_SOCKET_IOT bk_iot_init();//iot初始化 @@ -3581,6 +5632,9 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 VC_TTS_Play(vc_cfg.power_on_tone);//开启vc播放tts } + + + while (1) { if(AI_AMP_task_queue) { @@ -3608,16 +5662,35 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 //发送打断 //AI_VC_send_cancel();//发送打断,发送完打断还有发开始音频 //app_logi("interruption!!!!!!!!!!!!!!!!!!!!!"); + + is_dialog_status=0; + VC_Play_End(); VC_state = VC_State_None; websocket_deconnect_VC(); websocket_connect_VC();//重连 AI_VC_send_satrt(0);//发送开始 + + AI_AMP_MSG_put(0,0,VC_PLAY_START);//打开声音 break; case VC_CLOSE: AI_VC_Close(); + break; + case CLOSE_IOT: + + if(AI_client_IOT)//先断开再关闭读线程 + { + delete_websocket_res(AI_client_IOT);//删除该对象ws资源管控 + close_websocket_client(AI_client_IOT); + AI_client_IOT = NULL; + AI_VC_read_IOT_id=0; + + bk_printf("CLOSE_IOT"); + // AI_client_IOT + } + break; case VC_START: AI_VC_start(0); @@ -3670,6 +5743,8 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 break; case AI_KEY_PRESS: + // is_dialog_status=0; + AI_key_press(); break; @@ -3694,20 +5769,73 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 case AI_TIMER_EVENT: sys_10S_timeout_even(); break; + case AI_TIMER_EVENT_IOT: + sys_60S_timeout_even(); + break; case AI_PRINTF: if(AI_AMP_msg.data) uart_write(ai_uart_handle,AI_AMP_msg.data, AI_AMP_msg.len); break; - case AI_KEY2_PRESS: - bk_printf("AI_KEY2_PRESS"); - #if SUPPORT_MOT - mot_nod(5); - #endif - break; + case AI_KEY2_RELEASE: + // bk_printf("AI_KEY2_RELEASE"); + + // mot_nod_status(); + if(AI_VC_stata==1) + random_chumo(2,0); + // #if SUPPORT_MOT + // mot_nod(5); + // #endif + break; + case AI_KEY3_RELEASE: + bk_printf("AI_KEY3_RELEASE"); + // #if SUPPORT_MOT + // mot_nod(5); + // #endif + if(AI_VC_stata==1) + random_chumo(0,0); + break; + case AI_KEY4_RELEASE: + bk_printf("AI_KEY4_RELEASE"); + // #if SUPPORT_MOT + // mot_nod(5); + // #endif + if(AI_VC_stata==1) + random_chumo(1,0); + break; + case AI_KEY2_LONG_PRESS: + bk_printf("AI_KEY2_LONG_PRESS"); + // #if SUPPORT_MOT + // mot_nod(5); + // #endif + if(AI_VC_stata==1) + random_chumo(2,1); + + break; + case AI_KEY3_LONG_PRESS: + bk_printf("AI_KEY3_LONG_PRESS"); + // #if SUPPORT_MOT + // mot_nod(5); + // #endif + if(AI_VC_stata==1) + random_chumo(0,1); + break; + case AI_KEY4_LONG_PRESS: + bk_printf("AI_KEY4_LONG_PRESS"); + // #if SUPPORT_MOT + // mot_nod(5); + // #endif + if(AI_VC_stata==1) + random_chumo(1,1); + break; case MOT_GPIO_HANDLE_CB: mot_gpio_handle_cb(AI_AMP_msg.data); + break; + + case AI_MOT_BACK_MID: + + back_middle_statu_mot(); break; default: diff --git a/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.h b/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.h index efb83fa..e74e506 100644 --- a/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.h +++ b/2.code/aicos/app/AI_AMP_2_5/AI_AMP_2_5.h @@ -8,8 +8,9 @@ #define BK_LOG_UART 1//串口打印 #define BK_LOG_USB 2//USB打印 +// -#define BK_LOG_CFG BK_LOG_UART +#define BK_LOG_CFG BK_LOG_USB typedef enum { @@ -79,12 +80,23 @@ typedef enum AI_AMP_MSG AI_KEY_LONG_PRESS,//AI键长按 AI_KEY_LONG_RELEASE,//AI键长按释放 AI_KEY2_PRESS,//KEY2 + AI_KEY3_PRESS,//KEY2 + AI_KEY4_PRESS,//KEY2 + AI_KEY2_RELEASE, + AI_KEY3_RELEASE, + AI_KEY4_RELEASE, + AI_KEY2_LONG_PRESS, + AI_KEY3_LONG_PRESS, + AI_KEY4_LONG_PRESS, PWK_KEY_RELEASE,//侧键 PLAY_AUDIO_FILE,//播放本地音频文件 PLAY_FILE_STREAM_DATA,//播放本地文件,用音频流的方式 AI_TIMER_EVENT,//定时器事件 MOT_GPIO_HANDLE_CB, AI_PRINTF,//打印 + AI_TIMER_EVENT_IOT,//定时器事件 + AI_MOT_BACK_MID, + CLOSE_IOT, } AI_AMP_MSG_Type; typedef struct { diff --git a/2.code/aicos/app/AI_AMP_2_5/bk_key.c b/2.code/aicos/app/AI_AMP_2_5/bk_key.c index 65f307c..ec1d176 100644 --- a/2.code/aicos/app/AI_AMP_2_5/bk_key.c +++ b/2.code/aicos/app/AI_AMP_2_5/bk_key.c @@ -17,9 +17,6 @@ - - - static int32_t bk_kpc_callback(void *p_param, uint32_t size) { kpc_key_array_t *key_arr = (kpc_key_array_t *)p_param; @@ -29,37 +26,81 @@ static int32_t bk_kpc_callback(void *p_param, uint32_t size) } for (int i = 0; i < KPC_KEY_PRESSED_MAX_KEY_NUM; i++) { - bk_printf("bk_kpc_callback key[%d].key_value=%d",i,key_arr->key[i].key_value); + // bk_printf("bk_kpc_callback key[%d].key_value=%d",i,key_arr->key[i].key_value); switch (key_arr->key[i].key_event) { case KPC_KEY_EVENT_PRESS://按下 - // bk_printf("[%d]AI_key_press",key_arr->key[i].key_value); - if (key_arr->key[i].key_value == 0) {//AI键 + + // bk_printf("[%x]testkey123",key_arr->key[i].key_value); + + // bk_printf("[%x]testkey123",key_arr->key[i].); + if (key_arr->key[i].key_value == 0) { //AI键 + + // bk_printf("00000000000"); AI_AMP_MSG_put(0, 0, AI_KEY_PRESS); + // bk_printf("[%d]AI_key_press",key_arr->key[i].key_value); + }else if(key_arr->key[i].key_value == 1) {//AI键 - + // bk_printf("111111111"); AI_AMP_MSG_put(0, 0, AI_KEY_PRESS); }else if(key_arr->key[i].key_value == 2) {//按键2键 - + // bk_printf("222222"); AI_AMP_MSG_put(0, 0, AI_KEY2_PRESS); + }else if(key_arr->key[i].key_value == 4) {//按键2键 + // bk_printf("222222"); + AI_AMP_MSG_put(0, 0, AI_KEY2_PRESS); + }else if(key_arr->key[i].key_value == 5) {//按键2键 + // bk_printf("222222"); + AI_AMP_MSG_put(0, 0, AI_KEY3_PRESS); + }else if(key_arr->key[i].key_value == 6) {//按键2键 + // bk_printf("222222"); + AI_AMP_MSG_put(0, 0, AI_KEY4_PRESS); } break; case KPC_KEY_EVENT_RELEASE://释放 + + // bk_printf("KPC_KEY_EVENT_RELEASE"); + if (key_arr->key[i].key_value == 0) {//AI键 AI_AMP_MSG_put(0, 0, AI_KEY_RELEASE); }else if(key_arr->key[i].key_value == 1) {//AI键 AI_AMP_MSG_put(0, 0, AI_KEY_RELEASE); - }else if(key_arr->key[i].key_value == 2) {// + }else if(key_arr->key[i].key_value == 4) {// + AI_AMP_MSG_put(0, 0, AI_KEY2_RELEASE); + + }else if(key_arr->key[i].key_value == 5) {// + + AI_AMP_MSG_put(0, 0, AI_KEY3_RELEASE); + + }else if(key_arr->key[i].key_value == 6) {// + + AI_AMP_MSG_put(0, 0, AI_KEY4_RELEASE); } + break; + case KPC_KEY_EVENT_LONGKEY://长按 + + bk_printf("KPC_KEY_EVENT_LONGKEY"); if (key_arr->key[i].key_value == 0) {//AI键 AI_AMP_MSG_put(0, 0, AI_KEY_LONG_PRESS); }else if(key_arr->key[i].key_value == 1) {//AI键 AI_AMP_MSG_put(0, 0, AI_KEY_LONG_PRESS); + }else if(key_arr->key[i].key_value == 5) {//AI键 + + AI_AMP_MSG_put(0, 0, AI_KEY3_LONG_PRESS); + + } + else if(key_arr->key[i].key_value == 6) {//AI键 + + AI_AMP_MSG_put(0, 0, AI_KEY4_LONG_PRESS); + + }else if(key_arr->key[i].key_value == 4) {//AI键 + + AI_AMP_MSG_put(0, 0, AI_KEY2_LONG_PRESS); } break; @@ -81,7 +122,7 @@ static int32_t bk_kpc_callback(void *p_param, uint32_t size) break; } } - bk_printf("\n"); + // bk_printf("\n"); return 0; diff --git a/2.code/aicos/app/AI_AMP_2_5/bk_opus_coder.c b/2.code/aicos/app/AI_AMP_2_5/bk_opus_coder.c index 3279114..77e1006 100644 --- a/2.code/aicos/app/AI_AMP_2_5/bk_opus_coder.c +++ b/2.code/aicos/app/AI_AMP_2_5/bk_opus_coder.c @@ -278,9 +278,9 @@ int ogg_opus_decode_data(char *in_ogg_data,int in_ogg_data_len) /**********1阶段判断头********** */ if(ogg_hend_len==0)//没有剩余的头数据 { - bk_printf("ogg_hend_len123:%d",ogg_hend_len); + // bk_printf("ogg_hend_len123:%d",ogg_hend_len); - bk_printf("bk_rb_data_len:%d",bk_rb_data_len(OPUS_decoder_rb_data)); + // bk_printf("bk_rb_data_len:%d",bk_rb_data_len(OPUS_decoder_rb_data)); bk_rb_read(OPUS_decoder_rb_data,ogg_hend,27); ogg_hend_len+=27;//读页头 @@ -295,7 +295,7 @@ int ogg_opus_decode_data(char *in_ogg_data,int in_ogg_data_len) { if(bk_rb_data_len(OPUS_decoder_rb_data)< seg_num)//判断可读数据够不够 { - bk_printf("算页大小数据不够,退出当前解包:seg_num %d",seg_num); + // bk_printf("算页大小数据不够,退出当前解包:seg_num %d",seg_num); break; } @@ -327,11 +327,11 @@ int ogg_opus_decode_data(char *in_ogg_data,int in_ogg_data_len) } break; } - bk_printf("整页数据大小:%d",seg_size); + // bk_printf("整页数据大小:%d",seg_size); /************3阶段读完整包****************** */ if(bk_rb_data_len(OPUS_decoder_rb_data)< seg_size)//判断可读数据够不够 { - bk_printf("读整页数据大小不够,退出当前解包:seg_size %d,ogg_hend_len:%d",seg_size,ogg_hend_len); + // bk_printf("读整页数据大小不够,退出当前解包:seg_size %d,ogg_hend_len:%d",seg_size,ogg_hend_len); break; } @@ -400,7 +400,7 @@ int ogg_opus_decode_data(char *in_ogg_data,int in_ogg_data_len) // bk_printf("opus解码 输入大小:%d,输出大小:%d", frame_length,dec_inparam.outputfrms_size); - bk_printf("ogg-opus解码 输入数据大小:%d,输出数据大小:%d,耗时:%d ms",input_tmp_len,ooutput_tmp_len,aos_get_tickcount()-timer_ms ); + // bk_printf("ogg-opus解码 输入数据大小:%d,输出数据大小:%d,耗时:%d ms",input_tmp_len,ooutput_tmp_len,aos_get_tickcount()-timer_ms ); // opus_decode_len+=ooutput_tmp_len; @@ -428,4 +428,139 @@ int ogg_opus_decode_data(char *in_ogg_data,int in_ogg_data_len) #endif return 0; +} +int my_opus_decode_data(char *in_ogg_data,int in_ogg_data_len) +{ + int data_count = 0; + int page_type; + int channel_cnt, sample_rate; + unsigned char* p_audio; + int frame_length; + struct opus_dec_param dec_inparam; + int ret = 0; + int input_tmp_len = 0,ooutput_tmp_len = 0; + int seg_num =0; + + // char decode_buf_opus[480]; + //fread(page_buffer, 1, 27 + seg_num, fin); + if(!in_ogg_data) + return -2; + //fseek(fin, -1 * (27 + seg_num), SEEK_CUR); + //fread(page_buffer, 1, 27 + seg_num + seg_size, fin); + int seg_size; + + + char *pcm_buf = aic_malloc(1920); + if(pcm_buf) + { + + dec_inparam.input = in_ogg_data; + dec_inparam.inputfrm_count = 1; + dec_inparam.input_len_array[0] = in_ogg_data_len; + //memcpy(dec_inparam.input_len_array , enc_inparam.output_len_array, sizeof(dec_inparam.input_len_array)); + dec_inparam.output = (int16_t *)pcm_buf; + dec_inparam.outbuffer_size = 1920; + ret = aic_opus_decode(&dec_inparam); + + // bk_printf("opus解码 输入大小:%d,输出大小:%d", in_ogg_data_len,dec_inparam.outputfrms_size); + + opus_encode_len++; + + if (ret == OPUS_RESULT_ERROR) { + bk_printf("opus解码 error:%d", ret); + + // bk_printf("ogg data:"); + // audio_data(ogg_buf,27+seg_num+seg_size,27); + // bk_print_hex(ogg_buf,27+seg_num+seg_size); + + aic_free(pcm_buf); + // break; + } + + input_tmp_len+=frame_length; + ooutput_tmp_len += dec_inparam.outputfrms_size; + + AI_VC_put_play_data(pcm_buf,dec_inparam.outputfrms_size);//发送数据到音频队列 + + // audio_data(pcm_buf,dec_inparam.outputfrms_size,24); + + // aos_sleep(1); + + aic_free(pcm_buf); + } + + + // #if SUPPORT_OPUS + // if(OPUS_decoder_rb_data) + // { + // if(OPUS_DECODER_RB_LEN - bk_rb_data_len(OPUS_decoder_rb_data) >= in_ogg_data_len)//缓存够 + // { + // bk_rb_write(OPUS_decoder_rb_data,in_ogg_data,in_ogg_data_len); + // } + // }else + // { + // bk_printf("OPUS_decoder_rb_data error!!!!!"); + // return -1; + // } + // data_count = 0; + // u32 timer_ms = aos_get_tickcount(); + + // while(1) + // { + + // if(bk_rb_data_len(OPUS_decoder_rb_data) < 480)//不够一页数据 + // { + // break; + // }else + // { + + // // decode_buf_opus + + // bk_rb_read(OPUS_decoder_rb_data,decode_buf_opus,480); + + // char *pcm_buf = aic_malloc(1920); + // if(pcm_buf) + // { + + // dec_inparam.input = decode_buf_opus; + // dec_inparam.inputfrm_count = 1; + // dec_inparam.input_len_array[0] = 480; + // //memcpy(dec_inparam.input_len_array , enc_inparam.output_len_array, sizeof(dec_inparam.input_len_array)); + // dec_inparam.output = (int16_t *)pcm_buf; + // dec_inparam.outbuffer_size = 1920; + // ret = aic_opus_decode(&dec_inparam); + + // bk_printf("opus解码 输入大小:%d,输出大小:%d", 480,dec_inparam.outputfrms_size); + + // opus_encode_len++; + + // if (ret == OPUS_RESULT_ERROR) { + // bk_printf("opus解码 error:%d", ret); + // //bk_printf("ogg data:"); + + // // audio_data(ogg_buf,27+seg_num+seg_size,27); + + // // bk_print_hex(ogg_buf,27+seg_num+seg_size); + // aic_free(pcm_buf); + // break; + // } + + // input_tmp_len+=frame_length; + // ooutput_tmp_len += dec_inparam.outputfrms_size; + + // AI_VC_put_play_data(pcm_buf,dec_inparam.outputfrms_size);//发送数据到音频队列 + + // // audio_data(pcm_buf,dec_inparam.outputfrms_size,24); + + // //aos_sleep(1); + // aic_free(pcm_buf); + // } + + // } + + // //aos_sleep(1); + // } + + // #endif + return 0; } \ No newline at end of file diff --git a/2.code/aicos/app/AI_AMP_2_5/bk_opus_coder.h b/2.code/aicos/app/AI_AMP_2_5/bk_opus_coder.h index 82eed1c..4220e30 100644 --- a/2.code/aicos/app/AI_AMP_2_5/bk_opus_coder.h +++ b/2.code/aicos/app/AI_AMP_2_5/bk_opus_coder.h @@ -5,4 +5,7 @@ void opus_close(void); void opus_clean(void); int opus_encode_data(char *PCM_data,int data_len,int one_pack_len,char *opus_data,int opus_data_max_len); int ogg_opus_decode_data(char *in_ogg_data,int in_ogg_data_len); + +int my_opus_decode_data(char *in_ogg_data,int in_ogg_data_len); + #endif diff --git a/2.code/aicos/app/AI_AMP_2_5/bk_websocket.c b/2.code/aicos/app/AI_AMP_2_5/bk_websocket.c index 2b9812e..2dbcd22 100644 --- a/2.code/aicos/app/AI_AMP_2_5/bk_websocket.c +++ b/2.code/aicos/app/AI_AMP_2_5/bk_websocket.c @@ -957,3 +957,357 @@ client_ERROR: return -1; } +WebSocketClient *init_websocket_IOT_V3(const char *url, const char *headers) +{ + //bk_printf("init_websocket_client 1\n"); + char *buffer = NULL; + WebSocketClient *client =NULL; + BK_URL parsed_url = {0}; + parsed_url = parse_url(url);//解析url + //bk_printf("url: %s", url); + if (parsed_url.error) { + bk_printf("Error: %s", parsed_url.error_message); + goto client_ERROR; + } else { + bk_printf("Protocol: %s", parsed_url.protocol); + bk_printf("Host: %s", parsed_url.host); + bk_printf("Port: %d", parsed_url.port); + bk_printf("Path: %s", parsed_url.path); + bk_printf("Query: %s", parsed_url.query); + + } + client = aic_zalloc(sizeof(WebSocketClient)) ; + if(!client) + { + bk_printf("init_websocket_client alloc error"); + goto client_ERROR; + } + struct addrinfo hints, *addr_list, *cur; + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + if( getaddrinfo( parsed_url.host, parsed_url.port_str, &hints, &addr_list ) != 0 ) + //if( getaddrinfo( "www.baidu.com", "80", &hints, &addr_list ) != 0 ) + { + bk_printf("init_websocket_client getaddrinfo error"); + goto client_ERROR; + } + + for( cur = addr_list; cur != NULL; cur = cur->ai_next ) + { + client->sockfd = (int) socket( cur->ai_family, cur->ai_socktype, + cur->ai_protocol ); + if( client->sockfd < 0 ) + { + continue; + } + + if( connect( client->sockfd , cur->ai_addr, (int)cur->ai_addrlen ) == 0 ) + { + + break; + } + + close( client->sockfd ); + + + } + freeaddrinfo(addr_list); // 释放资源 + if(client->sockfd<0) + { + bk_printf("init_websocket_client connect error"); + goto client_ERROR; + } + + bk_printf("init_websocket_client connect ok,sockfd:%d",client->sockfd); +// client->sockfd = socket(AF_INET, SOCK_STREAM, 0); +// if (client->sockfd < 0) { +// bk_printf("socket creation failed"); +// goto client_ERROR; +// } + +// // bk_printf("init_websocket_client 3\n"); +// struct sockaddr_in server_addr; +// server_addr.sin_family = AF_INET; +// server_addr.sin_port = htons(parsed_url.port); +// inet_pton(AF_INET, parsed_url.host, &server_addr.sin_addr); + +// if (connect(client->sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { +// bk_printf("connection failed"); +// close(client->sockfd); +// goto client_ERROR; +// } + + + strcpy(client->host, parsed_url.host); + strcpy(client->path, parsed_url.path); + strcpy(client->query, parsed_url.query); + client->port = parsed_url.port; + if (send_handshake(client,headers) < 0) { //发送头 + close(client->sockfd); + goto client_ERROR; + } + + bk_printf("Received handshake response11"); + buffer=aic_zalloc(BUFFER_SIZE); + ssize_t bytes_received = recv(client->sockfd, buffer, BUFFER_SIZE - 1, 0); + + bk_printf("Received handshake response22 %d,",bytes_received); + if (bytes_received > 0) { + buffer[bytes_received] = '\0'; + bk_printf("Received handshake response:\n%s\n", buffer); + } + if(strstr(buffer,"HTTP/1.1 101") == NULL) + { + + goto client_ERROR; + } + aic_free(buffer); + + + free_url(parsed_url); + return client; +client_ERROR: + if(buffer) + aic_free(buffer); + if(client) + aic_free(client); + free_url(parsed_url); + return NULL; +} + +int receive_websocket_message_V3(WebSocketClient *client, unsigned char *buf,int len,WebSocketMessageType *code) { + // u64 timer_ms = aos_get_tickcount(); + // bk_printf("receive_websocket_message 1 timer_ms=%d\n",timer_ms); + if(!client ) + return -1; + unsigned char frame[20]={0}; + unsigned char masking_key[4]; + int bytes_received = 0; + int recv_len = 0 ; + static u8 last_byte = 0; + static u32 error_count = 0; + // while(1) + // { + // recv_len = recv(client->sockfd, frame+bytes_received, 2-bytes_received, 0); + // bytes_received +=recv_len; + // if(bytes_received>=2) + // break; + // } + + while(1) + { + bytes_received = recv(client->sockfd, frame, 1, 0); + + // bk_printf("receive_websocket_message:frame:0x%x,bytes_received:%d",frame[0],bytes_received); + + if (bytes_received == 0) { + bk_printf("Connection closed by server.1\n\n\n\n"); + return 0; + } else if(bytes_received<0){ + bk_printf("receive message failed1\n\n\n\n"); + return -1; + } + if(frame[0]!= 0x80 && frame[0]!= 0x81 && frame[0]!= 0x82 && frame[0]!= 0x88 && frame[0]!= 0x89 && frame[0]!= 0x8A) + { + error_count++; + bk_printf("receive_websocket_message:hend =0x%X,0x%X ,last_byte =0x%x error_count =%d ERROR!!!!!!!!!",frame[0],frame[1],last_byte,error_count); + + if(last_byte!= 0x80 && last_byte!= 0x81 && last_byte!= 0x82 && last_byte!= 0x88 && last_byte!= 0x89 && last_byte!= 0x8A) + { + bk_printf("receive_websocket_message:hend =0x%X,0x%X ,last_byte =0x%x ERROR222222222!!!!!!!!!",frame[0],frame[1],last_byte); + continue; + } + + }else + { + + break; + } + } + // bk_printf("websocket2 timer_ms=%d\n",timer_ms- aos_get_tickcount()); + // timer_ms = aos_get_tickcount(); + //bk_sleep(5); + bytes_received = recv(client->sockfd, frame+1, 1, 0); + if (bytes_received == 0) { + bk_printf("Connection closed by server.2\n\n\n\n"); + return 0; + } else if(bytes_received<0){ + bk_printf("receive message failed 2 \n\n\n\n"); + return -1; + } + //unsigned char fin = (frame[0] & 0x80) >> 7; + *code = frame[0] & 0x0F; + unsigned char mask = (frame[1] & 0x80) >> 7; + unsigned int payload_len = frame[1] & 0x7F; + + + size_t offset = 2; + if (payload_len == 126) { + unsigned short extended_payload_len; + bytes_received = 0; + while(1) + { + recv_len= recv(client->sockfd, frame+offset+bytes_received, 2-bytes_received, 0); + if (recv_len == 0) { + bk_printf("Connection closed by server 3.\n\n\n\n"); + return 0; + } else if(recv_len<0){ + bk_printf("receive message failed 3 \n\n\n\n"); + return -1; + } + bytes_received +=recv_len; + if(bytes_received>=2) + break; + + } + + // bytes_received_t = bytes_received; + memcpy(&extended_payload_len, frame + 2, 2); + payload_len = ntohs(extended_payload_len); + //bk_printf("receive_websocket_message:payload_len=0x%X",extended_payload_len); + offset += 2; + } else if (payload_len == 127) { + u64 extended_payload_len; + bytes_received = 0; + while(1) + { + recv_len= recv(client->sockfd, frame+offset+bytes_received, 8-bytes_received, 0); + if (recv_len == 0) { + bk_printf("Connection closed by server 4.1\n\n\n\n"); + return 0; + } else if(recv_len<0){ + bk_printf("receive message failed 4\n\n\n\n"); + return -1; + } + bytes_received +=recv_len; + if(bytes_received>=8) + break; + + } + memcpy(&extended_payload_len, frame + 2, 8); + payload_len = ntohll(extended_payload_len); + offset += 8; + } + if(payload_len>len) + { + bk_printf("receive_websocket_message:len =%d ERROR",payload_len); + recv(client->sockfd, buf, len, 0); + return -1; + } + + // bk_printf("receive_websocket_message :"); + // for(int i = 0;isockfd, frame+offset, 4, 0); + memcpy(masking_key, frame + offset, 4); + offset += 4; + } + + + bytes_received = 0; + // payload_len-=1;//少读一个字节,防止粘包 + //bk_sleep(1); + while(1)//读主体内容 + { + // bk_sleep(recv_len/200+1); + // bk_printf("bytes_received %d %d",payload_len,bytes_received); + recv_len = recv(client->sockfd, buf+bytes_received, payload_len-bytes_received, 0); + + // bk_printf("recv_len %d %d",payload_len,recv_len); + + if (recv_len == 0) { + bk_printf("Connection closed by server.5\n\n\n\n\n"); + return 0; + } else if(recv_len<0){ + bk_printf("receive message failed 5\n\n\n\n"); + return -1; + } + + bytes_received += recv_len; + + //bk_printf("receive_websocket_message:bytes_received=%d recv_len =%d",bytes_received,recv_len); + if(bytes_received >= payload_len) + { + //bk_printf("receive_websocket_message:payload_len=%d,bytes_received=%d",payload_len,bytes_received); + break; + } + + } + //bk_sleep(1); + // bk_printf("websocket 3 timer_ms=%d\n",timer_ms- aos_get_tickcount()); + // timer_ms= aos_get_tickcount(); + // bk_sleep(1);//等最后一字节返回,防止粘包 + // recv(client->sockfd, buf+payload_len, 1, 0);//读最后一字节 + // payload_len+=1; + if(mask) + { + for (size_t i = 0; i < payload_len; ++i) { + buf[i] = buf[i] ^ masking_key[i % 4]; + } + } + + // if (*code == WS_TEXT) { + // bk_printf("Received text message: %.*s\n", (int)payload_len, buf); + // } else if (*code == WS_BINARY) { + // bk_printf("Received binary message of length %zu\n", payload_len); + // } + // if(error_count>0) + // { + // bk_printf("WS ERROR!!!!!!last_byte:0x%x bytes_received_t_1:0x%x\r\n\n\n\n\n\n\n",last_byte,bytes_received_t_1); + // bk_print_hex(frame_t,frame_t_len); + // bk_print_hex(websocket_tmp_b,websocket_tmp_b_len); + // bk_printf("WS ERROR!!!!!!\r\n\n\n\n\n\n\n"); + // bk_print_hex(frame,offset); + // bk_print_hex(buf,payload_len); + + // } + // bytes_received_t_1 = bytes_received_t; + if (*code == WS_TEXT) + { + + }else if(*code == WS_BINARY) + { + + }else if(*code == WS_CLOSE) + { + payload_len = 0; + }else if(*code == WS_PONG) + { + //payload_len = 1; + }else if(*code == WS_PING) + { + send_websocket_message(client,buf,payload_len,WS_PONG); + //payload_len = 1; + }else if(*code == WS_CONT) + { + //payload_len = 1; + } + last_byte = buf[payload_len-1]; + //timer_ms = aos_get_tickcount(); + //bk_printf("receive_websocket_message 4 timer_ms=%d len = %d\n",timer_ms,payload_len); + error_count=0; + // websocket_tmp_b_len = payload_len; + // if(payload_len>sizeof(websocket_tmp_b)) + // { + // websocket_tmp_b_len=sizeof(websocket_tmp_b); + // } + // memcpy(websocket_tmp_b,buf,websocket_tmp_b_len); + + + // frame_t_len = offset; + // if(frame_t_len>sizeof(frame_t)) + // { + // frame_t_len=sizeof(frame_t); + // } + // memcpy(frame_t,frame,frame_t_len); + + + return payload_len;//parse_frame(buf, bytes_received, buf,code); +} + diff --git a/2.code/aicos/app/AI_AMP_2_5/bk_websocket.h b/2.code/aicos/app/AI_AMP_2_5/bk_websocket.h index 2252024..35e673e 100644 --- a/2.code/aicos/app/AI_AMP_2_5/bk_websocket.h +++ b/2.code/aicos/app/AI_AMP_2_5/bk_websocket.h @@ -24,7 +24,9 @@ typedef struct { // 初始化 WebSocket 客户端 WebSocketClient *init_websocket_client(const char *url, const char *headers); +WebSocketClient *init_websocket_IOT_V3(const char *url, const char *headers); +int receive_websocket_message_V3(WebSocketClient *client, unsigned char *buf,int len,WebSocketMessageType *code); // 关闭 WebSocket 客户端 void close_websocket_client(WebSocketClient *client) ; diff --git a/2.code/aicos/app/AI_AMP_2_5/dev_authentication.c b/2.code/aicos/app/AI_AMP_2_5/dev_authentication.c index 9316274..4511b17 100644 --- a/2.code/aicos/app/AI_AMP_2_5/dev_authentication.c +++ b/2.code/aicos/app/AI_AMP_2_5/dev_authentication.c @@ -24,6 +24,9 @@ #include "aic_http_client.h" #include "aic_fota.h" + + #define DMPTEST + #define bk_malloc aic_malloc #define bk_free aic_free int get_dev_pass_MAX_len(void)//获取设备密码最大长度,注意要防止内存越界 @@ -329,6 +332,146 @@ char * get_token(void) const char *dev_pid = "cqxJZi5CNgzjS3mX21Zw";//PID const char *dev_key = "uKLrChwrxA1LklgBc3VwawYjUkbT3BgX";//密钥 +#define HTTP_DEMO_CLIENT_NAME "HTTP Demo Client" +#define HTTP_DEMO_URL "http://47.101.171.33/doc/download/10.txt" +#define HTTPS_DEMO_URL "https://47.101.171.33/doc/download/CK8K.txt" + +#define HTTP_DEMO_WAIT_TIME (10 * 1000) +#define HTTP_DEMO_SLEEP_TIME (60 *1000) + +static u32 http_demo_handle = 0; +static u32 https_demo_handle = 0; +static aos_thread_id http_demo_thread; +static aos_thread_id https_demo_thread; + +void aic_http_demotest() +{ + u32 status = 0; + long lbytes = 0; + u8 *buff; + u32 bytes = 1500; + u32 total_length = 0; + u32 length_to_be_copied = 0; + u32 chunked_mode = 0; + + bk_printf("aic_http_demotest1213..."); + + http_demo_handle = aic_http_client_create(HTTP_DEMO_CLIENT_NAME); + if (http_demo_handle == 0) { + return; + } + aicx_error(0x1132e2, "", "http demo start"); + + bk_printf("aic_http_demotest121312..."); + + /*wait pdp active,only for demo test.*/ + //aos_sleep(HTTP_DEMO_SLEEP_TIME); + + status = aic_http_client_get_start(http_demo_handle, HTTP_DEMO_URL, NULL, + NULL, 80, HTTP_DEMO_WAIT_TIME); + if (status != NX_SUCCESS) { + aic_http_client_delete(http_demo_handle); + return; + } + + buff = aos_zalloc(bytes+2000); + + bk_printf("aic_http_demotest1213121..."); + + do { + + bk_printf("aic_http_demotest1213122..."); + lbytes = aic_https_client_response_data_get(http_demo_handle, buff, bytes, + HTTP_DEMO_WAIT_TIME); + bk_printf("aic_http_demotest1213123 lbytes %d...",lbytes); + // aicx_error(0x18afe9, "d", "http get lbytes len is %d", lbytes); + + if (lbytes <= 0) { + break; + } else { + chunked_mode = aic_http_client_chunked_mode_check(http_demo_handle); + length_to_be_copied = aic_https_client_total_receive_bytes_get(http_demo_handle); + if (!chunked_mode && length_to_be_copied) { + total_length += lbytes; + } + + bk_printf("aic_http_demotest1213123..."); + } + + } while (total_length < length_to_be_copied || chunked_mode); + + // aicx_error(0x1e6e26, "s", "http get data is %s", buff); + + bk_printf("aic_http_demotest1213123 finish..."); + + aic_http_client_delete(http_demo_handle); + + return; +} + + +void aic_https_demotest() +{ + u32 status = 0; + LONG lbytes = 0; + u8 *buff; + u32 bytes = 1500; + u32 total_length = 0; + u32 length_to_be_copied = 0; + u32 chunked_mode = 0; + AIC_HTTPS_CLIENT_INSTANCE *client_ptr; + + bk_printf("aic_https_demotest1213..."); + + https_demo_handle = aic_https_client_create(HTTP_DEMO_CLIENT_NAME); + if (https_demo_handle == 0) { + return; + } + + bk_printf("aic_https_demotest12131..."); + + /*for https test,set auth_type to 0, do not need certifica1*/ + client_ptr = (AIC_HTTPS_CLIENT_INSTANCE *)https_demo_handle; + client_ptr->https_client->auth_type = 0; + + /*wait pdp active,only for demo test.*/ + aos_sleep(HTTP_DEMO_SLEEP_TIME); + + status = aic_https_client_get_start(https_demo_handle, HTTPS_DEMO_URL, NULL, + NULL, 443, HTTP_DEMO_WAIT_TIME); + if (status != NX_SUCCESS) { + aic_https_client_delete(https_demo_handle); + return; + } + + buff = aos_zalloc(bytes+2000); + + do { + lbytes = aic_https_client_response_data_get(https_demo_handle, buff , bytes, + HTTP_DEMO_WAIT_TIME); + if (lbytes <= 0) { + break; + } else { + + bk_printf("https get data %d ",lbytes); + chunked_mode = aic_http_client_chunked_mode_check(https_demo_handle); + length_to_be_copied = aic_https_client_total_receive_bytes_get(https_demo_handle); + if (!chunked_mode && length_to_be_copied) { + total_length += lbytes; + } + } + + } while (total_length < length_to_be_copied || chunked_mode); + + // aicx_error(0x0f0971, "s", "https get data is %s", buff); + + bk_printf("download123 finish..."); + + aic_https_client_delete(https_demo_handle); + + return; +} + void aut_active(void)//设备激活 { @@ -374,10 +517,18 @@ void aut_active(void)//设备激活 //登陆数据 bk_printf("dev_id:%s timestamp:%s ",deviceId,timestamp_str); - char *sign_url = "http://dmp.raisound.com/bz-api/dev/auth/active"; + +#ifdef DMPTEST + + char *sign_url = "http://dmp-dev.raisound.com/dmp-api/dev/auth/active"; + bk_printf("http://dmp-dev.raisound.com/dmp-api/dev/auth/active\n"); +#else + char *sign_url = "http://dmp.raisound.com/bz-api/dev/auth/active"; bk_printf("http://dmp.raisound.com/bz-api/dev/auth/active\n"); +#endif + u32 response = 0; //创建客户端实例 aut_active_http_handle = aic_http_client_create("HTTP_DEMO_CLIENT_NAME"); @@ -1300,8 +1451,16 @@ void aut_login(void)//登录 aes_cbc_pkcs5_encrypt(dev_pass, strlen(dev_pass), dev_key, enc_iv,encrypt_data,&encrypt_data_len);//加密 bk_printf("deviceId:%s password:%s nonce:%s,dev_pass:%s", deviceId, encrypt_data, enc_iv,dev_pass); - char *sign_url = "http://dmp.raisound.com/bz-api/dev/auth/sign_in"; // 登录地址 + // char *sign_url = "http://dmp.raisound.com/bz-api/dev/auth/sign_in"; // 登录地址 //char *headers_T = "\"Content-Type\":\"application/json\""; + +#ifdef DMPTEST + char *sign_url = "http://dmp-dev.raisound.com/dmp-api/dev/auth/sign_in"; // 登录地址 +#else + + char *sign_url = "http://dmp.raisound.com/bz-api/dev/auth/sign_in"; // 登录地址 +#endif + bk_printf(sign_url); u32 response = 0; aut_login_http_handle = aic_http_client_create("HTTP_DEMO_CLIENT_NAME"); @@ -1440,12 +1599,12 @@ static void dev_authentication_task(void *thread_input)//鉴权逻辑线程 aut_login(); - // if(strlen(get_token())<8)//20秒都没更新tokey - // { + if(strlen(get_token())<8)//20秒都没更新tokey + { - // aut_active(); - // aut_login(); - // } + aut_active(); + aut_login(); + } diff --git a/2.code/aicos/app/AI_AMP_2_5/imsl_kws.h b/2.code/aicos/app/AI_AMP_2_5/imsl_kws.h index 394e975..daa83b8 100644 --- a/2.code/aicos/app/AI_AMP_2_5/imsl_kws.h +++ b/2.code/aicos/app/AI_AMP_2_5/imsl_kws.h @@ -2,7 +2,7 @@ * Build Information * Git Commit: 66c47c389123d4d655eb5b1d63b5918355f15ce7 * Branch: master - * Build Date: 2025-09-29 18:13:29 + * Build Date: 2025-12-17 16:12:17 */ #ifndef _IMSL_KWS_DLL @@ -62,9 +62,10 @@ kws_conf.kws_log_level = 0; int kws_status = init_kws(&kws_conf); -struct AuthInfo auth_info; -strcpy(auth_info.dmp_token, dmp_token); -auth_kws(&auth_info); +// 授权部分,可以忽ç•? +// struct AuthInfo auth_info; +// strcpy(auth_info.dmp_token, dmp_token); +// auth_kws(&auth_info); // 在每次接收语音时调用 注意 如果是void* æˆ?int8* 的指针,长度 / 2 // 运行结束后获取kws状æ€? @@ -80,7 +81,24 @@ free_kws(); */ -/* example 2 配合vad使用 + + + + + + + + + + + + + + + + + +/* example 2 配合vad使用 废弃方案 // 初始åŒ? diff --git a/2.code/aicos/app/AI_AMP_2_5/imsl_vad.h b/2.code/aicos/app/AI_AMP_2_5/imsl_vad.h index b95741f..407f713 100644 --- a/2.code/aicos/app/AI_AMP_2_5/imsl_vad.h +++ b/2.code/aicos/app/AI_AMP_2_5/imsl_vad.h @@ -2,7 +2,7 @@ * Build Information * Git Commit: 66c47c389123d4d655eb5b1d63b5918355f15ce7 * Branch: master - * Build Date: 2025-09-29 18:13:30 + * Build Date: 2025-12-17 16:12:18 */ #ifndef _IMSL_VAD_DLL @@ -16,6 +16,7 @@ typedef int (*imsl_nn_printf_func)(const char *format, ...); struct AuthInfo { char dmp_token[64]; + int server_addr; }; #endif @@ -94,6 +95,7 @@ void free_vad(); init_vad(&conf); struct AuthInfo auth_info; + auth_info.server_addr = 0; // 0 表示 国内 1 表示 海外 strcpy(auth_info.dmp_token, dmp_token); auth_vad(&auth_info); diff --git a/2.code/aicos/app/AI_AMP_2_5/libimslkws.a b/2.code/aicos/app/AI_AMP_2_5/libimslkws.a index 5610ab3..fde1017 100644 Binary files a/2.code/aicos/app/AI_AMP_2_5/libimslkws.a and b/2.code/aicos/app/AI_AMP_2_5/libimslkws.a differ diff --git a/2.code/aicos/app/AI_AMP_2_5/libimslnn.a b/2.code/aicos/app/AI_AMP_2_5/libimslnn.a index 9e25eca..9ce432c 100644 Binary files a/2.code/aicos/app/AI_AMP_2_5/libimslnn.a and b/2.code/aicos/app/AI_AMP_2_5/libimslnn.a differ diff --git a/2.code/aicos/app/AI_AMP_2_5/libimslvad.a b/2.code/aicos/app/AI_AMP_2_5/libimslvad.a index b8bf999..2a72056 100644 Binary files a/2.code/aicos/app/AI_AMP_2_5/libimslvad.a and b/2.code/aicos/app/AI_AMP_2_5/libimslvad.a differ diff --git a/2.code/aicos/app/AI_AMP_2_5/mot_dev.c b/2.code/aicos/app/AI_AMP_2_5/mot_dev.c index 4fe4896..929263b 100644 --- a/2.code/aicos/app/AI_AMP_2_5/mot_dev.c +++ b/2.code/aicos/app/AI_AMP_2_5/mot_dev.c @@ -17,7 +17,7 @@ #include "aic_srv_tele_sim.h" #include #include "aic_version.h" - +#include "eipu.h" #include "dev_authentication.h" #include "imsl_vad.h" @@ -30,24 +30,24 @@ #include "efuse.h" #include "gpo_inc.h" #include "mot_dev.h" -// #define MOT_EN_FWD_IO GPO_2 //马达驱动正反转,20脚 GPO2 -// #define MOT_EN_REV_IO GPIO_14 //马达驱动正反转,74脚 GPIO_14 +//点头 + #define MOT_EN_FWD_IO GPO_2 //马达驱动正反转,20脚 GPO2 + #define MOT_EN_REV_IO GPIO_14 //马达驱动正反转,74脚 GPIO_14 + #define MOT_TOP_SITE_IO GPIO_1 //马达转到最上位置io,56脚 + #define MOT_MIDDLE_SITE_IO GPIO_0 //马达转到最中位置io,81脚 + #define MOT_BOOTOM_SITE_IO GPIO_7//马达转到最下位置io ,77脚 +//摇头 +#define MOT_LR_EN_FWD_IO GPO_13 //马达驱动正反转,20脚 GPO2 GPIO_AGPIO_1 GPO_13 +#define MOT_LR_EN_REV_IO GPIO_19 //马达驱动正反转,74脚 GPIO_14 +#define MOT_LR_TOP_SITE_IO GPIO_AGPIO_3 //马达转到最左位置io,85脚 +// #define MOT_LR_BOOTOM_SITE_IO GPO_8 //马达转到最中左右位置io,86脚 +#define MOT_LR_MIDDLE_SITE_IO GPIO_6//马达转到最中位置io ,80脚 + // #define MOT_TOP_SITE_IO GPIO_1 //马达转到最上位置io,56脚 // #define MOT_MIDDLE_SITE_IO GPIO_26 //马达转到最中位置io,77脚 // #define MOT_BOOTOM_SITE_IO GPIO_7//马达转到最下位置io ,81脚 -// #define MOT_EN_LR_FWD_IO GPO_13 //马达驱动正反转,79脚 GPO2 -// #define MOT_EN_LR_REV_IO GPIO_19 //马达驱动正反转,75脚 GPIO_14 -// #define MOT_LR_TOP_SITE_IO GPIO_18 //马达转到最上位置io,85脚 -// #define MOT_LR_MIDDLE_SITE_IO GPIO_26 //马达转到最中位置io,86脚 -// #define MOT_LR_BOOTOM_SITE_IO GPIO_6//马达转到最下位置io ,80脚 - -#define MOT_EN_FWD_IO GPO_13 //马达驱动正反转,20脚 GPO2 -#define MOT_EN_REV_IO GPIO_19 //马达驱动正反转,74脚 GPIO_14 -#define MOT_TOP_SITE_IO GPIO_18 //马达转到最左位置io,85脚 -#define MOT_BOOTOM_SITE_IO GPIO_26 //马达转到最中左右位置io,86脚 -#define MOT_MIDDLE_SITE_IO GPIO_6//马达转到最中位置io ,81脚 static unsigned char mot_nod_count = 0;//点头次数 static unsigned char mot_nod_state = 0;//当前点头方向,0向下,1向上 @@ -81,15 +81,15 @@ void mot_gpio_handle_cb(void *param) mot_state = 3; } - if(aic_gpio_level_get(MOT_TOP_SITE_IO) == 0) + if(aic_gpio_level_get(MOT_LR_TOP_SITE_IO) == 0) { mot_state = 1; } - else if(aic_gpio_level_get(MOT_MIDDLE_SITE_IO) == 0) + else if(aic_gpio_level_get(MOT_LR_MIDDLE_SITE_IO) == 0) { mot_state = 2; } - else if(aic_gpio_level_get(MOT_BOOTOM_SITE_IO) == 0) + else if(EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4) == 0) { mot_state = 3; } @@ -140,20 +140,31 @@ void mot_gpio_handle_cb(void *param) }else { - aic_gpo_output(MOT_EN_FWD_IO,GPIO_OUTPUT_LVL_LOW );//停止马达 - aic_gpio_output(MOT_EN_REV_IO,GPIO_OUTPUT_LVL_LOW );//马达 + aic_gpo_output(MOT_LR_EN_FWD_IO,GPIO_OUTPUT_LVL_LOW);//停止马达 + aic_gpio_output(MOT_LR_EN_REV_IO,GPIO_OUTPUT_LVL_LOW);//马达 } old_mot_state = mot_state; } + static void mot_nod1(void);//点头处理; static void mot_nod2(void);//点头处理; static void mot_nod3(void);//点头处理3 +static void mot_nod5(void);//点头处理3 + +static void mot_nothappy(void); + +static void mot_laugh(void); + +static void mot_cute(void); + +static void mot_angry(void); + static aos_thread_id mot_dev_task_id = 0; static aos_queue_ptr mot_dev_task_queue = NULL; aos_status mot_dev_MSG_put(const char *data,u32 len,mot_dev_MSG_Type MSG_Type) { mot_dev_MSG_queue_t mot_dev_MSG_queue_data = {0}; - //bk_msg_printf("mot_dev_MSG_put1 MSG_Type:%d",MSG_Type); + // bk_printf("mot_dev_MSG_put1 MSG_Type:%d",MSG_Type); if(len >0) { mot_dev_MSG_queue_data.data = aic_malloc(len+1); @@ -170,7 +181,7 @@ aos_status mot_dev_MSG_put(const char *data,u32 len,mot_dev_MSG_Type MSG_Type) mot_dev_MSG_queue_data.MSG_Type=MSG_Type; if(mot_dev_task_queue && AOS_SUCCESS!=aos_send_to_queue(mot_dev_task_queue,&mot_dev_MSG_queue_data,AOS_NO_WAIT)) { - //bk_msg_printf("mot_dev_MSG_put :aos_send_to_queue ERROR MSG_Type:%d\n\n",MSG_Type); + // bk_printf("mot_dev_MSG_put :aos_send_to_queue ERROR MSG_Type:%d\n\n",MSG_Type); if(!mot_dev_MSG_queue_data.data) aic_free(mot_dev_MSG_queue_data.data); return AOS_ERROR; @@ -199,21 +210,68 @@ static void mot_dev_task(void *thread_input)//马达线程 while (1) { if(mot_dev_task_queue) { - aos_recv_from_queue(mot_dev_task_queue,&mot_dev_msg,AOS_WAIT_FOREVER) ; + aos_recv_from_queue(mot_dev_task_queue,&mot_dev_msg,AOS_WAIT_FOREVER); + + + aic_get_wakelock(); + + bk_printf("mot_dev_msg.MSG_Type112:%d",mot_dev_msg.MSG_Type); switch (mot_dev_msg.MSG_Type) { - case MOT_NOD1://点头 + case MOT_NOD1://摇头 mot_nod1(); break; - case MOT_NOD2://点头 - mot_nod2(); + case MOT_NOD2://抬头 + mot_test_2(); + break; + case MOT_NOD3://低头,哭泣 + mot_test_3(); break; - case MOT_NOD3://点头 - mot_nod3(); + case MOT_NOD4://点头 + mot_nod5(); break; + case MOT_NOD5://不满 + mot_nothappy(); + break; + case MOT_NOD6://坏笑 + mot_laugh(); + break; + case MOT_NOD7://生气 + mot_angry(); + break; + case MOT_NOD8://卖萌 + mot_cute(); + break; + case MOT_NOD9://开心 + mot_nod5(); + break; + case MOT_CM_0_0://开心 + mot_chumo_0_0(); + break; + case MOT_CM_0_1://开心 + mot_chumo_0_1(); + break; + case MOT_CM_1_0://开心 + mot_chumo_1_0(); + break; + case MOT_CM_1_1://开心 + mot_chumo_1_1(); + break; + case MOT_CM_2_0://开心 + mot_chumo_2_0(); + break; + case MOT_CM_2_1://开心 + mot_chumo_2_1(); + break; + case MOT_LEFT://开心 + mot_test_4(); + break; + case MOT_RIGHT://开心 + mot_test_5(); + break; default: break; @@ -229,18 +287,42 @@ static void mot_dev_task(void *thread_input)//马达线程 } + + bk_printf("mot_dev_task_end...\n"); } + + + void mot_init(void) { bk_printf("mot_init:!!!!"); - aic_gpo_output(MOT_EN_FWD_IO,GPO_OUTPUT_LOW );//马达 - aic_gpio_output(MOT_EN_REV_IO,GPIO_OUTPUT_LVL_LOW );//马达 - // aic_gpo_output( GPO_2,GPO_OUTPUT_LOW );//马达 - // aic_gpio_output(GPIO_14,GPIO_OUTPUT_LVL_LOW );//马达 + + //return ; + // // EIPU_SetPol(NOSEC_MODE, EIPU_DBNC, 1, !pol);//配置为反转电平触发 + // eipu_sample_init(); + + aic_gpo_output(MOT_LR_EN_FWD_IO,GPO_OUTPUT_LOW );//马达 + + bk_printf("mot_init123:!!!!"); + aic_gpio_output(MOT_LR_EN_REV_IO,GPIO_OUTPUT_LVL_LOW );//马达 + bk_printf("mot_init:22!!!!"); - aic_gpio_input(MOT_TOP_SITE_IO, GPIO_INPUT_NOINT, NULL, NULL); - aic_gpio_input(MOT_MIDDLE_SITE_IO, GPIO_INPUT_NOINT, NULL, NULL); - aic_gpio_input(MOT_BOOTOM_SITE_IO, GPIO_INPUT_NOINT, NULL, NULL); + + aic_gpio_input(MOT_LR_TOP_SITE_IO, GPIO_INPUT_NOINT, NULL, NULL); //56pin + aic_gpio_input(MOT_LR_MIDDLE_SITE_IO, GPIO_INPUT_NOINT, NULL, NULL); //77pin + // aic_gpio_input(MOT_LR_BOOTOM_SITE_IO, GPIO_INPUT_NOINT, NULL, NULL); //81pin + + aic_gpo_output(GPO_2,GPO_OUTPUT_LOW );//马达 + aic_gpio_output(GPIO_14,GPIO_OUTPUT_LVL_LOW );//马达 + + aic_gpio_input(MOT_BOOTOM_SITE_IO, GPIO_INPUT_NOINT, NULL, NULL); //80pin + aic_gpio_input(MOT_TOP_SITE_IO, GPIO_INPUT_NOINT, NULL, NULL); //87pin + aic_gpio_input(MOT_MIDDLE_SITE_IO, GPIO_INPUT_NOINT, NULL, NULL); //18pin eiu 4 + + // EIPU_SetPol(NOSEC_MODE, EIPU_DBNC, 4, 2);//配置为反转电平触发 + + + //创建mot_dev_task队列 if(mot_dev_task_queue == NULL) { @@ -261,32 +343,55 @@ void mot_init(void) } void head_drop(void)//低头 { - bk_printf("head_drop"); + //bk_printf("head_drop"); + aic_gpo_output(MOT_LR_EN_FWD_IO,GPO_OUTPUT_HIGH );//马达 + aic_gpio_output(MOT_LR_EN_REV_IO,GPIO_OUTPUT_LVL_LOW );//马达 +} +void head_up(void)//抬头 +{ + // bk_printf("head_up"); + aic_gpo_output(MOT_LR_EN_FWD_IO,GPO_OUTPUT_LOW );//马达 + aic_gpio_output(MOT_LR_EN_REV_IO,GPIO_OUTPUT_LVL_HIGH );//马达 +} + +void head_drop_tb(void)//低头 +{ + // bk_printf("head_drop"); aic_gpo_output(MOT_EN_FWD_IO,GPO_OUTPUT_HIGH );//马达 aic_gpio_output(MOT_EN_REV_IO,GPIO_OUTPUT_LVL_LOW );//马达 } -void head_up(void)//抬头 +void head_up_tb(void)//抬头 { - bk_printf("head_up"); + // bk_printf("head_up"); aic_gpo_output(MOT_EN_FWD_IO,GPO_OUTPUT_LOW );//马达 aic_gpio_output(MOT_EN_REV_IO,GPIO_OUTPUT_LVL_HIGH );//马达 } + + void MTO_stop(void) { bk_printf("MTO_stop"); mot_nod_count=0; mot_MIDDLE_flag = 0; + aic_gpo_output(MOT_LR_EN_FWD_IO,GPO_OUTPUT_LOW );//马达 + aic_gpio_output(MOT_LR_EN_REV_IO,GPIO_OUTPUT_LVL_LOW );//马达 + aic_gpo_output(MOT_EN_FWD_IO,GPO_OUTPUT_LOW );//马达 aic_gpio_output(MOT_EN_REV_IO,GPIO_OUTPUT_LVL_LOW );//马达 + + // aic_gpio_output(GPIO_15,GPIO_OUTPUT_LVL_HIGH); } //马达归位 void MTO_restert(void) { - bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); - bk_printf("MTO_restert:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); - bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_LR_MIDDLE_SITE_IO)); + // bk_printf("MTO_restert:底部IO:%d",EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4)); + // bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_LR_TOP_SITE_IO)); // if(aic_gpio_level_get(MOT_BOOTOM_SITE_IO) == 0)//到低部 // { + //EIPU_GetIndata( + + //void EIU_Get_Level(u32 eiu_id) // head_up();//抬头 // bk_printf("MTO_restert:向上归位"); @@ -302,28 +407,83 @@ void MTO_restert(void) // return; // }else // { - // head_drop();//低头 + + bk_printf("the MTO_restert start "); + if(aic_gpio_level_get(MOT_LR_MIDDLE_SITE_IO) != 0) + head_up();//抬头 // } - int count = 10000; + int count = 2000; while (count--) { // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); // bk_printf("MTO_restert:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); // bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); - if(aic_gpio_level_get(MOT_MIDDLE_SITE_IO) == 0) - break; - else if(aic_gpio_level_get(MOT_BOOTOM_SITE_IO) == 0)//到低部 + if(aic_gpio_level_get(MOT_LR_MIDDLE_SITE_IO) == 0){ + + bk_printf("MTO_restert:检测到中间位置"); + break; + } + + else if(EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4) == 0)//到低部 { head_up();//抬头 - bk_printf("MTO_restert:向上归位"); + // bk_printf("MTO_restert:向上归位"); - }else if(aic_gpio_level_get(MOT_TOP_SITE_IO) == 0)//到顶部 + }else if(aic_gpio_level_get(MOT_LR_TOP_SITE_IO) == 0)//到顶部 { - bk_printf("MTO_restert:向下归位"); + // bk_printf("MTO_restert:向下归位"); head_drop();//低头 } aos_sleep(1); } + + bk_printf("the MTO_restert count33 is %d ",count); + + aos_sleep(50); + aic_gpo_output(MOT_LR_EN_FWD_IO,GPO_OUTPUT_LOW );//马达 + aic_gpio_output(MOT_LR_EN_REV_IO,GPIO_OUTPUT_LVL_LOW );//马达 +} + +void MTO_restert_tb(void) +{ + // bk_printf("MTO_restert_tb:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + // bk_printf("MTO_restert_tb:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + // bk_printf("MTO_restert_tb:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + // if(aic_gpio_level_get(MOT_BOOTOM_SITE_IO) == 0)//到低部 + // { + + bk_printf("the MTO_restert_tb start"); + + if(aic_gpio_level_get(MOT_MIDDLE_SITE_IO) != 0) + head_up_tb();//抬头 + + int count = 2000; + while (count--) + { + // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + // bk_printf("MTO_restert:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + // bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + if(aic_gpio_level_get(MOT_MIDDLE_SITE_IO) == 0){ + + bk_printf("MTO_restert_tb:检测到中间位置"); + break; + } + + else if(aic_gpio_level_get(MOT_BOOTOM_SITE_IO) == 0)//到低部 + { + head_up_tb();//抬头 + // bk_printf("MTO_restert_tb:向上归位"); + + }else if(aic_gpio_level_get(MOT_TOP_SITE_IO) == 0)//到顶部 + { + // bk_printf("MTO_restert_tb:向下归位"); + head_drop_tb();//低头 + } + aos_sleep(1); + } + + bk_printf("the MTO_restert_tb count33 is %d ",count); + aos_sleep(50); aic_gpo_output(MOT_EN_FWD_IO,GPO_OUTPUT_LOW );//马达 aic_gpio_output(MOT_EN_REV_IO,GPIO_OUTPUT_LVL_LOW );//马达 @@ -337,7 +497,7 @@ static void mot_nod3(void)//点头处理 count = 10000; while (count--) { - if(aic_gpio_level_get(MOT_BOOTOM_SITE_IO) == 0)//到顶部 + if(EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4) == 0)//到顶部 break; aos_sleep(1); } @@ -360,7 +520,7 @@ static void mot_nod2(void) count = 10000; while (count--) { - if(aic_gpio_level_get(MOT_TOP_SITE_IO) == 0)//到顶部 + if(aic_gpio_level_get(MOT_LR_TOP_SITE_IO) == 0)//到顶部 break; aos_sleep(1); } @@ -376,32 +536,175 @@ static void mot_nod2(void) } static void mot_nod1(void)//点头处理 { + + + bk_printf("mot_nod1"); + MTO_restert_tb(); + + head_drop();//直接低头 int count = 255; while(count--) { - count = 10000; + count = 2000; while (count--) { - if(aic_gpio_level_get(MOT_BOOTOM_SITE_IO) == 0)//到低部 + //EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4) + //if(aic_gpio_level_get(MOT_BOOTOM_SITE_IO) == 0)//到低部 + if(EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4) == 0)//到低部 break; aos_sleep(1); } + bk_printf("this is MOT_BOOTOM_SITE_IO count11 is %d...\n",count); head_up();//抬头 - count = 10000; + count = 2000; while (count--) { - if(aic_gpio_level_get(MOT_TOP_SITE_IO) == 0)//到顶部 + if(aic_gpio_level_get(MOT_LR_TOP_SITE_IO) == 0)//到顶部 break; + + if(aic_gpio_level_get(MOT_LR_MIDDLE_SITE_IO) == 0){ + + bk_printf("mot_nod1检测到中间位置...\n"); + } + aos_sleep(1); } + + bk_printf("this is MOT_TOP_SITE_IO count22 is %d...\n",count); head_drop(); if(mot_nod_count>0) mot_nod_count--; if(mot_nod_count ==0) break; } - MTO_restert();//回中间 + + MTO_restert();//回中间 + + bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_LR_MIDDLE_SITE_IO)); + bk_printf("MTO_restert:底部IO:%d",EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4)); + bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_LR_TOP_SITE_IO)); + + // bk_printf("MTO_restert:LR底部IO:%d",EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4)); +} + +static void mot_nod5(void)//点头处理 +{ + + + bk_printf("mot_nod5"); + MTO_restert(); + + head_drop_tb();//直接低头 + + int count = 255; + while(count--) + { + count = 1200; + while (count--) + { + //EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4) + if(aic_gpio_level_get(MOT_BOOTOM_SITE_IO) == 0)//到低部 + //f(EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4) == 0)//到低部 + break; + aos_sleep(1); + } + bk_printf("this is MOT_BOOTOM_SITE_IO count11 is %d...\n",count); + head_up_tb();//抬头 + count = 1200; + while (count--) + { + if(aic_gpio_level_get(MOT_TOP_SITE_IO) == 0)//到顶部 + break; + aos_sleep(1); + } + + bk_printf("this is MOT_TOP_SITE_IO count22 is %d...\n",count); + head_drop_tb(); + if(mot_nod_count>0) + mot_nod_count--; + if(mot_nod_count ==0) + break; + } + + MTO_restert_tb();//回中间 + + bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + + bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + + +} + + +void mot_nod_status() +{ + //马达 + bk_printf("MTO_restert:LR中间IO:%d",aic_gpio_level_get(MOT_LR_MIDDLE_SITE_IO)); + bk_printf("MTO_restert:LR顶部IO:%d",aic_gpio_level_get(MOT_LR_TOP_SITE_IO)); + bk_printf("MTO_restert:LR底部eiu 4IO:%d",EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4)); + bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + bk_printf("MTO_restert:底部:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + //触摸屏 + // bk_printf("触摸屏 eiu4:%d",EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4)); + // bk_printf("触摸屏 eiu5:%d",EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 5)); + // bk_printf("触摸屏 eiu7::%d",EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 7)); + // bk_printf("触摸屏 GPIO_AGPIO_1::%d",aic_gpio_level_get(GPIO_AGPIO_1)); + + // bk_printf("触摸屏 GPIO_15::%d",aic_gpio_level_get(GPIO_15)); + + // bk_printf("MTO_restert:LR底部IO:%d",aic_gpio_level_get(MOT_LR_BOOTOM_SITE_IO)); + +} + +void mot_nod_diantou(unsigned char count){ + + static char nod_flag = 0; + nod_flag++; + mot_nod_count = count; + mot_MIDDLE_flag = 1; + mot_dev_MSG_put(NULL,0,MOT_NOD1); +} + +void mot_nod_yaotou(unsigned char count){ + + static char nod_flag = 0; + nod_flag++; + mot_nod_count = count; + mot_MIDDLE_flag = 1; + + bk_printf("mot_nod_yaotou"); + mot_dev_MSG_put(NULL,0,MOT_NOD4); +} + +void mot_nod_ditou(unsigned char count){ + + static char nod_flag = 0; + nod_flag++; + mot_nod_count = count; + mot_MIDDLE_flag = 1; + mot_dev_MSG_put(NULL,0,MOT_NOD2); +} + +void mot_nod_taitou(unsigned char count){ + + static char nod_flag = 0; + nod_flag++; + mot_nod_count = count; + mot_MIDDLE_flag = 1; + mot_dev_MSG_put(NULL,0,MOT_NOD3); +} + +void mot_nod_exp(unsigned char exp,unsigned char count){ + + static char nod_flag = 0; + nod_flag++; + mot_nod_count = count; + mot_MIDDLE_flag = 1; + mot_dev_MSG_put(NULL,0,exp); + } void mot_nod(unsigned char count) @@ -434,13 +737,19 @@ void mot_test(void) static char mot_test_flag = 0; MTO_stop(); aos_sleep(20); - for(int i =0;i<5;i++) + for(int i =0;i<2;i++) { - head_up(); - aos_sleep(1500); + head_up(); + aos_sleep(1500); - head_drop(); - aos_sleep(1500); + + bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_LR_TOP_SITE_IO)); + + head_drop(); + aos_sleep(1500); + + + bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_LR_TOP_SITE_IO)); } MTO_stop(); @@ -457,4 +766,393 @@ void mot_test(void) // aic_gpio_output(MOT_EN_REV_IO,GPIO_OUTPUT_LVL_HIGH );//马达 // bk_printf("AI_KEY2_PRESS 1"); // } +} + +void mot_test_2(void) +{ + + MTO_restert(); + + static char mot_test_flag = 0; + MTO_stop(); + aos_sleep(20); + + head_up_tb(); + //aos_sleep(1500); + + int count = 800; + while (count--) + { + // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + // bk_printf("MTO_restert:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + // bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + if(aic_gpio_level_get(MOT_TOP_SITE_IO) == 0){ + + bk_printf("MTO_restert:检测到中间位置"); + break; + } + + + + aos_sleep(1); + } + + // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_LR_MIDDLE_SITE_IO)); + + // bk_printf("MTO_restert:LR顶部IO:%d",aic_gpio_level_get(MOT_LR_TOP_SITE_IO)); + + // bk_printf("MTO_restert:eiu 4IO:%d",EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4)); + + MTO_stop(); + +} +void mot_test_3(void) +{ + MTO_restert(); + static char mot_test_flag = 0; + MTO_stop(); + aos_sleep(20); + + head_drop_tb(); + int count = 2000; + while (count--) + { + // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + // bk_printf("MTO_restert:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + // bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + if(aic_gpio_level_get(MOT_BOOTOM_SITE_IO) == 0){ + + bk_printf("MTO_restert:检测到中间位置"); + break; + } + + aos_sleep(1); + } + + MTO_stop(); + + +} + +void mot_test_4(void) +{ + MTO_restert_tb(); + static char mot_test_flag = 0; + MTO_stop(); + aos_sleep(20); + + head_drop(); + int count = 2000; + while (count--) + { + // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + // bk_printf("MTO_restert:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + // bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + if(EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4) == 0){ + + bk_printf("MTO_restert:检测到中间位置"); + break; + } + + aos_sleep(1); + } + + MTO_stop(); + + +} + +void mot_test_5(void) +{ + MTO_restert_tb(); + static char mot_test_flag = 0; + MTO_stop(); + aos_sleep(20); + + head_up(); + int count = 2000; + while (count--) + { + // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + // bk_printf("MTO_restert:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + // bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + if(aic_gpio_level_get(MOT_LR_TOP_SITE_IO) == 0){ + + bk_printf("MTO_restert:检测到中间位置"); + break; + } + + aos_sleep(1); + } + + MTO_stop(); + + +} + +void mot_cute(void) +{ + bk_printf("mot_cute"); + MTO_restert_tb(); + MTO_restert(); + +} + + +void mot_chumo_0_0(){ + + bk_printf("mot_angry"); + mot_cute(); + MTO_stop(); + aos_sleep(20); + + head_up_tb(); + + int count = 2000; + while (count--) + { + // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + // bk_printf("MTO_restert:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + // bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + if(aic_gpio_level_get(MOT_TOP_SITE_IO) == 0){ + + bk_printf("MTO_restert:检测到中间位置"); + break; + } + + aos_sleep(1); + } + + MTO_stop(); + + +} + +void mot_chumo_0_1(){ + + mot_nod5(); + +} + + +void mot_chumo_1_0(){ + + bk_printf("mot_chumo_1_0"); + mot_cute(); + MTO_stop(); + aos_sleep(20); + + head_up(); + int count = 2000; + while (count--) + { + // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + // bk_printf("MTO_restert:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + // bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + if(aic_gpio_level_get(MOT_LR_TOP_SITE_IO) == 0){ + + bk_printf("MTO_restert:检测到中间位置"); + break; + } + + aos_sleep(1); + } + + MTO_stop(); +} + +void mot_chumo_1_1(){ + + mot_nod5(); + + +} + + +void mot_chumo_2_0(){ + + bk_printf("mot_chumo_2_0"); + mot_cute(); + MTO_stop(); + aos_sleep(20); + + head_drop(); + int count = 2000; + while (count--) + { + // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + // bk_printf("MTO_restert:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + // bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + + if(EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4) == 0)//到低部 + break; + //if(aic_gpio_level_get(MOT_LR_TOP_SITE_IO) == 0){ + // + // bk_printf("MTO_restert:检测到中间位置"); + // break; + // } + + aos_sleep(1); + } + + MTO_stop(); +} + +void mot_chumo_2_1(){ + + mot_nod1(); + +} + + +void mot_angry(void) +{ + + bk_printf("mot_angry"); + mot_cute(); + MTO_stop(); + aos_sleep(20); + + head_drop(); + int count = 2000; + while (count--) + { + // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + // bk_printf("MTO_restert:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + // bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + if(EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4) == 0){ + + bk_printf("MTO_restert:检测到中间位置"); + break; + } + + aos_sleep(1); + } + + MTO_stop(); + head_drop_tb(); + + count = 2000; + while (count--) + { + // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + // bk_printf("MTO_restert:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + // bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + if(aic_gpio_level_get(MOT_BOOTOM_SITE_IO) == 0){ + + bk_printf("MTO_restert:检测到中间位置"); + break; + } + + aos_sleep(1); + } + + MTO_stop(); + +} + +void mot_laugh(void) +{ + + + bk_printf("mot_laugh"); + mot_cute(); + MTO_stop(); + aos_sleep(20); + head_drop(); + int count = 2000; + while (count--) + { + // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + // bk_printf("MTO_restert:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + // bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + if(EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4) == 0){ + + bk_printf("MTO_restert:检测到中间位置"); + break; + } + + aos_sleep(1); + } + + MTO_stop(); + //bk_printf("mot_nod5"); + head_drop_tb();//直接低头 + count = 255; + while(count--) + { + count = 1200; + while (count--) + { + //EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4) + if(aic_gpio_level_get(MOT_BOOTOM_SITE_IO) == 0)//到低部 + //f(EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4) == 0)//到低部 + break; + aos_sleep(1); + } + bk_printf("this is MOT_BOOTOM_SITE_IO count11 is %d...\n",count); + head_up_tb();//抬头 + count = 1200; + while (count--) + { + if(aic_gpio_level_get(MOT_TOP_SITE_IO) == 0)//到顶部 + break; + aos_sleep(1); + } + + bk_printf("this is MOT_TOP_SITE_IO count22 is %d...\n",count); + head_drop_tb(); + if(mot_nod_count>0) + mot_nod_count--; + if(mot_nod_count ==0) + break; + } + + MTO_restert_tb();//回中间 +} + +void mot_nothappy(void) +{ + + bk_printf("mot_nothappy"); + mot_cute(); + MTO_stop(); + aos_sleep(20); + + head_drop(); + int count = 2000; + while (count--) + { + // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + // bk_printf("MTO_restert:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + // bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + if(EIPU_GetIndata(NOSEC_MODE, EIPU_DBNC, 4) == 0){ + + bk_printf("MTO_restert:检测到中间位置"); + break; + } + + aos_sleep(1); + } + + MTO_stop(); + head_up_tb(); + + count = 2000; + while (count--) + { + // bk_printf("MTO_restert:中间IO:%d",aic_gpio_level_get(MOT_MIDDLE_SITE_IO)); + // bk_printf("MTO_restert:底部IO:%d",aic_gpio_level_get(MOT_BOOTOM_SITE_IO)); + // bk_printf("MTO_restert:顶部IO:%d",aic_gpio_level_get(MOT_TOP_SITE_IO)); + if(aic_gpio_level_get(MOT_TOP_SITE_IO) == 0){ + + bk_printf("MTO_restert:检测到中间位置"); + break; + } + + aos_sleep(1); + } + + MTO_stop(); + } \ No newline at end of file diff --git a/2.code/aicos/app/AI_AMP_2_5/mot_dev.h b/2.code/aicos/app/AI_AMP_2_5/mot_dev.h index bc15320..c26553a 100644 --- a/2.code/aicos/app/AI_AMP_2_5/mot_dev.h +++ b/2.code/aicos/app/AI_AMP_2_5/mot_dev.h @@ -5,6 +5,20 @@ typedef enum mot_dev_MSG MOT_NOD1,//点头1 MOT_NOD2,//点头2 MOT_NOD3,//点头3 + MOT_NOD4,//点头3 + MOT_NOD5,//点头3 + MOT_NOD6,//点头3 + MOT_NOD7,//点头3 + MOT_NOD8,//点头3 + MOT_NOD9,//点头9 + MOT_CM_0_0, + MOT_CM_0_1, + MOT_CM_1_0, + MOT_CM_1_1, + MOT_CM_2_0, + MOT_CM_2_1, + MOT_LEFT, + MOT_RIGHT } mot_dev_MSG_Type; typedef struct { @@ -18,4 +32,17 @@ void MTO_stop(void); void mot_init(void); void mot_nod(unsigned char count); void mot_gpio_handle_cb(void *param); + +void mot_nod_diantou(unsigned char count); + +void mot_nod_taitou(unsigned char count); + +void mot_nod_ditou(unsigned char count); + +void mot_nod_yaotou(unsigned char count); + +void mot_nod_exp(unsigned char exp,unsigned char count); + + +void mot_nod_status(); #endif \ No newline at end of file