message_queue.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #pragma once
  2. #include<mutex>
  3. #include<memory>
  4. #include<string>
  5. #include<condition_variable>
  6. #include <vector>
  7. #include "protocol.pb.h"
  8. #include "../common/iobuffer.h"
  9. #include "../common/socket_client.h"
  10. #include "../common/sensor_socket.h"
  11. #include "../common/update_thread.h"
  12. #include "MqttClient.h"
  13. #include "DataMqttClient.h"
  14. #include "can_bus.h"
  15. #include "radar_can.h"
  16. #include "pcan_sensor.h"
  17. #include "radar_ip.h"
  18. #ifdef LIDAR_SENSOR
  19. #include "./lidar/lidar_sensor.h"
  20. #endif
  21. class CImuSensor;
  22. class SocketClient;
  23. class CPeerConnection;
  24. class VideoRenderer;
  25. class CMqttSensor;
  26. class CRtkSensor;
  27. class CDataMqttSensor;
  28. class CCanBusSensor;
  29. class CCanRadarSensor;
  30. class CPcanSensor;
  31. class CRadarSensor;
  32. struct ImuData;
  33. enum MessageType:int32_t
  34. {
  35. ReqVideo,
  36. RepVideo,
  37. Connected,
  38. Leave,
  39. StopSensor,
  40. Ping,
  41. AsyncMessage,
  42. //BootStrap,
  43. //Startup,
  44. };
  45. struct Message
  46. {
  47. MessageType cmd;
  48. int64_t param_l;
  49. int64_t param_r;
  50. };
  51. struct LocalCameraInfo
  52. {
  53. int32_t index;
  54. std::string label;
  55. };
  56. enum RA {
  57. RA_Boot,
  58. RA_Stop,
  59. RA_Goal,
  60. RA_Encode,
  61. };
  62. // typedef struct {
  63. // int16_t fire_status; //启动/熄火
  64. // int16_t remote_forward; //远程控制前进
  65. // int16_t remote_backward; //远程控制后退
  66. // int16_t Brake; //刹车
  67. // int16_t Park; //驻车
  68. // int16_t Outrigger_status; //支腿
  69. // int16_t Turn_angle; //转弯角度
  70. // int16_t Left_turn; //左旋 左手柄 左信号
  71. // int16_t Right_turn; //右旋 右手柄 右信号
  72. // int16_t Raised; //小臂抬起 左手柄 向后
  73. // int16_t Decrease; //小臂下降 左手柄 向前
  74. // int16_t Stretch; //大臂伸起 右手柄 向后
  75. // int16_t Bulls_decline ; //大臂下降 右手柄 向前
  76. // int16_t Material ; //吸盘吸料
  77. // int16_t Discharge ; //吸盘放料
  78. // int16_t zhua; //抓斗抓料
  79. // int16_t fang; //抓斗放料
  80. // int16_t Shell_rotation ; //贝壳斗旋转
  81. // int16_t Cabin ; //驾驶室升
  82. // int16_t Cab ; //驾驶室降
  83. // int16_t Working_signal ; //作业灯开/关
  84. // int16_t Turn_left_signal; //左转向 开/关
  85. // int16_t Turn_right_signal ; //右转向 开/关
  86. // int16_t Warning_Light ; //警示灯 开/关
  87. // int16_t Trumpet; //喇叭
  88. // int16_t Security_lock ; //安全锁 开/关
  89. // int16_t Urget_stop ; //急停
  90. // int16_t Vehicle_id; //车辆id
  91. // } vehicle_status;
  92. class CIOBuffer;
  93. struct RadarData;
  94. class CMessageQueue:public INativeNotify
  95. {
  96. public:
  97. CMessageQueue();
  98. virtual ~CMessageQueue();
  99. void Create();
  100. void EnQueue(CIOBuffer* pBuffer);
  101. void Process();
  102. //virtual void OnAdd(bool bRet) override;
  103. virtual void OnAdd(bool bRet) override;
  104. virtual void OnConnected(bool bRet) override;
  105. // virtual bool IsCarId(int32_t value) override;
  106. // virtual void WriteCanMessage(std::unordered_map<int32_t, cannet_frame>& node,bool islidar) override;
  107. #ifdef WIN32
  108. virtual void OnVideoRep(int32_t index,int32_t peer) override;
  109. #else
  110. virtual void OnVideoReq(int32_t index,int32_t peer) override;
  111. #endif
  112. virtual void OnVideoOffer(int32_t index,const char* type, const char* sdp) override;
  113. virtual void OnVideoAnswer(int32_t index, const char* type, const char* sdp) override;
  114. virtual void OnVideoCandidate(int32_t index,const char* candidate,
  115. int32_t sdp_mline_index,
  116. const char* sdp_mid) override;
  117. /*virtual void OnVideoAddTrack(RemoteVideoTrackWrapper* ptr) = 0;*/
  118. //virtual void OnCancelReq(int32_t index) override;
  119. virtual void OnVideoLeave(int32_t peer,EgoType type) override;
  120. virtual void OnMessageFrameNotify(ChannelType type,int16_t cmd,int16_t length,const void * data) override;
  121. void OnNotifyConnected(bool bRet);
  122. void OnNotifyReq(int32_t index);
  123. void OnNotifyRep(int32_t index);
  124. void OnNotifyStopSensor();
  125. void OnNotifyLeave();
  126. void OnNotifyMessage();
  127. void OnNotifyPing(int64_t value);
  128. void InitPeerConnection(int32_t peer,int32_t index);
  129. void WriteIMUData(ImuData* data);
  130. void WriteRadarData(RadarData& data);
  131. void WriteRobotStatus(int32_t value,int32_t desc);
  132. void WritePacket(ChannelType type, CIOBuffer & pBuffer);
  133. void SwitchCamera(bool front);
  134. void SetTick(long long tick);
  135. void ChangeState(UserState state);
  136. void OnSwitchDriver();
  137. #ifdef LIDAR_SENSOR
  138. void WriteLidarPoint(const PointCloudMsg<PointXYZI>& msg,ChannelType side);
  139. #endif
  140. void StopCar();
  141. // void StartCar();
  142. void CheckSignal();
  143. void SendZGJStatus(int status);
  144. // void SendVehicleStatus(int16_t Direction,int16_t Hand_Throttle,int16_t Foot_Throttle,int16_t Brake);
  145. void SendVehicleStatus(vehicle_status can_status);
  146. bool bStopedCar;
  147. long long _curStopTick;
  148. bool btimeStopedCar;
  149. long long DataMqtt_curTick;
  150. bool DataMqtt_SendDate;
  151. FILE *File_fd;
  152. int32_t _Version;
  153. void SerichFile(char *filename);
  154. long long _source = 0;
  155. long long _dst = 0;
  156. private:
  157. std::mutex _lock;
  158. std::condition_variable _cv;
  159. CIOBuffer* Head;
  160. CIOBuffer* Tail;
  161. //add-3-7
  162. //CRobotSensor *cs;
  163. // std::unique_ptr<PeerConnectionWrapper> _peer_video;
  164. std::vector<std::unique_ptr<CPeerConnection> > _peerArray;
  165. std::vector<LocalCameraInfo> _cameraArray;
  166. //EgoType _egoType;
  167. //int32_t _indexOffset;
  168. // std::vector<std::unique_ptr<VideoRenderer> > _windowArray;
  169. // std::unique_ptr<VideoRenderer> _main_window;
  170. // std::unique_ptr<VideoRenderer> _arm_window;
  171. std::unique_ptr<SocketClient> _client;
  172. std::unique_ptr<SensorSocket<CImuSensor>> _imu;
  173. std::unique_ptr<SensorMQTT<CMqttSensor>> _Mqtt_ZR;
  174. std::unique_ptr<SensorMQTT<CDataMqttSensor>> _Mqtt_SE;
  175. std::unique_ptr<SensorSocket<CRtkSensor>> _Rtk;
  176. std::unique_ptr<SensorCanBus<CCanBusSensor>> _CanBusVehicle;
  177. std::unique_ptr<SensorCanBus<CCanRadarSensor>> _CanBusRadar;
  178. std::unique_ptr<SensorPeakCan<CPcanSensor>> _PcanBusVehicle;
  179. std::unique_ptr<SensorSocket<CRadarSensor>> _RadarIp;
  180. int32_t _peerId;
  181. std::string _serial;
  182. std::string _name;
  183. int32_t _uid=0;
  184. int32_t _UdpMinPort;
  185. int32_t _UdpMaxPort;
  186. CUpdateThread _updatethread;
  187. std::mutex _canLock;
  188. long long _curTick;
  189. ////////////////////////////////////////////////////////////////
  190. #ifdef LIDAR_SENSOR
  191. std::unique_ptr<CLidarSensor> _left;
  192. std::unique_ptr<CLidarSensor> _right;
  193. #endif
  194. };