Feedback.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include "FeedBack.h"
  2. #include <string>
  3. #include <cstring>
  4. #include <iostream>
  5. FeedbackStat::FeedbackStat()
  6. {
  7. }
  8. FeedbackStat::~FeedbackStat()
  9. {
  10. }
  11. void FeedbackStat::receiveCanData()
  12. {
  13. int i;
  14. for(i=0; i<FeedbackStat::num_of_rec; i++)
  15. {
  16. dealCanData(FeedbackStat::can_receive_struct[i]);
  17. }
  18. }
  19. void FeedbackStat::dealCanData(CAN_OBJ candata)
  20. {
  21. uint32_t id_normal = candata.ID;
  22. if(id_normal == 0x200)
  23. {
  24. dealPDO200Status(candata);
  25. } else if (id_normal == 0x300)
  26. {
  27. dealPDO300Status(candata);
  28. } else if (id_normal == 0x400)
  29. {
  30. dealPDO400Status(candata);
  31. } else if (id_normal == 0x500)
  32. {
  33. dealPDO500Status(candata);
  34. }
  35. }
  36. FeedbackData FeedbackStat::GetFeedback()
  37. {
  38. std::lock_guard<std::mutex> guard(feedback_state_mutex_);
  39. return feedBackState_;
  40. }
  41. void FeedbackStat::dealPDO200Status(CAN_OBJ candata)
  42. {
  43. std::lock_guard<std::mutex> guard(feedback_state_mutex_);
  44. FeedbackStat::feedBackData.feedback.water_temp_alarm = static_cast<uint8_t>(candata.Data[0] & 0b01);
  45. FeedbackStat::feedBackData.feedback.oil_pressure_low_alarm = static_cast<uint8_t>((candata.Data[0] & 0b10) >> 2);
  46. FeedbackStat::feedBackData.feedback.air_filter_alarm = static_cast<uint8_t>((candata.Data[0] & 0b100) >> 3);
  47. FeedbackStat::feedBackData.feedback.right_oil_filter_alarm = static_cast<uint8_t>((candata.Data[0] & 0b1000) >> 4);
  48. FeedbackStat::feedBackData.feedback.left_oil_filter_alarm = static_cast<uint8_t>((candata.Data[0] & 0b10000) >> 5);
  49. FeedbackStat::feedBackData.feedback.oil_loop_filter_alarm = static_cast<uint8_t>((candata.Data[0] & 0b100000) >> 6);
  50. FeedbackStat::feedBackData.feedback.hydr_pressure_low_alarm = static_cast<uint8_t>((candata.Data[0] & 0b1000000) >> 7);
  51. FeedbackStat::feedBackData.feedback.engine_rpm = ((uint8_t)candata.Data[2]<<8) + (uint8_t)candata.Data[3];
  52. FeedbackStat::feedBackData.feedback.oil_pressure = static_cast<uint8_t>((candata.Data[4]));
  53. FeedbackStat::feedBackData.feedback.water_temperature = static_cast<uint8_t>((candata.Data[5]));
  54. FeedbackStat::feedBackData.feedback.left_MA_pressure = ((uint8_t)candata.Data[6]<<8) + (uint8_t)candata.Data[7];
  55. }
  56. void FeedbackStat::dealPDO300Status(CAN_OBJ candata)
  57. {
  58. std::lock_guard<std::mutex> guard(feedback_state_mutex_);
  59. FeedbackStat::feedBackData.feedback.left_MB_pressure = ((uint8_t)candata.Data[0]<<8) + (uint8_t)candata.Data[1];
  60. FeedbackStat::feedBackData.feedback.right_MA_pressure = ((uint8_t)candata.Data[2]<<8) + (uint8_t)candata.Data[3];
  61. FeedbackStat::feedBackData.feedback.right_MB_pressure = ((uint8_t)candata.Data[4]<<8) + (uint8_t)candata.Data[5];
  62. FeedbackStat::feedBackData.feedback.pump_pressure = ((uint8_t)candata.Data[6]<<8) + (uint8_t)candata.Data[7];
  63. }
  64. void FeedbackStat::dealPDO400Status(CAN_OBJ candata)
  65. {
  66. std::lock_guard<std::mutex> guard(feedback_state_mutex_);
  67. FeedbackStat::feedBackData.feedback.left_motor_rpm = ((uint8_t)candata.Data[0]<<8) + (uint8_t)candata.Data[1];
  68. FeedbackStat::feedBackData.feedback.right_motor_rpm = ((uint8_t)candata.Data[2]<<8) + (uint8_t)candata.Data[3];
  69. FeedbackStat::feedBackData.feedback.hydr_oil_height = (uint8_t)candata.Data[4];
  70. FeedbackStat::feedBackData.feedback.disel_oil_height = (uint8_t)candata.Data[5];
  71. FeedbackStat::feedBackData.feedback.up_time = ((uint8_t)candata.Data[6]<<8) + (uint8_t)candata.Data[7];
  72. }
  73. void FeedbackStat::dealPDO500Status(CAN_OBJ candata)
  74. {
  75. std::lock_guard<std::mutex> guard(feedback_state_mutex_);
  76. FeedbackStat::feedBackData.feedback.votage = (uint8_t)candata.Data[0];
  77. }
  78. CAN_OBJ FeedbackStat::can_receive_struct[100];
  79. volatile int32_t FeedbackStat::num_of_rec = 0;
  80. volatile FeedbackData FeedbackStat::feedBackData;