123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665 |
- /********************************************************************************
- * File Name: MainTask.c
- * Function Describe:The main task for the system
- * Relate Module:
- * Explain: Hardware version is HS121
- * Writer: ShiLiangWen
- * Date: 2015.7.8
- *******************************************************************************/
- #define THIS_FILE_ID 7
- //---------------------------------------------------------------------------------
- #include "includes.h"
- //OS ID
- OS_TID idMainTask=0;
- U64 stkMainTask[MAIN_TASK_STK_SIZE];
- U32 g_ulSysTick=0;
- SUT_POSITION sutPosition;
- unsigned char g_ucUart1Activated=0;
- void FingerDaemonfinger(void);
- //======================================
- //-----
- #ifdef USE_RUNNING_MAKE
- void RunningMake(unsigned short FileID,unsigned long line)
- {
- g_usFileID=FileID;
- g_ulFileLine=line;
- }
- #endif
- unsigned short g_usFileID=0;
- unsigned long g_ulFileLine=0;
- unsigned char g_ucSystemReset=0;
- /***********************************************
- 强制复位
- ************************************************/
- void SystemReboot(void)
- {
- g_ucSystemReset=1;
- SlwTrace(DEBUG,"System reboot now!\r\n");
- while(1);
- }
- /*************************************************************************
- 拷贝数据,并判断与原数据是否相同
- 相同返回0
- 不同返回1
- **************************************************************************/
- unsigned char CopyData(unsigned char *pDst,unsigned char *pSrc,unsigned char len)
- {
- unsigned char i;
- unsigned char flag=0;
- for(i=0;i<len;i++){
- if(*pDst!=*pSrc){
- flag=1;
- *pDst=*pSrc;
- }
- pDst++;
- pSrc++;
- }
- return flag;
- }
- /*
- */
- unsigned char AscToHex(unsigned char aHex)
- {
- if((aHex>=0)&&(aHex<=9))
- aHex += 0x30;
- else if((aHex>=10)&&(aHex<=15))//A-F
- //aHex += 0x37;
- aHex += 0x57;
- else aHex = 0xff;
- return aHex;
- }
- void AscStrToHexStr(char *AscStr, char *HexStr)
- {
- char *pAscStr=AscStr;
- unsigned char d,h,l;
- while(0!=(d=(unsigned char)*pAscStr++)){
- l=d&0x0f;
- h=d>>4;
- *HexStr++=AscToHex(h);
- *HexStr++=AscToHex(l);
- }
- *HexStr=0;
- }
- void PcMsgHandle(char *msg)
- {
- const char *CmdList[]={
- "TM", //调试Modem
- "TG", //调试GPS
- "DEBUGLOG",//打印LOG
- "SSIM", //设置SIM卡配置信息
- "RSIM", //读取SIM卡配置信息
- "RVER",//读取版本号
- "RSERVER",//读取服务器信息
- "SETID",//设置PSN和AKEY
- "RPSN",//读PSN
- "REBOOT",//重启
- // "TEST",
- // "FASTTEST",
- // "GNSS",
- "RPNAME",
- "SPNAME",
- "RDNAME",
- "SDNAME",
- "RASER",
- "SASER",
- ""//必须以空字串为结束
- };
- char needsave=0;
- unsigned short Port;
- unsigned long PSN,AKEY;
- char buf[150];
- char tracebuf[50];
- char bufIP[6];
- //char strAccount[20];
- //char strPassword[20];
- int i,j,temp,len;
- char flag;
- const char *pCmd;
- char *pMsg;
- int CmdListNum=0;
- RunMake(THIS_FILE_ID);
- pMsg = msg;
- while(*CmdList[CmdListNum++]);//计算命令列表个数
- CmdListNum--;
- RunMake(THIS_FILE_ID);
- //查找与命令列表相同的命令位置
- for(i=0;i<CmdListNum;i++){
- pCmd=CmdList[i];
- pMsg=&msg[3];
- flag=0;
- j=0;
- while(*pCmd){
- if(*pCmd!=*pMsg){
- flag=1;
- break;
- }
- pCmd++;
- pMsg++;
- j++;
- }
- if(!flag){
- break;
- }
- }
- RunMake(THIS_FILE_ID);
- if(i==CmdListNum)return;
- //处理命令
- switch(i)
- {
- case 0://"RT+TM"
- SlwTrace(INF,"RT+TM:OK\r\n");
- ComSelect(COM_SEL_MODEM);
- break;
- case 1://"RT+TG"
- SlwTrace(INF,"RT+TG:OK\r\n");
- ComSelect(COM_SEL_GPS);
- break;
- case 2://"RT+DEBUGLOG"
- if(sutDeviceConfig.DebugPrintEn == 0){
- SlwTrace(INF,"RT+DEBUGLOG:ON\r\n");
- sutDeviceConfig.DebugPrintEn=1;
- }else{
- SlwTrace(INF,"RT+DEBUGLOG:OFF\r\n");
- sutDeviceConfig.DebugPrintEn=0;
- }
- SaveDeviceConfigToFlash();
- break;
- case 3://RT+SSIM=APN=CMNET;NAME=card;PASS=card;
- len=GetParaFromStr(msg,"APN",buf);
- if(len<1 || len>=20){
- SlwTrace(INF,"RT+SSIM:FAIL[APN Invalid]\r\n");
- break;
- }else strcpy(sutProductPara.CardAPN,buf);
- len=GetParaFromStr(msg,"NAME",buf);
- if(len<1 || len>=20){
- SlwTrace(INF,"RT+SSIM:FAIL[NAME Invalid]\r\n");
- break;
- }else strcpy(sutProductPara.CardUsrName,buf);
-
- len=GetParaFromStr(msg,"PASS",buf);
- if(len<1 || len>=20){
- SlwTrace(INF,"RT+SSIM:FAIL[PASS Invalid]\r\n");
- break;
- }else{
- strcpy(sutProductPara.CardUsrPass,buf);
- }
-
- SaveProductParaToFlash();
- SlwTrace(INF,"Set SIM Info OK!\r\n");
-
- break;
- case 4://RT+RSIM
- sprintf(buf,"APN=%s;USR=%s;PASS=%s\r\n",sutProductPara.CardAPN,sutProductPara.CardUsrName,sutProductPara.CardUsrPass);
- SlwTrace(INF,buf);
- break;
- case 5://RT+RVER
- sprintf(buf,"HVer=%d SVer=%d\r\n",sutProductPara.HardwareVer,sutProductPara.SoftwareVer);
- SlwTrace(INF,buf);
- break;
- case 6://RT+RSERVER
- sprintf(buf,"AppS:%s:%d\r\n",sutProductPara.AppServer,sutProductPara.AppPort);
- SlwTrace(INF,buf);
- sprintf(buf,"ServerIP:%d.%d.%d.%d:%d\r\n",sutServerIp.AppServerIP[0],sutServerIp.AppServerIP[1],sutServerIp.AppServerIP[2],sutServerIp.AppServerIP[3],sutProductPara.AppPort);
- SlwTrace(INF,buf);
- sprintf(buf,"FotaS:%s:%d\r\n",sutProductPara.FotaServer,sutProductPara.FotaPort);
- SlwTrace(INF,buf);
- sprintf(buf,"FotaIP:%d.%d.%d.%d:%d\r\n",sutServerIp.FotaServerIP[0],sutServerIp.FotaServerIP[1],sutServerIp.FotaServerIP[2],sutServerIp.FotaServerIP[3],sutProductPara.FotaPort);
- SlwTrace(INF,buf);
- break;
- case 7://RT+SETID=PSN=190310005;AKEY=1412652393
- len=GetParaFromStr(msg,"PSN",buf);
- if(len<1 || len>10){
- SlwTrace(INF,"RT+SETID:FAIL[PSN Invalid]\r\n");
- break;
- }
- PSN=atoll(buf);
- if(PSN==0){
- SlwTrace(INF,"RT+SETID:FAIL[PSN Invalid]\r\n");
- break;
- }
-
- len=GetParaFromStr(msg,"AKEY",buf);
- if(len<1 || len>10){
- SlwTrace(INF,"RT+SETID:FAIL[AKEY Invalid]\r\n");
- break;
- }
- AKEY=atoll(buf);
-
- if(AKEY!=getAKeyByPSN(PSN)){
- SlwTrace(INF,"PSN=0\r\n");
- return;
- }
- sutProductPara.PSN = PSN;
- sutProductPara.AKEY = AKEY;
- memset(sutProductPara.DeviceID,0,sizeof(sutProductPara.DeviceID));
- DecToBCD(sutProductPara.PSN,&sutProductPara.DeviceID[1],5);
- sutProductPara.MAC[0]=((MY_MAC_HEAD&0xFF0000)>>16);
- sutProductPara.MAC[1]=((MY_MAC_HEAD&0x00FF00)>>8);
- sutProductPara.MAC[2]=((MY_MAC_HEAD&0x0000FF));
- sutProductPara.MAC[3]=((sutProductPara.PSN&0xFF0000)>>16);
- sutProductPara.MAC[4]=((sutProductPara.PSN&0x00FF00)>>8);
- sutProductPara.MAC[5]=(sutProductPara.PSN&0x0000FF);
- SaveProductParaToFlash();
- ReadProductParaFromFlash();
- sprintf(buf,"PSN=%lu\r\nAKEY=%lu\r\n",sutProductPara.PSN,sutProductPara.AKEY);
- SlwTrace(INF,buf);
- sprintf(buf,"DeviceID=%x%02x%02x%02x%02x\r\n",sutProductPara.DeviceID[1],sutProductPara.DeviceID[2],
- sutProductPara.DeviceID[3],sutProductPara.DeviceID[4],sutProductPara.DeviceID[5]);
- SlwTrace(INF,buf);
-
- sprintf(buf,"MAC=%02X.%02X.%02X.%02X.%02X.%02X\r\n",sutProductPara.MAC[0],sutProductPara.MAC[1],sutProductPara.MAC[2],
- sutProductPara.MAC[3],sutProductPara.MAC[4],sutProductPara.MAC[5]);
- SlwTrace(INF,buf);
- break;
- case 8://RT+RPSN
- sprintf(buf,"PSN=%ld\r\n",sutProductPara.PSN);
- SlwTrace(INF,buf);
- break;
- case 9://REBOOT
- SystemReboot();
- break;
- #if 0
- case 10://TEST
- // sprintf(buf,"RTC:%d-%d-%d %d:%d:%d\r\n",sutRTC.Years,sutRTC.Months,sutRTC.Days,sutRTC.Hours,sutRTC.Minute,sutRTC.Seconds);
- // SlwTrace(INF,buf);
- // if(sutGpsInfo.isGpsValid){
- // sprintf(buf,"GPS:[A] lat=%ld lng=%ld\r\n",sutGpsInfo.Latitude,sutGpsInfo.Longitude);
- // }else{
- // sprintf(buf,"GPS:[V] lat=%ld lng=%ld\r\n",sutGpsInfo.Latitude,sutGpsInfo.Longitude);
- // }
- // SlwTrace(INF,buf);
-
- if(!sutGpsInfo.isGpsValid){//GPS模块未定位
- SlwTrace(INF,"Test:GPS Fail!\r\n");
- }else if(sutWLanStatus.Step<WL_STEP_IDEL){//网络模块DHCP未分配内网IP
- SlwTrace(INF,"Test:RJ45 Fail!\r\n");
- }else if(sutModemStatus.ServerStatus!=OPENED){//4G模块未登陆过服务器
- SlwTrace(INF,"Test:4G Fail!\r\n");
- }else SlwTrace(INF,"Test:OK!\r\n");
- break;
- case 11://FASTTEST
- if(!sutGpsInfo.isGpsWork){//GPS模块未工作
- SlwTrace(INF,"FastTest:GPS Error!\r\n");
- }else if(sutWLanStatus.Step<WL_STEP_GET_PHYLINK){//网络模块未工作
- SlwTrace(INF,"FastTest:RJ45 Error!\r\n");
- }else if(sutModemStatus.OnceWorked==0){//4G模块未曾工作过
- SlwTrace(INF,"FastTest:4G Error!\r\n");
- }else SlwTrace(INF,"FastTest:OK!\r\n");
- break;
- case 12://GNSS
- sprintf(buf,"GNSS=%lu,%lu\r\n",sutGpsInfo.Longitude,sutGpsInfo.Latitude);
- SlwTrace(INF,buf);
- //sprintf(buf,"GNSS=%0.6f,%0.6f\r\n",(double)sutGpsInfo.Longitude/1000000.0,(double)sutGpsInfo.Latitude/1000000.0);
- //SlwTrace(INF,buf);
- break;
- #endif
- case 10://RPNAME
- sprintf(buf, "RPNAME=%s\r\n", sutProductPara.proName);
- SlwTrace(INF, buf);
- break;
- case 11://RT+SPNAME=
- memset(sutProductPara.proName, 0, sizeof(sutProductPara.proName));
- for(i=0;i<strlen(msg);i++) if(msg[i]=='\r') msg[i]=0;
- len=strlen(msg+10);
- if(len>=sizeof(sutProductPara.proName)) len=sizeof(sutProductPara.proName)-1;
- memcpy(sutProductPara.proName, msg+10,len);
- SaveProductParaToFlash();
- SlwTrace(INF, "RT+SPNAME:OK\r\n");
- break;
- case 12://RDNAME
- sprintf(buf, "RDNAME=%s\r\n", sutProductPara.devName);
- SlwTrace(INF, buf);
- break;
- case 13://SDNAME
- memset(sutProductPara.devName, 0, sizeof(sutProductPara.devName));
- for(i=0;i<strlen(msg);i++) if(msg[i]=='\r') msg[i]=0;
- len=strlen(msg+10);
- if(len>=sizeof(sutProductPara.devName)) len=sizeof(sutProductPara.devName)-1;
- memcpy(sutProductPara.devName, msg+10,len);
- SaveProductParaToFlash();
- SlwTrace(INF, "RT+SDNAME:OK\r\n");
- break;
- case 14://RASER
- sprintf(buf, "RT+RASER=%s,%d\r\n", sutProductPara.authServer, sutProductPara.authPort);
- SlwTrace(INF, buf);
- break;
- case 15://SASER
- len=GetParaFromStr(msg,"IP",buf);
- if(len<1 || len>=20){
- SlwTrace(INF,"RT+SASER:FAIL[IP Invalid]\r\n");
- break;
- }else{
- if(0!=strcmp(sutProductPara.authServer, buf)){
- strcpy(sutProductPara.authServer,buf);
- needsave=1;
- }
- }
-
- len=GetParaFromStr(msg,"Port",buf);
- if(len<1 || len> 5){
- SlwTrace(INF,"RT+SASER:FAIL[Port Invalid]\r\n");
- break;
- }else{
- if(sutProductPara.authPort != atoi(buf)){
- sutProductPara.authPort=atoi(buf);
- needsave=1;
- }
- }
- if(needsave != 0) SaveProductParaToFlash();
- snprintf(buf, sizeof(buf), "RT+SASER:IP=%s;Port=%d\r\n", sutProductPara.authServer, sutProductPara.authPort);
- SlwTrace(INF, buf);
- break;
- }
- RunMake(THIS_FILE_ID);
-
-
- //AB CD E5 02 54 4D 32 5C
- if(msg[0]=='T' && msg[1]=='M'){//0x544D
- printf("----TM----\r\n");
- ComSelect(COM_SEL_MODEM);
- }
- }
- void ShowHex(unsigned char *pData,unsigned char len)
- {
- char temp[5];
- char buf[100];
- int i;
- if(len>(sizeof(buf)-3))len=(sizeof(buf)-3);
- buf[0]=0;
- for(i=0;i<len;i++){
- sprintf(temp,"%02X",(int)pData[i]);
- strcat(buf,temp);
- }
- strcat(buf,"\r\n");
- SlwTrace(DEBUG,buf);
- }
- /*******************************************************************
- *MainTask
- *主任务
- ********************************************************************/
- __task void MainTask(void)
- {
- int r;
- char tracebuf[20];
- unsigned char SecCt=0;
- static unsigned char sucRefreshTimeCt=0;
- static unsigned long lastTick=100;
- unsigned long curTick;
- //Obtain own system task identification number. */
- idMainTask = os_tsk_self();
- ReadProductParaFromFlash();//读取产品参数
- Uart1Init(0);
- //SPI FLASH init...
- if(!AT25DF_Init()){
- SecCt=20;
- SlwTrace(DEBUG,"sFlash Failed!");
- while(SecCt--){
- os_dly_wait(50);
- FEED_EXTWATCHDOG();//喂狗
- }
- }
- ReadDeviceConfigFromFlash();//读取设备配置参数
- ReadServerIP();
- //StorageFiFoInit();
- //Led Init
- LedInit();
- SlwTrace(DEBUG," \r\nMain Task Start!\r\n");
- /////////////////
- //testAKeyByPSN();
- //鉴权
- // if(sutProductPara.AKEY!=getAKeyByPSN(sutProductPara.PSN)){
- // while(1){
- // os_dly_wait(1);
- // if(g_usUart1RecvLen){
- // if(RxBuffer1[0]=='R' && RxBuffer1[1]=='T' && RxBuffer1[2]=='+'){//处理电脑发过来的RT指令数据包
- // PcMsgHandle((char *)RxBuffer1);
- // }
- // g_usUart1RecvLen=0;
- // }
- // curTick=os_time_get();
- // if(curTick>lastTick){
- // lastTick=curTick+100;
- // } else continue;
- // FEED_EXTWATCHDOG();//喂狗
- // IWDG_ReloadCounter();//喂狗
- // sprintf(tracebuf,"%c%c%c%c%s",'U','N','A','!',"\r\n");//Unauthorized
- // SlwTrace(DEBUG,tracebuf);
- // if(sutProductPara.AKEY==getAKeyByPSN(sutProductPara.PSN))break;
- // }
- // }
- /////////////////
- //GPS初始化
- // GpsInit();
-
- //trace
- SlwTrace(DEBUG,sutProductPara.ProductName);
- sprintf(tracebuf,"_V%d\r\n",sutProductPara.SoftwareVer);
- SlwTrace(DEBUG,tracebuf);
- sprintf(tracebuf,"PSN=%lu\r\n",sutProductPara.PSN);
- SlwTrace(DEBUG,tracebuf);
- FEED_EXTWATCHDOG();
- idModemUartTask=os_tsk_create_user(ModemUartTask,4,&stkModemUartTask,sizeof(stkModemUartTask));
- FEED_EXTWATCHDOG();
- idModemTask=os_tsk_create_user(ModemTask,3,&stkModemTask,sizeof(stkModemTask));
- FEED_EXTWATCHDOG();
- //idWLanTask=os_tsk_create_user(WiredLanTask,2,&stkWLANTask,sizeof(stkWLANTask));
- FEED_EXTWATCHDOG();
- RunMake(THIS_FILE_ID);
- authNewInit();
- while(1)
- {
- //----以下每10ms执行一次----
- os_dly_wait(1);
- //处理TG和TM模式下 PC<-->GPS 或 PC<-->Modem
- if(g_ucUARTSel==COM_SEL_GPS || g_ucUARTSel==COM_SEL_MODEM){
- r=MsgQueueAccept(&ModemMsgQueue,ModemMsgBuf,sizeof(ModemMsgBuf));
- if(r>0){
- sutModemStatus.UartInactiveCt=0;
- ModemMsgBuf[r]=0;
- if(g_ucUARTSel==COM_SEL_GPS){
- IWDG_ReloadCounter();//喂狗
- FEED_EXTWATCHDOG();//喂狗
- Uart1Send((char *)ModemMsgBuf,r);
- FEED_EXTWATCHDOG();//喂狗
- }else{
- Uart1Send((char *)ModemMsgBuf,r);
- }
- }
- if(g_ucUARTSel==COM_SEL_MODEM && g_usUart1RecvLen>0){
- Uart3Send((char *)RxBuffer1,g_usUart1RecvLen);
- g_usUart1RecvLen=0;
- }
- }else if(g_usUart1RecvLen){//正常模式下,处理UART1发过来的命令
- if(RxBuffer1[0]=='R' && RxBuffer1[1]=='T' && RxBuffer1[2]=='+'){//处理电脑发过来的RT指令数据包
- PcMsgHandle((char *)RxBuffer1);
- g_ucUart1Activated=1;
- }else authHandleData(CHL_UART1,RxBuffer1, g_usUart1RecvLen);
- RxBuffer1[0]=0;
- g_usUart1RecvLen=0;
- }
- #if 0
- //处理GPS发过来的数据
- if(g_usRx2Len>0){
- process_nema((char *)RxBuffer2);
- memset(RxBuffer2,0,sizeof(RxBuffer2));
- g_usRx2Len=0;
- GpsConversionTime();
- // if(sutGpsInfo.isGpsValid){
- // printf("GPS[A]=%ld,%ld,%d,%d\r\n",sutGpsInfo.Latitude,sutGpsInfo.Longitude,sutGpsInfo.Speed,sutGpsInfo.Aspect);
- // }else{
- // printf("GPS[V]=%ld,%ld,%d,%d\r\n",sutGpsInfo.Latitude,sutGpsInfo.Longitude,sutGpsInfo.Speed,sutGpsInfo.Aspect);
- // }
- //printf("GPS:%02X%02X%02X %02X%02X%02X\r\n",sutGpsInfo.year,sutGpsInfo.month,sutGpsInfo.day,sutGpsInfo.hour,sutGpsInfo.minu,sutGpsInfo.sec);
- //printf("GPS:%02d-%02d-%02d %02d:%02d:%02d\r\n",sutGpsInfo.Years,sutGpsInfo.Months,sutGpsInfo.Days,sutGpsInfo.Hours,sutGpsInfo.Minute,sutGpsInfo.Seconds);
- if(sutGpsInfo.Years>2000){
- if(sutRTC.Seconds>sutGpsInfo.Seconds)r=sutRTC.Seconds-sutGpsInfo.Seconds;
- else r=sutGpsInfo.Seconds-sutRTC.Seconds;
- if(sutRTC.Years!=sutGpsInfo.Years || r>3){
- tsk_lock();
- sutRTC.Years=sutGpsInfo.Years;
- sutRTC.Months=sutGpsInfo.Months;
- sutRTC.Days=sutGpsInfo.Days;
- sutRTC.Hours=sutGpsInfo.Hours;
- sutRTC.Minute=sutGpsInfo.Minute;
- sutRTC.Seconds=sutGpsInfo.Seconds;
- tsk_unlock();
- }
- }
- }
- #endif
- //控制指示灯
- LedProcess(0);
- //防护进程
- FingerDaemonfinger();
- //---以下控制每秒执行1次----
- curTick=os_time_get();
- if(curTick>lastTick){
- lastTick=curTick+100;
- } else continue;
- //指示灯设置
- SetLedIndicator();
- //RTC加1秒
- RTCIncSecond();
- //存储控制
- //StorageCtrlSavePos();
- }
- }
- /*******************************************************************
- *GetParaFromStr
- *从Str中找到Para=后面至';'或非字符的字串并放入Value
- 返回Value的长度
- 举例:Str="GT+SMP=IP=192.168.1.1;Port=12345"
- 如果Para="Port" 则Value将被赋值为"12345",并返回5
- 如果Para="IP" 则Value将被赋值为"192.168.1.1",并返回11
- 要求Para长度不大于20字节 ,Value长度不大于40字节
- ********************************************************************/
- int GetParaFromStr(char *Str,char *Para,char *Value)
- {
- int ValueLen=0,ParaLen=0;
- char ParaTemp[22];
- char *p;
- char d;
- int i=0;
- if(0==*Str || 0==*Para)return 0;
- while(0!=(d=*Para) && ParaLen<20){
- ParaTemp[i++]=d;
- if(d=='=' || d==';')return 0;
- Para++;
- ParaLen++;
- }
- ParaTemp[ParaLen++]='=';
- ParaTemp[ParaLen]=0;
- p=strstr(Str,ParaTemp);
- if(p==0)return 0;
- p+=ParaLen;
- //--
- while(*p>0x20 && ';'!=*p && ValueLen<40){
- *Value=*p;
- p++;
- Value++;
- ValueLen++;
- }
- *Value=0;
- return ValueLen;
- }
- /*************************************************************************************
- FingerDaemonfinger
- 守护进程
- 用于防止通讯模块死机,或者与通讯模块通讯的串口异常而重新启动模块或通讯驱动。
- 此函数需要确保每秒调用一次
- **************************************************************************************/
- void FingerDaemonfinger(void)
- {
- int i;
- int OffLineMax;
- static unsigned char ext_dog_flag=0;
- //以下控制每秒执行一次,喂狗则0.5秒一次
- static U32 os_old_time=0;
- U32 os_cur_time,os_def_time;
- os_cur_time=os_time_get();
- os_def_time=os_cur_time-os_old_time;
- if(g_ucSystemReset==1)return;//g_ucSystemReset被设置为1 将不再喂狗,会导致MCU系统复位
-
-
- if(os_def_time>100){
- os_old_time=os_cur_time;
- }else{
- if(os_def_time<50){
- if(ext_dog_flag==0){
- ext_dog_flag=1;
- FEED_EXTWATCHDOG();//喂狗
- IWDG_ReloadCounter();//喂狗
- }
- }else{
- if(ext_dog_flag==1){
- ext_dog_flag=0;
- FEED_EXTWATCHDOG();//喂狗
- IWDG_ReloadCounter();//喂狗
- }
- }
- return;
- }
- if(g_ucUARTSel!=COM_SEL_MCU)return;//非正常模式下不防护
- //串口1防护
- if(sutTestData.OnceRecvFlag){//曾经收到过,5分钟防护
- if(++sutTestData.RecvIdelCt>300){
- sutTestData.RecvIdelCt=0;
- SlwTrace(DEBUG,"Uart1RxIdelTimeout!\r\n");
- os_tsk_delete(idModemTask);
- ModemSendAT("AT+QPOWD\r\n");
- os_dly_wait(1000);
- SystemReboot();
- }
- }else{//未曾收到过,1小时防护
- // if(++sutTestData.RecvIdelCt>3600){
- // sutTestData.RecvIdelCt=0;
- // SlwTrace(DEBUG,"Uart1RxIdelTimeout!\r\n");
- // os_tsk_delete(idModemTask);
- // ModemSendAT("AT+QPOWD\r\n");
- // os_dly_wait(1000);
- // SystemReboot();
- // }
- }
- //GPS模块防护
- //开机后超过1分钟没收到GPS或BD数据包,认为异常,应重启GPS模块
- // if(++sutGpsInfo.GpsCheckWorkCt>60 || ++sutGpsInfo.BDCheckWorkCt>120){
- // SlwTrace(DEBUG,"GNSS not work!reboot GNSS!\r\n");
- // GpsInit();
- // }
- //Modem防护
- //3分钟没有收到串口消息,重启MCU
- if(++sutModemStatus.UartInactiveCt>180){
- SlwTrace(DEBUG,"ModemUartTimeout!\r\n");
- os_tsk_delete(idModemTask);
- SystemReboot();
- }
- //1个小时登陆不上服务器,重启MCU
- tsk_lock();
- if(sutModemStatus.ServerOfflineCt<65535)sutModemStatus.ServerOfflineCt++;
- if(sutWLanStatus.ServerOfflineCt<65535)sutWLanStatus.ServerOfflineCt++;
- tsk_unlock();
- if(sutModemStatus.ServerOfflineCt>3600 && sutWLanStatus.ServerOfflineCt>3600){
- SlwTrace(DEBUG,"ServerOfflineTimeout!\r\n");
- os_tsk_delete(idModemTask);
- ModemSendAT("AT+QPOWD\r\n");
- os_dly_wait(1000);
- SystemReboot();
- }
-
- }
|