ModemTask.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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_uGtTaskEn=0; //进入写号模式
  18. unsigned char g_uGtFactory=0;
  19. unsigned char g_ucQuitModemInitNow=0;//此值设置时,无论公网处于何种操作,马上退出,主要针对ModemTask进入WHILE前的判断
  20. FEEDBACK_DEF sutFeed;
  21. SUPPORT_TYPE support_type=Un_Known;
  22. Modem_TYPE Modem_type=Un_KnownModem;
  23. YUNYINGSHANG_DEF thisYunYingShang=CHINA_NONE;
  24. int WaitModemReady(void);
  25. /*******************************************************************
  26. *ModemUartTask
  27. ********************************************************************/
  28. __task void ModemUartTask(void)
  29. {
  30. os_sem_init (&ModemUartSem, 0);
  31. while(1){
  32. os_sem_wait (&ModemUartSem, 0xffff);
  33. Uart2RecvProcess();
  34. }
  35. }
  36. /*******************************************************************
  37. *ModemTask
  38. ********************************************************************/
  39. __task void ModemTask(void)
  40. {
  41. static unsigned char sucPocLostTimeoutCount=0;//
  42. static unsigned char sucModemInactiveCount=0;
  43. RCC_ClocksTypeDef User_Rcc_Clock;
  44. #ifdef SLW_DEBUG
  45. unsigned short MsgBoxCheck;
  46. unsigned short MinMsgBoxCheck=20;
  47. #endif
  48. static unsigned int sucCt=0;
  49. unsigned char i;
  50. unsigned short susCt=0;
  51. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  52. char PrintfBuf[20];
  53. g_ucModemTaskEn=1;
  54. SlwTrace(INF,"Poc Task start!",1);
  55. //GPS相关初始化
  56. GpsTaskTick(1);
  57. g_ucModemSentTcpCt=0;
  58. TSGpsDataInit();
  59. sutGpsStatus.PPPStatus=INVALID;
  60. sutGpsStatus.IPStatus=INVALID;
  61. sutGpsStatus.CheckCnt=0;
  62. SlwTrace(INF,"Modem Task start!",1);
  63. EnterGTProcess();/*************M20检测写号*********************/
  64. GtFactory_XIEHAO(0); //写号死等
  65. MODEM_RESTART:
  66. SlwTrace(INF,"ModemInit...",1);
  67. sutPocStatus.modemRstFlag=0;
  68. sutPocStatus.ModemInactiveCt=0;//
  69. sutPocStatus.loginResult=0;
  70. modemInitReady=0;
  71. PWR_EN_HIGH;
  72. USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); //这个中断开过早,系统会崩
  73. printf("\r\n%s_V%d.%d Start...\r\n",sutProductPara.ProductName,sutProductPara.ProductVersion,INTER_VER);
  74. os_dly_wait(100);//gps会受到模块刚开机的干扰,而定位变差
  75. sutPocStatus.Prepare=1;
  76. //
  77. //1、模块初始
  78. if(ModemInit())
  79. {//成功
  80. SlwTrace(INF,"[01] Modem Init OK",1);
  81. }else
  82. {
  83. //模块初始化失败,进入GT模式,为了升级模块
  84. bootFlag=1;
  85. PWR_EN_HIGH;
  86. SlwTrace(INF,"[01]Failed\r\nEnter GT Mode!",1);
  87. EnterGTMode();
  88. IWDG_ReloadCounter();
  89. while(1)
  90. {
  91. sutPocStatus.ModemInactiveCt=0;
  92. os_dly_wait(100);
  93. }
  94. }
  95. SetLedIndicator(IndNoNet);
  96. GtFactory_XIEHAO(1);
  97. RCC_GetClocksFreq(&User_Rcc_Clock);
  98. snprintf(PrintfBuf,sizeof(PrintfBuf),"Clock===%d\r\n",User_Rcc_Clock.SYSCLK_Frequency);
  99. SlwTrace(INF,PrintfBuf,1);
  100. modemInitReady=1;
  101. if(WaitPocInit())goto MODEM_RESTART;
  102. SpeakerEnable();
  103. GetPocVer();
  104. GetModemVer();
  105. VolumeSet();
  106. modemInitReady=2;
  107. Ear_check(1);
  108. // //apn接入点设置
  109. // APNSet();
  110. // ModemGetCCID();
  111. // //判断国内还是国外
  112. // GetCountry();
  113. // //开机设置网络模式
  114. // ModemNetSet();
  115. // //检测卡是否存在
  116. if(0==ModemCheckUIM())
  117. {//卡不在位,循环播报请插卡
  118. sutPocStatus.loginResult=4;
  119. susCt=3500;
  120. //SetPowerEn(0);
  121. if(sutGpsInfo.Updata==1){
  122. GPSInit();
  123. }
  124. sutPocStatus.Modeminited=1;
  125. while(1)
  126. {
  127. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  128. {
  129. continue;
  130. }
  131. else os_dly_wait(1);
  132. sutPocStatus.ModemInactiveCt=0;
  133. if(0==g_ucModemTaskEn)continue;
  134. //GPS Uart消息处理
  135. if(g_usUart3RecvLen){
  136. process_nema((char *)RxBuffer3);
  137. g_usUart3RecvLen=0;
  138. }
  139. }
  140. }else SlwTrace(INF, "[2]Card ready",1);
  141. //开机发送二次
  142. LoginPocInfo();
  143. sutPocStatus.Modeminited=1;
  144. while(1)
  145. {
  146. GOWHILE:
  147. if(0==g_ucModemTaskEn)
  148. {
  149. sutPocStatus.ModemInactiveCt=0;
  150. pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData));
  151. if(pMsg->MsgLen > 0)
  152. {
  153. sutPocStatus.ModemInactiveCt=0;
  154. SlwTrace(INF,(char *)pMsg->MsgData,0);
  155. AtHandle(pMsg->MsgData);
  156. continue;
  157. }else if(pMsg->MsgLen < 0)
  158. {
  159. SlwTrace(INF, "QueueF1",1);
  160. continue;
  161. }
  162. else os_dly_wait(1);
  163. continue;
  164. }
  165. pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData));
  166. if(pMsg->MsgLen > 0)
  167. {
  168. sutPocStatus.ModemInactiveCt=0;
  169. if(pMsg->MsgData[0]=='+' || pMsg->MsgData[0] == '^')
  170. {
  171. AtHandle((char *)pMsg->MsgData);
  172. continue;
  173. }
  174. ZXPocHandle((char *)pMsg->MsgData,pMsg->MsgLen);
  175. continue;
  176. }else if(pMsg->MsgLen < 0)
  177. {
  178. SlwTrace(INF, "QueueF1",1);
  179. continue;
  180. }
  181. else os_dly_wait(1);
  182. if(0==sutPocStatus.Logined)SetLedIndicator(IndNoNet);// 快闪掉线
  183. else if(sutPocStatus.Speaker>0)SetLedIndicator(IndRX);
  184. else if(sutPocStatus.PPTpress>0)SetLedIndicator(IndTX);
  185. else if(((Vbat-340)*100/(430-340))<15)SetLedIndicator(InVbatLow);
  186. else SetLedIndicator(IndStandby);
  187. //以下控制GPS上传
  188. //GpsTaskTick(0);//GPS功能打开。
  189. if(sutPocStatus.modemRstFlag !=0) goto MODEM_RESTART;
  190. if(os_time_get() < sucCt) continue;
  191. sucCt = os_time_get()+100;//
  192. AtQuery();
  193. }
  194. }
  195. void Vbatsend()
  196. {
  197. static unsigned char VbatSendct=0;// 定时发送
  198. char PrintfBuf[20];
  199. if(sutPocStatus.Modeminited==0)return;
  200. if(g_ucModemTaskEn==0)return;
  201. if(BOOTDebug==1)return;
  202. if(VbatSendct<250) {
  203. VbatSendct++;
  204. if(VbatSendct%30==0){
  205. //SEND Vbat
  206. if(Vbat>330&&ChangeIng!=1){
  207. if(Vbat>435)snprintf(PrintfBuf,sizeof(PrintfBuf),"AT+POC=522&%d&%d\r\n",100,g_iCSQ);
  208. else snprintf(PrintfBuf,sizeof(PrintfBuf),"AT+POC=522&%d&%d\r\n",(Vbat-340)*100/(430-340),g_iCSQ);//435
  209. ModemSendAT(PrintfBuf);
  210. SlwTrace(INF,PrintfBuf,1);
  211. VbatSendct=0;
  212. }
  213. // os_dly_wait(10);
  214. // ModemSendAT("AT+POC=606\r\n");//心跳
  215. }
  216. }else VbatSendct=0;
  217. }
  218. void Modem_Stopinit()
  219. {
  220. //PWR_EN_LOW;
  221. SlwTrace(INF, "go GT_Mode\r\n",1);
  222. EnterGTMode();
  223. while(1)
  224. {
  225. sutPocStatus.ModemInactiveCt = 0;
  226. os_dly_wait(100);
  227. }
  228. }
  229. void GtFactory_XIEHAO(char type)
  230. {
  231. char flag=0;
  232. if(!type){
  233. if(g_uGtTaskEn==1) flag=1;
  234. }else{
  235. if(g_uGtFactory==1){
  236. flag=1;
  237. ModemSendAT(RF_TEST);
  238. SlwTrace(INF,RF_TEST,1);
  239. }
  240. }
  241. if(flag){
  242. while(1)
  243. {
  244. sutPocStatus.ModemInactiveCt=0;
  245. os_dly_wait(100);
  246. }
  247. }
  248. }
  249. /*******************************************************************************/