123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- /********************************************************************************
- * File Name: MW3650GpsTask.h
- * Function Describe: Header file for MW3650GpsTask.c
- * Explain:
- * Writer:
- * Date: 2016-3-11
- *******************************************************************************/
- #include "includes.h"
- unsigned char resetModem=0;
- /*************************************************
- 部标处理
- *****************************************************/
- void MW3600TSHandle(char *pMsg)
- {
- // int i;
- // static int flag =0;
- // static int flag1 =0;
- // static int flag2 =0;
- // char *pTemp;
- // static unsigned char buf[28];
- // unsigned char d,h,l;
- // static char name[16]={0};
- // static int name1[16]={0};
- /////////////////////////////////
- // char buf1[5];
- // unsigned short smsLen;
- /////////////////////////////////
- // SUT_MODEM_AT_MSG *Msg;
- // if(pMsg[61]=='0'){ //00注册 01 车辆已注册 02无此车辆 03 终端已经被注册 04 数据库无此终端
- // pTemp=(char *)&(pMsg[62]);
- // for(i=0;i<14;i++){//34
- // // SlwTrace(DEBUG,(char *)pTemp);
- // if(*pTemp==EOF){
- // pTemp++;
- // break;
- // }
- // name[i]=*pTemp++;
- // }
- // for(i =0; i < 7; i++)//14位变成16进制所以两位变成一位所以相应变成一半
- // {
- // sscanf(name+2*i,"%2x",&name1[i]);
- // sutProductPara.AutH[i]=name1[i];
- // SaveProductParaToFlash();
- // }
- // flag1++;
- // if(1 == flag1){
- // flag1 +=1;
- // Authentication(name1); //注册后 每次发送鉴权消息 去握手链接
- // if(0==ModemStrCmp(pMsg,"^IPRECV:")){
- // if(pMsg[8]=='1'){
- // if((pMsg[61]=='1')&&(pMsg[63]=='2')){
- // TSGpsTimingSendPos();
- // _free_box(AtMpool,Msg);
- // }
- // }
- // }
- // }
- // _free_box(AtMpool,Msg);
- // }
- // ///////////////////////////消息/////////////
- // //^IPRECV:1,183.131.13.6,1395,0,7E8300000500016600000900000131323334ED7E
- // else if(pMsg[32] == '8' && pMsg[33] == '3')
- // {
- // if(0==ModemStrCmp(pMsg,"^IPRECV:"))
- // {
- // memcpy(buf1, pMsg+36, 4);
- // buf1[4] = 0;
- // smsLen = strtol(buf1, NULL, 16);
- // if(SMS_SIGNAL_LEN <= smsLen)
- // smsLen = SMS_SIGNAL_LEN;
- // GBKTostr(pMsg+58,sutMess.GBKMess1,smsLen);
- // sutMess.GBKMess1[smsLen] = 0;//最后一个补0
- // sutMess.len = smsLen;
- // if(sutMess.len > 1)
- // SetGotNewMessage();
- // }
- // }
- // ////////////////////////////////////////
- // else{
- // for(i = 0; i < 7; i++){//14
- // name1[i]= (unsigned char)sutProductPara.AutH[i];
- // }
- // flag2++;
- // if(1 == flag2){
- // flag2 +=1;
- // Authentication(name1);
- // }
- // _free_box(AtMpool,Msg);//多清一次
- // if(0==ModemStrCmp(pMsg,"^IPRECV:")){
- // if((pMsg[61]=='1')&&(pMsg[63]=='2')){
- // TSGpsTimingSendPos();
- // _free_box(AtMpool,Msg);
- // }
- // if(0==ModemStrCmp(pMsg,"^IPRECV:")){
- // if((pMsg[61]=='2')&&(pMsg[63]=='0')){
- // _free_box(AtMpool,Msg);
- // }
- // }
- // }
- // _free_box(AtMpool,Msg);
- // }
- // _free_box(AtMpool,Msg);
- }
- void MW3650AtHandle(char *pMsg)
- {
- SUT_MODEM_AT_MSG *Msg;
- int csq, i;
- static int flag =0;
- static int flag1 =0;
- static int flag2 =0;
- char *pTemp;
- static unsigned char buf[28];
- unsigned char d,h,l;
- static char name[16]={0};
- static int name1[16]={0};;
- if(0==ModemStrCmp(pMsg,"+CSQ:")){
- csq=GetCSQ(pMsg);
- if(csq>=0 && csq<100)g_iCSQ=csq;
- }
- else if(0==ModemStrCmp(pMsg,"^IPCALL:")){
- //^IPCALL:1,10.6.3.217
- //^IPCALL: 0
- //SlwTrace(DEBUG,"IPCALL!");
- if(pMsg[8]=='1'){
- sutGpsStatus.PPPStatus=OPEN;
- /////////////////////
- if(resetModem == 2)
- {
- resetModem=3;
- ModemSendAT("ATE0\r\n");
-
- }else if(resetModem == 3)
- {
- resetModem = 4;
- }else if(resetModem == 4)
- {
- resetModem=0;
- ModemSendAT(POC_CMD_PPT_STOP);
- }
- //////////////////////
- }else{
- sutGpsStatus.PPPStatus=CLOSE;
- }
- }else if(0==ModemStrCmp(pMsg,"^IPOPEN:")){
- //^IPOPEN:1,0,183.131.13.6,1391 --已连接
- //^IPOPEN: 0 --已断开
- if(pMsg[8]=='1'){
- sutGpsStatus.IPStatus=OPEN;
- sutGpsInfo.isServerLogin = OPEN;
- // if(TimeFlag==0){
- // ModeGetTime();//获取时间 文工说只有IP通了 才正确
- // TimeFlag+=1;
- // }
- flag++;
- if(1==flag){
- flag+=1;
- Registration();// 先关了
- }
- // if(TimeFlag==0){
- // ModeGetTime();//获取时间 文工说只有IP通了 才正确
- // TimeFlag+=1;
- // }
- // ModemSendAT("AT^IPSEND=1,\"2929B100075986B38300590D\"\r\n");
- }else{
- sutGpsStatus.IPStatus=CLOSE;
- }
- }else if(0==ModemStrCmp(pMsg,"^IPRECV:")){
- if(pMsg[8]=='1'){
- RecvModemData(pMsg);
- MW3600TSHandle(pMsg);
- // SlwTrace(DEBUG,"HELLO IPRECV!");
- }else{
- sutGpsInfo.isServerLogin = 0;
- }
- //sutGpsInfo.isServerLogin = OPEN;
-
- //^IPRECV:1,183.131.13.6,1391,0,292921000559B100CC0D
- if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&Msg,1)){ //
- if(0==ModemStrCmp((char *)Msg->MsgData,"^IPRECV:")){ //
- //sutGpsInfo.isServerLogin = OPEN;
- SlwTrace(INF,(char *)Msg->MsgData); //
- _free_box(AtMpool,Msg); //
- }
-
- }
- }
- else if(0==ModemStrCmp(pMsg, "^IPSTAT:"))
- {
- if(pMsg[10] == '1')//SOCKET BROKEN
- {
- if(IapPra.FOTA_IS_ON == 0)
- {
- resetModem = 1;
- sutGpsStatus.PPPStatus=CLOSE;
- }else//空中升级中
- {
- IapPra.timeTry = 0;//重置重传数
- IapPra.resetModemTime ++;
- if(IapPra.resetModemTime >=3)
- {
- IapPra.resetModemTime=0;
- resetModem = 1;
- sutGpsStatus.PPPStatus=CLOSE;
- }
- }
- }
- }
- /////////////////END CALL //////////////////////
- else if(0 == ModemStrCmp(pMsg, "+ZCEND"))
- {
- g_ucCallPhonePro = 2;//tell end call
- }
- // }else if(0==ModemStrCmp(pMsg,"+ZPPPSTATUS:")){
- // sutGpsStatus.PPPStatus=GetPPPStatus(pMsg);
- // }else if(0==ModemStrCmp(pMsg,"+ZIPSTATUS:")){
- // sutGpsStatus.IPStatus=GetIPStatus(pMsg);
- // }else if(0==ModemStrCmp(pMsg,"+ZIPRECV:")){
- // RecvModemData(pMsg);
- // }else if(0==ModemStrCmp(pMsg,"+ZIPSEND:")){
- //
- // }else if(0==ModemStrCmp(pMsg,"^IPCALL:1,10")){
- // sutGpsStatus.PPPStatus=GetIPStat(pMsg);
- // }
- }
- /************************************************
- 每10ms处理一次
- **************************************************/
- void MW3650GpsTaskTick(unsigned char reset)
- {
- static unsigned char sucSecCt=0;
- static unsigned char sucSteep=0;
- static unsigned char sucSynSentCt=0;
- unsigned char temp[4];
-
- char buf[50];
- int i;
- SUT_MODEM_AT_MSG *pMsg;
- if(reset){
- sucSecCt=0;
- sucSteep=0;
- return;
- }
- #ifdef GPS_ENABLE
- //GPS Uart消息处理
- if(g_usUart2RecvLen){
- process_nema((char *)RxBuffer2);
- g_usUart2RecvLen=0;
- }
- #endif
- //===========以下控制每秒执行一次============
- if(++sucSecCt>99)sucSecCt=0;
- else return;
- //=========================================
- if(sutGpsInfo.isGpsWork!=0){//GPS模块未正常工作!不发送数据,也可能是无GPS版本
- GpsCtrlSendPos();
- }
- //TCP发送防护,如果IPSTATUS一直等于SYN_SENT持续达10秒,则关闭TCP链路
- if(sutGpsStatus.IPStatus==SYN_SENT){
- if(++sucSynSentCt>10){
- sucSynSentCt=0;
- sutGpsInfo.isServerLogin=0;
- g_ucModemSentTcpCt=0;
- sutGpsStatus.IPStatus=CLOSE;
- g_ucModemSentTcpCt=0;
- sutGpsInfo.isServerLogin=0;
- }
- }else sucSynSentCt=0;
- //---以下控制---
- if(++sucSteep>4)sucSteep=0;
- //----
- if(sucSteep==0){
- ModemSendAT("AT+CSQ\r\n");
- //用来测试16进制转化的代码
- //temp[0]=0xAB;temp[1]=0x12;temp[2]=0xEF;temp[3]=0xCD;
- //HexToStr(temp,buf,4);
- // buf[9]=0;
- // SlwTrace(INF,buf);
- }
- //#ifdef GPS_ENABLE //关了
- /***********************************
- **int i;
- **SUT_MODEM_AT_MSG *pMsg;
- **for(i=0;i<10;i++){
- ** if(ModemSendAT2WaitAckMsg("AT+CPIN?\r\n","+CPIN: READY",&pMsg,100)){
- ** _free_box(AtMpool,pMsg);
- ** return 1;
- ** }
- }
- ***********************************/
- else if(1==sucSteep){
- ModemSendAT("AT^IPCALL?\r\n");
- //for(i=0;i<10;i++){//+
- //if(ModemSendAT2WaitAckMsg("AT^IPCALL=1,""\"\",""\"\"\r\n","^IPCALL:",&pMsg,100)){ //AT^IPCALL=1,"",""
- //_free_box(AtMpool,pMsg);
- //}
- //os_dly_wait(20);
- // ModemSendAT("AT^IPCALL=1,""\"\",""\"\"\r");
- // if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&pMsg,1)){
- // if(0==ModemStrCmp((char *)pMsg->MsgData,"^IPCALL")){
- // SlwTrace(INF,(char *)pMsg->MsgData);
- // _free_box(AtMpool,pMsg);
- // }
- // }
- //}
- }else if(2==sucSteep){
- if(99==g_iCSQ)return;
- if(sutGpsStatus.PPPStatus!=OPEN){
- ModemSendAT("AT^IPCALL=1,""\"\",""\"\"\r\n");
- }
- //for(i=0;i<10;i++){//+
- //if(ModemSendAT2WaitAckMsg("AT^IPCALL?\r\n","^IPCALL:",&pMsg,100)){ //AT^IPCALL?
- //_free_box(AtMpool,pMsg);//+
-
- // }
- //}//+
- /* if(sutGpsStatus.PPPStatus==OPEN){
- //SlwTrace(DEBUG,"AT+ZIPSTATUS=0\r\n");
- ModemSendAT("AT+ZIPSTATUS=0\r");
- //if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&pMsg,1)){ //+
- // if(0==ModemStrCmp((char *)pMsg->MsgData,"^IPCALL")){ //+
- // SlwTrace(INF,(char *)pMsg->MsgData); //+
- // SUT_MODEM_AT_MSG *Msg;
- //while(timeout){
- //if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&Msg,1)){
- //SlwTrace(DEBUG,(char *)Msg->MsgData);
- }else{
- os_dly_wait(20);
-
- //SlwTrace(DEBUG,"AT+ZPPPOPEN\r\n");
- //ModemSendAT("AT+ZPPPOPEN\r");
- //int i,t=10;//+
- // int t =10;
- //SUT_MODEM_AT_MSG *pMsg;//+
- //while(t--){//+
- if(ModemSendAT2WaitAckMsg("AT^IPOPEN=1,9501,\"183.131.13.6\",1391,0\r\n","^IPOPEN:1,1",&pMsg,100)){ //AT^IPCALL=1,......
- _free_box(AtMpool,pMsg);//+
- SlwTrace(INF,"AT^IPOPEN=OK\r\n");
- }
- // }
-
- // ModemSendAT("AT^IPOPEN=1,9501,\"183.131.13.6\",1391,0\r\n");
- // if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&pMsg,10)){
- // if(0==ModemStrCmp((char *)pMsg->MsgData,"^IPOPEN:1,1")){
- // SlwTrace(INF,"AT^IPOPEN=OK\r\n");
- // SlwTrace(INF,(char *)pMsg->MsgData);
- // _free_box(AtMpool,pMsg);
- // }
- // }
- os_dly_wait(50);
- if(ModemSendAT2WaitAckMsg("AT^IPSEND=1,\"4142\"\r\n","^IPSEND:",&pMsg,100)){ //AT^IPCALL?
- _free_box(AtMpool,pMsg);//+
- }
-
- }*/
- }else if(3==sucSteep){
- if(99==g_iCSQ){
- return;
- }
- if(sutGpsInfo.isGpsWork==0){
- SlwTrace(INF,"GPS modem not work!\r\n");
- return;
- }
-
- if(sutGpsStatus.IPStatus!=OPEN && sutGpsStatus.PPPStatus==OPEN){
- sutGpsInfo.isServerLogin=0; //0
- //AT^IPOPEN=1,9501,"183.131.13.6",1391,0
- //"AT^IPOPEN=1,9501,\"183.131.13.6\",1391,0\r\n"
- sprintf(buf,"AT^IPOPEN=1,9501,\"%s\",%d,0\r\n",sutProductPara.GIP,sutProductPara.GpsPort);
- SlwTrace(DEBUG,buf);
- ModemSendAT(buf);
- }
-
- }else if(4==sucSteep){
- if(99==g_iCSQ)return;
-
- if(sutGpsInfo.isGpsWork==0)return;
- //AT^IPSEND=1,"2929b100075986b38300590d"
-
- if(sutGpsStatus.IPStatus==OPEN && 0==sutGpsInfo.isServerLogin){
-
- TSGpsServerConect();
- }
- }
- }
- void Modem3650CheckReset(void)
- {
- if(resetModem==1)
- {
- SlwTrace(INF, "Reset Module\r\n");
- sutGpsStatus.PPPStatus=CLOSE;
- ResetModem();
- resetModem = 2;
- }
- }
|