123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- #include <WinSock2.h>
- #include "./include/EgoInterface.h"
- #include "EgoWindow.h"
- #include "protocol.pb.h"
- #include "udpcan.h"
- #include "../common/iobuffer.h"
- #include "protocol.pb.h"
- //#include "PCANBasic.h"
- int16_t ChangeINT(unsigned char h, unsigned char l)
- {
- int16_t hi = (int16_t)(h & 0x00FF);
- int16_t low = (int16_t)(l & 0x00FF);
- return (hi << 8) | low;
- }
- CUdpSensor::CUdpSensor(CMessageQueue* q)
- {
- _window = static_cast<CEgoWindow*>(q);
- assert(_window != nullptr);
- }
- void CUdpSensor::Start()
- {
- /*cannet_frame frame;
- memset(&frame, 0, sizeof(frame));
- frame.canid = htonl(0x0601);
- frame.dlc = 3;
- frame.data[0] = 0xb3;
- frame.data[1] = 0x10;
- frame.data[2] = 0xff;
- CIOBuffer buffer;
- memcpy(buffer.Buffer, &frame, sizeof(frame));
- buffer.Length = sizeof(frame);*/
- //_socket->Write(&buffer);
- }
- void CUdpSensor::Stop()
- {
- }
- void CUdpSensor::SetSensorSocket(SensorSocket<CUdpSensor>* can)
- {
- _socket = can;
- }
- void CUdpSensor::Notify(int8_t* buffer, int32_t size)
- {
- int16_t m_cmd = ChangeINT(buffer[1], buffer[0]);
- if (m_cmd == RemoNet::CC_STATE)
- {
- RemoNet::State msg;
- msg.ParseFromArray(buffer + 4, size - 4);
- 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();//档位信息1F 2R 3N
- 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);
- _window->WriteStatue(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;//转向编码器故障
- _window->DisplayStatue(data);
- }
- else if (m_cmd == RemoNet::CC_Ping)
- {
- for (int i = 0; i < 10; i++);
- RemoNet::CCPing Req;
- Req.ParseFromArray(buffer + 4, size - 4);
- int64_t tick = GetTickCount64();
- int32_t diff = tick - Req.tick();
- double temp = Req.temp();
- _window->DisplayPing(diff, temp);
- }
- else if (m_cmd == RemoNet::CC_Radar)
- {
- RemoNet::CCRadarMessage ReqRadar;
- ReqRadar.ParseFromArray(buffer + 4, size - 4);
- _window->DisplayRadar(ReqRadar.radar0(), ReqRadar.radar1(), ReqRadar.radar2(), ReqRadar.radar3(), ReqRadar.radar4(), ReqRadar.radar5(), ReqRadar.radar6(), ReqRadar.radar7(), ReqRadar.radar8());
- }
- }
|