message_queue.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 <sys/time.h>
  13. #include "MqttClient.h"
  14. #include "DataMqttClient.h"
  15. #include "can_bus.h"
  16. #include "radar_can.h"
  17. #include "pcan_sensor.h"
  18. #include "radar_ip.h"
  19. #ifdef LIDAR_SENSOR
  20. #include "./lidar/lidar_sensor.h"
  21. #endif
  22. class CImuSensor;
  23. class SocketClient;
  24. class CPeerConnection;
  25. class VideoRenderer;
  26. class CMqttSensor;
  27. class CRtkSensor;
  28. class CDataMqttSensor;
  29. class CCanBusSensor;
  30. class CCanRadarSensor;
  31. class CPcanSensor;
  32. class CRadarSensor;
  33. struct ImuData;
  34. enum MessageType:int32_t
  35. {
  36. ReqVideo,
  37. RepVideo,
  38. Connected,
  39. Leave,
  40. StopSensor,
  41. Ping,
  42. AsyncMessage,
  43. //BootStrap,
  44. //Startup,
  45. };
  46. struct Message
  47. {
  48. MessageType cmd;
  49. int64_t param_l;
  50. int64_t param_r;
  51. };
  52. struct LocalCameraInfo
  53. {
  54. int32_t index;
  55. std::string label;
  56. };
  57. enum RA {
  58. RA_Boot,
  59. RA_Stop,
  60. RA_Goal,
  61. RA_Encode,
  62. };
  63. class CIOBuffer;
  64. struct RadarData;
  65. class CMessageQueue:public INativeNotify
  66. {
  67. public:
  68. CMessageQueue();
  69. virtual ~CMessageQueue();
  70. void Create();
  71. void EnQueue(CIOBuffer* pBuffer);
  72. void Process();
  73. //virtual void OnAdd(bool bRet) override;
  74. virtual void OnAdd(bool bRet) override;
  75. virtual void OnConnected(bool bRet) override;
  76. // virtual bool IsCarId(int32_t value) override;
  77. // virtual void WriteCanMessage(std::unordered_map<int32_t, cannet_frame>& node,bool islidar) override;
  78. #ifdef WIN32
  79. virtual void OnVideoRep(int32_t index,int32_t peer) override;
  80. #else
  81. virtual void OnVideoReq(int32_t index,int32_t peer) override;
  82. #endif
  83. virtual void OnVideoOffer(int32_t index,const char* type, const char* sdp) override;
  84. virtual void OnVideoAnswer(int32_t index, const char* type, const char* sdp) override;
  85. virtual void OnVideoCandidate(int32_t index,const char* candidate,
  86. int32_t sdp_mline_index,
  87. const char* sdp_mid) override;
  88. /*virtual void OnVideoAddTrack(RemoteVideoTrackWrapper* ptr) = 0;*/
  89. //virtual void OnCancelReq(int32_t index) override;
  90. virtual void OnVideoLeave(int32_t peer,EgoType type) override;
  91. virtual void OnMessageFrameNotify(ChannelType type,int16_t cmd,int16_t length,const void * data) override;
  92. virtual void OnMqttUser(std::string user_uid,int32_t cockpitId,int32_t vehicleId) override;//增加
  93. void OnNotifyConnected(bool bRet);
  94. void OnNotifyReq(int32_t index);
  95. void OnNotifyRep(int32_t index);
  96. void OnNotifyStopSensor();
  97. void OnNotifyLeave();
  98. void OnNotifyMessage();
  99. void OnNotifyPing(int64_t value);
  100. void InitPeerConnection(int32_t peer,int32_t index);
  101. void WriteIMUData(ImuData* data);
  102. void WriteRadarData(RadarData& data);
  103. void WriteRobotStatus(int32_t value,int32_t desc);
  104. void WritePacket(ChannelType type, CIOBuffer & pBuffer);
  105. void SwitchCamera(bool front);
  106. void SetTick(long long tick);
  107. void ChangeState(UserState state);
  108. void OnSwitchDriver();
  109. #ifdef LIDAR_SENSOR
  110. void WriteLidarPoint(const PointCloudMsg<PointXYZI>& msg,ChannelType side);
  111. #endif
  112. void StopCar();
  113. // void StartCar();
  114. void CheckSignal();
  115. void SendZGJStatus(int status);
  116. void SendVehicleStatus(vehicle_control_cv control_can);
  117. void SendStatusToServer(int32_t travelSpeed, int fGear, int bGear, int gearStatus) ; //发送底盘状态给服务器
  118. bool bStopedCar;
  119. long long _curStopTick;
  120. bool btimeStopedCar;
  121. long long DataMqtt_curTick;
  122. bool DataMqtt_SendDate;
  123. FILE *File_fd;
  124. int32_t _Version;
  125. void SerichFile(char *filename);
  126. long long _source = 0;
  127. long long _dst = 0;
  128. //增加
  129. std::string user_uuid;
  130. int32_t cockpit_id;
  131. int32_t vehicle_id;
  132. private:
  133. std::mutex _lock;
  134. std::condition_variable _cv;
  135. CIOBuffer* Head;
  136. CIOBuffer* Tail;
  137. //add-3-7
  138. //CRobotSensor *cs;
  139. // std::unique_ptr<PeerConnectionWrapper> _peer_video;
  140. std::vector<std::unique_ptr<CPeerConnection> > _peerArray;
  141. std::vector<LocalCameraInfo> _cameraArray;
  142. //EgoType _egoType;
  143. //int32_t _indexOffset;
  144. // std::vector<std::unique_ptr<VideoRenderer> > _windowArray;
  145. // std::unique_ptr<VideoRenderer> _main_window;
  146. // std::unique_ptr<VideoRenderer> _arm_window;
  147. std::unique_ptr<SocketClient> _client;
  148. std::unique_ptr<SensorSocket<CImuSensor>> _imu;
  149. std::unique_ptr<SensorMQTT<CMqttSensor>> _Mqtt_ZR;
  150. std::unique_ptr<SensorMQTT<CDataMqttSensor>> _Mqtt_SE;
  151. std::unique_ptr<SensorSocket<CRtkSensor>> _Rtk;
  152. std::unique_ptr<SensorCanBus<CCanBusSensor>> _CanBusVehicle;
  153. std::unique_ptr<SensorCanBus<CCanRadarSensor>> _CanBusRadar;
  154. std::unique_ptr<SensorPeakCan<CPcanSensor>> _PcanBusVehicle;
  155. std::unique_ptr<SensorSocket<CRadarSensor>> _RadarIp;
  156. int32_t _peerId;
  157. std::string _serial;
  158. std::string _name;
  159. int32_t _uid=0;
  160. int32_t _UdpMinPort;
  161. int32_t _UdpMaxPort;
  162. CUpdateThread _updatethread;
  163. std::mutex _canLock;
  164. long long _curTick;
  165. ////////////////////////////////////////////////////////////////
  166. #ifdef LIDAR_SENSOR
  167. std::unique_ptr<CLidarSensor> _left;
  168. std::unique_ptr<CLidarSensor> _right;
  169. #endif
  170. };