ModemTask.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. //Uart1RxEnable2(0); ///////////////////////////////
  66. sutPocStatus.Prepare=1;
  67. MODEM_RESTART:
  68. sutPocStatus.Logined=0;
  69. SlwTrace(INF,"ModemInit...",1);
  70. //SetLedIndicator(IndNoNet);
  71. sutPocStatus.modemRstFlag=0;
  72. sutPocStatus.ModemInactiveCt=0;//
  73. sutPocStatus.loginResult=0;
  74. modemInitReady=0;
  75. PWR_EN_HIGH;
  76. printf("\r\n%s_V%d.%d Start...\r\n",sutProductPara.ProductName,sutProductPara.ProductVersion,INTER_VER);
  77. os_dly_wait(100);//gps会受到模块刚开机的干扰,而定位变差
  78. //1、模块初始
  79. if(ModemInit())
  80. {//成功
  81. SlwTrace(INF,"[01] Modem Init OK",1);
  82. }else
  83. {
  84. //模块初始化失败,进入GT模式,为了升级模块
  85. bootFlag=1;
  86. PWR_EN_LOW;
  87. SlwTrace(INF,"[01]Failed\r\nEnter GT Mode!",1);
  88. EnterGTMode();
  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. if(GPIO_ReadInputDataBit(ONOFF_CK_PORT,ONOFF_CK_PIN)==1)
  101. modemPwrOffNow=1; ///////////////////////////////0 M20---- 1
  102. else PWR_EN_LOW;
  103. modemInitReady=1;
  104. /// M20---- 1
  105. /*********************CODEC调试 *******************************/
  106. ModemSendAT("ATE0\r\n");
  107. os_dly_wait(200);
  108. ModemSendAT("AT+AUDIOTEST=7\r\n"); //at+audiotest? +AUDIOTEST: 7
  109. os_dly_wait(10);
  110. ModemSendAT("AT+CODECTEST=0x0a,0x008\r\n");
  111. os_dly_wait(10);
  112. ModemSendAT("AT+CODECTEST=0x0e,0x108\r\n");
  113. os_dly_wait(10);
  114. ModemSendAT("AT+CODECTEST=0x2d,0x012\r\n"); //
  115. os_dly_wait(10);
  116. ModemSendAT("AT+CODECTEST=0x36,0x037\r\n"); //
  117. os_dly_wait(10);
  118. ModemSendAT("AT+CODECTEST=0x12,0x12c\r\n");
  119. os_dly_wait(10);
  120. ModemSendAT("AT+CODECTEST=0x16,0x08c\r\n");
  121. os_dly_wait(10);
  122. ModemSendAT("AT+CODECTEST=0x18,0x132\r\n"); //
  123. os_dly_wait(10);
  124. ModemSendAT("AT+CODECTEST=0x19,0x00C\r\n"); //
  125. SpeakerEnable();
  126. //开机发送二次
  127. LoginPocInfo();
  128. GetPocVer();
  129. GetModemVer();
  130. //apn接入点设置
  131. APNSet();
  132. ModemGetCCID();
  133. //判断国内还是国外
  134. GetCountry();
  135. //开机设置网络模式
  136. ModemNetSet();
  137. //检测卡是否存在
  138. if(0==ModemCheckUIM())
  139. {//卡不在位,循环播报请插卡
  140. sutPocStatus.loginResult=4;
  141. susCt=3500;
  142. //SetPowerEn(0);
  143. if(sutGpsInfo.Updata==1){
  144. GPSInit();
  145. }
  146. sutPocStatus.Modeminited=1;
  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, "[8]Card ready",1);
  163. snprintf(PrintfBuf,sizeof(PrintfBuf),"AT+POC=511&%d&%d&1\r\n",sutProductPara.SendToneEnadble,sutProductPara.RecvToneEnadble);
  164. ModemSendAT(PrintfBuf);
  165. sutPocStatus.Modeminited=1;
  166. while(1)
  167. {
  168. if(0==g_ucModemTaskEn)
  169. {
  170. pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData));
  171. if(pMsg->MsgLen > 0)
  172. {
  173. sutPocStatus.ModemInactiveCt=0;
  174. SlwTrace(INF,(char *)pMsg->MsgData,0);
  175. AtHandle(pMsg->MsgData);
  176. continue;
  177. }else if(pMsg->MsgLen < 0)
  178. {
  179. SlwTrace(INF, "QueueF1",1);
  180. continue;
  181. }
  182. else os_dly_wait(1);
  183. continue;
  184. }
  185. pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData));
  186. if(pMsg->MsgLen > 0)
  187. {
  188. sutPocStatus.ModemInactiveCt=0;
  189. if(pMsg->MsgData[0]=='+' || pMsg->MsgData[0] == '^')
  190. {
  191. AtHandle((char *)pMsg->MsgData);
  192. continue;
  193. }
  194. ZXPocHandle((char *)pMsg->MsgData,pMsg->MsgLen);
  195. continue;
  196. }else if(pMsg->MsgLen < 0)
  197. {
  198. SlwTrace(INF, "QueueF1",1);
  199. continue;
  200. }
  201. else os_dly_wait(1);
  202. if(0==sutPocStatus.Logined)SetLedIndicator(IndNoNet);// 快闪掉线
  203. else if(sutPocStatus.Speaker>0)SetLedIndicator(IndRX);
  204. else if(sutPocStatus.PPTpress>0)SetLedIndicator(IndTX);
  205. else if(((Vbat-340)*100/(430-340))<15)SetLedIndicator(InVbatLow);
  206. else SetLedIndicator(IndStandby);
  207. //以下控制GPS上传
  208. GpsTaskTick(0);//GPS功能打开。
  209. if(sutPocStatus.modemRstFlag !=0) goto MODEM_RESTART;
  210. if(os_time_get() < sucCt) continue;
  211. sucCt = os_time_get()+200;//
  212. AtQuery();
  213. }
  214. }
  215. void Vbatsend()
  216. {
  217. static unsigned char VbatSendct=0;// 定时发送
  218. char PrintfBuf[20];
  219. if(VbatSendct<250) {
  220. VbatSendct++;
  221. if(VbatSendct%30==0){
  222. //SEND Vbat
  223. if(Vbat>330&&ChangeIng!=1){
  224. if(Vbat>435)snprintf(PrintfBuf,sizeof(PrintfBuf),"AT+POC=522&%d&%d\r\n",100,g_iCSQ);
  225. else snprintf(PrintfBuf,sizeof(PrintfBuf),"AT+POC=522&%d&%d\r\n",(Vbat-340)*100/(430-340),g_iCSQ);//435
  226. ModemSendAT(PrintfBuf);
  227. SlwTrace(INF,PrintfBuf,1);
  228. VbatSendct=0;
  229. os_dly_wait(10);
  230. ModemSendAT("AT+POC=509\r\n");
  231. }
  232. }
  233. }else VbatSendct=0;
  234. }
  235. void Modem_Stopinit()
  236. {
  237. PWR_EN_LOW;
  238. SlwTrace(INF, "go GT_Mode\r\n",1);
  239. EnterGTMode();
  240. while(1)
  241. {
  242. sutPocStatus.ModemInactiveCt = 0;
  243. os_dly_wait(100);
  244. }
  245. }
  246. void GtFactory_XIEHAO(char type)
  247. {
  248. char flag=0;
  249. if(!type){
  250. if(g_uGtTaskEn==1) flag=1;
  251. }else{
  252. if(g_uGtFactory==1){
  253. flag=1;
  254. ModemSendAT(RF_TEST);
  255. SlwTrace(INF,RF_TEST,1);
  256. }
  257. }
  258. }
  259. /*******************************************************************************/