MW3650GpsTask.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /********************************************************************************
  2. * File Name: MW3650GpsTask.h
  3. * Function Describe: Header file for MW3650GpsTask.c
  4. * Explain:
  5. * Writer:
  6. * Date: 2016-3-11
  7. *******************************************************************************/
  8. #include "includes.h"
  9. unsigned char resetModem=0;
  10. /*************************************************
  11. 部标处理
  12. *****************************************************/
  13. void MW3600TSHandle(char *pMsg)
  14. {
  15. // int i;
  16. // static int flag =0;
  17. // static int flag1 =0;
  18. // static int flag2 =0;
  19. // char *pTemp;
  20. // static unsigned char buf[28];
  21. // unsigned char d,h,l;
  22. // static char name[16]={0};
  23. // static int name1[16]={0};
  24. /////////////////////////////////
  25. // char buf1[5];
  26. // unsigned short smsLen;
  27. /////////////////////////////////
  28. // SUT_MODEM_AT_MSG *Msg;
  29. // if(pMsg[61]=='0'){ //00注册 01 车辆已注册 02无此车辆 03 终端已经被注册 04 数据库无此终端
  30. // pTemp=(char *)&(pMsg[62]);
  31. // for(i=0;i<14;i++){//34
  32. // // SlwTrace(DEBUG,(char *)pTemp);
  33. // if(*pTemp==EOF){
  34. // pTemp++;
  35. // break;
  36. // }
  37. // name[i]=*pTemp++;
  38. // }
  39. // for(i =0; i < 7; i++)//14位变成16进制所以两位变成一位所以相应变成一半
  40. // {
  41. // sscanf(name+2*i,"%2x",&name1[i]);
  42. // sutProductPara.AutH[i]=name1[i];
  43. // SaveProductParaToFlash();
  44. // }
  45. // flag1++;
  46. // if(1 == flag1){
  47. // flag1 +=1;
  48. // Authentication(name1); //注册后 每次发送鉴权消息 去握手链接
  49. // if(0==ModemStrCmp(pMsg,"^IPRECV:")){
  50. // if(pMsg[8]=='1'){
  51. // if((pMsg[61]=='1')&&(pMsg[63]=='2')){
  52. // TSGpsTimingSendPos();
  53. // _free_box(AtMpool,Msg);
  54. // }
  55. // }
  56. // }
  57. // }
  58. // _free_box(AtMpool,Msg);
  59. // }
  60. // ///////////////////////////消息/////////////
  61. // //^IPRECV:1,183.131.13.6,1395,0,7E8300000500016600000900000131323334ED7E
  62. // else if(pMsg[32] == '8' && pMsg[33] == '3')
  63. // {
  64. // if(0==ModemStrCmp(pMsg,"^IPRECV:"))
  65. // {
  66. // memcpy(buf1, pMsg+36, 4);
  67. // buf1[4] = 0;
  68. // smsLen = strtol(buf1, NULL, 16);
  69. // if(SMS_SIGNAL_LEN <= smsLen)
  70. // smsLen = SMS_SIGNAL_LEN;
  71. // GBKTostr(pMsg+58,sutMess.GBKMess1,smsLen);
  72. // sutMess.GBKMess1[smsLen] = 0;//最后一个补0
  73. // sutMess.len = smsLen;
  74. // if(sutMess.len > 1)
  75. // SetGotNewMessage();
  76. // }
  77. // }
  78. // ////////////////////////////////////////
  79. // else{
  80. // for(i = 0; i < 7; i++){//14
  81. // name1[i]= (unsigned char)sutProductPara.AutH[i];
  82. // }
  83. // flag2++;
  84. // if(1 == flag2){
  85. // flag2 +=1;
  86. // Authentication(name1);
  87. // }
  88. // _free_box(AtMpool,Msg);//多清一次
  89. // if(0==ModemStrCmp(pMsg,"^IPRECV:")){
  90. // if((pMsg[61]=='1')&&(pMsg[63]=='2')){
  91. // TSGpsTimingSendPos();
  92. // _free_box(AtMpool,Msg);
  93. // }
  94. // if(0==ModemStrCmp(pMsg,"^IPRECV:")){
  95. // if((pMsg[61]=='2')&&(pMsg[63]=='0')){
  96. // _free_box(AtMpool,Msg);
  97. // }
  98. // }
  99. // }
  100. // _free_box(AtMpool,Msg);
  101. // }
  102. // _free_box(AtMpool,Msg);
  103. }
  104. void MW3650AtHandle(char *pMsg)
  105. {
  106. SUT_MODEM_AT_MSG *Msg;
  107. int csq, i;
  108. static int flag =0;
  109. static int flag1 =0;
  110. static int flag2 =0;
  111. char *pTemp;
  112. static unsigned char buf[28];
  113. unsigned char d,h,l;
  114. static char name[16]={0};
  115. static int name1[16]={0};;
  116. if(0==ModemStrCmp(pMsg,"+CSQ:")){
  117. csq=GetCSQ(pMsg);
  118. if(csq>=0 && csq<100)g_iCSQ=csq;
  119. }
  120. else if(0==ModemStrCmp(pMsg,"^IPCALL:")){
  121. //^IPCALL:1,10.6.3.217
  122. //^IPCALL: 0
  123. //SlwTrace(DEBUG,"IPCALL!");
  124. if(pMsg[8]=='1'){
  125. sutGpsStatus.PPPStatus=OPEN;
  126. /////////////////////
  127. if(resetModem == 2)
  128. {
  129. resetModem=3;
  130. ModemSendAT("ATE0\r\n");
  131. }else if(resetModem == 3)
  132. {
  133. resetModem = 4;
  134. }else if(resetModem == 4)
  135. {
  136. resetModem=0;
  137. ModemSendAT(POC_CMD_PPT_STOP);
  138. }
  139. //////////////////////
  140. }else{
  141. sutGpsStatus.PPPStatus=CLOSE;
  142. }
  143. }else if(0==ModemStrCmp(pMsg,"^IPOPEN:")){
  144. //^IPOPEN:1,0,183.131.13.6,1391 --已连接
  145. //^IPOPEN: 0 --已断开
  146. if(pMsg[8]=='1'){
  147. sutGpsStatus.IPStatus=OPEN;
  148. sutGpsInfo.isServerLogin = OPEN;
  149. // if(TimeFlag==0){
  150. // ModeGetTime();//获取时间 文工说只有IP通了 才正确
  151. // TimeFlag+=1;
  152. // }
  153. flag++;
  154. if(1==flag){
  155. flag+=1;
  156. Registration();// 先关了
  157. }
  158. // if(TimeFlag==0){
  159. // ModeGetTime();//获取时间 文工说只有IP通了 才正确
  160. // TimeFlag+=1;
  161. // }
  162. // ModemSendAT("AT^IPSEND=1,\"2929B100075986B38300590D\"\r\n");
  163. }else{
  164. sutGpsStatus.IPStatus=CLOSE;
  165. }
  166. }else if(0==ModemStrCmp(pMsg,"^IPRECV:")){
  167. if(pMsg[8]=='1'){
  168. RecvModemData(pMsg);
  169. MW3600TSHandle(pMsg);
  170. // SlwTrace(DEBUG,"HELLO IPRECV!");
  171. }else{
  172. sutGpsInfo.isServerLogin = 0;
  173. }
  174. //sutGpsInfo.isServerLogin = OPEN;
  175. //^IPRECV:1,183.131.13.6,1391,0,292921000559B100CC0D
  176. if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&Msg,1)){ //
  177. if(0==ModemStrCmp((char *)Msg->MsgData,"^IPRECV:")){ //
  178. //sutGpsInfo.isServerLogin = OPEN;
  179. SlwTrace(INF,(char *)Msg->MsgData); //
  180. _free_box(AtMpool,Msg); //
  181. }
  182. }
  183. }
  184. else if(0==ModemStrCmp(pMsg, "^IPSTAT:"))
  185. {
  186. if(pMsg[10] == '1')//SOCKET BROKEN
  187. {
  188. if(IapPra.FOTA_IS_ON == 0)
  189. {
  190. resetModem = 1;
  191. sutGpsStatus.PPPStatus=CLOSE;
  192. }else//空中升级中
  193. {
  194. IapPra.timeTry = 0;//重置重传数
  195. IapPra.resetModemTime ++;
  196. if(IapPra.resetModemTime >=3)
  197. {
  198. IapPra.resetModemTime=0;
  199. resetModem = 1;
  200. sutGpsStatus.PPPStatus=CLOSE;
  201. }
  202. }
  203. }
  204. }
  205. /////////////////END CALL //////////////////////
  206. else if(0 == ModemStrCmp(pMsg, "+ZCEND"))
  207. {
  208. g_ucCallPhonePro = 2;//tell end call
  209. }
  210. // }else if(0==ModemStrCmp(pMsg,"+ZPPPSTATUS:")){
  211. // sutGpsStatus.PPPStatus=GetPPPStatus(pMsg);
  212. // }else if(0==ModemStrCmp(pMsg,"+ZIPSTATUS:")){
  213. // sutGpsStatus.IPStatus=GetIPStatus(pMsg);
  214. // }else if(0==ModemStrCmp(pMsg,"+ZIPRECV:")){
  215. // RecvModemData(pMsg);
  216. // }else if(0==ModemStrCmp(pMsg,"+ZIPSEND:")){
  217. //
  218. // }else if(0==ModemStrCmp(pMsg,"^IPCALL:1,10")){
  219. // sutGpsStatus.PPPStatus=GetIPStat(pMsg);
  220. // }
  221. }
  222. /************************************************
  223. 每10ms处理一次
  224. **************************************************/
  225. void MW3650GpsTaskTick(unsigned char reset)
  226. {
  227. static unsigned char sucSecCt=0;
  228. static unsigned char sucSteep=0;
  229. static unsigned char sucSynSentCt=0;
  230. unsigned char temp[4];
  231. char buf[50];
  232. int i;
  233. SUT_MODEM_AT_MSG *pMsg;
  234. if(reset){
  235. sucSecCt=0;
  236. sucSteep=0;
  237. return;
  238. }
  239. #ifdef GPS_ENABLE
  240. //GPS Uart消息处理
  241. if(g_usUart2RecvLen){
  242. process_nema((char *)RxBuffer2);
  243. g_usUart2RecvLen=0;
  244. }
  245. #endif
  246. //===========以下控制每秒执行一次============
  247. if(++sucSecCt>99)sucSecCt=0;
  248. else return;
  249. //=========================================
  250. if(sutGpsInfo.isGpsWork!=0){//GPS模块未正常工作!不发送数据,也可能是无GPS版本
  251. GpsCtrlSendPos();
  252. }
  253. //TCP发送防护,如果IPSTATUS一直等于SYN_SENT持续达10秒,则关闭TCP链路
  254. if(sutGpsStatus.IPStatus==SYN_SENT){
  255. if(++sucSynSentCt>10){
  256. sucSynSentCt=0;
  257. sutGpsInfo.isServerLogin=0;
  258. g_ucModemSentTcpCt=0;
  259. sutGpsStatus.IPStatus=CLOSE;
  260. g_ucModemSentTcpCt=0;
  261. sutGpsInfo.isServerLogin=0;
  262. }
  263. }else sucSynSentCt=0;
  264. //---以下控制---
  265. if(++sucSteep>4)sucSteep=0;
  266. //----
  267. if(sucSteep==0){
  268. ModemSendAT("AT+CSQ\r\n");
  269. //用来测试16进制转化的代码
  270. //temp[0]=0xAB;temp[1]=0x12;temp[2]=0xEF;temp[3]=0xCD;
  271. //HexToStr(temp,buf,4);
  272. // buf[9]=0;
  273. // SlwTrace(INF,buf);
  274. }
  275. //#ifdef GPS_ENABLE //关了
  276. /***********************************
  277. **int i;
  278. **SUT_MODEM_AT_MSG *pMsg;
  279. **for(i=0;i<10;i++){
  280. ** if(ModemSendAT2WaitAckMsg("AT+CPIN?\r\n","+CPIN: READY",&pMsg,100)){
  281. ** _free_box(AtMpool,pMsg);
  282. ** return 1;
  283. ** }
  284. }
  285. ***********************************/
  286. else if(1==sucSteep){
  287. ModemSendAT("AT^IPCALL?\r\n");
  288. //for(i=0;i<10;i++){//+
  289. //if(ModemSendAT2WaitAckMsg("AT^IPCALL=1,""\"\",""\"\"\r\n","^IPCALL:",&pMsg,100)){ //AT^IPCALL=1,"",""
  290. //_free_box(AtMpool,pMsg);
  291. //}
  292. //os_dly_wait(20);
  293. // ModemSendAT("AT^IPCALL=1,""\"\",""\"\"\r");
  294. // if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&pMsg,1)){
  295. // if(0==ModemStrCmp((char *)pMsg->MsgData,"^IPCALL")){
  296. // SlwTrace(INF,(char *)pMsg->MsgData);
  297. // _free_box(AtMpool,pMsg);
  298. // }
  299. // }
  300. //}
  301. }else if(2==sucSteep){
  302. if(99==g_iCSQ)return;
  303. if(sutGpsStatus.PPPStatus!=OPEN){
  304. ModemSendAT("AT^IPCALL=1,""\"\",""\"\"\r\n");
  305. }
  306. //for(i=0;i<10;i++){//+
  307. //if(ModemSendAT2WaitAckMsg("AT^IPCALL?\r\n","^IPCALL:",&pMsg,100)){ //AT^IPCALL?
  308. //_free_box(AtMpool,pMsg);//+
  309. // }
  310. //}//+
  311. /* if(sutGpsStatus.PPPStatus==OPEN){
  312. //SlwTrace(DEBUG,"AT+ZIPSTATUS=0\r\n");
  313. ModemSendAT("AT+ZIPSTATUS=0\r");
  314. //if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&pMsg,1)){ //+
  315. // if(0==ModemStrCmp((char *)pMsg->MsgData,"^IPCALL")){ //+
  316. // SlwTrace(INF,(char *)pMsg->MsgData); //+
  317. // SUT_MODEM_AT_MSG *Msg;
  318. //while(timeout){
  319. //if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&Msg,1)){
  320. //SlwTrace(DEBUG,(char *)Msg->MsgData);
  321. }else{
  322. os_dly_wait(20);
  323. //SlwTrace(DEBUG,"AT+ZPPPOPEN\r\n");
  324. //ModemSendAT("AT+ZPPPOPEN\r");
  325. //int i,t=10;//+
  326. // int t =10;
  327. //SUT_MODEM_AT_MSG *pMsg;//+
  328. //while(t--){//+
  329. if(ModemSendAT2WaitAckMsg("AT^IPOPEN=1,9501,\"183.131.13.6\",1391,0\r\n","^IPOPEN:1,1",&pMsg,100)){ //AT^IPCALL=1,......
  330. _free_box(AtMpool,pMsg);//+
  331. SlwTrace(INF,"AT^IPOPEN=OK\r\n");
  332. }
  333. // }
  334. // ModemSendAT("AT^IPOPEN=1,9501,\"183.131.13.6\",1391,0\r\n");
  335. // if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&pMsg,10)){
  336. // if(0==ModemStrCmp((char *)pMsg->MsgData,"^IPOPEN:1,1")){
  337. // SlwTrace(INF,"AT^IPOPEN=OK\r\n");
  338. // SlwTrace(INF,(char *)pMsg->MsgData);
  339. // _free_box(AtMpool,pMsg);
  340. // }
  341. // }
  342. os_dly_wait(50);
  343. if(ModemSendAT2WaitAckMsg("AT^IPSEND=1,\"4142\"\r\n","^IPSEND:",&pMsg,100)){ //AT^IPCALL?
  344. _free_box(AtMpool,pMsg);//+
  345. }
  346. }*/
  347. }else if(3==sucSteep){
  348. if(99==g_iCSQ){
  349. return;
  350. }
  351. if(sutGpsInfo.isGpsWork==0){
  352. SlwTrace(INF,"GPS modem not work!\r\n");
  353. return;
  354. }
  355. if(sutGpsStatus.IPStatus!=OPEN && sutGpsStatus.PPPStatus==OPEN){
  356. sutGpsInfo.isServerLogin=0; //0
  357. //AT^IPOPEN=1,9501,"183.131.13.6",1391,0
  358. //"AT^IPOPEN=1,9501,\"183.131.13.6\",1391,0\r\n"
  359. sprintf(buf,"AT^IPOPEN=1,9501,\"%s\",%d,0\r\n",sutProductPara.GIP,sutProductPara.GpsPort);
  360. SlwTrace(DEBUG,buf);
  361. ModemSendAT(buf);
  362. }
  363. }else if(4==sucSteep){
  364. if(99==g_iCSQ)return;
  365. if(sutGpsInfo.isGpsWork==0)return;
  366. //AT^IPSEND=1,"2929b100075986b38300590d"
  367. if(sutGpsStatus.IPStatus==OPEN && 0==sutGpsInfo.isServerLogin){
  368. TSGpsServerConect();
  369. }
  370. }
  371. }
  372. void Modem3650CheckReset(void)
  373. {
  374. if(resetModem==1)
  375. {
  376. SlwTrace(INF, "Reset Module\r\n");
  377. sutGpsStatus.PPPStatus=CLOSE;
  378. ResetModem();
  379. resetModem = 2;
  380. }
  381. }