📄 sms.c
字号:
#include "include.h"
//************************ //20071203 shinelee
uchar GsmDecode7bit(uchar*pSrc, char*pDst, uchar nSrcLength); //短信7-Bit编码
void SevenSmsHead(uchar *number);
void HandSmsSend(uchar *content ,uchar *number);//手机短信发送
uchar HandSmsUpdate(void); //手机短信升级
uchar ChangeNumber(uchar *src); //号码转换
uchar SmsConTentdeal(uchar *src);//短信处理
//****************************************88888***************
//////////////////////////
//AT+CGMR<CR>
//SW ver: 1.0.9
//HW ver: 1.0
//FS ver: 0.4.8.0
//Build Date: 2003/10/24
//Build Time: 14:17:57
//
//
/////////////////////////
void InitM23(void) //20070820hfc
{
uchar Flg,/*ComTmp1,*/times;
vDelayMS(150);
//================================================
//20080714xiehb
#ifdef SIM300
//SentComm(WHOLECOM, (uchar*)"AT+CSCLK=1", 10); //Enable slow Clock.
#else
SentComm(WHOLECOM, (uchar*)"AT$SMOD=1", 9);
#endif
//===============================================
//StarReceiveCom(5);
//CheckATFree(1);
RegistFlg=0; //0
vDelayMS(150);
SentComm(WHOLECOM, (uchar*)"AT", 2);
vDelayMS(150);
StarReceiveCom(2);
CheckATFree(1);
//ATF---恢复出厂设置
SentComm(WHOLECOM, (uchar*)"AT&F", 4);
StarReceiveCom(2);
CheckATFree(1);
//开回显
SentComm(WHOLECOM, (uchar*)"ATE1", 3);
StarReceiveCom(2);
CheckATFree(1);
// vAskSimPin(); //去询问SIM卡是否有开启PIN码;
//----------设置声音
//ATCMGF---设置短信为PDU模式
AT_Command_Return(3, (uchar*)AtComm[ATCMGF], hfcstrlen((uchar*)AtComm[ATCMGF]));
vDelayMS(50);
vGetGsmClock(); //wangyh080418 从模块中获得时间
//ATCLOCK 读模块日期时间
vDelayMS(50);
//AT+CGSN<CR> 读取IMEI
//IMEI: 44601919750759-5
//IMEISV: 44601919750759-00
times = Flg = 0;
while (Flg == 0)
{
if( (times++) > 3) break;
SentComm(WHOLECOM, (uchar*)AtComm[ATCGSN], hfcstrlen((uchar*)AtComm[ATCGSN]));
StarReceiveCom(3);//20071106 shinelee
while ((Flg == 0) && (Com.ReComTimeOut != 0))
{
if (Com.ReFlg == REOK)
{ //已经接收完成,判断接收结果
ReBufOut1 = 0;
while (1)
{
if (GetRetComm((uchar*) &ReBuf[ReBufOut1], ReBufOut1) == 1)
{
if (Result.Num == OK)//IMEI)
{
GetIMEI();
Flg = 1;
break;
}
}
MoveToNextReStr();
if (ReBufOut1 == 0xffff)
{
//已经查完所有的
StarReceiveCom(0); //继续接收
break;
}
}//End of while(1)
}
}
}
vDelayMS(50);
Flg = 0;
times = 5;
while (Flg == 0)
{
if (times)
times--;
else
break;
SentComm(WHOLECOM, (uchar*)AtComm[ATCIMI], hfcstrlen((uchar*)AtComm[ATCIMI]));
StarReceiveCom(3);//20071106 shinelee
while ((Flg == 0) && (Com.ReComTimeOut != 0))
{
if (Com.ReFlg == REOK)
{
//已经接收完成,判断接收结果
ReBufOut1 = 0;
while (1)
{
if (GetRetComm((uchar*) &ReBuf[ReBufOut1], ReBufOut1) == 1)
{
if (Result.Num == OK)
{
if (GetImsi() == 1)
{
Flg = 1;
break;
}
}
}
MoveToNextReStr();
if (ReBufOut1 == 0xffff)
{
//已经查完所有的
StarReceiveCom(0); //继续接收
break;
}
}
}
}
}
//来电号码显示
AT_Command_Return(3, (uchar*)AtComm[ATCLIP], hfcstrlen((uchar*)AtComm[ATCLIP]));
vDelayMS(50);
//wangyh080124 有短信时提示;
AT_Command_Return(3, (uchar*)AtComm[ATCNMI], hfcstrlen((uchar*)AtComm[ATCNMI]));
vDelayMS(50);
vDispClear();
vDispStr(3, 5, "网络初始化.");
vGetSmsCenter(); //wangyh080306读出短信中心号码并存储;
//读取短信中心号
vDelayMS(50);
//读取信号强度
//+CSQ:
//20,99
//
//OK
//*********************** 20070911 shinelee
CheckSignal();
if(CsqDegreed<8)
CheckSignal();
if(RegistFlg==0)
return;
vDelayMS(50);
vDispStr(3, 5, "网络初始化..");
//ATCOPS---//联通卡还是移动,运营商
//+COPS: 0,2,"46000" 移动
//OK
times = Flg = 0;
while (Flg == 0)
{
if( (times++) > 3) break;
SentComm(WHOLECOM, (uchar*)AtComm[ATCOPS], hfcstrlen((uchar*)AtComm[ATCOPS]));
StarReceiveCom(3);//20071106 shinelee
while ((Flg == 0) && (Com.ReComTimeOut != 0))
{
if (Com.ReFlg == REOK)
{
//已经接收完成,判断接收结果
ReBufOut1 = 0;
vDelayMS(100);
while (1)
{
if (GetRetComm((uchar*) &ReBuf[ReBufOut1], ReBufOut1) == 1)
{
if (Result.Num == COPS)
{//+COPS: 0,2,"46000"
if(LocateStr(&ReBuf[ReBufOut1], "46000",ReBufIn,5) != 0xffff)
cmobile=1;
else if(LocateStr(&ReBuf[ReBufOut1], "46001",ReBufIn,5) != 0xffff)
cmobile=0;
Flg = 1;
break;
}
}
MoveToNextReStr();
if (ReBufOut1 == 0xffff)
{ //已经查完所有的
StarReceiveCom(0); //继续接收
break;
}
}
}
}
}
vDelayMS(50);
vDispStr(3, 5, "网络初始化...");
// 注册信息
//+CREG: 1,1
SentComm(WHOLECOM, (uchar*)"AT+CREG?", 8);
StarReceiveCom(2);
CheckATFree(1);
vDelayMS(50);
AT_Command_Return(3, (uchar*)AtComm[ATCNMI], hfcstrlen((uchar*)AtComm[ATCNMI]));
vDelayMS(50);
//----------------------------------
//wangyh080328去收短信,收完后才进入空闲状态;
vDelayMS(100);
aFlagTemp =0;
ReSeSmsStep = 0;
ChkReSeSmsTI =0;
isHookOffSms = 1;
ucStatus = pIDLE;
while(1)
{
if((RegistFlg==0)||(SmsFullFlag==1)) //wangyh080414
break; //无SIM卡则不收短信;
ReSeSmsPro();
if(ReSeSmsStep == 6)
break;
}
//SentComm(WHOLECOM, "ATE1", 8);//20080805,zhangkai
//StarReceiveCom(2);//20080805,zhangkai
//检测SIM卡空间是否存满;wangyh080412
times = Flg = 0;
while (Flg == 0)
{
KeyIn =0;
if( RegistFlg==0 ) break; //无SIM卡则不去查看短信空间;
if( (times++) > 3) break;
SentComm(WHOLECOM, "AT+CPMS?", 8);
StarReceiveCom(2);
while ((Flg == 0) && (Com.ReComTimeOut != 0))
{
if (Com.ReFlg == REOK)
{
aStkUintIn = LocateStr(ReBuf, "\"SM\",", ReBufIn, 5);
if(aStkUintIn != 0xffff)
{//找到了这个命令;把菜单数保存起来;
KeyIn =0;
ParaSetBufIn =0;
aStkUintIn += 5;
for(KeyIn =0; KeyIn<4; KeyIn++)
{
if(ReBuf[aStkUintIn+KeyIn]==',')
break;
KeyBuf[KeyIn]=ReBuf[aStkUintIn+KeyIn];
}
aStkUintIn = (aStkUintIn+KeyIn+1);
for(ParaSetBufIn =0; ParaSetBufIn<4; ParaSetBufIn++)
{
if(ReBuf[aStkUintIn+ParaSetBufIn]==',')
break;
ParaSetBuf[ParaSetBufIn]=ReBuf[aStkUintIn+ParaSetBufIn];
}
if(memcmp(KeyBuf, ParaSetBuf, ParaSetBufIn)==0)
{//相同表示SIM卡空间已满;
KeyIn =1;
}
else
{
KeyIn =0;
}
Flg = 1;
break;
}
Com.ReFlg = RESTAR;
}
}
}
if(KeyIn==1)
{//SIM卡空间已满;
vDispClear();
vDispStrN(1, 4, 1, "SIM卡中信息已满,不能继续接收新信息,请确认是否清空SIM卡中信息?");
vDispStr(5, 1, " 确认 取消 ");
while(1)
{
if(!btMsgGet())//有按键,应响一下
{
PlayKeyTone();//按键音
if(ucMsg == SUREKEY)
{//确认;//AT+CMGD=1,4
vDispClear();
vDispStr(3,4,"正在清空");
vDispStr(3,4,"请 稍 候");
vDelayMS(300);
AT_Command_Return(20, (uchar*)"AT+CMGDA=6", 10); //20080714xiehb 删除所有短信
vDispClear();
vDispStr(3,4,"清空成功");
vDelayMS(1000);
break;
}
else if(ucMsg == CANCELKEY)
{//取消;
break;
}
}
ucMsg =0xff;
}
}
vDelayMS(150);
CheckSignal();
//=================结束SIM卡空间满程序==============;
}
void vGetGsmClock() //wangyh080418 从模块中获得时间
{ //ATCLOCK 读模块日期时间
uchar times;
uchar Flg;
uchar DateTime[12];
vDelayMS(100);
times = Flg = 0;
while (Flg == 0)
{
if( (times++) > 3) break;
SentComm(WHOLECOM, (uchar*)"AT+CCLK?", 8);
StarReceiveCom(3);//20071106 shinelee
while ((Flg == 0) && (Com.ReComTimeOut != 0))
{
if (Com.ReFlg == REOK)
{
//已经接收完成,判断接收结果
ReBufOut1 = 0;
while (1)
{
if (GetRetComm((uchar*) &ReBuf[ReBufOut1], ReBufOut1) == 1)
{
if (Result.Num == CLOCK)
{//+CCLK: "08/01/14,18:08:57-08"
Flg = 1;
DateTime[0] = ReBuf[Result.Pos + 8];
DateTime[1] = ReBuf[Result.Pos + 9];
DateTime[2] = ReBuf[Result.Pos + 11];
DateTime[3] = ReBuf[Result.Pos + 12];
DateTime[4] = ReBuf[Result.Pos + 14];
DateTime[5] = ReBuf[Result.Pos + 15];
DateTime[6] = ReBuf[Result.Pos + 17];
DateTime[7] = ReBuf[Result.Pos + 18];
DateTime[8] = ReBuf[Result.Pos + 20];
DateTime[9] = ReBuf[Result.Pos + 21];
DateTime[10] = ReBuf[Result.Pos + 23];
DateTime[11] = ReBuf[Result.Pos + 24];
SetTimeAT(DateTime);
break;
}
}
MoveToNextReStr();
if (ReBufOut1 == 0xffff)
{
//已经查完所有的
StarReceiveCom(0); //继续接收
break;
}
}
}
}
}
}
/////////////////////////////
void ControlTer(uchar Con)
{
if (Con == cTerstar)
{
//要求终端启动
Labe4010 = cTerstar;
LabeTime = 0;
vMainWaitInit();
}
else if (Con == cTerHalt)
{
//终端停止
vDispClear();
Labe4010 = cTerHalt;
LabeTime = 0;
}
else if (Con == cTerReset)
{
//要求终端重启
Labe4010 = cTerReset;
LabeTime = 6; //hfc20080816
}
}
//////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -