From: p15692025051 <846603105@qq.com> Date: Mon, 21 Apr 2025 09:30:47 +0000 (+0800) Subject: 接口修复 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=2ddca27499f233bfbbaf331d1afc8ab5b6c586cb;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 18007f2..b4895da 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 @@ -1,14 +1,5 @@ -/******************************************************************************/ -/* */ -/* Copyright 2023 by AICXTEK TECHNOLOGIES CO.,LTD. All rights reserved. */ -/* */ -/******************************************************************************/ -/** - * DESCRIPTION - * - * This file entry demo apps without GUI for aicos - */ + #define AIC_THIS_FILE 0x888888 #include #include @@ -16,6 +7,7 @@ #include #include "app_msg.h" #include "aic_net_pdp_mgr.h" +#include "aic_network_pcap.h" #include "aic_websocket_client.h" #include "cJSON.h" #include @@ -35,6 +27,7 @@ static aos_thread_id AI_VC_read_task_id = 0; static aos_queue_ptr AI_VC_send_queue = NULL; static aos_thread_id AI_VC_play_task_id = 0; static aos_queue_ptr AI_VC_play_queue = NULL; +static char VC_Play_flag = 0; static aos_thread_id AI_VC_record_task_id = 0; static aos_queue_ptr AI_VC_record_tmp_queue = NULL; WebSocketClient *AI_client_VC = NULL; @@ -222,7 +215,8 @@ static void AI_VC_send_satrt(void) cJSON_AddNumberToObject(outbound_cfg, "volume", 100); cJSON_AddNumberToObject(outbound_cfg, "speech_rate", 0); cJSON_AddNumberToObject(outbound_cfg, "chunk_interval_ms", 50); - cJSON_AddStringToObject(outbound_cfg, "voice", "7468512265134915635"); + cJSON_AddStringToObject(outbound_cfg, "voice", "7426720361733013513"); + cJSON_AddStringToObject(outbound_cfg, "voice", "ICL_zh_female_huoponvhai_tob"); cJSON_AddItemToObject(outbound_attributes, "cfg", outbound_cfg); cJSON_AddItemToObject(payload, "outbound_attributes", outbound_attributes); @@ -230,13 +224,13 @@ static void AI_VC_send_satrt(void) cJSON *inbound_attributes = cJSON_CreateObject(); cJSON_AddStringToObject(inbound_attributes, "provider", "volcengine"); cJSON_AddBoolToObject(inbound_attributes, "disable_vad", 0); - cJSON_AddNumberToObject(inbound_attributes, "vad_silence", 200); + cJSON_AddNumberToObject(inbound_attributes, "vad_silence", 500); // 创建 interrupt_options 对象 cJSON *interrupt_options = cJSON_CreateObject(); - cJSON_AddBoolToObject(interrupt_options, "concatenate_results", 1); - cJSON_AddBoolToObject(interrupt_options, "thinking_time_only", 1); - cJSON_AddBoolToObject(interrupt_options, "keyword_interrupt", 1); + cJSON_AddBoolToObject(interrupt_options, "concatenate_results", true);// 是否在打断后拼接前后的ASR结果 + cJSON_AddBoolToObject(interrupt_options, "thinking_time_only", true);// 是否只在思考时间允许打断 思考时间(ASR结束--->第一帧音频合成) + cJSON_AddBoolToObject(interrupt_options, "keyword_interrupt", false);// 启用打断词功能 (打断词只有在思考以及之后才能打断) // 创建 interrupt_keywords 数组 cJSON *interrupt_keywords = cJSON_CreateArray(); @@ -298,7 +292,8 @@ static int websocket_connect_VC(void) //连接服务器 if(AI_client_VC == NULL) { - AI_client_VC = init_websocket_client("ws://118.145.158.207:22086/vc/coze?is_auth=0",NULL); + //AI_client_VC = init_websocket_client("ws://118.145.158.207:22086/vc/coze?is_auth=0",NULL); + AI_client_VC = init_websocket_client("ws://118.145.158.207:22086/vc/chat?is_auth=0",NULL); } //创建发送线程 if(AI_VC_send_task_id == 0) @@ -417,7 +412,7 @@ static void AI_VC_send_task(void *thread_input)//websocket 发送线程 while(1) { - if(aos_recv_from_queue(AI_VC_send_queue,&AI_VC_send_queue_data,AOS_WAIT_FOREVER) == AOS_SUCCESS) + if(AI_VC_send_queue && aos_recv_from_queue(AI_VC_send_queue,&AI_VC_send_queue_data,AOS_WAIT_FOREVER) == AOS_SUCCESS) { if(AI_client_VC && AI_VC_send_queue_data.data) @@ -426,9 +421,9 @@ static void AI_VC_send_task(void *thread_input)//websocket 发送线程 int ret = send_websocket_message(AI_client_VC,AI_VC_send_queue_data.data,AI_VC_send_queue_data.len, (WebSocketMessageType)AI_VC_send_queue_data.AIC_WEBSOCKET_OPCODE); if(AI_VC_send_queue_data.AIC_WEBSOCKET_OPCODE ==AIC_WEBSOCKET_OPCODE_TEXT_FRAME ) - bk_printf("VCVC:send text ret=%d,len=%d,str=%s",ret,AI_VC_send_queue_data.len,AI_VC_send_queue_data.data); + bk_printf("VCVC:send ret=%d,len=%d,str=%s",ret,AI_VC_send_queue_data.len,AI_VC_send_queue_data.data); // else if(AI_VC_send_queue_data.AIC_WEBSOCKET_OPCODE ==AIC_WEBSOCKET_OPCODE_BINARY_FRAME ) - // bk_printf("VCVC:send bin ret=%d,len=%d",ret,AI_VC_send_queue_data.len); + // bk_printf("VCVC:send ret=%d,len=%d",ret,AI_VC_send_queue_data.len); aic_free(AI_VC_send_queue_data.data); }else { @@ -444,25 +439,29 @@ static void AI_VC_send_task(void *thread_input)//websocket 发送线程 static u8 recv_buff[20*1024]; static void AI_VC_read_task(void *thread_input)//websocket 读线程 { - int result_val=0; + int status; - UINT code; + WebSocketMessageType code; bk_printf("AI_VC_read_task go......"); while (1) { //if(AI_VC_client_websocket_handle!=0) + //bk_printf("AI_VC_read_task ..."); if(AI_client_VC) { memset(recv_buff,0,sizeof(recv_buff)); // status = aic_websocket_recv(AI_VC_client_websocket_handle, recv_buff, sizeof(recv_buff), // &code, AOS_WAIT_FOREVER,&result_val); - status = receive_websocket_message(AI_client_VC,recv_buff,sizeof(recv_buff),(WebSocketMessageType *)&code); + //bk_printf("AI_VC_read_task 1"); + status = receive_websocket_message(AI_client_VC,recv_buff,sizeof(recv_buff),&code); + //bk_printf("AI_VC_read_task 2"); if(status>0) { close_timerout = 60; - if(code == 1)//字符串 + if(code == WS_TEXT)//字符串 { - bk_printf("VCVC:read TEXT:status:%d,code:%d,result_val:%d,data:%s\n",status,code,result_val,recv_buff); + //bk_printf("AI_VC_read_task 3"); + bk_printf("VCVC:read TEXT:status:%d,data:%s\n",status,recv_buff); if(strstr(recv_buff,"\"started\""))//开始 { VC_state = VC_State_Listening; @@ -486,21 +485,27 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 VC_state = VC_State_TTSStart; AI_AMP_MSG_put(0,0,VC_PLAY_START);//打开声音 - }else if(strstr(recv_buff,"\"completed\""))//结束 + }else if(strstr(recv_buff,"\"tts.completed\""))//tts结束 + { + // VC_state = VC_State_TTSData; + // AI_AMP_MSG_put(0,0,VC_PLAY_START);//打开声音 + + } + else if(strstr(recv_buff,"\"completed\""))//结束 { VC_state = VC_State_End;//VC_State_Listening; //AI_AMP_MSG_put(0,0,VC_RECORD_START);//打开录音 } } - else if(code == 2)//二进制 + else if(code == WS_BINARY)//二进制 { //bk_printf("VCVC:read BIN status:%d,code:%d\n",status,code); // if(status<1000) // { // bk_printf("VCVC:read :status:%d,code:%d,result_val:%d,data:%s\n",status,code,result_val,recv_buff); // } - AI_VC_put_play_data(recv_buff,status); + AI_VC_put_play_data(recv_buff,status);//音频调试1 play_data_len+=status; } @@ -527,10 +532,10 @@ static void AI_VC_read_task(void *thread_input)//websocket 读线程 static void AI_VC_put_play_data(char *data,u32 len) { u32 count_tmp = 0; - if(AI_VC_play_queue == NULL) - return; while(1) { + if(AI_VC_play_queue == NULL) + return; aos_get_queue_used_count(AI_VC_play_queue,&count_tmp); if(count_tmp>100)//大于100个缓存 { @@ -570,7 +575,7 @@ static void AI_VC_put_play_data(char *data,u32 len) PUT_PLAY_ERROR: aic_free(AI_VC_play_queue_data.data); } -// char play_tmp_d[66*1024] = {0}; +char play_tmp_d[320] = {0}; // u32 play_tmp_d_len = 0; // #define SAMPLE_RATE 16000 // 采样率,通常为 44100 Hz // #define DURATION 2 // 音频时长,单位为秒 @@ -580,62 +585,48 @@ PUT_PLAY_ERROR: // short bk_audio_data[num_samples+4096]; // 定义音频数据数组 // #include // #include + static void AI_VC_play_task(void *thread_input)//音频播放线程 { int ret=0; //bk_stream_play_start(); AI_VC_audio_queue_t AI_VC_play_queue_data; - // bk_printf("AI_VC_play_task go......"); - // // 生成正弦波音频数据 - // for (int i = 0; i < num_samples; i++) { - // double time = (double)i / SAMPLE_RATE; // 计算当前时间 - // double sample = AMPLITUDE * sin(2 * M_PI * FREQUENCY * time); // 计算当前采样值 - // bk_audio_data[i] = (short)sample; // 将采样值转换为 16 位有符号整数 - // } - // bk_printf("AI_VC_play_task go2......"); - // int count_tmp = 0; - // while(1) - // { - // ret = app_audio_write(APP_AUDIO_TYPE_STREAM_DUPLEX, - // (char *)(bk_audio_data+count_tmp*2048), 4096, AOS_WAIT_FOREVER); - // count_tmp+=1; - // if(count_tmp*2048>= num_samples) - // count_tmp = 0; - // //aos_sleep(1); - // } + while(1) { - if( aos_recv_from_queue(AI_VC_play_queue,&AI_VC_play_queue_data,AOS_WAIT_FOREVER) == AOS_SUCCESS) + if(VC_Play_flag ==1 && AI_VC_play_queue && aos_recv_from_queue(AI_VC_play_queue,&AI_VC_play_queue_data,AOS_NO_WAIT) == AOS_SUCCESS) { - if(AI_client_VC && AI_VC_play_queue_data.data) + if( AI_VC_play_queue_data.data) { - //bk_printf("AI_VC_play_task len=%d",AI_VC_play_queue_data.len); - // memcpy(play_tmp_d+play_tmp_d_len,AI_VC_play_queue_data.data,AI_VC_play_queue_data.len); - // play_tmp_d_len += AI_VC_play_queue_data.len; - // if(play_tmp_d_len > 64*1024) - // { - // ret = app_audio_write(APP_AUDIO_TYPE_STREAM_DUPLEX, - // play_tmp_d, play_tmp_d_len, AOS_WAIT_FOREVER); - // play_tmp_d_len=0; - // } - - - //bk_printf("VCVC:play1 "); - int audio_play_time = AI_VC_play_queue_data.len*1000/32000+1; + // int audio_play_time = AI_VC_play_queue_data.len*1000/32000+1; ret = app_audio_write(APP_AUDIO_TYPE_STREAM_DUPLEX, AI_VC_play_queue_data.data, AI_VC_play_queue_data.len, AOS_WAIT_FOREVER); - //audio_data(AI_VC_play_queue_data.data,AI_VC_play_queue_data.len,20); + //audio_data(AI_VC_play_queue_data.data,AI_VC_play_queue_data.len,20); if (ret < 0) - bk_printf("app_audio_write error, ret=%d,audio_play_time=%d\n", ret,audio_play_time); + bk_printf("app_audio_write error, ret=%d\n", ret); + // for(int i = 0;i<=AI_VC_play_queue_data.len/sizeof(play_tmp_d);i++)//分段写 + // { + // int play_tmp_d_len = sizeof(play_tmp_d); + // memset(play_tmp_d,0,play_tmp_d_len); + + // if(i == AI_VC_play_queue_data.len/sizeof(play_tmp_d))//最后一段 + // { + // play_tmp_d_len = AI_VC_play_queue_data.len - i*play_tmp_d_len; + // } + // memcpy(play_tmp_d,AI_VC_play_queue_data.data+i*play_tmp_d_len,play_tmp_d_len); + // ret = app_audio_write(APP_AUDIO_TYPE_STREAM_DUPLEX, + // play_tmp_d, play_tmp_d_len, AOS_WAIT_FOREVER); + // bk_printf("AI_VC_play_task:write len = %d",play_tmp_d_len); + // } - //ret = bk_stream_play_write(AI_VC_play_queue_data.data,AI_VC_play_queue_data.len); - //bk_printf("VCVC:play2 ret=%d,len=%d ",ret,AI_VC_play_queue_data.len); + aic_free(AI_VC_play_queue_data.data); if(VC_state == VC_State_End) { u32 count_tmp = 0; - aos_get_queue_used_count(AI_VC_play_queue,&count_tmp); + if(AI_VC_play_queue) + aos_get_queue_used_count(AI_VC_play_queue,&count_tmp); bk_printf("VC_State_End:count_tmp = %d",count_tmp); if(count_tmp <= 0 )//播放完了 { @@ -647,10 +638,13 @@ static void AI_VC_play_task(void *thread_input)//音频播放线程 bk_printf("AI_VC_play ERROR:AI_client_VC = %d",AI_client_VC); } - }else + }else//没数据的时候也要写0x00 { - bk_printf("AI_VC_play_task sleep...."); - aos_sleep(1); + //bk_printf("AI_VC_play_task no data "); + memset(play_tmp_d,0,sizeof(play_tmp_d)); + ret = app_audio_write(APP_AUDIO_TYPE_STREAM_DUPLEX, + play_tmp_d, sizeof(play_tmp_d), AOS_WAIT_FOREVER); + } } //app_audio_stop(APP_AUDIO_TYPE_STREAM_DUPLEX, NULL); @@ -679,19 +673,17 @@ void VC_Play_Start(void) AI_VC_play_queue = aos_create_queue("AI_VC_play_queue", sizeof(AI_VC_audio_queue_t), 200); + } - + if(AI_VC_play_queue && AI_VC_play_task_id) + VC_Play_flag = 1; + bk_printf("VC_Play_Start VC_Play_flag =%d!!!!!!!!!!!!",VC_Play_flag); } //关闭音频播放 void VC_Play_End(void) { bk_printf("VC_Play_End!!!!!!!!!!!!"); - //销毁发送线程 - if(AI_VC_play_task_id != 0) - { - aos_delete_thread(AI_VC_play_task_id); - AI_VC_play_task_id = 0; - } + VC_Play_flag = 0; //销毁发送队列 if(AI_VC_play_queue != NULL) { @@ -708,9 +700,10 @@ void VC_Play_End(void) break; } } - aos_delete_queue(AI_VC_play_queue); - AI_VC_play_queue = NULL; + // aos_delete_queue(AI_VC_play_queue); + // AI_VC_play_queue = NULL; } + //app_audio_stop(APP_AUDIO_TYPE_STREAM_DUPLEX, NULL); } @@ -758,14 +751,19 @@ static void AI_VC_record_task(void *thread_input)//录音线程 //bk_printf("AI_VC_record_task 1 "); ret = app_audio_read(APP_AUDIO_TYPE_STREAM_DUPLEX, vrecord_buf, 3200, 1010); - //bk_printf("AI_VC_record_task 2 len = %d,VC_state = %d",ret,VC_state); + // u32 timer_ms = aos_get_tickcount(); + // bk_printf("%d:ret=%d",timer_ms,ret); + if(ret<=0) { //bk_printf("AI_VC_record_task continue len = %d,VC_state = %d",ret,VC_state); aos_sleep(1); continue; } + //AI_VC_put_play_data(vrecord_buf,ret);//音频调试0 audio_data(vrecord_buf,ret,23); + if(AI_VC_record_tmp_queue == NULL) + continue; if(VC_state == VC_State_None)//开启的时候,先缓存音频 { @@ -832,12 +830,7 @@ void VC_record_Start(void) void VC_record_End(void) { bk_printf("VC_record_End!!!!!!!!!!!!"); - //销毁发送线程 - if(AI_VC_record_task_id != 0) - { - aos_delete_thread(AI_VC_record_task_id); - AI_VC_record_task_id = 0; - } + //销毁录音缓存队列 if(AI_VC_record_tmp_queue != NULL) { @@ -854,15 +847,15 @@ void VC_record_End(void) break; } } - aos_delete_queue(AI_VC_record_tmp_queue); - AI_VC_record_tmp_queue = NULL; + // aos_delete_queue(AI_VC_record_tmp_queue); + // AI_VC_record_tmp_queue = NULL; } } static void AI_VC_1S_timeout(void *param) { - bk_msg_printf("VC_END_play_timerout1!!!!!!!!!"); + //bk_msg_printf("AI_VC_1S_timeout 1!!!!!!!!!"); if(close_timerout>0) { close_timerout--; @@ -886,11 +879,16 @@ static void AI_VC_1S_timeout(void *param) { //bk_msg_printf("VC_END_play_timerout1=%d",VC_END_play_timerout); VC_state = VC_State_Listening;//重新开始了 - AI_AMP_MSG_put(0,0,VC_RECORD_START);//开启录音 + //AI_AMP_MSG_put(0,0,VC_RECORD_START);//开启录音 //bk_msg_printf("VC_END_play_timerout2=%d",VC_END_play_timerout); } } - + if(AI_VC_play_queue) + { + int play_queue_count = 0; + aos_get_queue_used_count(AI_VC_play_queue,&play_queue_count); + bk_msg_printf("AI_VC_send_queue:play_queue_count=%d",play_queue_count); + } } void AI_key_press(void) { @@ -940,9 +938,10 @@ void AI_VC_start(void) aic_assert(AI_VC_1S_timer); } VC_record_Start(); - websocket_connect_VC(); + VC_Play_Start();//音频调试1 + websocket_connect_VC();//音频调试1 aos_sleep(5); - AI_VC_send_satrt(); + AI_VC_send_satrt();//音频调试1 close_timerout = 0; } @@ -950,9 +949,61 @@ void AI_VC_Close(void) { bk_printf("AI_VC_Close!!!!!!!!!!!!"); app_audio_stop(APP_AUDIO_TYPE_STREAM_DUPLEX, NULL); + //销毁发送线程 + if(AI_VC_record_task_id != 0) + { + aos_delete_thread(AI_VC_record_task_id); + AI_VC_record_task_id = 0; + } + //销毁录音缓存队列 + if(AI_VC_record_tmp_queue != NULL) + { + char count_t= 200; + AI_VC_audio_queue_t AI_VC_record_tmp_queue_data_t; + while(count_t--)//清空队列数据 + { + if(aos_recv_from_queue(AI_VC_record_tmp_queue,&AI_VC_record_tmp_queue_data_t,AOS_NO_WAIT) == AOS_SUCCESS) + { + if(AI_VC_record_tmp_queue_data_t.data) + aic_free(AI_VC_record_tmp_queue_data_t.data); + } + else{ + break; + } + } + aos_delete_queue(AI_VC_record_tmp_queue); + AI_VC_record_tmp_queue = NULL; + } VC_record_End(); + /*************************************** */ bk_printf("AI_VC_Close1!!!!!!!!!!!!"); + //销毁播放线程 + if(AI_VC_play_task_id != 0) + { + aos_delete_thread(AI_VC_play_task_id); + AI_VC_play_task_id = 0; + } + //销毁发送队列 + if(AI_VC_play_queue != NULL) + { + char count_t= 200; + AI_VC_audio_queue_t AI_VC_play_queue_data_t; + while(count_t--)//清空队列数据 + { + if(aos_recv_from_queue(AI_VC_play_queue,&AI_VC_play_queue_data_t,AOS_NO_WAIT) == AOS_SUCCESS) + { + if(AI_VC_play_queue_data_t.data) + aic_free(AI_VC_play_queue_data_t.data); + } + else{ + break; + } + } + aos_delete_queue(AI_VC_play_queue); + AI_VC_play_queue = NULL; + } VC_Play_End(); + bk_printf("AI_VC_Close2!!!!!!!!!!!!"); websocket_deconnect_VC(); bk_printf("AI_VC_Close3!!!!!!!!!!!!"); @@ -1009,6 +1060,7 @@ static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程 bk_printf("AI_AMP_2_5_init 等待注网..... \n"); aos_sleep(1000); } + aic_network_enable_pdp_nic_capdump();//打开网络调试log char *tts_str = "你好!我是小瑞"; VC_TTS_Play(tts_str);//开启vc播放tts while (1) { 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 8eb726a..e809044 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 @@ -422,7 +422,8 @@ send_websocket_message_ERROR: // 接收 WebSocket 消息,返回读到长度 int receive_websocket_message(WebSocketClient *client, unsigned char *buf,int len,WebSocketMessageType *code) { - + u32 timer_ms = aos_get_tickcount(); + //bk_printf("receive_websocket_message 1 timer_ms=%d\n",timer_ms); unsigned char frame[20]={0}; unsigned char masking_key[4]; unsigned int bytes_received = 0; @@ -440,7 +441,7 @@ int receive_websocket_message(WebSocketClient *client, unsigned char *buf,int l bytes_received = recv(client->sockfd, frame, 1, 0); if (bytes_received <= 0) { if (bytes_received == 0) { - printf("Connection closed by server.\n"); + bk_printf("Connection closed by server.\n"); } else { bk_printf("receive message failed"); } @@ -461,10 +462,12 @@ int receive_websocket_message(WebSocketClient *client, unsigned char *buf,int l break; } } + timer_ms = aos_get_tickcount(); + //bk_printf("receive_websocket_message 2 timer_ms=%d\n",timer_ms); bytes_received = recv(client->sockfd, frame+1, 1, 0); if (bytes_received <= 0) { if (bytes_received == 0) { - printf("Connection closed by server.\n"); + bk_printf("Connection closed by server.\n"); } else { bk_printf("receive message failed"); } @@ -497,6 +500,8 @@ int receive_websocket_message(WebSocketClient *client, unsigned char *buf,int l recv(client->sockfd, buf, len, 0); return -1; } + timer_ms = aos_get_tickcount(); + //bk_printf("receive_websocket_message 3 timer_ms=%d\n",timer_ms); // bk_printf("receive_websocket_message :"); // for(int i = 0;isockfd, buf+bytes_received, payload_len-bytes_received, 0); if(recv_len>0) bytes_received += recv_len; @@ -538,9 +543,9 @@ int receive_websocket_message(WebSocketClient *client, unsigned char *buf,int l } // if (*code == WS_TEXT) { - // printf("Received text message: %.*s\n", (int)payload_len, buf); + // bk_printf("Received text message: %.*s\n", (int)payload_len, buf); // } else if (*code == WS_BINARY) { - // printf("Received binary message of length %zu\n", payload_len); + // bk_printf("Received binary message of length %zu\n", payload_len); // } if (*code == WS_TEXT) @@ -564,6 +569,8 @@ int receive_websocket_message(WebSocketClient *client, unsigned char *buf,int l payload_len = 0; } 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); return payload_len;//parse_frame(buf, bytes_received, buf,code); }