#include #include "../common/comm.h" #include "Protocol.pb.h" #include "car_sim.h" #include "EgoClient.h" #include "car_sim.h" #include #include "control_sensor.h" #include #include #include #include #include CCarSim::CCarSim(CEgoClient* car) :_car(car) { } void CCarSim::Start() { } void CCarSim::Stop() { } void CCarSim::OnPeerMessage(int16_t cmd, int16_t length, const void* data) { switch (cmd) { case RemoNet::CC_Ping: { RemoNet::CCPing Req; Req.ParseFromArray(data, length); int64_t tick = GetTickCount64(); int32_t diff = tick - Req.tick(); double temp = Req.temp(); testPing= Req.tick(); //增加打印日志文件内容 /* auto now = std::chrono::system_clock::now(); auto time = std::chrono::system_clock::to_time_t(now); auto localtime = std::localtime(&time); // 格式化当前系统时间作为文件名 std::ostringstream filenameStream; filenameStream << "E:\\DY\\EgoDY\\Run\\log_" << std::put_time(localtime, "%Y%m%d_%H%M%S") << ".txt"; filename = filenameStream.str(); // 添加日志记录 std::ofstream logFile("E:\\DY\\EgoDY\\Run\\log.txt", std::ios::app); //std::ofstream logFile(filename, std::ios::app); if (logFile.is_open()) { logFile << "System Time: " << std::put_time(localtime, "%Y-%m-%d %H:%M:%S") << std::endl; logFile << "Diff: " << diff << " Temp: " << temp << std::endl; //logFile.close(); } */ _car->OnPingValue(diff, temp); } break; case RemoNet::CC_StopACK: { _car->OnStopAck(); } case RemoNet::CC_STATE: { //创建一个RemoNet::State RemoNet::State msg; //用ParseFromArray(data, length)将从data中解析的数据填充到msg对象中 msg.ParseFromArray(data, length); //_control_sensor->_automous = (msg.left_lock()!=0) ? true:false;//left_lock为1时,切换为遥操,发送报文给下位机 //创建了FeedData类型的数据结构,用于存储从msg中提取的不同数据字段 FeedData data; data.brake_pressure = msg.brake_pressure();//制动气压 data.engine_rpm = msg.engine_rpm();//发动机转速 data.engine_pressure = msg.engine_pressure();//发动机压力 data.gearbox_oil_pressure = msg.gearbox_oil_pressure();//变速箱油压 data.gearbox_oil_temp = msg.gearbox_oil_temp();//变速箱油温 data.speed = msg.speed();//行驶速度 data.cold_water = msg.cold_water();//发动机水温 data.steer_angle = msg.steer_angle();//车辆姿态???原来是轮子现在定义为铰链 data.left_lock_status = msg.left_lock(); data.right_lock_status = msg.right_lock(); data.work_pressure = msg.work_pressure(); //data.gear = msg.gear(); //发送给qt的信息以下是大冶增加的: data.engine_time = msg.engine_time();//发动机工作小时 data.wire_sensor_l = msg.wire_sensor_l();//左支腿高度 data.wire_sensor_r = msg.wire_sensor_r();//右支腿高度 //OutputDebugStringA(("===================打印左支腿高度 " + std::to_string(data.wire_sensor_l) + "============\n").c_str()); //OutputDebugStringA(("===================打印右支腿高度 " + std::to_string(data.wire_sensor_r) + "============\n").c_str()); data.fuel_level = msg.fuel_level();//燃油油位油量 //data.lock_switch_l = msg.lock_switch_l();//锁钩到位开关L //data.lock_switch_r = msg.lock_switch_r();//锁钩到位开关R //data.tip_limit = msg.tip_limit();//倾翻限位 data.lock_switch_l = msg.outgrigger_l();//左支腿伸到位开关 data.lock_switch_r = msg.outgrigger_r();//右支腿伸到位开关 data.tip_limit = msg.tip_pressure();//倾翻压力开关 data.turn_left = msg.turn_left();//左转 data.turn_right = msg.turn_right();//右转 data.hight_beam = msg.hight_beam();//远光灯 data.low_beam = msg.low_beam();//近光灯 data.parking = msg.parking();//驻车 data.brake = msg.brake();//刹车 data.back_car = msg.back_car();//倒车 data.front_work_lamp = msg.front_work_lamp();//前工作灯 data.rear_work_lamp = msg.rear_work_lamp();//后工作灯 data.cargo_weight = msg.cargo_weight();//渣包重量 data.system_vol = msg.system_vol();//系统电压 data.f_gear = msg.f_gear();//档位信息1=F 2=R 3=N data.gear_1 = msg.gear_1();//档位1234 //发送信息给PCAN(下位机传的0x280透传) TPCANMsg* CANMsg = (TPCANMsg*)malloc(sizeof(TPCANMsg)); CANMsg->ID = 0x280; CANMsg->MSGTYPE = PCAN_MESSAGE_STANDARD; CANMsg->LEN = msg.error_buff().size(); memcpy(CANMsg->DATA, data.warningData, CANMsg->LEN); //SendCANMessage(CANMsg); _car->SendCanDate(CANMsg); free(CANMsg); for (int i = 0; i < msg.error_buff().size(); ++i)//报警信息 { data.warningData[i] = msg.error_buff()[i]; } //将报警信息解读出来赋值给data中的变量 data.low_oil_pressure_alarm = (data.warningData[0] & 0x1) == 0x1 ? 1 : 0;//机油压力低报警 data.engine_water_temperature_alarm = (data.warningData[0] & 0x2) == 0x2 ? 1 : 0;//发动机水温高报警 data.high_engine_oil_temperature_alarm = (data.warningData[0] & 0x4) == 0x4 ? 1 : 0;//发动机油温高报警 data.engine_water_level_low_alarm = (data.warningData[0] & 0x8) == 0x8 ? 1 : 0;//发动机水位低报警 data.low_fuel_oil_alarm = (data.warningData[0] & 0x10) == 0x10 ? 1 : 0;//燃油油位低报警 data.return_oil_filter_blocked_alarm = (data.warningData[0] & 0x20) == 0x20 ? 1 : 0;//回油滤网堵塞报警 data.oil_filter_blocked_alarm = (data.warningData[0] & 0x40) == 0x40 ? 1 : 0;//吸油滤网堵塞报警 data.control_screen_blockage_alarm = (data.warningData[0] & 0x80) == 0x80 ? 1 : 0;//控制滤网堵塞报警 data.emergency_filter_blocking_alarm = (data.warningData[1] & 0x1) == 0x1 ? 1 : 0;//应急滤网堵塞报警 data.cooling_filter_blocked_alarm = (data.warningData[1] & 0x2) == 0x2 ? 1 : 0;//冷却滤网堵塞报警 data.electric_pump_screen_blocked_alarm = (data.warningData[1] & 0x4) == 0x4 ? 1 : 0;//电泵滤网堵塞报警 data.brake_filter_blocked_alarm = (data.warningData[1] & 0x8) == 0x8 ? 1 : 0;//制动滤网堵塞报警 data.variable_speed_filter_blocked_alarm = (data.warningData[1] & 0x10) == 0x10 ? 1 : 0;//变速滤网堵塞报警 data.low_voltage_alarm = (data.warningData[1] & 0x20) == 0x20 ? 1 : 0;//电压低报警 data.high_transmission_oil_temperature = (data.warningData[2] & 0x1) == 0x1 ? 1 : 0;//变速箱油温高 data.transmission_oil_pressure_is_low = (data.warningData[2] & 0x2) == 0x2 ? 1 : 0;//变速箱油压低 data.oil_temperature_sensor_1_is_faulty = (data.warningData[2] & 0x4) == 0x4 ? 1 : 0; //油温传感器1故障 data.oil_temperature_sensor_2_is_faulty = (data.warningData[2] & 0x8) == 0x8 ? 1 : 0;//油温传感器2故障 data.oil_level_sensor_is_faulty = (data.warningData[2] & 0x10) == 0x10 ? 1 : 0;//油位传感器故障 data.front_throttle_fault = (data.warningData[2] & 0x20) == 0x20 ? 1 : 0;//前油门故障 data.rear_throttle_fault = (data.warningData[2] & 0x40) == 0x40 ? 1 : 0;//后油门故障 data.handle_of_the_upper_arm_is_faulty = (data.warningData[2] & 0x80) == 0x80 ? 1 : 0;//大臂手柄故障 data.left_leg_handle_is_faulty = (data.warningData[3] & 0x8) == 0x8 ? 1 : 0;//左支腿手柄故障 data.right_leg_handle_is_faulty = (data.warningData[3] & 0x10) == 0x10 ? 1 : 0;//右支腿手柄故障 data.engine_bus_fault = (data.warningData[3] & 0x20) == 0x20 ? 1 : 0;//发动机总线故障 data.transmission_bus_fault = (data.warningData[3] & 0x40) == 0x40 ? 1 : 0;//变速箱总线故障 data.remote_control_bus_fault = (data.warningData[3] & 0x80) == 0x80 ? 1 : 0;//遥控器总线故 data.rod_chamber_pressure_sensor_is_faulty = (data.warningData[4] & 0x1) == 0x1 ? 1 : 0;//有杆腔压力传感器故障 data.no_rod_chamber_pressure_sensor_is_faulty = (data.warningData[4] & 0x2) == 0x2 ? 1 : 0;//无杆腔压力传感器故障 data.brake_pressure_sensor_is_faulty = (data.warningData[4] & 0x4) == 0x4 ? 1 : 0;//制动压力传感器故障 data.system_pressure_sensor_is_faulty = (data.warningData[4] & 0x8) == 0x8 ? 1 : 0;//系统压力传感器故障 data.control_pressure_sensor_is_faulty = (data.warningData[4] & 0x10) == 0x10 ? 1 : 0;//控制压力传感器故障 data.steering_pressure_sensor_is_faulty = (data.warningData[4] & 0x20) == 0x20 ? 1 : 0;//转向压力传感器故障 data.pressure_sensor_of_the_lower_arm_is_faulty = (data.warningData[4] & 0x40) == 0x40 ? 1 : 0;//小臂压力传感器故障 data.locking_pin_displacement_sensor_L_is_faulty = (data.warningData[5] & 0x1) == 0x1 ? 1 : 0;//锁销位移传感器L故障 data.locking_pin_displacement_sensor_R_is_faulty = (data.warningData[5] & 0x2) == 0x2 ? 1 : 0;//锁销位移传感器R故障 data.leg_displacement_sensor_L_is_faulty = (data.warningData[5] & 0x4) == 0x4 ? 1 : 0;//支腿位移传感器L故障 data.leg_displacement_sensor_R_is_faulty = (data.warningData[5] & 0x8) == 0x8 ? 1 : 0;//支腿位移传感器R故障 data.steering_encoder_failure = (data.warningData[5] & 0x10) == 0x10 ? 1 : 0;//转向编码器故障 //qqq 发送给QT _car->OnFeedPage(data); } break; case RemoNet::CC_NDTPOS: { RemoNet::NDTPos Req; Req.ParseFromArray(data, length); Position pos; pos.x = Req.x(); pos.y = Req.y(); pos.z = Req.z(); pos.rx = Req.rx(); pos.ry = Req.ry(); pos.rz = Req.rz(); pos.rw = Req.rw(); _car->OnNDTPos(&pos); } break; } }