读取无名管道的函数
/*******************************************/
//函数功能:读取管道,获得管道输出内容,查找到有用信息并保存起来
//参数:void
//返回值:void
/********************************************/
#include"main.h"
char time_temp[255];
char *name_cmd;
char name_temp[255];
char position[255];
void the_next_song(){//检测是否到了歌曲的最后,到最后切歌
if(atoi(position)==98){
int fp_lrc=open("./fifo_cmd",O_WRONLY);
N++;
SONGNAME *namecmd;
if(N>10)N=0;//检错
char p[255]="loadfile ";
namecmd=readsongname();//读取歌曲名
while(namecmd!=NULL){
if(namecmd->num==N){
strcat(p,namecmd->songname);
disp_song_name(namecmd);//歌曲名字显示
break;
}
namecmd=namecmd->next;
}
strcat(p,"\n");
write(fp_lrc,p,strlen(p));
TFT_File_Picture(windowLrc, 25, 106, "./picture/title.bmp", 1);
TFT_File_Picture(windowLrc, 216, 189, "./picture/5.bmp", 1);
}
}
/*===============读取管道函数==================*/
void *readpip(){
char str[4096],ptr[4096],*p,*temp;
while(1){
while(1){
bzero(str,sizeof(str));
read(fifo_fd[0],str,sizeof(str));
p=str;
while(*p!='\0'){
char *a = NULL;
if((temp=strstr(p,"ANS_TIME_POSITION="))!=NULL){//时间
p=temp+18;
a = strstr(temp,"\n");
*a = '\0';
strcpy(time_temp,p);
p=a;
}
else if((temp=strstr(p,"ANS_PERCENT_POSITION="))!=NULL){//进度
p=temp+21;
a = strstr(temp,"\n");
*a = '\0';
strcpy(position,p);
//填充进度条,画矩形
TFT_Rectangle(windowHZ,25,88,264,103,PAINT_HOLLOW);
TFT_File_Picture(windowHZ, 25, 88, "./picture/jindu.bmp", 1);
TFT_Rectangle(windowHZ,25,88,atoi(position)*2+25,103,PAINT_SOLID);
TFT_Rectangle(windowHZ,atoi(position)*2+25,105,264,103,PAINT_SOLID);
p=a;
the_next_song();
}
else if((temp=strstr(p,"ANS_FILENAME="))!=NULL){//歌名
p=temp+13;
a = strstr(temp,"\n");
*a = '\0';
strcpy(name_temp,p);
p = a;
}
else if((temp=strstr(p,"Year:"))!=NULL){//年份
p=temp+5;
a = strstr(temp,"\n");
*a = '\0';
printHZ(windowHZ,p,35,136);
p = a;
}
else if((temp=strstr(p,"Artist:"))!=NULL){//艺术家名
p=temp+7;
a = strstr(temp,"\n");
*a = '\0';
}
else if((temp=strstr(p,"Title:"))!=NULL){//歌曲头
p=temp+6;
a = strstr(temp,"\n");
*a = '\0';
printHZ(windowHZ,p,18,120);
}
p++;
}
}
}
}