数据包转义处理VC6完整工程
代码如下:
// VerifyCode.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
unsigned char Mac_Id[6]={0x01,0x60,0x20,0x76,0x84,0x41};
unsigned char GPS_Info[49]={0x7e,
02,00,00,0x22,
0x01,0x60,0x20,0x76,0x84,0x41,
00,0x7c,
00,00,00,00,//报警标志
00,0x40,00,02,//状态
0x01,0xd2,0xee,0x39,
0x07,0x38,0xee,0xdd,
00,00,
00,00,
00,00,
0x19,//年
0x03,
0x05,
0x15,
0x56,//分
0x55,//秒
00,00,00,00,00,00,
0xe7,
0x7e
};
unsigned char Heart_Info[29]={
0x7e,
00,0x02,
00,0x0e,
0x01,0x60,0x20,0x76,0x84,0x41,
00,0x01,
0x40,//终端扩展信息
0x15,0xe7,//电压
0x03,//GSM信号
0x0f,//卫星
0x00,
00,00,00,00,00,00,
00,00,
0x1e,
0x7e
};
void gps_verify()
{
//校验码
unsigned char result=GPS_Info[1];
for(int k=2;k<=46;k++)
{
result^=GPS_Info[k];
}
GPS_Info[47]=result;
//打印输出
for(int s=0;s<49;s++)
{
printf("%02x",GPS_Info[s]);
}
}
void heart_verify()
{
//校验码
unsigned char result=Heart_Info[1];
for(int k=2;k<=26;k++)
{
result^=Heart_Info[k];
}
Heart_Info[27]=result;
//打印输出
for(int s=0;s<29;s++)
{
printf("%02x",Heart_Info[s]);
}
}
int main(int argc, char* argv[])
{
gps_verify();
printf("\r\n");printf("\r\n");printf("\r\n");
return 0;
}