c_cpp 上行报文解析
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 上行报文解析相关的知识,希望对你有一定的参考价值。
/************************************************************
* 功能:上行报文解析(仅作测试,发送APP)
* 注意:仅选择其中个ID作为测试
************************************************************/
struct down_APPframe frame_up_app_process(struct can_frame r_frame){
struct down_APPframe r_send_frame;
//-------------------------------------------------------------------
//ID:0x518
//-------------------------------------------------------------------
r_send_frame.head = 1; //头部
r_send_frame.MessageIdentification = 1; //报文识别
r_send_frame.RemoteIdentification = 1; //远程识别
r_send_frame.ElementLength = 1; //报文长度
r_send_frame.PositionTime = 1; //地址时间
r_send_frame.VehicleID = r_frame.data[7]; //控制车辆ID
r_send_frame.Left = (r_frame.data[6] & 0x01); //左
r_send_frame.Right = ((r_frame.data[6] & 0x02)>>1); //右
r_send_frame.Brake =(r_frame.data[6] & 0x04)>>2; //刹车
r_send_frame.Accelerator = ((r_frame.data[6] & 0x08)>>3); //加速
r_send_frame.LFWindowsStatus =((((r_frame.data[6] & 0xf0)>>4) + ((r_frame.data[5] & 0x07)<<4))); r_send_frame.RFWindowsStatus =((((r_frame.data[5] & 0xf8)>>3) + ((r_frame.data[4] & 0x03)<<5)));//右前窗户状态
r_send_frame.LRWindowsStatus =((((r_frame.data[4] & 0xfc)>>2) + ((r_frame.data[3] & 0x01)<<6)));//左后窗户状态
r_send_frame.RRWindowsStatus =((r_frame.data[3] & 0xfe)>>1); //右后窗户状态
r_send_frame.EmergencyBrakingStatus =((r_frame.data[2] & 0x01));//紧急刹车状态
r_send_frame.LockingStatus =((r_frame.data[2] & 0x02)>>1); //车锁状态
r_send_frame.FlameoutStatus =((r_frame.data[2] & 0x04)>>2); //序列状态
r_send_frame.GearStatus =((r_frame.data[2] & 0x30>>4)); //门状态
return r_send_frame;
}
/************************************************************
* 功能:上行报文解析(仅作测试,发送模拟器)
* 注意:修改时注意函数返回值类型
************************************************************/
struct down_SIMframe frame_up_sim_process(struct can_frame r_frame){
struct down_SIMframe r_send_frame;
//-------------------------------------------------------------------
//ID:0x517
//-------------------------------------------------------------------
int angle1;
short angle2;
unsigned int speed1, speed2;
float angle, speed;
r_send_frame.head = 1;
r_send_frame.MessageIdentification = 1;
//r_send_frame.RemoteIdentification = 1;
r_send_frame.ElementLength = 1;
r_send_frame.PositionTime = 1;
r_send_frame.VehicleID = 0x000A;
speed1 = r_frame.data[3] + (r_frame.data[2]<<8);
//speed2 = r_frame.data[2] + (r_frame.data[3] << 8);
//angle1 = r_frame.data[0] + (r_frame.data[1] << 8);
angle2= r_frame.data[1] + (r_frame.data[0] << 8);
//angle = angle1*0.1;
//printf("Angle1:%f\n",angle);
speed = speed1*0.05625;
printf("Speed:%f\n", speed);
// speed = speed2*0.05625;
// printf("Speed2:%f/n", speed);
r_send_frame.Con_Speed = speed * 100;
angle = angle2*0.1;
printf("Angle:%f\n", angle);
r_send_frame.Con_Angle = angle * 100;
// printf("Speed:%d\n", speed);
// printf("%x %x %x %x %x %x %x %x\n", r_frame.data[7], r_frame.data[6], r_frame.data[5], r_frame.data[4], r_frame.data[3], r_frame.data[2], r_frame.data[1], r_frame.data[0] );
r_send_frame.Hand_Brake = 0;
r_send_frame.Vehicle_Start = 0;
r_send_frame.Vehicle_Stop = 0;
r_send_frame.Vehicle_Gear = 0;
/* r_send_frame.Hand_Brake = r_frame.data[4] & 0x01;
r_send_frame.Vehicle_Start = (r_frame.data[4] & 0x02)>>1;
r_send_frame.Vehicle_Stop = (r_frame.data[4] & 0x04)>>2;
r_send_frame.Vehicle_Gear = (r_frame.data[4] & 0x18)>>3;
*/
return r_send_frame;
}
以上是关于c_cpp 上行报文解析的主要内容,如果未能解决你的问题,请参考以下文章