ModemTask.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /********************************************************************************
  2. * File Name: ModemTask.c
  3. * Function Describe: 完成串口与Modem的通讯
  4. * Explain:
  5. * Writer: ShiLiangWen
  6. * Date: 2015-8-2
  7. *******************************************************************************/
  8. #define THIS_FILE_ID 17
  9. /*******************************************************************************/
  10. #include "includes.h"
  11. OS_TID idModemTask=0;
  12. U64 stkModemTask[MODEM_TASK_STK_SIZE];
  13. OS_TID idModemUartTask=0;
  14. U64 stkModemUartTask[MODEM_UART_TASK_STK_SIZE];
  15. OS_SEM ModemUartSem;
  16. unsigned char g_ucModemTaskEn=0;
  17. unsigned char g_ucQuitModemInitNow=0;//此值设置时,无论公网处于何种操作,马上退出,主要针对ModemTask进入WHILE前的判断
  18. unsigned short g_usModemProtectEn=0;
  19. FEEDBACK_DEF sutFeed;
  20. SUPPORT_TYPE support_type=Un_Known;
  21. YUNYINGSHANG_DEF thisYunYingShang=CHINA_NONE;
  22. int WaitModemReady(void);
  23. void WarnTTSReport(void);
  24. /*******************************************************************
  25. *ModemUartTask
  26. ********************************************************************/
  27. __task void ModemUartTask(void)
  28. {
  29. os_sem_init (&ModemUartSem, 0);
  30. while(1){
  31. os_sem_wait (&ModemUartSem, 0xffff);
  32. Uart2RecvProcess();
  33. }
  34. }
  35. void SoSDetected(void)
  36. {
  37. static char tCnt=0;
  38. static unsigned int TickCnt=0;
  39. if(sutPocStatus.SOS_Flag==1)
  40. {
  41. if(os_time_get() < TickCnt) return;
  42. TickCnt=os_time_get()+15;
  43. if(++tCnt <=2)
  44. {
  45. SpeakerEnable();
  46. SetBeep(500,10);
  47. }
  48. else {
  49. sutPocStatus.SOS_Flag=0;
  50. tCnt=0;
  51. TickCnt=0;
  52. }
  53. }
  54. }
  55. //测试定位时间
  56. unsigned int locationTime=0;
  57. unsigned char locationflag=0;
  58. /*******************************************************************
  59. *ModemTask
  60. ********************************************************************/
  61. __task void ModemTask(void)
  62. {
  63. #ifdef SLW_DEBUG
  64. unsigned short MsgBoxCheck;
  65. unsigned short MinMsgBoxCheck=20;
  66. #endif
  67. static unsigned int sucCt=0;
  68. unsigned char i;
  69. unsigned short susCt=0;
  70. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  71. char buf[40];
  72. g_ucModemTaskEn=1;
  73. SlwTrace(INF,"Poc Task start!",1);
  74. //GPS相关初始化
  75. GpsTaskTick(1);
  76. g_ucModemSentTcpCt=0;
  77. //TSGpsDataInit();
  78. sutGpsStatus.PPPStatus=INVALID;
  79. sutGpsStatus.IPStatus=INVALID;
  80. sutGpsStatus.CheckCnt=0;
  81. SlwTrace(INF,"Modem Task start!",1);
  82. MODEM_RESTART:
  83. SlwTrace(INF,"ModemInit...",1);
  84. SetLedIndicator(IndNoNet);
  85. PWR_EN_HIGH;
  86. sutPocStatus.modemRstFlag=0;
  87. sutPocStatus.loginResult=0;
  88. sutPocStatus.Logined=0;
  89. modemInitReady=0;
  90. g_iPocVer=0;
  91. sutGpsInfo.locationTime=os_time_get();//
  92. //soc ID替代IMEI
  93. if(GetUniStringByID(DEV_HARDID)==1){
  94. snprintf(buf, sizeof(buf), "[01]hardID:%s", DEV_HARDID);
  95. SlwTrace(INF, buf,1);
  96. }
  97. //1、模块初始化
  98. if(ModemInit())
  99. {//成功
  100. }else
  101. {//模块初始化失败,进入GT模式,为了升级模块
  102. bootFlag=1;
  103. PWR_EN_LOW;
  104. SlwTrace(INF,"[01]Failed\r\nEnter GT Mode!",1);
  105. EnterGTMode();
  106. while(1)
  107. {
  108. sutPocStatus.ModemInactiveCt=0;
  109. os_dly_wait(100);
  110. }
  111. }
  112. if(0!=ModemLCCCheck()){
  113. goto MODEM_RESTART;
  114. }
  115. if(GPIO_ReadInputDataBit(ONOFF_CK_PORT,ONOFF_CK_PIN)==1)
  116. modemPwrOffNow=1;
  117. else PWR_EN_LOW;
  118. modemInitReady=1;
  119. //暂停POC
  120. ModemSendAT("AT+POC=050000\r\n");
  121. //2??????
  122. ModemSendAT("ATE0\r\n");
  123. SlwTrace(INF, "[02]ATE0 OK",1);
  124. os_dly_wait(250);
  125. //3、获取模块版本
  126. ModemInfo();
  127. //4、POC version check
  128. ModemPocVersionCheck();CheckPocType();ModemOwnPocSet();
  129. //5、查询IMEI
  130. ModemGetPocCodeType();
  131. //6、配置TTS语音速度
  132. ModemSetSpeed();os_dly_wait(50);
  133. //7、配置音量
  134. VolumeSet();
  135. /*****************************/
  136. VolumeSetSpk();
  137. VolumeSetMIC();
  138. CodecFileInit();
  139. SpeakTTSVoice();//定制化开机播报语
  140. //8、检测卡是否存在
  141. if(0==ModemCheckUIM())
  142. {//卡不在位,循环播报请插卡
  143. sutPocStatus.loginResult=4;
  144. susCt=3500;
  145. //SetPowerEn(0);
  146. GPSInit();
  147. while(1)
  148. {
  149. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  150. {
  151. continue;
  152. }
  153. else os_dly_wait(1);
  154. sutPocStatus.ModemInactiveCt=0;
  155. if(0==g_ucModemTaskEn)continue;
  156. //GPS Uart消息处理
  157. if(g_usUart3RecvLen){
  158. process_nema((char *)RxBuffer3);
  159. g_usUart3RecvLen=0;
  160. }
  161. }
  162. }else SlwTrace(INF, "[08]Card ready",1);
  163. //9、查询CCID
  164. ModemGetCCID();ResetNetConfi();
  165. //10、检查并重新设置POC参数
  166. if(ModemCheckPocParam()) SlwTrace(INF,"[10]Rst_POCPara",1);
  167. else SlwTrace(INF, "[10]POC still",1);
  168. sutPocStatus.ModemPowerOn=1;
  169. //SetPowerEn(0);
  170. //11、设置APN
  171. ModemApnConfig();
  172. //12、集群功能初始化数据
  173. SlwTrace(INF, "[12]HigosSerInit",1);
  174. //HigosInit();
  175. //ConolyInit();
  176. //13、GPS配置
  177. GPSInit();
  178. GpsTimeUpdate();
  179. //14、设置成员获取简单模式
  180. SetModemPocSimpleMode();
  181. SlwTrace(INF, "ModemLoopStart",1);
  182. //15、检查并设置POCFOTA域名
  183. if(ModemCheckFotaDomain()) SlwTrace(INF,"[15]Rst_FotaDomain",1);
  184. else SlwTrace(INF, "[15]FotaDomain still",1);
  185. //启动POC
  186. ModemSendAT("AT+POC=030000\r\n");
  187. while(1)
  188. {
  189. if(0==g_ucModemTaskEn)
  190. {
  191. pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData));
  192. if(pMsg->MsgLen > 0)
  193. {
  194. SlwTrace(INF,(char *)pMsg->MsgData,0);
  195. AtHandle(pMsg->MsgData);
  196. continue;
  197. }else if(pMsg->MsgLen < 0)
  198. {
  199. SlwTrace(INF, "QueueF1",1);
  200. continue;
  201. }
  202. else os_dly_wait(1);
  203. #if(USE_CONFIG_FUN==1)
  204. ConfigCtrHandle();
  205. #endif
  206. continue;
  207. }
  208. pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData));
  209. if(pMsg->MsgLen > 0)
  210. {
  211. if(pMsg->MsgData[0] == '\r' && pMsg->MsgData[1] == '\n') continue;
  212. #if ENABL_FOGA_BACK_DATA_PRINT
  213. if(Fota_Rcv_Pri_Flag)
  214. #endif
  215. SlwTrace(INF,(char *)pMsg->MsgData,0);
  216. FotaIap_Handle((char *)pMsg->MsgData);
  217. sutPocStatus.ModemInactiveCt=0;
  218. if(pMsg->MsgData[0]=='+' || pMsg->MsgData[0] == '^')
  219. {
  220. if(1 == PocHandle((char *)pMsg->MsgData)) continue;
  221. AtHandle((char *)pMsg->MsgData);
  222. }
  223. continue;
  224. }else if(pMsg->MsgLen < 0)
  225. {
  226. SlwTrace(INF, "QueueF1",1);
  227. continue;
  228. }
  229. else os_dly_wait(1);
  230. //---指示灯设置---
  231. if(0==sutPocStatus.Logined)SetLedIndicator(IndNoNet);
  232. else if(sutPocStatus.Speaker>0)SetLedIndicator(IndRX);
  233. else if(sutPocStatus.Mic>0 && sutPocStatus.PPTpress>0)SetLedIndicator(IndTX);
  234. else SetLedIndicator(IndStandby);
  235. //以下控制GPS上传
  236. GpsTaskTick(0);//GPS功能打开。
  237. if(sutGpsStatus.PPPStatus==OPEN)
  238. SMSHandle();
  239. SoSDetected();
  240. WarnTTSReport();
  241. if(sutPocStatus.modemRstFlag !=0) goto MODEM_RESTART;
  242. if(os_time_get() < sucCt) continue;
  243. sucCt = os_time_get()+100;//
  244. AtQuery();
  245. }
  246. }
  247. void WarnTTSReport(void)
  248. {
  249. static unsigned char cnt=0;
  250. if(sutPocStatus.FirstLogined==0) return;
  251. if(sutPocStatus.Logined==1)
  252. {
  253. sutPocStatus.reportTimeCnt1=0;
  254. sutPocStatus.reportTimeCnt2=0;
  255. return;
  256. }
  257. if(++cnt< 99) return;
  258. cnt=0;
  259. if(sutPocStatus.reportTimeCnt1 < 250) sutPocStatus.reportTimeCnt1++;
  260. if(sutPocStatus.reportTimeCnt2 < 250) sutPocStatus.reportTimeCnt2++;
  261. }
  262. void Modem_Stopinit()
  263. {
  264. PWR_EN_LOW;
  265. SlwTrace(INF, "go GT_Mode\r\n",1);
  266. EnterGTMode();
  267. while(1)
  268. {
  269. sutPocStatus.ModemInactiveCt = 0;
  270. os_dly_wait(100);
  271. }
  272. }
  273. /*******************************************************************************/