12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048 |
- /********************************************************************************
- * 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 8
- //---------------------------------------------------------------------------------
- #include "includes.h"
- #include "stm32f10x_it.h"
- //OS ID
- OS_TID idMainTask=0;
- U64 stkMainTask[MAIN_TASK_STK_SIZE];
- unsigned char modemInitReady=0;//0模块没开始初始化 1模块初始化成功 2模块初始化失败
- unsigned char modemPwrOffNow=0;
- unsigned char g_ucBackLightCnt;
- int g_iVbat=0;
- unsigned int g_LCDTemp = 0;
- unsigned char g_ucGtMode=0;
- unsigned char g_usOptionCnt;
- char sysStartTTS[START_TTS_LENGTH];
- //SUT_MSG_QUEUE ModemMsgQueue;
- //char ModemMsgBuffer[512];
- void FingerDaemonfinger(void);
- unsigned char g_ucUpdataVer=0;
- unsigned char g_ucKeyDownPressFlag=0;
- unsigned char g_ucGroupSelect=0;
- unsigned char g_ucUserSelect=0;
- unsigned char g_ucGroup_User_Select=0;
- unsigned char g_ucFun1KeyPressCt=0;//Fun1Key持续按下计数器,松开后清零
- unsigned char g_ucFun2KeyPressCt=0;//Fun2Key持续按下计数器,松开后清零
- int g_iFun1KeyEncodeCt=0; //Fun1Key按下时旋转Encode次数计数器,正数为顺时针,负数为逆时针,松开后清零
- int g_iFun2KeyEncodeCt=0; //Fun2Key按下时旋转Encode次数计数器,正数为顺时针,负数为逆时针,松开后清零
- unsigned int g_uikey_up_stat =0; //快捷键,用于进入GT模式 按下KEY_UP再按下OK
- unsigned char g_ucEnterGroupFlag=0;
- unsigned char pocTimeOutTime=30;//默认30分钟
- //======================================
- void EncodeKeyProcess(void);
- void iap_jump_app_s(void);
- int GetCheckCodeByPsnMEID(char *pCheckCode,unsigned long PSN,char *pMEID);
- void ReportCheckCode(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 m_GroupSelect=0;//用于使用左边上下键去选择群组时使用 wjl
- unsigned char m_GroupSwitch=0;//表示是否曾经按过左边上下群组切换按键
- unsigned char m_GroupSwitchCnt=0;//按过的话,5秒内没按OK键则退出切换
-
- /***********************************************
- 强制复位
- ************************************************/
- void SystemReset(void)
- {
- //IWDG_Configuration();
- while(1);
- }
- void PowerCtrlInit(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Pin = PWR_EN_PIN;
- GPIO_Init(PWR_EN_PORT, &GPIO_InitStructure);
- PWR_EN_LOW;
- }
- /*************************************************************************
- 拷贝数据,并判断与原数据是否相同
- 相同返回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;
- }
- /********************************************************************
- *开关机键检测
- *********************************************************************/
- int OnOffCheck(void)
- {
- static unsigned char sucCt=0;
- unsigned long k;
- k=ONOFF_CK_PORT->IDR;
- if((k&ONOFF_CK_PIN)==ONOFF_CK_PIN){
- if(sucCt<5)sucCt++;
- else return 1;
- }else{
- sucCt=0;
- }
- return 0;
- }
- void GPIO_Config_ALL_AIN(void);
- /**********************************************************************
- *系统关机
- ***********************************************************************/
- void SysShutDown(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- unsigned long k;
- int len;
- GPS_PWREN_LOW;
- MODEM_LED1_HIGH;
- MODEM_LED2_HIGH;
- ModemSendAT("AT+ZPWROFF\r\n");
- SlwTrace(INF,"Set modem OnOff down!",1);
- ModemSendAT("AT+ZPWROFF\r\n");
- //os_dly_wait(50);
- SlwTrace(INF,"Set system power off!",1);
- //SlwTraceWaitCompleted();
- MODEM_LED1_LOW;
- MODEM_LED2_LOW;
- //-------
- k=ONOFF_CK_PORT->IDR;
- if((k&ONOFF_CK_PIN)==0){
- SlwTrace(INF,"Reset system!",1);
- //SlwTraceWaitCompleted();
- SystemReset();
- }else{
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Pin = PWR_EN_PIN;
- GPIO_Init(PWR_EN_PORT, &GPIO_InitStructure);
- while(1);
- }
- }
- //从source查找长度为targetLen目标的target,找到后返回目标段后一字节的索引,没找到返回-1,source结束为sourceEndIndicator
- //witchOne: 找第几个目标
- short FindTargetIndex(char *source, char sourceEndIndicator, char *target, unsigned char targetLen,unsigned char witchOne)
- {
- unsigned short targetIndex;
- unsigned char targetNum;
- targetIndex=0;
- targetNum=0;
- while(*source != sourceEndIndicator)
- {
- if(0==memcmp(source, target, targetLen))
- {//找到了
- targetNum++;
- if(targetNum == witchOne)
- return (targetIndex+targetLen);
- }
- source++;
- targetIndex++;
- }
- return -1;
- }
- 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;
- }
- unsigned char apnUpdateFlag=0;
- void PcMsgHandle(char *msg)
- {
- const char *CmdList[]={
- "TM", //Trace Modem
- "TG", //Trace GPS
- "DM", //Download Modem
- "FOTA", //Fota Modem
- "STP", //Set Test Parameter
- "SMP", //Set Modem Parameter
- "SGP", //Set GPS Parameter
- "RMP", //Read Modem Parameter
- "PST", //PST Mode for modem
- "VER", //Read Version
- "BAT", //Battery voltage
- "APN", //SET APN
- "RAPN", //Read APN
- "BEEP", //Beep test
- "RGP",
- "RMIP", //Read Manager/Load IP
- "SMIP", //Set Manager/Load IP
- "RCIP", //Read ConfigIP
- "SCIP", //Set ConfigIP
- "SACC", //Set access point
- "RACC", //Read access point
- "RREC", //Read record info
- "RFIP", //read fota IP
- "SFIP", //set fota ip
- "RDOMAIN", //read main ip
- "SDOMAIN",//set main ip
- "RPOCDOMAIN", //read POCdomain
- "SPOCDOMAIN",//set POCdomain
- "" //必须以空字串为结束
- };
- int h,m,s;
- unsigned short Port;
- unsigned short Select;
- unsigned long PSN;
- char buf[150];
- char buf1[300];
- char strIP[40];
- char strAccount[20+20];
- char strPassword[20+20];
-
- unsigned short PID;//省域ID 16byte
- unsigned short CID; //市域ID16byte
- char Mfactur[10]; //制造商
- char TMod[42]; //终端型号 不足补0x00
- char TID[28]; //终端ID 不足补0x00 本来7个字节 为了跟星安一致 取4个字节8
- unsigned char PColor; //车牌颜色 未上牌取值为0
- char Plate[16]; // 车牌8
- char SIM[12];
-
- int i,j,len;
- char flag;
- const char *pCmd;
- char *pMsg;
- int CmdListNum=0;
- RunMake(THIS_FILE_ID);
- 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://"TM"
- //idNetTask
- SetLedStatus(RedBlueSlowFlash);
- // g_ucNetTaskDisable=0xff;
- SlwTrace(INF,"GT+TM:OK",1);
- //SlwTraceWaitCompleted();
- ComSelect(COM_SEL_MODEM);
- g_ucGtMode=1;
- // MODEM_LED1_HIGH;
- // MODEM_LED2_LOW;
- // while(1){
- // IWDG_ReloadCounter();//喂狗
- // if(OnOffCheck()){
- // PWR_EN_LOW;
- // }
- // //OSTimeDlyHMSM(0, 0, 0, 1);
- // }
-
- break;
- case 1://"TG"
- SetLedStatus(RedBlueSlowFlash);
- SlwTrace(INF,"GT+TG:OK",1);
- //SlwTraceWaitCompleted();
- GPSInit();
- ComSelect(COM_SEL_GPS);
- break;
- case 2://"DM"
- SetLedStatus(RedBlueSlowFlash);
- //g_ucNetTaskDisable=0xff;
- SlwTrace(INF,"GT+DM:OK",1);
- //SlwTraceWaitCompleted();
- //OSTimeDlyHMSM(0, 0, 1, 0);
- ComSelect(COM_SEL_MODEM);
- MODEM_LED1_LOW;
- MODEM_LED2_HIGH;
- GPS_PWREN_LOW;
- ModemSetDtrLow();
- ModemSetRingLow();
- MODEM_PWRKEY_HIGH;
- MODEM_RESET_HIGH;
- //OSTimeDlyHMSM(0, 0, 1, 0);
- MODEM_RESET_LOW;
- while(1){
- IWDG_ReloadCounter();//喂狗
- if(OnOffCheck()){
- PWR_EN_LOW;
- }
- }
- break;
- case 3://"FOTA"
- SetLedStatus(RedBlueSlowFlash);
- if(msg[8]=='M' && msg[9]=='C' && msg[10]=='U' ){//GT+FOTA=MCU
- //g_ucNetTaskDisable=0xff;
- SlwTrace(INF,"GT+FOTA:MCU",1);
- //SlwTraceWaitCompleted();
- sutProductPara.IapFlag=0x55;
- SaveProductParaToFlash("COM-FOTA");
- while(1);
- }else if(msg[8]=='M' && msg[9]=='O' && msg[10]=='D' && msg[11]=='E' && msg[12]=='M' ){//GT+FOTA=MODEM 对讲版本
- //g_ucNetTaskDisable=0xff;
- SlwTrace(INF,"GT+FOTA:MODEM",1);
- //SlwTraceWaitCompleted();
- //OSTimeDlyHMSM(0, 0, 0, 100);
- ModemSendAT("at+poc=10000018\r\n");
- while(1){
- IWDG_ReloadCounter();//喂狗
- if(OnOffCheck()){
- PWR_EN_LOW;
- }
- }
- }
- break;
- case 4://"STP" GT+STP=IP=地址或域名;Port=端口号; Account=账号;Password=密码;
- //g_ucNetTaskDisable=0xff;
- //OSTimeDlyHMSM(0, 0, 0, 100);
- len=GetParaFromStr(msg,"IP",buf);
- if(len<1 || len>=40){
- SlwTrace(INF,"GT+STP:FAIL[IP Invalid]",1);
- break;
- }else strcpy(strIP,buf);
-
- len=GetParaFromStr(msg,"Port",buf);
- if(len==0)Port=0;
- else if(len>5){
- SlwTrace(INF,"GT+STP:FAIL[Port Invalid]",1);
- break;
- }else{
- Port=atoi(buf);
- }
- len=GetParaFromStr(msg,"Account",buf);
- if(len<1 || len>=20){
- SlwTrace(INF,"GT+STP:FAIL[Account Invalid]",1);
- break;
- }else strcpy(strAccount,buf);
- len=GetParaFromStr(msg,"Password",buf);
- if(len<1 || len>=20){
- SlwTrace(INF,"GT+STP:FAIL[Password Invalid]",1);
- break;
- }else strcpy(strPassword,buf);
- //send to modem
- snprintf(buf, sizeof(buf),"id=%s;ip=%s;pwd=%s;",strAccount,strIP,strPassword);
- AscStrToHexStr(buf,buf1);
- ModemSendAT("AT+POC=120000");
- ModemSendAT(buf1);
- ModemSendAT("\r\n");
- //send to pc
- snprintf(buf, sizeof(buf),"GT+STP:IP=%s;Port=%u;Account=%s;Password=%s",strIP,Port,strAccount,strPassword);
- SlwTrace(INF,buf,1);
- break;
- case 5://"SMP" GT+SMP=IP=地址或域名;Port=端口号;PSN=终端序列号
- len=GetParaFromStr(msg,"IP",buf);
- if(len<1 || len>=40){
- SlwTrace(INF,"GT+SMP:FAIL[IP Invalid]",1);
- break;
- }
- strcpy(strIP,buf);
-
- len=GetParaFromStr(msg,"Port",buf);
- if(len==0)Port=0;
- else if(len>5){
- SlwTrace(INF,"GT+SMP:FAIL[Port Invalid]",1);
- break;
- }else{
- Port=atoi(buf);
- }
- len=GetParaFromStr(msg,"PSN",buf);
- if(len<1 || len>10){
- SlwTrace(INF,"GT+SMP:FAIL[PSN Invalid]",1);
- break;
- }else{
- PSN=atol(buf);
- }
- //PSN
- sutProductPara.PSN=PSN;
- strcpy(sutProductPara.PIP,strIP);
- sutProductPara.PocPort=Port;
- //send to modem
- if(strlen(sutProductPara.HARDID)<14){
- SlwTrace(INF,"GT+SMP:FAIL[MEID Invalid]",1);
- break;
- }
- snprintf(buf, sizeof(buf),"id=%lu;ip=%s;pwd=%s;",sutProductPara.PSN,strIP,sutProductPara.HARDID);
- AscStrToHexStr(buf,buf1);
- ModemSendAT("AT+POC=010000");
- ModemSendAT(buf1);
- ModemSendAT("\r\n");
- //save para
- SaveProductParaToFlash("COM-SMP");
- snprintf(buf, sizeof(buf),"GT+SMP:IP=%s;Port=%u;PSN=%lu",sutProductPara.PIP,sutProductPara.PocPort,sutProductPara.PSN);
- SlwTrace(INF,buf,1);
- break;
- case 6://"SGP" GT+SGP=IP=地址或域名;Port=端口号;
- len=GetParaFromStr(msg,"IP",buf);
- if(len<1 || len>=40){
- SlwTrace(INF,"GT+SGP:FAIL[IP Invalid]",1);
- break;
- }else strcpy(strIP,buf);
-
- len=GetParaFromStr(msg,"Port",buf);
- if(len==0)Port=0;
- else if(len>5){
- SlwTrace(INF,"GT+SGP:FAIL[Port Invalid]",1);
- break;
- }else{
- Port=atoi(buf);
- }
- strcpy(sutProductPara.GIP,strIP);
- sutProductPara.GpsPort=Port;
- //Save para to flash
- SaveProductParaToFlash("COM-SGP");
- //echo
- snprintf(buf, sizeof(buf),"GT+SGP:IP=%s;Port=%u;",sutProductPara.GIP,sutProductPara.GpsPort);
- SlwTrace(INF,buf,1);
- break;
- case 7://"RMP" GT+RMP<CR><LF> PSN=终端序列号;MEID=模块MEID号;CNUM=电信号;UIMID=电信UIMID;
- snprintf(buf, sizeof(buf),"GT+RMP:PSN=%lu;MEID=%s;CNUM=0000000000;UIMID=0000000000;IP=%s;",sutProductPara.PSN,sutProductPara.HARDID,sutProductPara.PIP);
- SlwTrace(INF,buf,1);
- break;
- case 8://"PST"
- SetLedStatus(RedBlueSlowFlash);
- //g_ucNetTaskDisable=0xff;
- SlwTrace(INF,"GT+PST:OK",1);
- //SlwTraceWaitCompleted();
- os_dly_wait(1);
- ComSelect(COM_SEL_MODEM);
- ModemSetDtrLow();
- MODEM_PWRKEY_LOW;
- MODEM_RESET_HIGH;
- os_dly_wait(5);
- MODEM_RESET_LOW;
- while(1){
- IWDG_ReloadCounter();//喂狗
- if(OnOffCheck()){
- PWR_EN_LOW;
- }
- }
- break;
- case 9://"VER"
- snprintf(buf, sizeof(buf),"GT+VER:%s_V%d",sutProductPara.ProductName,sutProductPara.ProductVersion);
- SlwTrace(INF,buf,1);
- break;
- case 10://BAT
- snprintf(buf, sizeof(buf),"GT+BAT: %d V",g_iVbat);
- SlwTrace(INF,buf,1);
- // SlwTrace(INF, msg,1);
- // cntMeiTiao=atoi(&msg[7]);
- // SpeakerEnable();
- // //SetBeepByNoOS(878, 100);
- // SetBeep(878, 3000);
- break;
- case 11://APN
- /*
- 设置格式:GT+APN=Account=用户名;Password=密码;<CR><LF>
- 成功返回:GT+APN:Account=用户名;Password=密码;<CR><LF>
- 失败返回:GT+APN:FAIL[失败原因]<CR><LF>
- */
- len=GetParaFromStr(msg,"Account",buf);
- if(len<1 || len > 30){
- SlwTrace(INF,"GT+APN:FAIL[Account Invalid]",1);
- return;
- }
- strcpy(strAccount,buf);
-
- len=GetParaFromStr(msg,"Password",buf);
- if(len<1 || len > 30){
- SlwTrace(INF,"GT+APN:FAIL[Password Invalid]",1);
- return;
- }
- if(sutProductPara.APNIndex==3 && validApnNum != 1)
- {
- strcpy(sutProductPara.APNName,strAccount);
- strcpy(sutProductPara.APNPass,buf);
- SaveProductParaToFlash("COM-APN");
- }
- snprintf(buf1, sizeof(buf1),"GT+APN:Account=%s;Password=%s;",strAccount,buf);
- SlwTrace(INF,buf1,1);
-
- if(ApnFileIndex==-1 || HgsApnLen==0) break;
- if(0==strcmp(strAccount, showApnTable[6]) &&
- 0==strcmp(buf, showApnTable[7]))
- break;
- strcpy(showApnTable[6],strAccount);
- strcpy(showApnTable[7],buf);
- apnUpdateFlag=1;
- break;
- case 12://RAPN
- if(validApnNum==1){
- i=0;j=1;
- }
- else{//有多个时,只能读取可配置的那个
- i=6;j=7;
- }
- sprintf(buf1,"GT+RAPN:Account=%s;Password=%s;",showApnTable[i],showApnTable[j]);
- SlwTrace(INF,buf1,1);
- break;
- case 13://BEEP
- len=GetParaFromStr(msg,"F",buf);
- if(len)i=atoi(buf);
- else i=878;
- len=GetParaFromStr(msg,"T",buf);
- if(len)Port=atoi(buf);
- else Port=8;//80
- SpeakerEnable();
- SetBeep(i,Port);
- snprintf(buf, sizeof(buf),"BEEP=%dHz,%dms",i,Port*10);
- SlwTrace(INF,buf,1);
- break;
- case 14://RGP
- snprintf(buf, sizeof(buf),"GT+RGP:IP=%s;PORT=%d;",sutProductPara.GIP,sutProductPara.GpsPort);
- SlwTrace(INF,buf,1);
- break;
- case 15://RMIP
- snprintf(buf, sizeof(buf),"GT+RMIP:IP=%d.%d.%d.%d;PORT=%d;",sutProductPara.ManagerIP[0],sutProductPara.ManagerIP[1],sutProductPara.ManagerIP[2],sutProductPara.ManagerIP[3],sutProductPara.ManagerPort);
- SlwTrace(INF,buf,1);
- break;
- case 16://SMIP
- len=GetParaFromStr(msg,"IP",buf);
- if(len<1 || len>=40){
- SlwTrace(INF,"GT+SMIP:FAIL[IP Invalid]",1);
- break;
- }else strcpy(strIP,buf);
-
- len=GetParaFromStr(msg,"Port",buf);
- if(len==0)Port=0;
- else if(len>5){
- SlwTrace(INF,"GT+SMIP:FAIL[Port Invalid]",1);
- break;
- }else Port=atoi(buf);
- GetStringIP2Bytes(sutProductPara.ManagerIP, strIP);
- sutProductPara.ManagerPort=Port;
- //Save para to flash
- SaveProductParaToFlash("COM-SMIP");
- //echo
- snprintf(buf, sizeof(buf),"GT+SMIP:IP=%d.%d.%d.%d;Port=%u;",sutProductPara.ManagerIP[0],
- sutProductPara.ManagerIP[1],
- sutProductPara.ManagerIP[2],
- sutProductPara.ManagerIP[3],
- sutProductPara.ManagerPort);
- SlwTrace(INF,buf,1);
- break;
- case 17://RCIP
- snprintf(buf, sizeof(buf),"GT+RCIP:IP=%d.%d.%d.%d;PORT=%d;",sutProductPara.ConfigSerIP[0],
- sutProductPara.ConfigSerIP[1],
- sutProductPara.ConfigSerIP[2],
- sutProductPara.ConfigSerIP[3],
- sutProductPara.ConfigSerPort);
- SlwTrace(INF,buf,1);
- break;
- case 18://SCIP
- len=GetParaFromStr(msg,"IP",buf);
- if(len<1 || len>=40){
- SlwTrace(INF,"GT+SCIP:FAIL[IP Invalid]",1);
- break;
- }else strcpy(strIP,buf);
-
- len=GetParaFromStr(msg,"Port",buf);
- if(len==0)Port=0;
- else if(len>5){
- SlwTrace(INF,"GT+SCIP:FAIL[Port Invalid]",1);
- break;
- }else Port=atoi(buf);
- GetStringIP2Bytes(sutProductPara.ConfigSerIP, strIP);
- sutProductPara.ConfigSerPort=Port;
- //Save para to flash
- SaveProductParaToFlash("COM-SCIP");
- //echo
- snprintf(buf, sizeof(buf),"GT+SCIP:IP=%d.%d.%d.%d;Port=%u;",sutProductPara.ConfigSerIP[0],
- sutProductPara.ConfigSerIP[1],
- sutProductPara.ConfigSerIP[2],
- sutProductPara.ConfigSerIP[3],
- sutProductPara.ConfigSerPort);
- SlwTrace(INF,buf,1);
- break;
- case 19://SACC
- len=GetParaFromStr(msg,"Accessp",buf);
- if(len<0 || len > APN_LEN)
- {
- SlwTrace(INF,"GT+SACC:FAIL[Accessp Invalid]",1);
- return;
- }
- if(len ==0) sutProductPara.APNApn[0]=0;
- else strcpy(sutProductPara.APNApn,buf);
- SaveProductParaToFlash("COM-SACC");
- snprintf(buf1, sizeof(buf1),"GT+SACC:Accessp=%s;",sutProductPara.APNApn);
- SlwTrace(INF,buf1,1);
- break;
- case 20://RACC
- snprintf(buf, sizeof(buf),"GT+RACC:Accessp=%s;",sutProductPara.APNApn);
- SlwTrace(INF,buf,1);
- break;
- case 21://RREC
- sFlash_Read(buf1, RECORD_INFO_ADDRESS, 100);
- SlwTrace(INF, buf1, 1);
- break;
-
- case 22://RFIP
- snprintf(buf, sizeof(buf),"GT+RFIP:IP=%d.%d.%d.%d;PORT=%d;",sutProductPara.MFotaIP[0],
- sutProductPara.MFotaIP[1],
- sutProductPara.MFotaIP[2],
- sutProductPara.MFotaIP[3],
- sutProductPara.MFotaPort);
- SlwTrace(INF,buf,1);
- break;
- case 23://SCIP
- len=GetParaFromStr(msg,"IP",buf);
- if(len<1 || len>=40){
- SlwTrace(INF,"GT+SFIP:FAIL[IP Invalid]",1);
- break;
- }else strcpy(strIP,buf);
-
- len=GetParaFromStr(msg,"Port",buf);
- if(len==0)Port=0;
- else if(len>5){
- SlwTrace(INF,"GT+SFIP:FAIL[Port Invalid]",1);
- break;
- }else Port=atoi(buf);
- GetStringIP2Bytes(sutProductPara.MFotaIP, strIP);
- sutProductPara.MFotaPort=Port;
- //Save para to flash
- SaveProductParaToFlash("COM-SFIP");
- //echo
- snprintf(buf, sizeof(buf),"GT+SFIP:IP=%d.%d.%d.%d;Port=%u;",sutProductPara.MFotaIP[0],
- sutProductPara.MFotaIP[1],
- sutProductPara.MFotaIP[2],
- sutProductPara.MFotaIP[3],
- sutProductPara.MFotaPort);
- SlwTrace(INF,buf,1);
- break;
- case 24://RDOMAIN
- snprintf(buf,sizeof(buf),"GT+RDOMAIN:%s;",sutProductPara.domain);
- SlwTrace(INF,buf,1);
- break;
- case 25://SDOMAIN
- len=GetParaFromStr(msg,"SDOMAIN",buf);//buf=www.baidu.com ,return len
- if(len>40){
- SlwTrace(INF,"MAINIP LEN ERR",1);
- return;
- }
- memset(sutProductPara.domain,0,sizeof(sutProductPara.domain));
- strcpy(sutProductPara.domain,buf);
- snprintf(buf,sizeof(buf),"GT+SDOMAIN=%s",sutProductPara.domain);
- //Save para to flash
- SaveProductParaToFlash("COM-SDOMINIP");
- SlwTrace(INF,buf,1);
- break;
- case 26://RPOCDOMAIN
- snprintf(buf,sizeof(buf),"GT+RPOCDOMAIN:%s;",sutProductPara.fota_pocdomain);
- SlwTrace(INF,buf,1);
- break;
- case 27://SPOCDOMAIN
- len=GetParaFromStr(msg,"SPOCDOMAIN",buf);//buf=www.baidu.com ,return len
- if(len>40){
- SlwTrace(INF,"FOTAPOCMAIN LEN ERR",1);
- return;
- }
- memset(sutProductPara.domain,0,sizeof(sutProductPara.fota_pocdomain));
- strcpy(sutProductPara.fota_pocdomain,buf);
- snprintf(buf,sizeof(buf),"GT+SPOCDOMAIN=%s",sutProductPara.fota_pocdomain);
- SlwTrace(INF,buf,1);
- break;
-
-
-
-
-
- }
- RunMake(THIS_FILE_ID);
- }
- /*********************************************
- ************************************************/
- void TSMakeSendStrData(void){
- int i;
- static int Temp1[7];
- static int Table1[20]={0};
- //static int Table[20]={0};
- static int Temp[8];
- unsigned char SendBuf[100];
- unsigned short PacketLen,data1,data2,data3,data4;
- char buf1[300];
- // char str1[4];
- // int strData[4];
-
- // sprintf(str1,"%x",sutProductPara.proID);
- //发现Regist.proID 和egist.CityID输出的是他的BCD码
- //for (i=0;i<6;i+=2) {
- // Hexstr[i]='0'|(Bcdstr[i/2]>>4);
- // Hexstr[i+1]='0'|(Bcdstr[i/2]&0x0F);
- // }
- // BcdToHex(xx,xx);
-
- // Regist.proID =((sutProductPara.proID>>8)&0xff);
- // Regist.proID =(sutProductPara.proID&0xff);
- // Regist.proID=(sutProductPara.proID/16*10)+(sutProductPara.proID%16);//BCD转16进制
- Regist.proID=(sutProductPara.proID/10*16)+(sutProductPara.proID%10);//16进制转BCD
- // Regist.proID='0'|(sutProductPara.proID>>4);//
- // Regist.proID='0'|(sutProductPara.proID&0x0F);
- // sprintf(buf1,"proID=%d;\r\n",Regist.proID);
- // SlwTrace(INF,buf1);
- data1=sutProductPara.CityID/100;
- data3=(data1/10*16)+(data1%10);
- data2=sutProductPara.CityID%100;
- data4=(data2/10*16)+(data2%10);
- Regist.CityID = ((data4>>24)&0xffff);
- Regist.CityID = ((data4>>16)&0xffff);
- Regist.CityID = ((data3>>8)&0xffff);
- Regist.CityID = (data3&0xffff);
-
- for(i = 0; i < 5; i++){
- Regist.Manufacturers[i] = sutProductPara.Manufacturers[i];
- }
-
- for(i = 0; i < 20; i++){
- sscanf(sutProductPara.TerMod+2*i,"%2x",&Table1[i]);
- Regist.TerMod[i]= Table1[i];
- }
- // for(i=0;i<14;i+=2)
- // {
- // Regist.TerID[i/2]=(sutProductPara.TerID[i]<<4)|(sutProductPara.TerID[i+1]&0x0F);
- // }
- for(i = 0; i < 7; i++){
- sscanf(sutProductPara.TerID+2*i,"%2x",&Temp1[i]);
- Regist.TerID[i]= Temp1[i];
- }
- // sprintf(buf1,"TerID=%s;\r\n",sutProductPara.TerID);
- // SlwTrace(INF,buf1);
-
- Regist.PlateColor=sutProductPara.PlateColor;//
- for(i = 0; i < 8; i++){//16
- sscanf(sutProductPara.Plate+2*i,"%2x",&Temp[i]);
- Regist.Plate[i] = Temp[i];
- }
- PacketLen=TSGpsPacket(SendBuf,sutProductPara.PSN,TS_TERMINAL_REGISTRATION,(unsigned char *)&Regist,sizeof(REGISTRATION));
- MC8332ModemSendTcpData(0,SendBuf,PacketLen);
- }
- void SwitchGroupCtrl(void)
- {
- if(m_GroupSwitch)
- {
- if(++m_GroupSwitchCnt >=5)
- {
- //MeSpeak(ENCODE_GBK, "CDCBB3F6", 0);
- if(sutUIstatus.Status == UIS_STANDBY)
- ShowButton(1,107,"菜单");
- m_GroupSwitch=0;
- SlwTrace(INF, "QuitGroupSel",1);
- }
- }
- }
- void SwitchGroupPre(void)
- {
- //让菜单变成:确定
- ShowButton(1,107,"确定");
- m_GroupSwitch=1;
- m_GroupSwitchCnt=0;
- }
- //volatile unsigned int pttPressFreeCt;
- /***********************************************************************
- *按键按下事件
- ************************************************************************/
- void KeyPress(void)
- {
- char buf[30];
- static unsigned char sucReportFlag=0;
- if(g_ucGtMode==0){//在GT模式下不能与串口同时发送AT指令会冲突,导致重启
- UI_Key();
- }
-
- switch(g_ulKeyValue){
- //-------------------------------------------------------------------
- case KEY_PPT_MIC:
- case KEY_PPT://=====================KEY_PPT Press====================
- g_ucKeyMode=1;//单次模式
- SlwTrace(INF,"[KEY_PPT/KEY_PPT_MIC Press]",1);
- sutPocStatus.PPTpress=1;
- if((g_ucGtMode==0)&&(g_ucCallPhonePro==0))
- {
- //pttPressFreeCt=os_time_get()+40;
- ModemSendAT(POC_CMD_PPT_START);//
- //SlwTrace(INF, "Speak",1);
- }
- break;
- //-------------------------------------------------------------------
- case KEY_INFO://=====================KEY_UP Press==================
- g_ucKeyMode=1;//单次模式
- SlwTrace(INF,"[KEY_UP Press]",1);
-
- if(sutProductPara.QuickGroup==1&&(g_ucGtMode==0)&&(g_ucCallPhonePro==0)&&(sutUIstatus.Status == UIS_STANDBY)){
- g_ucEnterGroupFlag=1;
- snprintf(buf, sizeof(buf),"AT+POC=090000%08x\r\n",sutProductPara.QuickGroupId[1]);
- ModemSendAT(buf);
- }else if((g_ucGtMode==0)&&(g_ucCallPhonePro==0)&&(sutUIstatus.Status == UIS_STANDBY)&&(sutPocStatus.Logined))
- {
- ModemSendAT(POC_CMD_UP);
- SwitchGroupPre();
- }
- break;
- case KEY_FUNC://=====================KEY_DOWN Press=================
- g_ucKeyMode=1;//单次模式
- g_ucEnterGroupFlag=1;
- SlwTrace(INF,"[KEY_DOWN Press]",1);
- if(sutProductPara.QuickGroup==1&&(g_ucGtMode==0)&&(g_ucCallPhonePro==0)&&(sutUIstatus.Status == UIS_STANDBY)){
- snprintf(buf, sizeof(buf),"AT+POC=090000%08x\r\n",sutProductPara.QuickGroupId[2]);
- ModemSendAT(buf);
-
- }else if((g_ucGtMode==0)&&(g_ucCallPhonePro==0)&&(sutUIstatus.Status == UIS_STANDBY)&&(sutPocStatus.Logined))
- {
- ModemSendAT(POC_CMD_DOWN);
- SwitchGroupPre();
- }
- break;
- case KEY_PANEL_OK://=====================KEY_PANEL_OK Press=================
-
- if(sutProductPara.QuickGroup==1&&(g_ucGtMode==0)&&(g_ucCallPhonePro==0)&&(sutUIstatus.Status == UIS_STANDBY)){
- g_ucEnterGroupFlag=1;
- snprintf(buf, sizeof(buf),"AT+POC=090000%08x\r\n",sutProductPara.QuickGroupId[0]);
- ModemSendAT(buf);
-
- }else
- if(sutUIstatus.Status == UIS_STANDBY && m_GroupSwitch==0)
- UISetNextStatus(UIS_MENU_GROUP_SEL);
- SlwTrace(INF,"[KEY_PANEL_OK Press]",1);
- break;
- case KEY_PANEL_MENU://=====================KEY_PANEL_MENU Press=================
- if(m_GroupSwitch)
- {//
- m_GroupSwitch=0;
- snprintf(buf, sizeof(buf),"AT+POC=090000%s\r\n",sutPocStatus.switchGroupID);
- ModemSendAT(buf);
- ShowButton(1,107,"菜单");
- SlwTrace(INF, buf,0);
- }
- SlwTrace(INF,"[KEY_PANEL_MENU Press]",1);
- break;
- case KEY_PANEL_EXIT://=====================KEY_PANEL_EXIT Press=================
- SlwTrace(INF,"[KEY_PANEL_EXIT Press]",1);
- break;
- case KEY_PANEL_UP://=====================KEY_PANEL_UP Press=================
- SlwTrace(INF,"[KEY_PANEL_UP Press]",1);
- break;
- case KEY_PANEL_DOWN://=====================KEY_PANEL_DOWN Press=================
- SlwTrace(INF,"[KEY_PANEL_DOWN Press]",1);
- break;
- case KEY_EXIT_DOWN_GT://=====================KEY_UP_OK_GT Press=================
- // EnterGTMode();
- SlwTrace(INF,"[KEY_EXIT_DOWN_GT Press]",1);
- break;
- case KEY_P1_P3_UPDATE:
- SlwTrace(INF, "[KEY_P1_P3_UPDATE Press]",1);
- break;
- case KEY_OK_DOWN_GPS:
- SlwTrace(INF, "[KEY_OK_DOWN_GPS Press]",1);
- break;
- case KEY_OPTION:
- g_usOptionCnt++;
- //在待机界面按一下'S'键,网络允许情况下发SOS消息
- if(sutGpsInfo.isGpsAuthOk==1 && sutUIstatus.Status==UIS_STANDBY && g_ucModemTaskEn==1)
- {
- if(g_usOptionCnt ==3)
- TS_SendSOSMessage();
- }
- SlwTrace(INF, "[KEY_OPTION Press]",1);
- break;
- }
- }
- //长按 EXIT和下箭头3秒,只进入一次
- void GTMode_Detected(void)
- {
- static char GT_Flag=0;
-
- if(GT_Flag == 2) return;
- if(g_ulKeyValue == KEY_EXIT_DOWN_GT)
- {
- if(GT_Flag == 0)
- {
- g_ucUKC=0;
- GT_Flag ++;
- }else
- {
- if(g_ucUKC>3){
- EnterGTMode();
- GT_Flag++;
- }
- }
- }else
- {
- if(GT_Flag == 1)
- GT_Flag = 0;
- }
- }
- void UpdataAppVersion(void)
- {
- //正旋1格后松开,升级应用版本
- SpeakerEnable();
- ModemSendAT("AT+ZTTS=1,\"C6510759F466B065945E287548722C67F78B73513A678D51005F3A67\"\r"); //准备更新应用版本,请关机再开机
- SlwTrace(INF,"Update APP Version!",1);
- SetLedStatus(RedFastFlash);
- sutProductPara.IapFlag=0x55;
- SaveProductParaToFlash("MAIN-UP");
- while(1){
- IWDG_ReloadCounter();//喂狗
- os_dly_wait(1);
- if(OnOffCheck()){
- PWR_EN_LOW;
- }
- }
- }
- void UpdataPocVersion(void)
- {
- SpeakerEnable();
- ModemSendAT("AT+POC=10000018\r\n");
- SlwTrace(INF,"Update POC Version!",1);
- }
- void EnterGTMode(void)
- {
- ColonyFeature(0);
- g_ucModemTaskEn=0;
- SpeakerEnable();
- SetBeep(1176,10);
- os_dly_wait(20);
- SpeakerEnable();
- SetBeep(878,10);
- os_dly_wait(20);
- SpeakerEnable();
- SetBeep(1176,10);
- g_ucUART1RxMode=1;
- Uart1RxEnable(1);
- LedProcess(1);
- SetLedStatus(RedBlueFastFlash);
- SlwTrace(INF,"[EnterTxMode]",1);
- }
- void openModem()
- {
- MODEM_RESET_HIGH;
- os_dly_wait(100);
- MODEM_RESET_LOW;
- MODEM_PWRKEY_HIGH;
- os_dly_wait(100);
- MODEM_PWRKEY_LOW;
- }
- void closeModem()
- {
- MODEM_RESET_HIGH;
- MODEM_PWRKEY_HIGH;
- }
- /***********************************************************************
- *按键释放事件
- ************************************************************************/
- void KeyFree(void)
- {
- int i;
- char CheckCode[10];
- char buf[30];
- int flag;
- SUT_MODEM_AT_MSG *pMsg;
- //unsigned int temp;
- char pressFlag;
- //-------------------------------------------------------------------
- if(KEY_PPT==g_ulKeyValue || KEY_PPT_MIC == g_ulKeyValue)
- {//===============KEY_PPT Free=============
- SlwTrace(INF,"[KEY_PPT/KEY_PPT_MIC Free]",1);
- g_ucKeyPPTPress=0;
- sutPocStatus.PPTpress=0;
- if((g_ucGtMode==0)&&((g_ucCallPhonePro==0)))
- {
- //#error "这里好了,发杨测试看看,等VPDN测试完一次发"
- //os_dly_wait(25);
- // if(os_time_get() > pttPressFreeCt)
- // {//按放间隔足够长了,只延时20即可
- // temp=20;//防止释放太快,导致对方有可能听不到最后一个字
- // }else{
- // //按放间隔太短,补足30
- // temp=pttPressFreeCt-os_time_get();
- // }
- // os_dly_wait(temp);
- ModemSendAT(POC_CMD_PPT_STOP);//结束讲话 放开PPT键
- g_ucKeyMode=0;
- }
- }else if(KEY_INFO==g_ulKeyValue)
- {//=========KEY_UP Free==============
- SlwTrace(INF,"[KEY_UP Free]",1);
- g_ucKeyMode=0;
- g_uikey_up_stat=1;
- }else if(KEY_FUNC==g_ulKeyValue)
- {//=========KEY_DOWN Free============
- g_ucKeyMode=0;
- SlwTrace(INF,"[KEY_DOWN Free]",1);
- }
- else if(KEY_PANEL_OK==g_ulKeyValue)
- {//=========KEY_PANEL_OK Free==============
- SlwTrace(INF,"[KEY_PANEL_OK Free]",1);
- return;
- }
- else if(KEY_PANEL_MENU==g_ulKeyValue)
- {//=========KEY_PANEL_MENU Free==============
- SlwTrace(INF,"[KEY_PANEL_MENU Free]",1);
- return;
- }
- else if(KEY_PANEL_EXIT==g_ulKeyValue)
- {//=========KEY_PANEL_EXIT Free==============
- g_uikey_up_stat=0;
- SlwTrace(INF,"[KEY_PANEL_EXIT Free]",1);
- return;
- }
- else if(KEY_PANEL_UP==g_ulKeyValue)
- {//=========KEY_PANEL_UP Free============
- //closeModem();
- }
- else if(KEY_PANEL_DOWN==g_ulKeyValue)
- {//=========KEY_PANEL_DOWN Free============
- //openModem();
- }
- else if(KEY_EXIT_DOWN_GT==g_ulKeyValue)
- {//=====================KEY_EXIT_DOWN_GT Press=================
- g_ulKeyValue=0;
- SlwTrace(INF,"[KEY_EXIT_DOWN_GT Free]",1);
- }else if(KEY_OPTION == g_ulKeyValue)
- {
- g_usOptionCnt=0;
- SlwTrace(INF,"[KEY_OPTION Free]",1);
- }
- }
- #if(USE_CONFIG_FUN==1)
- void ConfigModeDetect(void)
- {//检测进入配置服务器功能
- //GT模式下
- //长按OPTION键
- char buf[20];
- unsigned char timeout=150;
- if(0 != g_ucModemTaskEn) return;
- if(sutConfig.g_ubConfigFlag==0)
- {
- if(sutConfig.g_usOptionCnt ==5)
- {
- sutConfig.g_ubConfigFlag=1;
- sutConfig.g_usOptionCnt=0;
- snprintf(buf, sizeof(buf), "AT+TCPCLOSE=%d\r\n", GPS_DATA_SOCKET);
- ModemSendAT(buf);
- SlwTrace(INF, "ConfigModeActive",1);
- GuiShowBmp(30,34,"logo.bmp");
- GuiClearRect(0,55, LCD_WIDTH-1, 100);
- GuiShowStr(8, 65, "正在访问配置服务器",1);
- sutConfig.g_ucTcpRetryNum=CONFIG_TCP_RETRY_CNT;
- sutConfig.g_ucConfigStatus=0x01;//上报列表
- sutConfig.g_ubConfigFinished=0;//
- tcpControl=2;
- }
- }
- }
- #endif
- void apnUpdateFun(void)
- {
- int len;
- char buf1[400];
- char *pMsg;
- if(apnUpdateFlag!=1) return;
- apnUpdateFlag=0;
- len=HgsApnLen;
- if(HgsApnLen > sizeof(buf1)) len=sizeof(buf1);
- len=ReadFileData(ApnFileIndex,0,len,(u8*)buf1);
- if(len==0) return;
- pMsg=strstr(buf1,"APN4=");
- if(0==pMsg) return;
- sprintf(pMsg+5, "%s,%s;\r\n",showApnTable[6],showApnTable[7]);
- ModifyFileData(ApnFileIndex, 0, strlen(buf1), (unsigned char *)buf1);
- }
- void cmdShutDown(char type)
- {
- static short cntDown;
- static char ttype;
- char buf[30];
-
- ttype=type;
- SlwTrace(INF, "Try to PwrOff",1);
- ModemSendAT("AT$QCPWRDN\r\n");
- for(cntDown=6;cntDown>=0;cntDown--)
- {
- switch(ttype)
- {
- case 0:snprintf(buf, sizeof(buf), "正在关机[%d]", cntDown);break;
- case 1:snprintf(buf, sizeof(buf), "低压关机[%d]", cntDown);break;
- default:return;
- }
- ShowMessageBox(buf);
- SlwTrace(INF, buf, 1);
- IWDG_ReloadCounter();
- os_dly_wait(100);
- }
- }
- void PowerOffProtetion(void)
- {
- if(modemPwrOffNow==0) return;
- LCDTimeOut(0);
- GPS_PWREN_LOW;
- cmdShutDown(0);
- PWR_EN_LOW;
- while(1);
- }
- unsigned int bootMapCnt=0;
- unsigned char bootFlag=0;
- /*******************************************************************
- *MainTask
- *主任务
- ********************************************************************/
- __task void MainTask(void)
- {
- int BeepFlag=0;
- int KeyFlag,GTKeystat=0;
- int RealTime;
- int FileIndex,SMSIndex;
- char *msg;
- INT8U err;
- unsigned char ucCheckVbatCt=0;
- static unsigned int sucCt=0;
- static unsigned char sucFunReportFlag=0;
- unsigned short g_usModemProtectEn;
- int Vbat;
- RunMake(THIS_FILE_ID);
- //Obtain own system task identification number. */
- idMainTask = os_tsk_self();
- memset((unsigned char *)&sutPocStatus,0,sizeof(SUT_POC_STATUS));
- //开机提示音
- SpeakerEnable();
- os_dly_wait(10);
- SetBeepByNoOS(888,100);
- SpeakerDisable();
- //Read Product param from flash
- ReadProductParaFromFlash();
- APNFileInit();
- printf("\r\n%s_V%d.%d Start...\r\n",sutProductPara.ProductName,sutProductPara.ProductVersion,INTER_VER);
- printf("PSN:%lu\r\n",sutProductPara.PSN);
- g_ucUpdataVer=0;
- SlwTrace(INF,"Main Task Start!",1);
- //LCD设置参数初始化
- FileIndex=GetFileIndex("LcdParam.ini");
- ReadFileData(FileIndex,0,sizeof(SUT_LCD_PARAM),(unsigned char *)&sutLcdParam);
- if(sutLcdParam.OnTimeIndex > 4){
- sutLcdParam.OnTimeIndex = 0;
- sutLcdParam.OnTime=10;
- ModifyFileData(FileIndex,0,sizeof(SUT_LCD_PARAM),(unsigned char *)&sutLcdParam);
- //到此,说明是重新烧代码了,则初始化GPS为默认值
- sutProductPara.m_GPS_TimeIndex = DEFAULT_GPS_SEND_TIME_INDEX;
- GpsTimeUpdate();
- SaveProductParaToFlash("MAIN-PARA");
- }
- sutLcdParam.OnTimeCt = 0;
- //电话本
- SetPhoneNumFile("HGS.Tell");
- //短信
- SetMessageConfi();
- //SetCodePara();
- LedInit();
- SlwTrace(INF,"Led Init...",1);
- g_iFun2KeyEncodeCt=0;
- bootMapCnt=os_time_get()+2000;//开机界面持续20秒
- //create PocTask
- idModemUartTask=os_tsk_create_user(ModemUartTask,3,&stkModemUartTask,sizeof(stkModemUartTask));
- idModemTask=os_tsk_create_user(ModemTask,3,&stkModemTask,sizeof(stkModemTask));
- //idTTSTask=os_tsk_create_user(TTSTask, 3, &stkTTSTask,sizeof(stkTTSTask));
- RunMake(THIS_FILE_ID);
-
- UI_Init();
- while(1)
- {
- if(bootFlag==0)
- {
- if((os_time_get() > bootMapCnt) || sutPocStatus.FirstLogined)
- bootFlag=1;
- }
- PowerOffProtetion();
- if(bootFlag==1)
- UI_Loop();
- os_dly_wait(1);
- IncomingSMS();
- LocalTTSHandle();
- //处理PC发送过来的消息
- RunMake(THIS_FILE_ID);
- if(g_usUart1RecvLen){
- PcMsgHandle((char *)RxBuffer1);
- g_usUart1RecvLen=0;
- DMA1_Channel5->CNDTR = UART1_RX_BUFFER_SIZE;//重设DMA传输数据长度
- DMA_Cmd(DMA1_Channel5,ENABLE);//打开DMA
- }
- RunMake(THIS_FILE_ID);
- apnUpdateFun();
- //键盘处理
- if(0!=(KeyFlag=GetKey())){
- //按键处理
- if(1==KeyFlag){ //按键按下
- KeyPress();
- //if(g_ulKeyValue != KEY_PPT &&
- // g_ulKeyValue != KEY_PPT_MIC)
- //{
- LCDTimeOut(0);
- sutLcdParam.OnTimeCt=0;
- //}
- }else{ //按键释放
- KeyFree();
-
- }
- }
- RunMake(THIS_FILE_ID);
- //LED处理
- LedProcess(0);
- #if(USE_CONFIG_FUN==1)
- ConfigModeDetect();
- #endif
- GTMode_Detected();
- //---以下控制每秒执行一次---
- if(os_time_get() < sucCt) continue;
- sucCt = os_time_get()+100;
- RunMake(THIS_FILE_ID);
- KeyCount();//键盘按下、释放计数控制
- RunMake(THIS_FILE_ID);
- //信号
- //测量电池电压
- Vbat=GetVbat();
- if(Vbat>0)g_iVbat=Vbat;
- //判断电池电压是否过低关机
- if(ucCheckVbatCt<3)ucCheckVbatCt++;
- else CheckVbat(g_iVbat);
- //MODEM防护
- FingerDaemonfinger(); //3.21关闭
- SwitchGroupCtrl();
- if(sutLcdParam.OnTime>0){
- if(++sutLcdParam.OnTimeCt>=sutLcdParam.OnTime){
- sutLcdParam.OnTimeCt=0;
- if(sutPocStatus.FirstLogined==1)//没登陆过(刚开机),LCD一直亮着
- LCDTimeOut(1);
- }
- }
- }
- }
- void ADCInit(void)
- {
- ADC_InitTypeDef ADC_InitStructure;
- GPIO_InitTypeDef GPIO_InitStructure;
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
-
- GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0;
- GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IPU;//先内部上拉模式给IO充能
- GPIO_Init(GPIOA,&GPIO_InitStructure);
- DelayMs(100);
- GPIO_InitStructure.GPIO_Mode =GPIO_Mode_AIN;
- GPIO_Init(GPIOA,&GPIO_InitStructure); //默认速度为两兆
- DelayMs(200);//让电平恢复正常
-
- //配置ADC的运行:
- ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //独立模式
- ADC_InitStructure.ADC_ScanConvMode =DISABLE; //连续多通道模式
- ADC_InitStructure.ADC_ContinuousConvMode =DISABLE;//ENABLE; //连续转换
- ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //转换不受外界决定
- ADC_InitStructure.ADC_DataAlign =ADC_DataAlign_Right; //右对齐
- ADC_InitStructure.ADC_NbrOfChannel =1; //扫描通道数
- ADC_Init(ADC1,&ADC_InitStructure);
- ADC_RegularChannelConfig(ADC1,ADC_Channel_0, 1,ADC_SampleTime_1Cycles5); //通道X,采样时间为1.5周期,1代表规则通道第1个这个1是啥意思我不太清楚只有是1的时候我的ADC才正常。
- ADC_Cmd (ADC1,ENABLE); //使能或者失能指定的ADC
- ADC_SoftwareStartConvCmd(ADC1,ENABLE);//使能或者失能指定的ADC的软件转换启动功能
- }
- void GPIO_Config_ALL_AIN(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Enable GPIOD and GPIOE clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB
- | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD
- | RCC_APB2Periph_AFIO, ENABLE);
-
-
- /* Disable the Serial Wire Jtag Debug Port SWJ-DP */
- GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
-
- /* PA */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /* PB */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- /* PC */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- /* PD */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA
- | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD
- , DISABLE);
- }
- /***********************************************************************
- *获取电池电压
- 返回值: -1为无效 ; 正数表示电池电压放大100倍,如 382表示3.82V
- ***********************************************************************/
- int GetVbat(void)
- {
- char buf[30];
- static int Ct=0;
- static int siVbat[10]={0,0,0,0,0,0,0,0,0,0};
- int iVbat[10];
- int max[5];
- int sum;
- int i,j,k;
-
- int adc;
- int Vbat;
- #if 1
- ADC_SoftwareStartConvCmd(ADC1,ENABLE);
- while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
- adc=ADC_GetConversionValue(ADC1);
- if(adc<100 && adc>4095)
- {
- printf("VDAC OVER");
- return -1;
- }
- #else
- //采集ADC
- if(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)!=RESET){//检查制定ADC标志位置1与否 ADC_FLAG_EOC 转换结束标志位 if(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)!=RESET){
-
- ADC_SoftwareStartConvCmd(ADC1,ENABLE);
- adc=ADC_GetConversionValue(ADC1);
- if(adc<100 && adc>4095)
- {
- //printf("ERR1");
- return -1;
- }
- }else
- {
- printf("ERR2");
- return -1;
- }
- #endif
- //循环存储
- siVbat[Ct]=adc;
- if(++Ct>9)Ct=0;
- //printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n",siVbat[0],siVbat[1],siVbat[2],siVbat[3],siVbat[4],siVbat[5],siVbat[6],siVbat[7],siVbat[8],siVbat[9]);
- //滤波处理,排列取3个最大值,3个最大中去掉第一大,其余求平均
- //拷贝
- for(i=0;i<10;i++){
- iVbat[i]=siVbat[i];
- }
- for(i=0;i<4;i++){
- max[i]=0;
- for(j=0;j<10;j++){
- if(iVbat[j]>max[i]){
- max[i]=iVbat[j];
- k=j;
- }
- }
- iVbat[k]=0;
- }
- // printf("%d,%d,%d\r\n",max[0],max[1],max[2]);
- sum=max[1]+max[2];
- if(max[2]<200)
- {
- //printf("ERR3");
- return -1;
- }
- Vbat=sum*308/4096;
- return Vbat;
- }
- void Sys_Standby(void)
- {
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); //使能PWR外设时钟
- PWR_WakeUpPinCmd(ENABLE); //使能唤醒管脚功能,PA0
- PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);
- }
- /*******************************************************
- *CheckVbat
- *检查电池电压,控制低压报警,
- *低压关机已由硬件监测
- ******************************************************/
- void CheckVbat(int Vbat)
- {
- static unsigned char sucCt=0;//提示“请充电”计数器
- if(Vbat<MIN_PWR_LEVEL){//300
- SlwTrace(INF,"Vbat low!shutdown now!",1);
- os_dly_wait(1);
- //关闭模块
- if(sutPocStatus.ModemPowerOn==1){
- #if 1
- //发送机指令并等待7秒
- cmdShutDown(1);
- #else
- SpeakerEnable();
- ModemSendAT("AT+LSHTTSSTP\r\n");
- os_dly_wait(30);
- ModemSendAT("AT+LSHTTS=1,\"B5CDD1B9B4FDBBFA\"\r\n");//低压待机
- IWDG_ReloadCounter();
- os_dly_wait(100);
- IWDG_ReloadCounter();
- os_dly_wait(100);
- SlwTrace(INF,"ModemPoweroff!",1);
- ModemPoweroff();
- #endif
- }
- sutPocStatus.ModemPowerOn=0;
- PWR_EN_LOW;
- Sleeping();
- }else if(Vbat<WARN_PWR_LEVEL){//提示请充电 315
- if(++sucCt>30){
- sucCt=0;
- //MeSpeak(ENCODE_GBK, "C7EBB3E4B5E7",0);//请充电
- }
-
- }else sucCt=0;
-
- }
- void GetXinHao(int CSQ,char *XinHao)
- {
-
- if(CSQ>31 || CSQ<1){
- strcpy(XinHao,"2C00E065517FDC7EE14FF753");//无网络信号
-
- }else if(CSQ>25){
- //信号较强 "E14FF753838F3A5F"
- strcpy(XinHao,"E14FF753838F3A5F");
- }else if(CSQ>17){
- //信号适中 "E14FF75302902D4E"
- strcpy(XinHao,"E14FF75302902D4E");
- }else if(CSQ>10){
- //信号偏低 "E14FF7534F504E4F"
- strcpy(XinHao,"E14FF7534F504E4F");
- }else{
- //信号很弱 "E14FF753885F315F"
- strcpy(XinHao,"E14FF753885F315F");
- }
- }
- void GetVbatPercent(int Vbat,char *Percent)
- {
- //10 20 30 40 50 60 70 80 90 100
- const char *ccPercent[]={
- "31003000",
- "32003000",
- "33003000",
- "34003000",
- "35003000",
- "36003000",
- "37003000",
- "38003000",
- "39003000",
- "310030003000"};
-
- //播报电量百分比 10,20,30, 40, 50, 60, 70, 80, 90,100
- const int siVbat[] ={335,343,350,360,370,377,384,392,400,500};
- int i;
- for(i=0;i<10;i++){
- if(Vbat<siVbat[i])break;
- }
- if(i>9)i=9;
- strcpy(Percent,ccPercent[i]);
- }
- /***************************************************************************
- 将数字转Unicode编码
- pUnicode空间最长 5*4+1=21字节
- ****************************************************************************/
- void NumToUnicode(unsigned short Num,char *pUnicode)
- {
- char temp[6];
- int i,j,len;
- snprintf(temp, sizeof(temp),"%u",Num);//0~65535
- len=strlen(temp);
- j=0;
- for(i=0;i<len;i++){
- pUnicode[j++]=0x30+temp[i]/16;
- pUnicode[j++]=0x30+temp[i]%16;
- pUnicode[j++]=0x30;
- pUnicode[j++]=0x30;
- }
- pUnicode[j]=0;
- }
- void ReportVersion(void)
- {
- char buf[150];
- char temp[20];
- snprintf(buf, sizeof(buf),"AT+ZTTS=1,\"945E287548722C67");
- NumToUnicode(sutProductPara.ProductVersion,temp);
- strcat(buf,temp);
- strcat(buf,"2C00F95BB28B48722C67");
- NumToUnicode((unsigned short)g_iModemVer,temp);
- strcat(buf,temp);
- strcat(buf,"\"\r\n");
- SpeakerEnable();
- ModemSendAT(buf);//应用版本
- SlwTrace(INF,buf,0);
- /*
- SlwTrace(INF,"[ReportVersion]");
- sprintf(buf,"Mcu=%u,Modem=%u\r\n",sutProductPara.ProductVersion,(unsigned short)g_iModemVer);
- SlwTrace(INF,buf);
- */
-
- }
- /*******************************************************************
- *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);
- p+=ParaLen;
- //--
- while(*p>0x20 && ';'!=*p && ValueLen<=80){
- *Value=*p;
- p++;
- Value++;
- ValueLen++;
- }
- *Value=0;
- return ValueLen;
- }
- void IWDG_Configuration(unsigned int value)
- {
- // WWDG 时钟使能
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
- if(RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)RCC_ClearFlag();
- //写入0x5555,用于允许狗狗寄存器写入功能
- IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
-
- //狗狗时钟分频,40K/256=156HZ(6.4ms)
- IWDG_SetPrescaler(IWDG_Prescaler_256);
-
- //喂狗时间
- //IWDG_SetReload(200);1.28s/6.4MS=200 .注意不能大于0xfff
- IWDG_SetReload(value);//3.2s/6.4MS=500 .注意不能大于0xfff
-
- //喂狗
- IWDG_ReloadCounter();
-
- //使能狗狗
- IWDG_Enable();
- }
- /*
- 此处修改:删去ModemSendAT("2C00");另外pocTask.cReplaceStrWithN(&msg[9]、msg[17]);强制将字符串后面的\n\r去掉
- */
- void ReportUserGroupName(void)
- {
- #if POC_USER_NAME_LEN>POC_GROUP_NAME_LEN
- char buf[POC_USER_NAME_LEN*4];
- #else
- char buf[POC_GROUP_NAME_LEN*4];
- #endif
-
-
- SpeakerEnable();
- ModemSendAT("AT+ZTTS=1,\"");
- AnsiToStrUnicode((uint8_t *)buf,sizeof(buf),sutPocStatus.LocalUser.name); //函数功能未实现,需要修改
- ModemSendAT(buf);
- AnsiToStrUnicode((uint8_t *)buf,sizeof(buf),sutPocStatus.LocalUser.name);
- ModemSendAT(buf);
- ModemSendAT("\"\r");
-
-
- }
- void SetPowerEn(unsigned char en)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- if(en!=0){
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Pin = PWR_EN_PIN;
- GPIO_Init(PWR_EN_PORT, &GPIO_InitStructure);
- PWR_EN_HIGH;
- }else{
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Pin = PWR_EN_PIN;
- GPIO_Init(PWR_EN_PORT, &GPIO_InitStructure);
- PWR_EN_LOW;
- }
- }
- /*****************************************************************************************
- *函数名:GetCheckCodeByPsnMEID
- *功能:根据PSN号和MEID码,生成伪随机码
- *入口:PSN--PSN码,无符号长整形,必须是大于150000000的数值,有可能是9位数也可能是10位数
- pMEID--MEID字串,长度14位或15位,第16字节必须为0。
- *出口:pCheckCode:--长度为6的字符串,第7字节为结束符0x00,因此必须留够7字节的空间!
- 返回:1--成功 0--因参数非法而失败
- ******************************************************************************************/
- const unsigned char sucRandTable[256]={
- 0x68,0x59,0x63,0x64,0xc8,0xcc,0xaa,0xa7,0xa2,0xab,0xa5,0x6e,0x6a,0x56,0x8a,0x57,
- 0xf4,0xbb,0xfe,0xfa,0x26,0x21,0x2d,0x29,0x0d,0x09,0x3e,0x3a,0x37,0x32,0x0a,0x07,
- 0xf7,0xf2,0xfb,0xf5,0xff,0xf6,0x1c,0x18,0x13,0x14,0xf1,0xfd,0xf9,0x0c,0x9f,0x08,
- 0x9a,0x97,0x92,0x9b,0x95,0x9f,0x12,0x1b,0x15,0x2c,0x28,0x23,0xf9,0x2a,0x27,0x22,
- 0x24,0x2e,0x67,0x25,0x2f,0x98,0xfc,0x75,0xf8,0xf3,0x3c,0x38,0x33,0x34,0x03,0x04,
- 0x05,0x0f,0x06,0x01,0x7a,0x77,0x72,0x62,0x6b,0x83,0x84,0x8e,0xc4,0xcb,0x87,0x82,
- 0x35,0x3f,0x36,0x4f,0x3d,0x39,0x9c,0x98,0x93,0x94,0x42,0x4f,0x46,0x41,0x81,0x8d,
- 0x4d,0x49,0x71,0x7d,0x79,0x96,0x91,0x9d,0x99,0xc3,0xc4,0x1d,0xce,0xca,0x7f,0x76,
- 0x7c,0x78,0x73,0x74,0x7e,0x7b,0x75,0x1e,0x1a,0x17,0x1f,0x16,0x11,0x1d,0x47,0x19,
- 0x5d,0xc7,0xc2,0xcb,0xc5,0xcf,0xd1,0xdd,0xd9,0x4c,0x48,0xc6,0xc1,0xcd,0x61,0xc9,
- 0xd7,0x8c,0xfd,0x88,0xa1,0xad,0xa9,0xb1,0xbd,0xb9,0x8b,0x85,0x8f,0x4b,0x45,0x86,
- 0xdc,0xd8,0xd3,0xd4,0xde,0xd2,0xdb,0xd5,0xdf,0xd6,0x43,0x44,0x4e,0x4a,0xe7,0x47,
- 0xac,0xa8,0xa3,0xa4,0xae,0xba,0x0d,0xb7,0xb2,0xaf,0xa6,0xe4,0xee,0xea,0xe7,0xe2,
- 0xe1,0xed,0x0f,0xe9,0x66,0x61,0x6d,0x69,0xbb,0xb5,0xbf,0xb6,0xec,0xe8,0x0b,0xe3,
- 0x52,0x5c,0x65,0x6f,0x58,0x53,0x54,0x0c,0x5e,0x5b,0x55,0x5f,0x31,0x2f,0x9a,0x0b,
- 0x0b,0x5a,0x2b,0x9e,0x02,0x89,0x59,0x3b,0x0e,0x51,0x6c,0xeb,0xda,0xe6,0x31,0xf6
- };
- int GetCheckCodeByPsnMEID(char *pCheckCode,unsigned long PSN,char *pMEID)
- {
- char aucPSN[12];
- char aucMEID[16];
- unsigned char key[10];
- unsigned char temp1,temp2;
- int MeidLen,PsnLen;
- int i,j;
- //PSN合法性检测
- if(PSN<150100000)return 0;
- //MEID合法性检测
- MeidLen=strlen(pMEID);
- //if(MeidLen!=14 && MeidLen!=15)return 0; //MEID号长度必须为14或15
- if(MeidLen!=14 && MeidLen!=15){
-
- snprintf(aucPSN, sizeof(aucMEID),"%015lu",pMEID); //不够15位前面补零
- }
-
- //PSN转字符串,不够10位的前面补'0'
- snprintf(aucPSN, sizeof(aucPSN),"%010lu",PSN);
- PsnLen=strlen(aucPSN);
- //取MEID的最后10个字符
- j=0;
- for(i=(MeidLen-10);i<MeidLen;i++){
- aucMEID[j]=pMEID[i];
- j++;
- }
- //所有字节进行相互异或运算,使每个字节的变化对整体结果都敏感
- temp1=0;
- temp2=0;
- for(i=0;i<10;i++){
- temp1^=(unsigned char)aucPSN[i];
- temp2^=(unsigned char)aucMEID[i];
- }
- temp1^=temp2;
- temp2=sucRandTable[temp1];
- //循环查表异或运算,生成key
- for(i=0;i<10;i++){
- temp1=aucPSN[i]^temp2;
- key[i]=aucMEID[i]^temp1;
- temp2=sucRandTable[temp1];
- }
- //取最后6个key,分别除10取余后再转Ascii,作为结果,结果为6个数字串,如"123456"
- j=0;
- for(i=4;i<10;i++){
- pCheckCode[j]=key[i]%10;
- pCheckCode[j]+=0x30;
- j++;
- }
- pCheckCode[6]=0; //结束符,方便调试打印和语音播报。
- return 1;
- }
- //使用12位唯一ID生成唯一7位(14位)鉴权码
- void makeAuthCode(unsigned char *auth)
- {
- unsigned char i,temp1,temp2;
- unsigned char tempAuth[14]="hS";//前面设置成唯一的
- unsigned char srcId[12];
- GetSTM32ID(srcId);
-
- temp1=0;
- for(i=0;i<12;i++)
- {
- temp1 ^= srcId[i];
- temp1 ^= i;
- }
-
- memcpy(&tempAuth[2], srcId, 12);
- for(i=0;i<14;i++)
- {
- temp2 = tempAuth[i] ^ sucRandTable[temp1];
- tempAuth[i] = temp1 ^ temp2;
- }
- //组合成7个字节内容
- AscStrToHexStr(tempAuth, auth);
- }
- /***************************************************************************
- 将数字串转Unicode编码,方便播报
- pUnicode长度必须为pNum长度的8倍,否则内存溢出!
- ****************************************************************************/
- void NumStrToUnicode(char *pNum,char *pUnicode)
- {
- char temp[10];
- int i,j,len;
- len=strlen(pNum);
- snprintf(temp, sizeof(temp),"len=%d",len);
- SlwTrace(INF,temp,1);
-
- j=0;
- for(i=0;i<len;i++){
- pUnicode[j++]='3';
- pUnicode[j++]=pNum[i];
- pUnicode[j++]='0';
- pUnicode[j++]='0';
-
- if(i==(len-1))break;//最后一个不用加逗号‘,’
- //","
- pUnicode[j++]='2';
- pUnicode[j++]='0';
- pUnicode[j++]='0';
- pUnicode[j++]='0';
- }
- pUnicode[j]=0;
- }
- /**************************************************************
- *ReportCheckCode
- ***************************************************************/
- void ReportCheckCode(void)
- {
- char temp[12];
- char buf[80];
- SpeakerEnable();
- //终端编号xxxx
- if(sutProductPara.PSN<150100000 || sutProductPara.PSN==0xffffffff){
- SlwTrace(INF,"PSN Error!",1);
- ModemSendAT("AT+ZTTS=1,\"C87EEF7A167FF7531995EF8B\"\r");//终端编号错误
- return;
- }
- //校验码xxxx
- if(GetCheckCodeByPsnMEID(temp,sutProductPara.PSN,sutProductPara.HARDID)){
- snprintf(buf, sizeof(buf),"CheckCode=%s",temp);
- SlwTrace(INF,buf,1);
- NumStrToUnicode(temp,buf);
- ModemSendAT("AT+ZTTS=1,\"21688C9A01782C00");//校验码,
- ModemSendAT(buf);
- ModemSendAT("\"\r");
- }else{
- SlwTrace(INF,"CheckCode=NULL",1);
- ModemSendAT("AT+ZTTS=1,\"21688C9A0178B783D6533159258D\"\r");//校验码获取失败
- }
- IWDG_ReloadCounter();//喂狗
- os_dly_wait(100);
- IWDG_ReloadCounter();//喂狗
- os_dly_wait(100);
- IWDG_ReloadCounter();//喂狗
- os_dly_wait(100);
- IWDG_ReloadCounter();//喂狗
-
- //终端编码xxx
- snprintf(temp, sizeof(temp),"%lu",sutProductPara.PSN);
- snprintf(buf, sizeof(buf),"CheckCode=%s",temp);
- SlwTrace(INF,buf,1);
- NumStrToUnicode(temp,buf);
- ModemSendAT("AT+ZTTS=1,\"C87EEF7A167FF7532C00");//终端编码,
- ModemSendAT(buf);
- ModemSendAT("\"\r");
- }
- /************************************************************************************
- ResetModem
- *************************************************************************************/
- void ResetModem(void)
- {
- //set modem reset
- MODEM_RESET_HIGH;
- os_dly_wait(100);
- MODEM_RESET_LOW;
- MODEM_PWRKEY_HIGH;
- os_dly_wait(100);
- MODEM_PWRKEY_LOW;
- //set uart3 reset
- Uart3Init();
- }
- /*************************************************************************************
- *FingerDaemonfinger
- *守护进程
- *用于防止通讯模块死机,或者与通讯模块通讯的串口异常而重新启动模块或通讯驱动。
- *用于防止GPS模块异常而重启GPS
- *此函数需要确保每秒调用一次
- 入口参数
- sutPocStatus.FirstLogined
- sutPocStatus.PocLostCt
- sutPocStatus.ModemPowerOn
- sutPocStatus.ModemInactiveCt
- g_iCSQ
- **************************************************************************************/
- void FingerDaemonfinger(void)
- {
- static unsigned char sucPocLostTimeoutCount=0;//
- static unsigned char sucModemInactiveCount=0;
- unsigned short PocLostCtMax;
-
- IWDG_ReloadCounter();//喂狗
- //return;
- if(g_ucModemTaskEn==0)return;
-
- //如果曾经登陆过POC系统,然后离线,开始计数,直到再次登陆,如果一直不登陆超过一定时间,则重启模块和串口
- if(sutPocStatus.FirstLogined){
- if(sutPocStatus.Logined==0){
-
- PocLostCtMax=pocTimeOutTime*60;
-
- if(++sutPocStatus.PocLostCt>PocLostCtMax){
- sutPocStatus.PocLostCt=0;
- //长时间不登陆,重启模块及串口驱动部分
- SlwTrace(INF,"PocLostTimeout!Reset Modem!",1);
- ResetModem();
- }
- }else{
- sutPocStatus.PocLostCt=0;
- sucPocLostTimeoutCount=0;
- }
- }else{
- //一个小时未登录复位模块
- if(++sutPocStatus.PocLostCt>3600){
- sutPocStatus.PocLostCt=0;
- ResetModem();
- }
- }
- //如果模块已开机,长时间收不到串口消息,则重启模块及串口驱动部分
- if(sutPocStatus.ModemPowerOn==1){
- if(sutPocStatus.ModemInactiveCt==0){//ModemInactiveCt必须在接收到Modem串口消息后才清零
- sucModemInactiveCount=0;
- }
- if(++sutPocStatus.ModemInactiveCt>40){//等待时间15秒 4G模块重启后至少要15秒才能启动
- sutPocStatus.ModemInactiveCt=1;
- //长时间收不到串口消息,重启模块及串口驱动
- SlwTrace(INF,"ModemRecvTimeout!Reset Modem!",1);
- ResetModem();
- }
- }
- //GPS守护
- if(sutGpsInfo.isGpsWork>0){
- if(++sutGpsInfo.GpsInactiveCt>10){
- sutGpsInfo.GpsInactiveCt=0;
- //复位GPS
- GPSInit();
- Uart3Init();
- TSGpsDataInit();
- }
- }
- }
- /**************************************
- *延时(带喂狗)
- t 系统滴答为单位
- ***************************************/
- void OsDelayTime(unsigned short t)
- {
- int i;
- for(i=0;i<t;i++){
- os_dly_wait(1);
- IWDG_ReloadCounter();//喂狗
- }
- }
- //255.255.255.255
- //-->0xff 0xff 0xff 0xff
- unsigned char GetStringIP2Bytes(unsigned char *IPBytes,char *IPString)
- {
- unsigned char len,i,segment,j;
- char *p;
- char temp[3];
- len = strlen(IPString);
- if(len<7 || len >15) return 1;
- segment=0;
- j=0;
- p=IPString;
- for(i=0;i<len;i++)
- {
- if(IPString[i] == '.')
- {
- if(segment < 4) IPBytes[segment++] = atoi(p);
- else return 2;
- p=&IPString[i+1];
- }else if(IPString[i] < '0' || IPString[i] > '9') return 3;
- }
- if(segment < 5) IPBytes[segment++] = atoi(p);
- return 0;
- }
- void MakeStrEndByNewLine(char *str)
- {//一定要以'\r'结尾
- unsigned short i;
-
- for(i=0;i<strlen(str);i++)
- {
- if(str[i] == '\r')
- {
- str[i]=0;
- return;
- }
- }
- }
- uint16_t StrUnicodeToAnsi(uint8_t *dest,uint16_t size,const char *src)
- {
- //不需要转
- }
- uint16_t AnsiToStrUnicode(uint8_t *dest,uint16_t size,const char *src)
- {
- //不需要转
- }
- //"3132" --> 0x31,0x32
- void StrAsciiToHex(char *src, unsigned char *des)
- {
- unsigned char temp[2],i;
- if(strlen(src)%2) return;
- while(0!=*src)
- {
- for(i=0;i<2;i++)
- {
- temp[i] = *src++;
- if(temp[i] >= '0' && temp[i] <= '9') temp[i] -= 0x30;
- else if(temp[i] >= 'A' && temp[i] <= 'F') temp[i] -= 0x37;
- else temp[i] -= 0x57;
- }
- temp[0] <<= 4;
- temp[0] &= 0xf0;
- *des++=temp[0]|temp[1];
- }
- *des=0;
- }
- void PrintBufferData(unsigned char *data, unsigned short length)
- {
- unsigned short i;
-
- printf("Data[%d]:\r\n",length);
-
- for(i=0;i<length;i++) printf("%02x",data[i]);
- printf("\r\n");
- }
|