tt808.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. #include "tt808.h"
  2. #include "usart.h"
  3. #include "key.h"
  4. #include <stdio.h>
  5. #include <time.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "rtc.h"
  9. #include "database.h"
  10. //*整型
  11. int rlt;
  12. uint16_t uploadtime=0; //上传时间
  13. uint16_t hccd = 0;//ascii个数(*2)
  14. uint8_t header[12]; //处理头部
  15. uint8_t index_2c = 0;
  16. uint8_t MIPurc[100]; //接收平台数据
  17. uint8_t MIPurc1[100]; //接收平台数据
  18. uint8_t MIPurcXXTCSJ[100];//平台下行透传数据
  19. uint8_t speedBegin=0;
  20. uint8_t speedEnd=0;
  21. uint8_t speed[10]; //处理头部
  22. int pushpullcount = 0;
  23. double dSpeed=0;
  24. double dlatitude=0;
  25. double dlongitude=0;
  26. char cSpeed[10];
  27. char clatitude[15];
  28. char clongitude[15];
  29. char csatellitesNum[5];
  30. char MGNSSLOC[100]; //接收定位数据
  31. char CSQ[12]; //接收定位数据
  32. char MGNSSLOC_time[6]; //接收定位数据
  33. uint32_t Stamp =0;
  34. uint8_t GNSSdata[40]={0};
  35. //*结构体
  36. TT808 tt808;
  37. extern TipsFlag tipsflag;
  38. extern Menu_table menu;
  39. extern bool refresh;
  40. //*布尔
  41. bool authFlag = false;
  42. bool GnssFlag = false;
  43. bool Offline = false;
  44. bool Retrans = false;
  45. bool Online = false;
  46. /**
  47. 时间 纬度(北纬) 经度(东经) 水平精度因子 海拔高度 定位类型(1无,2 2d,3 3d) 运动角度 水平运动速度(KM/h) 水平运动速度(Knots) 日月年 卫星数量 差分定位标识(1单点,2差分)
  48. eg.+MGNSSLOC: 015032.301,3014.8605N,12001.9250E,1.8, 17.6, 3, 0.00, 3.6, 1.9, 080424, 12, 1
  49. */
  50. uint8_t Messagetemp_length=0;
  51. uint8_t MessageHandleData[100]; //放入封装后数据
  52. uint8_t tcppacket[100]; //消息数据
  53. void MessageHandle(uint16_t MessageID)
  54. {
  55. uint16_t MessageAttributeData = Messagetemp_length;
  56. if(MessageID ==MessageID_Retrans)
  57. {
  58. MessageAttributeData+=3;
  59. }
  60. MessageAttributeData |= ( Messagetemp_length | (TCPJMFSNULL<<10)); // 将长度左移3位后和加密方式进行按位或操作(001 RSA ,000 无加密)
  61. header[0] = ((MessageID>>8)&0xff);
  62. header[1] = (MessageID&0xff); //消息ID
  63. header[2] = ((MessageAttributeData>>8)&0xff);
  64. header[3] = (MessageAttributeData&0xff); //消息属性
  65. header[4] = 0x00;
  66. header[5] = 0x00;
  67. header[6] = 0x16;
  68. header[7] = 0x00;
  69. header[8] = 0x00;
  70. header[9] = 0x08; //“手机号”
  71. header[10] = ((tt808.LSH>>8)&0xff);;
  72. header[11] = (tt808.LSH&0xff);;
  73. int index = 0;
  74. tcppacket[index++] = TT808FLAG; // Set the headflag 0x7E
  75. for (int i = 0; i < 12; i++) {
  76. tcppacket[index++] = header[i];
  77. }
  78. // Copy message body to packet
  79. for (size_t i = 0; i < Messagetemp_length; i++) {
  80. tcppacket[index++] = MessageHandleData[i];
  81. }
  82. tcppacket[index++] = xorBytes(&tcppacket[1],12+Messagetemp_length);; // Set the checksum
  83. tcppacket[index++] = TT808FLAG; // Set the flag at the end
  84. for (int i = 0; i < index; i++) {
  85. printf("%02X ", tcppacket[i]); // 以十六进制格式打印每个元素
  86. }
  87. printf("\r\n");
  88. char TCPvalue[100];
  89. char *ptr = TCPvalue;
  90. ptr += sprintf(ptr, "AT+MIPSEND=1,%d,\"",index);
  91. for (int i = 0; i < index; i++) {
  92. ptr += sprintf(ptr, "%02X", tcppacket[i]);
  93. }
  94. sprintf(ptr, "\"\r\n");//TCPvalue
  95. if(sendCmd_4G(TCPvalue, "+MIPSEND:", 1, 1))//发送
  96. {
  97. printf("#发送完成\r\n");
  98. }
  99. tt808.LSH+=1;//需做写入处理
  100. }
  101. uint16_t swapBytes16(uint16_t value) {
  102. return (value >> 8) | (value << 8);
  103. }
  104. uint32_t swapBytes32(uint32_t value) {
  105. return ((value & 0xFF) << 24) | ((value & 0xFF00) << 8) |
  106. ((value >> 8) & 0xFF00) | ((value >> 24) & 0xFF);
  107. }
  108. /**
  109. * @breaf 消息体封装
  110. * Message[] 消息数据; length 消息数据长度; outMessage[] 封装后消息数据; MessageID 消息ID
  111. */
  112. uint8_t Message_bodydata(uint8_t *Message, uint8_t length, uint8_t outMessage[],uint16_t MessageID)
  113. {
  114. int index = 0;
  115. uint8_t temp_length = 0;//加首尾 25/23/crc
  116. if(MessageID==MessageID_authentication || MessageID==MessageID_heartbeat)//不加头尾(鉴权、心跳)
  117. {
  118. temp_length = length;//不加首尾
  119. uint8_t temp_Message[temp_length];
  120. for (int i = 0; i < length; i++) {
  121. temp_Message[index++] = Message[i]; // 将消息头拷贝到报文中
  122. }
  123. temp_length = index;
  124. for(int i =0;i<temp_length;i++)
  125. {
  126. outMessage[i]=temp_Message[i];
  127. }
  128. }
  129. else if(MessageID==MessageID_location)//终端地址0200 补传0704
  130. {
  131. temp_length = length;//不加首尾
  132. //状态标志/纬度/经度/速度
  133. uint8_t temp_Message[temp_length];
  134. dblocptr->location.statusFlag = swapBytes32(dblocptr->location.statusFlag);
  135. dblocptr->location.latitude = swapBytes32(dblocptr->location.latitude);
  136. dblocptr->location.longitude = swapBytes32(dblocptr->location.longitude);
  137. dblocptr->location.speed = swapBytes16(dblocptr->location.speed);
  138. for (int i = 0; i < length; i++) {
  139. temp_Message[index++] = Message[i]; // 将消息头拷贝到报文中
  140. }
  141. for(int i =0;i<temp_length;i++)
  142. {
  143. outMessage[i]=temp_Message[i];
  144. }
  145. }
  146. else if(MessageID==MessageID_Retrans)// 补传0704+5
  147. {
  148. temp_length = length;//不加首尾
  149. //状态标志/纬度/经度/速度
  150. dblocptr->temppull.statusFlag = swapBytes32(dblocptr->temppull.statusFlag);
  151. dblocptr->temppull.latitude = swapBytes32(dblocptr->temppull.latitude);
  152. dblocptr->temppull.longitude = swapBytes32(dblocptr->temppull.longitude);
  153. dblocptr->temppull.speed = swapBytes16(dblocptr->temppull.speed);
  154. uint8_t temp_Message[temp_length];
  155. temp_Message[index++] = 0x00;
  156. temp_Message[index++] = 0x01;
  157. temp_Message[index++] = 0x00;
  158. temp_Message[index++] = 0x00;
  159. temp_Message[index++] = 0x22;
  160. for (int i = 0; i < length; i++) {
  161. temp_Message[index++] = Message[i]; // 将消息头拷贝到报文中
  162. }
  163. for(int i =0;i<temp_length;i++)
  164. {
  165. outMessage[i]=temp_Message[i];
  166. }
  167. }
  168. else//加首尾
  169. {
  170. temp_length = length+3;//加首尾 25/23/crc
  171. uint8_t temp_Message[temp_length];
  172. temp_Message[index++]=temp_length;
  173. temp_Message[index++]=0x2A;
  174. for (int i = 0; i < length; i++) {
  175. temp_Message[index++] = Message[i]; // 将消息头拷贝到报文中
  176. }
  177. temp_Message[index++]=0x23;
  178. temp_Message[index++]=xorBytes(&temp_Message[1],temp_length-1);
  179. temp_length = index;
  180. for(int i =0;i<temp_length;i++)
  181. {
  182. outMessage[i]=temp_Message[i];
  183. }
  184. }
  185. //test
  186. // for (int i = 0; i < temp_length; i++) {
  187. // printf("%02X ", temp_Message[i]); // 以十六进制格式打印每个元素
  188. // }
  189. return temp_length;
  190. }
  191. /*需要传入消息体长度sizeof(Message)/sizeof(Message[0]);*/
  192. void tt808FsFunc(uint8_t* Message, uint8_t length, uint16_t MessageID)
  193. {
  194. HAL_Delay(200);
  195. Messagetemp_length = Message_bodydata(Message, length, MessageHandleData, MessageID);
  196. MessageHandle(MessageID);
  197. }
  198. void printBytes(uint8_t *data, size_t length) {
  199. for (size_t i = 0; i < length; i++) {
  200. printf("%02x ", data[i]);
  201. }
  202. printf("\n");
  203. }
  204. // 函数用于提取第7到第8个逗号之间的字符串
  205. void extractString(char* receiveStr, char* result, uint8_t start, uint16_t end)
  206. {
  207. int comma_count = 0;
  208. int start_index = -1;
  209. int end_index = -1;
  210. int length = strlen(receiveStr);
  211. // 遍历字符串,统计逗号数量和记录起始和结束索引
  212. for (int i = 0; i < length; i++)
  213. {
  214. if (receiveStr[i] == ',')
  215. {
  216. comma_count++;
  217. if (comma_count == start)
  218. {
  219. start_index = i + 1; // 第start个逗号之后的字符
  220. }
  221. else if (comma_count == end)
  222. {
  223. if(start==1 && end==2)//*纬度去尾符号
  224. {
  225. end_index = i-1; // 第end个逗号之前的字符
  226. }
  227. else if(start==2 && end==3)//*经度去尾符号
  228. {
  229. end_index = i-1; // 第end个逗号之前的字符
  230. }
  231. else
  232. {
  233. end_index = i; // 第end个逗号之前的字符
  234. }
  235. break;
  236. }
  237. }
  238. }
  239. // 提取字符串并存储在result数组中
  240. if (start_index != -1 && end_index != -1 && start_index < end_index)
  241. {
  242. strncpy(result, receiveStr + start_index, end_index - start_index);
  243. result[end_index - start_index] = '\0'; // 添加字符串结束符
  244. }
  245. }
  246. double convertToDouble(char* str) {
  247. if(str == csatellitesNum)
  248. {
  249. uint8_t result;
  250. sscanf(str, "%hhu", &result);
  251. return result;
  252. }
  253. else
  254. {
  255. double result;
  256. sscanf(str, "%lf", &result);
  257. return result;
  258. }
  259. }
  260. char hex2asc(const char *hex)
  261. {
  262. char asc = 0;
  263. char a = (hex[0]>='A' && hex[0]<='F')?(hex[0]^32):hex[0];
  264. char b = (hex[1]>='A' && hex[1]<='F')?(hex[1]^32):hex[1];
  265. if ((a>='0' && a<='9' || a>='a' && a<='f') && (b>='0' && b<='9' || b>='a' && b<='f')){
  266. asc = ((('a'<=a && a<='f')?(a-'a')+10:a-'0')<<4)|(('a'<=b && b<='f')?(b-'a')+10:b-'0');
  267. }
  268. return asc;
  269. }
  270. uint8_t testHex2Asc(const char *hex) {
  271. char asc = hex2asc(hex);
  272. printf("Hex: %s\tASC: %d\n", hex, asc);
  273. return asc;
  274. }
  275. char *bin2hex(char *hex, const unsigned char *bin, int size)
  276. {
  277. size_t i;
  278. for(i=0; i<size; i++)
  279. {
  280. sprintf(hex+i*2, "%02x", bin[i]);
  281. }
  282. hex[i+i] = 0;
  283. return hex;
  284. }
  285. int hex2bin(unsigned char *bin, const char *hex)
  286. {
  287. const char *h = hex;
  288. unsigned char *b = bin;
  289. int rlt = 0;
  290. while(*h){
  291. *b++ = hex2asc(h);
  292. h = h + 2;
  293. rlt++;
  294. }
  295. return rlt;//长度
  296. }
  297. // 将单个十六进制数转换为 BCD 码
  298. uint8_t hexToBcd(uint8_t hex) {
  299. return ((hex / 10) << 4) | (hex % 10);
  300. }
  301. // 将整数数组中的所有十六进制数转换为 BCD 码
  302. void hexArrayToBcd(uint8_t* array, size_t length, uint8_t* out) {
  303. array[3]+=8;
  304. for (size_t i = 0; i < length; i++) {
  305. out[i] = hexToBcd(array[i]);
  306. }
  307. }
  308. void ReMIPURC(void)
  309. {
  310. if(strncmp((char*)U4_4GrecvBuff, "+MIPURC", strlen("+MIPURC"))==0) //监测平台回复+MIPURC:
  311. {
  312. uint8_t high_byte = (U4_4GrecvBuff[18]&0x0f) *10;
  313. uint8_t low_byte = U4_4GrecvBuff[19]&0x0f;
  314. hccd = high_byte + low_byte;
  315. memcpy(MIPurc1,&U4_4GrecvBuff[21],hccd*2);
  316. const char *hex = (const char *)MIPurc1; // 将 uint8_t * 转换为 const char *
  317. int size = strlen(hex) / 2; // 计算二进制数据的长度
  318. unsigned char *bin = (unsigned char *)malloc(size); // 分配足够的内存用于存储二进制数据
  319. rlt = hex2bin(bin, hex); // 调用hex2bin函数进行转换
  320. memcpy(MIPurc, bin, rlt); // 将 bin 中的 rlt 个字节复制到 MIPurc1 中 接收到的数据放入MIPurc1中
  321. free(bin); // 释放内存
  322. memset(U4_4GrecvBuff,0,BUFFER_SIZE);
  323. memset(MIPurc1,0,100);
  324. }
  325. else if(strncmp((char*)U4_4GrecvBuff, "+MGNSSURC: \"state\",1", strlen("+MGNSSURC: \"state\",1"))==0)
  326. {
  327. printf("@MGNSS设置成功\r\n");
  328. memset(U4_4GrecvBuff,0,strlen("+MGNSSURC: \"state\",1"));
  329. }
  330. else if(strncmp((char*)U4_4GrecvBuff, "+MGNSSURC: \"state\",0", strlen("+MGNSSURC: \"state\",0"))==0)//断开平台
  331. {
  332. printf("@主动取消GNSS\r\n");
  333. memset(U4_4GrecvBuff,0,strlen("+MGNSSURC: \"state\",0"));
  334. }
  335. else if(strncmp((char*)U4_4GrecvBuff, "+MIPURC: \"di", strlen("+MIPURC: \"di"))==0)//"disconn" 平台断连
  336. {
  337. Offline=true;
  338. printf("@与平台断开连接\r\n");
  339. //ML307AReset();//与平台断开连接 offline
  340. memset(U4_4GrecvBuff,0,BUFFER_SIZE);
  341. }
  342. //*连接成功 Offline=false;
  343. else if(strncmp((char*)U4_4GrecvBuff, "+MIPOPEN: 1,0", strlen("+MIPOPEN: 1,0"))==0)//连接平台
  344. {
  345. Offline=false;
  346. Online = true;
  347. printf("@设备已上线!!\r\n");
  348. module4G_F = true;
  349. menu.current = 0xBB;
  350. tipsflag = Back;
  351. refresh=true;
  352. memset(U4_4GrecvBuff,0,BUFFER_SIZE);
  353. }
  354. else if(((strncmp((char*)U4_4GrecvBuff, "+MGNSSLOC", strlen("+MGNSSLOC"))==0) || (strncmp((char*)U4_4GrecvBuff, "OK", strlen("OK"))==0)) && MgnssFlag) //监测平台回复+MGNSSLOC OK4f4b
  355. {
  356. memcpy(MGNSSLOC,&U4_4GrecvBuff[11],75);
  357. GnssFlag=true;
  358. memset(U4_4GrecvBuff,0,BUFFER_SIZE);
  359. }
  360. else if((strncmp((char*)U4_4GrecvBuff, "+CPIN: SIM REMOVED", strlen("+CPIN: SIM REMOVED"))==0) || (strncmp((char*)U4_4GrecvBuff, "+CME ERROR: 10", strlen("+CME ERROR: 10"))==0) )//无SIM
  361. {
  362. //TODO
  363. printf("@SIM卡缺失\r\n");
  364. Offline=true;
  365. signal = false;
  366. menu.current = 0xBB;
  367. tipsflag = NoSIM;
  368. refresh=true;
  369. memset(U4_4GrecvBuff,0,BUFFER_SIZE);
  370. }
  371. else if((strncmp((char*)U4_4GrecvBuff, "+MIPCALL: 1,0", strlen("+MIPCALL: 1,0"))==0) || (strncmp((char*)U4_4GrecvBuff, "+CME ERROR: 550", strlen("+CME ERROR: 550"))==0))//意外断开平台连接!!!!//TCP未知错误
  372. {
  373. //TODO
  374. Offline=true;
  375. signal = false;
  376. printf("@与平台断开连接\r\n");
  377. memset(U4_4GrecvBuff,0,BUFFER_SIZE);
  378. }
  379. else if((strncmp((char*)U4_4GrecvBuff, "+MIPOPEN: 1,571", strlen("+MIPOPEN: 1,571"))==0))//PDP激活失败
  380. {
  381. //TODO
  382. Offline=true;
  383. printf("@PDP激活失败\r\n");
  384. memset(U4_4GrecvBuff,0,BUFFER_SIZE);
  385. }
  386. // else if(strncmp((char*)U4_4GrecvBuff+1, "CSQ", strlen("CSQ")))//CSQ 信号
  387. // {
  388. // memcpy(CSQ,U4_4GrecvBuff,U4_4GrecvLength);
  389. // dblocptr->location.CSQ = (uint8_t)(CSQ[6]&0xf*10)+(CSQ[7]&0xf);
  390. // memset(CSQ,0,12);
  391. // memset(U4_4GrecvBuff,0,BUFFER_SIZE);
  392. // }
  393. else if(U4_4GrecvBuff[1]== 0x43 && U4_4GrecvBuff[2]== 0x53 && U4_4GrecvBuff[3]== 0x51)//CSQ 信号
  394. {
  395. memcpy(CSQ,U4_4GrecvBuff,U4_4GrecvLength);
  396. dblocptr->location.CSQ = (uint8_t)(CSQ[6]&0xf*10)+(CSQ[7]&0xf);
  397. memset(CSQ,0,12);
  398. memset(U4_4GrecvBuff,0,BUFFER_SIZE);
  399. }
  400. }
  401. void MIPURCHandle(void)
  402. {
  403. if(MIPurc[0]==0x7E)
  404. {
  405. uint16_t PTXXID = MIPurc[1]<<8 | MIPurc[2]; //消息ID
  406. uint16_t xxtcLen = MIPurc[3]<<8 | MIPurc[4]; //数据长度
  407. uint16_t xxRE = MIPurc[15]<<8 | MIPurc[16]; //回复ID
  408. uint8_t YESorNO = MIPurc[17]; //00 success ; 01 fail
  409. if(PTXXID==XXID_pttyyd) //收到平台通用应答0x8001
  410. {
  411. if(xxRE == MessageID_authentication)//回复鉴权ID
  412. {
  413. if(YESorNO==YES)
  414. {
  415. printf("@鉴权应答yes\r\n");
  416. authFlag = true;
  417. }
  418. else if(YESorNO==NO)
  419. {
  420. printf("@鉴权应答no\r\n");
  421. }
  422. memset(MIPurc,0,rlt);//rlt下发长度
  423. }
  424. else if(xxRE == MessageID_heartbeat)//回复鉴权ID
  425. {
  426. if(YESorNO==YES)
  427. {
  428. printf("@心跳应答yes\r\n");
  429. }
  430. else if(YESorNO==NO)
  431. {
  432. printf("@心跳应答no\r\n");
  433. }
  434. memset(MIPurc,0,rlt);//rlt下发长度
  435. }
  436. else if(xxRE == MessageID_location)//回复鉴权ID
  437. {
  438. if(YESorNO==YES)
  439. {
  440. printf("@地址应答yes\r\n");
  441. }
  442. else if(YESorNO==NO)
  443. {
  444. printf("@地址应答no\r\n");
  445. }
  446. memset(MIPurc,0,rlt);//rlt下发长度
  447. }
  448. }
  449. else if(PTXXID == XXID_ptxxtc) //收到平台消息透传 8900
  450. {
  451. uint8_t tcsjLen = MIPurc[13];
  452. memcpy(MIPurcXXTCSJ,&MIPurc[13],xxtcLen);
  453. printf("@得到透传数据,%d\r\n",tcsjLen);
  454. memset(MIPurc,0,rlt);//rlt下发长度
  455. }
  456. }
  457. else if(authFlag)
  458. {
  459. authFlag = false;
  460. HAL_Delay(500);
  461. uint8_t test[] = {0x05}; //test心跳
  462. tt808FsFunc(test,1,MessageID_heartbeat); //test心跳
  463. }
  464. }
  465. time_t timestamp ;
  466. void time_bj(void)
  467. {
  468. struct tm timeinfo;
  469. timeinfo.tm_year = tt808.Rtime[0]+2000-1900;
  470. timeinfo.tm_mon = tt808.Rtime[1]-1;
  471. timeinfo.tm_mday = tt808.Rtime[2];
  472. timeinfo.tm_hour = tt808.Rtime[3]-8;
  473. timeinfo.tm_min = tt808.Rtime[4];
  474. timeinfo.tm_sec = tt808.Rtime[5];
  475. timestamp = mktime(&timeinfo);
  476. dblocptr->location.timeStamp = timestamp;
  477. }
  478. void ReU4Proces(void)
  479. {
  480. if(GnssFlag)
  481. {
  482. GnssFlag=false;
  483. RTCtime();//同步时间
  484. // 调用函数提取字符串
  485. extractString(MGNSSLOC, cSpeed,7 ,8);//采集
  486. dSpeed = convertToDouble(cSpeed); //转换浮点数
  487. dSpeed*=10;
  488. // 调用函数提取字符串
  489. extractString(MGNSSLOC, clatitude,1 ,2);//采集
  490. dlatitude = convertToDouble(clatitude); //转换浮点数
  491. dblocptr->location.latitude = convertGPS(dlatitude);
  492. extractString(MGNSSLOC, clongitude,2 ,3);//采集
  493. dlongitude = convertToDouble(clongitude); //转换浮点数
  494. dblocptr->location.longitude = convertGPS(dlongitude);
  495. // printf("%d\r\n",dblocptr->location.latitude);
  496. // printf("%d\r\n",dblocptr->location.longitude);
  497. // printf("%08X\r\n",dblocptr->location.latitude);
  498. // printf("%08X\r\n",dblocptr->location.longitude);
  499. extractString(MGNSSLOC, csatellitesNum,10 ,11);//采集卫星个数
  500. dblocptr->location.satellitesNum = convertToDouble(csatellitesNum); //转换浮点数
  501. //printf("%d",tt808.satellitesNum);
  502. dblocptr->location.speed = (uint16_t)dSpeed;
  503. if(dSpeed !=0 && dlongitude!=0 && dlatitude!=0) //有数据进行更新!
  504. {
  505. signal = true;
  506. if(menu.current == 0xBB && tipsflag!= ConnOK)
  507. {
  508. menu.current = 0;
  509. refresh=true;
  510. }
  511. else if(tipsflag == Back && signal)
  512. {
  513. menu.current = 0;
  514. refresh=true;
  515. }
  516. }
  517. else
  518. {
  519. if(signal && sys_mode[0]!=0xFFFF)
  520. {
  521. signal = false;
  522. menu.current = 0xBB;
  523. tipsflag = Nosignal;
  524. refresh=true;
  525. }
  526. }
  527. memset(MGNSSLOC,0,100);
  528. }
  529. }
  530. int countregular = 0;
  531. void Regular_reporting_Loc(void)
  532. {
  533. countregular+=1;
  534. if(countregular==3 && !Offline )//在线状态10s更新状态,30s上传 (各种状态正常在线,直接上传信息)
  535. {
  536. countregular=0;
  537. tt808FsFunc((uint8_t*)&(dblocptr->location.alarmFlag), 34, MessageID_location);
  538. }
  539. }
  540. void pushpullWork(void)
  541. {
  542. pushpullcount++;
  543. if(Offline && pushpullcount==10000)//掉线状态10s入库定位记录
  544. {
  545. RTCtime();//写入做参考
  546. printf("@@@设备掉线,执行入库操作!!%d\r\n",dblocptr->temppush.loc_pushIndex);
  547. Database_Push(0);
  548. //*每10s重连平台
  549. char TCPconnvalue[100];
  550. TcpConn(TCPconnvalue, 1, JLPTIP, JLPTPORT,0); //cid=1 tcpConnmode=0 普通模式
  551. if(sendCmd_4G(TCPconnvalue, "+MIPOPEN: 1,0", 1, 1)) //TCP连接 0普通模式 2缓存模式 1透传模式
  552. {
  553. printf("@@@TCP连接完成\r\n");
  554. }
  555. else
  556. {
  557. printf("@@@重连失败!\r\n");
  558. }
  559. }
  560. else if(Retrans && MiddleObj)//重传 7e0704002701820200777700060001000022000000000000000301cd8b7007278acd00000000000023051918174830011e310103b77e
  561. {
  562. tt808FsFunc((uint8_t*)&(dblocptr->temppull.alarmFlag), 39, MessageID_Retrans);
  563. printf("出库%d操作完成,当前索引%d\r\n",dblocptr->headinfo.loc_pullIndex-1,dblocptr->headinfo.loc_pullIndex);
  564. MiddleObj = false;
  565. }
  566. else if(Online && !MiddleObj && pushpullcount==1000) //上线出库
  567. {
  568. pushpullcount=0;
  569. if(dblocptr->headinfo.loc_pushIndex==0)
  570. {
  571. printf("@@@更新上线标识,库内无数据\r\n");
  572. Online = false;
  573. }
  574. else
  575. {
  576. RTCtime();//写入做参考
  577. printf("@@@库内有数据,执行操作\r\n");
  578. Database_Pull(0);
  579. MiddleObj=true;
  580. }
  581. }
  582. else if(pushpullcount>10001)
  583. {
  584. pushpullcount=0;
  585. }
  586. }