#include "aic_srv_tele_ex.h"
#include "power_supply.h"
#include "sysoff.h"
+#include "app_msg.h"
// #include "opus/include/opus.h"
u8 current_card_id = 0;
u8 VC_TTS_PLAY_EVENT = 0;
static char *AI_ASR_str_tmp = NULL;
#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 int login_timer_count = 0;
+static int power_off_count = 60*6*24;
+
// OpusEncoder *opus_encoder_h = NULL;
// OpusDecoder *opus_decoder_h = NULL;
+static void play_file_stop(void);
static struct opus_enc_init_param *opus_encoder_h = NULL;
static struct opus_dec_init_param *opus_decoder_h = NULL;
{
vc_cfg.start_flag = 0xaaaa;
vc_cfg.end_flag = 0xaaaa;
- //vc_cfg.dev_type = DEV_FX1_H;//产品
+ vc_cfg.dev_type = DEV_FX1_H;//产品
vc_cfg.dev_type = DEV_ADS;//奥德赛
//strcpy(vc_cfg.server_ip,"amp.raisound.com");//服务器地址
strcpy(vc_cfg.server_ip,"115.190.94.208:22080");//服务器地址
FILE *fp = NULL;
fp = fopen("C:/VC_cfg.bin","r");
bk_printf("init_VC_cfg:fp:%p",fp);
- //reset_VC_cfg();
+ // if(fp <=0)//没有文件
+ // {
+ // fp = fopen("C:/VC_cfg.bin","a");
+ // bk_printf("init_VC_cfg:没有文件,建立文件fp:%p",fp);
+ // fclose(fp);
+ // fp = fopen("C:/VC_cfg.bin","r");
+ // }
+
+ reset_VC_cfg();
if(fp)
{
int fread_len ;
{
bk_printf("init_VC_cfg:没有配置");
reset_VC_cfg();
+ memset(vc_cfg.dev_pass,0,sizeof(vc_cfg.dev_pass));
}
fclose(fp);
}
}
}
- if(strstr(text,"音量"))
+ if(strstr(text,"音量") || strstr(text,"声音"))
{
if(strstr(text,"加")||(strstr(text,"大")&&!strstr(text,"太")) || (strstr(text,"太小")))
{
cJSON *payload = cJSON_CreateObject();
cJSON_AddStringToObject(payload, "device_id", vc_cfg.dev_imei);
cJSON_AddStringToObject(payload, "user_agent", "AudioClient/1.0");
+ cJSON_AddBoolToObject(payload, "simple_response", FALSE);
if(AI_ASR_str && VAD_time_count !=0 && VAD_time_count <= VAD_TIMEOUT )//时间间隔短,认为是一次对话,加上上一次内容
{
if(strlen(AI_ASR_str)>0)
// 创建 outbound_attributes 对象
cJSON *outbound_attributes = cJSON_CreateObject();
- cJSON_AddStringToObject(outbound_attributes, "provider", "volcengine");
-
+ //cJSON_AddStringToObject(outbound_attributes, "provider", "volcengine");
+ if(vc_cfg.dev_type == DEV_ADS)
+ {
+ cJSON_AddStringToObject(outbound_attributes, "provider", "ads_coze");
+ }else
+ cJSON_AddStringToObject(outbound_attributes, "provider", "volcengine");
// 创建 outbound_attributes 下的 cfg 对象
cJSON *outbound_cfg = cJSON_CreateObject();
cJSON_AddStringToObject(outbound_cfg, "format", "pcm");
cJSON_AddNumberToObject(outbound_cfg, "chunk_interval_ms", 20);
//cJSON_AddStringToObject(outbound_cfg, "voice", "7426720361733013513");
//cJSON_AddStringToObject(outbound_cfg, "voice", "ICL_zh_female_huoponvhai_tob");
+
if(vc_cfg.dev_type == DEV_ADS)
- cJSON_AddStringToObject(outbound_cfg, "voice", "zh_female_mengyatou_mars_bigtts");
+ cJSON_AddStringToObject(outbound_cfg, "voice", "7511638457475710987");
else
cJSON_AddStringToObject(outbound_cfg, "voice", "zh_female_meituojieer_moon_bigtts");
VC_state = VC_State_SpeechIng;
}else if(strstr(recv_buff,"\"asr.result\""))
{
+
//bk_printf("asr.result!!");
char *str_tmp = strstr(recv_buff,"\"content\":\"");
if(str_tmp)
}
}else if(strstr(recv_buff,"\"asr.completed\""))//asr结束
{
+ VC_state = VC_State_ASR_End;
if(AI_ASR_str && AI_ASR_str_tmp)
{
if(VAD_time_count <= VAD_TIMEOUT )//时间间隔短,认为是一次对话,拼接内容
VC_state = VC_State_End;//VC_State_Listening;
//AI_AMP_MSG_put(0,0,VC_RECORD_START);//打开录音
+ }else if(strstr(recv_buff,"\"event\":\"failed\""))//扣子报错
+ {
+ char *str_tmp = NULL;
+
+ str_tmp = strstr(recv_buff,"\"message\":\"");
+ if(str_tmp)
+ {
+ str_tmp+=strlen("\"message\":\"");
+ int count = str_count(str_tmp,'\"');
+ AI_AMP_MSG_put(str_tmp,count,VC_CONNECT_ERROR);
+ }
+
}
+
}
else if(code == WS_BINARY)//二进制
{
//bk_stream_record_start();
int vad_status_t = 0;
+ static char vad_end_flag = 0;
int ret = 0;
bk_printf("AI_VC_record_task go......");
if(app_audio_flag == 0)
param.bit_rate = 0;
play_data_len = 0;
app_audio_flag = 1;
+ bk_printf("AI_VC_record_task app_audio_start 1");
ret = app_audio_start(APP_AUDIO_TYPE_STREAM_DUPLEX, ¶m, bk_audio_start_callback);//初始化音频
bk_printf("app_audio_start ret=%d",ret);
app_logi("AI_VC_record_task app_audio_start ret=%d",ret);
unsigned char *vad_r_tmp = aic_malloc(2560);
while(bk_rb_data_len(VAD_rb_data))//清空缓存数据
{
-
if(vad_r_tmp)
{
+
unsigned int r_len = bk_rb_read(VAD_rb_data,vad_r_tmp,2560);
//AI_VC_send_data(vad_r_tmp,r_len,AIC_WEBSOCKET_OPCODE_BINARY_FRAME);//发送缓冲数据
AI_VC_put_record_data(vad_r_tmp,r_len);//入队缓冲数据
audio_data(vad_r_tmp,r_len,21);
+ }else
+ {
+ bk_printf("VAD:vad_r_tmp alloc ERROR");
}
}
if(vad_r_tmp)
//bk_printf("count_tmp:%d,VC_state:%d",count_tmp,VC_state);
if(count_tmp>0)//有有效录音数据
{
+
if(VC_state >= VC_State_TTSStart)//
{
VC_state = VC_State_None;
break;
}
}
- else if(VC_state == VC_State_Listening )
+ 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)
+ bk_printf("VAD:有数据还没发:VC_state:%d\r\n\r\n",VC_state);
+ // AI_VC_send_audio_create();//发送开始音频
+ // bk_printf("VAD:发送开始音频");
}
-
+ vad_end_flag = 1;
}else//没录音数据
{
- if(VC_state == VC_State_SpeechIng )//开始说话,且没数据
+ if(VAD_status)
+ {
+ bk_printf("VAD2:VC_state:%d",VC_state);
+ }
+ if(VC_state == VC_State_SpeechIng || vad_end_flag ==1)//开始说话,且没数据
{
AI_VC_send_audio_completed();//发送停止音频、、目前还是会有数据下发
bk_printf("VAD:发送停止音频");
bk_printf("VAD:vad_status_t:%d",vad_status_t);
+ vad_end_flag = 0;
}
- VAD_status = 0;
+
}
{
ret = app_audio_write(APP_AUDIO_TYPE_STREAM_DUPLEX,
AI_VC_play_queue_data.data, AI_VC_play_queue_data.len, 2000);
-
- if (ret < 0)
+ //bk_printf("app_audio_write len=%d\n", ret);
+ if (ret <= 0)
+ {
+ aos_sleep(1);
bk_printf("app_audio_write error, ret=%d\n", ret);
+ }
+
aic_free(AI_VC_play_queue_data.data);
if(VC_state == VC_State_End)
{
u32 count_tmp = 0;
- if(AI_VC_play_queue)
- aos_get_queue_used_count(AI_VC_play_queue,&count_tmp);
+
+ 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 )//播放完了
{
//app_logi("app_audio_write0:write 0");
ret = app_audio_write(APP_AUDIO_TYPE_STREAM_DUPLEX,
play_tmp_d, sizeof(play_tmp_d), AOS_WAIT_FOREVER);
+ if (ret <= 0)
+ {
+ aos_sleep(1);
+ bk_printf("app_audio_write error, ret=%d\n", ret);
+ }
// app_logi("app_audio_write3:write 0");
}
int url_len = 0;
if(!url)
return -1;
- url_len =snprintf(url,511,"ws://%s/vc/chat?is_auth=0",vc_cfg.server_ip);
+ int count = 2000;//等待20秒获取token
+ while(count--)
+ {
+ if(strlen(get_token())>=8)
+ break;
+ aos_sleep(10);
+ }
+ if(strlen(get_token())<8)//20秒都没更新tokey
+ {
+ bk_printf("设备登录失败 count:%d",count);
+ dev_authentication_MSG_put(NULL,0,AUT_LOGIN);
+ return - 1;
+ }
+ url_len =snprintf(url,511,"ws://%s/vc/chat?is_auth=1&dt=%s",vc_cfg.server_ip,get_token());
url[url_len] = 0;
- AI_client_VC = init_websocket_client(url,NULL);
bk_printf("连接服务器 url:%s",url);
+ AI_client_VC = init_websocket_client(url,NULL);
+
+ if(!AI_client_VC)
+ {
+ dev_authentication_MSG_put(NULL,0,AUT_LOGIN);
+ bk_printf("连接服务器 失败");
+ return -1;
+ }
+ bk_printf("AI_client_VC:%d",AI_client_VC);
aic_free(url);
}
//创建发送线程
{
AI_VC_send_queue = aos_create_queue("AI_VC_send_queue",
sizeof(AI_VC_send_queue_t),
- 200);
+ 400);
bk_printf("创建发送队列 AI_VC_send_queue:%d",AI_VC_send_queue);
}
//创建读线程
AI_VC_send_queue_data.AIC_WEBSOCKET_OPCODE=AIC_WEBSOCKET_OPCODE;
if(AI_VC_send_queue && AOS_SUCCESS!=aos_send_to_queue(AI_VC_send_queue,&AI_VC_send_queue_data,AOS_NO_WAIT))
{
-
+ bk_printf("AI_VC_send_data :aos_send_to_queue ERROR\n\n");
aic_free(AI_VC_send_queue_data.data);
return AOS_ERROR;
}
return AOS_SUCCESS;
}
+/********************************音频**************************************** */
+//播放本地音频文件,但不能和音频流同时运行
+int play_audio_file(char *file_name)
+{
+ bk_printf("play_audio_file:%s",file_name);
+ AI_AMP_MSG_put(file_name,strlen(file_name)+1,PLAY_AUDIO_FILE);
+
+
+ return 0;
+}
+volatile char app_audio_play_file_stop_flag = 0;
+static int32_t play_audio_file_cb(void *p_param, uint32_t size)
+{
+ app_event_audio_t *p_event = NULL;
+ if(NULL == p_param) {
+ bk_printf("[%s]p_param is NULL.\r\n", __func__);
+ return -1;
+ }
+ p_event = (app_event_audio_t *)(p_param);
+ bk_printf("[%s]event id = %d.\r\n", __func__, p_event->event_id);
+ switch(p_event->event_id)
+ {
+ case APP_EVENT_AUDIO_PLAY_FILE_STOP_SUCC://关闭成功
+ app_audio_play_file_stop_flag = 1;
+ break;
+ case APP_EVENT_AUDIO_PLAY_FILE_STOP_FAIL://关闭失败
+ app_audio_play_file_stop_flag = 1;
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+
+static void play_file_stop(void)
+{
+ app_audio_play_file_stop_flag = 0;
+ app_audio_play_file_stop(play_audio_file_cb);
+ int count = 300;
+ while(count--)
+ {
+ if(app_audio_play_file_stop_flag == 1)
+ break;
+ aos_sleep(1);
+ }
+ bk_printf("play_file_stop:count:%d",count);
+}
+static int play_audio_file_event(char *file_name)
+{
+ bk_printf("play_audio_file_event:\"%s\"",file_name);
+ if(app_audio_flag != 0)
+ {
+ bk_printf("play_audio_file:ERROR.音频资源忙");
+ return -1;
+ }
+ //bk_printf("play_audio_file_event:\"%s\"",file_name);
+ play_file_stop();
+ app_audio_play_file_start(file_name, play_audio_file_cb);
+ return 0;
+}
+void play_file_stream_data(char *file_name)
+{
+ bk_printf("play_file_stream_data:%s",file_name);
+ AI_AMP_MSG_put(file_name,strlen(file_name)+1,PLAY_FILE_STREAM_DATA);
+}
+static int play_file_stream_data_event(char *file_name)
+{
+ //bk_printf("play_file_stream_data:\"%s\"",file_name);
+
+ FILE *fp = NULL;
+ fp = fopen(file_name,"r");
+ bk_printf("play_file_stream_data_event:\"%s\" ,fp =%d",file_name,fp);
+ if(fp)
+ {
+ unsigned char * stream_data = aic_malloc(4096);
+ if(stream_data)
+ {
+ int count = 100;
+ int read_len = 0;
+
+ while(count--)
+ {
+ read_len = fread(stream_data,1,4096,fp);
+ if(read_len>0)
+ {
+ //bk_printf("play_file_stream_data:read_len:%d ",read_len);
+ AI_VC_put_play_data(stream_data,read_len);
+ if(read_len<4096)
+ {
+ break;
+ }
+ }else if(read_len <0)
+ {
+ bk_printf("play_file_stream_data:fread ERROR");
+ break;
+ }else
+ {
+ break;
+ }
+ }
+ play_data_len = 10*1024;//让音频播放起来
+ aic_free(stream_data);
+ }else
+ {
+ bk_printf("play_file_stream_data:aic_malloc ERROR");
+ }
+ fclose(fp);
+ }else
+ return -1;
+ return 0;
+}
static void AI_VC_put_play_data(char *data,u32 len)
{
u32 count_tmp = 0;
if(AI_VC_play_queue)
{
if(AOS_SUCCESS != aos_send_to_queue(AI_VC_play_queue,&AI_VC_play_queue_data,AOS_NO_WAIT))
- goto PUT_PLAY_ERROR;
+ {
+ bk_printf("AI_VC_put_play_data :aos_send_to_queue ERROR\n\n");
+ goto PUT_PLAY_ERROR;
+
+ }
+ //bk_printf("AI_VC_put_play_data:aos_send_to_queue:%d ",len);
}
else
{
if(AOS_SUCCESS != aos_send_to_queue(AI_VC_record_tmp_queue,&AI_VC_record_queue_data,AOS_NO_WAIT))
{
+ bk_printf("AI_VC_put_record_data :aos_send_to_queue ERROR \n\n");
goto PUT_RECORD_ERROR;
}
}
{
AI_VC_record_tmp_queue = aos_create_queue("AI_VC_record_tmp_queue",
sizeof(AI_VC_audio_queue_t),
- 200);
+ 400);
}
//创建VAD回溯缓冲buf
if(vc_cfg.is_VAD == 1 && VAD_rb_data == NULL)
VC_state = VC_State_None;
VC_record_Start() ;
- AI_VC_start();
- int ret = 0;
- ret = audio_play_tone(3,300);//播放提示音,测试用
- app_logi("audio_play_tone ret = %d\r\n",ret);
- aos_sleep(1);
+
+ if(AI_VC_start()==0)
+ {
+ play_file_stream_data("C:/chenggong.pcm");
+ //audio_play_tone(3,300);//播放提示音,测试用,位置不能变,和双向流有冲突
+ //app_logi("audio_play_tone ret = %d\r\n",ret);
+ aos_sleep(1);
+ }
+
+
}
void AI_key_release(void)
{
return 0;
}
-void AI_VC_start(void)
+char AI_VC_start_lock = 0;
+int AI_VC_start(void)
{
- int ret = 0;
+ power_off_count = 6*60*24;//24小时倒计时
+ int ret = 0,status = 0;
+ if(AI_VC_start_lock == 1)
+ goto AI_VC_start_RET;
+ AI_VC_start_lock = 1;
+
bk_printf("AI_VC_start !!!!!!!! ");
+ //play_file_stop();//先关闭一次本地文件音频播放
VC_state = VC_State_None;
app_audio_param_t param;
param.channel = 1;
if(app_audio_flag == 0)
{
app_audio_flag = 1;
- ret = app_audio_start(APP_AUDIO_TYPE_STREAM_DUPLEX, ¶m, bk_audio_start_callback);//初始化音频
- bk_printf("app_audio_start ret=%d",ret);
- app_logi("app_audio_start ret=%d",ret);
+ status = app_audio_start(APP_AUDIO_TYPE_STREAM_DUPLEX, ¶m, bk_audio_start_callback);//初始化音频
+ bk_printf("app_audio_start status=%d",status);
+ app_logi("app_audio_start status=%d",status);
}
VAD_time = 0;
VAD_time_count = 0;
AI_ASR_str = aic_zalloc(AI_ASR_STR_MAX_LEN);
}
- aic_gpio_output(GPIO_25,GPIO_OUTPUT_LVL_HIGH );//led
- aic_gpio_output(GPIO_30,GPIO_OUTPUT_LVL_HIGH );//led
- aic_gpio_output(GPIO_31,GPIO_OUTPUT_LVL_HIGH );//led
- aic_gpio_output(GPIO_GPO_8,GPIO_OUTPUT_LVL_HIGH );//马达
- aic_gpio_output(GPIO_GPO_1,GPIO_OUTPUT_LVL_LOW );//马达
- aic_gpio_output(GPIO_20,GPIO_OUTPUT_LVL_HIGH );//马达
+ // aic_gpio_output(GPIO_25,GPIO_OUTPUT_LVL_HIGH );//led
+ // aic_gpio_output(GPIO_30,GPIO_OUTPUT_LVL_HIGH );//led
+ // aic_gpio_output(GPIO_31,GPIO_OUTPUT_LVL_HIGH );//led
+ // aic_gpio_output(GPIO_GPO_8,GPIO_OUTPUT_LVL_HIGH );//马达
+ // aic_gpio_output(GPIO_GPO_1,GPIO_OUTPUT_LVL_LOW );//马达
+ // aic_gpio_output(GPIO_20,GPIO_OUTPUT_LVL_HIGH );//马达
//app_audio_set_master_volume(8);
- // if (ret) {
- // bk_printf("AI_VC_start app_audio_start error");
- // return;
- // }
+
if(AI_VC_1S_timer == NULL)
{
AI_VC_1S_timer = aos_create_timer("AI_VC_1S_timer",
if(!opus_encoder_h)
{
bk_printf("opus_encoder_h alloc error");
- return ;
+ ret = -1;
+ goto AI_VC_start_RET;
}
opus_encoder_h->channel_cnt = 1;
opus_encoder_h->sample_rate = 16000;
opus_encoder_h->period_ms = OPUS_PERIOD_20_MS;
opus_encoder_h->bitrate = 16000;
- ret = aic_opus_init_encoder(opus_encoder_h);
- if (ret)
+ status = aic_opus_init_encoder(opus_encoder_h);
+ if (status)
{
bk_printf("aic_opus_init_encoder error");
- return ;
+ ret = -1;
+ goto AI_VC_start_RET;
}
//opus_encoder_h = opus_encoder_create(16000, 1, OPUS_APPLICATION_VOIP, &err);
if(!opus_decoder_h)
{
bk_printf("opus_decoder_h alloc error");
- return;
+ ret = -1;
+ goto AI_VC_start_RET;
}
opus_decoder_h->channel_cnt = 1;
opus_decoder_h->sample_rate = 16000;
- ret = aic_opus_init_decoder(opus_decoder_h);
- if (ret)
+ status = aic_opus_init_decoder(opus_decoder_h);
+ if (status)
{
bk_printf("aic_opus_init_decoder error");
- return ;
+ ret = -1;
+ goto AI_VC_start_RET;;
}
//opus_decoder_h = opus_decoder_create(16000, 1, &err);
}
VC_record_Start();
VC_Play_Start();//
- websocket_connect_VC();//
+ if(websocket_connect_VC() !=0)//
+ {
+ AI_VC_Close();
+ play_audio_file("C:/xinhaoruo1.mp3");
+ ret = -1;
+ goto AI_VC_start_RET;
+
+ }
//aos_sleep(5);
AI_VC_send_satrt();//
close_timerout = 0;
+AI_VC_start_RET:
+ AI_VC_start_lock = 0;
+ return ret;
}
-
+char AI_VC_Close_lock = 0;
void AI_VC_Close(void)
{
+ if(AI_VC_Close_lock == 1)
+ return;
+ AI_VC_Close_lock = 1;
int count;
- aic_gpio_output(GPIO_25,GPIO_OUTPUT_LVL_LOW );
- aic_gpio_output(GPIO_30,GPIO_OUTPUT_LVL_LOW );
- aic_gpio_output(GPIO_31,GPIO_OUTPUT_LVL_LOW );
- aic_gpio_output(GPIO_GPO_8,GPIO_OUTPUT_LVL_LOW );
- aic_gpio_output(GPIO_GPO_1,GPIO_OUTPUT_LVL_LOW);
- aic_gpio_output(GPIO_20,GPIO_OUTPUT_LVL_LOW );
+ // aic_gpio_output(GPIO_25,GPIO_OUTPUT_LVL_LOW );
+ // aic_gpio_output(GPIO_30,GPIO_OUTPUT_LVL_LOW );
+ // aic_gpio_output(GPIO_31,GPIO_OUTPUT_LVL_LOW );
+ // aic_gpio_output(GPIO_GPO_8,GPIO_OUTPUT_LVL_LOW );
+ // aic_gpio_output(GPIO_GPO_1,GPIO_OUTPUT_LVL_LOW);
+ // aic_gpio_output(GPIO_20,GPIO_OUTPUT_LVL_LOW );
if(vc_cfg.is_VAD == 1)
{
// 不使用或暂停使用VAD时调用
//app_logi("app_audio_stop1");
if(app_audio_flag == 1)
{
- app_audio_flag = 0;
+
audio_stop_flag = 0;
app_audio_stop(APP_AUDIO_TYPE_STREAM_DUPLEX, bk_audio_stop_callback);//要在销毁线程之后
int audio_count = 300;
break;
aos_sleep(1);
}
+ app_audio_flag = 0;
bk_printf("app_audio_stop2 audio_count:%d",audio_count);
}
if(AI_ASR_str_tmp)
AI_ASR_str =NULL;
}
//app_logi("app_audio_stop2");
-
+
+ AI_VC_Close_lock = 0;
}
+
aos_status AI_AMP_MSG_put(const char *data,u32 len,AI_AMP_MSG_Type MSG_Type)
{
AI_AMP_MSG_queue_t AI_AMP_MSG_queue_data = {0};
AI_AMP_MSG_queue_data.MSG_Type=MSG_Type;
if(AI_AMP_task_queue && AOS_SUCCESS!=aos_send_to_queue(AI_AMP_task_queue,&AI_AMP_MSG_queue_data,AOS_NO_WAIT))
{
+ bk_printf("AI_AMP_MSG_put :aos_send_to_queue ERROR\n\n");
if(!AI_AMP_MSG_queue_data.data)
aic_free(AI_AMP_MSG_queue_data.data);
return AOS_ERROR;
//bk_msg_printf("AI_AMP_MSG_put2 MSG_Type:%d",MSG_Type);
return AOS_SUCCESS;
}
+//每小时更新一次登录
+//每小时更新登录一次的更新定时器
+static void sys_10S_timeout(void *param)
+{
+ // if (sizeof(dev_pass) == 0)
+ // aut_active();//没有密钥走激活
+ // //每小时登录一次
+ // aut_login();
+ login_timer_count++;
+ if(login_timer_count>60*6)
+ {
+ login_timer_count = 0;
+ dev_authentication_MSG_put(NULL,0,AUT_LOGIN);
+ }
+ if(power_off_count>0)
+ {
+ power_off_count--;
+ if(power_off_count == 0)
+ {
+ AI_AMP_MSG_put(NULL,0,POWER_OFF);
+
+ }
+ }
+}
static void AI_AMP_2_5_task(void *thread_input)//做逻辑线程
{
char count = 30;
AI_AMP_MSG_queue_t AI_AMP_msg = {0};
init_VC_cfg();
+
app_audio_set_master_volume(15*vc_cfg.VC_TTS_volume/100);
+ play_audio_file_event("C:/R_POWER_1.mp3");
while(count --)
{
pdp_activated = aic_is_default_pdp_activated();
if(pdp_activated == TRUE)
break;
bk_printf("AI_AMP_2_5_init 等待注网..... \n");
- audio_play_tone(count%10,500);//播放提示音,测试用
+ //audio_play_tone(count%15,500);//播放提示音,测试用
+ //audio_play_tone(3,500);//播放提示音,测试用
aos_sleep(1000);
}
aic_srv_tele_sim_get_iccid_sync(current_card_id,vc_cfg.ICCID);
bk_printf("vc_cfg.ICCID:%s",vc_cfg.ICCID);
dev_authentication_init();
-
+ if(sys_10S_timer == NULL)
+ {
+ sys_10S_timer = aos_create_timer("AI_VC_1S_timer",
+ sys_10S_timeout, &sys_10S_timer,
+ 10000,
+ AOS_AUTO_ACTIVATE, AOS_BE_PERIOD);
+ aic_assert(sys_10S_timer);
+ }
aic_network_enable_pdp_nic_capdump();//打开网络调试log
// while(1)
// {
case PWK_KEY_RELEASE:
pwk_key_release();
break;
+ case PLAY_AUDIO_FILE:
+ play_audio_file_event(AI_AMP_msg.data);
+ break;
+ case PLAY_FILE_STREAM_DATA:
+ play_file_stream_data_event(AI_AMP_msg.data);
+ break;
case AI_PRINTF:
if(AI_AMP_msg.data)
{
unsigned int start_flag;
+ char dev_pass[50];
DEV_TYPE dev_type;//产品
char dev_imei[20] ;
char ICCID[20] ;
int speech_rate;//语速配置
unsigned int vad_silence;//vad断句时间 ms
char VC_TTS_volume;
+
//unsigned
unsigned int end_flag;
AI_KEY_LONG_PRESS,//AI键长按
AI_KEY_LONG_RELEASE,//AI键长按释放
PWK_KEY_RELEASE,//侧键
+ PLAY_AUDIO_FILE,//播放本地音频文件
+ PLAY_FILE_STREAM_DATA,//播放本地文件,用音频流的方式
AI_PRINTF,//打印
} AI_AMP_MSG_Type;
typedef struct
typedef enum
{
VC_State_None=0,
- VC_State_Listening=1,//#听
- VC_State_SpeechStart=2,//#说开始
- VC_State_SpeechIng=3,//#正在说
- VC_State_SpeechEnd=4,//#说结束
- VC_State_RequestToRespond=5 ,//#TTS请求或者chat请求
- VC_State_Thinking=6,//#想(chat)
- VC_State_Responding=7,//#音频播放
- VC_State_TTSStart=8,
- VC_State_TTSData=9,
- VC_State_TTSFinish=10,
- VC_State_TTSEnd=11,
- VC_State_TTSError=12,
- VC_State_DialogError=13,
- VC_State_End=14,
+ VC_State_Listening,//#听
+ VC_State_SpeechStart,//#说开始
+ VC_State_SpeechIng,//#正在说
+ VC_State_SpeechEnd,//#说结束
+ VC_State_ASR_End,//#ASR,识别结束
+ VC_State_RequestToRespond ,//#TTS请求或者chat请求
+ VC_State_Thinking,//#想(chat)
+ VC_State_Responding,//#音频播放
+ VC_State_TTSStart,
+ VC_State_TTSData,
+ VC_State_TTSFinish,
+ VC_State_TTSEnd,
+ VC_State_TTSError,
+ VC_State_DialogError,
+ VC_State_End,
}VC_state_type;
extern VC_state_type VC_state ;
// #define APP_CFG_TASK_STK_SIZE (4096u)
u32 len;
}AI_VC_audio_queue_t;
-void AI_VC_start(void);
+int AI_VC_start(void);
void AI_VC_Close(void);
int bk_printf(const char *format, ...);
void bk_print_hex(u8 *data,int data_len);
//用于定时器打印
int bk_msg_printf(const char *format, ...);
aos_status AI_AMP_MSG_put(const char *data,u32 len,AI_AMP_MSG_Type MSG_Type);
-int bk_get_imei(char *imei);
\ No newline at end of file
+int bk_get_imei(char *imei);
+int save_VC_cfg(void);
+int play_audio_file(char *file_name);
\ No newline at end of file
#include <stdint.h>
#include "alog_api.h"
#include "pwr_key.h"
-
+#include "sysoff.h"
#define LOG_MODULE AMOD_KPC
{
int ret = 0;
int pwr_status = 0;
- kpc_key_array_t key_arr = {0};
+ //kpc_key_array_t key_arr = {0};
memcpy(&pwr_status, para, size);
case AIC_PWR_KEYUP:
bk_msg_printf("AIC_PWR_KEYUP");
AI_AMP_MSG_put(0, 0, PWK_KEY_RELEASE);
+ //play_audio_file("C:/zhengzaiguanji.mp3");
break;
default:
// gx_ups_phy_from_rtc();
// gx_ups_phy_cnt_clr();
+ play_audio_file("C:/zhengzaiguanji.mp3");
bk_msg_printf("bk_to_ups_sync");
+ aos_sleep(4000);
}
void bk_key_init(void)
} else {
aicx_info(0x0202e8, "d", "g_kpc_handle = %d \n", handle); //
}
- int ret = register_pwr_key_monitor("kpc", bk_kpc_pwr_key_handle);//注册电源按键回调
+ register_pwr_key_monitor("kpc", bk_kpc_pwr_key_handle);//注册电源按键回调
sysoff_register_hook(bk_to_ups_sync, AIC_NULL);//注册关机事件
}
#include "mbedtls/cipher.h"
#include "dev_authentication.h"
#include "aic_http_comm.h"
-
-#define kb_malloc aic_malloc
+#include "aic_http_client.h"
+#define bk_malloc aic_malloc
#define bk_free aic_free
-// static char * dev_key = "uKLrChwrxA1LklgBc3VwawYjUkbT3BgX" ;
-// static char * dev_pid = "cqxJZi5CNgzjS3mX21Zw";
+int get_dev_pass_MAX_len(void)//获取设备密码最大长度,注意要防止内存越界
+{
+ return sizeof(vc_cfg.dev_pass);
+}
+void save_dev_pass(char *dev_pass)//保存设备密码,dev_pass字符串
+{
+ memset(vc_cfg.dev_pass,0,sizeof(vc_cfg.dev_pass));
+ strncpy(vc_cfg.dev_pass,dev_pass,get_dev_pass_MAX_len());
+ save_VC_cfg();
+}
+char *get_dev_pass(void)//获取设备密码,字符串的方式,返回字符串长度为0,即没密码
+{
+ return vc_cfg.dev_pass;
+}
+
static char aut_token[50] ={0};
int str_count(char *data,char type)
{
if(strlen(timestamp)>256)
return -4;
char md5_buf[16]={0};
- char *sign_buf = kb_malloc(1024);
+ char *sign_buf = bk_malloc(1024);
if(!sign_buf)
return -10;
char md5_buf[33]={0};
active_md5_sign(dev_id,pid,timestamp,productSecret,md5_buf);
bk_printf("md5_buf:%s",md5_buf);
- ase_encrypt_demo();
+ ase_encrypt_dome();
}
#define AES_BLOCK_SIZE 16
// PKCS5填充
padded_len+=AES_BLOCK_SIZE;
//bk_printf("aes_cbc_pkcs5_encrypt3");
// 复制明文并进行填充
- padded_plaintext = (unsigned char *)kb_malloc(padded_len);
+ padded_plaintext = (unsigned char *)bk_malloc(padded_len);
if (padded_plaintext == NULL) {
ret = MBEDTLS_ERR_CIPHER_ALLOC_FAILED;
bk_printf("Memory allocation failed\n");
goto exit;
}
//bk_printf("aes_cbc_pkcs5_encrypt4 padded_len :%d,input_len:%d",padded_len,input_len);
- aes_data = (unsigned char *)kb_malloc(padded_len);
+ aes_data = (unsigned char *)bk_malloc(padded_len);
if (aes_data == NULL) {
ret = MBEDTLS_ERR_CIPHER_ALLOC_FAILED;
bk_printf("Memory allocation failed\n");
}
// AES/CBC/PKCS5Padding解密
int aes_cbc_pkcs5_decrypt(const char *Base64_str_input,const char* str_key,const char* str_iv,char *output,int *output_len)
- // const unsigned char *key, size_t key_len,
+ // const unsigned char *dev_key, size_t key_len,
// const unsigned char *iv, size_t iv_len,
// const unsigned char *ciphertext, size_t ciphertext_len,
// unsigned char *plaintext, size_t *plaintext_len)
// goto exit;
// }
size_t input_buf_len = strlen(Base64_str_input)+1;
- input_buf = kb_malloc(input_buf_len);
+ input_buf = bk_malloc(input_buf_len);
memset(input_buf,0,input_buf_len);
//bk_printf("mbedtls_base64_decode1:input_buf_len:%d,Base64_str_input:%s",input_buf_len,Base64_str_input);
mbedtls_base64_decode(input_buf, input_buf_len, &input_buf_len, Base64_str_input, strlen(Base64_str_input));
exit:
if(input_buf)
bk_free(input_buf);
- mbedtls_cipher_free(&ctx);
+ //mbedtls_cipher_free(&ctx);
return ret;
}
void ase_encrypt_demo(void)
{
const char *data = "123456789123456789001234567890";
size_t Base64_data_len = strlen(data)*3+32;
- char *Base64_data = kb_malloc(Base64_data_len);
+ char *Base64_data = bk_malloc(Base64_data_len);
memset(Base64_data,0,Base64_data_len);
aes_cbc_pkcs5_encrypt(data,strlen(data),"uKLrChwrxA1LklgBc3VwawYjUkbT3BgX","5555555566666666",Base64_data,&Base64_data_len);
bk_printf("ase_encrypt_dome:aes_cbc_pkcs5_encrypt:len:%d,Base64_data:%s",Base64_data_len,Base64_data);
- char *decrypt_data = kb_malloc(Base64_data_len);
+ char *decrypt_data = bk_malloc(Base64_data_len);
aes_cbc_pkcs5_decrypt(Base64_data,"uKLrChwrxA1LklgBc3VwawYjUkbT3BgX","5555555566666666",decrypt_data,&Base64_data_len);
bk_printf("ase_encrypt_dome:aes_cbc_pkcs5_decrypt:len:%d,decrypt_data:%s",Base64_data_len,decrypt_data);
if(Base64_data)
}
/****************************************************************************** */
-int set_token(char *token)
+
+char * get_token(void)
{
- if(strlen(token)>=sizeof(aut_token))
- {
- bk_printf("ERROR token to0 long");
- return -1;
- }
- memset(aut_token,0,sizeof(aut_token));
- strcpy(aut_token,token);
- return 0;
+ return aut_token;
}
-int get_token(char *token)
-{
- strcpy(token,aut_token);
- token[strlen(aut_token)] = 0;
- return 0;
-
-}
-int32_t SHA1_BLOCK_SIZE = 64;
-int32_t PAD_BLOCK_SIZE = 16;
-int32_t dev_res_timerCount = 0;
-int32_t ud_token_timer_Count = 0;
-int32_t res_error_count = 0;
-int32_t ntptime_flag = 0;
-//激活
-u8 aut_buf[1024];
-// http创建客户端句柄
-u32 http_demo_handle;
-// 设备激活
-char dev_pass_base64[100] ={0};
-char dev_pass[100] ={0};
-char enc_iv[100] = {0};
-char *dev_token = NULL; // token令牌
-char buff[1024];
+
+
+
//激活->登录的密钥
-const char * key = "uKLrChwrxA1LklgBc3VwawYjUkbT3BgX" ;
-//每小时更新登录一次的更新定时器
-static aos_timer_ptr LOGIN_1H_timer = NULL;
+
+const char *dev_pid = "cqxJZi5CNgzjS3mX21Zw";//PID
+const char *dev_key = "uKLrChwrxA1LklgBc3VwawYjUkbT3BgX";//密钥
+
void aut_active(void)//设备激活
{
bk_printf("aut_active");
AIC_HTTPS_CLIENT_INSTANCE *http_client;
char deviceId[20] = {0};
- aic_srv_tele_radio_get_current_slot_imei_sync(deviceId);
- time_t timestamp;
- timestamp = time(NULL);
- bk_printf("2时间戳: %ld\n", (long)timestamp);
- long long timestamp_ms = (long long)timestamp * 1000;
+ char dev_pass_base64[100] ={0};
+ char enc_iv[65] = {0};
+ // http创建客户端句柄
+ u32 aut_active_http_handle = 0;
+ char *aut_buf =NULL;
+ char *json_string =NULL;
+ cJSON *root = NULL;
+ aut_buf = bk_malloc(5*1024);
+ if(aut_buf)
+ memset(aut_buf , 0,5*1024);
+ else
+ goto aut_active_return;
+
+ bk_get_imei(deviceId);
+ time_t timestamp;
+ timestamp = time(NULL);
+ bk_printf("2时间戳: %ld\n", (long)timestamp);
+ long long timestamp_ms = (long long)timestamp * 1000;
char timestamp_str[20] ={0};
// 使用 sprintf 将 long long 类型的时间戳转换为字符串
timestamp_str[ret] =0;
// 打印转换后的字符串形式的时间戳
bk_printf("2时间戳(ms 转换为字符串): %s\n", timestamp_str);
- const char *dev_pid = "cqxJZi5CNgzjS3mX21Zw";//PID
- const char *dev_key = "uKLrChwrxA1LklgBc3VwawYjUkbT3BgX";//密钥
+
char md5_buf[33]={0};
active_md5_sign(deviceId,dev_pid,timestamp_str,dev_key,md5_buf);
const char *signMethod ="MD5";
- //创建客户端实例
- http_demo_handle = aic_https_client_create("HTTP_DEMO_CLIENT_NAME");
- if (http_demo_handle == 0) {
- bk_printf("Failed to create HTTP client instance\n");
- return;
- }
alog_info("http demo start");
//登陆数据
- ulong total_bytes = 100;
+
bk_printf("dev_id:%s timestamp:%s ",deviceId,timestamp_str);
char *sign_url = "http://dmp.raisound.com/bz-api/dev/auth/active";
- int response_result = 1;
u32 response = 0;
- http_demo_handle = aic_http_client_create("HTTP_DEMO_CLIENT_NAME");
- int url_value = aic_process_https_url(http_demo_handle,sign_url,AIC_HTTP_HEAD);
+ //创建客户端实例
+ aut_active_http_handle = aic_http_client_create("HTTP_DEMO_CLIENT_NAME");
+ if (aut_active_http_handle == 0) {
+ bk_printf("Failed to create HTTP client instance\n");
+ goto aut_active_return;
+ }
+ int url_value = aic_process_https_url(aut_active_http_handle,sign_url,AIC_HTTP_HEAD);
bk_printf("url_value:%d",url_value);
- http_client = (AIC_HTTPS_CLIENT_INSTANCE *)http_demo_handle;
+ http_client = (AIC_HTTPS_CLIENT_INSTANCE *)aut_active_http_handle;
http_client->login_info.server_port = 80;
- aic_http_client_connect(http_demo_handle, 5000);
+ aic_http_client_connect(aut_active_http_handle, 5000);
- // 创建JSON对象
- cJSON *root = cJSON_CreateObject();
- if (root == NULL) {
- bk_printf( "Failed to create JSON object\n");
- return ;
- }
-
- // 添加字段
- cJSON_AddStringToObject(root, "deviceId", deviceId);
- cJSON_AddStringToObject(root, "pid", dev_pid);
- cJSON_AddStringToObject(root, "sign", md5_buf);
- cJSON_AddStringToObject(root, "timeStamp", timestamp_str);
- cJSON_AddStringToObject(root, "signMethod", signMethod);
-
- // 生成JSON字符串
- char *json_string = cJSON_Print(root);
- if (json_string == NULL) {
- bk_printf("Failed to print JSON\n");
- cJSON_Delete(root);
- return ;
- }
-
- // 输出JSON
- bk_printf("JSON output: %s\n", json_string);
- aic_https_client_request_initialize(http_demo_handle,AIC_HTTPS_METHOD_PUT, strlen(json_string),
- 0, NULL,NULL, 10000);
- aic_https_client_request_header_add(http_demo_handle,"Content-Type",strlen("Content-Type"),"application/json",strlen("application/json"),10000);//添加头
+ // 创建JSON对象
+ root = cJSON_CreateObject();
+ if (root == NULL) {
+ bk_printf( "Failed to create JSON object\n");
+ goto aut_active_return; ;
+ }
+
+ // 添加字段
+ cJSON_AddStringToObject(root, "deviceId", deviceId);
+ cJSON_AddStringToObject(root, "pid", dev_pid);
+ cJSON_AddStringToObject(root, "sign", md5_buf);
+ cJSON_AddStringToObject(root, "timeStamp", timestamp_str);
+ cJSON_AddStringToObject(root, "signMethod", signMethod);
+
+ // 生成JSON字符串
+ json_string = cJSON_Print(root);
+ if (json_string == NULL) {
+ bk_printf("Failed to print JSON\n");
+ //cJSON_Delete(root);
+ goto aut_active_return;
+ }
+
+ // 输出JSON
+ bk_printf("JSON output: %s\n", json_string);
+ aic_https_client_request_initialize(aut_active_http_handle,AIC_HTTPS_METHOD_PUT, strlen(json_string),
+ 0, NULL,NULL, 10000);
+ aic_https_client_request_header_add(aut_active_http_handle,"Content-Type",strlen("Content-Type"),"application/json",strlen("application/json"),10000);//添加头
bk_printf("aic_https_client_request_header_add");
response = nx_web_http_client_request_send(http_client->https_client,10 * 1000);
http_client->https_client->nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_PUT;
- ret = aic_https_client_put_data(http_demo_handle, json_string, strlen(json_string),
- 1000);
- if (ret == 0) {
- bk_printf("数据发送成功\n");
-
- } else {
- // 处理错误
- bk_printf("数据发送失败,错误码: %d\n", ret);
- }
- memset(aut_buf , 0,sizeof(aut_buf));
- aic_https_client_response_data_get(http_demo_handle,aut_buf,sizeof(aut_buf),1000);
-
- bk_printf("http put data :%s",aut_buf);
- char *str_tmp = NULL;
- str_tmp = strstr(aut_buf,"\"password\":\"");
- //bk_printf("str_tmp:%p",str_tmp);
- if(str_tmp)//解析password
+ ret = aic_https_client_put_data(aut_active_http_handle, json_string, strlen(json_string),
+ 1000);
+ if (ret == 0) {
+ bk_printf("数据发送成功\n");
+
+ } else {
+ // 处理错误
+ bk_printf("数据发送失败,错误码: %d\n", ret);
+ goto aut_active_return;
+ }
+
+ long read_bytes = aic_https_client_response_data_get(aut_active_http_handle,aut_buf,5*1024,10000);
+ if(read_bytes<=0)
+ goto aut_active_return;
+ bk_printf("http put data :%s",aut_buf);
+ char *str_tmp = NULL;
+ str_tmp = strstr(aut_buf,"\"password\":\"");
+ //bk_printf("str_tmp:%p",str_tmp);
+ if(str_tmp)//解析password
+ {
+ str_tmp += strlen("\"password\":\"");
+ int count = str_count(str_tmp,'\"');
+ bk_printf("count:%d",count);
+ if(count < sizeof(dev_pass_base64))
{
- str_tmp += strlen("\"password\":\"");
- int count = str_count(str_tmp,'\"');
- bk_printf("count:%d",count);
- if(count < sizeof(dev_pass_base64))
- {
- memcpy(dev_pass_base64,str_tmp,count);
- dev_pass_base64[count] = 0;
- bk_printf("dev_pass_base64:%s",dev_pass_base64);
-
- }else
- {
- bk_printf("激活获取base64失败");
- }
+ memcpy(dev_pass_base64,str_tmp,count);
+ dev_pass_base64[count] = 0;
+ bk_printf("dev_pass_base64:%s",dev_pass_base64);
+
+ }else
+ {
+ bk_printf("激活获取base64失败");
}
- str_tmp = NULL;
- str_tmp = strstr(aut_buf,"\"nonce\":\"");
- if(str_tmp)//nonce
+ }
+ str_tmp = NULL;
+ str_tmp = strstr(aut_buf,"\"nonce\":\"");
+ if(str_tmp)//nonce
+ {
+ str_tmp += strlen("\"nonce\":\"");
+ int count = str_count(str_tmp,'\"');
+ if(count < sizeof(enc_iv))
{
- str_tmp += strlen("\"nonce\":\"");
- int count = str_count(str_tmp,'\"');
- if(count < sizeof(enc_iv))
- {
- memcpy(enc_iv,str_tmp,count);
- enc_iv[count] = 0;
- bk_printf("nonce:%s",enc_iv);
-
- }else
- {
- bk_printf("激活获取base64失败");
- }
+ if(count>=sizeof(enc_iv))
+ count = sizeof(enc_iv)-1;
+ memcpy(enc_iv,str_tmp,count);
+ enc_iv[count] = 0;
+ bk_printf("nonce:%s",enc_iv);
+
+ }else
+ {
+ bk_printf("激活获取nonce失败");
}
- int dev_pass_len = sizeof(dev_pass);
+ }
+ int dev_pass_len = get_dev_pass_MAX_len();
+ char *dev_pass = bk_malloc(dev_pass_len);
+ if(dev_pass)
+ {
+ memset(dev_pass,0,dev_pass_len);
if(strlen(enc_iv)>8 && strlen(dev_pass_base64)>8)
{
- aes_cbc_pkcs5_decrypt(dev_pass_base64, key, enc_iv,dev_pass,&dev_pass_len);//解密
+ aes_cbc_pkcs5_decrypt(dev_pass_base64, dev_key, enc_iv,dev_pass,&dev_pass_len);//解密
dev_pass[dev_pass_len] = 0;
bk_printf("dev_pass:%s dev_pass_len:%d",dev_pass,dev_pass_len);
+ save_dev_pass(dev_pass);//保存设备密钥
}
+ bk_free(dev_pass);
+ }else
+ {
+ bk_printf("dev_pass malloc error!!!!!!!!!!!");
+ }
+
+
- // 释放内存
- free(json_string);
- cJSON_Delete(root);
- aic_http_client_delete(http_demo_handle);
+aut_active_return:
+ // 释放内存
+ if(aut_buf)
+ bk_free(aut_buf);
+ if(json_string)
+ cJSON_free(json_string);
+ if(root)
+ cJSON_Delete(root);
+ if(aut_active_http_handle)
+ aic_http_client_delete(aut_active_http_handle);
}
void aut_login(void)//登录
{
bk_printf("dev_sign_in 1");
- char *token = dev_token; // 中间变量 处理变化的token值
+ char *dev_pass = get_dev_pass();
AIC_HTTPS_CLIENT_INSTANCE *http_client;
bk_printf("dev_sign_in 2");
- // int read = fmd_read(password_handle, 0, 1024, dev_pass); // 将密码读到dev_pass
- // fmd_close(password_handle);//关闭
- // if (read == 0)
- // bk_printf("read OK");
- // else
- // bk_printf("read worse");
-
- if (token == NULL)
- token = "";
- if (sizeof(dev_pass) == 0) // 没有密码
+ int count = 5;
+ char *encrypt_data = NULL;
+ char *response_data =NULL;
+ int aut_login_http_handle = 0;
+ char enc_iv[17]={0};
+ char *json_string = NULL;
+ while(count--)//没有密钥的情况下,尝试重新激活,最多尝试5次
+ {
+ if (strlen(dev_pass) <8) // 没有密码,走激活
+ {
+ aut_active();
+ }else
+ {
+ break;
+ }
+ }
+ if(count == 0 && strlen(dev_pass) <8)
+ {
+ bk_printf("无密码,登录失败");
return;
+ }
+
bk_printf("sign_in PASSWORD OK");
// 随机生成16个字符串 设备生成做加密使用
//char *random_string= generate_random_string(); // 随机的16个字符串
/**
* password, productSecret, nonce utJMIAPRN1E81DzSDVigh/f0ZmHQdBgdAGZ/DhkPJ/s= uKLrChwrxA1LklgBc3VwawYjUkbT3BgX qgofeplofqeoadha
*/
- char encrypt_data[400] = {0};
- int encrypt_data_len = sizeof(encrypt_data);
-
-
+ int encrypt_data_len = 512;
+ encrypt_data = bk_malloc(encrypt_data_len);
// 登录数据
char deviceId[20] = {0};
- aic_srv_tele_radio_get_current_slot_imei_sync(deviceId);
+ //aic_srv_tele_radio_get_current_slot_imei_sync(deviceId);
+ bk_get_imei(deviceId);
time_t timestamp;
timestamp = time(NULL);
bk_printf("2时间戳: %ld\n", (long)timestamp);
memset(enc_iv,'1',16);
memcpy(enc_iv,timestamp_str,strlen(timestamp_str));
enc_iv[16] = 0;
- aes_cbc_pkcs5_encrypt(dev_pass, strlen(dev_pass), key, enc_iv,encrypt_data,&encrypt_data_len);//加密
+ 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 *headers_T = "\"Content-Type\":\"application/json\"";
- int response_result = 1;
+ //char *headers_T = "\"Content-Type\":\"application/json\"";
u32 response = 0;
- http_demo_handle = aic_http_client_create("HTTP_DEMO_CLIENT_NAME");
- int url_value = aic_process_https_url(http_demo_handle,sign_url,AIC_HTTP_HEAD);
+ aut_login_http_handle = aic_http_client_create("HTTP_DEMO_CLIENT_NAME");
+ int url_value = aic_process_https_url(aut_login_http_handle,sign_url,AIC_HTTP_HEAD);
bk_printf("url_value:%d",url_value);
- http_client = (AIC_HTTPS_CLIENT_INSTANCE *)http_demo_handle;
+ http_client = (AIC_HTTPS_CLIENT_INSTANCE *)aut_login_http_handle;
http_client->login_info.server_port = 80;
- aic_http_client_connect(http_demo_handle,5000);
+ aic_http_client_connect(aut_login_http_handle,5000);
//这里需要发送数据
// 创建JSON对象
cJSON *root = cJSON_CreateObject();
if (root == NULL)
{
bk_printf("Failed to create JSON object\n");
- return ;
+ goto aut_login_renurn ;
}
// 添加字段
cJSON_AddStringToObject(root, "deviceId", deviceId);
cJSON_AddStringToObject(root, "password", encrypt_data);
cJSON_AddStringToObject(root, "nonce", enc_iv);
// 生成JSON字符串
- char *json_string = cJSON_Print(root);
+ json_string = cJSON_Print(root);
if (json_string == NULL)
{
bk_printf( "Failed to print JSON\n");
- cJSON_Delete(root);
- return ;
+ //cJSON_Delete(root);
+ goto aut_login_renurn ;
}
bk_printf("json_string:%s",json_string);
- aic_https_client_request_initialize(http_demo_handle,AIC_HTTPS_METHOD_POST, strlen(json_string),
+ aic_https_client_request_initialize(aut_login_http_handle,AIC_HTTPS_METHOD_POST, strlen(json_string),
0, NULL,NULL, 10000);
- aic_https_client_request_header_add(http_demo_handle,"Content-Type",strlen("Content-Type"),"application/json",strlen("application/json"),10000);//添加头
+ aic_https_client_request_header_add(aut_login_http_handle,"Content-Type",strlen("Content-Type"),"application/json",strlen("application/json"),10000);//添加头
bk_printf("aic_https_client_request_header_add");
- // response = aic_http_client_post_start(http_demo_handle, sign_url,
+ // response = aic_http_client_post_start(aut_login_http_handle, sign_url,
// NULL, NULL, 80, NULL,10 * 1000);
response = nx_web_http_client_request_send(http_client->https_client,10 * 1000);
+ if (response != NX_SUCCESS)
+ {
+ bk_printf( "nx_web_http_client_request_send error");
+ goto aut_login_renurn ;
+ }
http_client->https_client->nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_POST;
- int flag = aic_https_client_put_data(http_demo_handle,json_string,strlen(json_string),1000);
+ int flag = aic_https_client_put_data(aut_login_http_handle,json_string,strlen(json_string),1000);
if (flag == 0)
bk_printf( "Put_data_OKK");
else
bk_printf( "Put_data_FAIL");
- if (response == 1) // 出现异常
- response_result = 0;
- if (response_result == 1)
+
+ if (response == 0)
{
- u32 lbytes = aic_https_client_response_data_get(http_demo_handle, buff, 1024*2,
- 10 * 1024);
- bk_printf("LOGIN:%s",buff);
+ response_data = bk_malloc(1024*5);
+ if( response_data)
+ {
+ long read_bytes = aic_https_client_response_data_get(aut_login_http_handle, response_data, 1024*5,
+ 10000);
+ if(read_bytes<=0)
+ goto aut_login_renurn;
+ bk_printf("LOGIN:%s",response_data);
+ char *str_tmp = NULL;
+ str_tmp = strstr(response_data,"\"token\":\"");
+ if(str_tmp)//nonce
+ {
+ str_tmp += strlen("\"token\":\"");
+ int count = str_count(str_tmp,'\"');
+
+ if(count>=sizeof(aut_token)-1)
+ count = sizeof(aut_token)-1;
+ memcpy(aut_token,str_tmp,count);
+ aut_token[count] = 0;
+ bk_printf("aut_token:%s",aut_token);
+
+ }
+ }else
+ {
+ bk_printf("response_data alloc error!!!!!!!!!");
+ }
+
}
// 释放内存
- free(json_string);
- cJSON_Delete(root);
- if (response != NX_SUCCESS)
- {
- aic_http_client_delete(http_demo_handle);
- return;
- }
+aut_login_renurn:
+ if(json_string)
+ cJSON_free(json_string);
+ if(root)
+ cJSON_Delete(root);
+ if(aut_login_http_handle)
+ aic_http_client_delete(aut_login_http_handle);
+ if(encrypt_data)
+ bk_free(encrypt_data);
+ if(response_data)
+ bk_free(response_data);
+
}
-void aut_chack_token(void)//检查token
-{
+// void aut_chack_token(void)//检查token
+// {
-}
+// }
+
-//每小时更新一次登录
-static void LOGIN_1H_timeout(void *param)
-{
- if (sizeof(dev_pass) == 0)
- aut_active();//没有密钥走激活
- //每小时登录一次
- aut_login();
-}
static aos_thread_id dev_authentication_id = 0;
static aos_queue_ptr dev_authentication_task_queue = NULL;
//鉴权消息发送
static void dev_authentication_task(void *thread_input)//鉴权逻辑线程
{
dev_authentication_MSG_queue_t dev_authentication_msg = {0};
- ase_encrypt_demo();
+ //ase_encrypt_demo();
//dev_NTP();//获取时间
- aut_active();//激活
+ //aut_active();//激活
aut_login();//登录
- if(LOGIN_1H_timeout == NULL)
- {
- LOGIN_1H_timer = aos_create_timer("AI_VC_1S_timer",
- LOGIN_1H_timeout, &LOGIN_1H_timer,
- 1000*60,
- AOS_AUTO_ACTIVATE, AOS_BE_PERIOD);
- aic_assert(LOGIN_1H_timer);
- }
+
/**
* 原来已激活过了...AuthVo(password=rPbSCNTIVYWKso6I5+6l0KIbSiIembg3p10IEny2UVg=, deviceId=860132061481751, nonce=xiRqXDqkqGFodIiw)
case AUT_LOGIN://登录
aut_login();
break;
- case AUT_CHACK_TOKEN://检查token
- aut_chack_token();
- break;
+ // case AUT_CHACK_TOKEN://检查token
+ // aut_chack_token();
+ // break;
}
if(dev_authentication_msg.data)
aic_free(dev_authentication_msg.data);
//激活用的md5签名
int active_md5_sign(const char *dev_id,const char *pid,const char *timestamp,const char *productSecret,char*md5_str);
int str_count(char *data,char type);
+char * get_token(void);
typedef enum dev_authentication_MSG
{
AUT_ACTIVE,//激活
AUT_LOGIN,//登录
- AUT_CHACK_TOKEN//检查令牌
+ //AUT_CHACK_TOKEN//检查令牌
} dev_authentication_MSG_Type;
typedef struct
u32 len;
dev_authentication_MSG_Type MSG_Type;
}dev_authentication_MSG_queue_t;
+aos_status dev_authentication_MSG_put(const char *data,u32 len,dev_authentication_MSG_Type MSG_Type);
#endif
\ No newline at end of file
35,
AOS_AUTO_START);
}
-
+ return 0;
}
int bk_stream_play_write(char *data ,u32 len)
{
config FS_LFS_IMAGE_GEN_SIZE
int "Size of gernerated lfs image"
- default 65536
+ default 737280
depends on FS_LFS_IMAGE_GEN
help
Size of the LFS image in bytes.
+++ /dev/null
-1234567890
\ No newline at end of file
PMU_UNIT_INFO_OPS(VDDTCXO,VBAT, REG_GLB_PD_LDO6_CFG_REG, BIT_GLB_PD_LDO_VSEL_REG(0x1F, 0x1F),
REG_PMU_RTC_LDO6_BOUND_REG, BIT_PMU_RTC_BUCK_LDO_POWER_DOWN_REG,
REG_PMU_RTC_DCDC_LDO_CFG_UPDATE_REG, BIT_PMU_RTC_BUCK_LDO_POWER_DOWN_REG,
- 1600000, 1987500, 12500, GP201_SCALING_SETTLING_TIME, GP201_PD_SETTLING_TIME, true, true, true, &gp202_pmu_ldo_gen_ops, 0),
+ 1600000, 1987500, 12500, GP201_SCALING_SETTLING_TIME, GP201_PD_SETTLING_TIME, true, true, false, &gp202_pmu_ldo_gen_ops, 0),
#else
CONFIG_SOUND_SUPPORT=y
# CONFIG_SOUND_AIC_CODEC is not set
# CONFIG_SOUND_STREAM_IPC is not set
+CONFIG_SND_STREAM_VOICE_MIX=y
# CONFIG_SOUND_CODEC_ES8374 is not set
CONFIG_SOUND_CODEC_ES8311=y
CONFIG_SOUND_CODEC_ES8311_1V8=y
CONFIG_FS_LITTLEFS_RW_SIZE=256
CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE=32
CONFIG_FS_LITTLEFS_BLOCK_CYCLES=512
-# CONFIG_FS_LFS_IMAGE_GEN is not set
+CONFIG_FS_LFS_IMAGE_GEN=y
+CONFIG_FS_LFS_IMAGE_GEN_SIZE=737280
#
# File System AT Config
#define __PMIC_MISC_CFG_H__
#define VBAT_SHUTDOWN_VAL_MV 2900
-#define PWR_KEY_ANTI_SHAKE_TIME_MS 0
+#define PWR_KEY_ANTI_SHAKE_TIME_MS 500
/*long press reset timg 2/4/6/8/10/12/14 s */
#define LONG_PRESS_RESET_TIME 8
//#define CONFIG_STOP_CHARGER
}
},
"C": {
- "block_num": 20,
+ "block_num": 180,
"attribute": "RW"
},
"normdata": {
"block_num": 1,
"attribute": "RW"
},
- "ivTTS_irf": {
- "block_num": 160,
- "attribute": "RW"
- },
"ptable": {
"block_num": 1,
"attribute": "RW"
"description": "calibration data partition"
},
"C": {
- "flash_type": "qspi_nor",
- "description": "fs C disk data partition"
+
+ "flag":1,
+ "select":1,
+ "bin_path": "ap/bin/aicos_fs.bin",
+ "flash_type":"qspi_nor",
+ "description":"fs image"
},
"normdata": {
"backup": 2,
"flash_type": "qspi_nor",
"description": "factory backup station partition"
},
- "ivTTS_irf": {
- "flag": 1,
- "select": 1,
- "bin_path": "ap/bin/ivTTS_irf.bin",
- "flash_type": "qspi_nor",
- "description": "ivTTS irf partition"
- },
"ptable": {
"flash_type": "qspi_nor",
"description": "partition table"