control_sensor.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #include "mqtt/async_client.h"
  12. class CEgoWindow;
  13. class CMessageQueue;
  14. /*
  15. 舱端车辆控制
  16. 软件接收下发指令到车端
  17. */
  18. enum Sensor_Collection :int32_t
  19. {
  20. //发送给下位机的Pcan地址
  21. Sensor_None = 0x0,
  22. Sensor_181 = 0x1, //0x181
  23. Sensor_182 = 0x2, //0x182
  24. Sensor_183 = 0x4, //0x183
  25. Sensor_184 = 0x8, //0x184
  26. //Sensor_All = 0xF
  27. Sensor_185 = 0x10, //0x185
  28. Sensor_All = 0x1F
  29. /*
  30. Sensor_None = 0x0,
  31. Sensor_ER = 0x1, //0x181
  32. Sensor_Steer = 0x2, //0x185
  33. Sensor_Signal = 0x4, //0x281
  34. Sensor_Drive = 0x8, //0x381
  35. Sensor_Arm =0x10 ,//0x481
  36. //Sensor_Switch=0x20,
  37. Sensor_All = 0x1F
  38. */
  39. };
  40. enum OpSide
  41. {
  42. Empty,
  43. Arm,
  44. Bucket
  45. };
  46. class CControlSensor
  47. {
  48. public:
  49. CControlSensor(CMessageQueue * window);
  50. bool Start();
  51. void Stop();
  52. void Notify(TPCANMsg& canmsg,uint64_t timestamp);
  53. void NotifyMqtt();
  54. void SetEngineRPM(int32_t rpm);
  55. ControlStatus CheckStatus();
  56. TPCANStatus SendCANMessage(TPCANMsg* CANMsg);
  57. static std::string setSCSignUuid(std::string user_uuid);
  58. static int32_t setCarID(int32_t CarID);
  59. private:
  60. void Run();
  61. TPCANStatus ReadMessage();
  62. //TPCANStatus ReadMessageFD();
  63. void ReadMessages();
  64. private:
  65. CEgoWindow* _window;
  66. Sensor_Collection _collection;
  67. TPCANHandle _handle=-1;
  68. bool _isFD;
  69. std::thread _thread;
  70. bool _run;
  71. int16_t _last_speed = 0xF000;
  72. int64_t _startup = 0;
  73. int32_t _rpm = 0;
  74. cannet_frame frames[6];
  75. int32_t _old_steer = 0;
  76. uint64_t _old_timestamp = 0;
  77. bool isFront = false;
  78. bool isSliping = false;
  79. bool _remote_active = false;
  80. uint64_t _active_tick = 0;
  81. static std::string m_userID;
  82. static int32_t m_carID;
  83. };
  84. class callback : public virtual mqtt::callback
  85. {
  86. public:
  87. void connection_lost(const std::string& cause) override {
  88. std::cout << "\nConnection lost" << std::endl;
  89. if (!cause.empty())
  90. std::cout << "\tcause: " << cause <<std:: endl;
  91. }
  92. void delivery_complete(mqtt::delivery_token_ptr tok) override {
  93. std::cout << "\tDelivery complete for token: "
  94. << (tok ? tok->get_message_id() : -1) << std::endl;
  95. }
  96. };