rs71_usb_receiver.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. ******************************************************************************
  3. * @file : rs71_usb_receiver.h
  4. * @author : wangyingjie
  5. * @brief : None
  6. * @attention : None
  7. * @date : 2025/6/20
  8. ******************************************************************************
  9. */
  10. #ifndef RS71_USB_RECEIVER_H
  11. #define RS71_USB_RECEIVER_H
  12. #ifndef CAN_DEVICE_H
  13. #define CAN_DEVICE_H
  14. #include <vector>
  15. #include <string>
  16. #include <mutex>
  17. #ifdef WIN32
  18. #include <windows.h>
  19. #include <process.h>
  20. typedef HANDLE ThreadHandle;
  21. #define THREAD_RETURN unsigned __stdcall
  22. #else
  23. #include <pthread.h>
  24. #include <unistd.h>
  25. #define THREAD_RETURN void*
  26. typedef pthread_t ThreadHandle;
  27. #endif
  28. #include "controlcan.h"
  29. #define RX_BUFF_SIZE 1000
  30. #define RX_WAIT_TIME 100
  31. class RS71UsbReceiver
  32. {
  33. public:
  34. RS71UsbReceiver(unsigned devType, unsigned devIdx, unsigned chMask, unsigned baud);
  35. ~RS71UsbReceiver();
  36. bool init(unsigned devType, unsigned devIdx, unsigned chMask, unsigned baud);
  37. bool Open();
  38. void Close();
  39. bool Start();
  40. void Stop();
  41. std::vector<CanFrame> GetReceivedData(unsigned channel);
  42. private:
  43. struct RX_CTX
  44. {
  45. unsigned channel;
  46. volatile bool stop;
  47. std::vector<CanFrame> buffer;
  48. std::mutex mtx;
  49. };
  50. static THREAD_RETURN RxThreadFunc(void *param);
  51. unsigned devType, devIdx, chMask, baud;
  52. RX_CTX rxContexts[4];
  53. ThreadHandle rxThreads[4];
  54. #ifdef WIN32
  55. static unsigned __stdcall RxThreadWrapper(void* param);
  56. #endif
  57. };
  58. #endif
  59. #endif //RS71_USB_RECEIVER_H