message_queue.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #pragma once
  2. #include<mutex>
  3. #include<memory>
  4. #include <fstream>
  5. #include<string>
  6. #include<condition_variable>
  7. #include <vector>
  8. #include "protocol.pb.h"
  9. #include "../common/iobuffer.h"
  10. #include "../common/socket_client.h"
  11. #include "../common/sensor_socket.h"
  12. #include "../common/update_thread.h"
  13. #include "message.h"
  14. int8_t hi_byte(int16_t value);
  15. int8_t lo_byte(int16_t value);
  16. class CRadarSensor;
  17. class CEncoderSensor;
  18. class CCarSensor;
  19. class SocketClient;
  20. class CPeerConnection;
  21. //class VideoRenderer;
  22. //class CAutoSensor;
  23. enum MessageType:int32_t
  24. {
  25. ReqVideo,
  26. RepVideo,
  27. Connected,
  28. Leave,
  29. StopSensor,
  30. Ping,
  31. AsyncMessage,
  32. };
  33. enum class ParkingState:int32_t
  34. {
  35. None,
  36. Turn,
  37. Reverse,
  38. Restore,
  39. RiseDown,//举升
  40. // Down, //下降
  41. TipOut, //倾翻倒出
  42. TipIn, // 倾倒收回
  43. TipRise, //倾翻上升
  44. TipDown,//倾翻下降
  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. struct radar_node;
  58. class CIOBuffer;
  59. enum TurnSide
  60. {
  61. Left,
  62. Right,
  63. Other
  64. };
  65. enum ROUT_LIST
  66. {
  67. FRONT_IN_1,
  68. BACK_IN_1,
  69. FRONT_OUT_1,
  70. FRONT_IN_2,
  71. BACK_IN_2,
  72. FRONT_OUT_2,
  73. FRONT_IN_3,
  74. BACK_IN_3,
  75. FRONT_OUT_3,
  76. ROUT_ALL
  77. };
  78. class CMessageQueue:public INativeNotify
  79. {
  80. public:
  81. CMessageQueue();
  82. virtual ~CMessageQueue();
  83. void Create();
  84. void EnQueue(CIOBuffer* pBuffer);
  85. void Process();
  86. virtual void OnAdd(int32_t uid,bool bRet) override;
  87. virtual void OnConnected(bool bRet) override;
  88. // virtual bool IsCarId(int32_t value) override;
  89. // virtual void WriteCanMessage(std::unordered_map<int32_t, cannet_frame>& node,bool islidar) override;
  90. #ifdef WIN32
  91. virtual void OnVideoRep(int32_t index,int32_t peer) override;
  92. #else
  93. virtual void OnVideoReq(int32_t index,int32_t peer) override;
  94. virtual void OnMoveBegin(WorkArea area, int32_t no) override;
  95. #endif
  96. virtual void OnVideoOffer(int32_t index,const char* type, const char* sdp) override;
  97. virtual void OnVideoAnswer(int32_t index, const char* type, const char* sdp) override;
  98. virtual void OnVideoCandidate(int32_t index,const char* candidate,
  99. int32_t sdp_mline_index,
  100. const char* sdp_mid) override;
  101. /*virtual void OnVideoAddTrack(RemoteVideoTrackWrapper* ptr) = 0;*/
  102. //virtual void OnCancelReq(int32_t index) override;
  103. virtual void OnVideoLeave(int32_t peer,EgoType type) override;
  104. virtual void OnSwitchDriver() override;
  105. virtual void OnMessageFrameNotify(ChannelType type,int16_t cmd,int16_t length,const void * data) override;
  106. void OnNotifyConnected(bool bRet);
  107. void OnNotifyReq(int32_t index);
  108. void OnNotifyRep(int32_t index);
  109. void OnNotifyStopSensor();
  110. void OnNotifyLeave();
  111. void OnNotifyMessage();
  112. void SetNdtPos(ARNdtPos* pos);
  113. void SetSteerAngle(int16_t);
  114. void SetLeftAngle(int16_t);
  115. void SetRightAngle(int16_t);
  116. void OnGoalFinish(WorkArea are,int32_t no);
  117. void OnTip(int16_t value);
  118. void GetParkCanMessage(TPCANMsg* msg);
  119. void OnNotifyPing(int64_t value);
  120. void InitPeerConnection(int32_t peer,int32_t index);
  121. void WriteBuffer(ChannelType type,CIOBuffer& pBufer);
  122. void WriteBuffer(CIOBuffer& pBuffer);
  123. void WriteSensor(radar_node* node,int32_t count);
  124. // void WriteRadarData(radar_node* data);
  125. void SetAutomous(bool value,int32_t delay);
  126. void SwitchCamera(bool front);
  127. // void WriteRobotStatus(int32_t value,int32_t desc);
  128. const radar_node* GetRadar();
  129. void StopAutomous();
  130. ParkingState GetParkingState();
  131. void SetParkingState(ParkingState state);
  132. CarType GetCarType();
  133. //#ifdef LIDAR_SENSOR
  134. // void WriteLidarPoint(const PointCloudMsg<PointXYZI>& msg,ChannelType side);
  135. //#endif
  136. // void StopCar();
  137. // void StartCar();
  138. void CheckSignal();
  139. void ChangeState(UserState state);
  140. int32_t GetPeer();
  141. void TestPark();
  142. void OnRiseDown(TPCANMsg* msg);
  143. void OnTipRise(TPCANMsg* msg);
  144. void OnTipDown(TPCANMsg* msg);
  145. void OnTipOut(TPCANMsg* msg);
  146. void OnTipIn(TPCANMsg* msg);
  147. void OnTurn(TPCANMsg* msg);
  148. void OnReverse(TPCANMsg* msg);
  149. void OnRestore(TPCANMsg* msg);
  150. public:
  151. // void BegRecord();
  152. // void EndRecord();
  153. // void PlayRecord(ROUT_LIST index);
  154. // bool IsRecord(){ return _start_record;}
  155. // void WriteRecord(TPCANMsg * msg);
  156. private:
  157. // void LoadRecord(ROUT_LIST dir,const char * file);
  158. // void OnPlayrecord(TPCANMsg* msg);
  159. // bool _start_record=false;
  160. //bool _start_play=false;
  161. // ROUT_LIST _rout_index;
  162. // std::fstream _ofile;
  163. // std::vector<cannet_frame> frames[ROUT_LIST::ROUT_ALL];
  164. // int32_t _play_index=0;
  165. private:
  166. std::mutex _mlock;
  167. std::condition_variable _cv;
  168. CIOBuffer* Head;
  169. CIOBuffer* Tail;
  170. // std::unique_ptr<PeerConnectionWrapper> _peer_video;
  171. std::vector<std::unique_ptr<CPeerConnection> > _peerArray;
  172. std::vector<LocalCameraInfo> _cameraArray;
  173. //EgoType _egoType;
  174. //int32_t _indexOffset;
  175. // std::vector<std::unique_ptr<VideoRenderer> > _windowArray;
  176. // std::unique_ptr<VideoRenderer> _main_window;
  177. // std::unique_ptr<VideoRenderer> _arm_window;
  178. std::unique_ptr<SocketClient> _client;
  179. std::unique_ptr<SensorSocket<CRadarSensor>> _radar;
  180. std::unique_ptr<SensorSocket<CEncoderSensor>> _encoder;
  181. // std::unique_ptr<SensorSocket<CLidarSensor>> _lidar;
  182. std::unique_ptr<SensorSocket<CCarSensor>> _robot;
  183. //std::unique_ptr<SensorSocket<CAutoSensor>> _auto;
  184. int32_t _peerId;
  185. // int32_t _canport;
  186. // int32_t _hostport;
  187. // int32_t _lidarport;
  188. // std::string _canip;
  189. std::string _serial;
  190. std::string _name;
  191. CarType _car;
  192. bool _camera_inited=false;
  193. bool bStopedCar;
  194. CUpdateThread _updatethread;
  195. std::mutex _canLock;
  196. int64_t _curTick;
  197. int32_t _uid=0;
  198. ParkingState _parking=ParkingState::None;
  199. std::mutex _pose_lock;
  200. ARNdtPos _curpos;
  201. int16_t _steer_angle;
  202. FVector3d _initpos;
  203. WorkArea _workarea=WorkArea::Area_A;
  204. Metal_Area _metalArea=Metal_Area::Put_Wait;
  205. int32_t _no=0;
  206. TurnSide _side=TurnSide::Left;
  207. int16_t _left_length=0;
  208. int16_t _right_length=0;
  209. int16_t pre_left_length=-1;
  210. int16_t pre_right_length=-1;
  211. //int16_t _tip_length=0;
  212. int16_t max_left_length=0;
  213. int16_t max_right_length=0;
  214. int16_t min_left_length=0;
  215. int16_t min_right_length=0;
  216. int32_t tipin_time=0;
  217. int32_t tipout_time=0;
  218. int32_t _start_time=0;
  219. int32_t _diff_degree=30;
  220. int32_t _angle_value=10;
  221. int32_t _sq_length=102;
  222. int32_t _turn_base=1000;
  223. bool _start_check=false;
  224. };