control_sensor.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #include "../common/comm.h"
  3. #include "../common/notifier.h"
  4. #include "../common/sensor_socket.h"
  5. #include <thread>
  6. #include <mutex>
  7. #include <algorithm>
  8. #include <string>
  9. #include "EgoClient.h"
  10. #include "PCANBasic.h"
  11. class CEgoWindow;
  12. class CMessageQueue;
  13. /*
  14. 舱端车辆控制
  15. 软件接收下发指令到车端
  16. */
  17. enum Sensor_Collection :int32_t
  18. {
  19. //发送给下位机的Pcan地址
  20. Sensor_None = 0x0,
  21. Sensor_181 = 0x1, //0x181
  22. Sensor_182 = 0x2, //0x182
  23. Sensor_183 = 0x4, //0x183
  24. Sensor_184 = 0x8, //0x184
  25. //Sensor_All = 0xF
  26. Sensor_185 = 0x10, //0x185
  27. Sensor_All = 0x1F
  28. /*
  29. Sensor_None = 0x0,
  30. Sensor_ER = 0x1, //0x181
  31. Sensor_Steer = 0x2, //0x185
  32. Sensor_Signal = 0x4, //0x281
  33. Sensor_Drive = 0x8, //0x381
  34. Sensor_Arm =0x10 ,//0x481
  35. //Sensor_Switch=0x20,
  36. Sensor_All = 0x1F
  37. */
  38. };
  39. enum OpSide
  40. {
  41. Empty,
  42. Arm,
  43. Bucket
  44. };
  45. class CControlSensor
  46. {
  47. public:
  48. CControlSensor(CMessageQueue * window);
  49. bool Start();
  50. void Stop();
  51. void Notify(TPCANMsg& canmsg,uint64_t timestamp);
  52. void SetEngineRPM(int32_t rpm);
  53. ControlStatus CheckStatus();
  54. TPCANStatus SendCANMessage(TPCANMsg* CANMsg);
  55. private:
  56. void Run();
  57. TPCANStatus ReadMessage();
  58. //TPCANStatus ReadMessageFD();
  59. void ReadMessages();
  60. private:
  61. CEgoWindow* _window;
  62. Sensor_Collection _collection;
  63. TPCANHandle _handle=-1;
  64. bool _isFD;
  65. std::thread _thread;
  66. bool _run;
  67. int16_t _last_speed = 0xF000;
  68. int64_t _startup = 0;
  69. int32_t _rpm = 0;
  70. cannet_frame frames[6];
  71. int32_t _old_steer = 0;
  72. uint64_t _old_timestamp = 0;
  73. bool isFront = false;
  74. bool isSliping = false;
  75. bool _remote_active = false;
  76. uint64_t _active_tick = 0;
  77. };