1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273 |
- #include "tt808.h"
- #include "usart.h"
- #include "key.h"
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- #include <string.h>
- #include "rtc.h"
- #include "database.h"
- //*整型
- int rlt;
- uint16_t uploadtime=0; //上传时间
- uint16_t hccd = 0;//ascii个数(*2)
- uint8_t header[12]; //处理头部
- uint8_t index_2c = 0;
- uint8_t MIPurc[100]; //接收平台数据
- uint8_t MIPurc1[100]; //接收平台数据
- uint8_t MIPurcXXTCSJ[100];//平台下行透传数据
- uint8_t speedBegin=0;
- uint8_t speedEnd=0;
- uint8_t speed[10]; //处理头部
- uint8_t DTUurc[100]; //接收平台数据
- uint8_t DTUurc1[15]; //接收平台数据
- int pushpullcount = 0;
- double dSpeed=0;
- double dlatitude=0;
- double dlongitude=0;
- char cSpeed[10];
- char clatitude[15];
- char clongitude[15];
- char csatellitesNum[5];
- char MGNSSLOC[100]; //接收定位数据
- char CSQ[12]; //接收定位数据
- char MGNSSLOC_time[6]; //接收定位数据
- uint32_t Stamp =0;
- uint8_t GNSSdata[40]={0};
- //*结构体
- TT808 tt808;
- extern TipsFlag tipsflag;
- extern Menu_table menu;
- extern bool refresh;
- extern LockInfo lockinfo;
- //*布尔
- bool authFlag = false;
- bool GnssFlag = false;
- bool Offline = false;
- bool Retrans = false;
- bool Online = false;
- bool reIME = false;
- bool reAuth = false;//回复权限
- /**
- 时间 纬度(北纬) 经度(东经) 水平精度因子 海拔高度 定位类型(1无,2 2d,3 3d) 运动角度 水平运动速度(KM/h) 水平运动速度(Knots) 日月年 卫星数量 差分定位标识(1单点,2差分)
- eg.+MGNSSLOC: 015032.301,3014.8605N,12001.9250E,1.8, 17.6, 3, 0.00, 3.6, 1.9, 080424, 12, 1
- */
- void reconn(void)
- {
- char TCPconnvalue[120];
- TcpConn(TCPconnvalue, 1, JLPTIP, JLPTPORT,0); //cid=1 tcpConnmode=0 普通模式
- if(sendCmd_4G(TCPconnvalue, "+MIPOPEN: 1,0", 1, 1)) //TCP连接 0普通模式 2缓存模式 1透传模式
- {
- printf("重连成功\r\n");
- }
- }
- uint8_t Messagetemp_length=0;
- uint8_t MessageHandleData[100]; //放入封装后数据
- uint8_t tcppacket[100]; //消息数据
- uint8_t copyAddress[49];
- void MessageHandle(uint16_t MessageID)
- {
- Flash_ReadBytes((uint16_t*)&(tt808.LSH),tt808serialNum,1);//读取loc头部是否发生写入
- if(tt808.LSH==0xFFFF)
- {
- tt808.LSH=0;//初始未写入
- }
- uint16_t MessageAttributeData = Messagetemp_length;
- MessageAttributeData |= ( Messagetemp_length | (TCPJMFSNULL<<10)); // 将长度左移3位后和加密方式进行按位或操作(001 RSA ,000 无加密)
-
- header[0] = ((MessageID>>8)&0xff);
- header[1] = (MessageID&0xff); //消息ID
- header[2] = ((MessageAttributeData>>8)&0xff);
- header[3] = (MessageAttributeData&0xff); //消息属性
- //*test phoneNumxy
- //*work phoneNum
- if(phonenull)
- {
- header[4] = 0x00;
- header[5] = 0x00;
- header[6] = 0x16;
- header[7] = 0x00;
- header[8] = 0x00;
- header[9] = 0x08; //“手机号”
- phonenum[0]=0x0000;
- phonenum[1]=0x1600;
- phonenum[2]=0x0008;
-
- }
- else
- {
- header[4] = (phonenum[0]>>8)&0xff;
- header[5] = (phonenum[0])&0xff;
- header[6] = (phonenum[1]>>8)&0xff;
- header[7] = (phonenum[1])&0xff;
- header[8] = (phonenum[2]>>8)&0xff;
- header[9] = (phonenum[2])&0xff; //“手机号”
- }
- header[10] = ((tt808.LSH>>8)&0xff);
- header[11] = (tt808.LSH&0xff);
-
- int index = 0;
- tcppacket[index++] = TT808FLAG; // Set the headflag 0x7E
-
- for (int i = 0; i < 12; i++) {
- tcppacket[index++] = header[i];
- }
- // Copy message body to packet
- for (size_t i = 0; i < Messagetemp_length; i++) {
- tcppacket[index++] = MessageHandleData[i];
- }
- tcppacket[index++] = xorBytes(&tcppacket[1],12+Messagetemp_length);; // Set the checksum
- tcppacket[index++] = TT808FLAG; // Set the flag at the end
-
- // for (int i = 0; i < index; i++) {
- // printf("%02X ", tcppacket[i]); // 以十六进制格式打印每个元素
- // }
- printf("\r\n");
- memcpy(copyAddress,tcppacket,49);
-
- //#if open4G ==1
- char TCPvalue[120];
- char *ptr = TCPvalue;
- ptr += sprintf(ptr, "AT+MIPSEND=1,%d,\"",index);
- for (int i = 0; i < index; i++) {
- ptr += sprintf(ptr, "%02X", tcppacket[i]);
- }
- sprintf(ptr, "\"\r\n");//TCPvalue
- if(sendCmd_4G(TCPvalue, "+MIPSEND:", 1, 1))//发送
- {
- printf("#等待回应\r\n");
- }
- //#endif
-
-
- tt808.LSH+=1;//需做写入处理
- Flash_WriteBytes((uint16_t*)&(tt808.LSH),tt808serialNum,1);
- }
- uint16_t swapBytes16(uint16_t value) {
- return (value >> 8) | (value << 8);
- }
- uint32_t swapBytes32(uint32_t value) {
- return ((value & 0xFF) << 24) | ((value & 0xFF00) << 8) |
- ((value >> 8) & 0xFF00) | ((value >> 24) & 0xFF);
- }
- /**
- * @breaf 消息体封装
- * Message[] 消息数据; length 消息数据长度; outMessage[] 封装后消息数据; MessageID 消息ID
- */
- extern BtFrame btframe;
- uint8_t Message_bodydata(uint8_t *Message, uint8_t length, uint8_t outMessage[],uint16_t MessageID)
- {
- int index = 0;
- uint8_t temp_length = 0;//加首尾 25/23/crc
-
- if(MessageID==MessageID_authentication || MessageID==MessageID_heartbeat || MessageID==MessageID_Getauth)//不加头尾(鉴权、心跳、获取权限)
- {
- temp_length = length;//不加首尾
- uint8_t temp_Message[temp_length];
-
- for (int i = 0; i < length; i++) {
- temp_Message[index++] = Message[i]; // 将消息头拷贝到报文中
- }
-
- temp_length = index;
-
- for(int i =0;i<temp_length;i++)
- {
- outMessage[i]=temp_Message[i];
- }
- }
- else if(MessageID==MessageID_location)//终端地址0200 补传0704
- {
-
- temp_length = length;//不加首尾
- //状态标志/纬度/经度/速度
- uint8_t temp_Message[temp_length];
- for (int i = 0; i < length; i++) {
- temp_Message[index++] = Message[i]; // 将消息头拷贝到报文中
- }
-
-
- for(int i =0;i<temp_length;i++)
- {
- outMessage[i]=temp_Message[i];
- }
- }
- else if(MessageID==MessageID_Retrans)// 补传0704+5
- {
- temp_length = length;//不加首尾
- uint8_t temp_Message[temp_length];
-
- temp_Message[index++] = 0x00;
- temp_Message[index++] = 0x01;
- temp_Message[index++] = 0x00;
- temp_Message[index++] = 0x00;
- temp_Message[index++] = 0x22;
-
-
- for (int i = 0; i < length; i++) {
- temp_Message[index++] = Message[i]; // 将消息头拷贝到报文中
- }
-
-
- for(int i =0;i<temp_length;i++)
- {
- outMessage[i]=temp_Message[i];
- }
- }
- else if(MessageID==MessageID_uploadLock)//上传锁信息
- {
- temp_length = length+9;//加4字节操作时间+4字节userIDbtframe.userId+1byte操作类型
-
- uint8_t temp_Message[temp_length];
- for (int i = 0; i < length; i++) {
- temp_Message[index++] = Message[i]; // 将消息头拷贝到报文中
- }
- uint32_t ntime = dblocptr->location.timeStamp;//现在时间
- temp_Message[index++]=(ntime>>24) & 0xff;
- temp_Message[index++]=(ntime>>16) & 0xff;
- temp_Message[index++]=(ntime>>8) & 0xff;
- temp_Message[index++]= ntime & 0xff;
-
- temp_Message[index++]=(btframe.userId>>24) & 0xff;
- temp_Message[index++]=(btframe.userId>>16) & 0xff;
- temp_Message[index++]=(btframe.userId>>8) & 0xff;
- temp_Message[index++]=(btframe.userId) & 0xff;
- temp_Message[index++] = macsetptr->sta;
-
- for(int i =0;i<temp_length;i++)
- {
- outMessage[i]=temp_Message[i];
- }
- }
- else//加首尾
- {
- temp_length = length+3;//加首尾 25/23/crc
- uint8_t temp_Message[temp_length];
-
- temp_Message[index++]=temp_length;
- temp_Message[index++]=0x2A;
- for (int i = 0; i < length; i++) {
- temp_Message[index++] = Message[i]; // 将消息头拷贝到报文中
- }
- temp_Message[index++]=0x23;
- temp_Message[index++]=xorBytes(&temp_Message[1],temp_length-1);
- temp_length = index;
-
- for(int i =0;i<temp_length;i++)
- {
- outMessage[i]=temp_Message[i];
- }
- }
- return temp_length;
- }
- /*需要传入消息体长度sizeof(Message)/sizeof(Message[0]);*/
- void tt808FsFunc(uint8_t* Message, uint8_t length, uint16_t MessageID)
- {
- HAL_Delay(200);
- Messagetemp_length = Message_bodydata(Message, length, MessageHandleData, MessageID);
- MessageHandle(MessageID);
- }
- void printBytes(uint8_t *data, size_t length) {
- for (size_t i = 0; i < length; i++) {
- printf("%02x ", data[i]);
- }
- printf("\n");
- }
- // 函数用于提取第7到第8个逗号之间的字符串
- void extractString(char* receiveStr, char* result, uint8_t start, uint16_t end)
- {
- int comma_count = 0;
- int start_index = -1;
- int end_index = -1;
- int length = strlen(receiveStr);
- // 遍历字符串,统计逗号数量和记录起始和结束索引
- for (int i = 0; i < length; i++)
- {
- if (receiveStr[i] == ',')
- {
- comma_count++;
- if (comma_count == start)
- {
- start_index = i + 1; // 第start个逗号之后的字符
- }
- else if (comma_count == end)
- {
- if(start==1 && end==2)//*纬度去尾符号
- {
- end_index = i-1; // 第end个逗号之前的字符
- }
- else if(start==2 && end==3)//*经度去尾符号
- {
- end_index = i-1; // 第end个逗号之前的字符
- }
- else
- {
- end_index = i; // 第end个逗号之前的字符
- }
-
- break;
- }
- }
- }
-
- // 提取字符串并存储在result数组中
- if (start_index != -1 && end_index != -1 && start_index < end_index)
- {
- strncpy(result, receiveStr + start_index, end_index - start_index);
- result[end_index - start_index] = '\0'; // 添加字符串结束符
- }
- }
- void extractStringPoint(char* receiveStr, char* result, uint8_t start, uint16_t end)
- {
- int comma_count = 0;
- int start_index = -1;
- int end_index = -1;
- int length = strlen(receiveStr);
- // 遍历字符串,统计逗号数量和记录起始和结束索引
-
- for (int i = 0; i < length; i++)
- {
- if(start==0 && end==1)// = -> .
- {
- start_index = start; // 第start个逗号之后的字符
- if (receiveStr[i] == '.')
- {
- comma_count++;
- }
- else if (comma_count == end)
- {
- end_index = i-1; // 第end个逗号之前的字符
- break;
- }
- }
- else if(start==3 && end==4)
- {
- if (receiveStr[i] == '.')
- {
- comma_count++;
- if (comma_count == start)
- {
- start_index = i + 1; // 第start个逗号之后的字符
- }
- }
- else if(receiveStr[i] == ':')
- {
- end_index = i;
- }
- }
- else if(start==4 && end==5)
- {
- if (receiveStr[i] == ':')
- {
- comma_count=4;
- if (comma_count == start)
- {
- start_index = i+1; // 第start个逗号之后的字符
- }
- end_index = start_index+4;
- break;
- }
- }
-
- else
- {
- if (receiveStr[i] == '.')
- {
- comma_count++;
- if (comma_count == start)
- {
- start_index = i + 1; // 第start个逗号之后的字符
- }
- else if (comma_count == end)
- {
- end_index = i; // 第end个逗号之前的字符
- break;
- }
- }
- }
- }
-
- // 提取字符串并存储在result数组中
- if (start_index != -1 && end_index != -1 && start_index < end_index)
- {
- strncpy(result, receiveStr + start_index, end_index - start_index);
- result[end_index - start_index] = '\0'; // 添加字符串结束符
- }
- }
- double convertToDouble(char* str) {
- if(str == csatellitesNum)
- {
- uint8_t result;
- sscanf(str, "%hhu", &result);
- return result;
- }
- else
- {
- double result;
- sscanf(str, "%lf", &result);
- return result;
- }
- }
- char hex2asc(const char *hex)
- {
- char asc = 0;
- char a = (hex[0]>='A' && hex[0]<='F')?(hex[0]^32):hex[0];
- char b = (hex[1]>='A' && hex[1]<='F')?(hex[1]^32):hex[1];
- if ((a>='0' && a<='9' || a>='a' && a<='f') && (b>='0' && b<='9' || b>='a' && b<='f')){
- asc = ((('a'<=a && a<='f')?(a-'a')+10:a-'0')<<4)|(('a'<=b && b<='f')?(b-'a')+10:b-'0');
- }
- return asc;
- }
- uint8_t testHex2Asc(const char *hex) {
- char asc = hex2asc(hex);
- printf("Hex: %s\tASC: %d\n", hex, asc);
- return asc;
- }
- char *bin2hex(char *hex, const unsigned char *bin, int size)
- {
- size_t i;
- for(i=0; i<size; i++)
- {
- sprintf(hex+i*2, "%02x", bin[i]);
- }
- hex[i+i] = 0;
- return hex;
- }
- int hex2bin(unsigned char *bin, const char *hex)
- {
- const char *h = hex;
- unsigned char *b = bin;
- int rlt = 0;
- while(*h){
- *b++ = hex2asc(h);
- h = h + 2;
- rlt++;
- }
- return rlt;//长度
- }
- // 将单个十六进制数转换为 BCD 码
- uint8_t hexToBcd(uint8_t hex) {
- return ((hex / 10) << 4) | (hex % 10);
- }
- // 将整数数组中的所有十六进制数转换为 BCD 码
- void hexArrayToBcd(uint8_t* array, size_t length, uint8_t* out) {//时间用
- array[3]+=8;
- for (size_t i = 0; i < length; i++) {
- out[i] = hexToBcd(array[i]);
- }
- }
- void hexToBcd_arr(uint8_t* array, size_t length, uint8_t* out) {//通用
- for (size_t i = 0; i < length; i++) {
- out[i] = hexToBcd(array[i]);
- }
- }
- char input_strings[20]={0};
- char reIp0[10];
- char reIp1[10];
- char reIp2[10];
- char reIp3[10];
- char reIpP[10];
- Ipaddr ipaddr;
- MacSet macset;
- MacSet *macsetptr = &macset;
- char Newip[30];
- extern bool wdiFlag;
- char MqttReBuff[200];
- char MqttWorkBuff[200];
- char Mqtttotal_len[10];
- char payload_len[10];
- uint8_t Mqtttotal_lenu8=0;
- uint8_t payload_lenu8=0;
- void Process_str_collections(void) {
- // 循环遍历从0到macCount-1的每个索引
- for (int i = 0; i < macset.macCount; i++) {
- AtPRocess(
- lockinfo.SNname[i],
- macset.SNCONN[i],
- macset.SNED[i],
- macset.SNDIS[i]
- );
- }
- }
- char versionc[20]={0};
- void MqttRe(void)
- {
- if(strncmp((const char *)U4_4GrecvBuff, "+MQTTURC: \"publish\"", strlen("+MQTTURC: \"publish\""))==0)//接收到发布信息
- {
- memcpy(MqttReBuff,&U4_4GrecvBuff[2],U4_4GrecvLength-2);//全部copy
- //printf("@接收到Mqtt消息%s\r\n",MqttReBuff);
- extractString(MqttReBuff, Mqtttotal_len,4 ,5);//采集<total_len>
- extractString(MqttReBuff, payload_len,5 ,6);//采集<payload_len>
- Mqtttotal_lenu8 = atoi(Mqtttotal_len);
- payload_lenu8 = atoi(payload_len);
-
-
- //printf("%d,%d\r\n",Mqtttotal_lenu8,payload_lenu8);
- if(Mqtttotal_lenu8==payload_lenu8)
- {
- memcpy(MqttWorkBuff, &MqttReBuff[U4_4GrecvLength - payload_lenu8-4], payload_lenu8);
- printf("%s\r\n",MqttWorkBuff);
-
- }
- //*处理摘取字段
- if(strncmp((const char*)&MqttWorkBuff, "DTU+FLASH=deleteloc", strlen("DTU+FLASH=deleteloc"))==0)
- {
- dblocptr->headinfo.loc_pushIndex=0;
- dblocptr->headinfo.loc_pullIndex=0;
- Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
- printf("更新刻度成功\r\n");
- MQTT_PUB(0,topica,"Success","+MQTTURC: \"puback\"");
- }
- else if(strncmp((char*)MqttWorkBuff, "DTU+JT808_IMEI=", strlen("DTU+JT808_IMEI="))==0)//修改IME号
- {
- memcpy(DTUurc1,MqttWorkBuff+15,12);
- const char *hex = (const char *)DTUurc1; // 将 uint8_t * 转换为 const char *
- int size = strlen(hex) / 2; // 计算二进制数据的长度
- unsigned char *bin = (unsigned char *)malloc(size); // 分配足够的内存用于存储二进制数据
- rlt = hex2bin(bin, hex); // 调用hex2bin函数进行转换
- memcpy(DTUurc, bin, rlt); // 将 bin 中的 rlt 个字节复制到 MIPurc1 中 接收到的数据放入MIPurc1中
- free(bin); // 释放内存
- MQTT_PUB(0,topica,"Success","+MQTTURC: \"puback\"");
- reIME = true;
- HAL_Delay(500);
- }
- else if(strncmp((char*)MqttWorkBuff, "DTU+JT808_SERVER=", strlen("DTU+JT808_SERVER="))==0)
- {
- memcpy(input_strings,MqttWorkBuff+17,20);
- extractStringPoint(input_strings,reIp0,0,1);
- extractStringPoint(input_strings,reIp1,1,2);
- extractStringPoint(input_strings,reIp2,2,3);
- extractStringPoint(input_strings,reIp3,3,4);
- extractStringPoint(input_strings,reIpP,4,5);
- ipaddr.IP0 = atoi(reIp0);
- ipaddr.IP1 = atoi(reIp1);
- ipaddr.IP2 = atoi(reIp2);
- ipaddr.IP3 = atoi(reIp3);
- ipaddr.IPp = atoi(reIpP);
- //printf("%d.%d.%d.%d:%d",ipaddr.IP0,ipaddr.IP1,ipaddr.IP2,ipaddr.IP3,ipaddr.IPp);
- HAL_StatusTypeDef writeSta = Flash_WriteBytes((uint16_t*)&(ipaddr.IP0),ReIPAddr,5);
- if(writeSta == HAL_OK)
- {
- char *ptr = Newip;
- ptr += sprintf(ptr, "%d.", ipaddr.IP0);
- ptr += sprintf(ptr, "%d.", ipaddr.IP1);
- ptr += sprintf(ptr, "%d.", ipaddr.IP2);
- ptr += sprintf(ptr, "%d", ipaddr.IP3);
- printf("更换IP成功\r\n");
- MQTT_PUB(0,topica,"Success","+MQTTURC: \"puback\"");
- }
- //ptr += sprintf(ptr, ":%d", ipaddr.IPp);
- //printf("%s\r\n",Newip);
- HAL_Delay(500);
- printf("即将重启\r\n");
- wdiFlag = true;
- }
- else if(strncmp((char*)MqttWorkBuff, "DTU+VER=?", strlen("DTU+VER=?"))==0)
- {
- printf("%s\r\n",version);
- MQTT_PUB(0,topica,"Success","+MQTTURC: \"puback\"");
- }
-
- else if(strncmp((char*)MqttWorkBuff, "DTU+MANUALMODE=1", strlen("DTU+MANUALMODE=1"))==0)
- {
- ManualWork = 1;
- Flash_WriteBytes(&ManualWork,ManualWorkaddr,1);
- printf("手动模式开启\r\n");
- MQTT_PUB(0,topica,"Success","+MQTTURC: \"puback\"");
- }
- else if(strncmp((char*)MqttWorkBuff, "DTU+MANUALMODE=0", strlen("DTU+MANUALMODE=0"))==0)
- {
- ManualWork = 0;
- Flash_WriteBytes(&ManualWork,ManualWorkaddr,1);
- printf("手动模式关闭\r\n");
- MQTT_PUB(0,topica,"Success","+MQTTURC: \"puback\"");
- }
-
-
-
-
- HAL_StatusTypeDef WriteSta;
- //*PDA需求 485写入MAC号
- if(strncmp((char*)MqttWorkBuff, "DTU+ADDMAC=", strlen("DTU+ADDMAC="))==0)
- {
-
- macset.macCount=0;
- workedLock=0;
- memset(devices,0,8);
- erase_flash(MacDbBodyAddr);
- if(payload_lenu8>12){
- memcpy(macset.MACtemp[0],MqttWorkBuff+11,12);
- processPdadata(macset.MACtemp[0],macset.mactemp[0],macset.mac[0]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[0],MacDbBodyAddr,3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
- if(payload_lenu8>25){
- memcpy(macset.MACtemp[1],MqttWorkBuff+24,12);
- processPdadata(macset.MACtemp[1],macset.mactemp[1],macset.mac[1]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[1],MacDbBodyAddr+(macset.macCount*6),3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
- if(payload_lenu8>38){
- memcpy(macset.MACtemp[2],MqttWorkBuff+37,12);
- processPdadata(macset.MACtemp[2],macset.mactemp[2],macset.mac[2]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[2],MacDbBodyAddr+(macset.macCount*6),3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
- if(payload_lenu8>51){
- memcpy(macset.MACtemp[3],MqttWorkBuff+50,12);
- processPdadata(macset.MACtemp[3],macset.mactemp[3],macset.mac[3]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[3],MacDbBodyAddr+(macset.macCount*6),3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
- if(payload_lenu8>64){
- memcpy(macset.MACtemp[4],MqttWorkBuff+63,12);
- processPdadata(macset.MACtemp[4],macset.mactemp[4],macset.mac[4]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[4],MacDbBodyAddr+(macset.macCount*6),3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
- if(payload_lenu8>77){
- memcpy(macset.MACtemp[5],MqttWorkBuff+76,12);
- processPdadata(macset.MACtemp[5],macset.mactemp[5],macset.mac[5]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[5],MacDbBodyAddr+(macset.macCount*6),3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
- if(payload_lenu8>90){
- memcpy(macset.MACtemp[6],MqttWorkBuff+89,12);
- processPdadata(macset.MACtemp[6],macset.mactemp[6],macset.mac[6]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[6],MacDbBodyAddr+(macset.macCount*6),3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
- if(payload_lenu8>103){
- memcpy(macset.MACtemp[7],MqttWorkBuff+102,12);
- processPdadata(macset.MACtemp[7],macset.mactemp[7],macset.mac[7]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[7],MacDbBodyAddr+(macset.macCount*6),3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
-
-
- for(int i = 0; i < macset.macCount; i++) {
- memset(lockinfo.SNname[i], 0, 13);
- }
- if(WriteSta == HAL_OK)
- {
- printf("更新MAC存储完成共->%d\r\n",macset.macCount);
- }
- WriteSta = Flash_WriteBytes(&macsetptr->macCount,MacDbHeadAddr,1);
- if(WriteSta == HAL_OK)
- {
- printf("更新存储刻度完成\r\n");
- MQTT_PUB(0,topica,"Success","+MQTTURC: \"puback\"");
- }
- ReadSNname();//更新
- Process_str_collections();//处理连接字符串
- enterInterface_time = HAL_GetTick();
- menu.current=6;//提示mac
- refresh=true;
- }
-
-
-
-
- else if(strncmp((char*)MqttWorkBuff, "DTU+WORK=ALLOPEN", strlen("DTU+WORK=ALLOPEN"))==0)
- {
- enterInterface_time = HAL_GetTick();
- SET_MENU_STATUS(2,2,0,0);
- MQTT_PUB(0,topica,"Success","+MQTTURC: \"puback\"");
- Allopen=true;
- }
- else if(strncmp((char*)MqttWorkBuff, "DTU+WORK=ALLCLOSE", strlen("DTU+WORK=ALLCLOSE"))==0)
- {
- enterInterface_time = HAL_GetTick();
- SET_MENU_STATUS(2,1,1,1);
- MQTT_PUB(0,topica,"Success","+MQTTURC: \"puback\"");
- Allopen=true;
- }
-
-
- else
- {
- MQTT_PUB(0,topica,"Error","+MQTTURC: \"puback\"");
- }
-
-
-
-
-
-
-
-
- memset(U4_4GrecvBuff,0,BUFFER_SIZE);
- memset(MqttReBuff,0,U4_4GrecvLength);
- memset(MqttWorkBuff,0,payload_lenu8);
- }
-
-
-
-
- }
- //*485测试命令
- void Test485Re(void)
- {
- //*test485 模拟
- if(strncmp((char*)U1_485recvBuff, "+MIPURC: \"disconn\",1,1", strlen("+MIPURC: \"disconn\",1,1"))==0)//"disconn" 平台断连
- {
- Offline=true;
- uploaweork=false;
- printf("@U1与平台断开连接\r\n");
- memset(U1_485recvBuff,0,BUFFER_SIZE);
- }
- else if(strncmp((char*)U1_485recvBuff, "+MIPOPEN: 1,0", strlen("+MIPOPEN: 1,0"))==0)//连接平台
- {
- Offline=false;
- Online = true;
- uploaweork=true;
- printf("@U1设备已上线!!\r\n");
- refresh=true;
- memset(U1_485recvBuff,0,BUFFER_SIZE);
- }
- else if(strncmp((char*)&U1_485recvBuff, "DTU+FLASH=deleteloc", strlen("DTU+FLASH=deleteloc"))==0)//连接平台
- {
- dblocptr->headinfo.loc_pushIndex=0;
- dblocptr->headinfo.loc_pullIndex=0;
- Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
- memset(U1_485recvBuff,0,BUFFER_SIZE);
- printf("更新刻度成功\r\n");
- }
- else if(strncmp((char*)U1_485recvBuff, "DTU+JT808_IMEI=", strlen("DTU+JT808_IMEI="))==0)//修改IME号
- {
- memcpy(DTUurc1,U1_485recvBuff+15,12);
-
- const char *hex = (const char *)DTUurc1; // 将 uint8_t * 转换为 const char *
- int size = strlen(hex) / 2; // 计算二进制数据的长度
- unsigned char *bin = (unsigned char *)malloc(size); // 分配足够的内存用于存储二进制数据
- rlt = hex2bin(bin, hex); // 调用hex2bin函数进行转换
- memcpy(DTUurc, bin, rlt); // 将 bin 中的 rlt 个字节复制到 MIPurc1 中 接收到的数据放入MIPurc1中
- free(bin); // 释放内存
-
- //memset(DTUurc1,0,100);
- memset(U1_485recvBuff,0,BUFFER_SIZE);
- reIME = true;
- HAL_Delay(500);
- }
- else if(strncmp((char*)U1_485recvBuff, "DTU+JT808_SERVER=", strlen("DTU+JT808_SERVER="))==0)
- {
- memcpy(input_strings,U1_485recvBuff+17,20);
- extractStringPoint(input_strings,reIp0,0,1);
- extractStringPoint(input_strings,reIp1,1,2);
- extractStringPoint(input_strings,reIp2,2,3);
- extractStringPoint(input_strings,reIp3,3,4);
- extractStringPoint(input_strings,reIpP,4,5);
- ipaddr.IP0 = atoi(reIp0);
- ipaddr.IP1 = atoi(reIp1);
- ipaddr.IP2 = atoi(reIp2);
- ipaddr.IP3 = atoi(reIp3);
- ipaddr.IPp = atoi(reIpP);
- //printf("%d.%d.%d.%d:%d",ipaddr.IP0,ipaddr.IP1,ipaddr.IP2,ipaddr.IP3,ipaddr.IPp);
- HAL_StatusTypeDef writeSta = Flash_WriteBytes((uint16_t*)&(ipaddr.IP0),ReIPAddr,5);
- if(writeSta == HAL_OK)
- {
- char *ptr = Newip;
- ptr += sprintf(ptr, "%d.", ipaddr.IP0);
- ptr += sprintf(ptr, "%d.", ipaddr.IP1);
- ptr += sprintf(ptr, "%d.", ipaddr.IP2);
- ptr += sprintf(ptr, "%d", ipaddr.IP3);
- printf("更换IP成功\r\n");
- }
- //ptr += sprintf(ptr, ":%d", ipaddr.IPp);
- //printf("%s\r\n",Newip);
- memset(U1_485recvBuff,0,BUFFER_SIZE);
- HAL_Delay(500);
- printf("即将重启\r\n");
- wdiFlag = true;
- }
- else if(strncmp((char*)U1_485recvBuff, "DTU+VER=?", strlen("DTU+VER=?"))==0)
- {
- printf("%s\r\n",version);
- memset(U1_485recvBuff,0,BUFFER_SIZE);
- }
-
- else if(strncmp((char*)U1_485recvBuff, "DTU+WORK=ALLOPEN", strlen("DTU+WORK=ALLOPEN"))==0)
- {
- enterInterface_time = HAL_GetTick();
- SET_MENU_STATUS(2,2,0,0);
- Allopen=true;
- memset(U1_485recvBuff,0,BUFFER_SIZE);
- }
- else if(strncmp((char*)U1_485recvBuff, "DTU+WORK=ALLCLOSE", strlen("DTU+WORK=ALLCLOSE"))==0)
- {
- enterInterface_time = HAL_GetTick();
- SET_MENU_STATUS(2,1,1,1);
- Allopen=true;
- memset(U1_485recvBuff,0,BUFFER_SIZE);
- }
- else if(strncmp((char*)U1_485recvBuff, "DTU+MANUALMODE=1", strlen("DTU+MANUALMODE=1"))==0)
- {
- ManualWork = 1;
- Flash_WriteBytes(&ManualWork,ManualWorkaddr,1);
- printf("手动模式开启\r\n");
- memset(U1_485recvBuff,0,BUFFER_SIZE);
- }
- else if(strncmp((char*)U1_485recvBuff, "DTU+MANUALMODE=0", strlen("DTU+MANUALMODE=0"))==0)
- {
- ManualWork = 0;
- Flash_WriteBytes(&ManualWork,ManualWorkaddr,1);
- printf("手动模式关闭\r\n");
- memset(U1_485recvBuff,0,BUFFER_SIZE);
- }
- REPdaMode();//PDA 485 MQTT
- }
-
- void AtPRocess(char *value, char conn[],char connected[],char disconn[]) {
- // 使用snprintf代替sprintf以确保不会发生缓冲区溢出
- snprintf(conn, strlen(value) + 12, "AT+CONN=%s\r\n", value);
- snprintf(connected, strlen(value) + 14, "+CONNECTED:0,%s", value);
- snprintf(disconn, strlen(value) + 12, "+DISCONN:0,%s", value);
- // printf("%s\r\n", conn);
- // printf("%s\r\n", connected);
- // printf("%s\r\n", disconn);
- }
- void processPdadata(char MACtemp[], uint8_t mactemp[],uint16_t mac[])
- {
- const char *hex = (const char *)MACtemp; // 将 uint8_t * 转换为 const char *
- int size = strlen(hex) / 2; // 计算二进制数据的长度
- unsigned char *bin = (unsigned char *)malloc(size); // 分配足够的内存用于存储二进制数据
- rlt = hex2bin(bin, hex); // 调用hex2bin函数进行转换
- memcpy(mactemp, bin, rlt); // 将 bin 中的 rlt 个字节复制到 MIPurc1 中 接收到的数据放入MIPurc1中
- free(bin); // 释放内存
- mac[0] = mactemp[0]<<8|mactemp[1];
- mac[1] = mactemp[2]<<8|mactemp[3];
- mac[2] = mactemp[4]<<8|mactemp[5];
- }
- char* convertHexToString(const uint8_t* data, size_t dataSize) {
- char* output = (char*)malloc((dataSize * 2 + 1) * sizeof(char));
- if (output == NULL) {
- return NULL;
- }
- for (size_t i = 0; i < dataSize; i++) {
- sprintf(output + (i * 2), "%02X", data[i]);
- }
- output[dataSize * 2] = '\0';
- return output;
- }
- #define MAC_LENGTH 12
- #define MAC_DB_ENTRY_SIZE 3
- void REPdaMode(void)
- {
- HAL_StatusTypeDef WriteSta;
- //*PDA需求 485写入MAC号
- if(strncmp((char*)U1_485recvBuff, "DTU+ADDMAC", strlen("DTU+ADDMAC"))==0)
- {
- macset.macCount=0;
- workedLock=0;
- memset(devices,0,8);
- erase_flash(MacDbBodyAddr);
- if(U1_485recvLength>12){
- memcpy(macset.MACtemp[0],U1_485recvBuff+11,12);
- processPdadata(macset.MACtemp[0],macset.mactemp[0],macset.mac[0]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[0],MacDbBodyAddr,3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
- if(U1_485recvLength>25){
- memcpy(macset.MACtemp[1],U1_485recvBuff+24,12);
- processPdadata(macset.MACtemp[1],macset.mactemp[1],macset.mac[1]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[1],MacDbBodyAddr+(macset.macCount*6),3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
- if(U1_485recvLength>38){
- memcpy(macset.MACtemp[2],U1_485recvBuff+37,12);
- processPdadata(macset.MACtemp[2],macset.mactemp[2],macset.mac[2]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[2],MacDbBodyAddr+(macset.macCount*6),3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
- if(U1_485recvLength>51){
- memcpy(macset.MACtemp[3],U1_485recvBuff+50,12);
- processPdadata(macset.MACtemp[3],macset.mactemp[3],macset.mac[3]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[3],MacDbBodyAddr+(macset.macCount*6),3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
- if(U1_485recvLength>64){
- memcpy(macset.MACtemp[4],U1_485recvBuff+63,12);
- processPdadata(macset.MACtemp[4],macset.mactemp[4],macset.mac[4]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[4],MacDbBodyAddr+(macset.macCount*6),3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
- if(U1_485recvLength>77){
- memcpy(macset.MACtemp[5],U1_485recvBuff+76,12);
- processPdadata(macset.MACtemp[5],macset.mactemp[5],macset.mac[5]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[5],MacDbBodyAddr+(macset.macCount*6),3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
- if(U1_485recvLength>90){
- memcpy(macset.MACtemp[6],U1_485recvBuff+89,12);
- processPdadata(macset.MACtemp[6],macset.mactemp[6],macset.mac[6]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[6],MacDbBodyAddr+(macset.macCount*6),3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
- if(U1_485recvLength>103){
- memcpy(macset.MACtemp[7],U1_485recvBuff+102,12);
- processPdadata(macset.MACtemp[7],macset.mactemp[7],macset.mac[7]);
- WriteSta= Flash_WriteBytes(macsetptr->mac[7],MacDbBodyAddr+(macset.macCount*6),3);
- if(WriteSta== HAL_OK) macset.macCount += 1;}
-
-
-
- for(int i = 0; i < macset.macCount; i++) {
- memset(lockinfo.SNname[i], 0, 13);
- }
- if(WriteSta == HAL_OK)
- {
- printf("更新MAC存储完成共->%d\r\n",macset.macCount);
- }
- WriteSta = Flash_WriteBytes(&macsetptr->macCount,MacDbHeadAddr,1);
- if(WriteSta == HAL_OK)
- {
- printf("更新存储刻度完成\r\n");
- }
- ReadSNname();//更新
- Process_str_collections();//处理连接字符串
-
-
- enterInterface_time = HAL_GetTick();
- menu.current=6;//提示mac
- refresh=true;
- memset(U1_485recvBuff,0,BUFFER_SIZE);
- }
- }
- bool snConnected[NUM_OF_DEVICES] = {false};
- void ReBTcall(void)
- {
- for (int i = 0; i < NUM_OF_DEVICES; ++i) {
- if (strncmp((char*)autoRe, macsetptr->SNED[i], strlen(macsetptr->SNED[i])) == 0) {
- snConnected[i] = true;
- memset(autoRe, 0, BUFFER_SIZE);
- break; // Exit the loop once a match is found
- }
- }
- }
- //*工作命令
- void ReMIPURC(void)//DTU
- {
- //*设备上线,发送成功
- if(strncmp((char*)U4_4GrecvBuff, "+MIPOPEN: 1,0", strlen("+MIPOPEN: 1,0"))==0)//连接平台
- {
- memset(U4_4GrecvBuff,0,BUFFER_SIZE);
- }
- ///*定位信息(MGNSS)
- else if(strncmp((char*)U4_4GrecvBuff, "+MGNSSURC: \"state\",1", strlen("+MGNSSURC: \"state\",1"))==0)
- {
- printf("@MGNSS设置成功\r\n");
-
- memset(U4_4GrecvBuff,0,strlen("+MGNSSURC: \"state\",1"));
- }
- else if(strncmp((char*)U4_4GrecvBuff, "+MGNSSURC: \"state\",0", strlen("+MGNSSURC: \"state\",0"))==0)//断开平台
- {
- printf("@主动取消GNSS\r\n");
- memset(U4_4GrecvBuff,0,strlen("+MGNSSURC: \"state\",0"));
- }
- ///*定位信息(基站)
- else if(((strncmp((char*)U4_4GrecvBuff, "+MGNSSLOC", strlen("+MGNSSLOC"))==0) || (strncmp((char*)U4_4GrecvBuff, "OK", strlen("OK"))==0)) && MgnssFlag) //监测平台回复+MGNSSLOC OK4f4b
- {
- memcpy(MGNSSLOC,&U4_4GrecvBuff[11],75);
- GnssFlag=true;
- memset(U4_4GrecvBuff,0,BUFFER_SIZE);
- }
- ///*掉线
- #if open4G ==1
- else if(strncmp((char*)U4_4GrecvBuff, "+MIPURC: \"disconn\",1,1", strlen("+MIPURC: \"disconn\",1,1"))==0)//"disconn" 平台断连
- {
- Offline=true;
- printf("@未发送成功,平台断开连接\r\n");
- memset(U4_4GrecvBuff,0,BUFFER_SIZE);
- uploaweork = false;
- reconn();//重连
- }
- 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
- {
- //TODO
- printf("@SIM卡缺失\r\n");
- Offline=true;
- signal = false;
- menu.current = 0xBB;
- tipsflag = NoSIM;
- refresh=true;
- memset(U4_4GrecvBuff,0,BUFFER_SIZE);
- uploaweork = false;
- reconn();//重连
- }
-
- else if((strncmp((char*)U4_4GrecvBuff, "+MIPCALL: 1,0", strlen("+MIPCALL: 1,0"))==0))//意外断开平台连接!!!!//TCP未知错误
- {
- //TODO
- Offline=true;
- signal = false;
- printf("@与平台断开连接\r\n");
- memset(U4_4GrecvBuff,0,BUFFER_SIZE);
- uploaweork = false;
- reconn();//重连
-
- }
- else if( (strncmp((char*)U4_4GrecvBuff, "+CME ERROR: 550", strlen("+CME ERROR: 550"))==0))
- {
- Offline=true;
- signal = false;
- printf("@未发送成功->TCP/IP未知错误\r\n");
- memset(U4_4GrecvBuff,0,BUFFER_SIZE);
- uploaweork = false;
- reconn();//重连
-
- }
- else if((strncmp((char*)U4_4GrecvBuff, "+MIPOPEN: 1,571", strlen("+MIPOPEN: 1,571"))==0))//PDP激活失败
- {
- //TODO
- Offline=true;
- printf("@未发送成功,PDP激活失败\r\n");
- memset(U4_4GrecvBuff,0,BUFFER_SIZE);
- uploaweork = false;
- reconn();//重连
- }
- #endif
- else if(U4_4GrecvBuff[1]== 0x43 && U4_4GrecvBuff[2]== 0x53 && U4_4GrecvBuff[3]== 0x51)//CSQ 信号
- {
- memcpy(CSQ,U4_4GrecvBuff,U4_4GrecvLength);
- dblocptr->location.CSQ = (uint8_t)(CSQ[6]&0xf*10)+(CSQ[7]&0xf);
- memset(CSQ,0,12);
- memset(U4_4GrecvBuff,0,BUFFER_SIZE);
- }
- else if(strncmp((char*)U4_4GrecvBuff, "+MIPURC", strlen("+MIPURC"))==0) //监测平台回复+MIPURC:
- {
- uint8_t high_byte = (U4_4GrecvBuff[18]&0x0f) *10;
- uint8_t low_byte = U4_4GrecvBuff[19]&0x0f;
- hccd = high_byte + low_byte;
- memcpy(MIPurc1,&U4_4GrecvBuff[21],hccd*2);
- const char *hex = (const char *)MIPurc1; // 将 uint8_t * 转换为 const char *
- int size = strlen(hex) / 2; // 计算二进制数据的长度
- unsigned char *bin = (unsigned char *)malloc(size); // 分配足够的内存用于存储二进制数据
- rlt = hex2bin(bin, hex); // 调用hex2bin函数进行转换
- memcpy(MIPurc, bin, rlt); // 将 bin 中的 rlt 个字节复制到 MIPurc1 中 接收到的数据放入MIPurc1中
- free(bin); // 释放内存
-
- memset(U4_4GrecvBuff,0,BUFFER_SIZE);
- memset(MIPurc1,0,100);
-
- }
- }
- void MIPURCHandle(void)
- {
- #if open4G == 1
- if(MIPurc[0]==0x7E)
- {
- uint16_t PTXXID = MIPurc[1]<<8 | MIPurc[2]; //消息ID
- uint16_t xxtcLen = MIPurc[3]<<8 | MIPurc[4]; //数据长度
- uint16_t xxRE = MIPurc[15]<<8 | MIPurc[16]; //回复ID
- uint8_t YESorNO = MIPurc[17]; //00 success ; 01 fail
-
- if(PTXXID==XXID_pttyyd) //收到平台通用应答0x8001
- {
- if(xxRE == MessageID_authentication)//回复鉴权ID
- {
- if(YESorNO==YES)
- {
- printf("@鉴权应答yes\r\n");
- authFlag = true;
-
- Offline=false; //待判定假消息
- Online = true; //待判定假消息
- uploaweork=true;
- }
- else if(YESorNO==NO)
- {
- printf("@鉴权应答no\r\n");
- }
- memset(MIPurc,0,rlt);//rlt下发长度
- }
- else if(xxRE == MessageID_heartbeat)//回复鉴权ID
- {
- if(YESorNO==YES)
- {
- printf("@心跳应答yes\r\n");
- printf("@TCP连接成功!!\r\n");
- menu.current=0;
- refresh=true;
- }
- else if(YESorNO==NO)
- {
- printf("@心跳应答no\r\n");
- }
- memset(MIPurc,0,rlt);//rlt下发长度
-
- }
- else if(xxRE == MessageID_location)//回复鉴权ID
- {
- if(YESorNO==YES)
- {
- printf("@地址应答yes\r\n");
- }
- else if(YESorNO==NO)
- {
- printf("@地址应答no\r\n");
- }
- memset(MIPurc,0,rlt);//rlt下发长度
- }
- else if(xxRE == MessageID_Getauth)//获取权限
- {
- if(YESorNO==YES)
- {
- printf("@权限应答yes\r\n");
- reAuth=true;
- }
- else if(YESorNO==NO)
- {
- printf("@权限应答no\r\n");
- reAuth=false;
- }
- memset(MIPurc,0,rlt);//rlt下发长度
- }
- else if(xxRE == MessageID_uploadLock)//锁信息上传
- {
- if(YESorNO==YES)
- {
- printf("@锁信息上传应答yes\r\n");
- if(sendCmd_BT("AT+DISCONN=0\r\n","ERROR",1,2))
- {
- printf("已断开连接\r\n");
- }
- }
- else if(YESorNO==NO)
- {
- printf("@锁信息上传应答no\r\n");
- }
-
- memset(MIPurc,0,rlt);//rlt下发长度
- }
- }
- else if(PTXXID == XXID_ptxxtc) //收到平台消息透传 8900
- {
- authFlag = true;
- Offline=false; //待判定假消息
- Online = true; //待判定假消息
- uploaweork=true;
-
- uint8_t tcsjLen = MIPurc[13];
- memcpy(MIPurcXXTCSJ,&MIPurc[13],xxtcLen);
- printf("@得到透传数据,%d\r\n",tcsjLen);
- memset(MIPurc,0,rlt);//rlt下发长度
- }
- }
- else if(authFlag)
- {
- authFlag = false;
- HAL_Delay(500);
- uint8_t test[] = {0x05}; //test心跳
- tt808FsFunc(test,1,MessageID_heartbeat); //test心跳
- }
- #endif
- else if(reIME)
- {
- reIME=false;
- phonenum[0] = DTUurc[0]<<8|DTUurc[1];
- phonenum[1] = DTUurc[2]<<8|DTUurc[3];
- phonenum[2] = DTUurc[4]<<8|DTUurc[5];
- phonenull =false;
- Flash_WriteBytes(phonenum,phoneNumADDR,3);//更新ime
- //memset(DTUurc,0,100);
- printf("IMEI设置完成\r\n");
- printf("即将重启\r\n");
- wdiFlag = true;
- }
- }
- time_t timestamp ;
- void time_bj(void)
- {
- struct tm timeinfo;
- timeinfo.tm_year = tt808.Rtime[0]+2000-1900;
- timeinfo.tm_mon = tt808.Rtime[1]-1;
- timeinfo.tm_mday = tt808.Rtime[2];
- timeinfo.tm_hour = tt808.Rtime[3]-8;
- timeinfo.tm_min = tt808.Rtime[4];
- timeinfo.tm_sec = tt808.Rtime[5];
- timestamp = mktime(&timeinfo);
-
- dblocptr->location.timeStamp = timestamp;
- }
- void ReU4Proces(void)
- {
- if(GnssFlag)
- {
- GnssFlag=false;
- RTCtime();//同步时间
- // 调用函数提取字符串
- extractString(MGNSSLOC, cSpeed,7 ,8);//采集
- dSpeed = convertToDouble(cSpeed); //转换浮点数
- dSpeed*=10;
- // 调用函数提取字符串
- extractString(MGNSSLOC, clatitude,1 ,2);//采集
- dlatitude = convertToDouble(clatitude); //转换浮点数
- uint32_t latitudetemp=convertGPS(dlatitude);
- dblocptr->location.latitudeH = (latitudetemp>>16)&0xFFFF;
- dblocptr->location.latitudeH = swapBytes16(dblocptr->location.latitudeH);//转换H字节
- dblocptr->location.latitudeL = (latitudetemp)&0xFFFF;
- dblocptr->location.latitudeL = swapBytes16(dblocptr->location.latitudeL);//转换L字节
-
- extractString(MGNSSLOC, clongitude,2 ,3);//采集
- dlongitude = convertToDouble(clongitude); //转换浮点数
- uint32_t longitudetemp=convertGPS(dlongitude);
- dblocptr->location.longitudeH = (longitudetemp>>16)&0xFFFF;
- dblocptr->location.longitudeH = swapBytes16(dblocptr->location.longitudeH);//转换H字节
- dblocptr->location.longitudeL = (longitudetemp)&0xFFFF;
- dblocptr->location.longitudeL = swapBytes16(dblocptr->location.longitudeL);//转换L字节
-
- // printf("%d\r\n",dblocptr->location.latitude);
- // printf("%d\r\n",dblocptr->location.longitude);
- // printf("%08X\r\n",dblocptr->location.latitude);
- // printf("%08X\r\n",dblocptr->location.longitude);
-
- extractString(MGNSSLOC, csatellitesNum,10 ,11);//采集卫星个数
- dblocptr->location.satellitesNum = convertToDouble(csatellitesNum); //转换浮点数
- //printf("%d",tt808.satellitesNum);
-
-
- dblocptr->location.speed = (uint16_t)dSpeed;
- memset(MGNSSLOC,0,100);
- }
- }
- //*离线蓝牙锁
|