2、.h>voidmessage(char*mess);pthread_mutex_tmutx;sem_ts1,s2;time_ttimep;intfc;//串口描述符chartime1[14]={};//发送信号中时间字符串年月日时分秒如:2013030117520010chardh0[]="18740585120";//定时发送对方号码chardh1[11]=" ";//自动回复对方号码charcmgl[10]="AT+CMGLr";//读短信指令charcmgs[10]="AT+CMGS=";//写短信指令charmess[22]="FFF
3、FFFFFFFFFFFFFFFFF";//发送信息串voidint_char(char*buf,intt)//int时间转字符串{chars[2];memset(buf,' ',4);if(t<10){buf[0]='0';gcvt((double)t,1,s);strcat(buf,s);}else{gcvt((double)t,2,s);strcpy(buf,s);}}voidtime_char(char*t)//获取系统时间并转为字符串如:20130301175210{charbuf[4];structtm*p;time(&timep);
4、p=localtime(&timep);//取得当地时间gcvt((double)(1900+p->tm_year),4,buf);strcpy(t,buf);//年int_char(buf,(1+p->tm_mon));strcat(t,buf);//月int_char(buf,p->tm_mday);strcat(t,buf);//日int_char(buf,p->tm_hour);strcat(t,buf);//时int_char(buf,p->tm_min);strcat(t,buf);//分int_char(buf,p->tm_sec)
5、;strcat(t,buf);//秒}voidmessage(char*mess)//编辑信息************{intr,l=0,x;charwd[6]=" ";srand(time(0));r=(int)rand();r=(r%100)-30;//取随机数作为当前温度-30~70if(r<0){l++;r=r*-1;x=r;while(x){x=x/10;if(x>0)l++;//l为r的位数,包括负号}mess[0]='-';gcvt((double)r,l,wd);//转字符串memcpy(mess+1,wd,l);mess[l+
6、1]='C';}else{l++;x=r;while(x){x=x/10;if(x>0)l++;//l为r的位数}gcvt((double)r,l,wd);memcpy(mess,wd,l);mess[l]='C';}time_char(time1);memcpy(mess+6,time1,14);//将时间连接到温度后面}voidfason(char*s)//发送函数*******************************************************{charzl[20];charhc[]="r";strcpy(zl
7、,cmgs);strcat(zl,s);//号码连接到AT+CMGS=后面strcat(zl,hc);printf("zl=%s",zl);write(fc,zl,strlen(zl));//写入发送短信指令sleep(1);mess[strlen(mess)]=0x1a;//ctl+zmess[strlen(mess)]='r';//enterputs(mess);write(fc,mess,strlen(mess));//写入(发送)短信内容puts("sendover...");}void*receive(void*s)//接收线程*
8、*****************************************************{intx;charbuf[2