在进行数据传输的时候,发送一帧数据,为了保证其安全性,可以对一帧数据里面的东西进行“加密”
#include <stdio.h>
typedef struct My_Test
{
int head; //帧头
int length;
int type;
int command;
int work;
int fre;
int chan;
int check; //校验(异或值)
int end; //帧尾
};
void main()
{
struct My_Test one_test;
unsigned char test_rx[]="zzzzzzz";
int mycheck=0;
int i=0;
one_test.head = 0xAA;
one_test.length = 0x01;
one_test.type = 0x02;
one_test.command = 0x03;
one_test.work = 0x04;
one_test.fre = 0x05;
one_test.chan = 0x06;
//从帧头后到异或值前的6位进行异或
//把数据存在数组里面
test_rx[0] = one_test.length;
test_rx[1] = one_test.type;
test_rx[2] = one_test.command;
test_rx[3] = one_test.work;
test_rx[4] = one_test.fre;
test_rx[5] = one_test.chan;
//对数组里的数据挨个进行异或
for(i=0;i<6;i++)
{
mycheck ^= test_rx[i];
}
//得出一帧数据的异或值
one_t