//接受短信 #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <termios.h> #include <stdio.h> #include <string.h> #include <iconv.h> int decode_pdu(unsigned char *pdu); int init_device(int portfd); int code_convert(const char * srccode,const char * dstcode,const unsigned char * inbuf,unsigned char * outbuf); int main() { int portfd,n; unsigned char cmd[255],msg[255]; unsigned char *pdu,*pdu_end; portfd = open("/dev/ttyS0",O_RDWR); init_device(portfd); sprintf(cmd,"AT+CMGF=0/r"); sleep(1); write(portfd,cmd,strlen(cmd)); sleep(1); tcflush(portfd,TCIOFLUSH); sprintf(cmd,"AT+CMGR=1/r"); write(portfd,cmd,strlen(cmd)); while(n>0) n=read(portfd,msg+n,255); if((pdu=strstr(msg,"+CMGR:"))!=NULL) { pd