GpsTask.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /********************************************************************************
  2. * File Name: GpsTask.c
  3. * Function Describe:The GpsTask for the system
  4. * Relate Module:
  5. * Explain: Hardware version is HS110C
  6. * Writer: ShiLiangWen
  7. * Date: 2015.4.12
  8. *******************************************************************************/
  9. #define THIS_FILE_ID 16
  10. //--------------------------------------------------------------------------------
  11. #include "includes.h"
  12. //OS_TID idGpsTask=0;
  13. //U64 stkGpsTask[GPS_TASK_STK_SIZE];
  14. SUT_GPS_STATUS sutGpsStatus;
  15. SUT_MESS sutMess;
  16. int g_iCSQ=-1;
  17. //const unsigned char GPS_TimeTable[]={0,5,10,15,30,60};
  18. const unsigned char GPS_TimeTable[]={5,10,15,30,60};
  19. //======================================
  20. static STATUE GpsServerStatus=CLOSE;
  21. unsigned char TimeFlag=1;//获取服务器时间标记
  22. unsigned char sucGpsSentTcpCt=0;//从启动发送到收到计数器
  23. /*******************************************************************************
  24. 校验
  25. *******************************************************************************/
  26. unsigned char GetCheck(unsigned char *data, unsigned short datalen)
  27. {
  28. unsigned char ck=0;
  29. int i;
  30. for(i=0;i<datalen;i++){
  31. ck^=data[i];
  32. }
  33. return ck;
  34. }
  35. /*****************************************************************************
  36. *发送数据封包
  37. format: 0x29 0x29 CMD Len PSN[4] Data Check 0x0D
  38. Len=DataLen+6
  39. ******************************************************************************/
  40. int SendBufPack(char *pBuf,unsigned char cmd,unsigned short DataLen,unsigned char *data)
  41. {
  42. SUTDS ds;
  43. SUTDL dl;
  44. int i,j;
  45. if(DataLen>UART3_TX_BUFFER_SIZE)return 0;
  46. //包头
  47. pBuf[0]=0x29;//Head
  48. pBuf[1]=0x29;//Head
  49. pBuf[2]=cmd;//CMD
  50. //DataLen
  51. ds.Data.usData=DataLen+6;
  52. pBuf[3]=ds.Data.ucData.b2;
  53. pBuf[4]=ds.Data.ucData.b1;
  54. //PSN
  55. dl.Data.ulData=sutProductPara.PSN;
  56. pBuf[5]=dl.Data.ucData.b4;
  57. pBuf[6]=dl.Data.ucData.b3;
  58. pBuf[7]=dl.Data.ucData.b2;
  59. pBuf[8]=dl.Data.ucData.b1;
  60. //Data
  61. j=9;
  62. for(i=0;i<DataLen;i++){
  63. pBuf[j++]=data[i];
  64. }
  65. //check
  66. pBuf[j++]= GetCheck(TxBuffer3,(DataLen+6));
  67. pBuf[j++]=0x0D;
  68. return j;
  69. }
  70. /*******************************************************************
  71. *GetCSQ
  72. ********************************************************************/
  73. int GetCSQ(char* msg)
  74. {//+CSQ: 29,56
  75. return atoi(&msg[6]);
  76. }
  77. int GetCCSQ(char* msg)
  78. {//+CCSQ: 29,56
  79. return atoi(&msg[7]);
  80. }
  81. /*******************************************************************
  82. *GetIPStatus
  83. ********************************************************************/
  84. STATUE GetIPStatus(char *msg)
  85. {
  86. //if(ModemStrCmp(msg,"+ZIPSTATUS:")){ //+ZIPSTATUS: xxxx
  87. if(msg[12]=='E' && msg[14]=='T' && msg[22]=='D'){//+ZIPSTATUS: ESTABLISHED
  88. // if(TimeFlag==0){
  89. // ModeGetTime();//获取时间 文工说只有IP通了 才正确
  90. // TimeFlag+=1;
  91. // }
  92. return OPEN;
  93. }else if(msg[12]=='S' && msg[14]=='N' && msg[19]=='T'){//+ZIPSTATUS: SYN_SENT
  94. return SYN_SENT;
  95. }else{
  96. return CLOSE;
  97. }
  98. //}else return INVALID;
  99. }
  100. /*******************************************************************
  101. *GetIPStatusu
  102. ********************************************************************/
  103. STATUE GetIPStatusu(char *msg)
  104. {
  105. //if(ModemStrCmp(msg,"+ZIPSTATUSU:")){ //+ZIPSTATUSU: ESTABLISHED
  106. if(msg[13]=='E' && msg[15]=='T' && msg[23]=='D'){
  107. return OPEN;
  108. }else if(msg[13]=='S' && msg[15]=='N' && msg[20]=='T'){
  109. return SYN_SENT;
  110. }else{
  111. return CLOSE;
  112. }
  113. //}else return INVALID;
  114. }
  115. /*******************************************************************
  116. *GetIPStatus
  117. 返回:0--未获取 1--获取成功
  118. 00
  119. ********************************************************************/
  120. void StartFeedBack(void)
  121. {
  122. if(sutFeed.feedBackStart==0) return;
  123. TSGpsServerConect();
  124. sutFeed.feedBackStart=0;
  125. }
  126. /***********************************************************
  127. *控制发送位置信息
  128. 此函数每秒执行一次
  129. ************************************************************/
  130. void GpsCtrlSendPos(void)
  131. {
  132. static unsigned char authTryTime=0;//发起鉴权次数,也代表连续失败多少次
  133. static unsigned short SendTime=0;
  134. static unsigned char suctt;
  135. static unsigned short realTimeSecond=0xff00;
  136. char packetHadSend=0;
  137. uint32_t AvgSpeed;
  138. int i;
  139. static unsigned int susGpsTimingSendCt=0;//控制按时间发送
  140. char buf[30];
  141. //计算平均速度
  142. sutGpsInfo.speedbuf[4]=sutGpsInfo.speedbuf[3];
  143. sutGpsInfo.speedbuf[3]=sutGpsInfo.speedbuf[2];
  144. sutGpsInfo.speedbuf[2]=sutGpsInfo.speedbuf[1];
  145. sutGpsInfo.speedbuf[1]=sutGpsInfo.speedbuf[0];
  146. sutGpsInfo.speedbuf[0]=sutGpsInfo.speed;
  147. for(i=0;i<5;i++){
  148. AvgSpeed=sutGpsInfo.speedbuf[i];
  149. }
  150. AvgSpeed/=5;
  151. sutGpsInfo.AvgSpeed=AvgSpeed;
  152. //---控制按时间间隔发送GPS位置
  153. sutGpsInfo.GPS_SecondCnt++;
  154. if(sutGpsInfo.isGpsValid && g_uiGpsStat) //GPS是打开的。
  155. {//可以发位置包,检测时间是否到了
  156. if(sutGpsInfo.GPS_SecondCnt>=sutGpsInfo.GPS_UploadTime) //
  157. {
  158. sutGpsInfo.GPS_SecondCnt=0;
  159. //GetCoordinates(1);
  160. TSGpsTimingSendPos(); //向模块发送 GPS 数据
  161. packetHadSend=1;//已发了数据包
  162. }
  163. }
  164. if(++suctt >= 30)
  165. {
  166. suctt = 0;
  167. if(!g_uiGpsStat) SlwTrace(INF, "GPS close",1);
  168. }
  169. }
  170. STATUE GetIPNewStatus(char *msg, unsigned char socketNum)
  171. {//+TCPSTATUS:x:s [socket: status]
  172. //+TCPSTATUS:1:1
  173. //+TCPSTATUS:ERROR!
  174. STATUE sta=CLOSE;
  175. unsigned char thisSocket;
  176. thisSocket = atoi(&msg[11]);
  177. if(msg[13] == '1') sta = OPEN;
  178. else if(msg[13] == '0')sta = CLOSE;
  179. if(thisSocket == socketNum) return sta;
  180. else return INVALID;
  181. }