📄 gsmuart.c
字号:
{
Send_At(_AT_CCID,NULL,0,proc);
}
void At_Cmd_CGREG(void far (*proc)()) //added by leon 050928
{
Send_At(_AT_CGREG,NULL,0,proc);
}
/*
void At_Cmd_HangGPRS(void far(* proc)()) //added by leon 051011
{
Send_At(_AT_HANGGPRS,NULL,0,proc);
}
void At_Cmd_AnswerMode(void far (*proc)()) //added by leon 050926
{
Send_At(_AT_ANSWERMODE,NULL,0,proc);
}
void At_Cmd_CallScreenNum(void far (*proc)()) //added by leon 050926
{
Send_At(_AT_CALLSCREENNUM,NULL,0,proc);
}
void At_Cmd_RingCount(void far (*proc)()) //added by leon 050926
{
Send_At(_AT_RINGCOUNT,NULL,0,proc);
}
void At_Cmd_Accept(void far (*proc)()) //added by leon 050928
{
Send_At(_AT_ACCEPT,NULL,0,proc);
}
*/
uchar Is_Gprs_Data(void)
{
return gsmstatus.gprsdata;
}
uchar FindAtCmd0D0A(void)
{
uint i,j;
uchar *ptr;
ptr = at_con.recvbuf;
i = gsmuart.head;
j = 0;
while(i!=gsmuart.tail)
{
ptr[j++] = gsmuart.recvbuf[i++];
if(i>=MAXGSMRECVBUFFER)i = 0;
if(ptr[j-1]=='>')
{
gsmuart.head = i;
at_con.recvlen = j;
return TRUE;
}
if(j>1)
if((ptr[j-1]==0x0a&&ptr[j-2]==0x0d)) //recieve 0x0d 0x0a
{
gsmuart.head = i;
at_con.recvlen = j;
return TRUE;
}
if(j>=MAX_GSM_RECV) //数据长度超过
{
gsmuart.head = i;
j = 0;
}
}
return FALSE;
}
void Deal_Inform(void)
{
if(at_con.type==_AT_NONTYPE)
{
Stop_Timer(At_Over_Timer);
Abort_At_Cmd();
return;
}
if(at_con.type>_AT_MAX_TYPE)
{
Abort_At_Cmd();
return;
}//错误返回//
if(Get_Lefttime(At_Over_Timer)==0) //overtime//
{
at_con.result = _AT_RECV_OVERTIME;
}
if(AT_CMD[at_con.type].proc!=NULL)
{
AT_CMD[at_con.type].proc();
}
}
void Deal_Creg(void)
{
uchar index;
uchar mode;
uchar creg;
creg = 0;
index = Find_Pos(at_con.recvbuf,at_con.recvlen,':',1)+2;
creg = at_con.recvbuf[index]-'0';
if(gsmstatus.mode&INIT_OK)
{
if(creg==1||creg==5)
{
Clr_Char_Bit(&gsmstatus.mode,5);
}
else
{
Set_Char_Bit(&gsmstatus.mode,5);
}
}
}
void Deal_Cmti(void)
{
uchar buf[7];
uchar len;
uchar index;
uchar i;
i=0;
index = Find_Pos(at_con.recvbuf,at_con.recvlen,',',1)+1;
while(at_con.recvbuf[index]!=0x0d)
{
buf[i++] = at_con.recvbuf[index++];
}
if((gsmstatus.mode&INIT_OK)==0)return;
At_Cmd_Cmgr(buf,i);
}
void Deal_Wind(void)
{
uint event;
uint index;
#ifdef DEBUG_AT
Uart1Send("recv a wind");
#endif
event = 0;
index = Find_Pos(at_con.recvbuf,at_con.recvlen,':',1)+1;
while(at_con.recvbuf[index]!=','&&at_con.recvbuf[index]!=0x0d)
{
if(at_con.recvbuf[index]>='0'&&at_con.recvbuf[index]<='9')
{
event *= 10;
event += at_con.recvbuf[index]-'0';
}
index ++;
}
switch(event)
{
case 0:
Set_Char_Bit(&gsmstatus.mode,6);
break;
case 1:
Clr_Char_Bit(&gsmstatus.mode,6);
break;
case 3://added by lxo 122901 for wavecom modem reset during reopen tcp after dail.
#ifdef DEBUG_AT
Uart1Send("recv a wind:3");
#endif
if(at_con.type!=_AT_NONTYPE)
{
Reset_GsmUart();
Init_Modem_Step = 3;
Init_Gprs_Proc();
}
break;
case 4:
break;
case 5:
break;
case 6:
Hangup();
break;
case 9:
if(audio_status==1)break;
audio_status = 1;
if(gsmstatus.tel ==_TEL_MONITOR)
{
Voice_Sel(3);
}
else if(gsmstatus.tel ==_TEL_USER||gsmstatus.tel==_TEL_REDIAL)
{
if(save.basevalue.mode.bit.voice)
{
Voice_Sel(1);
}
else
{
Voice_Sel(2);
}
}
break;
}
}
void Deal_Clip(void)
{
uint index;
uint index1;
uchar buf[5];
if(isneedbacktogprs ==TRUE)
{
Hangup();
buf[0] = 'A';
buf[1] = 'T';
buf[2] = 'O';
buf[3] = 0x0d;
buf[4] = 0x0a;
Uart2Tx(buf,5);
gsmstatus.gprsdata = TRUE;
isneedbacktogprs = FALSE;
return;
}
if(save.basevalue.phone_mode==0||save.basevalue.phone_mode==0x03) //(alarm_flag&0xfe53 ||gsmstatus.isupdate==TRUE)||
{
Hangup();
return;
}
if(Hand_Power==_HAND_OFF)
{
Wake_Once_Handset();
return;
}
if(at_con.result==_AT_RECV_RING&&ring.clip==0)
{
if(ring.ack==0)
{
#ifdef DEBUG_AT
Uart1Send("recv a call");
#endif
ring.ack = 1;
AutoPickup();
}
if(ring.ack==1)
{
Send_H07Msg(NULL,0);
}
ring.time = 0;
}
if(at_con.result==_AT_RECV_CLIP)
{
ring.clip = 1;
if(ring.ack ==0)
{
ring.ack = 1;
#ifdef DEBUG_AT
Uart1Send("recv a tel call");
#endif
AutoPickup();
}
if(ring.ack==1)
{
index = Find_Pos(at_con.recvbuf,at_con.recvlen,'"',1)+1;
index1 = Find_Pos(at_con.recvbuf,at_con.recvlen,'"',2);
Send_H07Msg(at_con.recvbuf+index,index1-index);
}
ring.time = 0;
}
}
void Deal_Telephone(void)
{
uchar temp =0;
uchar fail =0;
if(at_con.type==_AT_ATD)return;
if(Str_Find(at_con.recvbuf,at_con.recvlen,"NO CARRIER"))
{
fail = 1;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"NO ANSWER"))
{
fail = 1;
temp = 4;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"BUSY"))
{
fail = 1;
temp = 3;
}
if(fail==1)
{
if(gsmstatus.tel ==_TEL_USER||gsmstatus.tel==_TEL_REDIAL)
{
Send_H09Msg(temp);
}
Hangup();
}
}
uchar Findgprs0D0A(void)
{
uint i,j;
uchar *ptr;
uchar ch;
uint len;
//uchar simid;
static uchar count =0;
ptr = at_con.recvbuf;
i = gsmuart.head;
j = 0;
while(i!=gsmuart.tail)
{
ch = gsmuart.recvbuf[i++];
if(i>=MAXGSMRECVBUFFER)i = 0;
if(ch==0x03&&count==0)
{
//gsmstatus.workmode = 0; //modified by leon 050921
#ifdef DEBUG_AT
Uart1Send("Got 0x03 in Findgprs0D0A!");
#endif
gsmstatus.gprsdata = FALSE;
if(gsmstatus.isupdate) //added by leon
{
if(!need_connect_update)
{
gsmstatus.isupdate = FALSE;
_MemFillCpy(cur_sim.IpAddr,gprsmode_sim.IpAddr,'\0',16,_StrlenForKey(gprsmode_sim.IpAddr,'\0',16));
_MemFillCpy(cur_sim.SocketPort,gprsmode_sim.SocketPort,'\0',6,_StrlenForKey(gprsmode_sim.SocketPort,'\0',6));
}
}
/*//lxo 112401 for reconnect after initialize the factory configure
if(port[_ACC].status == 0)
{
if(monitor_times > 20)
isgprsnoservice = 1;
else
isgprsnoservice = 0;
}
else
isgprsnoservice = 1;
*/
isgprsnoservice = 1;//lxo 112402 for reconnect after initialize the factory configure when accoff;
//simid = save.basevalue.mode.bit.simid; //added by leon 050919
//At_Cmd_Csca(save.phonenumber.MessageServiceNumb[simid],_Strlen(save.phonenumber.MessageServiceNumb[simid],15));
Start_Timer(Gprs_Service_Timer,30,SECOND);
return FALSE;
}
if(ch==0x10&&count==0)
{
count = 1;
}
else
{
count = 0;
ptr[j++] = ch;
}
if(j>1)
if(ptr[0]=='@'&&ptr[1]=='@')
{
if(j>=4)
{
len = ptr[2]+ptr[3]*256;
if(j==len)
{
gsmuart.head = i;
at_con.recvlen = j;
#ifdef DEBUG_AT
Uart1Send("RECV VALID BUF in GPRS mode");
#endif
return TRUE;
}
}
}
else
{
if((ptr[j-1]==0x0a&&ptr[j-2]==0x0d)) //recieve 0x0d 0x0a
{
gsmuart.head = i;
at_con.recvlen = j;
#ifdef DEBUG_AT
Uart1Send("RECV INVALID BUF in GPRS mode");
#endif
return TRUE;
}
}
if(j>=MAX_GSM_RECV) //数据长度超过//
{
gsmuart.head = i;
j = 0;
}
}
return FALSE;
}
//void Send_Gprsdata(uchar *ptr,uint len)//adjusted by lxo 1227081
void Send_Gprsdata(uchar far *ptr,uint len)//adjusted by lxo 1227082
{
uchar buf[2];
uint i;
//uint j;
if(gsmstatus.gprsdata==FALSE)
{
#ifdef DEBUG_AT
Uart1Send("NOT GPRSMODE");
#endif
return;
}
for(i=0; i<len; i++)
{
if(ptr[i]==0x10||ptr[i]==0x03)
{
buf[0] = 0x10;
buf[1] = ptr[i];
Uart2Tx(buf,2);
}
else
{
Uart2Tx(ptr+i,1);
}
}
}
void Gsmuart_Recv(void)
{
uchar sms_point=0;
uchar simid;
if(gsmstatus.gprsdata == TRUE) //GPRS DATA
{
//Uart1Send("Gsmuart Recv in GPRS MODE:");
while(Findgprs0D0A())
{
#ifdef DEBUG_AT
Uart1SendHex(at_con.recvbuf,at_con.recvlen);
//hand_send(at_con.recvbuf,at_con.recvlen);
#endif
Send_Taskmsg(GprsTaskid,RECV_ONE_GPRS,at_con.recvbuf);
}
}
else //GSM DATA OR AT CMD RESPONSE
{
while(FindAtCmd0D0A()) //
{
#ifdef DEBUG_AT
hand_send(at_con.recvbuf,at_con.recvlen);
#endif
if(at_con.recvbuf[0]==0x0d&&at_con.recvbuf[1]==0x0a)continue;
if(recv_cmt==1)
{
recv_cmt=0;
smsrecv[0]=gsmString2Bytes(at_con.recvbuf,&smsrecv[1],at_con.recvlen-2);
sms_point = Get_Free_Sms_Point();
if(sms_point!=0xff)
{
_Memset(sms_store[sms_point].smsdata, 0,200);
_Memcpy(sms_store[sms_point].smsdata,smsrecv,smsrecv[0]+1);
sms_store[sms_point].isvalid =1;
#ifdef DEBUG_AT
// Uart1Send("the sms point is :");
// Uart1Word(sms_point);
// Uart1SendHex(smsrecv,200);
// Uart1Send(" ");
// Uart1SendHex(sms_store[sms_point].smsdata,200);
#endif
Start_Timer(Recv_Sms_Timer,1,HMSEL);
}
//Send_Taskmsg(GprsTaskid,RECVONESMS,smsrecv);
}
if(Str_Find(at_con.recvbuf,at_con.recvlen,"RING"))
{
#ifdef DEBUG_AT
Uart1Send("recv ring");
#endif
if(!gsc.Gprs_Simcard_bits.isconnecting) //added by leon 050929
{
at_con.result=_AT_RECV_RING;
Deal_Clip();
}
else
Hangup();
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"+CREG:"))
{
Deal_Creg();
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"+CMTI:"))
{
Deal_Cmti();
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"+WIND:"))
{
Deal_Wind();
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"+CLIP:"))
{
if(!gsc.Gprs_Simcard_bits.isconnecting) //added by leon 050929
{
at_con.result=_AT_RECV_CLIP;
Deal_Clip();
}
else
Hangup();
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"+CMT:"))
{
recv_cmt = 1;
}
else if(Str_Find(at_con.recvbuf,at_con.recvlen,"Ok_Info_SocketClosed"))
{
gsmstatus.gprsdata = FALSE;
gsmstatus.mode |= INIT_OK;
if(need_set_messagenumber&&!isneedbacktogprs)
{
need_set_messagenumber = 0;
simid = save.basevalue.mode.bit.simid; //added by leon 050919
At_Cmd_Csca(save.phonenumber.MessageServiceNumb[simid],_Strlen(save.phonenumber.MessageServiceNumb[simid],15));
}
if(need_connect_update)
{
need_connect_update = 0;
#ifdef DEBUG_AT
Uart1Send("Current IP Port is:");
Uart1Word(gsmstatus.isupdate);
hand_send(cur_sim.SocketPort,6);
#endif
SwitchToGprs();
}
if(need_start_connect)
{
need_start_connect = 0;
isgprsnoservice = 1; //add lxo 112301 for reconnect after accoff
Gprs_Service_Proc();
}
}
else
{
if(at_con.type!=_AT_NONTYPE)
{
Deal_Inform();
}
Deal_Telephone();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -