tc35成功模块调试程序.rar

源代码在线查看: tc35.c

软件大小: 63 K
上传用户: bing1728
关键词: tc 35 模块
下载地址: 免注册下载 普通下载 VIP

相关代码

				#include 
				#include
				#include "tc35.h"
				#include "common.h"
				#include 
				
				// 初始化
				int ATE(char pBuf[])
				{
				    pBuf[0] = 'A';
				    pBuf[1] = 'T';
				    pBuf[2] = 'E';
				    pBuf[3] = '0';
				    pBuf[4] = 13;//HUI
				
				    return 5;
				}
				
				// 设置短信中心地址
				int CSCA(char pBuf[],char phone[])
				{
				    int offset;
				    int i;
				    pBuf[0] = 'A';
				    pBuf[1] = 'T';
				    pBuf[2] = '+';
				    pBuf[3] = 'C';
				    pBuf[4] = 'S';
				    pBuf[5] = 'C';
				    pBuf[6] = 'A';
				    pBuf[7] = '=';
				    pBuf[8] = '"';
				    offset = 9;
				    for(i = 0;i < 14;i++)
				    {
				        pBuf[offset + i] = phone[i];
				    }
				    offset += 14;
				    pBuf[8] = '"';
				    offset += 1;
				    pBuf[offset] = ',';
				    offset += 1;
				    pBuf[offset] = '1';
				    offset += 1;
				    pBuf[offset] = '4';
				    offset += 1;
				    pBuf[offset] = '9'; 
				    offset += 1;
				    pBuf[offset] = 13;
				    offset += 1;
				    return offset;
				}
				//设置短消息格式
				int CMGF(char pBuf[],int format)
				{
				    pBuf[0] = 'A';
				    pBuf[1] = 'T';
				    pBuf[2] = '+';
				    pBuf[3] = 'C';
				    pBuf[4] = 'M';
				    pBuf[5] = 'G';
				    pBuf[6] = 'F';
				    pBuf[7] = '=';
				    pBuf[8] = (char)('0' + format);   
				    pBuf[9] = 13;
				
				    return 10;
				}
				//删除短消息
				int CMGD(char pBuf[],char index)
				{
				    pBuf[0] = 'A';
				    pBuf[1] = 'T';
				    pBuf[2] = '+';
				    pBuf[3] = 'C';
				    pBuf[4] = 'M';
				    pBuf[5] = 'G';
				    pBuf[6] = 'D';
				    pBuf[7] = '=';
				    if(index >= 10)
				    {
				        pBuf[8] = (index/10) + 0x30;
				        pBuf[9] = (index%10) + 0x30;   
				        pBuf[10] = 13;
				        return 11;
				    }
				    else
				    {
				        pBuf[8] = index  + 0x30;   
				        pBuf[9] = 13;
				        return 10;
				    }
				}
				//设置模式参数
				int CSMP(char pBuf[],char index)
				{
				    pBuf[0] = 'A';
				    pBuf[1] = 'T';
				    pBuf[2] = '+';
				    pBuf[3] = 'C';
				    pBuf[4] = 'S';
				    pBuf[5] = 'M';
				    pBuf[6] = 'P';
				    pBuf[7] = '=';
				    pBuf[8] = '1';
				    pBuf[9] = '7';
				    pBuf[10] = ',';
				    pBuf[11] = '1';
				    pBuf[12] = '6';
				    pBuf[13] = '7';
				    pBuf[14] = ',';
				    pBuf[15] = '0';
				    pBuf[16] = ',';
				    pBuf[17] = index  + 0x30;
				    pBuf[18] = 13;
				    return 19;
				}
				//接收短消息
				int CMGR(char pBuf[],char index)
				{
				    pBuf[0] = 'A';
				    pBuf[1] = 'T';
				    pBuf[2] = '+';
				    pBuf[3] = 'C';
				    pBuf[4] = 'M';
				    pBuf[5] = 'G';
				    pBuf[6] = 'R';
				    pBuf[7] = '=';
				    if(index >= 10)
				    {
				        pBuf[8] = (index/10) + 0x30;
				        pBuf[9] = (index%10) + 0x30;  
				        pBuf[10] = 13;
				        return 11;
				    }
				    else
				    {
				        pBuf[8] = index  + 0x30; // 变换为asccii码
				        pBuf[9] = 13;
				        return 10;
				    }
				}
				//发送短消息
				void packSms_pdu(char pPhone[],int phonelen,char pData[],int nLen,
				            int *nTXLen1,int *nTXLen2,char *pout1,char *pout2)
				{
				    char strHead[12] = {'0','0','1','1','0','0',
				                        '0','D','9','1','6','8'};
				    char chrInfo[7] = {'0','0','0','8','0','1'};
				    char chrTmp[12];
				    char phoneTemp[12];
				  char nTemp[100];
				    int i;
				    int n;
				
				    for(i = 0;i < phonelen;i++)
				    {
				    	chrTmp[i] = pPhone[i];
				    }
				    chrTmp[phonelen] = 'F';
				    phonelen += 1;
				    // 将电话号码按照规范的顺序作成
				    n = 0;
				    for(i = 0;i < phonelen / 2;i++)
				    {
				    	phoneTemp[n++] = chrTmp[2 * i + 1];
				    	phoneTemp[n++] = chrTmp[2 * i];
				    }//算法忒好了 采用一半 
				    copy(pout2,0,strHead,0,12);
				    copy(pout2,12,phoneTemp,0,phonelen);//将电话号码 加载到Unicode码中
				    copy(pout2,24,chrInfo,0,6);
				    pout2[30]= nLen/10 + 0x30;
				    pout2[31]= nLen%10 + 0x30; 
				    copy(pout2,32,pData,0,nLen*2);//定义发送的数据量时为2个字符一个
				    pout2[32+nLen*2]=26;
				    *nTXLen2=33+nLen*2; 
				    //封装长度信息
				    nTemp[0] = 'A';
				    nTemp[1] = 'T';
				    nTemp[2] = '+';
				    nTemp[3] = 'C';
				    nTemp[4] = 'M';
				    nTemp[5] = 'G';
				    nTemp[6] = 'S';
				    nTemp[7] = '=';
				    nTemp[8] = (15+nLen)/10 + 0x30;
				    nTemp[9] = (15+nLen)%10 + 0x30;
				    nTemp[10] = 13;
				    
				    for(i = 0; i < 11;i++)
				    {
				    	pout1[i] = nTemp[i];
				    }
				    *nTXLen1 =11;
				}
				void packSms_text(char pPhone[],int phonelen,char pData[],int nLen,
				            int *nTXLen1,int *nTXLen2,char pOut1[],char pOut2[])
				{
				    int nOffset;
				    char nTemp[100];
				    int i;
				
				    nOffset = 0;
				    nTemp[0] = 'A';
				    nTemp[1] = 'T';
				    nTemp[2] = '+';
				    nTemp[3] = 'C';
				    nTemp[4] = 'M';
				    nTemp[5] = 'G';
				    nTemp[6] = 'S';
				    nTemp[7] = '=';
				    nTemp[8] = '"';
				
				    //处理电话号码
				    nOffset = 9;
				    for(i = 0;i < phonelen;i++)
				    {
				        nTemp[nOffset + i] = pPhone[i];
				    }
				    nOffset += nLen;
				    nTemp[nOffset] = '"';  
				    nOffset += 1;		
				    nTemp[nOffset] = 13;//13表示回车
				    nOffset += 1;
				    for(i = 0; i < nOffset;i++)
				    {
				    	pOut1[i] = nTemp[i];
				    }
				    *nTXLen1 = nOffset;
				    
				    //处理发送数据
				    for(i = 0; i < nLen;i++)
				    {
				    	pOut2[i] = pData[i];
				    }
				    pOut2[nLen] = 26;//26表示ctrl+z
				    
				    *nTXLen2 = nLen + 1;
				}
				char getSendResponse(char buf[],char res[])
				{char re=0;
				 char *p;
				delay(100);//延时一下
				p=strstr(buf,res);
				if(p!=NULL)
				re=1;
				else
				re=0;
				return re;
				}
				
				
				//将源数组的内容拷贝到目的数组
				void copy(char pDest[],int nOrg,char pOrg[],int nStart,int nLen)
				{
				    int i;
				    for(i = 0;i < nLen;i++)
				    {
				    	pDest[nOrg + i] = pOrg[i + nStart];
				    }
				}
				
				
				// 将字节处理成字符串
				/*void ByteToChar(char nInPut[],char Out[],int nLen)
				{
				    int i;
				    char chrTemp;
				    
				    for(i = 0;i < nLen;i++)
				    {
				        // 高字节			
				        chrTemp = (char)((nInPut[i] >> 4) & 0x0f);
				        if((chrTemp >= 0) && (chrTemp 				        else chrTemp += 55;
				        Out[i] = chrTemp;
				    
				        // 低字节
				        chrTemp = (char)(nInPut[i] & 0x0f);
				        if((chrTemp >= 0) && (chrTemp 				        else chrTemp += 55;
				        Out[i] = chrTemp;
				    }
				    
				    return;
				}*/
				// 数的范围为250以内
				int IntToChar(int n,char Out[])
				{
				
				    char chrTemp1;
				    char chrTemp2;
				    char chrTemp3;
				    int nLen;
				
				    chrTemp1 = n / 100;
				    chrTemp2 = (n - chrTemp1 * 100) / 10;
				    chrTemp3 = n - chrTemp1 * 100 - chrTemp2 * 10;
				    if(chrTemp1 != 0) 
				    {
				    	nLen = 3;
				        Out[0] = chrTemp1 + 0x30;
				        Out[1] = chrTemp2 + 0x30;
				        Out[2] = chrTemp3 + 0x30;
				    }
				    else
				    {
				    	if(chrTemp2 != 0)
				    	{
				    	    nLen = 2;
				            Out[0] = chrTemp2 + 0x30;
				            Out[1] = chrTemp3 + 0x30;
				    	}
				    	else
				    	{
				    	    nLen = 1;
				            Out[0] = chrTemp3 + 0x30;
				    	}
				    }
				
				    return nLen;
				}
				// 编码函数
				void Encode(char in[],char out[],int nLen)
				{
				    int nOrigin = 0;
				    int nCode = 0;
				    while(1)
				    {
				        if(nOrigin >= nLen) break;
				        out[nCode] = in[nOrigin];
				
				        if((nOrigin + 1) >= nLen) break;		    
				        out[nCode] |= (char)((in[nOrigin + 1] & 0x01) 				        out[nCode + 1] = (char)((in[nOrigin + 1] >> 1) & 0xff);	
				
				        if((nOrigin + 2) >= nLen) break;
				        out[nCode + 1] |= (char)((in[nOrigin + 2] & 0x03) 				        out[nCode + 2] = (char)((in[nOrigin + 2] >> 2) & 0xff);
				
				        if((nOrigin + 3) >= nLen) break;
				        out[nCode + 2] |= (char)((in[nOrigin + 3] & 0x07) 				        out[nCode + 3] = (char)((in[nOrigin + 3] >> 3) & 0xff);
				
				        if((nOrigin + 4) >= nLen) break;
				        out[nCode + 3] |= (char)((in[nOrigin + 4] & 0x0f) 				        out[nCode + 4] = (char)((in[nOrigin + 4] >> 4) & 0xff);
				
				        if((nOrigin + 5) >= nLen) break;
				        out[nCode + 4] |= (char)((in[nOrigin + 5] & 0x1f) 				        out[nCode + 5] = (char)((in[nOrigin + 5] >> 5) & 0xff);
				
				        if((nOrigin + 6) >= nLen) break;
				        out[nCode + 5] |= (char)((in[nOrigin + 6] & 0x3f) 				        out[nCode + 6] = (char)((in[nOrigin + 6] >> 6) & 0xff);
				
				        if((nOrigin + 7) >= nLen) break;
				        out[nCode + 6] |= (char)((in[nOrigin + 7] & 0x7f) 				
				        nCode += 7;
				        nOrigin += 8;
				    }
				}
				
				int FindERROR(char in[],int nLen)
				{
				    int nOffset,i;
				    nOffset = -1;if(nLen < 5) return nOffset;
				    for(i = 0;i < nLen;i++)
				    {
				    	if((in[i] == 'R') && (in[i - 1] == 'O') && (in[i - 2] == 'R') 
				    	   && (in[i - 3] == 'R') && (in[i - 4] == 'E')) 
				    	{
				    	    nOffset = i - 4;
				    	    break;
				    	}    	
				    }
				    return nOffset;
				}
				int FindCMGR(char in[],int nLen)
				{
				    int nOffset,i;
				    nOffset = -1;
				    if(nLen < 5) return nOffset;
				    for(i = 0;i < nLen;i++)
				    {
				    	if((in[i] == 'R') && (in[i - 1] == 'G') && (in[i - 2] == 'M') 
				    	   && (in[i - 3] == 'C') && (in[i - 4] == '+')) 
				    	{
				    	    nOffset = i - 4;
				    	    break;
				    	}    	
				    }
				    return nOffset;
				}
				int FindOK(char in[],int nLen)
				{
				    int nOffset,i;
				    nOffset = -1;
				    if(nLen < 2) return nOffset;
				    for(i = 0;i < nLen;i++)
				    {
				    	if((in[i] == 'K') && (in[i - 1] == 'K')) 
				    	{
				    	    nOffset = i - 1;
				    	    break;
				    	}    	
				    }
				    return nOffset;
				}
				void CharToByte(char in[],char out[],int nLen)
				{
				    char chrHi,chrLow;
				    
				    for(int i = 0;i < nLen / 2;i++)
				    {
				        chrHi = in[2 * i];			
				        if(chrHi >= 48 && chrHi 				            chrHi = (char)(chrHi - 48);
				        else if(chrHi >= 65 && chrHi 				            chrHi = (char)(chrHi - 55);
				        else if(chrHi >= 97 && chrHi 				            chrHi = (char)(chrHi - 87); 
						
				        chrLow = in[2 * i + 1];
				        if(chrLow >= 48 && chrLow 				            chrLow = (char)(chrLow - 48);
				        else if(chrLow >= 65 && chrLow 				            chrLow = (char)(chrLow - 55);
				        else if(chrLow >= 97 && chrLow 				            chrLow = (char)(chrLow - 87);
				        
				        out[i] = (char)(chrHi * 16 + chrLow);
				    }
				
				    return;
				}
				int Decode(char in[],char out[],int nLen)
				{
				    int nOrigin = 0;
				    int nCode = 0;
				    int nLenTemp = nLen * 8 / 7;           
				    
				    while(1)
				    {
				    	if(nOrigin >= nLen) break;
				    	out[nCode] = (char)(in[nOrigin] & 0x7f);
				    	
				    	if((nOrigin + 1) >= nLen) break;
				    	out[nCode + 1] = (char)((in[nOrigin + 1] & 0x3f) 				    	out[nCode + 1] += (char)((in[nOrigin] & 0x80) >> 7);
				    	
				    	if((nOrigin + 2) >= nLen) break;
				    	out[nCode + 2] = (char)((in[nOrigin + 2] & 0x1f) 				    	out[nCode + 2] += (char)((in[nOrigin + 1] & 0xc0) >> 6);
				    	
				    	if((nOrigin + 3) >= nLen) break;
				    	out[nCode + 3] = (char)((in[nOrigin + 3] & 0x0f) 				    	out[nCode + 3] += (char)((in[nOrigin + 2] & 0xe0) >> 5);
				    	
				    	if((nOrigin + 4) >= nLen) break;
				    	out[nCode + 4] = (char)((in[nOrigin + 4] & 0x07) 				    	out[nCode + 4] += (char)((in[nOrigin + 3] & 0xf0) >> 4);
				    	
				    	if((nOrigin + 5) >= nLen) break;
				    	out[nCode + 5] = (char)((in[nOrigin + 5] & 0x03) 				    	out[nCode + 5] += (char)((in[nOrigin + 4] & 0xf8) >> 3);
				    	
				    	if((nOrigin + 6) >= nLen) break;
				    	out[nCode + 6] = (char)((in[nOrigin + 6] & 0x01) 				    	out[nCode + 6] += (char)((in[nOrigin + 5] & 0xfc) >> 2);
				    	            	            	
				    	out[nCode + 7] = (char)((in[nOrigin + 6] & 0xfe) >> 1);
				    	
				    	nCode += 8;
				    	nOrigin += 7;
				    }
				    return nLenTemp;
				}
				
				
				
				
				
				
				
				
				
				
				
							

相关资源