radar_ip.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include <stdint.h>
  2. #include <chrono>
  3. #include "radar_ip.h"
  4. #include "message_queue.h"
  5. #pragma pack(1)
  6. struct Radar_Frame_Nl_Revice
  7. {
  8. int8_t DLC_Nl_radar;
  9. int32_t Addr_Nl_radar;
  10. uint8_t RegData_Nl_radar1[8];
  11. };
  12. CRadarSensor::CRadarSensor(CMessageQueue* q):_message(q)
  13. {
  14. _run = false;
  15. }
  16. void CRadarSensor::Notify(int8_t * buffer,int32_t size)
  17. {
  18. int i = 0;
  19. int8_t source[13];
  20. if(_run)
  21. {
  22. for(i = 0 ; i < size ; i += 13)
  23. {
  24. memset(source,0,13);
  25. memcpy(source,buffer + i,13);
  26. Radar_Frame_Nl_Revice * p = (Radar_Frame_Nl_Revice *)source;
  27. if ((htonl(p->Addr_Nl_radar) & 0x60B) == 0x60B)
  28. {
  29. int Nl_Index = (int)(((htonl(p->Addr_Nl_radar)) & 0x00f0) >> 4);
  30. switch (Nl_Index)
  31. {
  32. case 1:
  33. _data.r0 = ((((p->RegData_Nl_radar1[1] * 32) + (p->RegData_Nl_radar1[2] >> 3)) * 0.2) - 500);
  34. break;
  35. case 2:
  36. _data.r1 = ((((p->RegData_Nl_radar1[1] * 32) + (p->RegData_Nl_radar1[2] >> 3)) * 0.2) - 500);
  37. break;
  38. case 3:
  39. _data.r2 = ((((p->RegData_Nl_radar1[1] * 32) + (p->RegData_Nl_radar1[2] >> 3)) * 0.2) - 500);
  40. break;
  41. case 4:
  42. _data.r3 = ((((p->RegData_Nl_radar1[1] * 32) + (p->RegData_Nl_radar1[2] >> 3)) * 0.2) - 500);
  43. break;
  44. case 5:
  45. _data.r4 = ((((p->RegData_Nl_radar1[1] * 32) + (p->RegData_Nl_radar1[2] >> 3)) * 0.2) - 500);
  46. break;
  47. case 6:
  48. _data.r5 = ((((p->RegData_Nl_radar1[1] * 32) + (p->RegData_Nl_radar1[2] >> 3)) * 0.2) - 500);
  49. break;
  50. case 7:
  51. _data.r6 = ((((p->RegData_Nl_radar1[1] * 32) + (p->RegData_Nl_radar1[2] >> 3)) * 0.2) - 500);
  52. break;
  53. case 8:
  54. _data.r7 = ((((p->RegData_Nl_radar1[1] * 32) + (p->RegData_Nl_radar1[2] >> 3)) * 0.2) - 500);
  55. break;
  56. default:
  57. break;
  58. }
  59. }
  60. }
  61. std::cout << "radar :" << _data.r0 << " " << _data.r1 << " " << _data.r2 << " " << _data.r3 << " "
  62. << _data.r4 << " " << _data.r5 << " " << _data.r6 << " " << _data.r7 << " "<< std::endl;
  63. _count++;
  64. if (_count > 8)
  65. {
  66. _message->WriteRadarData(_data);
  67. _count = 0;
  68. }
  69. }
  70. }
  71. void CRadarSensor::Start()
  72. {
  73. if(!_run)
  74. {
  75. _run = true;
  76. _count = 0;
  77. }
  78. }
  79. void CRadarSensor::Run()
  80. {
  81. if (_run)
  82. {
  83. }
  84. }
  85. void CRadarSensor::SetSensorSocket(SensorSocket<CRadarSensor>* can)
  86. {
  87. _socket = can;
  88. }
  89. void CRadarSensor::Stop()
  90. {
  91. if (_run)
  92. {
  93. _run = false;
  94. _count = 0;
  95. }
  96. }