📄 gprs.c
字号:
Uart2Tx(buf,1);
isgprsnoservice =1;
gsc.Gprs_Simcard_bits.isconnecting = 0;
}
void SwitchToGprs(void)
{
if(gsmstatus.power==_GPRS_POWER_OFF)return;
if(gsmstatus.gprsdata!=FALSE)return;
if((gsmstatus.mode&INIT_OK)==0)return;
//if()//
#ifdef DEBUG_AT
Uart1Send("NOW SWITCH GPRS");
#endif
gsmstatus.mode |= INIT_OK; //modified by leon 050926 from gsmstatus.mode = 0;
gsmstatus.workmode = 2; //modified by leon 050921 from 1 to 2
InitSmsParamters();
Reset_GsmUart();
Init_Modem_Step = 8;
Init_To_Gprs();
}
//added by leon 051011 for Retry the OTCP session.
void RetryOTCP()
{
Init_Modem_Step = 17;
Init_To_Gprs();
}
void MonitorProc(void) //不同的工作状态//
{
static uchar status=0;
static uint prestatus=0;
uint sendstatus;
static uchar Bak_Register=0;
//uint temp;
Start_Timer(Moniter_Timer,8,SECOND);
sendstatus = 0;
if(save.basevalue.mode.bit.defend)
{
Set_Word_Bit(&sendstatus,9);
}
if(save.basevalue.mode.bit.private)
{
Set_Word_Bit(&sendstatus,8);
}
sendstatus |=(gsmstatus.signal<<4)&0xf0;
// if(gsmstatus.gprsstatus)
if(gsmstatus.gprsdata)//lxo 120611 for lcd display
{
Set_Word_Bit(&sendstatus,3);
}
if(save.basevalue.mode.bit.simid)
{
Set_Word_Bit(&sendstatus,2);
}
sendstatus |=gsmstatus.workmode&0x03;
//temp = gsmstatus.simid;
if(prestatus!=sendstatus)
{
#ifdef DEBUG_AT
// Uart1Send("send handset sendstatus:");
// Uart1Word(sendstatus);
#endif
Send_H05Msg(sendstatus);
prestatus = sendstatus;
}
if((gsmstatus.power == _GPRS_POWER_ON && at_atding!=1)&&(gsmstatus.gprsdata==FALSE && !isneedbacktogprs))
{
if(gsmstatus.mode&INIT_OK && !gsc.Gprs_Simcard_bits.isconnecting)
{
if(status<1)status++;
else status =0;
switch(status)
{
case 0:
At_Cmd_Ccid(NULL);//检查sim卡//
break;
case 1:
At_Cmd_Csq();
break;
}
}
}
if(gsmstatus.power!=_GPRS_POWER_ON||((gsmstatus.mode&INIT_OK)==0))
{
if(Bak_Register ==1)
{
Put_Led_Flash();
}
Bak_Register = 0;
}
else
{
if((gsmstatus.mode&0x70)==0)
{
if(Bak_Register ==0)
{
Put_Led_High();
}
Bak_Register = 1;
}
else
{
if(Bak_Register ==1)
{
Put_Led_Flash();
}
Bak_Register = 0;
}
}
if(gsmstatus.mode&NO_SIMCARD) //没有插卡//
{
}
else if(gsmstatus.mode&NO_REGISTER) //没有注册//
{
}
else if(gsmstatus.mode&NO_SIGNAL) //没有信号//
{
}
}
void Init_Gprs(void)
{
Init_Gprs_Data();
InitSmsParamters();
Init_GsmUart();
Voice_End();
Start_Init_Proc(0,0xff);
Init_Smsrecv();
Start_Timer(Moniter_Timer,10,SECOND);
}
void Wake_Up_Gprs(void)
{
Stop_Timer(Sleep_Gprs_Timer);
gsmstatus.wake = _GPRS_WAKE;
if(gsmstatus.power != _GPRS_POWER_ON)
{
#ifdef DEBUG_AT
Uart1Send("NEED TO WAKE GPRS");
#endif
gsmstatus.power = _GPRS_POWER_ON;
InitSmsParamters();
Reset_GsmUart();
Voice_End();
gsmstatus.mode = 0;
gsmstatus.workmode = 2; //added by leon 051021
Start_Init_Proc(0,0xff);
}
}
void Sleep_Gprs(void)
{
if(gsmstatus.wake != _GPRS_SLEEP)
{
#ifdef DEBUG_AT
Uart1Send("NEED TO SLEEP GPRS");
#endif
gsmstatus.wake = _GPRS_SLEEP;
Start_Timer(Sleep_Gprs_Timer,20,MINUTE);
}
}
uchar gsm_can_work(void)
{
if(gsmstatus.gprsdata==TRUE && gsmstatus.isupdate == TRUE) //modified by leon 050929
{
Uart1Send("IN gprsdata:");
Uart1Word(gsmstatus.gprsdata);
Uart1Word(gsmstatus.isupdate);
return FALSE;
}
if(gsmstatus.power != _GPRS_POWER_ON)
{
Uart1Send("IN power:");
Uart1Word(gsmstatus.power);
return FALSE;
}
if(gsmstatus.mode&0xf0)
{
Uart1Send("IN gsmstatus.mode:");
Uart1Word(gsmstatus.mode);
return FALSE;
}
else
{
return TRUE;
}
}
BOOL Check_Have_Sm(void)
{
if(SmBufHead!=SmBufTail)
return TRUE;
else
return FALSE;
}
BOOL Check_Sm_Full(void)
{
uchar temp;
temp = (SmBufHead+1)%MAXSMBUF;
if(temp==SmBufTail)
return TRUE;
else
return FALSE;
}
void SendSmsProc(void)
{
//Stop_Timer(Sms_Send_Timer);
if(at_return[_AT_CMGS]==_OK)
{
#ifdef DEBUG_AT
Uart1Send("send sms success");
#endif
if(SmBuf[SmBufTail].index==_INDEX_LCD || is_message_data)
{
Send_H06Msg(0x01);
if(is_message_data)
is_message_data =0;
}
else if(SmBuf[SmBufTail].index==_INDEX_SOS)
{
if(need_pull_led==1)
{
need_pull_led = 0;
Put_Led_High();
}
}
SmBufTail++;
if(SmBufTail>=MAXSMBUF) SmBufTail=0;
}
else
{
if(SmBuf[SmBufTail].index==_INDEX_LCD)
{
Send_H06Msg(0x0);
SmBufTail++;
if(SmBufTail>=MAXSMBUF) SmBufTail=0;
}
else
{
if(SmBuf[SmBufTail].attrib==_SMS_COMMON)
{
SmBufTail++;
if(SmBufTail>=MAXSMBUF) SmBufTail=0;
}
else
{
#ifdef DEBUG_AT
Uart1Send("need resend sms");
#endif
SmBuf[SmBufTail].time++;
if(SmBuf[SmBufTail].time>=2)
{
SmBufTail++;
if(SmBufTail>=MAXSMBUF) SmBufTail=0;
}
}
}
#ifdef DEBUG_AT
Uart1Send("send sms err by failure");
#endif
}
if(Check_Have_Sm())
{
At_Cmd_Cmgs(SmBuf[SmBufTail].buf,SmBuf[SmBufTail].len,SendSmsProc);
}
else
{
smssendstatus = _IDLE;
}
}
void SendSM(LPBYTE msg,WORD len,uchar isunicode,LPBYTE dstPhone,uchar attrib,uchar islcdmsg)
{
SM_PARAM far *buf;
uchar simid;
if(ring.ack !=0) //added by leon 051110
{
#ifdef DEBUG_AT
Uart1Send("it's ringing..can not send sms!");
#endif
return;
}
// if((gsmstatus.mode&INIT_OK)!=INIT_OK)//lxo 112801 for can not send sms when open tcp
if(((gsmstatus.mode&INIT_OK)!=INIT_OK)&&!(gsmstatus.workmode==2&&Init_Modem_Step>4))
{
if(islcdmsg==_INDEX_LCD)
{
Send_H06Msg(0);
}
#ifdef DEBUG_AT
Uart1Send("can't send sms");
#endif
if(alarm_flag&0xfe53)//added by lxo 021502
{
need_sendalarm_again = 1;
if(Hour24Remainder==0)//for 24 hours reset.
Hour24Remainder=(DWORD)(Get_Lefttime(Hour24_Send_Timer)/MINUTE);//for 24 hours reset.
Start_Timer(Hour24_Send_Timer,3,SECOND);
}
return;
}
if(save.basevalue.need_service==1)
{
if(islcdmsg!=_INDEX_LCD&&islcdmsg!=_INDEX_SPECIAL)
{
#ifdef DEBUG_AT
Uart1Send("don't need service");
#endif
return;
}
}
if((!gsm_can_work()))//can't send sms//
{
if(islcdmsg==_INDEX_LCD)
{
Send_H06Msg(0);
}
#ifdef DEBUG_AT
Uart1Send("can't send sms");
#endif
return;
}
if(gsmstatus.power != _GPRS_POWER_ON)
{
if(islcdmsg==_INDEX_LCD)
{
Send_H06Msg(0);
}
#ifdef DEBUG_SMS
Uart1Send("can't send sms");
#endif
return;
}
if(at_atding==1)
{
if(islcdmsg)
{
Send_H06Msg(0);
}
#ifdef DEBUG_SMS
Uart1Send("can't send sms");
#endif
return;
}
if(Check_Sm_Full())
{
#ifdef DEBUG_SMS
Uart1Send("out sms stack");
#endif
if(islcdmsg)
{
Send_H06Msg(0);
}
return;
}
buf=calloc(1,sizeof(SM_PARAM));
if(buf==NULL)
{
#ifdef DEBUG_AT
Uart1Send("can't allocate buf");
#endif
return;
}
#ifdef DEBUG_AT
Uart1Send("PUT IN SMS STACK");
#endif
simid = save.basevalue.mode.bit.simid; //added by leon 050919
_MemFillCpy(buf->SCA,save.phonenumber.MessageServiceNumb[simid]+1,'\0',16,_Strlen(save.phonenumber.MessageServiceNumb[simid],15)-1);
_Memcpy(buf->TP_UD,msg,len);
_MemFillCpy(buf->TPA,dstPhone,'\0',16,_Strlen(dstPhone,16));
if(isunicode>0)
{
#ifdef _HAVE_UNICODE
buf->TP_DCS=GSM_UCS2;
#else
buf->TP_DCS = GSM_7BIT;
#endif
}
else
{
buf->TP_DCS=GSM_8BIT;
}
buf->TPUD_len =len;
SmBuf[SmBufHead].len = gsmEncodePdu(buf, SmBuf[SmBufHead].buf,buf->TPUD_len);
SmBuf[SmBufHead].index = islcdmsg;
SmBuf[SmBufHead].attrib = attrib;
SmBuf[SmBufHead].time = 0;
SmBufHead++;
if(SmBufHead>=MAXSMBUF) SmBufHead=0;
free(buf);
#ifdef DEBUG_SMS
#endif
if(smssendstatus==_IDLE)
{
smssendstatus = _BUSY;
At_Cmd_Cmgs(SmBuf[SmBufTail].buf,SmBuf[SmBufTail].len,SendSmsProc);
}
}
void Hangup(void) //挂机//
{
At_Cmd_Ath();
gsmstatus.tel = _TEL_IDLE;
AutoDial.state = _IDLE;
gsmstatus.talkmode = _TALK_OFF;
ring.ack = 0; //added by leon 051101
Voice_End();
}
void Deal_Hangbyother(void) //拨号时被对方挂断//
{
#ifdef DEBUG_AT
// Uart1Send("Deal Hangup by other side.");
// Uart1Word(ring.ack);
// Uart1Word(gsmstatus.talkmode);
#endif
if(ring.ack==0)return;
ring.ack = 0;
if(gsmstatus.talkmode!= _TALK_ON)
{
Send_H09Msg(0x00);
Hangup();
}
}
void Pickup(void) //接电话//
{
if(gsmstatus.tel == _TEL_REDIAL)return;
if(gsmstatus.tel!=_TEL_IDLE)return;
if(save.basevalue.mode.bit.voice)
{
ToneSetting(save.basevalue.handvolume);
Voice_Sel(1);
}
else
{
ToneSetting(save.basevalue.volume);
Voice_Sel(2);
}
audio_status = 1;
gsmstatus.tel = _TEL_USER;
gsmstatus.talkmode = _TALK_ON;
At_Cmd_Ata();
}
void Dial(uchar *telptr,uchar tellen,uchar islcdtel,uchar monitor)
{
if((!gsm_can_work())||((gsmstatus.mode&0x0c)==0)||(gsmstatus.tel!=_TEL_IDLE)||AutoDial.state==_BUSY)
{
if(islcdtel)
{
Uart1Send("no telephone status:");
Uart1Word(gsmstatus.mode);
Uart1Word(gsmstatus.tel);
Uart1Word(AutoDial.state);
Send_H09Msg(0);
}
return;
}
if(monitor)
{
gsmstatus.tel = _TEL_MONITOR;
}
else
{
if(Need_Hangup())
{
if(islcdtel)
{
Uart1Send("need hangup:");
Uart1Word(alarm_flag);
Send_H09Msg(0);
}
return;
}
if(islcdtel)
{
Send_H09Msg(0x01);
gsmstatus.tel = _TEL_USER;
}
else
{
Send_H07Msg(telptr,tellen);
gsmstatus.tel = _TEL_REDIAL;
}
if(save.basevalue.mode.bit.voice)
{
ToneSetting(save.basevalue.handvolume);
}
else
{
ToneSetting(save.basevalue.volume);
}
}
if(gsmstatus.gprsdata == TRUE) //added by leon 051008
{
SwitchToAtCmd();
Start_Timer(Gprs_Service_Timer,1,MINUTE);
}
#ifdef DEBUG_AT
// Uart1Send(telptr);
#endif
At_Cmd_Atd(telptr,tellen);
}
void GprsTaskEntry(void)
{
Find_Proc(GPRSTASKPROC,Current_Tskmsg->msgid,sizeof(GPRSTASKPROC)/sizeof(ENTRY_PROC));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -