message_queue.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 "can_bus.h"
  14. #include "serial.h"
  15. #include "modbus.h"
  16. #include "Outriggers.h"
  17. #include "radar_can.h"
  18. #include "udp_can.h"
  19. #include "udp_state.h"
  20. #ifdef LIDAR_SENSOR
  21. #include "./lidar/lidar_sensor.h"
  22. #endif
  23. class CRadarSensor;
  24. class CImuSensor;
  25. class CRobotSensor;
  26. class SocketClient;
  27. class CPeerConnection;
  28. class VideoRenderer;
  29. class CMqttSensor;
  30. class CRtkSensor;
  31. class CCanBusSensor;
  32. class CSerialSensor;
  33. class CModbusTcpSensor;
  34. class COutriggersSensor;
  35. class CCanRadarSensor;
  36. class CUdpCanSensor;
  37. class CUdpStateSensor;
  38. struct ImuData;
  39. enum MessageType:int32_t
  40. {
  41. ReqVideo,
  42. RepVideo,
  43. Connected,
  44. Leave,
  45. StopSensor,
  46. Ping,
  47. AsyncMessage,
  48. //BootStrap,
  49. //Startup,
  50. };
  51. struct Message
  52. {
  53. MessageType cmd;
  54. int64_t param_l;
  55. int64_t param_r;
  56. };
  57. struct LocalCameraInfo
  58. {
  59. int32_t index;
  60. std::string label;
  61. };
  62. enum RA {
  63. RA_Boot,
  64. RA_Stop,
  65. RA_Goal,
  66. RA_Encode,
  67. };
  68. //#pragma pack()
  69. struct RadarData
  70. {
  71. int32_t r0;
  72. int32_t r1;
  73. int32_t r2;
  74. int32_t r3;
  75. int32_t r4;
  76. int32_t r5;
  77. int32_t r6;
  78. int32_t r7;
  79. int32_t r8;
  80. };
  81. class CIOBuffer;
  82. //struct RadarData;
  83. class CMessageQueue:public INativeNotify
  84. {
  85. public:
  86. CMessageQueue();
  87. virtual ~CMessageQueue();
  88. void Create();
  89. void EnQueue(CIOBuffer* pBuffer);
  90. void Process();
  91. //virtual void OnAdd(bool bRet) override;
  92. virtual void OnAdd(bool bRet) override;
  93. virtual void OnConnected(bool bRet) override;
  94. // virtual bool IsCarId(int32_t value) override;
  95. // virtual void WriteCanMessage(std::unordered_map<int32_t, cannet_frame>& node,bool islidar) override;
  96. #ifdef WIN32
  97. virtual void OnVideoRep(int32_t index,int32_t peer) override;
  98. #else
  99. virtual void OnVideoReq(int32_t index,int32_t peer) override;
  100. #endif
  101. virtual void OnVideoOffer(int32_t index,const char* type, const char* sdp) override;
  102. virtual void OnVideoAnswer(int32_t index, const char* type, const char* sdp) override;
  103. virtual void OnVideoCandidate(int32_t index,const char* candidate,
  104. int32_t sdp_mline_index,
  105. const char* sdp_mid) override;
  106. /*virtual void OnVideoAddTrack(RemoteVideoTrackWrapper* ptr) = 0;*/
  107. //virtual void OnCancelReq(int32_t index) override;
  108. virtual void OnVideoLeave(int32_t peer,EgoType type) override;
  109. virtual void OnMessageFrameNotify(ChannelType type,int16_t cmd,int16_t length,const void * data) override;
  110. void OnNotifyConnected(bool bRet);
  111. void OnNotifyReq(int32_t index);
  112. void OnNotifyRep(int32_t index);
  113. void OnNotifyStopSensor();
  114. void OnNotifyLeave();
  115. void OnNotifyMessage();
  116. void OnNotifyPing(int64_t value);
  117. void InitPeerConnection(int32_t peer,int32_t index);
  118. void WriteIMUData(ImuData* data);
  119. void WriteRadarData(RadarData& data);
  120. void WriteRobotStatus(int32_t value,int32_t desc);
  121. void WritePacket(ChannelType type, CIOBuffer & pBuffer);
  122. void SwitchCamera(bool front);
  123. void SetTick(long long tick);
  124. void ChangeState(UserState state);
  125. void OnSwitchDriver();
  126. void SendVehicleStatue();
  127. void SetTickLive(long long tick);
  128. void Senddirection(int16_t speed);
  129. void SendEmergency();
  130. void SendNoEmergency();
  131. #ifdef LIDAR_SENSOR
  132. void WriteLidarPoint(const PointCloudMsg<PointXYZI>& msg,ChannelType side);
  133. #endif
  134. void StopCar();
  135. // void StartCar();
  136. void CheckSignal();
  137. void SendZGJStatus(int status);
  138. bool bStopedCar;
  139. long long _curStopTick;
  140. bool btimeStopedCar;
  141. FeedData _Feeddata;
  142. RadarData _Radardata;
  143. std::unique_ptr<SensorCanBus<CCanBusSensor>> _CanBusVehicle;
  144. int32_t _GSML;
  145. void SetGsmlInfo(int64_t time,int64_t StartRecord,int64_t DeviceId);
  146. private:
  147. std::mutex _lock;
  148. std::condition_variable _cv;
  149. CIOBuffer* Head;
  150. CIOBuffer* Tail;
  151. //add-3-7
  152. //CRobotSensor *cs;
  153. // std::unique_ptr<PeerConnectionWrapper> _peer_video;
  154. std::vector<std::unique_ptr<CPeerConnection> > _peerArray;
  155. std::vector<LocalCameraInfo> _cameraArray;
  156. //EgoType _egoType;
  157. //int32_t _indexOffset;
  158. // std::vector<std::unique_ptr<VideoRenderer> > _windowArray;
  159. // std::unique_ptr<VideoRenderer> _main_window;
  160. // std::unique_ptr<VideoRenderer> _arm_window;
  161. std::unique_ptr<SocketClient> _client;
  162. std::unique_ptr<SensorSocket<CRadarSensor>> _radar;
  163. std::unique_ptr<SensorSocket<CImuSensor>> _imu;
  164. std::unique_ptr<SensorPeakCan<CRobotSensor>> _robot;
  165. std::unique_ptr<SensorMQTT<CMqttSensor>> _Mqtt;
  166. std::unique_ptr<SensorSocket<CRtkSensor>> _Rtk;
  167. std::unique_ptr<SensorSerial<CSerialSensor>> _ArticulatedSensor;
  168. std::unique_ptr<SensorModbusTcp<CModbusTcpSensor>> _ModbusTcp_Drivenwheels;
  169. std::unique_ptr<SensorModbusTcp<COutriggersSensor>> _ModbusTcp_Outriggers;
  170. std::unique_ptr<SensorCanBus<CCanRadarSensor>> _CanBusRadar;
  171. std::unique_ptr<SensorSocket<CUdpCanSensor>> _UdpCan;
  172. std::unique_ptr<SensorSocket<CUdpStateSensor>> _UdpState;
  173. int32_t _peerId;
  174. std::string _serial;
  175. std::string _name;
  176. int32_t _uid=0;
  177. int32_t _UdpMinPort;
  178. int32_t _UdpMaxPort;
  179. CUpdateThread _updatethread;
  180. std::mutex _canLock;
  181. long long _curTick;
  182. ////////////////////////////////////////////////////////////////
  183. #ifdef LIDAR_SENSOR
  184. std::unique_ptr<CLidarSensor> _left;
  185. std::unique_ptr<CLidarSensor> _right;
  186. #endif
  187. };