12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183 |
- /********************************************************************************
- * 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"
- //OS ID
- OS_TID idMainTask=0;
- U64 stkMainTask[MAIN_TASK_STK_SIZE];
- unsigned char g_net_flag=0;
- unsigned char net_sure=0;
- unsigned char g_net_cnt;
- unsigned char CSQ_flag;// 如果有按键按下,10秒内不触发 CSQ_Prompt();
- unsigned char CSQ_ct=0;
- int g_iVbat=0;
- void FingerDaemonfinger(void);
- unsigned char modemInitReady=0;//0模块没开始初始化 1模块初始化成功 2模块初始化失败
- unsigned char modemPwrOffNow=0;
- unsigned char g_ucUpdataVer=0;
- unsigned char g_ucKeyDownPressFlag=0;
- unsigned char g_ucGroupSelect=0;
- unsigned char g_ucUserSelect=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 char GroupSelectStat=0;//进入群组选择旋转旋钮后无法退出标志
- unsigned char GroupSelectFlag=0;
- unsigned char g_ucEnterGroupFlag=0;
- unsigned char pocTimeOutTime=30;//默认30分钟
- unsigned char g_ucEnterCnt=0;
- //======================================
- void ReportVbatCsqGps(void);
- 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;
-
- /***********************************************
- 强制复位
- ************************************************/
- void SystemReset(void)
- {
- SlwTrace(INF, "SysTem Reset!",1);
- os_tsk_delete(idModemUartTask);
- os_tsk_delete(idModemTask);
- os_tsk_delete(idTTSTask);
- 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);
- //从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,i;
- while((d=(unsigned char)*pAscStr++)!=0||i<(g_GroupNameLen*2)){
- i++;
- l=d&0x0f;
- h=d>>4;
- *HexStr++=AscToHex(h);
- *HexStr++=AscToHex(l);
- }
- *HexStr=0;
- }
- void AscStrToHexStr1(char *AscStr, char *HexStr,unsigned char len)
- {
- char *pAscStr=AscStr;
- unsigned char d,h,l;
- if(len==0)
- {
- while(0 != (d=(unsigned char )*pAscStr++))
- {
- l=d&0x0f;
- h=d>>4;
- *HexStr++=AscToHex(h);
- *HexStr++=AscToHex(l);
- }
- }else
- {
- while(len)
- {
- d=(unsigned char )*pAscStr++;
- l=d&0x0f;
- h=d>>4;
- *HexStr++=AscToHex(h);
- *HexStr++=AscToHex(l);
- len--;
- }
- }
- *HexStr=0;
- }
- char changeDataFormat(char *asciiData, unsigned short len)
- {//"313233"-->0x313233 len = 3
- unsigned char j,temp[2];
- unsigned short i;
-
- for(i=0;i<len;i++)
- {
- temp[0] = asciiData[2*i];
- temp[1] = asciiData[2*i+1];
-
- for(j=0;j<2;j++)
- {
- if(temp[j] >= '0' && temp[j] <= '9') temp[j] -= 0x30;
- else if(temp[j] >= 'A' && temp[j] <= 'F') temp[j] -= 0x37;
- else if(temp[j] >= 'a' && temp[j] <= 'f') temp[j] -= 0x57;
- else return 1;
- }
- temp[0] <<= 4;
- temp[0] &= 0xf0;
- asciiData[i] = temp[0] | temp[1];
- }
- return 0;//OK
- }
- void PcMsgHandle(char *msg)
- {
- const char *CmdList[]={
- "TM", //Trace Modem
- "TG", //Trace GPS
- "DM", //Download Modem
- "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", //Read GPS
- "RMIP", //Read Manager/Load IP
- "SMIP", //Set Manager/Load IP
- "RCIP", //Read ConfigIP
- "SCIP", //Set ConfigIP
- "SACC", //Set access point
- "RACC", //Read access point
- "" //必须以空字串为结束
- };
- unsigned short Port;
- unsigned long PSN;
- char buf[150];
- char buf1[300];
- char strIP[20];
- char strAccessp[20];
- char strAccount[20];
- char strPassword[20];
- int i,j,len;
- char flag;
- const char *pCmd;
- char *pMsg;
- int CmdListNum=0;
- char needSave=0,needSaveNew=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"
- SetLedStatus(RedBlueSlowFlash);
- SlwTrace(INF,"GT+TM:OK",1);
- ComSelect(COM_SEL_MODEM);
- SpeakerEnable();
- break;
- case 1://"TG"
- SetLedStatus(RedBlueSlowFlash);
- SlwTrace(INF,"GT+TG:OK",1);
- ComSelect(COM_SEL_GPS);
- break;
- case 2://"DM"
- SetLedStatus(RedBlueSlowFlash);
- SlwTrace(INF,"GT+DM:OK",1);
- ComSelect(COM_SEL_MODEM);
- MODEM_LED1_LOW;
- MODEM_LED2_HIGH;
- MODEM_PWRKEY_HIGH;
- MODEM_RESET_HIGH;
- MODEM_RESET_LOW;
- while(1){
- IWDG_ReloadCounter();//喂狗
- if(OnOffCheck()){
- PWR_EN_LOW;
- }
- }
- break;
- case 3://"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;
- needSave=1;
- if(0!=GetStringIP2Bytes(sutNewSegmentPara.PIP, strIP))
- {
- SlwTrace(INF,"GT+SMP:FAIL[IP Invalid]",1);
- break;
- }
- sutNewSegmentPara.PocPort=Port;
- needSaveNew=1;
- //send to modem
- if(strlen(sutNewSegmentPara.HARDID)<14){
- SlwTrace(INF,"GT+SMP:FAIL[MEID Invalid]",1);
- break;
- }
- sprintf(buf,"ip=%s;id=%lu;pwd=%s;",strIP,sutProductPara.PSN,sutNewSegmentPara.HARDID);
- AscStrToHexStr(buf,buf1);
- ModemSendAT("AT+POC=010000");
- ModemSendAT(buf1);
- ModemSendAT("\r\n");
- //save para
- sprintf(buf,"GT+SMP:IP=%d.%d.%d.%d;Port=%u;PSN=%lu",sutNewSegmentPara.PIP[0],sutNewSegmentPara.PIP[1],sutNewSegmentPara.PIP[2],sutNewSegmentPara.PIP[3],
- sutNewSegmentPara.PocPort,sutProductPara.PSN);
- SlwTrace(INF,buf,1);
- break;
- case 4://"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);
-
- if(0!=GetStringIP2Bytes(sutNewSegmentPara.GIP, strIP))
- {
- SlwTrace(INF,"GT+SGP:FAIL[IP Invalid]",1);
- break;
- }
- sutNewSegmentPara.GpsPort=Port;
- needSaveNew=1;
- //echo
- sprintf(buf,"GT+SGP:IP=%d.%d.%d.%d;Port=%u;",sutNewSegmentPara.GIP[0],sutNewSegmentPara.GIP[1],sutNewSegmentPara.GIP[2],sutNewSegmentPara.GIP[3],
- sutNewSegmentPara.GpsPort);
- SlwTrace(INF,buf,1);
- break;
- case 5://"RMP" GT+RMP<CR><LF> PSN=终端序列号;MEID=模块MEID号;CNUM=电信号;UIMID=电信UIMID;
- sprintf(buf,"GT+RMP:PSN=%lu;MEID=%s;CNUM=0000000000;UIMID=0000000000;IP=%d.%d.%d.%d",sutProductPara.PSN,sutNewSegmentPara.HARDID,
- sutNewSegmentPara.PIP[0],sutNewSegmentPara.PIP[1],sutNewSegmentPara.PIP[2],sutNewSegmentPara.PIP[3]);
- SlwTrace(INF,buf,1);
- break;
- case 6://"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 7://"VER"
- sprintf(buf,"GT+VER:%s_V%d",sutProductPara.ProductName,sutProductPara.ProductVersion);
- SlwTrace(INF,buf,1);
- break;
- case 8://BAT
- sprintf(buf,"GT+BAT: %d V",g_iVbat);
- SlwTrace(INF,buf,1);
- break;
- case 9://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<0 || len > APNNAME_LEN){
- SlwTrace(INF,"GT+APN:FAIL[Account Invalid]",1);
- return;
- }
- if(len == 0) sutProductPara.APNName[0]=0;//空值
- else strcpy(sutProductPara.APNName,buf);
-
- len=GetParaFromStr(msg,"Password",buf);
- if(len<0 || len > APNPASS_LEN){
- SlwTrace(INF,"GT+APN:FAIL[Password Invalid]",1);
- return;
- }
- if(len == 0) sutProductPara.APNPass[0]=0;//空值
- else strcpy(sutProductPara.APNPass,buf);
-
- needSave=1;
- sprintf(buf1,"GT+APN:Account=%s;Password=%s;",sutProductPara.APNName,sutProductPara.APNPass);
- SlwTrace(INF,buf1,1);
- //写入Modem
- ModemSendAT("AT+ZPIDPWD=");
- ModemSendAT(sutProductPara.APNName);
- ModemSendAT(",");
- ModemSendAT(sutProductPara.APNPass);
- ModemSendAT("\r\n");
- break;
- case 10://RAPN
- sprintf(buf1,"GT+RAPN:Account=%s;Password=%s;",sutProductPara.APNName,sutProductPara.APNPass);
- SlwTrace(INF,buf1,1);
- break;
- case 11://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=80;
- SetBeep(i,Port);
- sprintf(buf,"BEEP=%dHz,%dms",i,Port);
- SlwTrace(INF,buf,1);
- break;
- case 12://RGP
- sprintf(buf,"GT+RGP:IP=%d.%d.%d.%d;PORT=%d;",sutNewSegmentPara.GIP[0],sutNewSegmentPara.GIP[1],sutNewSegmentPara.GIP[2],sutNewSegmentPara.GIP[3],
- sutNewSegmentPara.GpsPort);
- SlwTrace(INF,buf,1);
- break;
- case 13://RMIP
- sprintf(buf,"GT+RMIP:IP=%d.%d.%d.%d;PORT=%d;",sutNewSegmentPara.ManagerIP[0],sutNewSegmentPara.ManagerIP[1],sutNewSegmentPara.ManagerIP[2],sutNewSegmentPara.ManagerIP[3],sutNewSegmentPara.ManagerPort);
- SlwTrace(INF,buf,1);
- break;
- case 14://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(sutNewSegmentPara.ManagerIP, strIP);
- sutNewSegmentPara.ManagerPort=Port;
- //Save para to flash
- needSaveNew=1;
- //echo
- sprintf(buf,"GT+SMIP:IP=%d.%d.%d.%d;Port=%u;",sutNewSegmentPara.ManagerIP[0],
- sutNewSegmentPara.ManagerIP[1],
- sutNewSegmentPara.ManagerIP[2],
- sutNewSegmentPara.ManagerIP[3],
- sutNewSegmentPara.ManagerPort);
- SlwTrace(INF,buf,1);
- break;
- case 15://RCIP
- sprintf(buf,"GT+RCIP:IP=%d.%d.%d.%d;PORT=%d;",sutNewSegmentPara.ConfigSerIP[0],
- sutNewSegmentPara.ConfigSerIP[1],
- sutNewSegmentPara.ConfigSerIP[2],
- sutNewSegmentPara.ConfigSerIP[3],
- sutNewSegmentPara.ConfigSerPort);
- SlwTrace(INF,buf,1);
- break;
- case 16://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(sutNewSegmentPara.ConfigSerIP, strIP);
- sutNewSegmentPara.ConfigSerPort=Port;
- //Save para to flash
- needSaveNew=1;
- //echo
- sprintf(buf,"GT+SCIP:IP=%d.%d.%d.%d;Port=%u;",sutNewSegmentPara.ConfigSerIP[0],
- sutNewSegmentPara.ConfigSerIP[1],
- sutNewSegmentPara.ConfigSerIP[2],
- sutNewSegmentPara.ConfigSerIP[3],
- sutNewSegmentPara.ConfigSerPort);
- SlwTrace(INF,buf,1);
- break;
- case 17://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);
- needSave=1;
- sprintf(buf1,"GT+SACC:Accessp=%s;",sutProductPara.APNApn);
- SlwTrace(INF,buf1,1);
- break;
- case 18://RACC
- sprintf(buf,"GT+RACC:Accessp=%s;",sutProductPara.APNApn);
- SlwTrace(INF,buf,1);
- break;
- }
- if(needSave) SaveProductParaToFlash();
- if(needSaveNew) SaveNewSegmentToFlash();
- RunMake(THIS_FILE_ID);
- }
- volatile static unsigned int pttPressFressCt;
- /***********************************************************************
- *按键按下事件
- ************************************************************************/
- void KeyPress(void)
- {
- char buf[30];
- static unsigned char sucReportFlag=0;
- switch(g_ulKeyValue){
-
- //-------------------------------------------------------------------
- #ifdef USE_NEW_KEY_DRI
- case KEY_PTT:
- case KEY_MIC_PTT:
- #else
- case KEY_PPT://=====================PPT KEY Press====================
- #endif
- //-------------------------------------------------------------------
- g_ucKeyPPTPress=1;
- g_ucKeyMode=1;//单次模式
- SlwTrace(INF,"[PPT Press]",1);
- //--
- if(g_ucGroupSelect==2)
- {//群组选择模式
- g_ucEnterCnt=0;
- g_ucEnterGroupFlag=1;//切换群组动作
- g_ucGroupSelect=0;
- SpeakerEnable();
- sprintf(buf, "AT+POC=090000%s\r\n",sutPocStatus.GroupIdTemp);
- ModemSendAT(buf);
- SlwTrace(INF,"[ExitGroupSel]",1);
- os_dly_wait(20);//+
- }else if(g_ucUserSelect==2)
- {//成员选择模式
- g_ucUserSelect=3;
- //if(sutPocStatus.UserOnLineNum!=0&&(i==0)) MeSpeak(ENCODE_GBK, "BDF8C8EB");//进入
- if(sutPocStatus.UserOnLineNum==0) MeSpeak(ENCODE_GBK, "CEDEC6E4CBFCB3C9D4B1D4DACFDF",0);//无其他成员在线
- else
- {
- os_dly_wait(10);
- sprintf(buf,"AT+POC=0A0000%s\r\n",sutPocStatus.UserIdTemp);//发起单呼
- ModemSendAT(buf);
- }
- SlwTrace(INF,"[ExitUserSel]",1);
- }else if(g_net_flag==2){
-
- net_sure=1;
- g_net_flag=0;
- }
- else
- {
- pttPressFressCt=os_time_get()+30;
- sutPocStatus.PPTpress=1;
- ModemSendAT("AT+POC=0B0000\r\n");
- }
- break;
- //-------------------------------------------------------------------
- case KEY_UP://=====================FUN1 KEY Press==================
- //-------------------------------------------------------------------
- g_ucKeyMode=0;//连续触发模式
- SlwTrace(INF,"[KEY1 Press]",1);
-
- if(g_ucFun1KeyPressCt<7)
- {
- g_ucFun1KeyPressCt++;
- if(3==g_ucFun1KeyPressCt && g_ucGroupSelect==0)
- {//进入成员选择
- if(sutPocStatus.Logined==0)return;
-
- g_ucUserSelect=1;
- SlwTrace(INF,"[EnterUserSel]",1);
- MeSpeak(ENCODE_GBK, "B3C9D4B1D1A1D4F1",0);
- os_dly_wait(2);
- ModemSendAT("AT+POC=10000020\r\n");
- os_dly_wait(2);
- sutPocStatus.UserOnLineNum=0;
- sutPocStatus.UserOnLineIndex=0;
- sprintf(buf,"AT+POC=0E0000%s\r\n",sutPocStatus.GroupId);
- SlwTrace(DEBUG,buf,0);
- ModemSendAT(buf);
- }else if(7==g_ucFun1KeyPressCt && g_ucGroupSelect==0){
- g_ucUserSelect=0;
- SlwTrace(INF,"[EnterNetSel]",1);
- g_net_flag=2;
- BroadCast_Net();
- }
-
- }
- break;
- //-------------------------------------------------------------------
- case KEY_DOWN://=====================FUN2 KEY Press=================
- //短按播报成员名称,所在组,长按播报电量信号GPS,
- //按着不放逆时针旋转10次PC TX模式。
- //-------------------------------------------------------------------
- g_ucKeyMode=0;//连续触发模式
- SlwTrace(INF,"[KEY2 Press]",1);
-
- //-------------
- if(g_ucFun2KeyPressCt<9)
- {
- g_ucFun2KeyPressCt++;
- if(3==g_ucFun2KeyPressCt) ReportVbatCsqGps();
- else if(9==g_ucFun2KeyPressCt) ReportVersion();
-
- }
- break;
- }
- }
- void UpdataAppVersion(void)
- {
- return;
- //正旋1格后松开,升级应用版本
- MeSpeak(ENCODE_UNICODE, "C6510759F466B065945E287548722C67F78B73513A678D51005F3A67",0);//准备更新应用版本,请关机再开机
- SlwTrace(INF,"Update APP Version!",1);
- SetLedStatus(RedFastFlash);
- SaveProductParaToFlash();
- while(1)
- {
- IWDG_ReloadCounter();//喂狗
- os_dly_wait(1);
- if(OnOffCheck())
- PWR_EN_LOW;
- }
- }
- void UpdataPocVersion(void)
- {
- char buf[80];
- MeSpeak(ENCODE_GBK, "D5FDD4DAC9FDBCB6",0);
- IWDG_ReloadCounter();
- os_dly_wait(100);
- IWDG_ReloadCounter();
- os_dly_wait(100);
-
- snprintf(buf, sizeof(buf), "AT+SYSCMD=./usr/bin/mAssistant 0 0 phone-client %d %d.%d.%d.%d\r\n",
- g_iPocVer,
- FOTA_IAP_IP0,
- FOTA_IAP_IP1,
- FOTA_IAP_IP2,
- FOTA_IAP_IP3);
- ModemSendAT(buf);
- SlwTrace(INF,"Update POC!",1);
- }
- void EnterGTMode(void)
- {
- 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 ExitGroupSelect(void)
- {
- if(GroupSelectFlag==1)
- {
- os_dly_wait(180);
- MeSpeak(ENCODE_UNICODE, "0090FA51",0);
- sutPocStatus.TTS=0;
- SpeakerDisable();
- }
- GroupSelectFlag=2;
- }
- /***********************************************************************
- *按键释放事件
- ************************************************************************/
- void KeyFree(void)
- {
- int i;
- char CheckCode[10];
- char buf[30];
- #ifdef USE_NEW_KEY_DRI
- if(KEY_PTT==g_ulKeyValue || KEY_MIC_PTT==g_ulKeyValue)
- #else
- if(KEY_PPT==g_ulKeyValue)
- #endif
- {
- SlwTrace(INF,"[PPT Free]",1);
- g_ucKeyPPTPress=0;
- sutPocStatus.PPTpress=0;
- if(g_ucUserSelect==3) g_ucUserSelect=0;
- else
- {
- if(os_time_get() > pttPressFressCt)
- {
- i=10;
- }else{
- i=pttPressFressCt-os_time_get();
- }
- os_dly_wait(i);
- ModemSendAT("AT+POC=0C0000\r\n");
- }
- g_ucKeyMode=0;
- }else if(KEY_UP==g_ulKeyValue)
- {
- SlwTrace(INF,"[KEY1 Free]",1);
- if(1==g_ucUART1RxMode)
- {
- #if 1
- g_ucUpdataVer=2;
- MeSpeak(ENCODE_UNICODE, "4753A77EF95BB28B48722C67",0);//升级对讲版本
- #else
- if(g_ucUpdataVer==0 || g_ucUpdataVer==2)
- {
- g_ucUpdataVer=1;
- MeSpeak(ENCODE_UNICODE, "4753A77E945E287548722C67",0);//升级应用版本
- }else if(g_ucUpdataVer==1)
- {
- g_ucUpdataVer=2;
- MeSpeak(ENCODE_UNICODE, "4753A77EF95BB28B48722C67",0);//升级对讲版本
- }
- #endif
- g_ucFun1KeyPressCt=0;
- g_iFun1KeyEncodeCt=0;
- return;
- }
- if(g_ucFun1KeyPressCt<3)
- {
- if(2==g_net_flag){
- g_net_flag=0;
- MeSpeak(ENCODE_UNICODE, "0090FA51",0);
- SlwTrace(INF,"[ExitNetSel]",1);
- }else if(g_ucUserSelect)
- {//退出成员选择
- g_net_flag=0;
- g_ucUserSelect=0;
- MeSpeak(ENCODE_UNICODE, "0090FA51",0);
- SlwTrace(INF,"[ExitUserSel]",1);
- }else if(0==g_ucGroupSelect)
- {//进入群组选择
- if(sutPocStatus.Logined==0)return; //从未登录过
- MeSpeak(ENCODE_UNICODE, "A47FC47E0990E962",0);
- SlwTrace(INF,"[EnterGroupSel]",1);
- g_ucGroupSelect=1;
- }else if(1==g_ucGroupSelect || 2 == g_ucGroupSelect)
- {//退出群组选择,包括未动旋钮和已转动旋钮
- g_ucGroupSelect=0;
- MeSpeak(ENCODE_GBK, "CDCBB3F6",0);//退出
- SlwTrace(INF,"[ExitGroupSel]",1);
- }
- }
- g_ucFun1KeyPressCt=0;
- g_iFun1KeyEncodeCt=0;
- //-------------------------------------------------------------------
- }else if(KEY_DOWN==g_ulKeyValue){//=========FUN2 KEY Free============
- //-------------------------------------------------------------------
- SlwTrace(INF,"[KEY2 Free]",1);
- //GT模式下
- if(1==g_ucUART1RxMode)
- {
- if(g_ucUpdataVer==1) UpdataAppVersion();//升级应用版本
- else if(g_ucUpdataVer==2) UpdataPocVersion();//升级对讲版本
- else ReportCheckCode();
- return;
- }
- //正旋2格以上后松开,进入PC TX模式
- if(g_iFun2KeyEncodeCt>2 && 0==g_ucUART1RxMode && g_ucModemTaskEn>0)
- {
- EnterGTMode();
- g_ucFun2KeyPressCt=0;
- g_iFun2KeyEncodeCt=0;
- #if(USE_CONFIG_FUN==1)
- memset((unsigned char *)&sutConfig, 0, sizeof(CONFIG_SER_DEF));
- #endif
- return;
- }
- //逆旋格以上后松开,播报POC GPS IP
- //
- if(g_iFun2KeyEncodeCt<-2 && g_ucFun2KeyPressCt != 3 && g_ucFun2KeyPressCt != 9 )
- {
-
- ReportPocGpsIP();
- }
- else
- //2秒内松开:如果未登陆则播报PSN和校验码,已登陆则播报用户名和群组名
- if(g_ucFun2KeyPressCt<3)
- {//2
-
- if(sutPocStatus.Logined==1){
- if(sutPocStatus.UserName[0]==0 || sutPocStatus.GroupName[0]==0) ReportCheckCode();
- else
- ReportUserGroupName();
- }
- else ReportCheckCode();
- }
-
-
- g_ucFun2KeyPressCt=0;
- g_iFun2KeyEncodeCt=0;
- }
- }
- void others(void)
- {//用于按PTT切换进入某个群组,MCU发TTS播报(模块不支持自己播报)
- if(g_ucEnterGroupFlag)
- {
- if(++g_ucEnterCnt > 3)
- {
- g_ucEnterCnt=0;
- g_ucEnterGroupFlag=0;
- }
- }
- }
- #if(USE_CONFIG_FUN==1)
- void ConfigModeDetect(void)
- {//检测进入配置服务器功能
- //GT模式下
- //先左CONF_PASS1再右CONF_PASS2再左CONF_PASS3
- char buf[20];
- unsigned char timeout=150;
- if(0 != g_ucModemTaskEn) return;
- if(sutConfig.g_ubConfigFlag==0)
- {
- if(sutConfig.g_ubConfigKeyStart)
- {
- if(++sutConfig.g_usConfigCnt >= timeout)
- {//旋转每一慢1.5秒内完成
- if(sutConfig.g_ucConfigKeyStep == 2 && sutConfig.g_ucConfigKeyPCnt == 3)
- {//顺1逆2顺3完成
- sutConfig.g_ubConfigFlag=1;
- sutConfig.g_ubConfigKeyStart=0;
- sutConfig.g_ucConfigKeyStep=0;
- sutConfig.g_ucConfigKeyPCnt=0;
- sutConfig.g_ucConfigKeyNCnt=0;
- sprintf(buf, "AT+TCPCLOSE=%d\r\n", GPS_DATA_SOCKET);
- ModemSendAT(buf);
- SlwTrace(INF, "ConfigModeActive",1);
- MeSpeak(ENCODE_GBK, "D5FDD4DAB7C3CECAC5E4D6C3B7FECEF1C6F7", 0);
- sutConfig.g_ucTcpRetryNum=CONFIG_TCP_RETRY_CNT;
- sutConfig.g_ucConfigStatus=0x01;//上报列表
- sutConfig.g_ubConfigFinished=0;//
- tcpControl=2;
- }else memset((unsigned char *)&sutConfig, 0, sizeof(CONFIG_SER_DEF));
- }
- }
- }
-
- if(1==sutConfig.g_ucConfigKeyPN)
- {//shun
- sutConfig.g_ucConfigKeyPN=0;
- if(0==g_ucModemTaskEn)
- {
- sutConfig.g_ucConfigKeyPCnt++;
- sutConfig.g_usConfigCnt=0;
- sutConfig.g_ubConfigKeyStart=1;
- if(sutConfig.g_ucConfigKeyStep==0)
- {
- if(sutConfig.g_ucConfigKeyPCnt > CONF_PASS1) sutConfig.g_usConfigCnt = 200;//复位
- }else if(sutConfig.g_ucConfigKeyStep == 1)
- {
- if(sutConfig.g_ucConfigKeyNCnt==CONF_PASS2)//顺3前逆2完成了
- {
- sutConfig.g_ucConfigKeyNCnt=0;
- sutConfig.g_ucConfigKeyStep=2;
- }else sutConfig.g_usConfigCnt = timeout;//复位
- }else if(sutConfig.g_ucConfigKeyStep==2)
- {
- if(sutConfig.g_ucConfigKeyPCnt>CONF_PASS3) sutConfig.g_usConfigCnt = timeout;
- }
- }
- }else if(2==sutConfig.g_ucConfigKeyPN)
- {//ni
- sutConfig.g_ucConfigKeyPN=0;
- if(0==g_ucModemTaskEn)
- {
- sutConfig.g_ubConfigKeyStart=1;
- sutConfig.g_ucConfigKeyNCnt++;
- sutConfig.g_usConfigCnt=0;
- if(sutConfig.g_ucConfigKeyStep==0)
- {
- if(sutConfig.g_ucConfigKeyPCnt==CONF_PASS1)//逆2前完成顺1
- {
- sutConfig.g_ucConfigKeyPCnt=0;
- sutConfig.g_ucConfigKeyStep=1;
- }else sutConfig.g_usConfigCnt = timeout;
- }else if(sutConfig.g_ucConfigKeyStep==1)
- {
- if(sutConfig.g_ucConfigKeyNCnt>CONF_PASS2) sutConfig.g_usConfigCnt = timeout;
- }else if(sutConfig.g_ucConfigKeyStep==2)
- {//没完成顺3,顺3后又逆至少1了
- sutConfig.g_usConfigCnt = timeout;
- }else sutConfig.g_usConfigCnt = timeout;
- }
- }
- }
- #endif
- void PowerOffProtetion(void)
- {
- static short cntDown;
- static char ledCnt,status;
- char buf[30];
- if(modemPwrOffNow==0) return;
- GPS_PWR_OFF;
- SlwTrace(INF, "Try to PwrOff",1);
- ModemSendAT("AT$QCPWRDN\r\n");
- MODEM_LED1_LOW;
- for(cntDown=6;cntDown>=0;cntDown--)
- {
- status=1;
- ledCnt=10;
- while(ledCnt>0)
- {
- if(cntDown!=0)
- {
- if(status==0)
- {
- MODEM_LED2_LOW;
- status=1;
- }else{
- MODEM_LED2_HIGH;
- status=0;
- }
- }else{
- MODEM_LED2_LOW;
- MODEM_LED1_HIGH;
- }
- ledCnt--;
- IWDG_ReloadCounter();
- DelayMs(20);
- }
-
- snprintf(buf, sizeof(buf), "PwrOff(%d)", cntDown);
- SlwTrace(INF, buf, 1);
- IWDG_ReloadCounter();
- os_dly_wait(70);
- }
- PWR_EN_LOW;
- while(1);
- }
- /*******************************************************************
- *MainTask
- *主任务
- ********************************************************************/
- __task void MainTask(void)
- {
- int KeyFlag;
- char *msg;
- INT8U err;
- unsigned char ucCheckVbatCt=0;
- static unsigned int sucCt=0;
- static unsigned char sucFunReportFlag=0;
- int Vbat;
- char buf[30];
- RunMake(THIS_FILE_ID);
- //Obtain own system task identification number. */
- idMainTask = os_tsk_self();
-
- memset((unsigned char *)&sutPocStatus,0,sizeof(SUT_POC_STATUS));
- SpeakerEnable();
- SetBeepByNoOS(888,100);
- SpeakerDisable();
- //Read Product param from flash
- ReadProductParaFromFlash();
- printf("\r\n%s_V%d Start...\r\n",sutProductPara.ProductName,sutProductPara.ProductVersion);
- printf("PSN:%lu\r\n",sutProductPara.PSN);
- //printf("volset 7 7 \r\n");
- g_ucUpdataVer=0;
- //Begin MainTask loop
- SlwTrace(INF,"Main Task Start!",1);
- //Led Init
- LedInit();
- SlwTrace(INF,"Led Init ok",1);
- g_iFun2KeyEncodeCt=0;
- SMSInit();
- //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);
- #if(USE_CONFIG_FUN==1)
- memset((unsigned char *)&sutConfig, 0, sizeof(CONFIG_SER_DEF));
- #endif
- while(1)
- {
- PowerOffProtetion();
- os_dly_wait(1);
- //处理PC发送过来的消息
- RunMake(THIS_FILE_ID);
- if(g_usUart1RecvLen)
- {
- PcMsgHandle((char *)RxBuffer1);
- g_usUart1RecvLen=0;
- }
- RunMake(THIS_FILE_ID);
- //键盘处理
- if(0!=(KeyFlag=GetKey()))
- {
- //printf("Key F=%d,V=%04x\r\n",KeyFlag,g_ulKeyValue);
- //按键处理
- if(1==KeyFlag) KeyPress(); //按键按下
- else KeyFree();//按键释放
- // CSQ_flag=1;
- // CSQ_ct=0;
- }
- RunMake(THIS_FILE_ID);
- //旋码开关处理
- EncodeKeyProcess();
- Select_Net(g_net_cnt);
- //LED处理
- LedProcess(0);
- #if(USE_CONFIG_FUN==1)
- ConfigModeDetect();
- #endif
- //---以下控制每秒执行一次---
- 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();
- others();
- CSQ_Prompt();
-
- }
- }
- void EncodeKeyProcess(void)
- {
- static unsigned int limitedCnt=0;
- char buf[30];
- if(0==g_iEncode)return;
- if(g_iEncode > 0)
- {//这里是为了能让快旋能进入GT模式,因为下面作了速度限制,这部分必须提上来
- //否则GT模式很难进入
- if(g_ucFun2KeyPressCt>0){
- if(g_iFun2KeyEncodeCt<0)g_iFun2KeyEncodeCt=0;
- g_iFun2KeyEncodeCt++;
- }else g_iFun2KeyEncodeCt=0;
- }else if(g_iEncode<0){
-
- if(g_ucFun2KeyPressCt>0){
- if(g_iFun2KeyEncodeCt>0) g_iFun2KeyEncodeCt=0;
- g_iFun2KeyEncodeCt--;
- }else g_iFun2KeyEncodeCt=0;
- }
-
- if(os_time_get() < limitedCnt)
- {//限制速度,否则模块有可能会死掉
- g_iEncode=0;
- return;
- }
- limitedCnt=os_time_get()+50;
-
- if(g_iEncode>0){//====================顺时针旋转
- #if(USE_CONFIG_FUN==1)
- sutConfig.g_ucConfigKeyPN=1;
- #endif
- SlwTrace(INF,"[+]",1);
-
- if(g_net_flag==2)
- {
- if(g_net_cnt==5){
- g_net_cnt=0;
- g_iEncode=0;
- return;
- }
- g_net_cnt++;
- g_iEncode=0;
- return;
- }
-
- //-------------
- //群组选择、用户选择
- if(g_ucGroupSelect!=0){
- g_ucGroupSelect=2;
- SpeakerEnable();
- ModemSendAT(POC_CMD_UP);
- SlwTrace(INF,"[Group++]",1);
- }else if(g_ucUserSelect!=0){
- g_ucUserSelect=2;
- if(sutPocStatus.UserOnLineNum==0)
- {
- sutPocStatus.UserOnLineIndex=0;
- MeSpeak(ENCODE_GBK, "CEDEC6E4CBFCB3C9D4B1D4DACFDF",0);
- }else
- {
- sprintf(buf,"AT+POC=10000021%04x\r\n",sutPocStatus.UserOnLineIndex);
- ModemSendAT(buf);
- }
- //SlwTrace(INF,buf);
- // sutPocStatus.UserOnLineIndex++;
- ++sutPocStatus.UserOnLineIndex;
- if(sutPocStatus.UserOnLineIndex>=sutPocStatus.UserOnLineNum){
- sutPocStatus.UserOnLineIndex=0;
- }
- SlwTrace(INF,"[User++]",1);
- }
-
- }else{//==============================逆时针旋转
- #if(USE_CONFIG_FUN==1)
- sutConfig.g_ucConfigKeyPN=2;
- #endif
-
- SlwTrace(INF,"[-]",1);
- if(g_net_flag==2)
- {
- if(g_net_cnt==0){
- g_net_cnt=5;
- g_iEncode=0;
- return;
- }
- g_net_cnt--;
- g_iEncode=0;
- return;
- }
- // if(g_ucFun2KeyPressCt>0){
- // if(g_iFun2KeyEncodeCt>0) g_iFun2KeyEncodeCt=0;
- // g_iFun2KeyEncodeCt--;
- // }else g_iFun2KeyEncodeCt=0;
-
- //群组选择、用户选择
- if(g_ucGroupSelect!=0){
- g_ucGroupSelect=2;
- SpeakerEnable();
- ModemSendAT(POC_CMD_DOWN);
- SlwTrace(INF,"[Group--]",1);
- }else if(g_ucUserSelect!=0){
- g_ucUserSelect=2;
- if(sutPocStatus.UserOnLineNum==0)
- {
- sutPocStatus.UserOnLineIndex=0;
- MeSpeak(ENCODE_GBK, "CEDEC6E4CBFCB3C9D4B1D4DACFDF",0);
- }else
- {
- sprintf(buf,"AT+POC=10000021%04x\r\n",sutPocStatus.UserOnLineIndex);
- ModemSendAT(buf);
- }
- if(sutPocStatus.UserOnLineIndex>0) sutPocStatus.UserOnLineIndex--;
- else if(sutPocStatus.UserOnLineNum==0) sutPocStatus.UserOnLineIndex=0;
- else sutPocStatus.UserOnLineIndex=sutPocStatus.UserOnLineNum-1;
- SlwTrace(INF,"[User--]",1);
- }
- }
- g_iEncode=0;
- }
- 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_AIN;
- GPIO_Init(GPIOA,&GPIO_InitStructure); //默认速度为两兆
- //配置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;
- //采集ADC
- if(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)!=RESET){//检查制定ADC标志位置1与否 ADC_FLAG_EOC 转换结束标志位 if(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)!=RESET){
- adc=ADC_GetConversionValue(ADC1);
- ADC_SoftwareStartConvCmd(ADC1,ENABLE);
- if(adc<100 && adc>4095)return -1;
- }else{
- return -1;
- }
- //循环存储
- 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)return -1;
- //Vbat=sum*340/4096;
- 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;//提示“请充电”计数器
- char i;
-
- if(Vbat<MIN_PWR_LEVEL){
- SlwTrace(INF,"Vbat low!shutdown now!",1);
- //关闭模块
- if(sutPocStatus.ModemPowerOn==1){
- #if 0
- MeSpeak(ENCODE_GBK, "B5CDD1B9B9D8BBFA",0);//低压关机
- for(i=0;i<4;i++)
- {
- IWDG_ReloadCounter();
- os_dly_wait(50);
- }
- SlwTrace(INF,"ModemPoweroff!",1);
- ModemPoweroff();
- #else
- #endif
- }
- sutPocStatus.ModemPowerOn=0;
- PWR_EN_LOW;
- Sleeping();
- }else if(Vbat<WARN_PWR_LEVEL){//提示请充电
- 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"};//310030003000 004E7E76
-
- //播报电量百分比 10,20,30, 40, 50, 60, 70, 80, 90,100
- const int siVbat[] ={340,344,353,362,370,378,386,394,412};//V611
- int i;
- for(i=0;i<10;i++){
- if(Vbat<siVbat[i])break;
- }
- if(i>9)i=9;
- strcpy(Percent,ccPercent[i]);
- }
- /****************************************************************
- *语音播报 电量、信号、GPS
- *****************************************************************/
- void ReportVbatCsqGps(void)
- {
- unsigned char GpsFlag;
- //电量百分之N,信号强,GPS已登陆已定位
- char buf[30];
- CSQ_flag=1;
- CSQ_ct=0;
- SpeakerEnable();
- ModemSendAT("AT+LSHTTS=3,");
- ModemSendAT("\"3575CF917E7606524B4E");//电量百分之
- GetVbatPercent(g_iVbat,buf);
- ModemSendAT(buf); //10~100
- GetXinHao(g_iCSQ,buf); // 信号
- ModemSendAT(buf);
-
- // if(!sutGpsInfo.isGpsWork){
- // //ModemSendAT("E065470050005300");//,无GPS
- // GpsFlag=0x00;
- // ModemSendAT("\"\r\n");
- // }else
-
- if(sutGpsInfo.isGpsAuthOk)
- {
- ModemSendAT("F25D74924367"); //已鉴权
- GpsFlag=0x20;
- }else{
- ModemSendAT("2A6774924367"); //未鉴权
- GpsFlag=0x10;
- }
- if(sutGpsStatus.CheckCnt != NO_GPS_CHECK_TIMEOUT)
- {
- if(!sutGpsInfo.isGpsWork)
- {
- ModemSendAT("E065470050005300");//,无GPS
- GpsFlag=0x00;
- }else
- {
- if(sutGpsInfo.isGpsValid)
- {
- ModemSendAT("17539662F25D9A5B4D4F"); //已定位
- GpsFlag |= 0x01;
- }else{
- ModemSendAT("175396622A679A5B4D4F"); //未定位
- }
- }
- }
- ModemSendAT("\"\r\n");
-
- snprintf(buf,30,"Vbat=%d,CSQ=%d,GPS=%02x",g_iVbat,g_iCSQ,GpsFlag);
- SlwTrace(INF,buf,1);
- }
- /***************************************************************************
- 将数字转Unicode编码
- pUnicode空间最长 5*4+1=21字节
- ****************************************************************************/
- void NumToUnicode(unsigned short Num,char *pUnicode)
- {
- char temp[6];
- int i,j,len;
- sprintf(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[100];
- char temp1[40],temp2[20];
- CSQ_flag=1;
- CSQ_ct=0;
-
- sprintf(buf, "D3A6D3C3B0E6B1BE2C");//应用版本
- sprintf(temp2, "%d", sutProductPara.ProductVersion);
- AscStrToHexStr(temp2, temp1);
- strcat(buf, temp1);
- strcat(buf,"2CC4A3BFE9B0E6B1BE2C");
- sprintf(temp2, "%d,%d", g_iModemVer,g_iPocVer);
- AscStrToHexStr(temp2, temp1);
- strcat(buf, temp1);
- MeSpeak(ENCODE_GBK, buf,0);
-
- sprintf(buf, "AVer=%d,MVer=%d,PVer=%d", sutProductPara.ProductVersion,g_iModemVer,g_iPocVer);
- SlwTrace(INF, buf,1);
- }
- /*******************************************************************
- *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<40){
- *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();
- }
- void ReportUserGroupName(void)
- {
- char buf[90];
- sprintf(buf, "%s2C2C%s", sutPocStatus.UserName, sutPocStatus.GroupName);
- MeSpeak(ENCODE_GBK, buf,0);
- }
- void ChangeDig2Chinese(char dig, char *des)
- {//只认0x30~0x39 以及'.'
- const char ChineseTable[] = "C1E3D2BBB6FEC8FDCBC4CEE5C1F9C6DFB0CBBEC5B5E3";//零-九点
- unsigned char i,index;
- if(dig == '.') index = 10;
- else if(dig >= '0' && dig <= '9') index = dig-0x30;
- else return;
- memcpy(des, &ChineseTable[index*4],4);
- }
- void ReportPocGpsIP(void)
- {
- unsigned char i;
- char buf1[40],buf2[120];
- char temp[12];
- CSQ_flag=1;
- CSQ_ct=0;
-
- SpeakerEnable();
- //终端编码xxx
- ModemSendAT("AT+LSHTTS=1,");
- sprintf(temp,"%lu",sutProductPara.PSN);
- sprintf(buf2,"PSN=%s\r\n",temp);
- SlwTrace(INF,buf2,0);
- NumStrToUnicode(temp,buf2);
- ModemSendAT("\"D6D5B6CBB1E0C2EB2C");
- ModemSendAT(buf2);
-
- memset(buf2, 0 ,sizeof(buf2));
- ModemSendAT("BDBBBBBBB7FECEF1C6F72C");//交换服务器
- snprintf(buf1,sizeof(buf1), "%d.%d.%d.%d", sutNewSegmentPara.PIP[0],sutNewSegmentPara.PIP[1],sutNewSegmentPara.PIP[2],sutNewSegmentPara.PIP[3]);
-
- for(i=0;i<strlen(buf1);i++)
- {
- ChangeDig2Chinese(buf1[i], &buf2[i*4]);
- }
- ModemSendAT(buf2);
-
- ModemSendAT("2CB6A8CEBBB7FECEF1C6F72C");//定位服务器
- snprintf(buf1,sizeof(buf1), "%d.%d.%d.%d", sutNewSegmentPara.GIP[0],sutNewSegmentPara.GIP[1],sutNewSegmentPara.GIP[2],sutNewSegmentPara.GIP[3]);
- for(i=0;i<strlen(buf1);i++)
- {
- ChangeDig2Chinese(buf1[i], &buf2[i*4]);
- }
- ModemSendAT(buf2);
- memset(buf2, 0, sizeof(buf2));
- ModemSendAT("B6CBBFDABAC52C");//端口号
- sprintf(buf1,"%d",sutNewSegmentPara.GpsPort);
- for(i=0;i<strlen(buf1);i++)
- {
- ChangeDig2Chinese(buf1[i], &buf2[i*4]);
- }
- ModemSendAT(buf2);
- ModemSendAT("\"\r\n");
-
-
-
- // ModemSendAT("AT+LSHTTS=1,");
- //// ModemSendAT("\"D6D5B6CBB1E0BAC52C");
- //// snprintf(buf1,sizeof(buf1),""
- //
- // ModemSendAT("\"BDBBBBBBB7FECEF1C6F72C");//交换服务器
- // memset(buf2, 0 ,sizeof(buf2));
- // snprintf(buf1,sizeof(buf1), "%d.%d.%d.%d", sutNewSegmentPara.PIP[0],sutNewSegmentPara.PIP[1],sutNewSegmentPara.PIP[2],sutNewSegmentPara.PIP[3]);
- // for(i=0;i<strlen(buf1);i++)
- // {
- // ChangeDig2Chinese(buf1[i], &buf2[i*4]);
- // }
- // ModemSendAT(buf2);
- // ModemSendAT("2CB6A8CEBBB7FECEF1C6F72C");//定位服务器
- // memset(buf2, 0 ,sizeof(buf2));
- // snprintf(buf1,sizeof(buf1), "%d.%d.%d.%d", sutNewSegmentPara.GIP[0],sutNewSegmentPara.GIP[1],sutNewSegmentPara.GIP[2],sutNewSegmentPara.GIP[3]);
- // for(i=0;i<strlen(buf1);i++)
- // ChangeDig2Chinese(buf1[i], &buf2[i*4]);
- // ModemSendAT(buf2);
- // memset(buf2, 0, sizeof(buf2));
- // sprintf(buf2, "2C");
- // sprintf(buf1,"%d",sutNewSegmentPara.GpsPort);
- // for(i=0;i<strlen(buf1);i++)
- // ChangeDig2Chinese(buf1[i], &buf2[2+i*4]);
- //
- // ModemSendAT(buf2);
- // ModemSendAT("\"\r\n");
- }
- 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--因参数非法而失败
- ******************************************************************************************/
- int GetCheckCodeByPsnMEID(char *pCheckCode,unsigned long PSN,char *pMEID)
- {
- 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
- };
- char aucPSN[11];
- 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
- //PSN转字符串,不够10位的前面补'0'
- sprintf(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;
- }
- /***************************************************************************
- 将数字串转Unicode编码,方便播报
- pUnicode长度必须为pNum长度的8倍,否则内存溢出!
- ****************************************************************************/
- void NumStrToUnicode(char *pNum,char *pUnicode)
- {
- char temp[10];
- int i,j,len;
- len=strlen(pNum);
- // sprintf(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[11],i;
- char buf[80];
- CSQ_flag=1;
- CSQ_ct=0;
-
- SpeakerEnable();
- //终端编号xxxx
- if(sutProductPara.PSN<150100000 || sutProductPara.PSN==0xffffffff){
- SlwTrace(INF,"PSN Error!",1);
- MeSpeak(ENCODE_GBK, "D6D5B6CBB1E0BAC5B4EDCEF3",0);//终端编号错误
- return;
- }
- //校验码xxxx
- if(GetCheckCodeByPsnMEID(temp,sutProductPara.PSN,sutNewSegmentPara.HARDID)){
- sprintf(buf,"CheckCode=%s\r\n",temp);
- SlwTrace(INF,buf,0);
- NumStrToUnicode(temp,buf);
- ModemSendAT("AT+LSHTTS=1,\"D0A3D1E9C2EB");//校验码,
- ModemSendAT(buf);
- ModemSendAT("2C");
- }else{
- SlwTrace(INF,"CheckCode=NULL",1);
- ModemSendAT("AT+LSHTTS=1,\"D0A3D1E9C2EBBBF1C8A1CAA7B0DC2C");//校验码获取失败
- }
- //终端编码xxx
- sprintf(temp,"%lu",sutProductPara.PSN);
- sprintf(buf,"PSN=%s\r\n",temp);
- SlwTrace(INF,buf,0);
- NumStrToUnicode(temp,buf);
- ModemSendAT("D6D5B6CBB1E0C2EB");//终端编码,
- ModemSendAT(buf);
- ModemSendAT("\"\r\n");
- }
- /************************************************************************************
- ResetModem
- *************************************************************************************/
- void ResetModem(void)
- {
- SlwTrace(INF,"Reset Modem!",1);
- sutPocStatus.modemRstFlag=1;
- }
- /*************************************************************************************
- *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!",1);
- ResetModem();
- if(++sucPocLostTimeoutCount>2){//连续重启3次都失败,则复位整个系统
- sucPocLostTimeoutCount=0;
- SystemReset();
- }
- }
- }else{
- sutPocStatus.PocLostCt=0;
- sucPocLostTimeoutCount=0;
- }
- }
-
- //如果模块已开机,长时间收不到串口消息,则重启模块及串口驱动部分
- if(sutPocStatus.ModemPowerOn==1)
- {
- if(sutPocStatus.ModemInactiveCt==0)//ModemInactiveCt必须在接收到Modem串口消息后才清零
- sucModemInactiveCount=0;
- if(++sutPocStatus.ModemInactiveCt>35) //15
- {//等待时间15秒
- sutPocStatus.ModemInactiveCt=0;
- //长时间收不到串口消息,重启模块及串口驱动
- SlwTrace(INF,"ModemRecvTimeout!",1);
- ResetModem();
- //连续重启3次无效,复位整个系统
- if(++sucModemInactiveCount>2){
- sucModemInactiveCount=0;
- SystemReset();
- }
- }
- }
-
- //GPS守护
- if(sutGpsInfo.isGpsWork>0){
- if(++sutGpsInfo.GpsInactiveCt>10){
- sutGpsInfo.GpsInactiveCt=0;
- //复位GPS
- GPSRestart();
- Uart3Init();
- TSGpsDataInit();
- }
- }
- }
- void MakeStrEndByNewLine(char *str)
- {//一定要以'\r'结尾
- unsigned short i;
-
- for(i=0;i<strlen(str);i++)
- {
- if(str[i] == '\r')
- {
- str[i]=0;
- return;
- }
- }
- }
- //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 Select_Net(unsigned char net)
- {
- unsigned char now_choice=0;
- static unsigned char last_choice=0;
- now_choice=net;
- if(now_choice!=last_choice)
- {
- last_choice=now_choice;
- switch(last_choice)
- {
- case 0:
- MeSpeak(ENCODE_UNICODE,"517FDC7EEA81A852",1);//自动
- break;
-
- case 1:
- MeSpeak(ENCODE_UNICODE,"8C4E219E216A0F5F",1);
- break;
- case 2:
- MeSpeak(ENCODE_UNICODE,"094E219E216A0F5F",1);
- break;
- case 3:
- MeSpeak(ENCODE_UNICODE,"DB56219EEA81A852",1);//4G自动
- break;
- case 4:
- MeSpeak(ENCODE_UNICODE,"DB56219E31003800300030004651",1); //4G 1800M
- break;
- case 5:
- MeSpeak(ENCODE_UNICODE,"DB56219E3800300030004651",1); //4G 800M
- break;
- // case 3:
- // MeSpeak(ENCODE_UNICODE,"DB56219E216A0F5F",1);
- // break;
- default:
- break;
- }
-
-
-
- }
- if(net_sure==1){
-
- sutProductPara.g_net=last_choice;
- SaveProductParaToFlash();
-
- switch(last_choice)
- {
- case 0:
- ModemSendAT("AT+LCTMOBAPREF=2,0\r\n");
- os_dly_wait(1);
- GetMododexWithCard();
- MeSpeak(ENCODE_UNICODE,"DB8F6551517FDC7EEA81A852",1);//
- net_sure=0;
- break;
-
- case 1:
- ModemSendAT("AT+LCTMOBAPREF=2,0\r\n");
- os_dly_wait(1);
- GetMododexWithCard();
- MeSpeak(ENCODE_UNICODE,"DB8F65518C4E219E216A0F5F",1);
-
-
- net_sure=0;
- break;
- case 2:
- ModemSendAT("AT+LCTMOBAPREF=2,0\r\n");
- os_dly_wait(1);
- GetMododexWithCard();
- MeSpeak(ENCODE_UNICODE,"DB8F6551094E219E216A0F5F",1);
- net_sure=0;
- break;
- case 3:
- //GetMododexWithCard();
- ModemSendAT("AT+LCTMOBAPREF=5,0\r\n");
- os_dly_wait(1);
- ModemSendAT("AT+MODODREX=5\r\n");
-
- MeSpeak(ENCODE_UNICODE,"DB8F6551DB56219EEA81A852",1); //4G 自动
- net_sure=0;
- break;
-
- case 4:
- //GetMododexWithCard();
- ModemSendAT("AT+LCTMOBAPREF=5,6\r\n");
- os_dly_wait(1);
- ModemSendAT("AT+MODODREX=5\r\n");
-
- MeSpeak(ENCODE_UNICODE,"DB8F6551DB56219E31003800300030004651",1); //4G 1800M
- net_sure=0;
- break;
- case 5:
- //GetMododexWithCard();
- ModemSendAT("AT+LCTMOBAPREF=5,8\r\n");
- os_dly_wait(1);
- ModemSendAT("AT+MODODREX=5\r\n");
-
- MeSpeak(ENCODE_UNICODE,"DB8F6551DB56219E3800300030004651",1);//进入4G 800M
- net_sure=0;
- break;
-
- default:
- break;
-
- }
- }
- }
- void GetMododexWithCard(void)
- {
- char buf[30];
- //根据CardType和ModeSetup转换为Mododex值的一个表
- static const unsigned char MododrxTable[3][4]={{11,15,10,5},{2,25,7,5},{17,25,1,5}}; //
- snprintf(buf,sizeof(buf),"AT+MODODREX=%d\r\n",MododrxTable[thisYunYingShang][sutProductPara.g_net]);
- ModemSendAT(buf);
- SlwTrace(INF,buf,1);
-
- snprintf(buf,sizeof(buf),"HAHAHAHAHAA\r\n");
- SlwTrace(INF,buf,1);
- }
- void BroadCast_Net()
- {
- //ReadFlashData(APP_CONFIG_ADDR,(unsigned char *)&sutProductPara,sizeof(SUT_CONFIG));
- printf("g_net=%d\r\n",sutProductPara.g_net);
- switch(sutProductPara.g_net)
- {
- case 0:
- MeSpeak(ENCODE_UNICODE,"517FDC7EBE8B6E7F0CFF535F4D52517FDC7EEA81A852",1);//自动
- break;
-
- case 1:
- MeSpeak(ENCODE_UNICODE,"517F216ABE8B6E7F0CFF535F4D528C4E219E216A0F5F",1);
- break;
- case 2:
- MeSpeak(ENCODE_UNICODE,"517F216ABE8B6E7F0CFF535F4D52094E219E216A0F5F",1);
- break;
- case 3:
- MeSpeak(ENCODE_UNICODE,"517FDC7EBE8B6E7F0CFF535F4D52DB56219EEA81A852",1);//自动
- break;
-
- case 4:
- MeSpeak(ENCODE_UNICODE,"517FDC7EBE8B6E7F0CFF535F4D52DB56219E31003800300030004651",1);
- break;
- case 5:
- MeSpeak(ENCODE_UNICODE,"517FDC7EBE8B6E7F0CFF535F4D52DB56219E3800300030004651",1);
- break;
- // case 3:
- // MeSpeak(ENCODE_UNICODE,"517F216ABE8B6E7F0CFF535F4D52DB56219E216A0F5F",1);
- // break;
-
- default:
- break;
- }
- }
- void CSQ_Prompt()
- {
- static char CSQ_ct2=0;
- if(0==g_ucModemTaskEn) return;
- if(++CSQ_ct>16){
-
- if(CSQ_flag==1){
-
- CSQ_flag=0;
- CSQ_ct=0;
- return;
- }
- CSQ_ct=0;
- }
-
- if(++CSQ_ct2>10){
-
-
- if(sutPocStatus.FirstLogined==1 && CSQ_flag==0){
- if(sutPocStatus.Logined==0){
- if(0==g_iCSQ || 99==g_iCSQ){
- //滴滴两声持续一秒
- SpeakerEnable();
- SetBeep(1176,10);
- os_dly_wait(110);
- SpeakerEnable();
- SetBeep(1176,10);
- SlwTrace(INF,"CSQ_Prompt.........",1);
-
- }else if(g_iCSQ>1 && g_iCSQ<99){
-
- SpeakerEnable();
- SetBeep(1176,12);
- }
- }
- }
- CSQ_ct2=0;
- }else{}
-
- }
- void ReportIpInfo(void)
- {
- char buf[100];
- char temp1[40],temp2[20];
-
- sprintf(buf, "D3A6D3C3B0E6B1BE2C");//应用版本
- sprintf(temp2, "%d", sutProductPara.ProductVersion);
- AscStrToHexStr(temp2, temp1);
- strcat(buf, temp1);
- strcat(buf,"2CC4A3BFE9B0E6B1BE2C");
- sprintf(temp2, "%d,%d", g_iModemVer,g_iPocVer);
- AscStrToHexStr(temp2, temp1);
- strcat(buf, temp1);
- MeSpeak(ENCODE_GBK, buf,0);
-
- sprintf(buf, "AVer=%d,MVer=%d,PVer=%d", sutProductPara.ProductVersion,g_iModemVer,g_iPocVer);
- SlwTrace(INF, buf,1);
- }
|