can.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #pragma once
  2. #ifndef _IV_CONTROL_CAN_
  3. #define _IV_CONTROL_CAN_
  4. #include <control/controlcan.h>
  5. #include <common/boost.h>
  6. #include <common/car_status.h>
  7. #include <boost/serialization/singleton.hpp>
  8. #include <common/obstacle_type.h>
  9. #include <control/mobileye.h>
  10. #ifdef WIN32
  11. #include <control/can_card.h>
  12. #endif
  13. //#define USE_MOBILEYE
  14. namespace iv {
  15. namespace control {
  16. class CanUtil : public boost::noncopyable
  17. {
  18. public:
  19. CanUtil();
  20. ~CanUtil();
  21. void openCanCard();
  22. void closeCanCard();
  23. void receive();
  24. void send();
  25. void initial();
  26. void pack_command();
  27. void receive_radar(); //毫米波雷达接收数据线程执行方法
  28. #ifdef USE_MOBILEYE
  29. void receive_mobileye();
  30. #endif
  31. /* 获取毫米波雷达传输数据*/
  32. void getRadarData(iv::ObsRadar & obs_radar);
  33. //zsl 2018.06.19
  34. void Ui_GetRadarDate(iv::ObsRadar & obs_radar);
  35. // void Ui_GetRadarDate(iv::ObsRadarPointer & obs_radar);
  36. bool did_radar_ok();
  37. void startsend(bool start_or_stop);
  38. void set_trumpet_on();
  39. void set_trumpet_off();
  40. void set_handbrake_on();
  41. void set_handbrake_off();
  42. void impl_0x700(VCI_CAN_OBJ receivedata);
  43. void impl_0x737(VCI_CAN_OBJ receivedata);
  44. void impl_0x738(VCI_CAN_OBJ receivedata);
  45. obstacle_data_a impl_0x739(VCI_CAN_OBJ receivedata);
  46. obstacle_data_b impl_0x73a(VCI_CAN_OBJ receivedata);
  47. obstacle_data_c impl_0x73b(VCI_CAN_OBJ receivedata);
  48. void impl_0x669(VCI_CAN_OBJ receivedata);
  49. void impl_0x766(VCI_CAN_OBJ receivedata);
  50. void impl_0x767(VCI_CAN_OBJ receivedata);
  51. void impl_0x768(VCI_CAN_OBJ receivedata);
  52. void impl_0x769(VCI_CAN_OBJ receivedata);
  53. next_lane_a impl_0x76c(VCI_CAN_OBJ receivedata);
  54. next_lane_b impl_0x76d(VCI_CAN_OBJ receivedata);
  55. void impl_0x76a(VCI_CAN_OBJ receivedata);
  56. void impl_0x76b(VCI_CAN_OBJ receivedata);
  57. void obs_print(std::vector<obstacle_data_a> obstacleStatusA, std::vector<obstacle_data_b> obstacleStatusB, std::vector<obstacle_data_c> obstacleStatusC);
  58. bool is_stop = false;
  59. bool is_trumpet_duang = false;
  60. bool remotecontrol_is_stop = false;
  61. bool remotecontrol_is_start = false;
  62. private:
  63. boost::shared_ptr<boost::thread> thread_receive; //接收控制板数据线程
  64. boost::shared_ptr<boost::thread> thread_radar_receive; //接收毫米波雷达数据线程
  65. boost::shared_ptr<boost::thread> thread_mobileye_receive; //mobileye
  66. boost::shared_ptr<boost::thread> thread_send; //发送数据线程 每10毫秒发送一次
  67. iv::ObsRadar obs_radar1;
  68. iv::ObsRadar obs_radar_; //毫米波雷达障碍物数据
  69. iv::ObsRadar obs_radar_ui; //专门用来给GUI读毫米波雷达的数据
  70. bool obs_find_flag = false; //采集内容标志位,有内容就是true
  71. boost::mutex mutex_;
  72. #ifdef WIN32
  73. HINSTANCE m_hDLL;//用来保存打开的动态库句柄
  74. LPVCI_OpenDevice VCI_OpenDevice; //接口函数指针
  75. LPVCI_CloseDevice VCI_CloseDevice;
  76. LPVCI_InitCan VCI_InitCAN;
  77. LPVCI_ReadBoardInfo VCI_ReadBoardInfo;
  78. LPVCI_ReadErrInfo VCI_ReadErrInfo;
  79. LPVCI_ReadCanStatus VCI_ReadCanStatus;
  80. LPVCI_GetReference VCI_GetReference;
  81. LPVCI_SetReference VCI_SetReference;
  82. LPVCI_GetReceiveNum VCI_GetReceiveNum;
  83. LPVCI_ClearBuffer VCI_ClearBuffer;
  84. LPVCI_StartCAN VCI_StartCAN;
  85. LPVCI_ResetCAN VCI_ResetCAN;
  86. LPVCI_Transmit VCI_Transmit;
  87. LPVCI_Receive VCI_Receive;
  88. LPVCI_GetReference2 VCI_GetReference2;
  89. LPVCI_SetReference2 VCI_SetReference2;
  90. LPVCI_ResumeConfig VCI_ResumeConfig;
  91. LPVCI_ConnectDevice VCI_ConnectDevice;
  92. LPVCI_UsbDeviceReset VCI_UsbDeviceReset;
  93. LPVCI_FindUsbDevice VCI_FindUsbDevice;
  94. #endif
  95. DWORD m_devtype = 4;//USBCAN2类型号
  96. DWORD m_devind = 0; //can卡设备号 第一个插入的是0 第二个是1
  97. DWORD m_cannum = 0; //can通道号
  98. DWORD m_cannum_radar = 1; //毫米波雷达can通道号
  99. #ifdef USE_MOBILEYE
  100. DWORD m_devindmob = 1;
  101. #endif
  102. BYTE m_sendtype = 0;
  103. BYTE m_frameflag = 0;
  104. BYTE m_frameformat = 0;
  105. bool send_connect = false;
  106. bool is_repeat = false;
  107. int m_connect = 0;
  108. };
  109. typedef boost::serialization::singleton<iv::control::CanUtil> CanUtilSingleton;
  110. }
  111. }
  112. #define ServiceCanUtil iv::control::CanUtilSingleton::get_mutable_instance()
  113. #endif // !_IV_CONTROL_CAN_