FeedBack.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. #pragma once
  2. #include <stdint.h>
  3. #include <mutex>
  4. #include <thread>
  5. #include "comm.h"
  6. // typedef struct
  7. // {
  8. // union
  9. // {
  10. // struct
  11. // {
  12. // //头 数据长度 1个字节
  13. // uint8_t header;
  14. // // canid 4个字节
  15. // uint32_t canid;
  16. // // 8字节数据
  17. // uint8_t data1;
  18. // uint8_t data2;
  19. // uint8_t data3;
  20. // uint8_t data4;
  21. // uint8_t data5;
  22. // uint8_t data6;
  23. // uint8_t data7;
  24. // uint8_t data8;
  25. // } msg;
  26. // uint8_t rawMsg[13];
  27. // } data;
  28. // } CANFrame;
  29. // typedef enum
  30. // {
  31. // MsgNone = 0x00,
  32. // PDO200Msg = 0x200,
  33. // Feedback2Msg = 0x300,
  34. // Feedback3Msg = 0x400,
  35. // Feedback4Msg = 0x500,
  36. // } MsgType;
  37. //反馈信息表, 一共有4条信息
  38. //第一条 CANid 0x200+node id
  39. // typedef struct {
  40. // union
  41. // {
  42. // struct
  43. // {
  44. // struct
  45. // {
  46. // unsigned water_temp_alarm; //水温高报警
  47. // unsigned oil_pressure_low_alarm; //机油压力低报警
  48. // unsigned air_filter_alarm; //空滤堵塞报警
  49. // unsigned left_oil_filter_alarm; //左行走补油滤网堵塞报警
  50. // unsigned right_oil_filter_alarm; //右行走补油滤网堵塞报警
  51. // unsigned oil_loop_filter_alarm; //回油滤网堵塞报警
  52. // unsigned hydr_pressure_low_alarm; //液压油箱位低报警
  53. // unsigned reserved7;
  54. // } group1;
  55. // uint8_t reserved1;
  56. // struct
  57. // {
  58. // uint8_t high_byte;
  59. // uint8_t low_byte;
  60. // } engine_rpm; //发动机转速
  61. // uint8_t oil_pressure; //机油压力
  62. // uint8_t water_temperature; //水温
  63. // struct
  64. // {
  65. // uint8_t high_byte;
  66. // uint8_t low_byte;
  67. // } left_MA_pressure; //左行走MA压力
  68. // } status;
  69. // uint8_t raw[8];
  70. // } data;
  71. // } Feedback1Message;
  72. // //第二条 CANid 0x300+node id
  73. // typedef struct {
  74. // union
  75. // {
  76. // struct
  77. // {
  78. // struct
  79. // {
  80. // uint8_t high_byte;
  81. // uint8_t low_byte;
  82. // } left_MB_pressure; //左行走MB压力
  83. // struct
  84. // {
  85. // uint8_t high_byte;
  86. // uint8_t low_byte;
  87. // } right_MA_pressure; //右行走MA压力
  88. // struct
  89. // {
  90. // uint8_t high_byte;
  91. // uint8_t low_byte;
  92. // } right_MB_pressure; //右行走MB压力
  93. // struct
  94. // {
  95. // uint8_t high_byte;
  96. // uint8_t low_byte;
  97. // } pump_pressure; // 工作泵压力
  98. // } status;
  99. // uint8_t raw[8];
  100. // } data;
  101. // } Feedback2Message;
  102. // //第三条 CANid 0x400+node id
  103. // typedef struct {
  104. // union
  105. // {
  106. // struct
  107. // {
  108. // struct
  109. // {
  110. // uint8_t high_byte;
  111. // uint8_t low_byte;
  112. // } left_motor_rpm; //左马达转速
  113. // struct
  114. // {
  115. // uint8_t high_byte;
  116. // uint8_t low_byte;
  117. // } right_motor_rpm; //右马达转速
  118. // uint8_t hydr_oil_height; //液压油液位
  119. // uint8_t disel_oil_height; //柴油油位
  120. // struct
  121. // {
  122. // uint8_t high_byte;
  123. // uint8_t low_byte;
  124. // } up_time; //工作小时
  125. // } status;
  126. // uint8_t raw[8];
  127. // } data;
  128. // } Feedback3Message;
  129. // //第四条 CANid 0x500+node id
  130. // typedef struct {
  131. // union
  132. // {
  133. // struct
  134. // {
  135. // uint8_t votage; // 电压
  136. // uint8_t reserved1;
  137. // uint8_t reserved2;
  138. // uint8_t reserved3;
  139. // uint8_t reserved4;
  140. // uint8_t reserved5;
  141. // uint8_t reserved6;
  142. // uint8_t reserved7;
  143. // } status;
  144. // uint8_t raw[8];
  145. // } data;
  146. // } Feedback4Message;
  147. // typedef struct
  148. // {
  149. // MsgType type;
  150. // union {
  151. // Feedback1Message feedback_1_msg;
  152. // Feedback2Message feedback_2_msg;
  153. // Feedback3Message feedback_3_msg;
  154. // Feedback4Message feedback_4_msg;
  155. // } body;
  156. // } CANMsg;
  157. struct FeedbackData
  158. {
  159. struct ControlState
  160. {
  161. uint8_t main_start = 0;
  162. uint8_t horn = 0;
  163. uint8_t front_light = 0;
  164. uint8_t rear_light = 0;
  165. uint8_t front_rear_light = 0;
  166. uint8_t enable = 0;
  167. uint8_t brake_release = 0;
  168. uint8_t connect = 0;
  169. uint8_t connect_start = 0;
  170. uint8_t pilot_valve = 0;
  171. uint8_t em_stop = 0;
  172. uint8_t em_stop_inverted = 0;
  173. int8_t shovel_loader = 0;
  174. int8_t shovel_arm = 0;
  175. int8_t direction = 0;
  176. int8_t moverment = 0;
  177. };
  178. struct Feedback
  179. {
  180. uint8_t water_temp_alarm = 0;
  181. uint8_t oil_pressure_low_alarm = 0;
  182. uint8_t air_filter_alarm = 0;
  183. uint8_t left_oil_filter_alarm = 0;
  184. uint8_t right_oil_filter_alarm = 0;
  185. uint8_t oil_loop_filter_alarm = 0;
  186. uint8_t hydr_pressure_low_alarm = 0;
  187. int32_t engine_rpm = 0;
  188. uint8_t oil_pressure = 0;
  189. uint8_t water_temperature = 0;
  190. int32_t left_MA_pressure = 0;
  191. int32_t left_MB_pressure = 0;
  192. int32_t right_MA_pressure = 0;
  193. int32_t right_MB_pressure = 0;
  194. int32_t pump_pressure = 0;
  195. int32_t left_motor_rpm = 0;
  196. int32_t right_motor_rpm = 0;
  197. uint8_t hydr_oil_height = 0;
  198. uint8_t disel_oil_height = 0;
  199. int32_t up_time = 0;
  200. uint8_t votage = 0;
  201. };
  202. ControlState controlStat;
  203. Feedback feedback;
  204. };
  205. typedef struct _CAN_OBJ{
  206. uint32_t ID;
  207. uint8_t NodeId;
  208. uint32_t TimeStamp;
  209. uint8_t TimeFlag;
  210. uint8_t SendType;
  211. uint8_t RemoteFlag; //是否是远程帧
  212. uint8_t ExternFlag; //是否是扩展帧
  213. uint8_t DataLen;
  214. uint8_t Data[8];
  215. }CAN_OBJ;
  216. class FeedbackStat {
  217. public:
  218. FeedbackStat();
  219. ~FeedbackStat();
  220. // static void UpdateState(const CANMsg &can_msg, FeedbackState &feedBackState);
  221. FeedbackData GetFeedback();
  222. FeedbackData feedBackState_;
  223. void receiveCanData();
  224. void dealCanData(CAN_OBJ candata);
  225. static volatile int32_t num_of_rec;
  226. static CAN_OBJ can_receive_struct[100];
  227. void dealPDO200Status(CAN_OBJ candata);
  228. void dealPDO300Status(CAN_OBJ candata);
  229. void dealPDO400Status(CAN_OBJ candata);
  230. void dealPDO500Status(CAN_OBJ candata);
  231. static volatile FeedbackData feedBackData;
  232. private:
  233. std::mutex feedback_state_mutex_;
  234. };