以下是官方上位机的报文实例分析:
写一块伪代码写发送时对扩展帧操作的处理:
struct USB_DATA{
unsigned char target_id; //目标电机canid
unsigned char master_id; //主机canid
unsigned char preset_id; //预设canid
unsigned char connect_type; //通信类型
unsigned char data_len; //数据长度
unsigned char data_buf[8]; //数据内容
};
void func_use{
USB_DATA org_set;
memset(&org_set,0,sizeof(org_set));
org_set.connect_type = 0;
org_set.preset_id = 0;
org_set.master_id = 253;
org_set.target_id = 1;
org_set.data_len = 1;
org_set.data_buf[0] = 0x77;
org_set.data_buf[1] = 0x66;
//创建函数将扩展帧左移3位,右加4(即二进制 100)
//原理:结构体对齐规则
unsigned int * p = (unsigned int *)&org_set;
unsigned char * pt = (unsigned char *)&org_set;
qDebug("%x %x %x %x %x %x %x",pt[0],pt[1],pt[2],pt[3],pt[4],pt[5],pt[6]);
p[0] = (p[0]<<3)+4;
qDebug("%x %x %x %x %x %x %x",pt[0],pt[1],pt[2],pt[3],pt[4],pt[5],pt[6]);
qDebug("%x %x %x %x",org_set.connect_type,org_set.preset_id,org_set.master_id,org_set.target_id);
}
结果打印:
结果分析: