📄 sms.c
字号:
uchar CheckRecAndSend(uchar word)
{
uchar Flg = 0;
CommonSec = 0;
#if 0
while ((CommonSec < 5) && (Flg == 0))
{
//已经接收完成,判断接收结果
ReBufOut1 = 0;
while (1)
{
if(ReBufIn<2)
continue;
if (GetRetComm((uchar*) &ReBuf[ReBufOut1], ReBufOut1) == 1)
{
if (Result.Num == word)
{
//收到NOCARRIER
Flg = 1;
break;
}
else
{
//移到下一串
MoveToNextReStr();
if (ReBufOut1 == 0xffff)
//所接数据已经分析完成
break;
}
}
else
{
//无结果,不认识的结果
MoveToNextReStr();
if (ReBufOut1 == 0xffff)
//所接数据已经分析完成
break;
}
}
}
if (CommonSec >= 5)
{
return MSM_TIMEOUT;
}
if (Flg == 1)
{
return MSM_SENDOK;
}
return MSM_SENDNOACK;
#else
while ((Flg == 0) && (CommonSec <15))
{
if (Com.ReFlg == REOK)
{ //已经接收完成,判断接收结果
ReBufOut1 = 0;
while (1)
{
if (GetRetComm((uchar*) &ReBuf[ReBufOut1], ReBufOut1) == 1)
{
if (Result.Num == word)
{
Flg = 1;
break;
}
}
MoveToNextReStr();
if (ReBufOut1 == 0xffff)
{ //已经查完所有的
Com.ReFlg = RESTAR; //接收情况
break;
}
}
}
}
if (Flg == 1)
{
return MSM_SENDOK;
}
return MSM_SENDNOACK;
#endif
}
#if 0
/////////////////////////////////////////////
void BasMsmHead()
{
uchar i;
uchar tellen;
uchar tempbuff[20];
uchar lenbuff[2];
uchar tellen2; //20070905 wuyiyu
TpduHeadLen = 0;
memset(tempbuff, '\0', sizeof(tempbuff));
memset(TpduHead, '\0', sizeof(TpduHead));
//tellen = strlen((char *)cTelPhone);
tellen = hfcstrlen(cTelPhone);
for (i = 0; i < tellen; i += 2)
//电话号码
{
tempbuff[TpduHeadLen++] = cTelPhone[i + 1];
tempbuff[TpduHeadLen++] = cTelPhone[i];
}
tellen2 = tellen; //20070905 wuyiyu
if ((tellen % 2) != 0)
{
tempbuff[TpduHeadLen - 2] = 'F';
tellen = tellen + 1; //20070905 wuyiyu
}
TpduHeadLen = 0;
memcpy(TpduHead, (uchar*)cTelhead1, 6); //头6位
TpduHeadLen = TpduHeadLen + 6;
OneHL_TwoAscii(tellen2); //20070905 wuyiyu
lenbuff[0] = Ascii_H;
lenbuff[1] = Ascii_L;
memcpy(TpduHead + TpduHeadLen, lenbuff, 2); //长度2位
TpduHeadLen = TpduHeadLen + 2;
memcpy(TpduHead + TpduHeadLen, (uchar*)cTelhead2, 2); //电话头部2位
TpduHeadLen = TpduHeadLen + 2;
memcpy(TpduHead + TpduHeadLen, tempbuff, tellen); //电话
TpduHeadLen = TpduHeadLen + tellen;
memcpy(TpduHead + TpduHeadLen, cTelend, 6); //头6位
TpduHeadLen = TpduHeadLen + 6;
return ;
}
/////////////////////////////////////////////
void HEXTOASCII()
{
//将字符转成16进制的字符串
uchar i;
TpduHead[TpduHeadLen++] = SeSmsBuf1[0];
TpduHead[TpduHeadLen++] = SeSmsBuf1[1];
for (i = 2; i < 150; i++)
{
if (SeSmsBuf1[i] != '\0')
{
OneHL_TwoAscii(SeSmsBuf1[i]);
TpduHead[TpduHeadLen++] = Ascii_H;
TpduHead[TpduHeadLen++] = Ascii_L;
}
}
TpduHead[TpduHeadLen++] = 0x1a;
}
/////////////////////////////////////////////
uchar SendPduSms1(uchar *p, uchar Len)
{
uchar i = 0;
for (i = 0; i < BUFFMAX; i++)
{
if (MsmMsg_Send[i][0] == MSM_NULL)
break;
}
if(i<BUFFMAX) //20070908 shinelee
MsmMsg_Send[i][0] = MSM_SETSEND;
else return 0; //20070908 shinelee
BasMsmHead();
HEXTOASCII();
OneHex_StreeAscii((TpduHeadLen - 2) / 2);
if (TpduHeadLen > 0xCA)
{
MsmMsg_Send[i][1] = Ascii_H;
MsmMsg_Send[i][2] = Ascii_M;
MsmMsg_Send[i][3] = Ascii_L;
MsmMsg_Send[i][4] = 0;
MsmMsg_Send[i][5] = 3;
}
else
{
MsmMsg_Send[i][1] = Ascii_M;
MsmMsg_Send[i][2] = Ascii_L;
MsmMsg_Send[i][3] = 0;
MsmMsg_Send[i][4] = 0;
MsmMsg_Send[i][5] = 2;
}
MsmMsg_Send[i][6] = TpduHeadLen;
MsmMsg_Send[i][7] = (TpduHeadLen >> 8);
MsmMsg_Send[i][8] = 0x0A;
MsmMsg_Send[i][9] = 0x0D;
memcpy((uchar*) &MsmMsg_Send[i][10], TpduHead, TpduHeadLen); //烤内容
return 1;
}
#endif
/////////////////////////////////////////////
void SendPduSms(void)
{
uchar atmp[4];
uint msglen;
uchar i = 0;
uchar temp1; //20071014xiehb
AT_Command_Return(5, (uchar*)"ATE0", 4); //关回显 //20071014xiehb
for (i = 0; i < BUFFMAX; i++)
{
if (MsmMsg_Send[i][0] != MSM_NULL)
{
//********************************************************************
//20071014xiehb
temp1 = 0;
while(1)
{
if(temp1++ > 2)
{
MsmMsg_Send[i][0] = MSM_NULL; //20071020heq
break;
}
memcpy(atmp, (uchar*) &MsmMsg_Send[i][1], 4);
SentComm(PRECOM, (uchar*)AtComm[ATCMGS], hfcstrlen((uchar*)AtComm[ATCMGS]));
SentComm(WHOLECOM, atmp, MsmMsg_Send[i][5]);
StarReceiveCom(2);
CheckATFree(1);
if (CheckRecAndSend(DaYuHao) != MSM_SENDOK)
{
SentComm(PRECOM, "\x0d\x0a", 2); //20070919
return ;
}
else
{
msglen = (MsmMsg_Send[i][6] + (MsmMsg_Send[i][7] << 8));
SentComm(PRECOM, (uchar*) &MsmMsg_Send[i][10], msglen);
MsmMsg_Send[i][0] = MSM_NULL;
StarReceiveCom(10);
if(CheckATFree(2)==2) //返回错误,重发
MsmMsg_Send[i][0] = MSM_SETSEND;
else//*************** 20071101 shinelee
{//发送后清除缓冲区
memset(MsmMsg_Send[i], 0x0, MSGMAXLEN);
break;
}
}
}
}
}
AT_Command_Return(5, (uchar*)"ATE1", 4); //开回显 //20071014xiehb
return ;
}
//---------------------------------------------------
//通过串口发AT命令,从串口读入消息,解包放入缓冲区
//---------------------------------------------------
void RecSmsMsg()
{
uchar tempbuff[500];
uchar NoLen;//20071203 shinelee
uint i = 0, j = 0, templen = 0, sizelen = 0;
uint k = 0;
uchar iTemp,aTemp;
uint userdatahead = 0;
uchar aTempBufIn;
aFlagTemp =0;
aTempBufIn =0;
SwitchPort = 0;
SwitchLen = 0;
//****************** 20071011 shinelee
//平台同时下发多条短信时,且是分包短信,且收上来的顺序打乱了就会出错。
for(i = 0; i < BUFFMAX;)
{
if(MsmMsg_Reco[i][0] == MSM_NULL)
break;
i++;
}
if(i==BUFFMAX)
{
for(i = 0; i < BUFFMAX; i++)
MsmMsg_Reco[i][0] = MSM_NULL;
}
//******************
AT_Command_Return(5, (uchar*)"ATE0", 4); //关回显 //20071014xiehb
vDelayMS(50);
SentComm(PRECOM, (uchar*)AtComm[ATCMGL], hfcstrlen((uchar*)AtComm[ATCMGL]));
// SentComm(PRECOM, (uchar*)AtComm[ATCMGR], hfcstrlen((uchar*)AtComm[ATCMGR]));
StarReceiveCom(15);//20071106 shinelee
//while(Com.ReFlg != REOK);
CheckRecAndSend(OK);
memset(SeSmsBuf1,0x00,sizeof(SeSmsBuf1));
// memset(aTempBuf,0x00,sizeof(aTempBuf));
// if (Flg == MSM_SENDOK) wangyh080320解决一次性来多条短信时收不到OK的从而导致收不到短信的处理;
{
//将缓冲的消息分解后放入缓冲区里面
for (i = 0; i < ReBufIn; i++)
{
if((ReBuf[i]=='M') && (ReBuf[i+1]=='G') && (ReBuf[i+2]=='L') && (ReBuf[i+3]==':'))
{
aFlagTemp =1;
i += 5; //wangyh080314
SeSmsBuf1[aTempBufIn++]=ReBuf[i];
SeSmsBuf1[aTempBufIn++]=ReBuf[i+1];
SeSmsBuf1[aTempBufIn++]=ReBuf[i+2];
while(1)
{
if((ReBuf[i]==0x0d)&&(ReBuf[i+1]==0x0a))
{
i += 2;
break;
}
i++;
if(i >= ReBufIn)
{
return;
}
}
SwitchPort =i;
while(1)
{
if((ReBuf[i]==0x0d)&&(ReBuf[i+1]==0x0a))
{
i += 2;
break;
}
i++;
if(i >= ReBufIn)
{
ChkReSeSmsTI = ON; //打开有短信标志;
TelorSmsTime = 0;
TelorSmsChk = OFF;
return;
}
}
SwitchLen = i - SwitchPort;
memset(tempbuff, '\0', sizeof(tempbuff));
memcpy(tempbuff, ReBuf + SwitchPort, SwitchLen);
if (((tempbuff[0] == 'A') && (tempbuff[1] == 'T')) || ((tempbuff[0] ==
'+') && (tempbuff[1] == 'C')) || ((tempbuff[0] == 'O') &&
(tempbuff[1] == 'K'))){}
else
{
for (j = 0; j < BUFFMAX; j++)
{
if (MsmMsg_Reco[j][0] == MSM_NULL)
break;
}
//wangyh080314
if(j==BUFFMAX)
{//RAM都收满了;
ChkReSeSmsTI = ON; //打开有短信标志;
TelorSmsTime = 0;
TelorSmsChk = OFF;
break;
}
k = 0;
Ascii_H = 0x00;
Ascii_H = tempbuff[0];
Ascii_L = tempbuff[1];
TwoAscii_OneBcd();
k = (Ascii_H *2) + 4;
Ascii_H = 0x00; //判断是否有user-data-header
Ascii_H = tempbuff[k - 2];
Ascii_L = tempbuff[k - 1];
TwoAscii_OneBcd();
userdatahead = Ascii_H;
if ((userdatahead &0x40) != 0)
{
userdatahead = 0xFF;
}
//************* 20071203 shinelee
Ascii_H = 0x00;
Ascii_H = tempbuff[20];
Ascii_L = tempbuff[21];
TwoAscii_OneBcd();
NoLen=Ascii_H + Ascii_H%2; //手机号码长度
Ascii_H = 0x00;
Ascii_H = tempbuff[26+NoLen];//[38];//手机短信专用
Ascii_L = tempbuff[27+NoLen];//[39];//默认13位号码
TwoAscii_OneBcd();
//08为16位编码,04为8位编码,00为7位编码
SmsCodeType[j] = Ascii_H;
memset(MoveNumber[j], 0x00, 20); //wangyh080226
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -