📄 gsmuart.c
字号:
#define GSMUART_GLOBAL 1
#include "includes.h"
//Added by lxo 06081101 for modem type condition compile
#define WAVE2406B 0x01
#define WAVE2406A 0x02
#define MODEMTYPE WAVE2406A
//Added by lxo 06081101 for modem type condition compile
#pragma ROM AT_CMD[]
const _AT_CMD_STRUCT far AT_CMD[]={
{"AT" ,15,1,Inform_Common},
{"ATA" ,15,1,Inform_Common},
{"ATH" ,15,1,Inform_Common},
{"AT+CMGF=0;E0;+WIND=511;+CMEE=1;+CREG=1;+CNMI=0,2,0,0,0;+SPEAKER=1;+CRC=1;+CLIP=1;+SIDET=0;+ECHO=1,1,0,3,10,7;&d0;+VGT=101;&W;",20,1,Inform_Cmd_Init},//Modified by lxo 122832
// {"AT+CMGF=0;E0;+WIND=511;+CMEE=1;+CREG=1;+CNMI=0,2,0,0,0;+SPEAKER=1;+CRC=1;+CLIP=1;+SIDET=0;+ECHO=1,1,0,3,10,7;&d0;+VGT=101;",20,1,Inform_Cmd_Init},//Removed by lxo 122831
//{"AT+CMGF=0;E0;+WIND=511;+CMEE=1;+CREG=1;+CNMI=0,2,0,0,0;+SPEAKER=1;+CRC=1;+CLIP=1;+SIDET=0;+ECHO=1,1,0,3,10,7;+VGT=168;+VGR=128;&W",20,1,Inform_Cmd_Init},
{"AT+CPOF" ,30 ,1,Inform_Common},
{"AT+VGR=" ,30 ,1,Inform_Common},
{"AT+CMEE=1" ,30 ,1,Inform_Common},
{"AT+CPIN?" ,30 ,1,Inform_Cpin },
{"ATD" ,700,1,Inform_Atd },
{"AT+CMGS=" ,350,1,Inform_Cmgs },
{"AT+CSQ" ,30 ,1,Inform_Csq },
{"AT+CREG=1" ,30 ,1,Inform_Common},
{"AT+CREG?" ,30,1 ,Inform_Common},
{"AT+CMGR=" ,70,1 ,Inform_Cmgr },
{"AT+CPMS=" ,30,1 ,Inform_Common},
{"AT+CMGD=1,3" ,30,1 ,Inform_Common},
{"AT+WIND=511" ,30,1 ,Inform_Common},
{"AT+CSCA=" ,30,1 ,Inform_Common},
{"AT+VTS=" ,30,1 ,Inform_Common},
{"AT+WOPEN=1" ,30,1 ,Inform_Common},
{"AT#DLEMODE=1" ,30,1 ,Inform_Common},
{"AT#GPRSMODE=1" ,30,1 ,Inform_Common},
{"AT#APNSERV=" ,30,1 ,Inform_Common},
{"AT#APNUN=" ,30,1 ,Inform_Common},
{"AT#APNPW=" ,30,1 ,Inform_Common},
//Added by lxo 06081102 for modem type condition compile
#if MODEMTYPE == WAVE2406B
{"AT#TCPSERV=" ,30,1 ,Inform_Common},//lxo 121601 for wavecom 2406a
#else
{"AT#TCPSERV=1," ,30,1 ,Inform_Common},//lxo 121601 for wavecom 2406a
#endif
//Added by lxo 06081102 for modem type condition compile
#if MODEMTYPE == WAVE2406B
{"AT#TCPPORT=" ,30,1 ,Inform_Common},//lxo 121602 for wavecom 2406a
#else
{"AT#TCPPORT=1," ,30,1 ,Inform_Common},//lxo 121602 for wavecom 2406a
#endif
{"AT+CGATT=1" ,40,1 ,Inform_Common},
{"AT+CGATT?" ,50,1 ,Inform_Cgatt },
{"AT#CONNECTIONSTART" ,60,1 ,Inform_Start },
//Added by lxo 06081102 for modem type condition compile
#if MODEMTYPE == WAVE2406B
{"AT#OTCP" ,30000,1 ,Inform_Otcp },//add lxo 112430 for reconnect with invalid ip&port//lxo 121603 for wavecom 2406a
#else
{"AT#OTCP=1" ,30000,1 ,Inform_Otcp },//add lxo 112430 for reconnect with invalid ip&port//lxo 121603 for wavecom 2406a
#endif
{"AT+CMGD=1,4" ,150,1 ,Inform_Common},
{"AT+CCID" ,80, 1,Inform_Ccid},
{"AT+CGREG=1" ,40,1,Inform_Common},
//{"+++" ,30,1,Inform_Common},
//{"AT#ANSWERMODE=1" ,30,1,Inform_Common},
//{"AT#CALLSCREENNUM=\"*\"" ,30,1,Inform_Common},
//{"AT#RINGCOUNT=2" ,30,1,Inform_Common},
//{"AT#ACCEPT" ,30,1,Inform_Common},
};
//void far (*Informproc)();//Removed by lxo 0227041
#define MAX_SMSRECV_LEN 200
uchar smsrecv[MAX_SMSRECV_LEN];
typedef struct
{
//uchar flag[3];
uchar type;
void far (*proc)();
uint len;
}AT_CMD_TCB;
#define MAX_AT_CMD_BUF 1100
typedef struct
{
uchar status;
uint head;
uint tail;
uchar buf[MAX_AT_CMD_BUF];
}_AT_CMD_BUF;
_AT_CMD_BUF at_cmd_buf;
//#define MAX_SMS_SEND_BUF 400
//uchar sms_send_buf[MAX_SMS_SEND_BUF];
//uint sms_send_len;
//uchar recvcmgr;
//uchar recvcmgs;
//uchar recvcsq;
uchar recv_cmt;
//------------------------------gsm send--------------------------------
TIMER *At_Over_Timer;
//------------------------------for at inform funcation-----------------
void Inform_Common(void)
{
uchar flag =0;
if(Str_Find(at_con.recvbuf,at_con.recvlen,"OK"))
{
flag = 1;
at_return[at_con.type] = _OK;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"ERROR"))
{
flag = 1;
at_return[at_con.type] = _ERR;
}
else if(at_con.result ==_AT_RECV_OVERTIME)
{
flag = 1;
at_return[at_con.type] = _OVERTIME;
}
if(flag ==1)
{
if(AT_CMD[at_con.type].flag)
{
if(Informproc!=NULL)Informproc();
}
Abort_At_Cmd();
}
}
void Inform_Cmd_Init(void)
{
uchar flag = 0;
if(Str_Find(at_con.recvbuf,at_con.recvlen,"OK"))
{
flag = 1;
at_return[at_con.type] = _OK;
}
else
{
if(Str_Find(at_con.recvbuf,at_con.recvlen,"ERROR"))
{
if(Str_Find(at_con.recvbuf, at_con.recvlen,"310"))
{
flag = 1;
at_return[at_con.type] = _NOSIM;
}
else
{
flag = 1;
at_return[at_con.type] = _ERR;
}
}
else if(at_con.result ==_AT_RECV_OVERTIME)
{
#ifdef DEBUG_AT
Uart1Send("recv atinit failure");
#endif
flag = 1;
at_return[at_con.type] = _OVERTIME;
}
}
if(flag ==1)
{
if(AT_CMD[at_con.type].flag)
{
if(Informproc!=NULL)Informproc();
}
Abort_At_Cmd();
}
}
void Inform_Cpin(void)
{
uchar flag = 0;
if(Str_Find(at_con.recvbuf,at_con.recvlen,"+CPIN:"))
{
flag = 1;
Clr_Char_Bit(&gsmstatus.mode,6);
at_return[at_con.type] = _OK;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"ERROR"))
{
flag = 1;
if(Str_Find(at_con.recvbuf, at_con.recvlen,"10")) //added by leon 050919 //"310"
{
Set_Char_Bit(&gsmstatus.mode,6);
}
at_return[at_con.type] = _ERR;
}
else if(at_con.result ==_AT_RECV_OVERTIME)
{
flag = 1;
at_return[at_con.type] = _OVERTIME;
}
if(flag ==1)
{
if(AT_CMD[at_con.type].flag)
{
if(Informproc!=NULL)Informproc();
}
Abort_At_Cmd();
}
}
void Inform_Atd(void)
{
uchar flag = 0;
uchar fail = 0;
uchar success = 0;
uchar temp = 0;
#ifdef DEBUG_AT
Uart1Send("ATD END!!");
#endif
if(Str_Find(at_con.recvbuf,at_con.recvlen,"NO CARRIER"))
{
fail = 1;
flag = 1;
Uart1Send("NO CARRIER");
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"NO ANSWER"))
{
fail = 1;
flag = 1;
temp = 4;
Uart1Send("NO ANSWER");
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"BUSY"))
{
fail = 1;
flag = 1;
temp = 3;
Uart1Send("BUSY");
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"OK"))
{
flag = 1;
success = 1;
Uart1Send("OK");
}
else if(at_con.result ==_AT_RECV_OVERTIME)
{
fail = 1;
flag = 1;
Uart1Send("OVERTIME");
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"ERROR"))
{
fail = 1;
flag = 1;
Uart1Send("ERROR");
}
if(fail==1)
{
if(gsmstatus.tel == _TEL_REDIAL)
{
Send_H09Msg(0x0);
}
if(gsmstatus.tel ==_TEL_USER)
{
Send_H09Msg(temp);
}
Hangup();
if(AutoDial.state ==_BUSY)
{
Send_Taskmsg(GprsTaskid,AUTODIALFAIL,NULL);
}
at_return[at_con.type] = _ERR;
}
if(success==1)
{
if(AutoDial.state ==_BUSY)
{
Stop_Autodial();
}
if(gsmstatus.tel ==_TEL_USER)
{
gsmstatus.talkmode = _TALK_ON;
Send_H09Msg(0x02);
}
if(gsmstatus.tel==_TEL_REDIAL)
{
gsmstatus.talkmode = _TALK_ON;
Send_H09Msg(0x05);
}
at_return[at_con.type] = _OK;
}
if(flag ==1)
{
if(AT_CMD[at_con.type].flag)
{
if(Informproc!=NULL)Informproc();
}
Abort_At_Cmd();
}
}
void Inform_Cmgs(void)
{
uchar flag = 0;
if(Str_Find(at_con.recvbuf,at_con.recvlen,"+CMGS:"))
{
at_con.time = 1;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"OK"))
{
if(at_con.time==1)
{
at_return[at_con.type] = _OK;
flag = 1;
}
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"ERROR"))
{
at_return[at_con.type] = _ERR;
flag = 1;
}
else if(at_con.result ==_AT_RECV_OVERTIME)
{
flag = 1;
at_return[at_con.type] = _OVERTIME;
}
if(flag ==1)
{
if(AT_CMD[at_con.type].flag)
{
if(Informproc!=NULL)Informproc();
}
Abort_At_Cmd();
}
}
void Inform_Csq(void)
{
uchar index;
uint signal;
uchar flag = 0;
if(Str_Find(at_con.recvbuf,at_con.recvlen,"+CSQ:"))
{
signal = 0;
index = Find_Pos(at_con.recvbuf,at_con.recvlen,':',1)+1;
while(at_con.recvbuf[index]!=',')
{
if(at_con.recvbuf[index]>='0'&&at_con.recvbuf[index]<='9')
{
signal *= 10;
signal += at_con.recvbuf[index]-'0';
}
index ++;
}
if(signal>=99)
{
Set_Char_Bit(&gsmstatus.mode,4);
gsmstatus.signal = 0;
}
else
{
Clr_Char_Bit(&gsmstatus.mode,4);
// gsmstatus.signal = signal/6;
gsmstatus.signal = signal/3;//lxo 120601 for gsm signal deal with
}
at_con.time = 1;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"OK"))
{
if(at_con.time==1)
{
at_return[at_con.type] = _OK;
flag = 1;
}
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"ERROR"))
{
at_return[at_con.type] = _ERR;
flag = 1;
}
else if(at_con.result ==_AT_RECV_OVERTIME)
{
flag = 1;
at_return[at_con.type] = _OVERTIME;
}
if(flag ==1)
{
if(AT_CMD[at_con.type].flag)
{
if(Informproc!=NULL)Informproc();
}
Abort_At_Cmd();
}
}
void Inform_Cmgr(void)
{
uchar flag =0;
if(at_con.time==1)
{
smsrecv[0]=gsmString2Bytes(at_con.recvbuf,&smsrecv[1],at_con.recvlen-2);
Send_Taskmsg(GprsTaskid,RECVONESMS,smsrecv);
at_con.time = 2;
return;
}
if(Str_Find(at_con.recvbuf,at_con.recvlen,"+CMGR:"))
{
at_con.time =1;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"OK"))
{
if(at_con.time ==2)
{
flag = 1;
at_return[at_con.type] = _OK;
if(smscount!=0xff)smscount++;
if(smscount>5)
{
smscount = 0;
At_Cmd_Cmgd();
}
}
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"ERROR"))
{
at_return[at_con.type] = _ERR;
flag = 1;
}
else if(at_con.result ==_AT_RECV_OVERTIME)
{
flag = 1;
at_return[at_con.type] = _OVERTIME;
}
if(flag ==1)
{
if(AT_CMD[at_con.type].flag)
{
if(Informproc!=NULL)Informproc();
}
Abort_At_Cmd();
}
}
void Inform_Cgatt(void )
{
uchar flag = 0;
uchar index;
static uchar cgatt =0;
if(Str_Find(at_con.recvbuf,at_con.recvlen,"+CGATT:"))
{
index = Find_Pos(at_con.recvbuf,at_con.recvlen,':',1)+2;
cgatt = at_con.recvbuf[index]-'0';
at_con.time =1;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"OK"))
{
if(at_con.time==1)
{
if(cgatt==1||cgatt==5){
at_return[at_con.type] = _OK;
flag = 1;
}
else {
at_return[at_con.type] = _CGATT_ERR;
flag = 1;
}
}
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"ERROR"))
{
at_return[at_con.type] = _ERR;
flag = 1;
}
else if(at_con.result ==_AT_RECV_OVERTIME)
{
flag = 1;
at_return[at_con.type] = _OVERTIME;
}
if(flag ==1)
{
if(AT_CMD[at_con.type].flag)
{
if(Informproc!=NULL)Informproc();
}
Abort_At_Cmd();
}
}
void Inform_Start(void)
{
uchar flag = 0;
if(Str_Find(at_con.recvbuf,at_con.recvlen,"Ok_Info_GprsActivation")){
at_return[at_con.type] = _OK;
flag = 1;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"CME ERROR: 35840")){
at_return[at_con.type] = _OK;
flag = 1;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"CME ERROR: 35868")){
at_return[at_con.type] = _APN_ERR;
flag = 1;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"CME ERROR: 49155")){
at_return[at_con.type] = _CGATT_ERR;
flag = 1;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"ERROR")){
at_return[at_con.type] = _ERR;
flag = 1;
}
else if(at_con.result ==_AT_RECV_OVERTIME)
{
flag = 1;
at_return[at_con.type] = _OVERTIME;
}
if(flag ==1)
{
if(AT_CMD[at_con.type].flag)
{
if(Informproc!=NULL)Informproc();
}
Abort_At_Cmd();
}
}
void Inform_Otcp(void )
{
uchar flag = 0;
if(Str_Find(at_con.recvbuf,at_con.recvlen,"Ok_Info_WaitingForData")){
at_return[at_con.type] = _OK;
flag = 1;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"#CME ERROR: 37122")){
at_return[at_con.type] = _OK;
flag = 1;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"Ok_Info_SocketClosed")){
at_return[at_con.type] = _ERR;
flag = 1;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"ERROR")){
at_return[at_con.type] = _ERR;
flag = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -