|
@@ -463,138 +463,138 @@ void tcphuifu(void);
|
|
|
int tcpdataLength = 0;
|
|
|
void wjwd(void);
|
|
|
|
|
|
-void replyCenter(void)
|
|
|
-{
|
|
|
- U4re=false;
|
|
|
- if(tcpd.Cmd==0x30 || tcpd.Cmd==0x32 || tcpd.Cmd==0x38)
|
|
|
- {
|
|
|
- wsj();//闻讯时间
|
|
|
- HAL_Delay(100);
|
|
|
- //wjwd();
|
|
|
- //HAL_Delay(100);
|
|
|
-
|
|
|
- tcpc.workcmd = tcpd.workcmd;//终端回复
|
|
|
- tcpc.Cmd = tcpd.Cmd;
|
|
|
- //64 74 75 31 dtu1
|
|
|
- tcpc.LockID = ((DTUID << 24)&0xff) | ((DTUID << 16)&0xff) | ((DTUID << 8)&0xff) | DTUID;
|
|
|
- //tcpc.Gate = 0x00;//待传入
|
|
|
-
|
|
|
- /* 载货清单 */
|
|
|
-
|
|
|
- tcpc.Bill[0] = (JD_dw>>24)&0xff;//待传入
|
|
|
- tcpc.Bill[1] = (JD_dw>>16)&0xff;//待传入
|
|
|
- tcpc.Bill[2] = (JD_dw>>8)&0xff;//待传入
|
|
|
- tcpc.Bill[3] = (JD_dw)&0xff;//待传入
|
|
|
- tcpc.Bill[4] = (WD_dw>>24)&0xff;//待传入
|
|
|
- tcpc.Bill[5] = (WD_dw>>16)&0xff;//待传入
|
|
|
- tcpc.Bill[6] = (WD_dw>>8)&0xff;//待传入
|
|
|
- tcpc.Bill[7] = (WD_dw)&0xff;//待传入
|
|
|
- /* 电压 */
|
|
|
- tcpc.Voltage = 0x00;//待传入
|
|
|
-
|
|
|
- if(tcpc.Cmd==0x32)//施封
|
|
|
- {
|
|
|
- if(tcpd.VaildTime==0x01)//锁1施封
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- if(tcpd.VaildTime==0x02)//锁2施封
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- if(tcpd.VaildTime==0x03)//锁3施封
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- if(tcpd.VaildTime==0x04)//锁4施封
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(tcpc.Cmd==0x38)//解封
|
|
|
- {
|
|
|
- if(tcpd.VaildTime==0x01)//锁1解封
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- if(tcpd.VaildTime==0x02)//锁2解封
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- if(tcpd.VaildTime==0x03)//锁3解封
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- if(tcpd.VaildTime==0x04)//锁4解封
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- /* 锁状态 */
|
|
|
- //tcpc.LockStatus = 0xAA;//待传入
|
|
|
- tcpc.LockStatus = tt808.L1Lockstatus;
|
|
|
- /* 电机状态 */
|
|
|
- //tcpc.MotoStatus = 0x00;//待传入
|
|
|
- tcpc.MotoStatus = tt808.L2Lockstatus;
|
|
|
- /* 线路编号 */
|
|
|
- tcpc.LineCode = ((uint16_t)tt808.L3Lockstatus << 8) | tt808.L4Lockstatus;//待传入
|
|
|
-
|
|
|
-
|
|
|
-// /* 操作标识码 */
|
|
|
-
|
|
|
- tcpc.OperationIdNum[0] = 0x00;//待传入
|
|
|
- tcpc.OperationIdNum[1] = 0x00;//待传入
|
|
|
- tcpc.OperationIdNum[2] = 0x00;//待传入
|
|
|
- tcpc.OperationIdNum[3] = 0x00;//待传入
|
|
|
- tcpc.OperationIdNum[4] = 0x00;//待传入
|
|
|
- tcpc.OperationIdNum[5] = 0x00;//待传入
|
|
|
- tcpc.OperationIdNum[6] = 0x00;//待传入
|
|
|
- tcpc.OperationIdNum[7] = 0x00;//待传入
|
|
|
- /* 设备标识码 */
|
|
|
- tcpc.cmdSRC = 0x0F;//dtu设备
|
|
|
-
|
|
|
- /* 下发命令时间 */
|
|
|
- tcpc.Time[0] = time.year;
|
|
|
- tcpc.Time[1] = time.month;
|
|
|
- tcpc.Time[2] = time.day;
|
|
|
- tcpc.Time[3] = time.hour;
|
|
|
- tcpc.Time[4] = time.minute;
|
|
|
- tcpc.Time[5] = time.second;
|
|
|
-
|
|
|
-
|
|
|
- //***
|
|
|
- cmd_replyArray[1]=TCPHeadBYTE;
|
|
|
- cmd_replyArray[2]=tcpc.workcmd;
|
|
|
- cmd_replyArray[3]=tcpc.Cmd;
|
|
|
- cmd_replyArray[4]=(tcpc.LockID>>24)&0xff;
|
|
|
- cmd_replyArray[5]=(tcpc.LockID>>16)&0xff;
|
|
|
- cmd_replyArray[6]=(tcpc.LockID>>8)&0xff;
|
|
|
- cmd_replyArray[7]=(tcpc.LockID)&0xff;
|
|
|
- cmd_replyArray[8]=tcpc.Gate;
|
|
|
- memcpy(&cmd_replyArray[9],tcpc.Bill,8);
|
|
|
- cmd_replyArray[17]=tcpc.Voltage;
|
|
|
- cmd_replyArray[18]=tcpc.LockStatus;
|
|
|
- cmd_replyArray[19]=tcpc.MotoStatus;
|
|
|
- cmd_replyArray[20]=(tcpc.LineCode>>8)&0xff;
|
|
|
- cmd_replyArray[21]=(tcpc.LineCode)&0xff;
|
|
|
- memcpy(&cmd_replyArray[22],tcpc.OperationIdNum,8);
|
|
|
- cmd_replyArray[30]=tcpc.cmdSRC;
|
|
|
- memcpy(&cmd_replyArray[31],tcpc.Time,6);
|
|
|
-
|
|
|
- cmd_replyArray[0]=sizeof(cmd_replyArray)-1;
|
|
|
- cmd_replyArray[37]=TCPTAILBYTE;
|
|
|
- cmd_replyArray[38]=xorBytes(&cmd_replyArray[1],37);//第2字节开始校验
|
|
|
-
|
|
|
- tcpdataLength = sizeof(cmd_replyArray) / sizeof(cmd_replyArray[0]);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- tcphuifu();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+//void replyCenter(void)
|
|
|
+//{
|
|
|
+// U4re=false;
|
|
|
+// if(tcpd.Cmd==0x30 || tcpd.Cmd==0x32 || tcpd.Cmd==0x38)
|
|
|
+// {
|
|
|
+// wsj();//闻讯时间
|
|
|
+// HAL_Delay(100);
|
|
|
+// //wjwd();
|
|
|
+// //HAL_Delay(100);
|
|
|
+//
|
|
|
+// tcpc.workcmd = tcpd.workcmd;//终端回复
|
|
|
+// tcpc.Cmd = tcpd.Cmd;
|
|
|
+// //64 74 75 31 dtu1
|
|
|
+// tcpc.LockID = ((DTUID << 24)&0xff) | ((DTUID << 16)&0xff) | ((DTUID << 8)&0xff) | DTUID;
|
|
|
+// //tcpc.Gate = 0x00;//待传入
|
|
|
+//
|
|
|
+// /* 载货清单 */
|
|
|
+
|
|
|
+// tcpc.Bill[0] = (JD_dw>>24)&0xff;//待传入
|
|
|
+// tcpc.Bill[1] = (JD_dw>>16)&0xff;//待传入
|
|
|
+// tcpc.Bill[2] = (JD_dw>>8)&0xff;//待传入
|
|
|
+// tcpc.Bill[3] = (JD_dw)&0xff;//待传入
|
|
|
+// tcpc.Bill[4] = (WD_dw>>24)&0xff;//待传入
|
|
|
+// tcpc.Bill[5] = (WD_dw>>16)&0xff;//待传入
|
|
|
+// tcpc.Bill[6] = (WD_dw>>8)&0xff;//待传入
|
|
|
+// tcpc.Bill[7] = (WD_dw)&0xff;//待传入
|
|
|
+// /* 电压 */
|
|
|
+// tcpc.Voltage = 0x00;//待传入
|
|
|
+//
|
|
|
+// if(tcpc.Cmd==0x32)//施封
|
|
|
+// {
|
|
|
+// if(tcpd.VaildTime==0x01)//锁1施封
|
|
|
+// {
|
|
|
+//
|
|
|
+// }
|
|
|
+// if(tcpd.VaildTime==0x02)//锁2施封
|
|
|
+// {
|
|
|
+//
|
|
|
+// }
|
|
|
+// if(tcpd.VaildTime==0x03)//锁3施封
|
|
|
+// {
|
|
|
+//
|
|
|
+// }
|
|
|
+// if(tcpd.VaildTime==0x04)//锁4施封
|
|
|
+// {
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(tcpc.Cmd==0x38)//解封
|
|
|
+// {
|
|
|
+// if(tcpd.VaildTime==0x01)//锁1解封
|
|
|
+// {
|
|
|
+//
|
|
|
+// }
|
|
|
+// if(tcpd.VaildTime==0x02)//锁2解封
|
|
|
+// {
|
|
|
+//
|
|
|
+// }
|
|
|
+// if(tcpd.VaildTime==0x03)//锁3解封
|
|
|
+// {
|
|
|
+//
|
|
|
+// }
|
|
|
+// if(tcpd.VaildTime==0x04)//锁4解封
|
|
|
+// {
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+// /* 锁状态 */
|
|
|
+// //tcpc.LockStatus = 0xAA;//待传入
|
|
|
+// tcpc.LockStatus = tt808.L1Lockstatus;
|
|
|
+// /* 电机状态 */
|
|
|
+// //tcpc.MotoStatus = 0x00;//待传入
|
|
|
+// tcpc.MotoStatus = tt808.L2Lockstatus;
|
|
|
+// /* 线路编号 */
|
|
|
+// tcpc.LineCode = ((uint16_t)tt808.L3Lockstatus << 8) | tt808.L4Lockstatus;//待传入
|
|
|
+
|
|
|
+//
|
|
|
+//// /* 操作标识码 */
|
|
|
+
|
|
|
+// tcpc.OperationIdNum[0] = 0x00;//待传入
|
|
|
+// tcpc.OperationIdNum[1] = 0x00;//待传入
|
|
|
+// tcpc.OperationIdNum[2] = 0x00;//待传入
|
|
|
+// tcpc.OperationIdNum[3] = 0x00;//待传入
|
|
|
+// tcpc.OperationIdNum[4] = 0x00;//待传入
|
|
|
+// tcpc.OperationIdNum[5] = 0x00;//待传入
|
|
|
+// tcpc.OperationIdNum[6] = 0x00;//待传入
|
|
|
+// tcpc.OperationIdNum[7] = 0x00;//待传入
|
|
|
+// /* 设备标识码 */
|
|
|
+// tcpc.cmdSRC = 0x0F;//dtu设备
|
|
|
+//
|
|
|
+// /* 下发命令时间 */
|
|
|
+// tcpc.Time[0] = time.year;
|
|
|
+// tcpc.Time[1] = time.month;
|
|
|
+// tcpc.Time[2] = time.day;
|
|
|
+// tcpc.Time[3] = time.hour;
|
|
|
+// tcpc.Time[4] = time.minute;
|
|
|
+// tcpc.Time[5] = time.second;
|
|
|
+//
|
|
|
+//
|
|
|
+// //***
|
|
|
+// cmd_replyArray[1]=TCPHeadBYTE;
|
|
|
+// cmd_replyArray[2]=tcpc.workcmd;
|
|
|
+// cmd_replyArray[3]=tcpc.Cmd;
|
|
|
+// cmd_replyArray[4]=(tcpc.LockID>>24)&0xff;
|
|
|
+// cmd_replyArray[5]=(tcpc.LockID>>16)&0xff;
|
|
|
+// cmd_replyArray[6]=(tcpc.LockID>>8)&0xff;
|
|
|
+// cmd_replyArray[7]=(tcpc.LockID)&0xff;
|
|
|
+// cmd_replyArray[8]=tcpc.Gate;
|
|
|
+// memcpy(&cmd_replyArray[9],tcpc.Bill,8);
|
|
|
+// cmd_replyArray[17]=tcpc.Voltage;
|
|
|
+// cmd_replyArray[18]=tcpc.LockStatus;
|
|
|
+// cmd_replyArray[19]=tcpc.MotoStatus;
|
|
|
+// cmd_replyArray[20]=(tcpc.LineCode>>8)&0xff;
|
|
|
+// cmd_replyArray[21]=(tcpc.LineCode)&0xff;
|
|
|
+// memcpy(&cmd_replyArray[22],tcpc.OperationIdNum,8);
|
|
|
+// cmd_replyArray[30]=tcpc.cmdSRC;
|
|
|
+// memcpy(&cmd_replyArray[31],tcpc.Time,6);
|
|
|
+//
|
|
|
+// cmd_replyArray[0]=sizeof(cmd_replyArray)-1;
|
|
|
+// cmd_replyArray[37]=TCPTAILBYTE;
|
|
|
+// cmd_replyArray[38]=xorBytes(&cmd_replyArray[1],37);//第2字节开始校验
|
|
|
+//
|
|
|
+// tcpdataLength = sizeof(cmd_replyArray) / sizeof(cmd_replyArray[0]);
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// tcphuifu();
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//}
|
|
|
|
|
|
uint8_t MIPurc[256];
|
|
|
uint8_t MIPurc1[256];
|
|
@@ -657,6 +657,15 @@ char day_str[3];
|
|
|
char hour_str[3];
|
|
|
char minute_str[3];
|
|
|
char second_str[3];
|
|
|
+void ZHSJ(uint8_t outTt[],char in[])//转换时间
|
|
|
+{
|
|
|
+ const char *hex = (const char *)in; // 将 uint8_t * 转换为 const char *
|
|
|
+ int size = strlen(hex) / 2; // 计算二进制数据的长度
|
|
|
+ unsigned char *bin = (unsigned char *)malloc(size); // 分配足够的内存用于存储二进制数据
|
|
|
+ hex2bin(bin, hex); // 调用hex2bin函数进行转换
|
|
|
+ memcpy(outTt, bin, 1); // 将 bin 中的 rlt 个字节复制到 MIPurc1 中 接收到的数据放入MIPurc1中
|
|
|
+ free(bin); // 释放内存
|
|
|
+}
|
|
|
void wsj(void)
|
|
|
{
|
|
|
if (sendCmd_4G("AT+CCLK?\r\n", "OK", 1, 1))
|
|
@@ -676,135 +685,149 @@ void wsj(void)
|
|
|
minute_str[2] = '\0';
|
|
|
second_str[2] = '\0';
|
|
|
|
|
|
- time.year = (uint8_t)atoi(year_str); // 使用atoi函数将字符转换为数字并赋值给time.year
|
|
|
- time.month = (uint8_t)atoi(month_str);
|
|
|
- time.day = (uint8_t)atoi(day_str);
|
|
|
- time.hour = (uint8_t)atoi(hour_str)+8;
|
|
|
- time.minute = (uint8_t)atoi(minute_str);
|
|
|
- time.second = (uint8_t)atoi(second_str);
|
|
|
+// time.year = (uint8_t)atoi(year_str); // 使用atoi函数将字符转换为数字并赋值给time.year转16
|
|
|
+// time.month = (uint8_t)atoi(month_str);
|
|
|
+// time.day = (uint8_t)atoi(day_str);
|
|
|
+// time.hour = (uint8_t)atoi(hour_str)+8;
|
|
|
+// time.minute = (uint8_t)atoi(minute_str);
|
|
|
+// time.second = (uint8_t)atoi(second_str);
|
|
|
+
|
|
|
+
|
|
|
+ ZHSJ(&time.tt[0],year_str);
|
|
|
+ ZHSJ(&time.tt[1],month_str);
|
|
|
+ ZHSJ(&time.tt[2],day_str);
|
|
|
+ ZHSJ(&time.tt[3],hour_str);
|
|
|
+ ZHSJ(&time.tt[4],minute_str);
|
|
|
+ ZHSJ(&time.tt[5],second_str);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
uint8_t tcpoutarr[]={0};
|
|
|
uint8_t header[12];
|
|
|
-void tcphuifu(void)
|
|
|
-{
|
|
|
- if(!tcpconn)
|
|
|
- {
|
|
|
- if(sendCmd_4G("AT+MIPCLOSE=1\r\n", "+MIPSEND:", 1, 1))//发送11BYTE MAX1460
|
|
|
- {
|
|
|
- printf("#断开连接\r\n");
|
|
|
- }
|
|
|
- if(sendCmd_4G("AT+MIPOPEN=1,\"TCP\",\"118.31.22.26\",8901,60,0\r\n", "+MIPOPEN: 1,0", 1, 3))//TCP连接
|
|
|
- {
|
|
|
- printf("#TCP连接成功\r\n");
|
|
|
- if(sendCmd_4G("AT+MIPCFG=\"encoding\",1,1,1\r\n", "OK", 1, 3))//默认输入输出为ASCII,0 发16,1 接16,1
|
|
|
- {
|
|
|
- printf("#TCP设置完成\r\n");
|
|
|
- tcpconn=true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+//void tcphuifu(void)
|
|
|
+//{
|
|
|
+// if(!tcpconn)
|
|
|
+// {
|
|
|
+// if(sendCmd_4G("AT+MIPCLOSE=1\r\n", "+MIPSEND:", 1, 1))//发送11BYTE MAX1460
|
|
|
+// {
|
|
|
+// printf("#断开连接\r\n");
|
|
|
+// }
|
|
|
+// if(sendCmd_4G("AT+MIPOPEN=1,\"TCP\",\"118.31.22.26\",8901,60,0\r\n", "+MIPOPEN: 1,0", 1, 3))//TCP连接
|
|
|
+// {
|
|
|
+// printf("#TCP连接成功\r\n");
|
|
|
+// if(sendCmd_4G("AT+MIPCFG=\"encoding\",1,1,1\r\n", "OK", 1, 3))//默认输入输出为ASCII,0 发16,1 接16,1
|
|
|
+// {
|
|
|
+// printf("#TCP设置完成\r\n");
|
|
|
+// tcpconn=true;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
- module4G_F=false;
|
|
|
- uint16_t XXTSXdata = tcpdataLength;
|
|
|
- uint8_t checksum = 0; // Initialize checksum
|
|
|
-
|
|
|
- //XXTSXdata |= ( tcpdataLength | (TCPJMFSRSA<<10)); // 将长度左移3位后和加密方式进行按位或操作(001 RSA ,000 无加密)
|
|
|
- XXTSXdata |= ( tcpdataLength | (TCPJMFSNULL<<10)); // 将长度左移3位后和加密方式进行按位或操作(001 RSA ,000 无加密)
|
|
|
-
|
|
|
- if(xxid == XXIDzdy)
|
|
|
- {
|
|
|
- //xxid=0;
|
|
|
- header[0] = ((XXIDzdy>>8)&0xff);
|
|
|
- header[1] = (XXIDzdy&0xff);
|
|
|
- }
|
|
|
-
|
|
|
- if(xxid == XXIDxfMac1)
|
|
|
- {
|
|
|
- //xxid=0;
|
|
|
- header[0] = ((XXIDxfMac1>>8)&0xff);
|
|
|
- header[1] = (XXIDxfMac1&0xff);
|
|
|
- }
|
|
|
- if(xxid == XXIDxfMac2)
|
|
|
- {
|
|
|
- //xxid=0;
|
|
|
- header[0] = ((XXIDxfMac2>>8)&0xff);
|
|
|
- header[1] = (XXIDxfMac2&0xff);
|
|
|
- }
|
|
|
- if(xxid == XXIDxfMac3)
|
|
|
- {
|
|
|
- //xxid=0;
|
|
|
- header[0] = ((XXIDxfMac3>>8)&0xff);
|
|
|
- header[1] = (XXIDxfMac3&0xff);
|
|
|
- }
|
|
|
- if(xxid == XXIDxfMac4)
|
|
|
- {
|
|
|
- //xxid=0;
|
|
|
- header[0] = ((XXIDxfMac4>>8)&0xff);
|
|
|
- header[1] = (XXIDxfMac4&0xff);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- header[2] = ((XXTSXdata>>8)&0xff);
|
|
|
- header[3] = (XXTSXdata&0xff);
|
|
|
- header[4] = 0x64;
|
|
|
- header[5] = 0x74;
|
|
|
- header[6] = 0x75;
|
|
|
- header[7] = 0x30;
|
|
|
- header[8] = 0x30;
|
|
|
- header[9] = 0x31;
|
|
|
- header[10] = ((tt808.LSH>>8)&0xff);
|
|
|
- header[11] = (tt808.LSH&0xff);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- for (int i = 0; i < 12; i++) {
|
|
|
- checksum ^= header[i];
|
|
|
- }
|
|
|
-
|
|
|
- for (int i = 0; i < tcpdataLength; i++) {
|
|
|
- checksum ^= cmd_replyArray[i];
|
|
|
- }
|
|
|
- ;
|
|
|
- uint8_t len = 1 + 12 + tcpdataLength + 1 + 1;
|
|
|
- uint8_t tcppacket[len];
|
|
|
- int index = 0;
|
|
|
- tcppacket[index++] = TT808FLAG; // Set the flag
|
|
|
-
|
|
|
- for (int i = 0; i < 12; i++) {
|
|
|
- tcppacket[index++] = header[i];
|
|
|
- }
|
|
|
- // Copy message body to packet
|
|
|
- for (size_t i = 0; i < tcpdataLength; i++) {
|
|
|
- tcppacket[index++] = cmd_replyArray[i];
|
|
|
- }
|
|
|
-
|
|
|
- uint16_t tcpoutLength = len;
|
|
|
-
|
|
|
- tcppacket[index++] = checksum; // Set the checksum
|
|
|
- tcppacket[index++] = TT808FLAG; // Set the flag at the end
|
|
|
-
|
|
|
-
|
|
|
- char TCPvalue[256];
|
|
|
- char *ptr = TCPvalue;
|
|
|
- ptr += sprintf(ptr, "AT+MIPSEND=1,%d,\"",tcpoutLength);
|
|
|
- for (int i = 0; i < tcpoutLength; i++) {
|
|
|
- ptr += sprintf(ptr, "%02X", tcppacket[i]);
|
|
|
- }
|
|
|
- sprintf(ptr, "\"\r\n");//TCPvalue
|
|
|
- if(sendCmd_4G(TCPvalue, "+MIPSEND:", 1, 1))//发送11BYTE MAX1460
|
|
|
- {
|
|
|
- printf("#发送完成\r\n");
|
|
|
- }
|
|
|
-
|
|
|
- module4G_F=true;
|
|
|
- tt808.LSH+=1;
|
|
|
- memset(MIPurc1,0,rlt);
|
|
|
+// module4G_F=false;
|
|
|
+// uint16_t XXTSXdata = tcpdataLength;
|
|
|
+// uint8_t checksum = 0; // Initialize checksum
|
|
|
+//
|
|
|
+// //XXTSXdata |= ( tcpdataLength | (TCPJMFSRSA<<10)); // 将长度左移3位后和加密方式进行按位或操作(001 RSA ,000 无加密)
|
|
|
+// XXTSXdata |= ( tcpdataLength | (TCPJMFSNULL<<10)); // 将长度左移3位后和加密方式进行按位或操作(001 RSA ,000 无加密)
|
|
|
+//
|
|
|
+// if(xxid == XXIDzdy)
|
|
|
+// {
|
|
|
+// //xxid=0;
|
|
|
+// header[0] = ((XXIDzdy>>8)&0xff);
|
|
|
+// header[1] = (XXIDzdy&0xff);
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(xxid == XXIDxfMac1)
|
|
|
+// {
|
|
|
+// //xxid=0;
|
|
|
+// header[0] = ((XXIDxfMac1>>8)&0xff);
|
|
|
+// header[1] = (XXIDxfMac1&0xff);
|
|
|
+// }
|
|
|
+// if(xxid == XXIDxfMac2)
|
|
|
+// {
|
|
|
+// //xxid=0;
|
|
|
+// header[0] = ((XXIDxfMac2>>8)&0xff);
|
|
|
+// header[1] = (XXIDxfMac2&0xff);
|
|
|
+// }
|
|
|
+// if(xxid == XXIDxfMac3)
|
|
|
+// {
|
|
|
+// //xxid=0;
|
|
|
+// header[0] = ((XXIDxfMac3>>8)&0xff);
|
|
|
+// header[1] = (XXIDxfMac3&0xff);
|
|
|
+// }
|
|
|
+// if(xxid == XXIDxfMac4)
|
|
|
+// {
|
|
|
+// //xxid=0;
|
|
|
+// header[0] = ((XXIDxfMac4>>8)&0xff);
|
|
|
+// header[1] = (XXIDxfMac4&0xff);
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// header[2] = ((XXTSXdata>>8)&0xff);
|
|
|
+// header[3] = (XXTSXdata&0xff);
|
|
|
+// header[4] = 0x64;
|
|
|
+// header[5] = 0x74;
|
|
|
+// header[6] = 0x75;
|
|
|
+// header[7] = 0x30;
|
|
|
+// header[8] = 0x30;
|
|
|
+// header[9] = 0x31;
|
|
|
+// header[10] = ((tt808.LSH>>8)&0xff);
|
|
|
+// header[11] = (tt808.LSH&0xff);
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// for (int i = 0; i < 12; i++) {
|
|
|
+// checksum ^= header[i];
|
|
|
+// }
|
|
|
+//
|
|
|
+// for (int i = 0; i < tcpdataLength; i++) {
|
|
|
+// checksum ^= cmd_replyArray[i];
|
|
|
+// }
|
|
|
+// ;
|
|
|
+// uint8_t len = 1 + 12 + tcpdataLength + 1 + 1;
|
|
|
+// uint8_t tcppacket[len];
|
|
|
+// int index = 0;
|
|
|
+// tcppacket[index++] = TT808FLAG; // Set the flag
|
|
|
+//
|
|
|
+// for (int i = 0; i < 12; i++) {
|
|
|
+// tcppacket[index++] = header[i];
|
|
|
+// }
|
|
|
+// // Copy message body to packet
|
|
|
+// for (size_t i = 0; i < tcpdataLength; i++) {
|
|
|
+// tcppacket[index++] = cmd_replyArray[i];
|
|
|
+// }
|
|
|
+//
|
|
|
+// uint16_t tcpoutLength = len;
|
|
|
+//
|
|
|
+// tcppacket[index++] = checksum; // Set the checksum
|
|
|
+// tcppacket[index++] = TT808FLAG; // Set the flag at the end
|
|
|
+//
|
|
|
+//
|
|
|
+// char TCPvalue[256];
|
|
|
+// char *ptr = TCPvalue;
|
|
|
+// ptr += sprintf(ptr, "AT+MIPSEND=1,%d,\"",tcpoutLength);
|
|
|
+// for (int i = 0; i < tcpoutLength; i++) {
|
|
|
+// ptr += sprintf(ptr, "%02X", tcppacket[i]);
|
|
|
+// }
|
|
|
+// sprintf(ptr, "\"\r\n");//TCPvalue
|
|
|
+// if(sendCmd_4G(TCPvalue, "+MIPSEND:", 1, 1))//发送11BYTE MAX1460
|
|
|
+// {
|
|
|
+// printf("#发送完成\r\n");
|
|
|
+// }
|
|
|
+//
|
|
|
+// module4G_F=true;
|
|
|
+// tt808.LSH+=1;
|
|
|
+// memset(MIPurc1,0,rlt);
|
|
|
|
|
|
-}
|
|
|
+//}
|
|
|
|
|
|
|
|
|
|
|
@@ -826,7 +849,7 @@ void chuli(uint16_t XXID)
|
|
|
{
|
|
|
|
|
|
uint16_t XXTSXdata = xxtnewlength;
|
|
|
- XXTSXdata |= ( tcpdataLength | (TCPJMFSNULL<<10)); // 将长度左移3位后和加密方式进行按位或操作(001 RSA ,000 无加密)
|
|
|
+ XXTSXdata |= ( xxtnewlength | (TCPJMFSNULL<<10)); // 将长度左移3位后和加密方式进行按位或操作(001 RSA ,000 无加密)
|
|
|
|
|
|
header[0] = ((XXID>>8)&0xff);
|
|
|
header[1] = (XXID&0xff);
|
|
@@ -841,8 +864,7 @@ void chuli(uint16_t XXID)
|
|
|
header[10] = ((tt808.LSH>>8)&0xff);;
|
|
|
header[11] = (tt808.LSH&0xff);;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
|
|
|
int index = 0;
|
|
|
tcppacket[index++] = TT808FLAG; // Set the flag
|
|
@@ -883,35 +905,52 @@ void chuli(uint16_t XXID)
|
|
|
|
|
|
|
|
|
/*需要传入消息体长度sizeof(xxt)/sizeof(xxt[0]);*/
|
|
|
-void tt808FsFunc(uint8_t xxt[], uint8_t xxtlength)
|
|
|
+void tt808FsFunc(uint8_t xxt[], uint8_t xxtlength, uint16_t XXID)
|
|
|
{
|
|
|
- xxtnewlength = xxtFZ(xxt, xxtlength, xxtfz);
|
|
|
+ xxtnewlength = xxtFZ(xxt, xxtlength, xxtfz, XXID);
|
|
|
|
|
|
- //chuli(XXIDzdxt);
|
|
|
- chuli(XXIDzdjq);
|
|
|
+ chuli(XXID);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
-uint8_t xxtFZ(uint8_t xxt[], uint8_t xxtlength, uint8_t outXxt[])
|
|
|
+uint8_t xxtFZ(uint8_t xxt[], uint8_t xxtlength, uint8_t outXxt[],uint16_t XXID)
|
|
|
{
|
|
|
int index = 0;
|
|
|
uint8_t newlength = xxtlength+3;
|
|
|
|
|
|
uint8_t newXxt[newlength];
|
|
|
- newXxt[index++]=newlength;
|
|
|
- newXxt[index++]=0x2A;
|
|
|
- for (int i = 0; i < xxtlength; i++) {
|
|
|
- newXxt[index++] = xxt[i]; // 将消息头拷贝到报文中
|
|
|
- }
|
|
|
- newXxt[index++]=0x23;
|
|
|
- newXxt[index++]=xorBytes(&newXxt[1],newlength-1);
|
|
|
- newlength = index;
|
|
|
|
|
|
- for(int i =0;i<newlength;i++)
|
|
|
+ if(XXID==XXIDzdjq || XXID==XXIDzdxt || XXID==XXIDzddz)//不加头尾
|
|
|
+ {
|
|
|
+ for (int i = 0; i < xxtlength; i++) {
|
|
|
+ newXxt[index++] = xxt[i]; // 将消息头拷贝到报文中
|
|
|
+ }
|
|
|
+
|
|
|
+ newlength = index;
|
|
|
+
|
|
|
+ for(int i =0;i<newlength;i++)
|
|
|
+ {
|
|
|
+ outXxt[i]=newXxt[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- outXxt[i]=newXxt[i];
|
|
|
+ newXxt[index++]=newlength;
|
|
|
+ newXxt[index++]=0x2A;
|
|
|
+ for (int i = 0; i < xxtlength; i++) {
|
|
|
+ newXxt[index++] = xxt[i]; // 将消息头拷贝到报文中
|
|
|
+ }
|
|
|
+ newXxt[index++]=0x23;
|
|
|
+ newXxt[index++]=xorBytes(&newXxt[1],newlength-1);
|
|
|
+ newlength = index;
|
|
|
+
|
|
|
+ for(int i =0;i<newlength;i++)
|
|
|
+ {
|
|
|
+ outXxt[i]=newXxt[i];
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -922,3 +961,263 @@ uint8_t xxtFZ(uint8_t xxt[], uint8_t xxtlength, uint8_t outXxt[])
|
|
|
return newlength;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+void ReMLBSLOC(void)
|
|
|
+{
|
|
|
+ if(g_ML307A_8buf_Down[1]==0x4D && g_ML307A_8buf_Down[2]==0x4C && g_ML307A_8buf_Down[3]==0x42 \
|
|
|
+ && g_ML307A_8buf_Down[4]==0x53 && g_ML307A_8buf_Down[5]==0x4C && g_ML307A_8buf_Down[6]==0x4F \
|
|
|
+ && g_ML307A_8buf_Down[7]==0x43 && g_ML307A_8buf_Down[8]==0x3A)//检测MLBSLOC:定位
|
|
|
+ {
|
|
|
+
|
|
|
+ memcpy(JD_str, &g_ML307A_8buf_Down[14], 12);
|
|
|
+ memcpy(WD_str, &g_ML307A_8buf_Down[27], 11);
|
|
|
+ double num;
|
|
|
+ double num1;
|
|
|
+ num = atof(JD_str);
|
|
|
+ num1 = atof(WD_str);
|
|
|
+ num = num* 1000000;
|
|
|
+ num1= num1* 1000000;
|
|
|
+ JD_dw = (uint32_t)num;
|
|
|
+ WD_dw = (uint32_t)num1;
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void ReMIPURC(void)
|
|
|
+{
|
|
|
+ //4D 49 50 55 52 43
|
|
|
+ if(g_ML307A_8buf_Down[1]==0x4D && g_ML307A_8buf_Down[2]==0x49 && g_ML307A_8buf_Down[3]==0x50 \
|
|
|
+ && g_ML307A_8buf_Down[4]==0x55 && g_ML307A_8buf_Down[5]==0x52 && g_ML307A_8buf_Down[6]==0x43 ) //监测平台回复
|
|
|
+ {
|
|
|
+ uint8_t high_byte = (g_ML307A_8buf_Down[18]&0x0f) *10;
|
|
|
+ uint8_t low_byte = g_ML307A_8buf_Down[19]&0x0f;
|
|
|
+ hccd = high_byte + low_byte;
|
|
|
+ memcpy(MIPurc,&g_ML307A_8buf_Down[21],hccd*2);
|
|
|
+ const char *hex = (const char *)MIPurc; // 将 uint8_t * 转换为 const char *
|
|
|
+ int size = strlen(hex) / 2; // 计算二进制数据的长度
|
|
|
+ unsigned char *bin = (unsigned char *)malloc(size); // 分配足够的内存用于存储二进制数据
|
|
|
+ rlt = hex2bin(bin, hex); // 调用hex2bin函数进行转换
|
|
|
+ memcpy(MIPurc1, bin, rlt); // 将 bin 中的 rlt 个字节复制到 MIPurc1 中 接收到的数据放入MIPurc1中
|
|
|
+ free(bin); // 释放内存
|
|
|
+ memset(g_ML307A_8buf_Down,0,u4length);
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+bool JQflag = false;
|
|
|
+void MIPURCHandle(void)
|
|
|
+{
|
|
|
+ if(MIPurc1[0]==0x7E)
|
|
|
+ {
|
|
|
+ uint16_t PTXXID = MIPurc1[1]<<8 | MIPurc1[2]; //消息ID
|
|
|
+ uint16_t xxtcLen = MIPurc1[3]<<8 | MIPurc1[4]; //数据长度
|
|
|
+ uint16_t xxRE = MIPurc1[15]<<8 | MIPurc1[16]; //数据长度
|
|
|
+ uint8_t YESorNO = MIPurc1[17]; //00 success ; 01 fail
|
|
|
+
|
|
|
+ if(PTXXID==XXIDpttyyd)//平台通用应答8001
|
|
|
+ {
|
|
|
+
|
|
|
+ if(xxRE==0x0102)//回复鉴权ID
|
|
|
+ {
|
|
|
+ if(YESorNO==YES)
|
|
|
+ {
|
|
|
+ printf("鉴权应答yes\r\n");
|
|
|
+ JQflag = true;
|
|
|
+ }
|
|
|
+ else if(YESorNO==NO)
|
|
|
+ {
|
|
|
+ printf("鉴权应答no\r\n");
|
|
|
+ }
|
|
|
+ memset(MIPurc1,0,rlt);//rlt下发长度
|
|
|
+ }
|
|
|
+
|
|
|
+ if(xxRE==0x0002)//回复心跳ID
|
|
|
+ {
|
|
|
+ if(YESorNO==YES)
|
|
|
+ {
|
|
|
+ printf("心跳应答yes\r\n");
|
|
|
+ }
|
|
|
+ else if(YESorNO==NO)
|
|
|
+ {
|
|
|
+ printf("心跳应答no\r\n");
|
|
|
+ }
|
|
|
+ memset(MIPurc1,0,rlt);//rlt下发长度
|
|
|
+ }
|
|
|
+
|
|
|
+ if(xxRE==0x0200)//回复地址ID
|
|
|
+ {
|
|
|
+ if(YESorNO==YES)
|
|
|
+ {
|
|
|
+ printf("地址应答yes\r\n");
|
|
|
+ }
|
|
|
+ else if(YESorNO==NO)
|
|
|
+ {
|
|
|
+ printf("地址应答no\r\n");
|
|
|
+ }
|
|
|
+ memset(MIPurc1,0,rlt);//rlt下发长度
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else if(PTXXID == XXIDptxxtc) //平台消息透传
|
|
|
+ {
|
|
|
+ uint8_t tcsjLen = MIPurc1[13];
|
|
|
+ memcpy(MIPurcXXTCSJ,&MIPurc1[13],xxtcLen);
|
|
|
+ printf("得到透传数据,%d\r\n\r\n",tcsjLen);
|
|
|
+ memset(MIPurc1,0,rlt);//rlt下发长度
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+0-3报警标志
|
|
|
+4-7状态
|
|
|
+8-11纬度
|
|
|
+12-15经度
|
|
|
+16-17高程
|
|
|
+18-19速度
|
|
|
+20-21方向
|
|
|
+22-27时间
|
|
|
+
|
|
|
+*/
|
|
|
+/**
|
|
|
+ "报警标志对象": {
|
|
|
+ "[bit31]非法开门报警": "0",
|
|
|
+ "[bit30]侧翻预警": "0",
|
|
|
+ "[bit29]碰撞预警": "0",
|
|
|
+ "[bit28]车辆非法位移": "0",
|
|
|
+ "[bit27]车辆非法点火": "0",
|
|
|
+ "[bit26]车辆被盗(通过车辆防盗器)": "0",
|
|
|
+ "[bit25]车辆油量异常": "0",
|
|
|
+ "[bit24]车辆VSS故障": "0",
|
|
|
+ "[bit23]路线偏离报警": "0",
|
|
|
+ "[bit22]路段行驶时间不足/过长": "0",
|
|
|
+ "[bit21]进出路线": "0",
|
|
|
+ "[bit20]进出区域": "0",
|
|
|
+ "[bit19]超时停车": "0",
|
|
|
+ "[bit18]当天累计驾驶超时": "0",
|
|
|
+ "[bit15~bit17]保留": "000",
|
|
|
+ "[bit14]疲劳驾驶预警": "0",
|
|
|
+ "[bit13]超速预警": "0",
|
|
|
+ "[bit12]道路运输证IC卡模块故障": "0",
|
|
|
+ "[bit11]摄像头故障": "0",
|
|
|
+ "[bit10]TTS模块故障": "0",
|
|
|
+ "[bit9]终端LCD或显示器故障": "0",
|
|
|
+ "[bit8]终端主电源掉电": "0",
|
|
|
+ "[bit7]终端主电源欠压": "0",
|
|
|
+ "[bit6]GNSS天线短路": "0",
|
|
|
+ "[bit5]GNSS天线未接或被剪断": "0",
|
|
|
+ "[bit4]GNSS模块发生故障": "0",
|
|
|
+ "[bit3]危险预警": "0",
|
|
|
+ "[bit2]疲劳驾驶": "0",
|
|
|
+ "[bit1]超速报警": "0",
|
|
|
+ "[bit0]紧急报警,触动报警开关后触发": "0"
|
|
|
+
|
|
|
+ "状态标志对象": {
|
|
|
+ "[bit22~bit31]保留": "0000000000",
|
|
|
+ "[0]bit21": "未使用Galileo卫星进行定位",
|
|
|
+ "[0]bit20": "未使用GLONASS卫星进行定位",
|
|
|
+ "[0]bit19": "未使用北斗卫星进行定位",
|
|
|
+ "[0]bit18": "未使用GPS卫星进行定位",
|
|
|
+ "[0]bit17": "门5关",
|
|
|
+ "[0]bit16": "门4关",
|
|
|
+ "[0]bit15": "门3关",
|
|
|
+ "[0]bit14": "门2关",
|
|
|
+ "[0]bit13": "门1关",
|
|
|
+ "[0]bit12": "车门解锁",
|
|
|
+ "[0]bit11": "车辆电路正常",
|
|
|
+ "[0]bit10": "车辆油路正常",
|
|
|
+ "[00]bit8~bit9": "空车",
|
|
|
+ "[bit6~bit7]保留": "00",
|
|
|
+ "[0]bit5": "经纬度未经保密插件加密",
|
|
|
+ "[0]bit4": "运营状态",
|
|
|
+ "[0]bit3": "东经",
|
|
|
+ "[0]bit2": "北纬",
|
|
|
+ "[0]bit1": "未定位",
|
|
|
+ "[0]bit0": "ACC关"
|
|
|
+
|
|
|
+ "[01CD81D6]纬度": 30245334,
|
|
|
+ "[0727A76F]经度": 120039279,
|
|
|
+ "[0000]高程": 0,
|
|
|
+ "[0000]速度": 0,
|
|
|
+ "[0000]方向": 0,
|
|
|
+ "[180323093105]定位时间": "2018-03-23 09:31:05",
|
|
|
+*/
|
|
|
+
|
|
|
+LBSset lbsset;
|
|
|
+
|
|
|
+uint8_t LBSdata[28];
|
|
|
+
|
|
|
+void Lbsprocess(void)
|
|
|
+{
|
|
|
+ wsj(); //问时间
|
|
|
+ LBSdata[0] = (lbsset.bjbz>>24)&0xff;
|
|
|
+ LBSdata[1] = (lbsset.bjbz>>16)&0xff;
|
|
|
+ LBSdata[2] = (lbsset.bjbz>>8)&0xff;
|
|
|
+ LBSdata[3] = lbsset.bjbz&0xff;
|
|
|
+
|
|
|
+ LBSdata[4] = (lbsset.zt>>24)&0xff;
|
|
|
+ LBSdata[5] = (lbsset.zt>>16)&0xff;
|
|
|
+ LBSdata[6] = (lbsset.zt>>8)&0xff;
|
|
|
+ LBSdata[7] = lbsset.zt&0xff;
|
|
|
+
|
|
|
+ LBSdata[8] = (WD_dw>>24)&0xff;
|
|
|
+ LBSdata[9] = (WD_dw>>16)&0xff;
|
|
|
+ LBSdata[10] = (WD_dw>>8)&0xff;
|
|
|
+ LBSdata[11] = WD_dw&0xff;
|
|
|
+
|
|
|
+ LBSdata[12] = (JD_dw>>24)&0xff;
|
|
|
+ LBSdata[13] = (JD_dw>>16)&0xff;
|
|
|
+ LBSdata[14] = (JD_dw>>8)&0xff;
|
|
|
+ LBSdata[15] = JD_dw&0xff;
|
|
|
+
|
|
|
+ LBSdata[16] = (lbsset.gaocheng>>8)&0xff;
|
|
|
+ LBSdata[17] = lbsset.gaocheng&0xff;
|
|
|
+
|
|
|
+ LBSdata[18] = (lbsset.sudu>>8)&0xff;
|
|
|
+ LBSdata[19] = lbsset.sudu&0xff;
|
|
|
+
|
|
|
+ LBSdata[20] = (lbsset.fangxiang>>8)&0xff;
|
|
|
+ LBSdata[21] = lbsset.fangxiang&0xff;
|
|
|
+
|
|
|
+ LBSdata[22] = time.tt[0];
|
|
|
+ LBSdata[23] = time.tt[1];
|
|
|
+ LBSdata[24] = time.tt[2];
|
|
|
+ LBSdata[25] = time.tt[3]+8;
|
|
|
+ LBSdata[26] = time.tt[4];
|
|
|
+ LBSdata[27] = time.tt[5];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|