ivdetection_radar_delphi_esr.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "ivdetection_radar_delphi_esr.h"
  2. #include <math.h>
  3. namespace iv {
  4. ivdetection_radar_delphi_esr::ivdetection_radar_delphi_esr(std::string strxmlpath)
  5. {
  6. iv::xmlparam::Xmlparam xp(strxmlpath);
  7. std::string strcanmsgname = xp.GetParam("canrecv","canrecv1");
  8. std::string strradarmsgname = xp.GetParam("radar","radar");
  9. setcanmsgname(strcanmsgname);
  10. setradarmsgname(strradarmsgname);
  11. }
  12. int ivdetection_radar_delphi_esr::DecodeCANMsg(radar::radarobjectarray &xradar, can::canraw *prawmsg)
  13. {
  14. int nrtn = 0;
  15. int32_t range, rate, angle;
  16. static int ncount = 0;
  17. static qint64 nlastsend = 0;
  18. ncount++;
  19. iv::can::canraw canmsg;
  20. canmsg.CopyFrom(*prawmsg);
  21. if((canmsg.id() >= 0x500)&&(canmsg.id() <= 0x53f))
  22. {
  23. int data[8];
  24. unsigned char cdata[8];
  25. memcpy(cdata,canmsg.data().data(),8);
  26. int radar_ID_index = canmsg.id() - 0x500;
  27. int j;
  28. for(j=0;j<8;j++)data[j] = cdata[j];
  29. angle = ((data[1] & 0x1F) << 5) + ((data[2] & 0xF8) / 8);
  30. range = ((data[2] & 0x07) << 8) + data[3];
  31. rate = ((data[6] & 0x3F) << 8) | data[7];
  32. if (angle & 0x200) {
  33. angle = angle | 0xFFFFFC00;
  34. }
  35. if (rate & 0x2000) {
  36. rate = rate | 0xFFFFC000;
  37. }
  38. // qDebug("range = %d angle = %d ",range,angle);
  39. //If angle and range both are 0, it is an invalid data.
  40. if (angle != 0 || range != 0) {
  41. iv::radar::radarobject * pobj = xradar.add_obj();
  42. pobj->set_bvalid(true);
  43. pobj->set_x(range * 0.1 * sin(angle * 1.0 / 1800.0 * M_PI));
  44. pobj->set_y(range * 0.1 * cos(angle * 1.0 / 1800.0 * M_PI));
  45. pobj->set_vel(rate * 1.0 / 100.0);
  46. pobj->set_vx(pobj->vel() * sin(angle / 1800.0 * M_PI));
  47. pobj->set_vy(pobj->vel() * cos(angle / 1800.0 * M_PI));
  48. }
  49. else {
  50. iv::radar::radarobject * pobj = xradar.add_obj();
  51. pobj->set_bvalid(false);
  52. }
  53. if(canmsg.id() == 0x53f)
  54. {
  55. nrtn = 1;
  56. }
  57. if(ncount > 100)
  58. {
  59. nrtn = 1;
  60. }
  61. if((QDateTime::currentMSecsSinceEpoch() - nlastsend) > 100)
  62. {
  63. nrtn = 1;
  64. }
  65. }
  66. if(nrtn == 1)
  67. {
  68. ncount = 0;
  69. nlastsend = QDateTime::currentMSecsSinceEpoch();
  70. }
  71. // qDebug("id is %08x",canmsg.id());
  72. return nrtn;
  73. }
  74. }