Example #1
0
void dfs_thread_entry(void* parameter)
{

   char *rev_meail;//定义指针,用来保存邮件内容	
  	/******************启动文件系统***************/
		/* init the device filesystem */
		dfs_init();
		elm_init();
		/* mount sd card fat partition 1 as root directory */
		if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
		{
			rt_kprintf("文件系统初始化成功!\n");
		}
		else
			rt_kprintf("文件系统初始化失败!\n");
	

	/*************************初始化LD3320***********************/
			ld3320_gpio_configuration();
			ld3320_nvic_cfg();
			ld3320_spi_init();
			LD_reset();
			nAsrStatus = LD_ASR_NONE;
			bMp3Play=0;
	
		if(wugege_read_ini(sys_ini_name)!=1)
				rt_kprintf("读取系统配置文件失败,语音识别将受到严重影响\n");
				rt_kprintf("读取系统配置文件成功\n");
		 if(PlayDemoSound_mp3(sys_shi_mp3)<0)
	   			rt_kprintf(" 播放初始化音乐失败,请确认是否能使用LD3320!\n");
		  		 rt_kprintf("播放初始化音乐成功!\n");
	 		rt_thread_delay(10);//延迟该线程10ms
			sys_wake=1;
			sys_wake_count=0;
  while(1)
  {
		  	if(RT_EOK==(rt_mb_recv(&mb,(rt_uint32_t*)&rev_meail,RT_WAITING_NO)))
		{
			
			rt_kprintf("接收到邮件,播放音乐%s\r\n",rev_meail);
					 if(PlayDemoSound_mp3(rev_meail)<0)
							rt_kprintf("播放音乐失败%s \r\n",rev_meail);
			rt_kprintf("接收到邮件,播放音乐完毕\r\n");
				//	 *rev_meail=NULL;
			nAsrStatus = LD_ASR_NONE;
		}
			rt_thread_delay(5);//延迟该线程5ms
			while(bMp3Play != 0)
				rt_thread_delay(5);
			switch (nAsrStatus)
			{
			case LD_ASR_RUNING:    //  LD3320芯片正在语音识别中
				break;
		
			case LD_ASR_ERROR:	   //  LD3320芯片发生错误
				break;
		
			case LD_ASR_NONE:	   //  LD3320芯片无动作
			{
				nAsrStatus=LD_ASR_RUNING;
				if (RunASR(sys_wake)==0)	//	启动一次ASR识别流程:ASR初始化,ASR添加关键词语,启动ASR运算
				{
					nAsrStatus = LD_ASR_ERROR;
				}
				break;
			}
			case LD_ASR_FOUNDOK:	//	LD3320芯片识别到语音
			{
	char mp3_name[25];	//mp3文件名缓冲区
	char action[15];
	char ini_name[20];
				int nAsrRes = LD_GetResult();	//	一次ASR识别流程结束,去取ASR识别结果
							if(nAsrRes==49)
							{
							sys_wake=1;
							sys_wake_count=0;
							PlayDemoSound_mp3(sys_shi_mp3);
							rt_kprintf("系统唤醒成功 \n"); 		
							}
							else if(sys_wake)
							{
							get_mps_ini_file(mp3_name,ini_name,action,nAsrRes);
							rt_kprintf("识别用户的mp3名字 %s 配置文件%s 命令%s 原始码%d\r\n",mp3_name,ini_name,action,nAsrRes);
							sys_wake_count=0;
							sys_wake=1;
							deal_action(action);
							 if(PlayDemoSound_mp3(mp3_name)<0)
							rt_kprintf("播放音乐失败%s \r\n",mp3_name);
							if(0!=strcmp(ini_name,sys_ini_name))
								{
									strcpy(sys_ini_name,ini_name);
									rt_kprintf("重新载入配置文件%s \r\n",sys_ini_name);
										if(wugege_read_ini(sys_ini_name)!=1)
									rt_kprintf("读取系统配置文件失败,语音识别将受到严重影响\r\n");
									}
							}
				rt_kprintf("\r\n识别到用户关键字为:%d \r\n",nAsrRes); 	
				nAsrStatus = LD_ASR_NONE;
				break;
			}
			case LD_ASR_FOUNDZERO: //无识别结果
				nAsrStatus = LD_ASR_NONE;
				break;
			default:
				nAsrStatus = LD_ASR_NONE;
				break;
			}
			}
  }
Example #2
0
void App_ASRTask(void *pdata)
{
	unsigned char tempResult;
	unsigned char err;
	unsigned short temp;
#if OS_CRITICAL_METHOD == 3/* Allocate storage for CPU status register      */
	OS_CPU_SR  cpu_sr = 0;
#endif
	(void)pdata;
	while (1)
	{
		if(myRobot.ld3320State.mode==LD_MODE_ASR_RUN)
		{			
			switch(myRobot.ld3320State.state)
			{
				case LD_ASR_RUNING:
					break;
				case LD_ASR_ERROR:		
					break;
				case LD_ASR_NONE:
				{
					myRobot.ld3320State.state=LD_ASR_RUNING;
					if (RunASR()==0)															
					{
						myRobot.ld3320State.state = LD_ASR_ERROR;
					
					}
					break;						 
				}
				case LD_ASR_FOUNDOK:
				{
		
					tempResult = LD_GetResult();											
					switch(tempResult)
					{
						case 0: 	
							break;
						case 1:
							say(myName);
							break;
						case 2:
							say(myPlace);
							break;
						case 3:
							say(yourName);
							break;
						case 4: 
							motorSpeed(20,1,1);
							break;
						case 5: 
							Stop(1);
							break;
						case 6:
							err = f_open(&lis, MUSICLIS_DIR, FA_OPEN_EXISTING | FA_READ );
							if (err == FR_OK)
							{
								//打开成功,开始查找文件
								err = SeekFile(&lis, 47, myRobot.ld3320State.filename, &temp);//查找列表文件,得到文件名,并将其保存至filename中
								if (err == 0)//没有错误就改变音乐播放状态,并发送信号量,表示可以播放.
								{
									myRobot.ld3320State.mp3State = MP3_NEW_PLAY;

									OSSemPost(Mp3TransSem); //再次添加信号量
								}//
								
								//关闭文件
								f_close(&lis);
							
							}
							break;
						case 7: 
							err = f_open(&lis, ACTION_DIR, FA_OPEN_EXISTING | FA_READ );
							if (err == FR_OK)
							{
								err = SeekFile(&lis, 3, myRobot.actionctrl.filename, &temp);
								if (err == 0)
								{
									myRobot.actionctrl.status |= ACTION_START;
									if (temp & ACTION_BASIC)	//如果是基本动作,则将基本动作标志置位
										myRobot.actionctrl.status |= ACTION_BASIC;
									else
										myRobot.actionctrl.status &= ~ACTION_BASIC;
									f_close(&lis);
									OSSemPost(ActionSem);
									//在此添加信号量
								}
							}
							break;
						case 8:	
							err = f_open(&lis, ACTION_DIR, FA_OPEN_EXISTING | FA_READ );
							if (err == FR_OK)
							{
								err = SeekFile(&lis, 4, myRobot.actionctrl.filename, &temp);
								if (err == 0)
								{
									myRobot.actionctrl.status |= ACTION_START;
									if (temp & ACTION_BASIC)	//如果是基本动作,则将基本动作标志置位
										myRobot.actionctrl.status |= ACTION_BASIC;
									else
										myRobot.actionctrl.status &= ~ACTION_BASIC;
									f_close(&lis);
									OSSemPost(ActionSem);
									//在此添加信号量
								}
							}
							break;
						case 9:
							err = f_open(&lis, ACTION_DIR, FA_OPEN_EXISTING | FA_READ );
							if (err == FR_OK)
							{
								err = SeekFile(&lis, 7, myRobot.actionctrl.filename, &temp);
								if (err == 0)
								{
									myRobot.actionctrl.status |= ACTION_START;
									if (temp & ACTION_BASIC)	//如果是基本动作,则将基本动作标志置位
										myRobot.actionctrl.status |= ACTION_BASIC;
									else
										myRobot.actionctrl.status &= ~ACTION_BASIC;
									f_close(&lis);
									OSSemPost(ActionSem);
									//在此添加信号量
								}
							}
							break;
						case 10:
							err = f_open(&lis, ACTION_DIR, FA_OPEN_EXISTING | FA_READ );
							if (err == FR_OK)
							{
								err = SeekFile(&lis, 8, myRobot.actionctrl.filename, &temp);
								if (err == 0)
								{
									myRobot.actionctrl.status |= ACTION_START;
									if (temp & ACTION_BASIC)	//如果是基本动作,则将基本动作标志置位
										myRobot.actionctrl.status |= ACTION_BASIC;
									else
										myRobot.actionctrl.status &= ~ACTION_BASIC;
									f_close(&lis);
									OSSemPost(ActionSem);
									//在此添加信号量
								}
							}
							break;
						case 11:
							err = f_open(&lis, ACTION_DIR, FA_OPEN_EXISTING | FA_READ );
							if (err == FR_OK)
							{
								err = SeekFile(&lis, 32, myRobot.actionctrl.filename, &temp);
								if (err == 0)
								{
									myRobot.actionctrl.status |= ACTION_START;
									if (temp & ACTION_BASIC)	//如果是基本动作,则将基本动作标志置位
										myRobot.actionctrl.status |= ACTION_BASIC;
									else
										myRobot.actionctrl.status &= ~ACTION_BASIC;
									f_close(&lis);
									OSSemPost(ActionSem);
									//在此添加信号量
								}
							}
							break;
						case 12:
							err = f_open(&lis, ACTION_DIR, FA_OPEN_EXISTING | FA_READ );
							if (err == FR_OK)
							{
								err = SeekFile(&lis, 33, myRobot.actionctrl.filename, &temp);
								if (err == 0)
								{
									myRobot.actionctrl.status |= ACTION_START;
									if (temp & ACTION_BASIC)	//如果是基本动作,则将基本动作标志置位
										myRobot.actionctrl.status |= ACTION_BASIC;
									else
										myRobot.actionctrl.status &= ~ACTION_BASIC;
									f_close(&lis);
									OSSemPost(ActionSem);
									//在此添加信号量
								}
							}
							break;
						case 13:
							break;
						case 14:
							break;
						case 15:
							break;
						case 16:
							break;
						case 17:
							break;
						case 18:
							break;
						case 19:
							break;
						default:
							break;
					}
					myRobot.ld3320State.state = LD_ASR_NONE;
					break;
				}
				case LD_ASR_FOUNDZERO:
				default:
					myRobot.ld3320State.state = LD_ASR_NONE;
					break;
			}
		}
	}
}