modemTask.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. #include "includes.h"
  2. #include "socket.h"
  3. int g_iCSQ=-1;
  4. signed char Chargeing;
  5. YUNYINGSHANG_DEF thisYunYingShang=CHINA_NONE;
  6. unsigned char g_ucModemTaskEn=0;
  7. unsigned char modemInitStatus=0;
  8. unsigned char g_ucCardStatus=0;
  9. unsigned char modemInitReady=0;//0模块没开始初始化 1模块初始化成功 2模块初始化失败
  10. static char ChekCardCnt=0;
  11. char CardStatue=0x11;
  12. unsigned char SIMSelect;
  13. unsigned int TTSPlayTick=0;
  14. char SendAT[50];
  15. char WaitAT1[30];
  16. char WaitAT2[30];
  17. typedef enum{
  18. MINI_WAT_START,
  19. MINI_GET_MODULE,
  20. MINI_GET_POC_VER,
  21. MINI_GET_POC_CODE,
  22. MINI_GET_CARD,
  23. MINI_GET_IMEI,
  24. MINI_PLY_ICCID,
  25. MINI_POC_PARA,
  26. MINI_SET_TONES,
  27. MINI_READ_SPKLV,
  28. MINI_GET_SIMSELECT,
  29. MINI_SET_MICLV,
  30. MINI_SET_TTSPARM,
  31. MINI_SET_GPSPARM,
  32. MINI_CHEAK_HEADSET,
  33. MINI_POC_AUTHSET,
  34. }M_INIT_STATUS;
  35. static unsigned char initStatus;
  36. static unsigned short timeOut;
  37. static unsigned char PocGetTypeCnt=0;
  38. char *FirmSperkr="AT+CAIET=0,0,9600,400,\"8080808002003400d3ff000002003400d6ff0000020\
  39. 03400d9ff000002003400dcff000002003400dfff000002003400e2ff000002003400e5ff000002003400e8ff000002003400ebff000002003400eeff000002003400f1ff000002003400f4ff000002003400f7ff000002003400faff000002003400fdff0000020034000000000002003400d3ff000002003400d6ff000002003400d9ff000002003400dcff000002003400dfff000002003400e2ff000002003400e5ff000002003400e8ff000002003400ebff000002003400eeff000002003400f1ff000002003400f4ff000002003400f7ff000002003400faff000002003400fdff0000020034000000000004003400d3ff000004003400d6ff000004003400d9ff000004003400dcff000004003400dfff000004003400e2ff000004003400e5ff000004003400e8ff000004003400ebff000004003400eeff000004003400f1ff000004003400f4ff000004003400f7ff000004003400faff000004003400fdff0000040034000000000004003400d3ff000004003400\"\r\n";
  40. char *FirmSperkr2="AT+CAIET=0,0,10000,372,\"d6ff000004003400d9ff000004003400dcff000004\
  41. 003400dfff000004003400e2ff000004003400e5ff000004003400e8ff000004003400ebff000004003400eeff000004003400f1ff000004003400f4ff000004003400f7ff000004003400faff000004003400fdff0000040034000000000004003400d3ff000004003400d6ff000004003400d9ff000004003400dcff000004003400dfff000004003400e2ff000004003400e5ff000004003400e8ff000004003400ebff000004003400eeff000004003400f1ff000004003400f4ff000004003400f7ff000004003400faff000004003400fdff0000040034000000000004003400d3ff000004003400d6ff000004003400d9ff000004003400dcff000004003400dfff000004003400e2ff000004003400e5ff000004003400e8ff000004003400ebff000004003400eeff000004003400f1ff000004003400f4ff000004003400f7ff000004003400faff000004003400fdff00000400340000000000\"\r\n";
  42. void SpeakTTSVoice(void)
  43. {
  44. int len,timeout,i;
  45. char ttsMessage[20*4];
  46. //SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  47. unsigned char codeType=ENCODE_UNICODE;
  48. if(newPara.ttsMessage[0]==0) return;
  49. len=strlen(newPara.ttsMessage);
  50. len = len+(8-len%8);//8倍数
  51. if(newPara.ttsCodeType==TTS_UNICODE)
  52. {
  53. codeType=ENCODE_UNICODEBigend;
  54. for(i=0;i<len;i+=4){
  55. ttsMessage[i]=newPara.ttsMessage[i+2];
  56. ttsMessage[i+1]=newPara.ttsMessage[i+3];
  57. ttsMessage[i+2]=newPara.ttsMessage[i];
  58. ttsMessage[i+3]=newPara.ttsMessage[i+1];
  59. printf("%c",ttsMessage[i]);
  60. printf("%c",ttsMessage[i+1]);
  61. printf("%c",ttsMessage[i+2]);
  62. printf("%c",ttsMessage[i+3]);
  63. }
  64. ttsMessage[len-1]=0;
  65. printf("\r\n");
  66. }else if(newPara.ttsCodeType==TTS_GBK) codeType=ENCODE_ASCII;
  67. MeSpeak(codeType,ttsMessage);
  68. }
  69. void mInitSwitchStatus(unsigned char status){
  70. timeOut=10;//5秒
  71. initStatus=status;
  72. snprintf(WaitAT2, sizeof(WaitAT2), "@#@");
  73. switch(initStatus){
  74. case MINI_WAT_START:
  75. timeOut=60;//只有模块启动时时间才要长些这里设置为30秒//60
  76. SlwTrace(INF, "WaitModemRun..",1);
  77. snprintf(SendAT, sizeof(SendAT), "ATE0\r\n");
  78. snprintf(WaitAT1, sizeof(WaitAT1), "OK");
  79. snprintf(WaitAT2, sizeof(WaitAT2), "+POC:START");
  80. break;
  81. case MINI_POC_AUTHSET:
  82. timeOut=6;
  83. //timeOut=10;//只有模块启动时时间才要长些这里设置为30秒//60
  84. SlwTrace(INF, "PocAuth",1);
  85. snprintf(SendAT, sizeof(SendAT), "AT+GAUTH\r\n");
  86. snprintf(WaitAT1, sizeof(WaitAT1), "+GAUTH:");
  87. snprintf(WaitAT2, sizeof(WaitAT2), "+GAUTH:");
  88. break;
  89. case MINI_GET_MODULE:
  90. SlwTrace(INF, "GetModemModule..",1);
  91. snprintf(SendAT, sizeof(SendAT), "ATI\r\n");
  92. snprintf(WaitAT1, sizeof(WaitAT1), "SV");
  93. break;
  94. case MINI_GET_POC_VER:
  95. timeOut=12;
  96. SlwTrace(INF, "GetPocVersion..",1);
  97. if(PocGetTypeCnt==0){
  98. snprintf(SendAT, sizeof(SendAT), "AT+POC_VER?\r\n");
  99. snprintf(WaitAT1, sizeof(WaitAT1), "+POC_VER:");
  100. }
  101. else {
  102. snprintf(SendAT, sizeof(SendAT), "AT+POC=version\r\n");
  103. snprintf(WaitAT1, sizeof(WaitAT1), "+POC:BROAD");
  104. }
  105. break;
  106. case MINI_GET_POC_CODE:
  107. SlwTrace(INF, "GetPocCode..",1);
  108. snprintf(SendAT, sizeof(SendAT), "AT+POC=40000000\r\n");
  109. snprintf(WaitAT1, sizeof(WaitAT1), "+POC:400000000");
  110. break;
  111. case MINI_GET_CARD:
  112. SlwTrace(INF, "GetCardStatus..",1);
  113. snprintf(SendAT, sizeof(SendAT), "AT+CPIN?\r\n");
  114. snprintf(WaitAT1, sizeof(WaitAT1), "+CPIN: READY");
  115. break;
  116. case MINI_GET_IMEI:
  117. SlwTrace(INF, "GetIMEI..",1);
  118. snprintf(SendAT, sizeof(SendAT), "AT+LSHIMEI\r\n");
  119. snprintf(WaitAT1, sizeof(WaitAT1), "+LSHIMEI:");
  120. break;
  121. case MINI_PLY_ICCID:
  122. SlwTrace(INF, "GetICCID..",1);
  123. snprintf(SendAT, sizeof(SendAT), "AT+CCID\r\n");
  124. snprintf(WaitAT1, sizeof(WaitAT1), "+CCID:");
  125. break;
  126. case MINI_POC_PARA:
  127. SlwTrace(INF, "GetPOCPara..",1);
  128. snprintf(SendAT, sizeof(SendAT), "AT+POC=020000\r\n");
  129. snprintf(WaitAT1, sizeof(WaitAT1), "+POC:02");
  130. break;
  131. case MINI_SET_TONES:
  132. SlwTrace(INF, "SetTones..",1);
  133. if(newPara.KeySound!=0){
  134. snprintf(SendAT, sizeof(SendAT), "AT+TONES=1\r\n");
  135. snprintf(WaitAT1, sizeof(WaitAT1), "+TONES:1");
  136. }else {
  137. snprintf(SendAT, sizeof(SendAT), "AT+TONES=0\r\n");
  138. snprintf(WaitAT1, sizeof(WaitAT1), "+TONES:0");
  139. }
  140. break;
  141. case MINI_READ_SPKLV:
  142. SlwTrace(INF, "SetCLVL..",1);
  143. snprintf(SendAT, sizeof(SendAT), "AT+CLVL?\r\n");
  144. snprintf(WaitAT1, sizeof(WaitAT1), "+CLVL:");
  145. break;
  146. //MINI_GET_SIMSELECT
  147. case MINI_GET_SIMSELECT:
  148. SlwTrace(INF, "GetSIMSelect..",1);
  149. snprintf(SendAT, sizeof(SendAT), "AT+SIMCROSS?\r\n");
  150. snprintf(WaitAT1, sizeof(WaitAT1), "+SIMCROSS:");
  151. break;
  152. //newPara.Miclv
  153. case MINI_SET_MICLV:
  154. SlwTrace(INF, "SetMIClv..",1);
  155. //+CACCP: "07000b00" newPara.Miclv
  156. snprintf(SendAT, sizeof(SendAT), "AT+CACCP=2,1,6,\"%02x00%02x00\"\r\n",newPara.Miclv/16,newPara.Miclv%16);
  157. snprintf(WaitAT1, sizeof(WaitAT1), "+CACCP:");
  158. break;
  159. //AT+LSHTTSPARAM=3000,106,100 设置TTS 音量 语调 语速
  160. // +LSHTTSPARAM:3000,106,100
  161. case MINI_SET_TTSPARM:
  162. SlwTrace(INF, "SetTTSPARAM..",1);
  163. snprintf(SendAT, sizeof(SendAT), "AT+LSHTTSPARAM=3000,106,100\r\n");//32768
  164. snprintf(WaitAT1, sizeof(WaitAT1), "OK");
  165. break;
  166. //MINI_SET_GPSPARM
  167. case MINI_SET_GPSPARM:
  168. SlwTrace(INF, "Set_SET_GPSPARM..",1);
  169. snprintf(SendAT, sizeof(SendAT), "AT+GPS?\r\n");
  170. snprintf(WaitAT1, sizeof(WaitAT1), "+GPS:O");//+GPS:ON +GPS:OFF
  171. break;
  172. case MINI_CHEAK_HEADSET:
  173. SlwTrace(INF, "CHEAK_HEADSET..",1);
  174. snprintf(SendAT, sizeof(SendAT), "AT+HEADSET?\r\n");
  175. snprintf(WaitAT1, sizeof(WaitAT1), "+HEADSET:");//+GPS:ON
  176. break;
  177. }
  178. }
  179. short ModemInitAckHandler(unsigned char result){
  180. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  181. char buf[20];
  182. char *msg=(char *)pMsg->MsgData;
  183. short ret=0;
  184. static char FirstInitTTS=0;
  185. switch(initStatus){
  186. case MINI_WAT_START:
  187. if(result==1){
  188. SlwTrace(INF, "ModemStart...",1);
  189. ModemSendAt("ATE0\r\n");
  190. mInitSwitchStatus(MINI_POC_AUTHSET);
  191. }else ret=-1;
  192. break;
  193. case MINI_POC_AUTHSET:
  194. if(result==1){
  195. SlwTrace(INF, "POC-AuthOk--",1);
  196. PocAuthProcess(&msg[7]);
  197. }
  198. mInitSwitchStatus(MINI_GET_POC_VER);
  199. break;
  200. case MINI_GET_POC_VER:
  201. if(result!=1) {
  202. PocGetTypeCnt++;
  203. if(PocGetTypeCnt==1){
  204. mInitSwitchStatus(MINI_GET_POC_VER);//
  205. break;
  206. }
  207. else if(PocGetTypeCnt==2){
  208. hgs_poc_type=POC_NULL;
  209. SlwTrace(INF, "GetPocVer fail",1);
  210. }
  211. }
  212. else{
  213. if(PocGetTypeCnt==0){
  214. hgs_poc_type=POC_OWN;
  215. ModemSendAt("AT+POC=050000\r\n");
  216. }
  217. else if(PocGetTypeCnt==1){
  218. hgs_poc_type=POC_BND;
  219. ModemSendAt("AT+LSPA=1\r\n");
  220. }
  221. getPocVersion(msg,hgs_poc_type);
  222. }
  223. PocGetTypeCnt=0;
  224. mInitSwitchStatus(MINI_SET_TTSPARM);
  225. break;
  226. case MINI_SET_TTSPARM:
  227. if(result != 1) SlwTrace(INF, "SetTTSPARAM fail",1);
  228. else SlwTrace(INF, "SetTTSPARAM OK",1);
  229. // if(hgs_poc_type==POC_OWN)mInitSwitchStatus(MINI_CHEAK_HEADSET);//
  230. // else {
  231. // mInitSwitchStatus(MINI_GET_MODULE);
  232. // }
  233. mInitSwitchStatus(MINI_GET_MODULE);
  234. break;
  235. case MINI_SET_MICLV://目前未使用
  236. if(result != 1) SlwTrace(INF, "SET_MICLV fail",1);
  237. else SlwTrace(INF, "SET_MICLV OK",1);
  238. mInitSwitchStatus(MINI_CHEAK_HEADSET);
  239. break;
  240. case MINI_CHEAK_HEADSET:
  241. if(result != 1) SlwTrace(INF, "CHEAK_HEADSET fail",1);
  242. else{
  243. SlwTrace(INF, "CHEAK_HEADSET OK",1);
  244. if(msg[9]=='0'){
  245. sutPocStatus.HeadSetPtt=1;
  246. // ModemSendAt("AT+AUDCH=1,3\r\n");
  247. printf("耳机接入-----\r\n");
  248. }
  249. else if(msg[9]=='1'){
  250. ModemSendAt("AT+AUDCH=0,0\r\n");
  251. printf("耳机未接入----\r\n");
  252. }
  253. }
  254. mInitSwitchStatus(MINI_GET_MODULE);
  255. break;
  256. case MINI_GET_MODULE:
  257. if(result != 1) SlwTrace(INF, "GetModemModule fail",1);
  258. else getModemModule(msg);
  259. uTimerHardDly(100);
  260. HeadsetProcess(1);
  261. /***********************************/
  262. uTimerHardDly(50);
  263. ModemSendAt(FirmSperkr);
  264. uTimerHardDly(50);
  265. ModemSendAt(FirmSperkr2);
  266. mInitSwitchStatus(MINI_PLY_ICCID);
  267. break;
  268. case MINI_PLY_ICCID:
  269. if(result != 1) SlwTrace(INF, "GetICCID fail",1);
  270. else ModemGetICCID(msg);
  271. mInitSwitchStatus(MINI_GET_SIMSELECT);
  272. break;
  273. case MINI_GET_SIMSELECT:
  274. if(result != 1) SlwTrace(INF, "GetSIMSelect fail",1);
  275. else SIMSelect=atoi(&msg[10]);
  276. if(hgs_poc_type==POC_OWN)mInitSwitchStatus(MINI_SET_TONES);
  277. else mInitSwitchStatus(MINI_READ_SPKLV);
  278. break;
  279. case MINI_SET_TONES:
  280. if(result != 1) SlwTrace(INF, "SetTones fail",1);
  281. else SlwTrace(INF, "SetTones_Ok",1);
  282. mInitSwitchStatus(MINI_READ_SPKLV);
  283. break;
  284. case MINI_READ_SPKLV:
  285. //+CLVL:60
  286. if(result!=1) SlwTrace(INF, "ReadSpkLv fail",1);
  287. else{
  288. SetSpkLvProcess(2);
  289. if(newPara.VolumLv!=atoi(&msg[6])/10){
  290. snprintf(buf,sizeof(buf),"AT+CLVL=%d\r\n",newPara.VolumLv*10);//num
  291. printf("VolumLv=%d\r\n",newPara.VolumLv);
  292. ModemSendAt(buf);
  293. }
  294. SlwTrace(INF, "SetSPKlv OK",1);
  295. }
  296. TTSPlayTick=uSysTickGet()+500;//5S后 才播报TONE音
  297. if(hgs_poc_type==POC_BND){
  298. g_uiGpsStat=0;
  299. newPara.gpsTimeIndex=0;
  300. snprintf(buf,sizeof(buf),"AT+POC=ttsvol=%d\r\n",newPara.VolumLv);
  301. ModemSendAt(buf);
  302. SpeakerCtrl(1);
  303. if(newPara.KeySound==0)ModemSendAt("AT+POC=tonevol=0\r\n");
  304. else {
  305. //ModemSendAt("AT+POC=tonevol=%d\r\n",newPara.VolumLv);
  306. snprintf(buf,sizeof(buf),"AT+POC=tonevol=%d\r\n",newPara.VolumLv);
  307. ModemSendAt(buf);
  308. }
  309. mInitSwitchStatus(MINI_GET_CARD);
  310. }else {
  311. mInitSwitchStatus(MINI_SET_GPSPARM);
  312. }
  313. if(FirstInitTTS==0){
  314. SpeakTTSVoice();
  315. FirstInitTTS=1;
  316. }
  317. break;
  318. case MINI_SET_GPSPARM:
  319. if(result!=1) SlwTrace(INF, "GetGPSstatue fail",1);
  320. else {
  321. if(msg[6]=='N'){
  322. if(!g_uiGpsStat){
  323. ModemSendAt("AT+GPS=\"OFF\"\r\n");
  324. //AT+VIBCTRL
  325. ModemSendAt("AT+VIBCTRL=\"POWER\",\"OFF\"\r\n");
  326. printf("close GPS--%d\r\n",g_uiGpsStat);
  327. }
  328. }else{
  329. if(g_uiGpsStat){
  330. ModemSendAt("AT+GPS=\"ON\"\r\n");
  331. ModemSendAt("AT+VIBCTRL=\"POWER\",\"ON\"\r\n");
  332. printf("open GPS--%d\r\n",g_uiGpsStat);
  333. }
  334. }
  335. SlwTrace(INF, "Seting GPS",1);
  336. }
  337. if(g_uiGpsStat)ModemSendAt("AT+GPSANT=1\r\n");
  338. if(hgs_poc_type==POC_OWN)mInitSwitchStatus(MINI_GET_POC_CODE);
  339. else mInitSwitchStatus(MINI_GET_CARD);
  340. CardStatue=0x11;
  341. break;
  342. case MINI_GET_POC_CODE:
  343. if(result!=1) SlwTrace(INF, "GetPocCode fail",1);
  344. else getPocCode(msg);
  345. mInitSwitchStatus(MINI_GET_CARD);
  346. break;
  347. case MINI_GET_CARD:
  348. switch(ChekCardCnt){
  349. case 0:
  350. if(result != 1)CardStatue&=0x10;
  351. else {
  352. goto CARDREDY;
  353. }
  354. SIMSelect=!SIMSelect;
  355. snprintf(buf,sizeof(buf),"AT+SIMCROSS=%d\r\n",SIMSelect);
  356. ModemSendAt(buf);
  357. uTimerHardDly(100);
  358. ret=-3;
  359. ChekCardCnt=1;
  360. sutPocStatus.modemRstFlag=1;
  361. break;
  362. case 1:
  363. ChekCardCnt=0;
  364. if(result != 1){
  365. CardStatue&=0x01;
  366. ret=-2;
  367. break;
  368. }
  369. CARDREDY:
  370. SlwTrace(INF, "Card Ready",1);
  371. sutPocStatus.CardStatus=1;//卡准备好
  372. if(hgs_poc_type==POC_OWN){
  373. ModemSendAt("AT+POC=10000020\r\n");
  374. mInitSwitchStatus(MINI_POC_PARA);
  375. }
  376. else {
  377. ModemSendAt("AT+POC=open,1,1\r\n");
  378. ret=1;
  379. }
  380. break;
  381. }
  382. break;
  383. case MINI_POC_PARA:
  384. if(result != 1) SlwTrace(INF, "GetPocPara fail",1);
  385. else ModemSetPocPara(msg,pMsg->MsgLen);
  386. ModemApnConfig();
  387. //ModemSendAt("AT+ROUTE=0,1\r\n");//打开POClog
  388. ModemSendAt("AT+POC=030000\r\n");
  389. ret=1;
  390. break;
  391. }
  392. return ret;
  393. }
  394. PT_THREAD (ptModemInitTask(struct pt *pt))
  395. {
  396. static timer_t ptTimer;
  397. static unsigned char intCmd;
  398. static unsigned char status;
  399. static short i,t;
  400. short ret;
  401. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  402. PT_BEGIN(pt);
  403. while(1){
  404. M_RESTART:
  405. SlwTrace(INF,"ModemInit...",1);
  406. memset((unsigned char *)&sutPocStatus, 0, sizeof(SUT_POC_STATUS));
  407. SetLedIndicator(IndNoNet);
  408. sutPocStatus.modemRstFlag=0;
  409. modemInitReady=0;
  410. modemInitStatus=0;
  411. MsgQueueSet();
  412. MODEM_PWREN_HIGH;
  413. PTTimerStart(&pt_timerPool, &ptTimer, 200);
  414. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  415. MODEM_PWREN_LOW;
  416. PTTimerStart(&pt_timerPool, &ptTimer, 200);
  417. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  418. mInitSwitchStatus(MINI_WAT_START);
  419. modemInitReady=1;
  420. sutPocStatus.ModemPowerOn=1;
  421. SEND_WAIT_PRO:
  422. status=0;
  423. for(i=0;i<timeOut;i++){//共等60*500=30000ms
  424. ModemSendAt(SendAT);
  425. t=25;//以下等20*25=500ms
  426. while(t--){
  427. if(g_ucEnterGTNow!=0||USBSeletCt>1) goto INIT_DONE;//使得GT可以直接跳出初始化过程 //或者升级模块模式直接跳转
  428. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData)))){
  429. //printf("Ack:%s",pMsg->MsgData);调试
  430. if(0==ModemStrCmp((char *)pMsg->MsgData,"+POC:8B0002")) SpeakerEnable();//wjl
  431. else if(0==ModemStrCmp((char *)pMsg->MsgData,"+POC:8B0000")) SpeakerDisable();//wjl
  432. if(0==ModemStrCmp((char *)pMsg->MsgData,WaitAT1) ||
  433. 0==ModemStrCmp((char *)pMsg->MsgData,WaitAT2)){
  434. status=1;
  435. goto SEND_GET_RET;
  436. }
  437. }else{
  438. PTTimerStart(&pt_timerPool, &ptTimer, 2);
  439. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  440. }
  441. }
  442. }
  443. SEND_GET_RET:
  444. ret=ModemInitAckHandler(status);
  445. //ret=-1;
  446. if(ret ==0) goto SEND_WAIT_PRO;
  447. else if(ret<0){//模块启动失败/卡不在
  448. if(ret==-1){
  449. SlwTrace(INF, "ModemInitTimeout GT Mode",1);
  450. EnterGTMode();
  451. }else if(ret==-2){
  452. SlwTrace(INF, "insert card error----",1);
  453. sutPocStatus.loginResult=4;
  454. }
  455. }
  456. INIT_DONE:
  457. //初始化完成
  458. modemInitStatus=1;//可以消耗模块消息队列了
  459. g_ucModemTaskEn=1;
  460. while(1){
  461. if(sutPocStatus.modemRstFlag!=0){
  462. printf("reset modem----\r\n");
  463. MODEM_RESET_HIGH;
  464. PTTimerStart(&pt_timerPool, &ptTimer, 300);
  465. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  466. MODEM_RESET_LOW;
  467. goto M_RESTART;
  468. }
  469. //sutPocStatus.ModemInactiveCt=0; /****************V113守护进程BUG********/
  470. PTTimerStart(&pt_timerPool, &ptTimer, 100);//100
  471. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  472. }
  473. }
  474. PT_END(pt);
  475. }
  476. void InfoTick(void){
  477. static unsigned int tick;
  478. if(g_ucEnterGTNow) return;
  479. if(uTimerExpired(&tick)){
  480. uTimerStart(&tick, 500);
  481. printf("Info:Auth[%d],GT[%d],MI[%d],UI[%d] \r\n",sutGpsInfo.isGpsAuthOk,g_ucEnterGTNow,modemInitStatus,sutUIstatus.Status);
  482. }
  483. }
  484. static void AtHandle(char *msg);
  485. void ModemATProcess(void){
  486. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  487. if(modemInitStatus==0) return;
  488. while(1){
  489. pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData));
  490. if(pMsg->MsgLen>0){
  491. if(g_ucEnterGTNow!=0||USBSeletCt>1) continue;//如果进入GT模式,不需要处理模块消息了
  492. SlwTrace(INF, (char *)pMsg->MsgData,0);
  493. sutPocStatus.ModemInactiveCt=0;
  494. if(pMsg->MsgData[0]=='+' || pMsg->MsgData[0] == '^'){
  495. if(1 == PocHandle((char *)pMsg->MsgData)) continue;
  496. AtHandle((char *)pMsg->MsgData);
  497. }else if(pMsg->MsgData[0]=='$'&&pMsg->MsgData[3]=='R'&&pMsg->MsgData[5]=='C'){
  498. process_gps_data((char*)&pMsg->MsgData[7],pMsg->MsgLen);
  499. sutGpsInfo.isGpsWork=1;
  500. }
  501. continue;
  502. }else if(pMsg->MsgLen<0){
  503. SlwTrace(INF, "QueueF1",1);
  504. continue;
  505. }
  506. break;
  507. }
  508. }
  509. void ModemLedCtl(void){
  510. if(g_ucModemTaskEn==0||g_ucEnterGTNow!=0) return;
  511. if(0==sutPocStatus.Logined)SetLedIndicator(IndNoNet);
  512. else if(sutPocStatus.Speaker>0)SetLedIndicator(IndRX);
  513. else if(sutPocStatus.Mic>0 )SetLedIndicator(IndTX);
  514. else SetLedIndicator(IndStandby);
  515. }
  516. static void AtHandle(char *pMsg)
  517. {
  518. int csq;
  519. short targetIndex;
  520. unsigned char tempSocket,i,temp;
  521. unsigned short tempLen;
  522. char buf[80]="\r\n";
  523. char bufTemp[3];
  524. char buf3[40];
  525. static char Timerequest=0;
  526. STATUE ipStatus;
  527. if(0==ModemStrCmp(pMsg,"^SYSINFO:")){
  528. if(pMsg[15]!=','){
  529. netshowvalue=atoi(&pMsg[15]);
  530. }else{
  531. netshowvalue=atoi(&pMsg[16]);
  532. }
  533. }else if(0==ModemStrCmp(pMsg,"+CSQ:"))
  534. {
  535. g_iCSQ=atoi(&pMsg[6]);
  536. }else if(0==ModemStrCmp(pMsg,"+POC_PPP:")){
  537. if(pMsg[9]=='1') netPPP=OPEN;
  538. else netPPP=CLOSE;
  539. if(0==Timerequest&&netPPP==OPEN){
  540. Timerequest=1;
  541. ModemSendAt("AT+CCLK?\r\n");
  542. }
  543. }else if(0==ModemStrCmp(pMsg,"+POC:npong,"))
  544. {
  545. if(pMsg[11]=='1'){
  546. netPPP=OPEN;
  547. }
  548. else netPPP=CLOSE;
  549. if(0==Timerequest&&netPPP==OPEN){
  550. Timerequest=1;
  551. ModemSendAt("AT+CCLK?\r\n");
  552. }
  553. }
  554. else if(0==ModemStrCmp(pMsg,"+TCPSTATUS:")){
  555. tcpSocketStatusUpdate(pMsg[11],pMsg[13],0);
  556. }else if(0==ModemStrCmp(pMsg,"+TCPRECV:")){//+TCPRECV:0,2,31
  557. if(-1 != (targetIndex=FindTargetIndex(pMsg, '\r', ":", 1,1))){
  558. tempSocket = atoi(&pMsg[targetIndex]);//找到socket
  559. if(-1 != (targetIndex=FindTargetIndex(pMsg, '\r', ",",1,1))){
  560. tempLen = atoi(&pMsg[targetIndex]);
  561. if(-1 != (targetIndex=FindTargetIndex(pMsg, '\r', ",",1,2))){
  562. tcpSocketRecv(tempSocket, &pMsg[targetIndex], tempLen);
  563. }
  564. }
  565. }
  566. }else if(0==ModemStrCmp(pMsg,"+TCPOPEN:")){
  567. tcpSocketStatusUpdate(pMsg[9],pMsg[11],0);
  568. }else if(0==ModemStrCmp(pMsg, "+TCPCLOSE:")){//主动关掉或者服务器关掉都是这样
  569. tcpSocketStatusUpdate(pMsg[10],NULL,1);
  570. }else if(0==ModemStrCmp(pMsg, "+CCLK:"))
  571. {
  572. ModemGetTime(pMsg);
  573. }else if(0==ModemStrCmp(pMsg, "^MODE:"))
  574. {//^MODE: 9 与下面位置不一,模块问题
  575. //^MODE:2 与上面位置不一,模块问题
  576. if(pMsg[6] == ' ') bufTemp[0]=pMsg[7];
  577. else bufTemp[0]=pMsg[6];
  578. snprintf(buf, sizeof(buf), "[Mode %c]", bufTemp[0]);
  579. switch(bufTemp[0])
  580. {
  581. case 0x30:strcat(buf, "No server");break;
  582. case 0x32:strcat(buf, "CDMA Mode");break;
  583. case 0x33:strcat(buf, "GSM");break;
  584. case 0x34:strcat(buf, "TD-SCDMA/EVDO");break;
  585. case 0x35:strcat(buf, "WCDMA");break;
  586. case 0x39:strcat(buf, "LTE");break;
  587. default:strcat(buf, "Unknow");break;
  588. }
  589. SlwTrace(INF, buf, 1);
  590. }else if(0==ModemStrCmp(pMsg, "+POC:START"))
  591. {
  592. sutPocStatus.modemRstFlag=1;
  593. sutPocStatus.ModemInactiveCt=0;//当模块重启后重新计数串口通讯异常计数器
  594. }
  595. else if(0==ModemStrCmp(pMsg, "+GGIP:"))
  596. { //GSPIP返回
  597. //+GPIP:183.131.13.10
  598. if(newPara.serList.defaultuse==SER_JIQUN||newPara.serList.defaultuse==SER_IP)chekPipGip(pMsg,1);
  599. //strcpy(gSocket.socketList[0].Ip,showGIP);//
  600. }else if(0==ModemStrCmp(pMsg, "+GPIP:"))
  601. {
  602. if(newPara.serList.defaultuse==SER_JIQUN||newPara.serList.defaultuse==SER_IP)chekPipGip(pMsg,0);
  603. }else if(0==ModemStrCmp(pMsg, "+FOTA:")){
  604. FotaStatusProcess(pMsg+6);
  605. uTimerStart(&fotaTick,10);
  606. }else if(0==ModemStrCmp(pMsg, "+POC:WAKEUP")){
  607. enableDataSend();
  608. }else if(0==ModemStrCmp(pMsg, "+UDP:")){
  609. GetPwrMode(pMsg+5);
  610. }else if(0==ModemStrCmp(pMsg, "+AUDCH"))//
  611. {
  612. }else if(0==ModemStrCmp(pMsg,"+CTEC:"))
  613. {
  614. tempnetshowvalue=atoi(&pMsg[7]);
  615. if(newPara.netMode!=tempnetshowvalue){
  616. snprintf(buf,sizeof(buf),"AT+CTEC=%d,%d\r\n",tempnetshowvalue,newPara.netMode);
  617. ModemSendAt(buf);
  618. }
  619. }else if(0==ModemStrCmp(pMsg,"+COPS")){
  620. //netshowvalue=atoi(&pMsg[FindContentByChar( pMsg,',',3)]);
  621. netshowvalue=atoi(FindContentByChar(pMsg,',',3,buf));
  622. }else if(0==ModemStrCmp(pMsg,"+HEADSET:"))
  623. {
  624. //InternalHeadSet(atoi(&pMsg[9]));
  625. }
  626. }
  627. void InternalHeadSet(char type)
  628. {
  629. switch(type)
  630. {
  631. case 0:
  632. sutPocStatus.HeadSetPtt=1;
  633. //ModemSendAt("AT+AUDCH=1,3\r\n");
  634. break;
  635. case 1:
  636. sutPocStatus.HeadSetPtt=0;
  637. ModemSendAt("AT+AUDCH=0,0\r\n");
  638. break;
  639. case 2:
  640. ModemSendAt("AT+POC=0B0000\r\n");
  641. break;
  642. case 3:
  643. ModemSendAt("AT+POC=0C0000\r\n");
  644. break;
  645. }
  646. }
  647. char *FindContentByChar( char *src,char c, char index,char *dest)
  648. {
  649. char i;
  650. char j=0;
  651. char *p=dest;
  652. for(i=0;i<strlen(src);i++)
  653. {
  654. if(src[i]==c)j++;
  655. if(j==index){
  656. p=&src[i+1];
  657. return p;
  658. }
  659. }
  660. }
  661. void chekPipGip(char *src,char type)
  662. {
  663. char buf[40];
  664. char *p;
  665. p=src+6;
  666. if(!type)snprintf(buf,sizeof(buf),"+GPIP:%s\r\n",showPIP);
  667. else snprintf(buf,sizeof(buf),"+GGIP:%s\r\n",showGIP);
  668. if(strlen(src)<9||(0==ModemStrCmp(src, "+GGIP:0.0.0.0"))||(0==strcmp(src,buf))||(0==ModemStrCmp(src, "+GPIP:0.0.0.0")))return ;
  669. if(!type){
  670. memcpy(showPIP,p,strlen(p)-2);
  671. showPIP[strlen(p)-2]=0;
  672. printf("get new PIP====%s\r\n",showPIP);
  673. }else{
  674. memcpy(showGIP,p,strlen(p)-2);
  675. showGIP[strlen(p)-2]=0;
  676. printf("get new GIP====%s\r\n",showGIP);
  677. strcpy(gSocket.socketList[0].Ip,showGIP);
  678. }
  679. }
  680. int CodecFileInit(void)
  681. {
  682. int len;
  683. char tempData[400];
  684. char CodecFileIndex=0;
  685. int tempLen,i;
  686. char *p=NULL;
  687. char tempbuf[40];
  688. unsigned short PreRead;
  689. int StartAddr=0;
  690. CodecFileIndex=GetFileIndex("Audio.ini");
  691. if(CodecFileIndex == -1)
  692. {
  693. printf("No Audio.ini file\r\n");
  694. return -1;
  695. }
  696. len=GetFileLen(CodecFileIndex);
  697. printf("Audio.ini len===%d\r\n",len);
  698. if(len==0)
  699. {
  700. printf("Audio.ini empty\r\n");
  701. return-2;
  702. }
  703. while(len==0){
  704. if(len>400)PreRead=400;
  705. else PreRead=len;
  706. tempLen=ReadFileData(CodecFileIndex,StartAddr,PreRead,(u8*)tempData);
  707. len-=PreRead;
  708. StartAddr+=PreRead;
  709. snprintf(tempbuf,sizeof(tempbuf),"AT+CAIET=0,0,%d,%d,\"",StartAddr,PreRead);
  710. ModemSendAt(tempbuf);
  711. ModemSendData(tempData,PreRead);
  712. ModemSendAt("\"\r\n");
  713. }
  714. return 0;
  715. }