MainTask.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183
  1. /********************************************************************************
  2. * File Name: MainTask.c
  3. * Function Describe:The main task for the system
  4. * Relate Module:
  5. * Explain: Hardware version is HS121
  6. * Writer: ShiLiangWen
  7. * Date: 2015.7.8
  8. *******************************************************************************/
  9. #define THIS_FILE_ID 8
  10. //---------------------------------------------------------------------------------
  11. #include "includes.h"
  12. //OS ID
  13. OS_TID idMainTask=0;
  14. U64 stkMainTask[MAIN_TASK_STK_SIZE];
  15. unsigned char g_net_flag=0;
  16. unsigned char net_sure=0;
  17. unsigned char g_net_cnt;
  18. unsigned char CSQ_flag;// 如果有按键按下,10秒内不触发 CSQ_Prompt();
  19. unsigned char CSQ_ct=0;
  20. int g_iVbat=0;
  21. void FingerDaemonfinger(void);
  22. unsigned char modemInitReady=0;//0模块没开始初始化 1模块初始化成功 2模块初始化失败
  23. unsigned char modemPwrOffNow=0;
  24. unsigned char g_ucUpdataVer=0;
  25. unsigned char g_ucKeyDownPressFlag=0;
  26. unsigned char g_ucGroupSelect=0;
  27. unsigned char g_ucUserSelect=0;
  28. unsigned char g_ucFun1KeyPressCt=0;//Fun1Key持续按下计数器,松开后清零
  29. unsigned char g_ucFun2KeyPressCt=0;//Fun2Key持续按下计数器,松开后清零
  30. int g_iFun1KeyEncodeCt=0; //Fun1Key按下时旋转Encode次数计数器,正数为顺时针,负数为逆时针,松开后清零
  31. int g_iFun2KeyEncodeCt=0; //Fun2Key按下时旋转Encode次数计数器,正数为顺时针,负数为逆时针,松开后清零
  32. unsigned char GroupSelectStat=0;//进入群组选择旋转旋钮后无法退出标志
  33. unsigned char GroupSelectFlag=0;
  34. unsigned char g_ucEnterGroupFlag=0;
  35. unsigned char pocTimeOutTime=30;//默认30分钟
  36. unsigned char g_ucEnterCnt=0;
  37. //======================================
  38. void ReportVbatCsqGps(void);
  39. void EncodeKeyProcess(void);
  40. void iap_jump_app_s(void);
  41. int GetCheckCodeByPsnMEID(char *pCheckCode,unsigned long PSN,char *pMEID);
  42. void ReportCheckCode(void);
  43. //-----
  44. #ifdef USE_RUNNING_MAKE
  45. void RunningMake(unsigned short FileID,unsigned long line)
  46. {
  47. g_usFileID=FileID;
  48. g_ulFileLine=line;
  49. }
  50. #endif
  51. unsigned short g_usFileID=0;
  52. unsigned long g_ulFileLine=0;
  53. /***********************************************
  54. 强制复位
  55. ************************************************/
  56. void SystemReset(void)
  57. {
  58. SlwTrace(INF, "SysTem Reset!",1);
  59. os_tsk_delete(idModemUartTask);
  60. os_tsk_delete(idModemTask);
  61. os_tsk_delete(idTTSTask);
  62. while(1);
  63. }
  64. void PowerCtrlInit(void)
  65. {
  66. GPIO_InitTypeDef GPIO_InitStructure;
  67. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
  68. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  69. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  70. GPIO_InitStructure.GPIO_Pin = PWR_EN_PIN;
  71. GPIO_Init(PWR_EN_PORT, &GPIO_InitStructure);
  72. PWR_EN_LOW;
  73. }
  74. /*************************************************************************
  75. 拷贝数据,并判断与原数据是否相同
  76. 相同返回0
  77. 不同返回1
  78. **************************************************************************/
  79. unsigned char CopyData(unsigned char *pDst,unsigned char *pSrc,unsigned char len)
  80. {
  81. unsigned char i;
  82. unsigned char flag=0;
  83. for(i=0;i<len;i++){
  84. if(*pDst!=*pSrc){
  85. flag=1;
  86. *pDst=*pSrc;
  87. }
  88. pDst++;
  89. pSrc++;
  90. }
  91. return flag;
  92. }
  93. /********************************************************************
  94. *开关机键检测
  95. *********************************************************************/
  96. int OnOffCheck(void)
  97. {
  98. static unsigned char sucCt=0;
  99. unsigned long k;
  100. k=ONOFF_CK_PORT->IDR;
  101. if((k&ONOFF_CK_PIN)==ONOFF_CK_PIN){
  102. if(sucCt<5)sucCt++;
  103. else return 1;
  104. }else{
  105. sucCt=0;
  106. }
  107. return 0;
  108. }
  109. void GPIO_Config_ALL_AIN(void);
  110. //从source查找长度为targetLen目标的target,找到后返回目标段后一字节的索引,没找到返回-1,source结束为sourceEndIndicator
  111. //witchOne: 找第几个目标
  112. short FindTargetIndex(char *source, char sourceEndIndicator, char *target, unsigned char targetLen,unsigned char witchOne)
  113. {
  114. unsigned short targetIndex;
  115. unsigned char targetNum;
  116. targetIndex=0;
  117. targetNum=0;
  118. while(*source != sourceEndIndicator)
  119. {
  120. if(0==memcmp(source, target, targetLen))
  121. {//找到了
  122. targetNum++;
  123. if(targetNum == witchOne)
  124. return (targetIndex+targetLen);
  125. }
  126. source++;
  127. targetIndex++;
  128. }
  129. return -1;
  130. }
  131. unsigned char AscToHex(unsigned char aHex)
  132. {
  133. if((aHex>=0)&&(aHex<=9))
  134. aHex += 0x30;
  135. else if((aHex>=10)&&(aHex<=15))//A-F
  136. //aHex += 0x37;
  137. aHex += 0x57;
  138. else aHex = 0xff;
  139. return aHex;
  140. }
  141. void AscStrToHexStr(char *AscStr, char *HexStr)
  142. {
  143. char *pAscStr=AscStr;
  144. unsigned char d,h,l,i;
  145. while((d=(unsigned char)*pAscStr++)!=0||i<(g_GroupNameLen*2)){
  146. i++;
  147. l=d&0x0f;
  148. h=d>>4;
  149. *HexStr++=AscToHex(h);
  150. *HexStr++=AscToHex(l);
  151. }
  152. *HexStr=0;
  153. }
  154. void AscStrToHexStr1(char *AscStr, char *HexStr,unsigned char len)
  155. {
  156. char *pAscStr=AscStr;
  157. unsigned char d,h,l;
  158. if(len==0)
  159. {
  160. while(0 != (d=(unsigned char )*pAscStr++))
  161. {
  162. l=d&0x0f;
  163. h=d>>4;
  164. *HexStr++=AscToHex(h);
  165. *HexStr++=AscToHex(l);
  166. }
  167. }else
  168. {
  169. while(len)
  170. {
  171. d=(unsigned char )*pAscStr++;
  172. l=d&0x0f;
  173. h=d>>4;
  174. *HexStr++=AscToHex(h);
  175. *HexStr++=AscToHex(l);
  176. len--;
  177. }
  178. }
  179. *HexStr=0;
  180. }
  181. char changeDataFormat(char *asciiData, unsigned short len)
  182. {//"313233"-->0x313233 len = 3
  183. unsigned char j,temp[2];
  184. unsigned short i;
  185. for(i=0;i<len;i++)
  186. {
  187. temp[0] = asciiData[2*i];
  188. temp[1] = asciiData[2*i+1];
  189. for(j=0;j<2;j++)
  190. {
  191. if(temp[j] >= '0' && temp[j] <= '9') temp[j] -= 0x30;
  192. else if(temp[j] >= 'A' && temp[j] <= 'F') temp[j] -= 0x37;
  193. else if(temp[j] >= 'a' && temp[j] <= 'f') temp[j] -= 0x57;
  194. else return 1;
  195. }
  196. temp[0] <<= 4;
  197. temp[0] &= 0xf0;
  198. asciiData[i] = temp[0] | temp[1];
  199. }
  200. return 0;//OK
  201. }
  202. void PcMsgHandle(char *msg)
  203. {
  204. const char *CmdList[]={
  205. "TM", //Trace Modem
  206. "TG", //Trace GPS
  207. "DM", //Download Modem
  208. "SMP", //Set Modem Parameter
  209. "SGP", //Set GPS Parameter
  210. "RMP", //Read Modem Parameter
  211. "PST", //PST Mode for modem
  212. "VER", //Read Version
  213. "BAT", //Battery voltage
  214. "APN", //SET APN
  215. "RAPN", //Read APN
  216. "BEEP", //Beep test
  217. "RGP", //Read GPS
  218. "RMIP", //Read Manager/Load IP
  219. "SMIP", //Set Manager/Load IP
  220. "RCIP", //Read ConfigIP
  221. "SCIP", //Set ConfigIP
  222. "SACC", //Set access point
  223. "RACC", //Read access point
  224. "" //必须以空字串为结束
  225. };
  226. unsigned short Port;
  227. unsigned long PSN;
  228. char buf[150];
  229. char buf1[300];
  230. char strIP[20];
  231. char strAccessp[20];
  232. char strAccount[20];
  233. char strPassword[20];
  234. int i,j,len;
  235. char flag;
  236. const char *pCmd;
  237. char *pMsg;
  238. int CmdListNum=0;
  239. char needSave=0,needSaveNew=0;
  240. RunMake(THIS_FILE_ID);
  241. while(*CmdList[CmdListNum++]);//计算命令列表个数
  242. CmdListNum--;
  243. RunMake(THIS_FILE_ID);
  244. //查找与命令列表相同的命令位置
  245. for(i=0;i<CmdListNum;i++){
  246. pCmd=CmdList[i];
  247. pMsg=&msg[3];
  248. flag=0;
  249. j=0;
  250. while(*pCmd){
  251. if(*pCmd!=*pMsg){
  252. flag=1;
  253. break;
  254. }
  255. pCmd++;
  256. pMsg++;
  257. j++;
  258. }
  259. if(!flag){
  260. break;
  261. }
  262. }
  263. RunMake(THIS_FILE_ID);
  264. if(i==CmdListNum)return;
  265. //处理命令
  266. switch(i)
  267. {
  268. case 0://"TM"
  269. SetLedStatus(RedBlueSlowFlash);
  270. SlwTrace(INF,"GT+TM:OK",1);
  271. ComSelect(COM_SEL_MODEM);
  272. SpeakerEnable();
  273. break;
  274. case 1://"TG"
  275. SetLedStatus(RedBlueSlowFlash);
  276. SlwTrace(INF,"GT+TG:OK",1);
  277. ComSelect(COM_SEL_GPS);
  278. break;
  279. case 2://"DM"
  280. SetLedStatus(RedBlueSlowFlash);
  281. SlwTrace(INF,"GT+DM:OK",1);
  282. ComSelect(COM_SEL_MODEM);
  283. MODEM_LED1_LOW;
  284. MODEM_LED2_HIGH;
  285. MODEM_PWRKEY_HIGH;
  286. MODEM_RESET_HIGH;
  287. MODEM_RESET_LOW;
  288. while(1){
  289. IWDG_ReloadCounter();//喂狗
  290. if(OnOffCheck()){
  291. PWR_EN_LOW;
  292. }
  293. }
  294. break;
  295. case 3://"SMP" GT+SMP=IP=地址或域名;Port=端口号;PSN=终端序列号
  296. len=GetParaFromStr(msg,"IP",buf);
  297. if(len<1 || len>=40){
  298. SlwTrace(INF,"GT+SMP:FAIL[IP Invalid]",1);
  299. break;
  300. }
  301. strcpy(strIP,buf);
  302. len=GetParaFromStr(msg,"Port",buf);
  303. if(len==0)Port=0;
  304. else if(len>5){
  305. SlwTrace(INF,"GT+SMP:FAIL[Port Invalid]",1);
  306. break;
  307. }else Port=atoi(buf);
  308. len=GetParaFromStr(msg,"PSN",buf);
  309. if(len<1 || len>10){
  310. SlwTrace(INF,"GT+SMP:FAIL[PSN Invalid]",1);
  311. break;
  312. }else PSN=atol(buf);
  313. //PSN
  314. sutProductPara.PSN=PSN;
  315. needSave=1;
  316. if(0!=GetStringIP2Bytes(sutNewSegmentPara.PIP, strIP))
  317. {
  318. SlwTrace(INF,"GT+SMP:FAIL[IP Invalid]",1);
  319. break;
  320. }
  321. sutNewSegmentPara.PocPort=Port;
  322. needSaveNew=1;
  323. //send to modem
  324. if(strlen(sutNewSegmentPara.HARDID)<14){
  325. SlwTrace(INF,"GT+SMP:FAIL[MEID Invalid]",1);
  326. break;
  327. }
  328. sprintf(buf,"ip=%s;id=%lu;pwd=%s;",strIP,sutProductPara.PSN,sutNewSegmentPara.HARDID);
  329. AscStrToHexStr(buf,buf1);
  330. ModemSendAT("AT+POC=010000");
  331. ModemSendAT(buf1);
  332. ModemSendAT("\r\n");
  333. //save para
  334. 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],
  335. sutNewSegmentPara.PocPort,sutProductPara.PSN);
  336. SlwTrace(INF,buf,1);
  337. break;
  338. case 4://"SGP" GT+SGP=IP=地址或域名;Port=端口号;
  339. len=GetParaFromStr(msg,"IP",buf);
  340. if(len<1 || len>=40){
  341. SlwTrace(INF,"GT+SGP:FAIL[IP Invalid]",1);
  342. break;
  343. }else strcpy(strIP,buf);
  344. len=GetParaFromStr(msg,"Port",buf);
  345. if(len==0)Port=0;
  346. else if(len>5){
  347. SlwTrace(INF,"GT+SGP:FAIL[Port Invalid]",1);
  348. break;
  349. }else Port=atoi(buf);
  350. if(0!=GetStringIP2Bytes(sutNewSegmentPara.GIP, strIP))
  351. {
  352. SlwTrace(INF,"GT+SGP:FAIL[IP Invalid]",1);
  353. break;
  354. }
  355. sutNewSegmentPara.GpsPort=Port;
  356. needSaveNew=1;
  357. //echo
  358. sprintf(buf,"GT+SGP:IP=%d.%d.%d.%d;Port=%u;",sutNewSegmentPara.GIP[0],sutNewSegmentPara.GIP[1],sutNewSegmentPara.GIP[2],sutNewSegmentPara.GIP[3],
  359. sutNewSegmentPara.GpsPort);
  360. SlwTrace(INF,buf,1);
  361. break;
  362. case 5://"RMP" GT+RMP<CR><LF> PSN=终端序列号;MEID=模块MEID号;CNUM=电信号;UIMID=电信UIMID;
  363. sprintf(buf,"GT+RMP:PSN=%lu;MEID=%s;CNUM=0000000000;UIMID=0000000000;IP=%d.%d.%d.%d",sutProductPara.PSN,sutNewSegmentPara.HARDID,
  364. sutNewSegmentPara.PIP[0],sutNewSegmentPara.PIP[1],sutNewSegmentPara.PIP[2],sutNewSegmentPara.PIP[3]);
  365. SlwTrace(INF,buf,1);
  366. break;
  367. case 6://"PST"
  368. SetLedStatus(RedBlueSlowFlash);
  369. //g_ucNetTaskDisable=0xff;
  370. SlwTrace(INF,"GT+PST:OK",1);
  371. //SlwTraceWaitCompleted();
  372. os_dly_wait(1);
  373. ComSelect(COM_SEL_MODEM);
  374. //ModemSetDtrLow();
  375. MODEM_PWRKEY_LOW;
  376. MODEM_RESET_HIGH;
  377. os_dly_wait(5);
  378. MODEM_RESET_LOW;
  379. while(1){
  380. IWDG_ReloadCounter();//喂狗
  381. if(OnOffCheck()){
  382. PWR_EN_LOW;
  383. }
  384. }
  385. break;
  386. case 7://"VER"
  387. sprintf(buf,"GT+VER:%s_V%d",sutProductPara.ProductName,sutProductPara.ProductVersion);
  388. SlwTrace(INF,buf,1);
  389. break;
  390. case 8://BAT
  391. sprintf(buf,"GT+BAT: %d V",g_iVbat);
  392. SlwTrace(INF,buf,1);
  393. break;
  394. case 9://APN
  395. /*
  396. 设置格式:GT+APN=Account=用户名;Password=密码;<CR><LF>
  397. 成功返回:GT+APN:Account=用户名;Password=密码;<CR><LF>
  398. 失败返回:GT+APN:FAIL[失败原因]<CR><LF>
  399. */
  400. len=GetParaFromStr(msg,"Account",buf);
  401. if(len<0 || len > APNNAME_LEN){
  402. SlwTrace(INF,"GT+APN:FAIL[Account Invalid]",1);
  403. return;
  404. }
  405. if(len == 0) sutProductPara.APNName[0]=0;//空值
  406. else strcpy(sutProductPara.APNName,buf);
  407. len=GetParaFromStr(msg,"Password",buf);
  408. if(len<0 || len > APNPASS_LEN){
  409. SlwTrace(INF,"GT+APN:FAIL[Password Invalid]",1);
  410. return;
  411. }
  412. if(len == 0) sutProductPara.APNPass[0]=0;//空值
  413. else strcpy(sutProductPara.APNPass,buf);
  414. needSave=1;
  415. sprintf(buf1,"GT+APN:Account=%s;Password=%s;",sutProductPara.APNName,sutProductPara.APNPass);
  416. SlwTrace(INF,buf1,1);
  417. //写入Modem
  418. ModemSendAT("AT+ZPIDPWD=");
  419. ModemSendAT(sutProductPara.APNName);
  420. ModemSendAT(",");
  421. ModemSendAT(sutProductPara.APNPass);
  422. ModemSendAT("\r\n");
  423. break;
  424. case 10://RAPN
  425. sprintf(buf1,"GT+RAPN:Account=%s;Password=%s;",sutProductPara.APNName,sutProductPara.APNPass);
  426. SlwTrace(INF,buf1,1);
  427. break;
  428. case 11://BEEP
  429. len=GetParaFromStr(msg,"F",buf);
  430. if(len)i=atoi(buf);
  431. else i=878;
  432. len=GetParaFromStr(msg,"T",buf);
  433. if(len)Port=atoi(buf);
  434. else Port=80;
  435. SetBeep(i,Port);
  436. sprintf(buf,"BEEP=%dHz,%dms",i,Port);
  437. SlwTrace(INF,buf,1);
  438. break;
  439. case 12://RGP
  440. sprintf(buf,"GT+RGP:IP=%d.%d.%d.%d;PORT=%d;",sutNewSegmentPara.GIP[0],sutNewSegmentPara.GIP[1],sutNewSegmentPara.GIP[2],sutNewSegmentPara.GIP[3],
  441. sutNewSegmentPara.GpsPort);
  442. SlwTrace(INF,buf,1);
  443. break;
  444. case 13://RMIP
  445. 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);
  446. SlwTrace(INF,buf,1);
  447. break;
  448. case 14://SMIP
  449. len=GetParaFromStr(msg,"IP",buf);
  450. if(len<1 || len>=40){
  451. SlwTrace(INF,"GT+SMIP:FAIL[IP Invalid]",1);
  452. break;
  453. }else strcpy(strIP,buf);
  454. len=GetParaFromStr(msg,"Port",buf);
  455. if(len==0)Port=0;
  456. else if(len>5){
  457. SlwTrace(INF,"GT+SMIP:FAIL[Port Invalid]",1);
  458. break;
  459. }else Port=atoi(buf);
  460. GetStringIP2Bytes(sutNewSegmentPara.ManagerIP, strIP);
  461. sutNewSegmentPara.ManagerPort=Port;
  462. //Save para to flash
  463. needSaveNew=1;
  464. //echo
  465. sprintf(buf,"GT+SMIP:IP=%d.%d.%d.%d;Port=%u;",sutNewSegmentPara.ManagerIP[0],
  466. sutNewSegmentPara.ManagerIP[1],
  467. sutNewSegmentPara.ManagerIP[2],
  468. sutNewSegmentPara.ManagerIP[3],
  469. sutNewSegmentPara.ManagerPort);
  470. SlwTrace(INF,buf,1);
  471. break;
  472. case 15://RCIP
  473. sprintf(buf,"GT+RCIP:IP=%d.%d.%d.%d;PORT=%d;",sutNewSegmentPara.ConfigSerIP[0],
  474. sutNewSegmentPara.ConfigSerIP[1],
  475. sutNewSegmentPara.ConfigSerIP[2],
  476. sutNewSegmentPara.ConfigSerIP[3],
  477. sutNewSegmentPara.ConfigSerPort);
  478. SlwTrace(INF,buf,1);
  479. break;
  480. case 16://SCIP
  481. len=GetParaFromStr(msg,"IP",buf);
  482. if(len<1 || len>=40){
  483. SlwTrace(INF,"GT+SCIP:FAIL[IP Invalid]",1);
  484. break;
  485. }else strcpy(strIP,buf);
  486. len=GetParaFromStr(msg,"Port",buf);
  487. if(len==0)Port=0;
  488. else if(len>5){
  489. SlwTrace(INF,"GT+SCIP:FAIL[Port Invalid]",1);
  490. break;
  491. }else Port=atoi(buf);
  492. GetStringIP2Bytes(sutNewSegmentPara.ConfigSerIP, strIP);
  493. sutNewSegmentPara.ConfigSerPort=Port;
  494. //Save para to flash
  495. needSaveNew=1;
  496. //echo
  497. sprintf(buf,"GT+SCIP:IP=%d.%d.%d.%d;Port=%u;",sutNewSegmentPara.ConfigSerIP[0],
  498. sutNewSegmentPara.ConfigSerIP[1],
  499. sutNewSegmentPara.ConfigSerIP[2],
  500. sutNewSegmentPara.ConfigSerIP[3],
  501. sutNewSegmentPara.ConfigSerPort);
  502. SlwTrace(INF,buf,1);
  503. break;
  504. case 17://SACC
  505. len=GetParaFromStr(msg,"Accessp",buf);
  506. if(len<0 || len > APN_LEN)
  507. {
  508. SlwTrace(INF,"GT+SACC:FAIL[Accessp Invalid]",1);
  509. return;
  510. }
  511. if(len ==0) sutProductPara.APNApn[0]=0;
  512. else strcpy(sutProductPara.APNApn,buf);
  513. needSave=1;
  514. sprintf(buf1,"GT+SACC:Accessp=%s;",sutProductPara.APNApn);
  515. SlwTrace(INF,buf1,1);
  516. break;
  517. case 18://RACC
  518. sprintf(buf,"GT+RACC:Accessp=%s;",sutProductPara.APNApn);
  519. SlwTrace(INF,buf,1);
  520. break;
  521. }
  522. if(needSave) SaveProductParaToFlash();
  523. if(needSaveNew) SaveNewSegmentToFlash();
  524. RunMake(THIS_FILE_ID);
  525. }
  526. volatile static unsigned int pttPressFressCt;
  527. /***********************************************************************
  528. *按键按下事件
  529. ************************************************************************/
  530. void KeyPress(void)
  531. {
  532. char buf[30];
  533. static unsigned char sucReportFlag=0;
  534. switch(g_ulKeyValue){
  535. //-------------------------------------------------------------------
  536. #ifdef USE_NEW_KEY_DRI
  537. case KEY_PTT:
  538. case KEY_MIC_PTT:
  539. #else
  540. case KEY_PPT://=====================PPT KEY Press====================
  541. #endif
  542. //-------------------------------------------------------------------
  543. g_ucKeyPPTPress=1;
  544. g_ucKeyMode=1;//单次模式
  545. SlwTrace(INF,"[PPT Press]",1);
  546. //--
  547. if(g_ucGroupSelect==2)
  548. {//群组选择模式
  549. g_ucEnterCnt=0;
  550. g_ucEnterGroupFlag=1;//切换群组动作
  551. g_ucGroupSelect=0;
  552. SpeakerEnable();
  553. sprintf(buf, "AT+POC=090000%s\r\n",sutPocStatus.GroupIdTemp);
  554. ModemSendAT(buf);
  555. SlwTrace(INF,"[ExitGroupSel]",1);
  556. os_dly_wait(20);//+
  557. }else if(g_ucUserSelect==2)
  558. {//成员选择模式
  559. g_ucUserSelect=3;
  560. //if(sutPocStatus.UserOnLineNum!=0&&(i==0)) MeSpeak(ENCODE_GBK, "BDF8C8EB");//进入
  561. if(sutPocStatus.UserOnLineNum==0) MeSpeak(ENCODE_GBK, "CEDEC6E4CBFCB3C9D4B1D4DACFDF",0);//无其他成员在线
  562. else
  563. {
  564. os_dly_wait(10);
  565. sprintf(buf,"AT+POC=0A0000%s\r\n",sutPocStatus.UserIdTemp);//发起单呼
  566. ModemSendAT(buf);
  567. }
  568. SlwTrace(INF,"[ExitUserSel]",1);
  569. }else if(g_net_flag==2){
  570. net_sure=1;
  571. g_net_flag=0;
  572. }
  573. else
  574. {
  575. pttPressFressCt=os_time_get()+30;
  576. sutPocStatus.PPTpress=1;
  577. ModemSendAT("AT+POC=0B0000\r\n");
  578. }
  579. break;
  580. //-------------------------------------------------------------------
  581. case KEY_UP://=====================FUN1 KEY Press==================
  582. //-------------------------------------------------------------------
  583. g_ucKeyMode=0;//连续触发模式
  584. SlwTrace(INF,"[KEY1 Press]",1);
  585. if(g_ucFun1KeyPressCt<7)
  586. {
  587. g_ucFun1KeyPressCt++;
  588. if(3==g_ucFun1KeyPressCt && g_ucGroupSelect==0)
  589. {//进入成员选择
  590. if(sutPocStatus.Logined==0)return;
  591. g_ucUserSelect=1;
  592. SlwTrace(INF,"[EnterUserSel]",1);
  593. MeSpeak(ENCODE_GBK, "B3C9D4B1D1A1D4F1",0);
  594. os_dly_wait(2);
  595. ModemSendAT("AT+POC=10000020\r\n");
  596. os_dly_wait(2);
  597. sutPocStatus.UserOnLineNum=0;
  598. sutPocStatus.UserOnLineIndex=0;
  599. sprintf(buf,"AT+POC=0E0000%s\r\n",sutPocStatus.GroupId);
  600. SlwTrace(DEBUG,buf,0);
  601. ModemSendAT(buf);
  602. }else if(7==g_ucFun1KeyPressCt && g_ucGroupSelect==0){
  603. g_ucUserSelect=0;
  604. SlwTrace(INF,"[EnterNetSel]",1);
  605. g_net_flag=2;
  606. BroadCast_Net();
  607. }
  608. }
  609. break;
  610. //-------------------------------------------------------------------
  611. case KEY_DOWN://=====================FUN2 KEY Press=================
  612. //短按播报成员名称,所在组,长按播报电量信号GPS,
  613. //按着不放逆时针旋转10次PC TX模式。
  614. //-------------------------------------------------------------------
  615. g_ucKeyMode=0;//连续触发模式
  616. SlwTrace(INF,"[KEY2 Press]",1);
  617. //-------------
  618. if(g_ucFun2KeyPressCt<9)
  619. {
  620. g_ucFun2KeyPressCt++;
  621. if(3==g_ucFun2KeyPressCt) ReportVbatCsqGps();
  622. else if(9==g_ucFun2KeyPressCt) ReportVersion();
  623. }
  624. break;
  625. }
  626. }
  627. void UpdataAppVersion(void)
  628. {
  629. return;
  630. //正旋1格后松开,升级应用版本
  631. MeSpeak(ENCODE_UNICODE, "C6510759F466B065945E287548722C67F78B73513A678D51005F3A67",0);//准备更新应用版本,请关机再开机
  632. SlwTrace(INF,"Update APP Version!",1);
  633. SetLedStatus(RedFastFlash);
  634. SaveProductParaToFlash();
  635. while(1)
  636. {
  637. IWDG_ReloadCounter();//喂狗
  638. os_dly_wait(1);
  639. if(OnOffCheck())
  640. PWR_EN_LOW;
  641. }
  642. }
  643. void UpdataPocVersion(void)
  644. {
  645. char buf[80];
  646. MeSpeak(ENCODE_GBK, "D5FDD4DAC9FDBCB6",0);
  647. IWDG_ReloadCounter();
  648. os_dly_wait(100);
  649. IWDG_ReloadCounter();
  650. os_dly_wait(100);
  651. snprintf(buf, sizeof(buf), "AT+SYSCMD=./usr/bin/mAssistant 0 0 phone-client %d %d.%d.%d.%d\r\n",
  652. g_iPocVer,
  653. FOTA_IAP_IP0,
  654. FOTA_IAP_IP1,
  655. FOTA_IAP_IP2,
  656. FOTA_IAP_IP3);
  657. ModemSendAT(buf);
  658. SlwTrace(INF,"Update POC!",1);
  659. }
  660. void EnterGTMode(void)
  661. {
  662. g_ucModemTaskEn=0;
  663. SpeakerEnable();
  664. SetBeep(1176,10);
  665. os_dly_wait(20);
  666. SpeakerEnable();
  667. SetBeep(878,10);
  668. os_dly_wait(20);
  669. SpeakerEnable();
  670. SetBeep(1176,10);
  671. g_ucUART1RxMode=1;
  672. Uart1RxEnable(1);
  673. LedProcess(1);
  674. SetLedStatus(RedBlueFastFlash);
  675. SlwTrace(INF,"[EnterTxMode]",1);
  676. }
  677. void ExitGroupSelect(void)
  678. {
  679. if(GroupSelectFlag==1)
  680. {
  681. os_dly_wait(180);
  682. MeSpeak(ENCODE_UNICODE, "0090FA51",0);
  683. sutPocStatus.TTS=0;
  684. SpeakerDisable();
  685. }
  686. GroupSelectFlag=2;
  687. }
  688. /***********************************************************************
  689. *按键释放事件
  690. ************************************************************************/
  691. void KeyFree(void)
  692. {
  693. int i;
  694. char CheckCode[10];
  695. char buf[30];
  696. #ifdef USE_NEW_KEY_DRI
  697. if(KEY_PTT==g_ulKeyValue || KEY_MIC_PTT==g_ulKeyValue)
  698. #else
  699. if(KEY_PPT==g_ulKeyValue)
  700. #endif
  701. {
  702. SlwTrace(INF,"[PPT Free]",1);
  703. g_ucKeyPPTPress=0;
  704. sutPocStatus.PPTpress=0;
  705. if(g_ucUserSelect==3) g_ucUserSelect=0;
  706. else
  707. {
  708. if(os_time_get() > pttPressFressCt)
  709. {
  710. i=10;
  711. }else{
  712. i=pttPressFressCt-os_time_get();
  713. }
  714. os_dly_wait(i);
  715. ModemSendAT("AT+POC=0C0000\r\n");
  716. }
  717. g_ucKeyMode=0;
  718. }else if(KEY_UP==g_ulKeyValue)
  719. {
  720. SlwTrace(INF,"[KEY1 Free]",1);
  721. if(1==g_ucUART1RxMode)
  722. {
  723. #if 1
  724. g_ucUpdataVer=2;
  725. MeSpeak(ENCODE_UNICODE, "4753A77EF95BB28B48722C67",0);//升级对讲版本
  726. #else
  727. if(g_ucUpdataVer==0 || g_ucUpdataVer==2)
  728. {
  729. g_ucUpdataVer=1;
  730. MeSpeak(ENCODE_UNICODE, "4753A77E945E287548722C67",0);//升级应用版本
  731. }else if(g_ucUpdataVer==1)
  732. {
  733. g_ucUpdataVer=2;
  734. MeSpeak(ENCODE_UNICODE, "4753A77EF95BB28B48722C67",0);//升级对讲版本
  735. }
  736. #endif
  737. g_ucFun1KeyPressCt=0;
  738. g_iFun1KeyEncodeCt=0;
  739. return;
  740. }
  741. if(g_ucFun1KeyPressCt<3)
  742. {
  743. if(2==g_net_flag){
  744. g_net_flag=0;
  745. MeSpeak(ENCODE_UNICODE, "0090FA51",0);
  746. SlwTrace(INF,"[ExitNetSel]",1);
  747. }else if(g_ucUserSelect)
  748. {//退出成员选择
  749. g_net_flag=0;
  750. g_ucUserSelect=0;
  751. MeSpeak(ENCODE_UNICODE, "0090FA51",0);
  752. SlwTrace(INF,"[ExitUserSel]",1);
  753. }else if(0==g_ucGroupSelect)
  754. {//进入群组选择
  755. if(sutPocStatus.Logined==0)return; //从未登录过
  756. MeSpeak(ENCODE_UNICODE, "A47FC47E0990E962",0);
  757. SlwTrace(INF,"[EnterGroupSel]",1);
  758. g_ucGroupSelect=1;
  759. }else if(1==g_ucGroupSelect || 2 == g_ucGroupSelect)
  760. {//退出群组选择,包括未动旋钮和已转动旋钮
  761. g_ucGroupSelect=0;
  762. MeSpeak(ENCODE_GBK, "CDCBB3F6",0);//退出
  763. SlwTrace(INF,"[ExitGroupSel]",1);
  764. }
  765. }
  766. g_ucFun1KeyPressCt=0;
  767. g_iFun1KeyEncodeCt=0;
  768. //-------------------------------------------------------------------
  769. }else if(KEY_DOWN==g_ulKeyValue){//=========FUN2 KEY Free============
  770. //-------------------------------------------------------------------
  771. SlwTrace(INF,"[KEY2 Free]",1);
  772. //GT模式下
  773. if(1==g_ucUART1RxMode)
  774. {
  775. if(g_ucUpdataVer==1) UpdataAppVersion();//升级应用版本
  776. else if(g_ucUpdataVer==2) UpdataPocVersion();//升级对讲版本
  777. else ReportCheckCode();
  778. return;
  779. }
  780. //正旋2格以上后松开,进入PC TX模式
  781. if(g_iFun2KeyEncodeCt>2 && 0==g_ucUART1RxMode && g_ucModemTaskEn>0)
  782. {
  783. EnterGTMode();
  784. g_ucFun2KeyPressCt=0;
  785. g_iFun2KeyEncodeCt=0;
  786. #if(USE_CONFIG_FUN==1)
  787. memset((unsigned char *)&sutConfig, 0, sizeof(CONFIG_SER_DEF));
  788. #endif
  789. return;
  790. }
  791. //逆旋格以上后松开,播报POC GPS IP
  792. //
  793. if(g_iFun2KeyEncodeCt<-2 && g_ucFun2KeyPressCt != 3 && g_ucFun2KeyPressCt != 9 )
  794. {
  795. ReportPocGpsIP();
  796. }
  797. else
  798. //2秒内松开:如果未登陆则播报PSN和校验码,已登陆则播报用户名和群组名
  799. if(g_ucFun2KeyPressCt<3)
  800. {//2
  801. if(sutPocStatus.Logined==1){
  802. if(sutPocStatus.UserName[0]==0 || sutPocStatus.GroupName[0]==0) ReportCheckCode();
  803. else
  804. ReportUserGroupName();
  805. }
  806. else ReportCheckCode();
  807. }
  808. g_ucFun2KeyPressCt=0;
  809. g_iFun2KeyEncodeCt=0;
  810. }
  811. }
  812. void others(void)
  813. {//用于按PTT切换进入某个群组,MCU发TTS播报(模块不支持自己播报)
  814. if(g_ucEnterGroupFlag)
  815. {
  816. if(++g_ucEnterCnt > 3)
  817. {
  818. g_ucEnterCnt=0;
  819. g_ucEnterGroupFlag=0;
  820. }
  821. }
  822. }
  823. #if(USE_CONFIG_FUN==1)
  824. void ConfigModeDetect(void)
  825. {//检测进入配置服务器功能
  826. //GT模式下
  827. //先左CONF_PASS1再右CONF_PASS2再左CONF_PASS3
  828. char buf[20];
  829. unsigned char timeout=150;
  830. if(0 != g_ucModemTaskEn) return;
  831. if(sutConfig.g_ubConfigFlag==0)
  832. {
  833. if(sutConfig.g_ubConfigKeyStart)
  834. {
  835. if(++sutConfig.g_usConfigCnt >= timeout)
  836. {//旋转每一慢1.5秒内完成
  837. if(sutConfig.g_ucConfigKeyStep == 2 && sutConfig.g_ucConfigKeyPCnt == 3)
  838. {//顺1逆2顺3完成
  839. sutConfig.g_ubConfigFlag=1;
  840. sutConfig.g_ubConfigKeyStart=0;
  841. sutConfig.g_ucConfigKeyStep=0;
  842. sutConfig.g_ucConfigKeyPCnt=0;
  843. sutConfig.g_ucConfigKeyNCnt=0;
  844. sprintf(buf, "AT+TCPCLOSE=%d\r\n", GPS_DATA_SOCKET);
  845. ModemSendAT(buf);
  846. SlwTrace(INF, "ConfigModeActive",1);
  847. MeSpeak(ENCODE_GBK, "D5FDD4DAB7C3CECAC5E4D6C3B7FECEF1C6F7", 0);
  848. sutConfig.g_ucTcpRetryNum=CONFIG_TCP_RETRY_CNT;
  849. sutConfig.g_ucConfigStatus=0x01;//上报列表
  850. sutConfig.g_ubConfigFinished=0;//
  851. tcpControl=2;
  852. }else memset((unsigned char *)&sutConfig, 0, sizeof(CONFIG_SER_DEF));
  853. }
  854. }
  855. }
  856. if(1==sutConfig.g_ucConfigKeyPN)
  857. {//shun
  858. sutConfig.g_ucConfigKeyPN=0;
  859. if(0==g_ucModemTaskEn)
  860. {
  861. sutConfig.g_ucConfigKeyPCnt++;
  862. sutConfig.g_usConfigCnt=0;
  863. sutConfig.g_ubConfigKeyStart=1;
  864. if(sutConfig.g_ucConfigKeyStep==0)
  865. {
  866. if(sutConfig.g_ucConfigKeyPCnt > CONF_PASS1) sutConfig.g_usConfigCnt = 200;//复位
  867. }else if(sutConfig.g_ucConfigKeyStep == 1)
  868. {
  869. if(sutConfig.g_ucConfigKeyNCnt==CONF_PASS2)//顺3前逆2完成了
  870. {
  871. sutConfig.g_ucConfigKeyNCnt=0;
  872. sutConfig.g_ucConfigKeyStep=2;
  873. }else sutConfig.g_usConfigCnt = timeout;//复位
  874. }else if(sutConfig.g_ucConfigKeyStep==2)
  875. {
  876. if(sutConfig.g_ucConfigKeyPCnt>CONF_PASS3) sutConfig.g_usConfigCnt = timeout;
  877. }
  878. }
  879. }else if(2==sutConfig.g_ucConfigKeyPN)
  880. {//ni
  881. sutConfig.g_ucConfigKeyPN=0;
  882. if(0==g_ucModemTaskEn)
  883. {
  884. sutConfig.g_ubConfigKeyStart=1;
  885. sutConfig.g_ucConfigKeyNCnt++;
  886. sutConfig.g_usConfigCnt=0;
  887. if(sutConfig.g_ucConfigKeyStep==0)
  888. {
  889. if(sutConfig.g_ucConfigKeyPCnt==CONF_PASS1)//逆2前完成顺1
  890. {
  891. sutConfig.g_ucConfigKeyPCnt=0;
  892. sutConfig.g_ucConfigKeyStep=1;
  893. }else sutConfig.g_usConfigCnt = timeout;
  894. }else if(sutConfig.g_ucConfigKeyStep==1)
  895. {
  896. if(sutConfig.g_ucConfigKeyNCnt>CONF_PASS2) sutConfig.g_usConfigCnt = timeout;
  897. }else if(sutConfig.g_ucConfigKeyStep==2)
  898. {//没完成顺3,顺3后又逆至少1了
  899. sutConfig.g_usConfigCnt = timeout;
  900. }else sutConfig.g_usConfigCnt = timeout;
  901. }
  902. }
  903. }
  904. #endif
  905. void PowerOffProtetion(void)
  906. {
  907. static short cntDown;
  908. static char ledCnt,status;
  909. char buf[30];
  910. if(modemPwrOffNow==0) return;
  911. GPS_PWR_OFF;
  912. SlwTrace(INF, "Try to PwrOff",1);
  913. ModemSendAT("AT$QCPWRDN\r\n");
  914. MODEM_LED1_LOW;
  915. for(cntDown=6;cntDown>=0;cntDown--)
  916. {
  917. status=1;
  918. ledCnt=10;
  919. while(ledCnt>0)
  920. {
  921. if(cntDown!=0)
  922. {
  923. if(status==0)
  924. {
  925. MODEM_LED2_LOW;
  926. status=1;
  927. }else{
  928. MODEM_LED2_HIGH;
  929. status=0;
  930. }
  931. }else{
  932. MODEM_LED2_LOW;
  933. MODEM_LED1_HIGH;
  934. }
  935. ledCnt--;
  936. IWDG_ReloadCounter();
  937. DelayMs(20);
  938. }
  939. snprintf(buf, sizeof(buf), "PwrOff(%d)", cntDown);
  940. SlwTrace(INF, buf, 1);
  941. IWDG_ReloadCounter();
  942. os_dly_wait(70);
  943. }
  944. PWR_EN_LOW;
  945. while(1);
  946. }
  947. /*******************************************************************
  948. *MainTask
  949. *主任务
  950. ********************************************************************/
  951. __task void MainTask(void)
  952. {
  953. int KeyFlag;
  954. char *msg;
  955. INT8U err;
  956. unsigned char ucCheckVbatCt=0;
  957. static unsigned int sucCt=0;
  958. static unsigned char sucFunReportFlag=0;
  959. int Vbat;
  960. char buf[30];
  961. RunMake(THIS_FILE_ID);
  962. //Obtain own system task identification number. */
  963. idMainTask = os_tsk_self();
  964. memset((unsigned char *)&sutPocStatus,0,sizeof(SUT_POC_STATUS));
  965. SpeakerEnable();
  966. SetBeepByNoOS(888,100);
  967. SpeakerDisable();
  968. //Read Product param from flash
  969. ReadProductParaFromFlash();
  970. printf("\r\n%s_V%d Start...\r\n",sutProductPara.ProductName,sutProductPara.ProductVersion);
  971. printf("PSN:%lu\r\n",sutProductPara.PSN);
  972. //printf("volset 7 7 \r\n");
  973. g_ucUpdataVer=0;
  974. //Begin MainTask loop
  975. SlwTrace(INF,"Main Task Start!",1);
  976. //Led Init
  977. LedInit();
  978. SlwTrace(INF,"Led Init ok",1);
  979. g_iFun2KeyEncodeCt=0;
  980. SMSInit();
  981. //create PocTask
  982. idModemUartTask=os_tsk_create_user(ModemUartTask,3,&stkModemUartTask,sizeof(stkModemUartTask));
  983. idModemTask=os_tsk_create_user(ModemTask,3,&stkModemTask,sizeof(stkModemTask));
  984. idTTSTask=os_tsk_create_user(TTSTask, 3, &stkTTSTask,sizeof(stkTTSTask));
  985. RunMake(THIS_FILE_ID);
  986. #if(USE_CONFIG_FUN==1)
  987. memset((unsigned char *)&sutConfig, 0, sizeof(CONFIG_SER_DEF));
  988. #endif
  989. while(1)
  990. {
  991. PowerOffProtetion();
  992. os_dly_wait(1);
  993. //处理PC发送过来的消息
  994. RunMake(THIS_FILE_ID);
  995. if(g_usUart1RecvLen)
  996. {
  997. PcMsgHandle((char *)RxBuffer1);
  998. g_usUart1RecvLen=0;
  999. }
  1000. RunMake(THIS_FILE_ID);
  1001. //键盘处理
  1002. if(0!=(KeyFlag=GetKey()))
  1003. {
  1004. //printf("Key F=%d,V=%04x\r\n",KeyFlag,g_ulKeyValue);
  1005. //按键处理
  1006. if(1==KeyFlag) KeyPress(); //按键按下
  1007. else KeyFree();//按键释放
  1008. // CSQ_flag=1;
  1009. // CSQ_ct=0;
  1010. }
  1011. RunMake(THIS_FILE_ID);
  1012. //旋码开关处理
  1013. EncodeKeyProcess();
  1014. Select_Net(g_net_cnt);
  1015. //LED处理
  1016. LedProcess(0);
  1017. #if(USE_CONFIG_FUN==1)
  1018. ConfigModeDetect();
  1019. #endif
  1020. //---以下控制每秒执行一次---
  1021. if(os_time_get() < sucCt) continue;
  1022. sucCt=os_time_get()+100;
  1023. RunMake(THIS_FILE_ID);
  1024. KeyCount();//键盘按下、释放计数控制
  1025. RunMake(THIS_FILE_ID);
  1026. //测量电池电压
  1027. Vbat=GetVbat();
  1028. if(Vbat>0)g_iVbat=Vbat;
  1029. //判断电池电压是否过低关机
  1030. if(ucCheckVbatCt<3)ucCheckVbatCt++;
  1031. else CheckVbat(g_iVbat);
  1032. //MODEM防护
  1033. FingerDaemonfinger();
  1034. others();
  1035. CSQ_Prompt();
  1036. }
  1037. }
  1038. void EncodeKeyProcess(void)
  1039. {
  1040. static unsigned int limitedCnt=0;
  1041. char buf[30];
  1042. if(0==g_iEncode)return;
  1043. if(g_iEncode > 0)
  1044. {//这里是为了能让快旋能进入GT模式,因为下面作了速度限制,这部分必须提上来
  1045. //否则GT模式很难进入
  1046. if(g_ucFun2KeyPressCt>0){
  1047. if(g_iFun2KeyEncodeCt<0)g_iFun2KeyEncodeCt=0;
  1048. g_iFun2KeyEncodeCt++;
  1049. }else g_iFun2KeyEncodeCt=0;
  1050. }else if(g_iEncode<0){
  1051. if(g_ucFun2KeyPressCt>0){
  1052. if(g_iFun2KeyEncodeCt>0) g_iFun2KeyEncodeCt=0;
  1053. g_iFun2KeyEncodeCt--;
  1054. }else g_iFun2KeyEncodeCt=0;
  1055. }
  1056. if(os_time_get() < limitedCnt)
  1057. {//限制速度,否则模块有可能会死掉
  1058. g_iEncode=0;
  1059. return;
  1060. }
  1061. limitedCnt=os_time_get()+50;
  1062. if(g_iEncode>0){//====================顺时针旋转
  1063. #if(USE_CONFIG_FUN==1)
  1064. sutConfig.g_ucConfigKeyPN=1;
  1065. #endif
  1066. SlwTrace(INF,"[+]",1);
  1067. if(g_net_flag==2)
  1068. {
  1069. if(g_net_cnt==5){
  1070. g_net_cnt=0;
  1071. g_iEncode=0;
  1072. return;
  1073. }
  1074. g_net_cnt++;
  1075. g_iEncode=0;
  1076. return;
  1077. }
  1078. //-------------
  1079. //群组选择、用户选择
  1080. if(g_ucGroupSelect!=0){
  1081. g_ucGroupSelect=2;
  1082. SpeakerEnable();
  1083. ModemSendAT(POC_CMD_UP);
  1084. SlwTrace(INF,"[Group++]",1);
  1085. }else if(g_ucUserSelect!=0){
  1086. g_ucUserSelect=2;
  1087. if(sutPocStatus.UserOnLineNum==0)
  1088. {
  1089. sutPocStatus.UserOnLineIndex=0;
  1090. MeSpeak(ENCODE_GBK, "CEDEC6E4CBFCB3C9D4B1D4DACFDF",0);
  1091. }else
  1092. {
  1093. sprintf(buf,"AT+POC=10000021%04x\r\n",sutPocStatus.UserOnLineIndex);
  1094. ModemSendAT(buf);
  1095. }
  1096. //SlwTrace(INF,buf);
  1097. // sutPocStatus.UserOnLineIndex++;
  1098. ++sutPocStatus.UserOnLineIndex;
  1099. if(sutPocStatus.UserOnLineIndex>=sutPocStatus.UserOnLineNum){
  1100. sutPocStatus.UserOnLineIndex=0;
  1101. }
  1102. SlwTrace(INF,"[User++]",1);
  1103. }
  1104. }else{//==============================逆时针旋转
  1105. #if(USE_CONFIG_FUN==1)
  1106. sutConfig.g_ucConfigKeyPN=2;
  1107. #endif
  1108. SlwTrace(INF,"[-]",1);
  1109. if(g_net_flag==2)
  1110. {
  1111. if(g_net_cnt==0){
  1112. g_net_cnt=5;
  1113. g_iEncode=0;
  1114. return;
  1115. }
  1116. g_net_cnt--;
  1117. g_iEncode=0;
  1118. return;
  1119. }
  1120. // if(g_ucFun2KeyPressCt>0){
  1121. // if(g_iFun2KeyEncodeCt>0) g_iFun2KeyEncodeCt=0;
  1122. // g_iFun2KeyEncodeCt--;
  1123. // }else g_iFun2KeyEncodeCt=0;
  1124. //群组选择、用户选择
  1125. if(g_ucGroupSelect!=0){
  1126. g_ucGroupSelect=2;
  1127. SpeakerEnable();
  1128. ModemSendAT(POC_CMD_DOWN);
  1129. SlwTrace(INF,"[Group--]",1);
  1130. }else if(g_ucUserSelect!=0){
  1131. g_ucUserSelect=2;
  1132. if(sutPocStatus.UserOnLineNum==0)
  1133. {
  1134. sutPocStatus.UserOnLineIndex=0;
  1135. MeSpeak(ENCODE_GBK, "CEDEC6E4CBFCB3C9D4B1D4DACFDF",0);
  1136. }else
  1137. {
  1138. sprintf(buf,"AT+POC=10000021%04x\r\n",sutPocStatus.UserOnLineIndex);
  1139. ModemSendAT(buf);
  1140. }
  1141. if(sutPocStatus.UserOnLineIndex>0) sutPocStatus.UserOnLineIndex--;
  1142. else if(sutPocStatus.UserOnLineNum==0) sutPocStatus.UserOnLineIndex=0;
  1143. else sutPocStatus.UserOnLineIndex=sutPocStatus.UserOnLineNum-1;
  1144. SlwTrace(INF,"[User--]",1);
  1145. }
  1146. }
  1147. g_iEncode=0;
  1148. }
  1149. void ADCInit(void)
  1150. {
  1151. ADC_InitTypeDef ADC_InitStructure;
  1152. GPIO_InitTypeDef GPIO_InitStructure;
  1153. RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
  1154. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
  1155. GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0;
  1156. GPIO_InitStructure.GPIO_Mode =GPIO_Mode_AIN;
  1157. GPIO_Init(GPIOA,&GPIO_InitStructure); //默认速度为两兆
  1158. //配置ADC的运行:
  1159. ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //独立模式
  1160. ADC_InitStructure.ADC_ScanConvMode =DISABLE; //连续多通道模式
  1161. ADC_InitStructure.ADC_ContinuousConvMode =DISABLE;//ENABLE; //连续转换
  1162. ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //转换不受外界决定
  1163. ADC_InitStructure.ADC_DataAlign =ADC_DataAlign_Right; //右对齐
  1164. ADC_InitStructure.ADC_NbrOfChannel =1; //扫描通道数
  1165. ADC_Init(ADC1,&ADC_InitStructure);
  1166. ADC_RegularChannelConfig(ADC1,ADC_Channel_0, 1,ADC_SampleTime_1Cycles5); //通道X,采样时间为1.5周期,1代表规则通道第1个这个1是啥意思我不太清楚只有是1的时候我的ADC才正常。
  1167. ADC_Cmd (ADC1,ENABLE); //使能或者失能指定的ADC
  1168. ADC_SoftwareStartConvCmd(ADC1,ENABLE);//使能或者失能指定的ADC的软件转换启动功能
  1169. }
  1170. void GPIO_Config_ALL_AIN(void)
  1171. {
  1172. GPIO_InitTypeDef GPIO_InitStructure;
  1173. /* Enable GPIOD and GPIOE clock */
  1174. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB
  1175. | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD
  1176. | RCC_APB2Periph_AFIO, ENABLE);
  1177. /* Disable the Serial Wire Jtag Debug Port SWJ-DP */
  1178. GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
  1179. /* PA */
  1180. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  1181. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  1182. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  1183. GPIO_Init(GPIOA, &GPIO_InitStructure);
  1184. /* PB */
  1185. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  1186. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  1187. GPIO_Init(GPIOB, &GPIO_InitStructure);
  1188. /* PC */
  1189. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  1190. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  1191. GPIO_Init(GPIOC, &GPIO_InitStructure);
  1192. /* PD */
  1193. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  1194. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  1195. GPIO_Init(GPIOD, &GPIO_InitStructure);
  1196. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA
  1197. | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD
  1198. , DISABLE);
  1199. }
  1200. /***********************************************************************
  1201. *获取电池电压
  1202. 返回值: -1为无效 ; 正数表示电池电压放大100倍,如 382表示3.82V
  1203. ***********************************************************************/
  1204. int GetVbat(void)
  1205. {
  1206. char buf[30];
  1207. static int Ct=0;
  1208. static int siVbat[10]={0,0,0,0,0,0,0,0,0,0};
  1209. int iVbat[10];
  1210. int max[5];
  1211. int sum;
  1212. int i,j,k;
  1213. int adc;
  1214. int Vbat;
  1215. //采集ADC
  1216. if(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)!=RESET){//检查制定ADC标志位置1与否 ADC_FLAG_EOC 转换结束标志位 if(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)!=RESET){
  1217. adc=ADC_GetConversionValue(ADC1);
  1218. ADC_SoftwareStartConvCmd(ADC1,ENABLE);
  1219. if(adc<100 && adc>4095)return -1;
  1220. }else{
  1221. return -1;
  1222. }
  1223. //循环存储
  1224. siVbat[Ct]=adc;
  1225. if(++Ct>9)Ct=0;
  1226. //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]);
  1227. //滤波处理,排列取3个最大值,3个最大中去掉第一大,其余求平均
  1228. //拷贝
  1229. for(i=0;i<10;i++){
  1230. iVbat[i]=siVbat[i];
  1231. }
  1232. for(i=0;i<4;i++){
  1233. max[i]=0;
  1234. for(j=0;j<10;j++){
  1235. if(iVbat[j]>max[i]){
  1236. max[i]=iVbat[j];
  1237. k=j;
  1238. }
  1239. }
  1240. iVbat[k]=0;
  1241. }
  1242. // printf("%d,%d,%d\r\n",max[0],max[1],max[2]);
  1243. sum=max[1]+max[2];
  1244. if(max[2]<200)return -1;
  1245. //Vbat=sum*340/4096;
  1246. Vbat=sum*308/4096;
  1247. return Vbat;
  1248. }
  1249. void Sys_Standby(void)
  1250. {
  1251. RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); //使能PWR外设时钟
  1252. PWR_WakeUpPinCmd(ENABLE); //使能唤醒管脚功能,PA0
  1253. PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);
  1254. }
  1255. /*******************************************************
  1256. *CheckVbat
  1257. *检查电池电压,控制低压报警,
  1258. ******************************************************/
  1259. void CheckVbat(int Vbat)
  1260. {
  1261. static unsigned char sucCt=0;//提示“请充电”计数器
  1262. char i;
  1263. if(Vbat<MIN_PWR_LEVEL){
  1264. SlwTrace(INF,"Vbat low!shutdown now!",1);
  1265. //关闭模块
  1266. if(sutPocStatus.ModemPowerOn==1){
  1267. #if 0
  1268. MeSpeak(ENCODE_GBK, "B5CDD1B9B9D8BBFA",0);//低压关机
  1269. for(i=0;i<4;i++)
  1270. {
  1271. IWDG_ReloadCounter();
  1272. os_dly_wait(50);
  1273. }
  1274. SlwTrace(INF,"ModemPoweroff!",1);
  1275. ModemPoweroff();
  1276. #else
  1277. #endif
  1278. }
  1279. sutPocStatus.ModemPowerOn=0;
  1280. PWR_EN_LOW;
  1281. Sleeping();
  1282. }else if(Vbat<WARN_PWR_LEVEL){//提示请充电
  1283. if(++sucCt>30){
  1284. sucCt=0;
  1285. MeSpeak(ENCODE_GBK, "C7EBB3E4B5E7",0);//请充电
  1286. }
  1287. }else sucCt=0;
  1288. }
  1289. void GetXinHao(int CSQ,char *XinHao)
  1290. {
  1291. if(CSQ>31 || CSQ<1){
  1292. strcpy(XinHao,"2C00E065517FDC7EE14FF753");//无网络信号
  1293. }else if(CSQ>25){
  1294. //信号较强 "E14FF753838F3A5F"
  1295. strcpy(XinHao,"E14FF753838F3A5F");
  1296. }else if(CSQ>17){
  1297. //信号适中 "E14FF75302902D4E"
  1298. strcpy(XinHao,"E14FF75302902D4E");
  1299. }else if(CSQ>10){
  1300. //信号偏低 "E14FF7534F504E4F"
  1301. strcpy(XinHao,"E14FF7534F504E4F");
  1302. }else{
  1303. //信号很弱 "E14FF753885F315F"
  1304. strcpy(XinHao,"E14FF753885F315F");
  1305. }
  1306. }
  1307. void GetVbatPercent(int Vbat,char *Percent)
  1308. {
  1309. //10 20 30 40 50 60 70 80 90 100
  1310. const char *ccPercent[]={
  1311. "31003000",
  1312. "32003000",
  1313. "33003000",
  1314. "34003000",
  1315. "35003000",
  1316. "36003000",
  1317. "37003000",
  1318. "38003000",
  1319. "39003000",
  1320. "310030003000"};//310030003000 004E7E76
  1321. //播报电量百分比 10,20,30, 40, 50, 60, 70, 80, 90,100
  1322. const int siVbat[] ={340,344,353,362,370,378,386,394,412};//V611
  1323. int i;
  1324. for(i=0;i<10;i++){
  1325. if(Vbat<siVbat[i])break;
  1326. }
  1327. if(i>9)i=9;
  1328. strcpy(Percent,ccPercent[i]);
  1329. }
  1330. /****************************************************************
  1331. *语音播报 电量、信号、GPS
  1332. *****************************************************************/
  1333. void ReportVbatCsqGps(void)
  1334. {
  1335. unsigned char GpsFlag;
  1336. //电量百分之N,信号强,GPS已登陆已定位
  1337. char buf[30];
  1338. CSQ_flag=1;
  1339. CSQ_ct=0;
  1340. SpeakerEnable();
  1341. ModemSendAT("AT+LSHTTS=3,");
  1342. ModemSendAT("\"3575CF917E7606524B4E");//电量百分之
  1343. GetVbatPercent(g_iVbat,buf);
  1344. ModemSendAT(buf); //10~100
  1345. GetXinHao(g_iCSQ,buf); // 信号
  1346. ModemSendAT(buf);
  1347. // if(!sutGpsInfo.isGpsWork){
  1348. // //ModemSendAT("E065470050005300");//,无GPS
  1349. // GpsFlag=0x00;
  1350. // ModemSendAT("\"\r\n");
  1351. // }else
  1352. if(sutGpsInfo.isGpsAuthOk)
  1353. {
  1354. ModemSendAT("F25D74924367"); //已鉴权
  1355. GpsFlag=0x20;
  1356. }else{
  1357. ModemSendAT("2A6774924367"); //未鉴权
  1358. GpsFlag=0x10;
  1359. }
  1360. if(sutGpsStatus.CheckCnt != NO_GPS_CHECK_TIMEOUT)
  1361. {
  1362. if(!sutGpsInfo.isGpsWork)
  1363. {
  1364. ModemSendAT("E065470050005300");//,无GPS
  1365. GpsFlag=0x00;
  1366. }else
  1367. {
  1368. if(sutGpsInfo.isGpsValid)
  1369. {
  1370. ModemSendAT("17539662F25D9A5B4D4F"); //已定位
  1371. GpsFlag |= 0x01;
  1372. }else{
  1373. ModemSendAT("175396622A679A5B4D4F"); //未定位
  1374. }
  1375. }
  1376. }
  1377. ModemSendAT("\"\r\n");
  1378. snprintf(buf,30,"Vbat=%d,CSQ=%d,GPS=%02x",g_iVbat,g_iCSQ,GpsFlag);
  1379. SlwTrace(INF,buf,1);
  1380. }
  1381. /***************************************************************************
  1382. 将数字转Unicode编码
  1383. pUnicode空间最长 5*4+1=21字节
  1384. ****************************************************************************/
  1385. void NumToUnicode(unsigned short Num,char *pUnicode)
  1386. {
  1387. char temp[6];
  1388. int i,j,len;
  1389. sprintf(temp,"%u",Num);//0~65535
  1390. len=strlen(temp);
  1391. j=0;
  1392. for(i=0;i<len;i++){
  1393. pUnicode[j++]=0x30+temp[i]/16;
  1394. pUnicode[j++]=0x30+temp[i]%16;
  1395. pUnicode[j++]=0x30;
  1396. pUnicode[j++]=0x30;
  1397. }
  1398. pUnicode[j]=0;
  1399. }
  1400. void ReportVersion(void)
  1401. {
  1402. char buf[100];
  1403. char temp1[40],temp2[20];
  1404. CSQ_flag=1;
  1405. CSQ_ct=0;
  1406. sprintf(buf, "D3A6D3C3B0E6B1BE2C");//应用版本
  1407. sprintf(temp2, "%d", sutProductPara.ProductVersion);
  1408. AscStrToHexStr(temp2, temp1);
  1409. strcat(buf, temp1);
  1410. strcat(buf,"2CC4A3BFE9B0E6B1BE2C");
  1411. sprintf(temp2, "%d,%d", g_iModemVer,g_iPocVer);
  1412. AscStrToHexStr(temp2, temp1);
  1413. strcat(buf, temp1);
  1414. MeSpeak(ENCODE_GBK, buf,0);
  1415. sprintf(buf, "AVer=%d,MVer=%d,PVer=%d", sutProductPara.ProductVersion,g_iModemVer,g_iPocVer);
  1416. SlwTrace(INF, buf,1);
  1417. }
  1418. /*******************************************************************
  1419. *GetParaFromStr
  1420. *从Str中找到Para=后面至';'或非字符的字串并放入Value
  1421. 返回Value的长度
  1422. 举例:Str="GT+SMP=IP=192.168.1.1;Port=12345"
  1423. 如果Para="Port" 则Value将被赋值为"12345",并返回5
  1424. 如果Para="IP" 则Value将被赋值为"192.168.1.1",并返回11
  1425. 要求Para长度不大于20字节 ,Value长度不大于40字节
  1426. ********************************************************************/
  1427. int GetParaFromStr(char *Str,char *Para,char *Value)
  1428. {
  1429. int ValueLen=0,ParaLen=0;
  1430. char ParaTemp[22];
  1431. char *p;
  1432. char d;
  1433. int i=0;
  1434. if(0==*Str || 0==*Para)return 0;
  1435. while(0!=(d=*Para) && ParaLen<20){
  1436. ParaTemp[i++]=d;
  1437. if(d=='=' || d==';')return 0;
  1438. Para++;
  1439. ParaLen++;
  1440. }
  1441. ParaTemp[ParaLen++]='=';
  1442. ParaTemp[ParaLen]=0;
  1443. p=strstr(Str,ParaTemp);
  1444. p+=ParaLen;
  1445. //--
  1446. while(*p>0x20 && ';'!=*p && ValueLen<40){
  1447. *Value=*p;
  1448. p++;
  1449. Value++;
  1450. ValueLen++;
  1451. }
  1452. *Value=0;
  1453. return ValueLen;
  1454. }
  1455. void IWDG_Configuration(unsigned int value)
  1456. {
  1457. // WWDG 时钟使能
  1458. RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
  1459. if(RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)RCC_ClearFlag();
  1460. //写入0x5555,用于允许狗狗寄存器写入功能
  1461. IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
  1462. //狗狗时钟分频,40K/256=156HZ(6.4ms)
  1463. IWDG_SetPrescaler(IWDG_Prescaler_256);
  1464. //喂狗时间
  1465. //IWDG_SetReload(200);1.28s/6.4MS=200 .注意不能大于0xfff
  1466. IWDG_SetReload(value);//3.2s/6.4MS=500 .注意不能大于0xfff
  1467. //喂狗
  1468. IWDG_ReloadCounter();
  1469. //使能狗狗
  1470. IWDG_Enable();
  1471. }
  1472. void ReportUserGroupName(void)
  1473. {
  1474. char buf[90];
  1475. sprintf(buf, "%s2C2C%s", sutPocStatus.UserName, sutPocStatus.GroupName);
  1476. MeSpeak(ENCODE_GBK, buf,0);
  1477. }
  1478. void ChangeDig2Chinese(char dig, char *des)
  1479. {//只认0x30~0x39 以及'.'
  1480. const char ChineseTable[] = "C1E3D2BBB6FEC8FDCBC4CEE5C1F9C6DFB0CBBEC5B5E3";//零-九点
  1481. unsigned char i,index;
  1482. if(dig == '.') index = 10;
  1483. else if(dig >= '0' && dig <= '9') index = dig-0x30;
  1484. else return;
  1485. memcpy(des, &ChineseTable[index*4],4);
  1486. }
  1487. void ReportPocGpsIP(void)
  1488. {
  1489. unsigned char i;
  1490. char buf1[40],buf2[120];
  1491. char temp[12];
  1492. CSQ_flag=1;
  1493. CSQ_ct=0;
  1494. SpeakerEnable();
  1495. //终端编码xxx
  1496. ModemSendAT("AT+LSHTTS=1,");
  1497. sprintf(temp,"%lu",sutProductPara.PSN);
  1498. sprintf(buf2,"PSN=%s\r\n",temp);
  1499. SlwTrace(INF,buf2,0);
  1500. NumStrToUnicode(temp,buf2);
  1501. ModemSendAT("\"D6D5B6CBB1E0C2EB2C");
  1502. ModemSendAT(buf2);
  1503. memset(buf2, 0 ,sizeof(buf2));
  1504. ModemSendAT("BDBBBBBBB7FECEF1C6F72C");//交换服务器
  1505. snprintf(buf1,sizeof(buf1), "%d.%d.%d.%d", sutNewSegmentPara.PIP[0],sutNewSegmentPara.PIP[1],sutNewSegmentPara.PIP[2],sutNewSegmentPara.PIP[3]);
  1506. for(i=0;i<strlen(buf1);i++)
  1507. {
  1508. ChangeDig2Chinese(buf1[i], &buf2[i*4]);
  1509. }
  1510. ModemSendAT(buf2);
  1511. ModemSendAT("2CB6A8CEBBB7FECEF1C6F72C");//定位服务器
  1512. snprintf(buf1,sizeof(buf1), "%d.%d.%d.%d", sutNewSegmentPara.GIP[0],sutNewSegmentPara.GIP[1],sutNewSegmentPara.GIP[2],sutNewSegmentPara.GIP[3]);
  1513. for(i=0;i<strlen(buf1);i++)
  1514. {
  1515. ChangeDig2Chinese(buf1[i], &buf2[i*4]);
  1516. }
  1517. ModemSendAT(buf2);
  1518. memset(buf2, 0, sizeof(buf2));
  1519. ModemSendAT("B6CBBFDABAC52C");//端口号
  1520. sprintf(buf1,"%d",sutNewSegmentPara.GpsPort);
  1521. for(i=0;i<strlen(buf1);i++)
  1522. {
  1523. ChangeDig2Chinese(buf1[i], &buf2[i*4]);
  1524. }
  1525. ModemSendAT(buf2);
  1526. ModemSendAT("\"\r\n");
  1527. // ModemSendAT("AT+LSHTTS=1,");
  1528. //// ModemSendAT("\"D6D5B6CBB1E0BAC52C");
  1529. //// snprintf(buf1,sizeof(buf1),""
  1530. //
  1531. // ModemSendAT("\"BDBBBBBBB7FECEF1C6F72C");//交换服务器
  1532. // memset(buf2, 0 ,sizeof(buf2));
  1533. // snprintf(buf1,sizeof(buf1), "%d.%d.%d.%d", sutNewSegmentPara.PIP[0],sutNewSegmentPara.PIP[1],sutNewSegmentPara.PIP[2],sutNewSegmentPara.PIP[3]);
  1534. // for(i=0;i<strlen(buf1);i++)
  1535. // {
  1536. // ChangeDig2Chinese(buf1[i], &buf2[i*4]);
  1537. // }
  1538. // ModemSendAT(buf2);
  1539. // ModemSendAT("2CB6A8CEBBB7FECEF1C6F72C");//定位服务器
  1540. // memset(buf2, 0 ,sizeof(buf2));
  1541. // snprintf(buf1,sizeof(buf1), "%d.%d.%d.%d", sutNewSegmentPara.GIP[0],sutNewSegmentPara.GIP[1],sutNewSegmentPara.GIP[2],sutNewSegmentPara.GIP[3]);
  1542. // for(i=0;i<strlen(buf1);i++)
  1543. // ChangeDig2Chinese(buf1[i], &buf2[i*4]);
  1544. // ModemSendAT(buf2);
  1545. // memset(buf2, 0, sizeof(buf2));
  1546. // sprintf(buf2, "2C");
  1547. // sprintf(buf1,"%d",sutNewSegmentPara.GpsPort);
  1548. // for(i=0;i<strlen(buf1);i++)
  1549. // ChangeDig2Chinese(buf1[i], &buf2[2+i*4]);
  1550. //
  1551. // ModemSendAT(buf2);
  1552. // ModemSendAT("\"\r\n");
  1553. }
  1554. void SetPowerEn(unsigned char en)
  1555. {
  1556. GPIO_InitTypeDef GPIO_InitStructure;
  1557. if(en!=0){
  1558. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
  1559. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  1560. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  1561. GPIO_InitStructure.GPIO_Pin = PWR_EN_PIN;
  1562. GPIO_Init(PWR_EN_PORT, &GPIO_InitStructure);
  1563. PWR_EN_HIGH;
  1564. }else{
  1565. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
  1566. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
  1567. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  1568. GPIO_InitStructure.GPIO_Pin = PWR_EN_PIN;
  1569. GPIO_Init(PWR_EN_PORT, &GPIO_InitStructure);
  1570. PWR_EN_LOW;
  1571. }
  1572. }
  1573. /*****************************************************************************************
  1574. *函数名:GetCheckCodeByPsnMEID
  1575. *功能:根据PSN号和MEID码,生成伪随机码
  1576. *入口:PSN--PSN码,无符号长整形,必须是大于150000000的数值,有可能是9位数也可能是10位数
  1577. pMEID--MEID字串,长度14位或15位,第16字节必须为0。
  1578. *出口:pCheckCode:--长度为6的字符串,第7字节为结束符0x00,因此必须留够7字节的空间!
  1579. 返回:1--成功 0--因参数非法而失败
  1580. ******************************************************************************************/
  1581. int GetCheckCodeByPsnMEID(char *pCheckCode,unsigned long PSN,char *pMEID)
  1582. {
  1583. const unsigned char sucRandTable[256]={
  1584. 0x68,0x59,0x63,0x64,0xc8,0xcc,0xaa,0xa7,0xa2,0xab,0xa5,0x6e,0x6a,0x56,0x8a,0x57,
  1585. 0xf4,0xbb,0xfe,0xfa,0x26,0x21,0x2d,0x29,0x0d,0x09,0x3e,0x3a,0x37,0x32,0x0a,0x07,
  1586. 0xf7,0xf2,0xfb,0xf5,0xff,0xf6,0x1c,0x18,0x13,0x14,0xf1,0xfd,0xf9,0x0c,0x9f,0x08,
  1587. 0x9a,0x97,0x92,0x9b,0x95,0x9f,0x12,0x1b,0x15,0x2c,0x28,0x23,0xf9,0x2a,0x27,0x22,
  1588. 0x24,0x2e,0x67,0x25,0x2f,0x98,0xfc,0x75,0xf8,0xf3,0x3c,0x38,0x33,0x34,0x03,0x04,
  1589. 0x05,0x0f,0x06,0x01,0x7a,0x77,0x72,0x62,0x6b,0x83,0x84,0x8e,0xc4,0xcb,0x87,0x82,
  1590. 0x35,0x3f,0x36,0x4f,0x3d,0x39,0x9c,0x98,0x93,0x94,0x42,0x4f,0x46,0x41,0x81,0x8d,
  1591. 0x4d,0x49,0x71,0x7d,0x79,0x96,0x91,0x9d,0x99,0xc3,0xc4,0x1d,0xce,0xca,0x7f,0x76,
  1592. 0x7c,0x78,0x73,0x74,0x7e,0x7b,0x75,0x1e,0x1a,0x17,0x1f,0x16,0x11,0x1d,0x47,0x19,
  1593. 0x5d,0xc7,0xc2,0xcb,0xc5,0xcf,0xd1,0xdd,0xd9,0x4c,0x48,0xc6,0xc1,0xcd,0x61,0xc9,
  1594. 0xd7,0x8c,0xfd,0x88,0xa1,0xad,0xa9,0xb1,0xbd,0xb9,0x8b,0x85,0x8f,0x4b,0x45,0x86,
  1595. 0xdc,0xd8,0xd3,0xd4,0xde,0xd2,0xdb,0xd5,0xdf,0xd6,0x43,0x44,0x4e,0x4a,0xe7,0x47,
  1596. 0xac,0xa8,0xa3,0xa4,0xae,0xba,0x0d,0xb7,0xb2,0xaf,0xa6,0xe4,0xee,0xea,0xe7,0xe2,
  1597. 0xe1,0xed,0x0f,0xe9,0x66,0x61,0x6d,0x69,0xbb,0xb5,0xbf,0xb6,0xec,0xe8,0x0b,0xe3,
  1598. 0x52,0x5c,0x65,0x6f,0x58,0x53,0x54,0x0c,0x5e,0x5b,0x55,0x5f,0x31,0x2f,0x9a,0x0b,
  1599. 0x0b,0x5a,0x2b,0x9e,0x02,0x89,0x59,0x3b,0x0e,0x51,0x6c,0xeb,0xda,0xe6,0x31,0xf6
  1600. };
  1601. char aucPSN[11];
  1602. char aucMEID[16];
  1603. unsigned char key[10];
  1604. unsigned char temp1,temp2;
  1605. int MeidLen,PsnLen;
  1606. int i,j;
  1607. //PSN合法性检测
  1608. if(PSN<150100000)return 0;
  1609. //MEID合法性检测
  1610. MeidLen=strlen(pMEID);
  1611. if(MeidLen!=14 && MeidLen!=15)return 0; //MEID号长度必须为14或15
  1612. //PSN转字符串,不够10位的前面补'0'
  1613. sprintf(aucPSN,"%010lu",PSN);
  1614. PsnLen=strlen(aucPSN);
  1615. //取MEID的最后10个字符
  1616. j=0;
  1617. for(i=(MeidLen-10);i<MeidLen;i++){
  1618. aucMEID[j]=pMEID[i];
  1619. j++;
  1620. }
  1621. //所有字节进行相互异或运算,使每个字节的变化对整体结果都敏感
  1622. temp1=0;
  1623. temp2=0;
  1624. for(i=0;i<10;i++){
  1625. temp1^=(unsigned char)aucPSN[i];
  1626. temp2^=(unsigned char)aucMEID[i];
  1627. }
  1628. temp1^=temp2;
  1629. temp2=sucRandTable[temp1];
  1630. //循环查表异或运算,生成key
  1631. for(i=0;i<10;i++){
  1632. temp1=aucPSN[i]^temp2;
  1633. key[i]=aucMEID[i]^temp1;
  1634. temp2=sucRandTable[temp1];
  1635. }
  1636. //取最后6个key,分别除10取余后再转Ascii,作为结果,结果为6个数字串,如"123456"
  1637. j=0;
  1638. for(i=4;i<10;i++){
  1639. pCheckCode[j]=key[i]%10;
  1640. pCheckCode[j]+=0x30;
  1641. j++;
  1642. }
  1643. pCheckCode[6]=0; //结束符,方便调试打印和语音播报。
  1644. return 1;
  1645. }
  1646. /***************************************************************************
  1647. 将数字串转Unicode编码,方便播报
  1648. pUnicode长度必须为pNum长度的8倍,否则内存溢出!
  1649. ****************************************************************************/
  1650. void NumStrToUnicode(char *pNum,char *pUnicode)
  1651. {
  1652. char temp[10];
  1653. int i,j,len;
  1654. len=strlen(pNum);
  1655. // sprintf(temp,"len=%d",len);
  1656. // SlwTrace(INF,temp,1);
  1657. j=0;
  1658. for(i=0;i<len;i++){
  1659. pUnicode[j++]='3';
  1660. pUnicode[j++]=pNum[i];
  1661. pUnicode[j++]='0';
  1662. pUnicode[j++]='0';
  1663. if(i==(len-1))break;//最后一个不用加逗号‘,’
  1664. //","
  1665. pUnicode[j++]='2';
  1666. pUnicode[j++]='0';
  1667. pUnicode[j++]='0';
  1668. pUnicode[j++]='0';
  1669. }
  1670. pUnicode[j]=0;
  1671. }
  1672. /**************************************************************
  1673. *ReportCheckCode
  1674. ***************************************************************/
  1675. void ReportCheckCode(void)
  1676. {
  1677. char temp[11],i;
  1678. char buf[80];
  1679. CSQ_flag=1;
  1680. CSQ_ct=0;
  1681. SpeakerEnable();
  1682. //终端编号xxxx
  1683. if(sutProductPara.PSN<150100000 || sutProductPara.PSN==0xffffffff){
  1684. SlwTrace(INF,"PSN Error!",1);
  1685. MeSpeak(ENCODE_GBK, "D6D5B6CBB1E0BAC5B4EDCEF3",0);//终端编号错误
  1686. return;
  1687. }
  1688. //校验码xxxx
  1689. if(GetCheckCodeByPsnMEID(temp,sutProductPara.PSN,sutNewSegmentPara.HARDID)){
  1690. sprintf(buf,"CheckCode=%s\r\n",temp);
  1691. SlwTrace(INF,buf,0);
  1692. NumStrToUnicode(temp,buf);
  1693. ModemSendAT("AT+LSHTTS=1,\"D0A3D1E9C2EB");//校验码,
  1694. ModemSendAT(buf);
  1695. ModemSendAT("2C");
  1696. }else{
  1697. SlwTrace(INF,"CheckCode=NULL",1);
  1698. ModemSendAT("AT+LSHTTS=1,\"D0A3D1E9C2EBBBF1C8A1CAA7B0DC2C");//校验码获取失败
  1699. }
  1700. //终端编码xxx
  1701. sprintf(temp,"%lu",sutProductPara.PSN);
  1702. sprintf(buf,"PSN=%s\r\n",temp);
  1703. SlwTrace(INF,buf,0);
  1704. NumStrToUnicode(temp,buf);
  1705. ModemSendAT("D6D5B6CBB1E0C2EB");//终端编码,
  1706. ModemSendAT(buf);
  1707. ModemSendAT("\"\r\n");
  1708. }
  1709. /************************************************************************************
  1710. ResetModem
  1711. *************************************************************************************/
  1712. void ResetModem(void)
  1713. {
  1714. SlwTrace(INF,"Reset Modem!",1);
  1715. sutPocStatus.modemRstFlag=1;
  1716. }
  1717. /*************************************************************************************
  1718. *FingerDaemonfinger
  1719. *守护进程
  1720. *用于防止通讯模块死机,或者与通讯模块通讯的串口异常而重新启动模块或通讯驱动。
  1721. *用于防止GPS模块异常而重启GPS
  1722. *此函数需要确保每秒调用一次
  1723. 入口参数
  1724. sutPocStatus.FirstLogined
  1725. sutPocStatus.PocLostCt
  1726. sutPocStatus.ModemPowerOn
  1727. sutPocStatus.ModemInactiveCt
  1728. g_iCSQ
  1729. **************************************************************************************/
  1730. void FingerDaemonfinger(void)
  1731. {
  1732. static unsigned char sucPocLostTimeoutCount=0;//
  1733. static unsigned char sucModemInactiveCount=0;
  1734. unsigned short PocLostCtMax;
  1735. IWDG_ReloadCounter();//喂狗
  1736. //return;
  1737. if(g_ucModemTaskEn==0)return;
  1738. //如果曾经登陆过POC系统,然后离线,开始计数,直到再次登陆,如果一直不登陆超过一定时间,则重启模块和串口
  1739. if(sutPocStatus.FirstLogined){
  1740. if(sutPocStatus.Logined==0){
  1741. PocLostCtMax=pocTimeOutTime*60;
  1742. if(++sutPocStatus.PocLostCt>PocLostCtMax){
  1743. sutPocStatus.PocLostCt=0;
  1744. //长时间不登陆,重启模块及串口驱动部分
  1745. SlwTrace(INF,"PocLostTimeout!",1);
  1746. ResetModem();
  1747. if(++sucPocLostTimeoutCount>2){//连续重启3次都失败,则复位整个系统
  1748. sucPocLostTimeoutCount=0;
  1749. SystemReset();
  1750. }
  1751. }
  1752. }else{
  1753. sutPocStatus.PocLostCt=0;
  1754. sucPocLostTimeoutCount=0;
  1755. }
  1756. }
  1757. //如果模块已开机,长时间收不到串口消息,则重启模块及串口驱动部分
  1758. if(sutPocStatus.ModemPowerOn==1)
  1759. {
  1760. if(sutPocStatus.ModemInactiveCt==0)//ModemInactiveCt必须在接收到Modem串口消息后才清零
  1761. sucModemInactiveCount=0;
  1762. if(++sutPocStatus.ModemInactiveCt>35) //15
  1763. {//等待时间15秒
  1764. sutPocStatus.ModemInactiveCt=0;
  1765. //长时间收不到串口消息,重启模块及串口驱动
  1766. SlwTrace(INF,"ModemRecvTimeout!",1);
  1767. ResetModem();
  1768. //连续重启3次无效,复位整个系统
  1769. if(++sucModemInactiveCount>2){
  1770. sucModemInactiveCount=0;
  1771. SystemReset();
  1772. }
  1773. }
  1774. }
  1775. //GPS守护
  1776. if(sutGpsInfo.isGpsWork>0){
  1777. if(++sutGpsInfo.GpsInactiveCt>10){
  1778. sutGpsInfo.GpsInactiveCt=0;
  1779. //复位GPS
  1780. GPSRestart();
  1781. Uart3Init();
  1782. TSGpsDataInit();
  1783. }
  1784. }
  1785. }
  1786. void MakeStrEndByNewLine(char *str)
  1787. {//一定要以'\r'结尾
  1788. unsigned short i;
  1789. for(i=0;i<strlen(str);i++)
  1790. {
  1791. if(str[i] == '\r')
  1792. {
  1793. str[i]=0;
  1794. return;
  1795. }
  1796. }
  1797. }
  1798. //255.255.255.255
  1799. //-->0xff 0xff 0xff 0xff
  1800. unsigned char GetStringIP2Bytes(unsigned char *IPBytes,char *IPString)
  1801. {
  1802. unsigned char len,i,segment,j;
  1803. char *p;
  1804. char temp[3];
  1805. len = strlen(IPString);
  1806. if(len<7 || len >15) return 1;
  1807. segment=0;
  1808. j=0;
  1809. p=IPString;
  1810. for(i=0;i<len;i++)
  1811. {
  1812. if(IPString[i] == '.')
  1813. {
  1814. if(segment < 4) IPBytes[segment++] = atoi(p);
  1815. else return 2;
  1816. p=&IPString[i+1];
  1817. }else if(IPString[i] < '0' || IPString[i] > '9') return 3;
  1818. }
  1819. if(segment < 5) IPBytes[segment++] = atoi(p);
  1820. return 0;
  1821. }
  1822. void Select_Net(unsigned char net)
  1823. {
  1824. unsigned char now_choice=0;
  1825. static unsigned char last_choice=0;
  1826. now_choice=net;
  1827. if(now_choice!=last_choice)
  1828. {
  1829. last_choice=now_choice;
  1830. switch(last_choice)
  1831. {
  1832. case 0:
  1833. MeSpeak(ENCODE_UNICODE,"517FDC7EEA81A852",1);//自动
  1834. break;
  1835. case 1:
  1836. MeSpeak(ENCODE_UNICODE,"8C4E219E216A0F5F",1);
  1837. break;
  1838. case 2:
  1839. MeSpeak(ENCODE_UNICODE,"094E219E216A0F5F",1);
  1840. break;
  1841. case 3:
  1842. MeSpeak(ENCODE_UNICODE,"DB56219EEA81A852",1);//4G自动
  1843. break;
  1844. case 4:
  1845. MeSpeak(ENCODE_UNICODE,"DB56219E31003800300030004651",1); //4G 1800M
  1846. break;
  1847. case 5:
  1848. MeSpeak(ENCODE_UNICODE,"DB56219E3800300030004651",1); //4G 800M
  1849. break;
  1850. // case 3:
  1851. // MeSpeak(ENCODE_UNICODE,"DB56219E216A0F5F",1);
  1852. // break;
  1853. default:
  1854. break;
  1855. }
  1856. }
  1857. if(net_sure==1){
  1858. sutProductPara.g_net=last_choice;
  1859. SaveProductParaToFlash();
  1860. switch(last_choice)
  1861. {
  1862. case 0:
  1863. ModemSendAT("AT+LCTMOBAPREF=2,0\r\n");
  1864. os_dly_wait(1);
  1865. GetMododexWithCard();
  1866. MeSpeak(ENCODE_UNICODE,"DB8F6551517FDC7EEA81A852",1);//
  1867. net_sure=0;
  1868. break;
  1869. case 1:
  1870. ModemSendAT("AT+LCTMOBAPREF=2,0\r\n");
  1871. os_dly_wait(1);
  1872. GetMododexWithCard();
  1873. MeSpeak(ENCODE_UNICODE,"DB8F65518C4E219E216A0F5F",1);
  1874. net_sure=0;
  1875. break;
  1876. case 2:
  1877. ModemSendAT("AT+LCTMOBAPREF=2,0\r\n");
  1878. os_dly_wait(1);
  1879. GetMododexWithCard();
  1880. MeSpeak(ENCODE_UNICODE,"DB8F6551094E219E216A0F5F",1);
  1881. net_sure=0;
  1882. break;
  1883. case 3:
  1884. //GetMododexWithCard();
  1885. ModemSendAT("AT+LCTMOBAPREF=5,0\r\n");
  1886. os_dly_wait(1);
  1887. ModemSendAT("AT+MODODREX=5\r\n");
  1888. MeSpeak(ENCODE_UNICODE,"DB8F6551DB56219EEA81A852",1); //4G 自动
  1889. net_sure=0;
  1890. break;
  1891. case 4:
  1892. //GetMododexWithCard();
  1893. ModemSendAT("AT+LCTMOBAPREF=5,6\r\n");
  1894. os_dly_wait(1);
  1895. ModemSendAT("AT+MODODREX=5\r\n");
  1896. MeSpeak(ENCODE_UNICODE,"DB8F6551DB56219E31003800300030004651",1); //4G 1800M
  1897. net_sure=0;
  1898. break;
  1899. case 5:
  1900. //GetMododexWithCard();
  1901. ModemSendAT("AT+LCTMOBAPREF=5,8\r\n");
  1902. os_dly_wait(1);
  1903. ModemSendAT("AT+MODODREX=5\r\n");
  1904. MeSpeak(ENCODE_UNICODE,"DB8F6551DB56219E3800300030004651",1);//进入4G 800M
  1905. net_sure=0;
  1906. break;
  1907. default:
  1908. break;
  1909. }
  1910. }
  1911. }
  1912. void GetMododexWithCard(void)
  1913. {
  1914. char buf[30];
  1915. //根据CardType和ModeSetup转换为Mododex值的一个表
  1916. static const unsigned char MododrxTable[3][4]={{11,15,10,5},{2,25,7,5},{17,25,1,5}}; //
  1917. snprintf(buf,sizeof(buf),"AT+MODODREX=%d\r\n",MododrxTable[thisYunYingShang][sutProductPara.g_net]);
  1918. ModemSendAT(buf);
  1919. SlwTrace(INF,buf,1);
  1920. snprintf(buf,sizeof(buf),"HAHAHAHAHAA\r\n");
  1921. SlwTrace(INF,buf,1);
  1922. }
  1923. void BroadCast_Net()
  1924. {
  1925. //ReadFlashData(APP_CONFIG_ADDR,(unsigned char *)&sutProductPara,sizeof(SUT_CONFIG));
  1926. printf("g_net=%d\r\n",sutProductPara.g_net);
  1927. switch(sutProductPara.g_net)
  1928. {
  1929. case 0:
  1930. MeSpeak(ENCODE_UNICODE,"517FDC7EBE8B6E7F0CFF535F4D52517FDC7EEA81A852",1);//自动
  1931. break;
  1932. case 1:
  1933. MeSpeak(ENCODE_UNICODE,"517F216ABE8B6E7F0CFF535F4D528C4E219E216A0F5F",1);
  1934. break;
  1935. case 2:
  1936. MeSpeak(ENCODE_UNICODE,"517F216ABE8B6E7F0CFF535F4D52094E219E216A0F5F",1);
  1937. break;
  1938. case 3:
  1939. MeSpeak(ENCODE_UNICODE,"517FDC7EBE8B6E7F0CFF535F4D52DB56219EEA81A852",1);//自动
  1940. break;
  1941. case 4:
  1942. MeSpeak(ENCODE_UNICODE,"517FDC7EBE8B6E7F0CFF535F4D52DB56219E31003800300030004651",1);
  1943. break;
  1944. case 5:
  1945. MeSpeak(ENCODE_UNICODE,"517FDC7EBE8B6E7F0CFF535F4D52DB56219E3800300030004651",1);
  1946. break;
  1947. // case 3:
  1948. // MeSpeak(ENCODE_UNICODE,"517F216ABE8B6E7F0CFF535F4D52DB56219E216A0F5F",1);
  1949. // break;
  1950. default:
  1951. break;
  1952. }
  1953. }
  1954. void CSQ_Prompt()
  1955. {
  1956. static char CSQ_ct2=0;
  1957. if(0==g_ucModemTaskEn) return;
  1958. if(++CSQ_ct>16){
  1959. if(CSQ_flag==1){
  1960. CSQ_flag=0;
  1961. CSQ_ct=0;
  1962. return;
  1963. }
  1964. CSQ_ct=0;
  1965. }
  1966. if(++CSQ_ct2>10){
  1967. if(sutPocStatus.FirstLogined==1 && CSQ_flag==0){
  1968. if(sutPocStatus.Logined==0){
  1969. if(0==g_iCSQ || 99==g_iCSQ){
  1970. //滴滴两声持续一秒
  1971. SpeakerEnable();
  1972. SetBeep(1176,10);
  1973. os_dly_wait(110);
  1974. SpeakerEnable();
  1975. SetBeep(1176,10);
  1976. SlwTrace(INF,"CSQ_Prompt.........",1);
  1977. }else if(g_iCSQ>1 && g_iCSQ<99){
  1978. SpeakerEnable();
  1979. SetBeep(1176,12);
  1980. }
  1981. }
  1982. }
  1983. CSQ_ct2=0;
  1984. }else{}
  1985. }
  1986. void ReportIpInfo(void)
  1987. {
  1988. char buf[100];
  1989. char temp1[40],temp2[20];
  1990. sprintf(buf, "D3A6D3C3B0E6B1BE2C");//应用版本
  1991. sprintf(temp2, "%d", sutProductPara.ProductVersion);
  1992. AscStrToHexStr(temp2, temp1);
  1993. strcat(buf, temp1);
  1994. strcat(buf,"2CC4A3BFE9B0E6B1BE2C");
  1995. sprintf(temp2, "%d,%d", g_iModemVer,g_iPocVer);
  1996. AscStrToHexStr(temp2, temp1);
  1997. strcat(buf, temp1);
  1998. MeSpeak(ENCODE_GBK, buf,0);
  1999. sprintf(buf, "AVer=%d,MVer=%d,PVer=%d", sutProductPara.ProductVersion,g_iModemVer,g_iPocVer);
  2000. SlwTrace(INF, buf,1);
  2001. }