udp_state.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #include "udp_state.h"
  2. #include <thread>
  3. #include "message_queue.h"
  4. CUdpStateSensor::CUdpStateSensor(CMessageQueue* q):_message(q)
  5. {
  6. _run = false;
  7. }
  8. void CUdpStateSensor::Notify(int8_t * buffer,int32_t size)
  9. {
  10. if(_run)
  11. {
  12. if(!_message->_GSML)
  13. {
  14. for(int i = 0 ; i < size ; i += 48)
  15. {
  16. memcpy(&m_StateDat,buffer + i,48);
  17. _message->_Radardata.r0 = m_StateDat.rader[0];
  18. _message->_Radardata.r1 = m_StateDat.rader[1];
  19. _message->_Radardata.r2 = m_StateDat.rader[2];
  20. _message->_Radardata.r3 = m_StateDat.rader[3];
  21. _message->_Radardata.r4 = m_StateDat.rader[4];
  22. _message->_Radardata.r5 = m_StateDat.rader[5];
  23. _message->_Radardata.r6 = m_StateDat.rader[6];
  24. _message->_Radardata.r7 = m_StateDat.rader[7];
  25. _message->_Radardata.r8 = m_StateDat.rader[8];
  26. std::cout << _message->_Radardata.r0 << _message->_Radardata.r1 << _message->_Radardata.r2 << _message->_Radardata.r3 <<
  27. _message->_Radardata.r4 << _message->_Radardata.r5 << _message->_Radardata.r6 << _message->_Radardata.r7 << _message->_Radardata.r8 << std::endl;
  28. _count++;
  29. if (_count > 4)
  30. {
  31. _message->WriteRadarData(_message->_Radardata);
  32. _count = 0;
  33. }
  34. _message->_Feeddata.wire_sensor_l = m_StateDat.outrigger[0];
  35. _message->_Feeddata.wire_sensor_r = m_StateDat.outrigger[1];
  36. unsigned char Source[12];
  37. memset(Source,0,12);
  38. if(m_StateDat.easypro[0] == '+')
  39. {
  40. sprintf((char *)Source,"0.%d",m_StateDat.easypro[1]);
  41. _message->_Feeddata.steer_angle = strtof((const char *)Source,NULL);
  42. }
  43. else if(m_StateDat.easypro[0] == '-')
  44. {
  45. sprintf((char *)Source,"1.%d",m_StateDat.easypro[1]);
  46. _message->_Feeddata.steer_angle = strtof((const char *)Source,NULL);
  47. }
  48. _message->_Feeddata.speed = m_StateDat.speed;
  49. std::cout << _message->_Feeddata.wire_sensor_l << _message->_Feeddata.wire_sensor_r << _message->_Feeddata.steer_angle << _message->_Feeddata.steer_angle <<
  50. _message->_Feeddata.speed << std::endl;
  51. //SendStatusToMSG();
  52. }
  53. }
  54. else
  55. {
  56. uint8_t temp = ':',temp1 = ',',*p = NULL,*p1 = NULL;
  57. p = (uint8_t *)strchr((const char *)buffer,temp);
  58. unsigned long m_time = strtol((const char *)p + 1,NULL,10);
  59. p = (uint8_t *)strchr((const char *)buffer,temp1);
  60. unsigned long m_startrevord = strtol((const char *)p + 1,NULL,10);
  61. p1 = (uint8_t *)strchr((const char *)p + 1,temp1);
  62. unsigned long m_deviceid = strtol((const char *)p1 + 1,NULL,10);
  63. _message->SetGsmlInfo(m_time,m_startrevord,m_deviceid);
  64. }
  65. }
  66. }
  67. void CUdpStateSensor::Start()
  68. {
  69. if(!_run)
  70. {
  71. //_udp_thread = std::thread(&CUdpStateSensor::Run, this);
  72. _run = true;
  73. }
  74. }
  75. void CUdpStateSensor::Run()
  76. {
  77. CIOBuffer buffer;
  78. while (_run)
  79. {
  80. }
  81. }
  82. void CUdpStateSensor::SetSensorSocket(SensorSocket<CUdpStateSensor>* udpstate)
  83. {
  84. _udpcan = udpstate;
  85. }
  86. void CUdpStateSensor::Stop()
  87. {
  88. if (_run)
  89. {
  90. _run = false;
  91. //_udp_thread.join();
  92. }
  93. }
  94. void CUdpStateSensor::SendStatusToMSG()
  95. {
  96. RemoNet::State req;
  97. /*
  98. req.set_engine_speed(_data.Engine_speed);
  99. req.set_travel_speed(_data.Travel_speed);
  100. req.set_fuel_level(_data.Fuel_level);
  101. req.set_engine_temperature(_data.Engine_temperature);
  102. req.set_hydraulic_oil_temperature(_data.Hydraulic_oil_temperature);
  103. req.set_main_pump_1_pressure(_data.Main_pump_1_pressure);
  104. req.set_main_pump_2_pressure(_data.Main_pump_2_pressure);
  105. req.set_hand_gear(_data.Hand_gear);
  106. req.set_actual_gear(_data.Actual_gear);
  107. req.set_gripper_height(_data.Gripper_height);
  108. req.set_amplitude(_data.amplitude);
  109. req.set_boom_angle(_data.Boom_angle);
  110. req.set_stick_angle(_data.Stick_angle);
  111. req.set_idle_protection(_data.Idle_protection);
  112. req.set_front_toggle(_data.Front_toggle);
  113. req.set_back_toggle(_data.Back_toggle);
  114. req.set_error_buff((char *)_data.Error_Buff,8);
  115. */
  116. req.set_work_pressure(_message->_Feeddata.work_pressure);
  117. req.set_brake_pressure(_message->_Feeddata.brake_pressure);
  118. req.set_gearbox_oil_temp(_message->_Feeddata.gearbox_oil_temp);
  119. req.set_gearbox_oil_pressure(_message->_Feeddata.gearbox_oil_pressure);
  120. req.set_engine_rpm(_message->_Feeddata.engine_rpm);//发动机转速
  121. req.set_speed(_message->_Feeddata.speed);//不知道?---可能是后加的传感器---驱动轮增量编码器
  122. req.set_gear(_message->_Feeddata.gear);
  123. req.set_engine_pressure(_message->_Feeddata.engine_pressure);//发动机压力
  124. req.set_cold_water(_message->_Feeddata.cold_water);//冷却液温度-发动机水温
  125. req.set_steer_angle(_message->_Feeddata.steer_angle);//转向角度(原来金川是轮子的现在大冶用铰链位置) 铰接转向姿态编码器
  126. req.set_left_lock(_message->_Feeddata.left_lock);//遥操模式
  127. req.set_right_lock(_message->_Feeddata.right_lock);//人工模式
  128. req.set_engine_time(_message->_Feeddata.engine_time);//发动机运行小时
  129. req.set_wire_sensor_l(_message->_Feeddata.wire_sensor_l);//拉线传感器左侧
  130. req.set_wire_sensor_r(_message->_Feeddata.wire_sensor_r);//拉线传感器右侧
  131. req.set_fuel_level(_message->_Feeddata.fuel_level);//燃油油位
  132. req.set_lock_switch_l(_message->_Feeddata.lock_switch_l);//锁钩到位开关左
  133. req.set_lock_switch_r(_message->_Feeddata.lock_switch_r); //锁钩到位开关右
  134. req.set_tip_limit(_message->_Feeddata.tip_limit);//倾翻限位
  135. req.set_turn_left(_message->_Feeddata.turn_left);//左转
  136. req.set_turn_right(_message->_Feeddata.turn_right);//右转
  137. req.set_hight_beam(_message->_Feeddata.hight_beam);//远光灯
  138. req.set_low_beam(_message->_Feeddata.low_beam);//近光灯
  139. req.set_parking(_message->_Feeddata.parking);//驻车
  140. req.set_brake(_message->_Feeddata.brake);//刹车
  141. req.set_back_car(_message->_Feeddata.back_car);//倒车
  142. req.set_front_work_lamp(_message->_Feeddata.front_work_lamp);//前工作灯
  143. req.set_rear_work_lamp(_message->_Feeddata.rear_work_lamp);//后工作灯
  144. req.set_cargo_weight(_message->_Feeddata.cargo_weight);//渣包重量
  145. req.set_system_vol(_message->_Feeddata.system_vol);//系统电压
  146. req.set_error_buff((char *)_message->_Feeddata.Error_Buff,8);//报警信息
  147. req.set_f_gear(_message->_Feeddata.f_gear);//1F,2R,3N
  148. req.set_gear_1(_message->_Feeddata.gear_1);//1,2,3,4
  149. MessageHead Head;
  150. CIOBuffer pBuffer;
  151. Head.Command = RemoNet::CC_STATE;
  152. Head.Length = req.ByteSizeLong();
  153. Head.Serialize(pBuffer.Buffer);
  154. auto ptr = pBuffer.Buffer + MessageHead::Size();
  155. req.SerializeToArray(ptr, Head.Length);
  156. pBuffer.Length = MessageHead::Size() + Head.Length;
  157. _message->WritePacket(ChannelType::CHANNEL_CAR, pBuffer);
  158. }