/******************************************************************************** * File Name: ModemTask.c * Function Describe: 完成串口与Modem的通讯 * Explain: * Writer: ShiLiangWen * Date: 2015-8-2 *******************************************************************************/ #define THIS_FILE_ID 8 /*******************************************************************************/ #include "includes.h" OS_TID idModemTask=0; U64 stkModemTask[MODEM_TASK_STK_SIZE]; OS_TID idModemUartTask=0; U64 stkModemUartTask[MODEM_UART_TASK_STK_SIZE]; OS_SEM ModemUartSem; SUT_MODEM_STATUS sutModemStatus; unsigned char g_ucModemTaskSleep=0; char ModemMsgQueueDataBuffer[MODEM_MSG_DATA_BUF_LEN]; SUT_MSG_QUEUE ModemMsgQueue; //---------------------------------------------------------- //---------------------------------------------------------- unsigned char g_ucModemTaskEn=0; unsigned char g_ucTestCodeSend = 0;//SendTest包的测量值标志码 unsigned char g_ucTestCodeRecv = 0;//SendTestAck包的测量值标志码 unsigned char g_ucSaveSetupAckResult = 0;// unsigned char g_ucReadTestAckResult = 0;// unsigned char g_ucSetControlAckResult = 0;// unsigned char g_ucSendTest = 0;// int SetControlRegNum=0; unsigned short atous(char *pMsg); M_RESULT SendPosition(void); /******************************************************************* *ModemUartTask ********************************************************************/ __task void ModemUartTask(void) { os_sem_init (&ModemUartSem, 0); while(1){ os_sem_wait (&ModemUartSem, 0xffff); tsk_lock (); Uart3RecvProcess(); tsk_unlock (); } } int CheckAKey(void) { char buf[15]; unsigned long akey; if(sutProductPara.PSN==0)return 1;//PSN=0 允许 akey = getAKeyByPSN(sutProductPara.PSN); if(akey!=sutProductPara.AKEY || sutProductPara.AKEY==0){ strcpy(buf,"ER"); strcat(buf,"ROR:A"); strcat(buf,"KN\r\n"); SlwTrace(DEBUG,buf);//ERROR:AKN return 0; } return 1; } /******************************************************************* *ConnectAppServer ********************************************************************/ M_RESULT ConnectAppServer(void) { SlwTrace(DEBUG,"ConnectAppServer>>\r\n"); return ModemOpenSocket(0,"TCP",sutProductPara.AppServer,sutProductPara.AppPort); } M_RESULT ConnectAuthServer(void) { SlwTrace(DEBUG,"ConnectAuthServer>>\r\n"); return ModemOpenSocket(AUTH_UDP_SOCKET,"UDP",sutProductPara.authServer,sutProductPara.authPort); } /******************************************************************* *ConnectFotaServer ********************************************************************/ M_RESULT ConnectFotaServer(void) { SlwTrace(DEBUG,"ConnectFotaServer>>\r\n"); return ModemOpenSocket(0,"TCP",sutProductPara.FotaServer,sutProductPara.FotaPort); } /* 发登陆包 */ M_RESULT SendLogin(void) { unsigned short len; SlwTrace(DEBUG,"SendLogin>>\r\n"); len=PacketLogin(sutModemStatus.CmdNum); return ModemSendToSocket(0,g_ucPropacketBuf,len); } /* 发当前点位置包 */ M_RESULT SendCurPosition(void) { char buf[30]; unsigned short i,len; SUT_POSITION sutPosition; SlwTrace(DEBUG,"SendTest>>\r\n"); memset(&sutPosition,0,sizeof(SUT_POSITION)); if(sutGpsInfo.isGpsValid)sutPosition.Status.GNSS=1; else sutPosition.Status.GNSS=0; sutPosition.Status.ACC=1; sutPosition.Status.BD=sutGpsInfo.isBDWork; sutPosition.Status.GPS=sutGpsInfo.isGpsWork; sutPosition.Status.West=sutGpsInfo.West; sutPosition.Status.South=sutGpsInfo.South; sutPosition.Latitude=sutGpsInfo.Latitude;//22620926;//114035268; //114.035268 sutPosition.Longitude=sutGpsInfo.Longitude; //114035268;//22620926; //22.620926 sutPosition.Speed=sutGpsInfo.Speed;//0; sutPosition.Aspect=sutGpsInfo.Aspect;//123; sutPosition.Altitude=sutGpsInfo.Altitude; RTC_Get(sutPosition.Time); sutPosition.ExtraMsgId=0x3A;//RT231项目固定0x3A sutPosition.NetMode=1;//4G sutPosition.CSQ =sutModemStatus.CSQ; sutPosition.Infrared=sutTestData.Infrared; sutPosition.Camera=sutTestData.Camera; for(i=0;i1){ // SlwTrace(DEBUG,"SendMorePosition>>\r\n"); // len=PacketMorePosition(sutModemStatus.CmdNum); // }else{ // SlwTrace(DEBUG,"SendOnePosition>>\r\n"); // if(StorageFiFoPop(&sutPosition)){ // len=PacketPosition(sutModemStatus.CmdNum,sutPosition); // } // } // return ModemSendToSocket(0,g_ucTcpSendBuf,len); //} /************************************************ NetProcess 每10ms执行一次 **************************************************/ void NetProcess(unsigned char reset) { int i; unsigned char AppIp[4]={0,0,0,0}; M_RESULT r; if(reset){ return; } //======= //===========以下控制每秒执行一次============ static U32 os_old_time=0; U32 os_cur_time=os_time_get(); if((os_cur_time-os_old_time)>100)os_old_time=os_cur_time; else return; //========================================= switch(sutModemStatus.Step){ case STEP_CARD: SlwTrace(DEBUG,"\r\n"); sutModemStatus.ServerStatus=CLOSED; r=ModemGetCardStatus(); if(SUCCEED==r){ sutModemStatus.ATTimeoutCt=0; sutModemStatus.CardStatus=OPENED; sutModemStatus.CheckCSQCt=0; sutModemStatus.RebootModemCt=0; sutModemStatus.Step=STEP_CSQ; }else if(FAIL==r){ sutModemStatus.ATTimeoutCt=0; sutModemStatus.CardStatus=CLOSED; if(++sutModemStatus.CheckCardCt>20){ ModemReboot(sutModemStatus.RebootModemCt++); } }else{//TIMEOUT sutModemStatus.CardStatus=CLOSED; if(++sutModemStatus.ATTimeoutCt>5){ sutModemStatus.ATTimeoutCt=0; ModemReboot(sutModemStatus.RebootModemCt++); } } break; case STEP_CSQ: SlwTrace(DEBUG,"\r\n"); sutModemStatus.ServerStatus=CLOSED; r=ModemGetCSQ(&sutModemStatus.CSQ); if(SUCCEED==r){ sutModemStatus.ATTimeoutCt=0; if(sutModemStatus.CSQ>1 && sutModemStatus.CSQ<32){ sutModemStatus.RebootModemCt=0; sutModemStatus.Step=STEP_CREG; }else if(++sutModemStatus.CheckCSQCt>20){ sutModemStatus.CheckCSQCt=0; sutModemStatus.Step=STEP_CARD; } }else{ sutModemStatus.Step=STEP_CARD; } break; case STEP_CREG: SlwTrace(DEBUG,"\r\n"); sutModemStatus.ServerStatus=CLOSED; r=WaitingForCReg(90); if(SUCCEED==r){ sutModemStatus.CregStatus=OPENED; sutModemStatus.Step=STEP_PDP; sutModemStatus.RebootModemCt=0; }else{//TIMEOUT sutModemStatus.CregStatus=CLOSED; ModemReboot(sutModemStatus.RebootModemCt++); if(sutModemStatus.RebootModemCt>6){ sutModemStatus.Step=STEP_CARD; } } break; case STEP_PDP: SlwTrace(DEBUG,"\r\n"); sutModemStatus.ServerStatus=CLOSED; r=ModemOpenPDP(); if(SUCCEED==r){ sutModemStatus.PDPStatus=OPENED; sutModemStatus.Step=STEP_QUERY_PDP; sutModemStatus.PDPCloseCt=0; sutModemStatus.RebootModemCt=0; }else if(FAIL==r){ sutModemStatus.PDPStatus=CLOSED; r=ModemClosePDP(); if(SUCCEED==r){ sutModemStatus.PDPCloseCt=0; sutModemStatus.Step=STEP_CREG; }else if(FAIL==r){ if(++sutModemStatus.PDPCloseCt>3){ sutModemStatus.PDPCloseCt=0; ModemReboot(sutModemStatus.RebootModemCt++); if(sutModemStatus.RebootModemCt>6){ sutModemStatus.RebootModemCt=0; sutModemStatus.Step=STEP_CARD; } } }else{//ModemClosePDP TIMEOUT sutModemStatus.PDPStatus=CLOSED; sutModemStatus.PDPCloseCt=0; ModemReboot(sutModemStatus.RebootModemCt++); if(sutModemStatus.RebootModemCt>6){ sutModemStatus.RebootModemCt=0; sutModemStatus.Step=STEP_CARD; } } }else{//ModemOpenPDP TIMEOUT sutModemStatus.PDPStatus=CLOSED; ModemReboot(sutModemStatus.RebootModemCt++); if(sutModemStatus.RebootModemCt>6){ sutModemStatus.RebootModemCt=0; sutModemStatus.Step=STEP_CARD; } } break; case STEP_QUERY_PDP://查询PDP状态 SlwTrace(DEBUG,"\r\n"); r=ModemQueryPDP(); if(SUCCEED==r){ if(authSocketStatus==0) sutModemStatus.Step=STEP_OPEN_USOCKET; }else if(FAIL==r){ sutModemStatus.Step=STEP_PDP; authSocketStatus=0; }else{//query timeout authSocketStatus=0; sutModemStatus.PDPStatus=CLOSED; ModemReboot(sutModemStatus.RebootModemCt++); if(sutModemStatus.RebootModemCt>6){ sutModemStatus.RebootModemCt=0; sutModemStatus.Step=STEP_CARD; } } break; case STEP_OPEN_USOCKET: SlwTrace(DEBUG,"\r\n"); r=ModemGetSocket(AUTH_UDP_SOCKET,10); if(r==FAIL){ r=ConnectAuthServer(); if(SUCCEED==r){ authSocketStatus=1; sutModemStatus.Step=STEP_QUERY_PDP; SlwTrace(DEBUG,"Connect server Ok!\r\n"); }else if(FAIL==r){ authSocketStatus=0; SlwTrace(DEBUG,"Connect server fail!\r\n"); sutModemStatus.Step=STEP_PDP; }else{ authSocketStatus=0; SlwTrace(DEBUG,"Connect server timeout!\r\n"); sutModemStatus.Step=STEP_PDP; } }else{ authSocketStatus=0; } break; #if 0 case STEP_DNS: SlwTrace(DEBUG,"\r\n"); unsigned char isSaveIP=0; if(SUCCEED==ModemGetIPbyDNS(sutProductPara.AppServer,AppIp)){ if(AppIp[0]!=sutServerIp.AppServerIP[0] || AppIp[1]!=sutServerIp.AppServerIP[1] || AppIp[2]!=sutServerIp.AppServerIP[2] || AppIp[3]!=sutServerIp.AppServerIP[3]){ for(i=0;i<4;i++)sutServerIp.AppServerIP[i]=AppIp[i]; isSaveIP=1; } if(SUCCEED==ModemGetIPbyDNS(sutProductPara.FotaServer,AppIp)){ if(AppIp[0]!=sutServerIp.FotaServerIP[0] || AppIp[1]!=sutServerIp.FotaServerIP[1] || AppIp[2]!=sutServerIp.FotaServerIP[2] || AppIp[3]!=sutServerIp.FotaServerIP[3]){ for(i=0;i<4;i++)sutServerIp.FotaServerIP[i]=AppIp[i]; isSaveIP=1; } sutModemStatus.Step=STEP_SOCKET; sutModemStatus.GetDNSCt=0; } if(isSaveIP){ SaveServerIP(); SlwTrace(DEBUG,"SaveServerIP\r\n"); } }else if(++sutModemStatus.GetDNSCt>5){ sutModemStatus.GetDNSCt=0; sutModemStatus.Step=STEP_SOCKET; } break; case STEP_SOCKET: SlwTrace(DEBUG,"\r\n"); sutModemStatus.ServerStatus=CLOSED; r=ModemGetSocket(0,10); if(r==FAIL){ sutModemStatus.SocketStatus=CLOSED; if(sutFotaPara.fotaStatus!=FOTA_END){ if(sutModemStatus.FoTaGetFileInfoCt<5){ sutModemStatus.FoTaGetFileInfoCt++; r=ConnectFotaServer(); }else{ sutFotaPara.fotaStatus=FOTA_END; ModemCloseSocket(0); return; } }else{ r=ConnectAppServer(); } if(SUCCEED==r){ sutModemStatus.SocketStatus=OPENED; sutModemStatus.Step=STEP_LOGIN; sutModemStatus.SocketStatus=OPENED; sutModemStatus.CmdNum=sutModemStatus.RecvCmdNum+1; sutModemStatus.CtrlReSendCt=5; SlwTrace(DEBUG,"Connect server succeed!\r\n"); }else if(FAIL==r){ sutModemStatus.SocketStatus=CLOSED; SlwTrace(DEBUG,"Connect server fail!\r\n"); ModemCloseSocket(0); sutModemStatus.Step=STEP_PDP; }else{ sutModemStatus.SocketStatus=CLOSED; SlwTrace(DEBUG,"Connect server timeout!\r\n"); ModemCloseSocket(0); sutModemStatus.Step=STEP_PDP; } }else{ sutModemStatus.SocketStatus=CLOSED; ModemCloseSocket(0); } break; case STEP_LOGIN: SlwTrace(DEBUG,"\r\n"); sutModemStatus.ServerStatus=CLOSED; //远程升级 if(sutFotaPara.fotaStatus==FOTA_GET_FILEINFO){ sutModemStatus.ServerStatus=CLOSED; if(++sutFotaPara.reSendCt>FOTA_RE_SEND_CT_MAX){ sutFotaPara.reSendCt=0; r=FoTaGetFileInfo(0); if(FAIL==r){ sutModemStatus.Step=STEP_SOCKET; }else if(TIMEOUT==r){ sutModemStatus.Step=STEP_CARD; } } if(sutModemStatus.SocketStatus==CLOSED){ sutModemStatus.Step=STEP_SOCKET; } return; }else if(sutFotaPara.fotaStatus==FOTA_GET_FILEDATA){ sutModemStatus.FoTaGetFileInfoCt=0; sutModemStatus.ServerStatus=OPENED; if(++sutFotaPara.reSendCt>FOTA_RE_SEND_CT_MAX){ sutFotaPara.reSendCt=0; r=FoTaGetFileData(0); if(FAIL==r){ sutModemStatus.Step=STEP_SOCKET; }else if(TIMEOUT==r){ sutModemStatus.Step=STEP_CARD; } } if(sutModemStatus.SocketStatus==CLOSED){ sutModemStatus.Step=STEP_SOCKET; } return; } //正常工作 sutModemStatus.ServerStatus=CLOSED; if(sutModemStatus.CmdNum!=sutModemStatus.RecvCmdNum){ if(++sutModemStatus.CtrlReSendCt>5){ sutModemStatus.CtrlReSendCt=0; r=SendLogin(); if(FAIL==r){ sutModemStatus.Step=STEP_SOCKET; }else if(TIMEOUT==r){ sutModemStatus.Step=STEP_CARD; } } }else{ if(sutModemStatus.UnauthorizedCt>0){ sutModemStatus.UnauthorizedCt--; if(sutModemStatus.UnauthorizedCt==0){ sutModemStatus.CmdNum=sutModemStatus.RecvCmdNum+1; } }else{ sutModemStatus.Step=STEP_SERVICE; sutModemStatus.CtrlIntervalSendCt=sutDeviceConfig.UploadInterval; } } if(sutModemStatus.SocketStatus==CLOSED){ sutModemStatus.Step=STEP_SOCKET; } break; case STEP_SERVICE: SlwTrace(DEBUG,"\r\n"); sutModemStatus.ServerStatus=OPENED; if(++sutModemStatus.CtrlIntervalSendCt>=sutDeviceConfig.UploadInterval || sutTestData.TcUpdated){ sutModemStatus.CtrlIntervalSendCt=0; sutModemStatus.CtrlReSendCt=5; sutModemStatus.CmdNum++; sutTestData.TcUpdated=0; } if(sutModemStatus.CmdNum!=sutModemStatus.RecvCmdNum){ if(++sutModemStatus.CtrlReSendCt>5){ sutModemStatus.CtrlReSendCt=0; r=SendCurPosition(); if(FAIL==r){ sutModemStatus.Step=STEP_SOCKET; }else if(TIMEOUT==r){ sutModemStatus.Step=STEP_CARD; } } } break; #endif } } /************************************************************* *将s转为数字 "123abc" --> 123 "123" --> 123 **************************************************************/ int stou(char *s) { int i; int j; char buf[6]; char d; for(i=0;i<5;i++){ d=s[i]; if(d>0x39 || d<0x30)break; buf[i]=d; } buf[i]=0; return atoi(buf); } //在“123,xxx" 这样的字符串里截取','前的数字转为整形出 unsigned short atous(char *pMsg) { int i=0; char data[6];//0~65535 char *p=pMsg; memset(data,0,6); while(*p){ if(*p==',')break; data[i++]=*p; if(i>5)break; p++; } if(*p==0)return 0; return atoi(data); } void TraceData(unsigned char *pData,unsigned short DataLen) { int i; char buf[10]; sprintf(buf,"[%d]",DataLen); SlwTrace(DEBUG,buf); if(DataLen>100)DataLen=100; for(i=0;i255)SlwTrace(DEBUG,"..."); SlwTrace(DEBUG,"\r\n"); } /******************************************************************* *AtHandle +QIURC: "recv",0,2\r\nXXXXXX +QIURC: "recv",0,20\r\nXXXXXXXXXXXXXXXXXXXX +QIURC: "recv",0,200\r\nXXXXXX +QIURC: "recv",0,2000\r\nXXXXXX ********************************************************************/ void AtHandle(char *pMsg,unsigned short MsgLen) { unsigned short UploadInterval,SamplingInterval; unsigned short AckID,AckNum; unsigned char Result; unsigned short NewVer; int cmd; int i; char buf[30]; unsigned char *pData; unsigned short len; unsigned char socket; if(ModemStrCmp(pMsg,"+QIURC: \"closed\",0")){ sutModemStatus.SocketStatus=CLOSED; return; } // if(MsgLen<20 || 1!=ModemStrCmp(pMsg,"+QIURC: \"recv\",")){ return; } socket=pMsg[15]-0x30; sutModemStatus.ServerOfflineCt=0; //+QIURC: "recv",0,25 len=atoi((char *)&pMsg[17]); if(len<1 || len>1035)return;//fota 一包数据最大可达1035bytes //printf("AtHandle=%d\r\n",MsgLen); if(len<10){//+QIURC: "recv",0,5\r\nXXX pData=(unsigned char *)&pMsg[20]; }else if(len<100){//+QIURC: "recv",0,25\r\nXXX pData=(unsigned char *)&pMsg[21]; }else if(len<1000){//+QIURC: "recv",0,255\r\nXXX pData=(unsigned char *)&pMsg[22]; }else{////+QIURC: "recv",0,1255\r\nXXX pData=(unsigned char *)&pMsg[23]; } //TraceData(pData,len); //FoTa升级接收数据处理 // if(sutFotaPara.fotaStatus!=FOTA_END){ // FoTaRecvData(pData,len); // return; // } // static unsigned char testdata[]={ // 0x7E,0x09,0x29,0x00,0x28,0x00,0x01,0x90,0x21,0x00,0x02,0x17,0x7D,0x01,0x52,0x54,0x4C,0x32,0x35,0x32, // 0x00,0x00,0x00,0x01,0x00,0x66,0xA6,0x94,0xDC,0xD8,0x38,0x39,0x38,0x36,0x30,0x37,0x42,0x33,0x31,0x35, // 0x31,0x37,0x33,0x30,0x34,0x38,0x37,0x33,0x37,0x35,0x00,0x05,0x00,0x05,0x8C,0x7E // }; // len=sizeof(testdata); // memcpy(pData,testdata,len); if(socket!=AUTH_UDP_SOCKET) return; //正常应用接收数据处理 cmd=CheckPacket(pData,len); if(cmd<0){ sprintf(buf,"CheckPacket Err=%d\r\n",cmd); SlwTrace(DEBUG,buf); return; } switch(cmd) { case AUTH_ACK_ID: //8930 0027 000123456789 0000 37ffd6054b543335504302430000000000000000000000000000000000000000 00 1f 04 6735d710 40 authBubiaoHandleRecv(pData+12); break; case 0x8200://上传应答 //pData=8001 0005 000000000000 0000 01 02 03 04 86 // ID 属性 设备编号 流水号 结果 红外使能 摄像头使能 复位使能 校验 SlwTrace(DEBUG,"<<[8001]\r\n"); AckNum=((unsigned short)pData[10]<<8) | pData[11]; sutModemStatus.RecvCmdNum=AckNum; if(pData[12]!=0){//结果 0--成功 return; }; sutTestData.InfraredEn=pData[13]; sutTestData.CameraEn=pData[14]; sutTestData.ResetEn=pData[15]; sprintf(buf,"IEn=%02X CEn=%02X REn=%02X\r\n",sutTestData.InfraredEn,sutTestData.CameraEn,sutTestData.ResetEn); SlwTrace(DEBUG,buf); break; case 0x8929://登陆应答 //pData=8929 000E 000190210001 0018 190217142738 01 00 0000 0500 0500 01 // ID Len 编码 流水号 时间 验证 升级 新版本 采样间隔 上传间隔 校验 SlwTrace(DEBUG,"<<[8929]\r\n"); AckNum=((unsigned short)pData[10]<<8)|pData[11]; sutModemStatus.RecvCmdNum=AckNum; RTC_Set(&pData[12]); //鉴权结果 0--成功 >0 未成功需要继续等N分钟再重新登陆 sutModemStatus.UnauthorizedCt=(unsigned short)pData[18]*60; if(sutModemStatus.UnauthorizedCt>0){ SlwTrace(DEBUG,"Unauthorized!\r\n"); sprintf(buf,"UCt=%d\r\n",sutModemStatus.UnauthorizedCt); SlwTrace(DEBUG,buf); } #if 0 //升级测试 *(pData+19)=1; *(pData+20)=0; *(pData+21)=108; #endif if(pData[19]==1){//使能升级 NewVer=((unsigned short)pData[20]<<8)|pData[21]; if(NewVer!=0 && NewVer>sutProductPara.SoftwareVer && sutModemStatus.FoTaGetFileInfoCt<5){ sprintf(buf,"CurVer=%d NewVer=%d\r\n",sutProductPara.SoftwareVer,NewVer); SlwTrace(DEBUG,buf); SlwTrace(DEBUG,"Upgrade now!\r\n"); sutFotaPara.targetVersion=NewVer; sutFotaPara.fotaStatus=FOTA_GET_FILEINFO; ModemCloseSocket(0); sutModemStatus.Step=STEP_SOCKET; return; }else{ sutModemStatus.FoTaGetFileInfoCt=0; } }else sutModemStatus.FoTaGetFileInfoCt=0; UploadInterval=((unsigned short)pData[22]<<8)|pData[23]; SamplingInterval=((unsigned short)pData[24]<<8)|pData[25]; if((sutDeviceConfig.UploadInterval!=UploadInterval&& UploadInterval>=5) || (sutDeviceConfig.SamplingInterval!=SamplingInterval && SamplingInterval>=5)){ sutDeviceConfig.UploadInterval=UploadInterval; sutDeviceConfig.SamplingInterval=SamplingInterval; SaveDeviceConfigToFlash(); } break; } } /* 等多久后重启 */ void WaitForReboot(unsigned short time) { char buf[30]; unsigned short t=time; while(t--){ sprintf(buf,"WaitForReboot...%d\r\n",t); SlwTrace(DEBUG,buf); os_dly_wait(100); } SlwTrace(DEBUG,"WillBeReboot!\r\n"); while(1); } /* 根据IMEI号后9位数转成unsigned long型号 */ unsigned long getAsnByIMEI(char *pIMEI) { char buf[10]; int i; for(i=0;i<9;i++){ buf[i]=pIMEI[6+i]; } buf[9]=0; return atol(buf); } /******************************************************************* *ModemTask ********************************************************************/ __task void ModemTask(void) { unsigned long ASN; int i,j; char *p; char temp[22]; int r; RunMake(THIS_FILE_ID); unsigned char sim_card_check_ct=0; SlwTrace(DEBUG,"ModemTask Start...\r\n"); memset(&sutModemStatus,0,sizeof(SUT_MODEM_STATUS)); NetProcess(1); //空中升级初始化 MyFoTaInit(); sutModemStatus.WorkStatus=CLOSED; MODEM_TASK_BEGIN: sutModemStatus.CardStatus=CLOSED; sutModemStatus.CregStatus=CLOSED; sutModemStatus.PDPStatus=CLOSED; sutModemStatus.SocketStatus=CLOSED; sutModemStatus.ServerStatus=CLOSED; //初始化模块 if(SUCCEED!=ModemInit()){ SlwTrace(DEBUG,"Will be reboot!\r\n"); while(1); } sutModemStatus.OnceWorked=1; //检查SIM是否在位 for(i=0;i<20;i++){ if(SUCCEED==ModemGetCardStatus())break; } if(i==20){ SlwTrace(DEBUG,"SIM card not ready!reboot and check again!\r\n"); ModemReboot(sutModemStatus.RebootModemCt); if(sutModemStatus.RebootModemCt<50)sutModemStatus.RebootModemCt++; goto MODEM_TASK_BEGIN; } sutModemStatus.RebootModemCt=0; sutModemStatus.CardStatus=OPENED; //获取CCID SlwTrace(DEBUG,"Get ICCID...\r\n"); memset(temp,0,sizeof(temp)); for(i=0;i<5;i++){ if(SUCCEED==ModemGetCCID(temp))break; os_dly_wait(100); } if(i<5){ if(0!=strcmp(sutDeviceConfig.CCID,temp)){ strncpy(sutDeviceConfig.CCID,temp,sizeof(sutDeviceConfig.CCID)); SaveDeviceConfigToFlash(); } } while(1) { if(g_ucModemTaskSleep){ os_dly_wait(0xffff); continue; }else{ os_dly_wait(1); } r=MsgQueueAccept(&ModemMsgQueue,ModemMsgBuf,sizeof(ModemMsgBuf)); if(r>0){ sutModemStatus.UartInactiveCt=0; ModemMsgBuf[r]=0; SlwTrace(DEBUG,ModemMsgBuf);//打印MODEM信息 AtHandle(ModemMsgBuf,r); //sprintf(buf,"Remaining MsgNum=%d\r\n",Uart3MsgQueue.MsgNum); //SlwTrace(DEBUG,buf); }else if(r<0){ // sprintf(buf,"ModemMsgBuf Over![%d]\r\n",r); SlwTrace(DEBUG,"ModemMsgBuf Over!\r\n"); // }else if(g_ucUARTSel!=COM_SEL_MODEM){ } if(g_ucUARTSel!=COM_SEL_MODEM){ // ModemSendAuthReqHandle(); NetProcess(0); } } } /*******************************************************************************/