ModemTask.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. YUNYINGSHANG_DEF thisYunYingShang=CHINA_NONE;
  18. void WarnTTSReport(void);
  19. /*******************************************************************
  20. *ModemUartTask
  21. ********************************************************************/
  22. __task void ModemUartTask(void)
  23. {
  24. os_sem_init (&ModemUartSem, 0);
  25. while(1)
  26. {
  27. os_sem_wait (&ModemUartSem, 0xffff);
  28. Uart2RecvProcess();
  29. }
  30. }
  31. /*******************************************************************
  32. *ModemTask
  33. ********************************************************************/
  34. __task void ModemTask(void)
  35. {
  36. unsigned char i;
  37. unsigned short susCt=0;
  38. static unsigned int Second2Cnt=0;
  39. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  40. char buf[40];
  41. g_ucModemTaskEn=1;
  42. SlwTrace(INF,"Poc Task start!",1);
  43. //GPS相关初始化
  44. GpsTaskTick(1);
  45. g_ucModemSentTcpCt=0;
  46. TSGpsDataInit();
  47. sutGpsStatus.PPPStatus=INVALID;
  48. sutGpsStatus.IPStatus=INVALID;
  49. sutGpsStatus.CheckCnt=0;
  50. snprintf(buf, sizeof(buf), "[01]hardID:%s", sutNewSegmentPara.HARDID);
  51. SlwTrace(INF, buf,1);
  52. SlwTrace(INF,"Modem Task start!",1);
  53. SlwTrace(INF,"ModemInit...",1);
  54. MODEM_RESTART:
  55. modemInitReady=0;
  56. PWR_EN_HIGH;
  57. SetLedIndicator(IndNoNet);
  58. memset((unsigned char *)&sutPocStatus,0,sizeof(SUT_POC_STATUS));
  59. //1、模块初始化:通过能否检测到MEID
  60. if(ModemInit())
  61. {//成功
  62. //sprintf(buf, "[01]IMEI:%s", sutProductPara.IMEI);
  63. SlwTrace(INF, buf,1);
  64. }else
  65. {//模块初始化失败,进入GT模式,为了升级模块
  66. PWR_EN_LOW;
  67. SlwTrace(INF,"[01]Failed\r\nEnter GT Mode!",1);
  68. // SlwTrace(INF,"GT+TM:OK",1);//进入GT+TM
  69. // ComSelect(COM_SEL_MODEM); //
  70. EnterGTMode();
  71. while(1)
  72. {
  73. sutPocStatus.ModemInactiveCt=0;
  74. os_dly_wait(100);
  75. }
  76. }
  77. if(GPIO_ReadInputDataBit(ONOFF_CK_PORT,ONOFF_CK_PIN)==1)
  78. modemPwrOffNow=1;
  79. else PWR_EN_LOW;
  80. modemInitReady=1;
  81. //2、关闭回显示
  82. ModemSendAT("ATE0\r\n");
  83. SlwTrace(INF, "[02]ATE0 OK",1);
  84. //3、获取模块版本
  85. ModemInfo();
  86. //4、POC version check
  87. ModemPocVersionCheck();
  88. //5、查询IMEI
  89. // if(ModemGetIMEI())
  90. // {
  91. // sprintf(buf, "[05]IMEI:%s", sutProductPara.IMEI);
  92. // SlwTrace(INF, buf,1);
  93. // }else SlwTrace(INF, "[05]IMEI:Failed",1);
  94. //6、配置TTS语音速度
  95. ModemSetSpeed();
  96. //7、配置音量
  97. VolumeSet();
  98. //8、检测卡是否存在
  99. if(0==ModemCheckUIM())
  100. {//卡不在位,循环播报请插卡
  101. susCt=3500;
  102. GPSRestart();
  103. while(1)
  104. {
  105. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  106. {
  107. continue;
  108. }
  109. else os_dly_wait(1);
  110. if(g_usRx3Len>0)
  111. {
  112. process_nema((char *)RxBuffer3);
  113. g_usRx3Len=0;
  114. }
  115. sutPocStatus.ModemInactiveCt=0;
  116. if(0==g_ucModemTaskEn)continue;
  117. if(++susCt>=1000)susCt=0;
  118. else continue;
  119. MeSpeak(ENCODE_UNICODE,"F78BD2636153",0);
  120. //os_dly_wait(200);
  121. SpeakerDisable();
  122. SlwTrace(INF,"[08]No UIM Card!",1);
  123. }
  124. }else SlwTrace(INF, "[08]Card ready",1);
  125. //9、查询CCID
  126. ModemGetCCID();
  127. //10、检查并重新设置POC参数
  128. if(ModemCheckPocParam()) SlwTrace(INF,"[10]Rst_POCPara",1);
  129. else SlwTrace(INF, "[10]POC still",1);
  130. //11、设置APN
  131. ModemApnConfig();
  132. //12、集群功能初始化数据
  133. SlwTrace(INF, "[12]HigosSerInit",1);
  134. HigosInit();
  135. //12、GPS配置
  136. GPSRestart();
  137. sutPocStatus.ModemPowerOn=1;
  138. SlwTrace(INF, "ModemLoopStart",1);
  139. while(1)
  140. {
  141. if(0==g_ucModemTaskEn)
  142. {
  143. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  144. {
  145. SlwTrace(INF,(char *)pMsg->MsgData,0);
  146. if(0==ModemStrCmp(pMsg->MsgData,"^MSG:Quit")){
  147. SetLedIndicator(IndReboot);//红灯闪表示升级完成(无论成功与否),用户需要重启设备
  148. }
  149. #if(USE_CONFIG_FUN==1)
  150. SlwTrace(INF,(char *)pMsg->MsgData,0);
  151. AtHandle(pMsg->MsgData);
  152. continue;
  153. #endif
  154. }else os_dly_wait(1);
  155. #if(USE_CONFIG_FUN==1)
  156. ConfigCtrHandle();
  157. #endif
  158. continue;
  159. }
  160. //Modem Uart消息处理,等待1个系统tick, 大约等待10ms
  161. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  162. {
  163. if(pMsg->MsgData[0]=='+' || pMsg->MsgData[0] == '$')
  164. {
  165. sutPocStatus.ModemInactiveCt=0;
  166. SlwTrace(INF,(char *)pMsg->MsgData,0);
  167. }else{
  168. continue;
  169. }
  170. if(1 == PocHandle((char *)pMsg->MsgData)) continue;
  171. AtHandle((char *)pMsg->MsgData);
  172. continue;
  173. }else os_dly_wait(1);
  174. //---指示灯设置---
  175. if(0==sutPocStatus.Logined)SetLedIndicator(IndNoNet);
  176. else if(sutPocStatus.Speaker>0)SetLedIndicator(IndRX);
  177. else if(sutPocStatus.Mic>0 && sutPocStatus.PPTpress>0)SetLedIndicator(IndTX);
  178. else SetLedIndicator(IndStandby);
  179. //以下控制GPS上传
  180. GpsTaskTick(0);
  181. if(sutGpsStatus.PPPStatus==OPEN)
  182. HigosTick();
  183. SMSHandle();
  184. WarnTTSReport();
  185. if(sutPocStatus.modemRstFlag !=0) goto MODEM_RESTART;
  186. if(os_time_get() < Second2Cnt) continue;
  187. Second2Cnt = os_time_get() + 300;
  188. ModemSendAT("AT+MODODREX?\r\n");
  189. os_dly_wait(1);
  190. ModemSendAT("AT+LCTMOBAPREF?\r\n");
  191. }
  192. }
  193. void WarnTTSReport(void)
  194. {
  195. static unsigned int cnt=0;
  196. if(sutPocStatus.FirstLogined==0) return;
  197. if(sutPocStatus.Logined==1)
  198. {
  199. sutPocStatus.reportTimeCnt1=0;
  200. sutPocStatus.reportTimeCnt2=0;
  201. return;
  202. }
  203. if(os_time_get() < cnt) return;
  204. cnt=os_time_get()+100;
  205. if(sutPocStatus.reportTimeCnt1 < 250) sutPocStatus.reportTimeCnt1++;
  206. if(sutPocStatus.reportTimeCnt2 < 250) sutPocStatus.reportTimeCnt2++;
  207. }
  208. void Modem_Stopinit()
  209. {
  210. PWR_EN_LOW;
  211. SlwTrace(INF, "go GT_Mode\r\n",1);
  212. EnterGTMode();
  213. while(1)
  214. {
  215. sutPocStatus.ModemInactiveCt = 0;
  216. os_dly_wait(100);
  217. }
  218. }
  219. /*******************************************************************************/