?? m32.lst
字號(hào):
771 4
772 4
773 4 }//if((ptr=strstr(task,"A")) != NULL)
774 3 }//if(gsmSearchPhone("M"))
775 2 else
776 2 {
777 3
778 3 sprintf(TP_UD,"You are not master!");
779 3 return 0;
780 3
781 3
782 3 }
783 2
784 2
785 2 }//if(task[0] == 'A')
786 1
C51 COMPILER V7.50 M32 04/04/2007 15:01:44 PAGE 14
787 1 if(task[0] == 'B') //設(shè)置第二個(gè)受權(quán)號(hào)碼
788 1 {
789 2 //if(gsmPhoneBookTask(GSM_SEARCH_PHONE,NULL,"A",0))
790 2 if(gsmSearchPhone("A")) //是否有第一個(gè)受權(quán)號(hào)碼?
791 2 {
792 3 if((ptr=strstr(task,"B")) != NULL)
793 3 {
794 4 //增加授權(quán):
795 4
796 4 ptr++;
797 4 putstring1("Phone Number to Save:\r\n");
798 4 putstring1(ptr);
799 4 putstring1("\r\n");
800 4 PhoneNumber=3;
801 4 //if(gsmPhoneBookTask(GSM_SAVE_PHONE,ptr,"M",PhoneNumber))
802 4 if(gsmSavePhone(ptr,"B")==TRUE) //第2個(gè)授權(quán),起名為:B
803 4 {
804 5
805 5 putstring1("Save Phone Ok,Number is:\r\n");
806 5 sprintf(TPA,"++");
807 5 strcat(TPA, ptr);
808 5 putstring1(TPA);
809 5 putstring1("\r\n");
810 5
811 5 sprintf(TP_UD,"OK");
812 5
813 5 return 1; //gsmSendMessage("OK");
814 5
815 5 }
816 4 else
817 4 {
818 5 putstring1("Save Phone Fail!");
819 5 sprintf(TP_UD,"Fail"); //gsmSendMessage("Fail");
820 5 return 0;
821 5
822 5 }
823 4
824 4
825 4
826 4 }//if((ptr=strstr(task,"B")) != NULL)
827 3 }//if(gsmSearchPhone("A"))
828 2 }//if(task[0] == 'B')
829 1
830 1
831 1 return 0;
832 1 }
833
834
835 // PDU編碼,用于編制、發(fā)送短消息
836 // pSrc: 源PDU參數(shù)指針
837 // pDst: 目標(biāo)PDU串指針
838 // 返回: 目標(biāo)PDU串長(zhǎng)度
839 int gsmEncodePdu(char xdata* pDst) //pDst=pdu;
840 {
841 1 int nLength; // 內(nèi)部用的串長(zhǎng)度
842 1 int nDstLength; // 目標(biāo)PDU串長(zhǎng)度
843 1
844 1 // SMSC地址信息段
845 1 nLength = strlen(SCA); // SMSC地址字符串的長(zhǎng)度
846 1
847 1 if((nLength & 0x01)==0)
848 1 nDstLength= nLength/2+1;
C51 COMPILER V7.50 M32 04/04/2007 15:01:44 PAGE 15
849 1 else
850 1 nDstLength= (nLength+1)/2 + 1;
851 1
852 1 ans[0] = (char)nDstLength; // SMSC地址信息長(zhǎng)度
853 1 ans[1] = 0x91; // 固定: 用國(guó)際格式號(hào)碼
854 1 nDstLength = gsmBytes2String(ans, pDst, 2); // 轉(zhuǎn)換2個(gè)字節(jié)到目標(biāo)PDU串
855 1
856 1 nDstLength += gsmInvertNumbers(SCA, &pDst[nDstLength], nLength); // 轉(zhuǎn)換SMSC到目標(biāo)PDU串
857 1 // TPDU段基本參數(shù)、目標(biāo)地址等
858 1 nLength = strlen(TPA); // TP-DA地址字符串的長(zhǎng)度
859 1 ans[0] = 0x11; // 是發(fā)送短信(TP-MTI=01),TP-VP用相對(duì)格式(TP-VPF=10)
860 1 ans[1] = 0; // TP-MR=0
861 1 ans[2] = (char)nLength; // 目標(biāo)地址數(shù)字個(gè)數(shù)(TP-DA地址字符串真實(shí)長(zhǎng)度)
862 1 ans[3] = 0x91; // 固定: 用國(guó)際格式號(hào)碼
863 1 nDstLength += gsmBytes2String(ans, &pDst[nDstLength], 4); // 轉(zhuǎn)換4個(gè)字節(jié)到目標(biāo)PDU串
864 1 nDstLength += gsmInvertNumbers(TPA, &pDst[nDstLength], nLength); // 轉(zhuǎn)換TP-DA到目標(biāo)PDU串
865 1
866 1 // TPDU段協(xié)議標(biāo)識(shí)、編碼方式、用戶信息等
867 1 nLength = strlen(TP_UD); // 用戶信息字符串的長(zhǎng)度
868 1 ans[0] = TP_PID; // 協(xié)議標(biāo)識(shí)(TP-PID)
869 1 ans[1] = TP_DCS; // 用戶信息編碼方式(TP-DCS)
870 1 ans[2] = 0; // 有效期(TP-VP)為5分鐘
871 1
872 1
873 1 if(TP_DCS == GSM_7BIT)
874 1 {
875 2 // 7-bit編碼方式
876 2 ans[3] = nLength; // 編碼前長(zhǎng)度
877 2 nLength = gsmEncode7bit(TP_UD, &ans[4], nLength+1) + 4; // 轉(zhuǎn)換TP-DA到目標(biāo)PDU串
878 2 }
879 1 else
880 1 if(TP_DCS == GSM_UCS2)
881 1 {
882 2 #if 0
// UCS2編碼方式
ans[3] = gsmEncodeUcs2(pSrc->TP_UD, &ans[4], nLength); // 轉(zhuǎn)換TP-DA到目標(biāo)PDU串
nLength = ans[3] + 4; // nLength等于該段數(shù)據(jù)長(zhǎng)度
#endif
887 2 }
888 1 else
889 1 {
890 2 // 8-bit編碼方式
891 2 //ans[3] = gsmEncode8bit(TP_UD, &ans[4], nLength); // 轉(zhuǎn)換TP-DA到目標(biāo)PDU串
892 2 nLength = ans[3] + 4; // nLength等于該段數(shù)據(jù)長(zhǎng)度
893 2 }
894 1
895 1 nDstLength += gsmBytes2String(ans, &pDst[nDstLength], nLength); // 轉(zhuǎn)換該段數(shù)據(jù)到目標(biāo)PDU串
896 1 // 返回目標(biāo)字符串長(zhǎng)度
897 1 return nDstLength;
898 1
899 1 }
900
901
902
903
904 /*****************************************************************************************************
905 * int gsmDecode7bit(const unsigned char* pSrc, char* pDst, int nSrcLength)
906 *
907 * 7-bit解碼
908 * pSrc: 源編碼串指針
909 * pDst: 目標(biāo)字符串指針
910 * nSrcLength: 源編碼串長(zhǎng)度
C51 COMPILER V7.50 M32 04/04/2007 15:01:44 PAGE 16
911 * 返回: 目標(biāo)字符串長(zhǎng)度
912 *******************************************************************************************************/
913 //int gsmDecode7bit(const unsigned char* pSrc, char* pDst, int nSrcLength)
914 int gsmDecode7bit(uchar* pSrc, char * pDst, int nSrcLength)
915 {
916 1 int nSrc; // 源字符串的計(jì)數(shù)值
917 1 int nDst; // 目標(biāo)解碼串的計(jì)數(shù)值
918 1 int nByte; // 當(dāng)前正在處理的組內(nèi)字節(jié)的序號(hào),范圍是0-6
919 1 unsigned char nLeft; // 上一字節(jié)殘余的數(shù)據(jù)
920 1
921 1 // 計(jì)數(shù)值初始化
922 1 nSrc = 0;
923 1 nDst = 0;
924 1 // 組內(nèi)字節(jié)序號(hào)和殘余數(shù)據(jù)初始化
925 1 nByte = 0;
926 1 nLeft = 0;
927 1 // 將源數(shù)據(jù)每7個(gè)字節(jié)分為一組,解壓縮成8個(gè)字節(jié)
928 1 // 循環(huán)該處理過程,直至源數(shù)據(jù)被處理完
929 1 // 如果分組不到7字節(jié),也能正確處理
930 1 while(nSrc<nSrcLength)
931 1 {
932 2 // 將源字節(jié)右邊部分與殘余數(shù)據(jù)相加,去掉最高位,得到一個(gè)目標(biāo)解碼字節(jié)
933 2 *pDst = ((*pSrc << nByte) | nLeft) & 0x7f;
934 2 // 將該字節(jié)剩下的左邊部分,作為殘余數(shù)據(jù)保存起來
935 2 nLeft = *pSrc >> (7-nByte);
936 2 // 修改目標(biāo)串的指針和計(jì)數(shù)值
937 2 pDst++;
938 2 nDst++;
939 2 // 修改字節(jié)計(jì)數(shù)值
940 2 nByte++;
941 2 // 到了一組的最后一個(gè)字節(jié)
942 2 if(nByte == 7)
943 2 {
944 3 // 額外得到一個(gè)目標(biāo)解碼字節(jié)
945 3 *pDst = nLeft;
946 3 // 修改目標(biāo)串的指針和計(jì)數(shù)值
947 3 pDst++;
948 3 nDst++;
949 3 // 組內(nèi)字節(jié)序號(hào)和殘余數(shù)據(jù)初始化
950 3 nByte = 0;
951 3 nLeft = 0;
952 3 }
953 2 // 修改源串的指針和計(jì)數(shù)值
954 2 pSrc++;
955 2 nSrc++;
956 2 }
957 1 *pDst = 0;
958 1 // 返回目標(biāo)串長(zhǎng)度
959 1 return nDst;
960 1 }
961
962
963
964
965 // PDU解碼,用于接收、閱讀短消息
966 // pSrc: 源PDU串指針
967 // pDst: 目標(biāo)PDU參數(shù)指針
968 // 返回: 用戶信息串長(zhǎng)度
969 int gsmDecodePdu(char * pSrc)
970 {
971 1 int nDstLength; // 目標(biāo)PDU串長(zhǎng)度
972 1 unsigned char tmp; // 內(nèi)部用的臨時(shí)字節(jié)變量
C51 COMPILER V7.50 M32 04/04/2007 15:01:44 PAGE 17
973 1
974 1 // SMSC地址信息段
975 1 gsmString2Bytes(pSrc, &tmp, 2); // 取長(zhǎng)度
976 1 tmp = (tmp - 1) * 2; // SMSC號(hào)碼串長(zhǎng)度
977 1 pSrc += 4; //指針后移
978 1 gsmSerializeNumbers(pSrc, SCA, tmp);
979 1
980 1 #if 0
putstring1("SCA=\r\n");
putstring1(SCA);
putstring1("\r\n");
#endif
985 1
986 1
987 1 // 轉(zhuǎn)換SMSC號(hào)碼到目標(biāo)PDU串
988 1 pSrc += tmp;
989 1 #if 0
putstring1("pSrc=\r\n");
putstring1(pSrc);
putstring1("\r\n"); //040D9168
#endif
994 1 // 指針后移
995 1 // TPDU段基本參數(shù)、回復(fù)地址等
996 1 gsmString2Bytes(pSrc, &tmp, 2);
997 1 //tmp=04 No return back addr
998 1 //tmp=84 have return back addr
999 1 // 取基本參數(shù)
1000 1 pSrc += 2;
1001 1 // 指針后移
1002 1 #if 0
putstring1("pSrc=\r\n");
putstring1(pSrc);
putstring1("\r\n"); //0D9168
#endif
1007 1
1008 1
1009 1 //if(tmp & 0x80)
1010 1 {
1011 2 // 包含回復(fù)地址,取回復(fù)地址信息
1012 2 gsmString2Bytes(pSrc, &tmp, 2); // 取長(zhǎng)度
1013 2 if(tmp==13)putstring1("13\r\n");
1014 2
1015 2 if(tmp & 1) tmp += 1; // 調(diào)整奇偶性
1016 2 if(tmp==14)putstring1("14\r\n");
1017 2
1018 2
1019 2 pSrc += 4;
1020 2 // 指針后移
1021 2 gsmSerializeNumbers(pSrc, TPA, tmp);
1022 2 // 取TP-RA號(hào)碼
1023 2 #if 0
putstring1("TPA=\r\n");
putstring1(TPA);
putstring1("\r\n");
#endif
1028 2 pSrc += tmp;
1029 2 // 指針后移
1030 2 }
1031 1
1032 1
1033 1 // TPDU段協(xié)議標(biāo)識(shí)、編碼方式、用戶信息等
1034 1 gsmString2Bytes(pSrc, (unsigned char*)&TP_PID, 2); // 取協(xié)議標(biāo)識(shí)(TP-PID)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -