?? gsm.h
字號:
/* 文 件 名:gsm.h 作 者:丁宏偉 創(chuàng)建時間:2008年10月 修改時間:2008年11月26日 */#ifndef _GSM_H#define _GSM_Htypedef struct { char *cmgf_cmd; char cmgs_cmd[12]; char *len_tpdu; char *addr_smsc; char *obj_tpdu; char *phone; char *use_tpdu; char len_msg[2]; //max = 256 char *unicode_msg; char send_cmd; char *MSG; int len2_tpdu; int len_smsc;}GSM;struct parse{ char phone[15]; char msg[1024]; char date[20]; char head[20]; char len[4]; char stat; char utf8_msg[2048];}msg_all;/*這個函數(shù)的作用是把一個16進制的字符串轉(zhuǎn)換成INT型的整數(shù); */int xatoi(char *p,int n){ int t; int i,j=1,k; int sum=0,v=1; if(!strncmp(p,"0x",2) || !strncmp(p,"0X",2)){//判斷格式是否以0X開頭; i=2;//忽略前導(dǎo)0x; while(p[i] == '0') i++;//忽略前導(dǎo)0; k=n-i;//獲得從第一個不為0的字符個數(shù); while(p[i]!='\0'){ if(p[i]>='0'&& p[i] <= '9'){//判斷p[i]是否為0-9之間的字符; t=p[i]-'0';//將字符轉(zhuǎn)換成ASSIC碼值; } if(p[i]>='A' && p[i] <= 'F'){ t=p[i]-'A'+10; } if(p[i]>='a'&& p[i] <= 'f'){ t=p[i]-'a'+10; } // else printf("False Character !\n"); for(v=1,j=1;j<k;j++) {//K代表位數(shù); v*=16;//V是16進制數(shù)的位權(quán); } sum+=(t*v);//計算出每一位的值; k--;i++;//K--表示從高位到低位; } return sum;/* if(!strncmp(p,"0",1){ } else strcpy(s,p); return atoi(s);*/ }}/* 此函數(shù)的作為是把一個INT型數(shù)轉(zhuǎn)換成16進制的字符串格式; T是一個小于255的INT型數(shù);*/void itoa(int t,char *a,int n){ int l,h; if(t>=256 && t<0){ perror("int value >255 !"); } l=t%16;//獲得T的低4位 h=t/16;//獲得T的高4位 if(h>=10){ a[0]=h%10+'A';//高位大于10 即A-F; }else a[0]=h+'0'; if(l>=10){ a[1]=l%10+'A'; }else a[1]=l+'0'; a[2]='\0';}/*tochar 這個函數(shù)是把接收到的GSM查詢信息分成兩個字符串段;to_head與to_msg;*/int tochar(char *buf,char *to_head,char *to_msg,int *n){ /* --------------------------- -----------------------------*/ static int i=0; int j=0; n[1]+=1; /* --------------------------- -----------------------------*/ if(i==0){ while(buf[i]!='\n') i++; i++; }// getchar(); /* --------------------------- -----------------------------*/ memset(to_head,0,sizeof(to_head)); while(buf[i]!='\n') to_head[j++]=buf[i++]; to_head[j]='\0';// printf("### to_head ###:%s\n",to_head); /* --------------------------- -----------------------------*/ if(!strncmp(to_head,"OK",2)) { printf("短信解碼成功!\n"); n[1]-=1; return i; } /* --------------------------- -----------------------------*/ i++; n[0]=j; j=0;// getchar(); /* --------------------------- -----------------------------*/ memset(to_msg,0,sizeof(to_msg)); while(buf[i]!='\n') to_msg[j++]=buf[i++]; to_msg[j]='\0';// printf("###to_msg###: %s\n",to_msg); /* --------------------------- -----------------------------*/ if(!strncmp(to_msg,"OK",2)) { printf("短信解碼成功!\n"); --(n[1]); return i; } i++; /* --------------------------- -----------------------------*/ return i;}#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -