|
@@ -19,6 +19,10 @@ 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;
|
|
@@ -44,37 +48,63 @@ bool GnssFlag = false;
|
|
|
bool Offline = false;
|
|
|
bool Retrans = false;
|
|
|
bool Online = false;
|
|
|
+bool reIME = 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]; //消息数据
|
|
|
void MessageHandle(uint16_t MessageID)
|
|
|
{
|
|
|
|
|
|
- uint16_t MessageAttributeData = Messagetemp_length;
|
|
|
- if(MessageID ==MessageID_Retrans)
|
|
|
+ Flash_ReadBytes((uint16_t*)&(tt808.LSH),tt808serialNum,1);//读取loc头部是否发生写入
|
|
|
+ if(tt808.LSH==0xFFFF)
|
|
|
{
|
|
|
- MessageAttributeData+=3;
|
|
|
+ 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); //消息属性
|
|
|
- header[4] = 0x00;
|
|
|
- header[5] = 0x00;
|
|
|
- header[6] = 0x16;
|
|
|
- header[7] = 0x00;
|
|
|
- header[8] = 0x00;
|
|
|
- header[9] = 0x08; //“手机号”
|
|
|
- header[10] = ((tt808.LSH>>8)&0xff);;
|
|
|
- header[11] = (tt808.LSH&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; //“手机号”
|
|
|
+ }
|
|
|
+ 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
|
|
@@ -89,14 +119,14 @@ void MessageHandle(uint16_t MessageID)
|
|
|
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");
|
|
|
|
|
|
|
|
|
- printf("\r\n");
|
|
|
- char TCPvalue[100];
|
|
|
+//#if open4G ==1
|
|
|
+ char TCPvalue[120];
|
|
|
char *ptr = TCPvalue;
|
|
|
ptr += sprintf(ptr, "AT+MIPSEND=1,%d,\"",index);
|
|
|
for (int i = 0; i < index; i++) {
|
|
@@ -105,10 +135,13 @@ void MessageHandle(uint16_t MessageID)
|
|
|
sprintf(ptr, "\"\r\n");//TCPvalue
|
|
|
if(sendCmd_4G(TCPvalue, "+MIPSEND:", 1, 1))//发送
|
|
|
{
|
|
|
- printf("#发送完成\r\n");
|
|
|
+ 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);
|
|
@@ -125,9 +158,7 @@ uint8_t Message_bodydata(uint8_t *Message, uint8_t length, uint8_t outMessage[],
|
|
|
{
|
|
|
int index = 0;
|
|
|
uint8_t temp_length = 0;//加首尾 25/23/crc
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
if(MessageID==MessageID_authentication || MessageID==MessageID_heartbeat)//不加头尾(鉴权、心跳)
|
|
|
{
|
|
|
temp_length = length;//不加首尾
|
|
@@ -151,13 +182,6 @@ uint8_t Message_bodydata(uint8_t *Message, uint8_t length, uint8_t outMessage[],
|
|
|
//状态标志/纬度/经度/速度
|
|
|
|
|
|
uint8_t temp_Message[temp_length];
|
|
|
-
|
|
|
-
|
|
|
- dblocptr->location.statusFlag = swapBytes32(dblocptr->location.statusFlag);
|
|
|
- dblocptr->location.latitude = swapBytes32(dblocptr->location.latitude);
|
|
|
- dblocptr->location.longitude = swapBytes32(dblocptr->location.longitude);
|
|
|
- dblocptr->location.speed = swapBytes16(dblocptr->location.speed);
|
|
|
-
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
temp_Message[index++] = Message[i]; // 将消息头拷贝到报文中
|
|
|
}
|
|
@@ -171,12 +195,6 @@ uint8_t Message_bodydata(uint8_t *Message, uint8_t length, uint8_t outMessage[],
|
|
|
else if(MessageID==MessageID_Retrans)// 补传0704+5
|
|
|
{
|
|
|
temp_length = length;//不加首尾
|
|
|
- //状态标志/纬度/经度/速度
|
|
|
- dblocptr->temppull.statusFlag = swapBytes32(dblocptr->temppull.statusFlag);
|
|
|
- dblocptr->temppull.latitude = swapBytes32(dblocptr->temppull.latitude);
|
|
|
- dblocptr->temppull.longitude = swapBytes32(dblocptr->temppull.longitude);
|
|
|
- dblocptr->temppull.speed = swapBytes16(dblocptr->temppull.speed);
|
|
|
-
|
|
|
uint8_t temp_Message[temp_length];
|
|
|
|
|
|
temp_Message[index++] = 0x00;
|
|
@@ -215,11 +233,6 @@ uint8_t Message_bodydata(uint8_t *Message, uint8_t length, uint8_t outMessage[],
|
|
|
outMessage[i]=temp_Message[i];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- //test
|
|
|
-// for (int i = 0; i < temp_length; i++) {
|
|
|
-// printf("%02X ", temp_Message[i]); // 以十六进制格式打印每个元素
|
|
|
-// }
|
|
|
return temp_length;
|
|
|
}
|
|
|
|
|
@@ -284,6 +297,34 @@ void extractString(char* receiveStr, char* result, uint8_t start, uint16_t end)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+void process_string(char** input_strings, char** output_strings, int start_index, int end_index) {
|
|
|
+ char* start_ptr;
|
|
|
+ char* end_ptr;
|
|
|
+ char* input = input_strings[start_index];
|
|
|
+ int count = 0;
|
|
|
+
|
|
|
+ if (start_index == 4) {
|
|
|
+ start_ptr = strchr(input, ':') + 1; // 寻找第一个冒号,并指向冒号后的字符
|
|
|
+ count = sscanf(start_ptr, "%d", &output_strings[4]);
|
|
|
+ } else {
|
|
|
+ start_ptr = strchr(input, '=') + 1; // 寻找第一个等号,并指向等号后的字符
|
|
|
+ for (int i = 0; i <= end_index; i++) {
|
|
|
+ end_ptr = strchr(start_ptr, '.'); // 寻找下一个点号,并指向点号后的字符
|
|
|
+ if (end_ptr == NULL) {
|
|
|
+ end_ptr = strchr(start_ptr, '\0'); // 如果是最后一个区间,指向字符串末尾
|
|
|
+ }
|
|
|
+ if (end_ptr != NULL) {
|
|
|
+ *end_ptr = '\0'; // 将点号替换为字符串结束符,截断字符串
|
|
|
+ count = sscanf(start_ptr, "%d", &output_strings[i]);
|
|
|
+ start_ptr = end_ptr + 1; // 移动指针到下一个区间的开头
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
double convertToDouble(char* str) {
|
|
|
if(str == csatellitesNum)
|
|
|
{
|
|
@@ -344,67 +385,107 @@ uint8_t hexToBcd(uint8_t hex) {
|
|
|
return ((hex / 10) << 4) | (hex % 10);
|
|
|
}
|
|
|
// 将整数数组中的所有十六进制数转换为 BCD 码
|
|
|
-void hexArrayToBcd(uint8_t* array, size_t length, uint8_t* out) {
|
|
|
+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) {//通用
|
|
|
|
|
|
-void ReMIPURC(void)
|
|
|
+ for (size_t i = 0; i < length; i++) {
|
|
|
+ out[i] = hexToBcd(array[i]);
|
|
|
+ }
|
|
|
+}
|
|
|
+char* input_strings[]={0};
|
|
|
+char* reIp0[5];
|
|
|
+char* reIp1[5];
|
|
|
+char* reIp2[5];
|
|
|
+char* reIp3[5];
|
|
|
+char* reIpP[5];
|
|
|
+
|
|
|
+void Test485Re(void)
|
|
|
{
|
|
|
- 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 *
|
|
|
+ //*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+IME", strlen("DTU+IME"))==0)//修改IME号
|
|
|
+ {
|
|
|
+ memcpy(DTUurc1,&U1_485recvBuff[8],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(MIPurc, bin, rlt); // 将 bin 中的 rlt 个字节复制到 MIPurc1 中 接收到的数据放入MIPurc1中
|
|
|
+ memcpy(DTUurc, bin, rlt); // 将 bin 中的 rlt 个字节复制到 MIPurc1 中 接收到的数据放入MIPurc1中
|
|
|
free(bin); // 释放内存
|
|
|
|
|
|
- memset(U4_4GrecvBuff,0,BUFFER_SIZE);
|
|
|
- memset(MIPurc1,0,100);
|
|
|
-
|
|
|
+ //memset(DTUurc1,0,100);
|
|
|
+ memset(U1_485recvBuff,0,BUFFER_SIZE);
|
|
|
+ reIME = true;
|
|
|
}
|
|
|
+ else if(strncmp((char*)U1_485recvBuff, "DTU+IP", strlen("DTU+IP"))==0)
|
|
|
+ {
|
|
|
+ printf("更换IP\r\n");
|
|
|
+ memcpy(input_strings,U1_485recvBuff+7,20);
|
|
|
+// process_string(input_strings,reIp0,0,1);//获取192
|
|
|
+// process_string(input_strings,reIp1,1,2);//获取168
|
|
|
+// process_string(input_strings,reIp2,2,3);//获取1
|
|
|
+// process_string(input_strings,reIp3,3,4);//获取2
|
|
|
+// process_string(input_strings,reIpP,4,5);//获取port
|
|
|
+ memset(U1_485recvBuff,0,BUFFER_SIZE);
|
|
|
+ }
|
|
|
+}
|
|
|
+void ReMIPURC(void)
|
|
|
+{
|
|
|
+//*工作
|
|
|
+
|
|
|
+//*设备上线,发送成功
|
|
|
+ if(strncmp((char*)U4_4GrecvBuff, "+MIPOPEN: 1,0", strlen("+MIPOPEN: 1,0"))==0)//连接平台
|
|
|
+ {
|
|
|
+// Offline=false; //待判定假消息
|
|
|
+// Online = true; //待判定假消息
|
|
|
+// uploaweork=true;
|
|
|
+ printf("@TCP连接成功!!\r\n");
|
|
|
+ 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, "+MIPURC: \"di", strlen("+MIPURC: \"di"))==0)//"disconn" 平台断连
|
|
|
- {
|
|
|
- Offline=true;
|
|
|
- printf("@与平台断开连接\r\n");
|
|
|
- //ML307AReset();//与平台断开连接 offline
|
|
|
- memset(U4_4GrecvBuff,0,BUFFER_SIZE);
|
|
|
- }
|
|
|
- //*连接成功 Offline=false;
|
|
|
-
|
|
|
- else if(strncmp((char*)U4_4GrecvBuff, "+MIPOPEN: 1,0", strlen("+MIPOPEN: 1,0"))==0)//连接平台
|
|
|
- {
|
|
|
- Offline=false;
|
|
|
- Online = true;
|
|
|
- printf("@设备已上线!!\r\n");
|
|
|
- module4G_F = true;
|
|
|
- menu.current = 0xBB;
|
|
|
- tipsflag = Back;
|
|
|
- refresh=true;
|
|
|
- memset(U4_4GrecvBuff,0,BUFFER_SIZE);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
+///*定位信息(基站)
|
|
|
else if(((strncmp((char*)U4_4GrecvBuff, "+MGNSSLOC", strlen("+MGNSSLOC"))==0) || (strncmp((char*)U4_4GrecvBuff, "OK", strlen("OK"))==0)) && MgnssFlag) //监测平台回复+MGNSSLOC OK4f4b
|
|
|
{
|
|
|
|
|
@@ -412,6 +493,16 @@ void ReMIPURC(void)
|
|
|
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
|
|
@@ -422,36 +513,44 @@ void ReMIPURC(void)
|
|
|
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) || (strncmp((char*)U4_4GrecvBuff, "+CME ERROR: 550", strlen("+CME ERROR: 550"))==0))//意外断开平台连接!!!!//TCP未知错误
|
|
|
+ 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");
|
|
|
+ printf("@未发送成功,PDP激活失败\r\n");
|
|
|
memset(U4_4GrecvBuff,0,BUFFER_SIZE);
|
|
|
-
|
|
|
+ uploaweork = false;
|
|
|
+ reconn();//重连
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-// else if(strncmp((char*)U4_4GrecvBuff+1, "CSQ", strlen("CSQ")))//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);
|
|
|
-// }
|
|
|
+#endif
|
|
|
else if(U4_4GrecvBuff[1]== 0x43 && U4_4GrecvBuff[2]== 0x53 && U4_4GrecvBuff[3]== 0x51)//CSQ 信号
|
|
|
{
|
|
|
memcpy(CSQ,U4_4GrecvBuff,U4_4GrecvLength);
|
|
@@ -459,10 +558,28 @@ void ReMIPURC(void)
|
|
|
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
|
|
@@ -471,8 +588,7 @@ void MIPURCHandle(void)
|
|
|
uint8_t YESorNO = MIPurc[17]; //00 success ; 01 fail
|
|
|
|
|
|
if(PTXXID==XXID_pttyyd) //收到平台通用应答0x8001
|
|
|
- {
|
|
|
-
|
|
|
+ {
|
|
|
if(xxRE == MessageID_authentication)//回复鉴权ID
|
|
|
{
|
|
|
if(YESorNO==YES)
|
|
@@ -510,20 +626,16 @@ void MIPURCHandle(void)
|
|
|
printf("@地址应答no\r\n");
|
|
|
}
|
|
|
memset(MIPurc,0,rlt);//rlt下发长度
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
else if(PTXXID == XXID_ptxxtc) //收到平台消息透传 8900
|
|
|
{
|
|
|
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;
|
|
@@ -531,6 +643,18 @@ void MIPURCHandle(void)
|
|
|
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("IME设置\r\n");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -567,12 +691,19 @@ void ReU4Proces(void)
|
|
|
// 调用函数提取字符串
|
|
|
extractString(MGNSSLOC, clatitude,1 ,2);//采集
|
|
|
dlatitude = convertToDouble(clatitude); //转换浮点数
|
|
|
- dblocptr->location.latitude = convertGPS(dlatitude);
|
|
|
+ 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); //转换浮点数
|
|
|
- dblocptr->location.longitude = convertGPS(dlongitude);
|
|
|
-
|
|
|
+ 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);
|
|
@@ -586,11 +717,9 @@ void ReU4Proces(void)
|
|
|
|
|
|
dblocptr->location.speed = (uint16_t)dSpeed;
|
|
|
|
|
|
-
|
|
|
if(dSpeed !=0 && dlongitude!=0 && dlatitude!=0) //有数据进行更新!
|
|
|
{
|
|
|
- signal = true;
|
|
|
-
|
|
|
+ signal = true;
|
|
|
if(menu.current == 0xBB && tipsflag!= ConnOK)
|
|
|
{
|
|
|
menu.current = 0;
|
|
@@ -611,78 +740,24 @@ void ReU4Proces(void)
|
|
|
tipsflag = Nosignal;
|
|
|
refresh=true;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
memset(MGNSSLOC,0,100);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-int countregular = 0;
|
|
|
-void Regular_reporting_Loc(void)
|
|
|
-{
|
|
|
- countregular+=1;
|
|
|
- if(countregular==3 && !Offline )//在线状态10s更新状态,30s上传 (各种状态正常在线,直接上传信息)
|
|
|
- {
|
|
|
- countregular=0;
|
|
|
- tt808FsFunc((uint8_t*)&(dblocptr->location.alarmFlag), 34, MessageID_location);
|
|
|
- }
|
|
|
+//int countregular = 0;
|
|
|
+//void Regular_reporting_Loc(void)
|
|
|
+//{
|
|
|
+// countregular+=1;
|
|
|
+// if(countregular==3 && !Offline )//在线状态10s更新状态,30s上传 (各种状态正常在线,直接上传信息)
|
|
|
+// {
|
|
|
+// countregular=0;
|
|
|
+// tt808FsFunc((uint8_t*)&(dblocptr->location.alarmFlagH), 34, MessageID_location);
|
|
|
+// }
|
|
|
|
|
|
-
|
|
|
-}
|
|
|
+//
|
|
|
+//}
|
|
|
+//+MIPURC: "disconn",1,1
|
|
|
|
|
|
-void pushpullWork(void)
|
|
|
-{
|
|
|
- pushpullcount++;
|
|
|
- if(Offline && pushpullcount==10000)//掉线状态10s入库定位记录
|
|
|
- {
|
|
|
-
|
|
|
- RTCtime();//写入做参考
|
|
|
- printf("@@@设备掉线,执行入库操作!!%d\r\n",dblocptr->temppush.loc_pushIndex);
|
|
|
- Database_Push(0);
|
|
|
-
|
|
|
- //*每10s重连平台
|
|
|
- char TCPconnvalue[100];
|
|
|
- TcpConn(TCPconnvalue, 1, JLPTIP, JLPTPORT,0); //cid=1 tcpConnmode=0 普通模式
|
|
|
- if(sendCmd_4G(TCPconnvalue, "+MIPOPEN: 1,0", 1, 1)) //TCP连接 0普通模式 2缓存模式 1透传模式
|
|
|
- {
|
|
|
- printf("@@@TCP连接完成\r\n");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- printf("@@@重连失败!\r\n");
|
|
|
- }
|
|
|
- }
|
|
|
- else if(Retrans && MiddleObj)//重传 7e0704002701820200777700060001000022000000000000000301cd8b7007278acd00000000000023051918174830011e310103b77e
|
|
|
- {
|
|
|
-
|
|
|
- tt808FsFunc((uint8_t*)&(dblocptr->temppull.alarmFlag), 39, MessageID_Retrans);
|
|
|
- printf("出库%d操作完成,当前索引%d\r\n",dblocptr->headinfo.loc_pullIndex-1,dblocptr->headinfo.loc_pullIndex);
|
|
|
- MiddleObj = false;
|
|
|
- }
|
|
|
- else if(Online && !MiddleObj && pushpullcount==1000) //上线出库
|
|
|
- {
|
|
|
- pushpullcount=0;
|
|
|
- if(dblocptr->headinfo.loc_pushIndex==0)
|
|
|
- {
|
|
|
- printf("@@@更新上线标识,库内无数据\r\n");
|
|
|
- Online = false;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- RTCtime();//写入做参考
|
|
|
- printf("@@@库内有数据,执行操作\r\n");
|
|
|
- Database_Pull(0);
|
|
|
- MiddleObj=true;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- else if(pushpullcount>10001)
|
|
|
- {
|
|
|
-
|
|
|
- pushpullcount=0;
|
|
|
- }
|
|
|
-}
|
|
|
|