ivdetection_radar.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include "ivdetection_radar.h"
  2. #include <iostream>
  3. namespace iv {
  4. ivdetection_radar::ivdetection_radar()
  5. {
  6. }
  7. void ivdetection_radar::setcanmsgname(const std::string str)
  8. {
  9. mstrcanmsgname = str;
  10. }
  11. void ivdetection_radar::setradarmsgname(const std::string str)
  12. {
  13. mstrradarmsgname = str;
  14. }
  15. void ivdetection_radar::modulerun()
  16. {
  17. iv::can::canmsg xmsg;
  18. ModuleFun funcan = std::bind(&iv::ivdetection_radar::UpdateCANMsg,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  19. mpmsgcan = iv::modulecomm::RegisterRecvPlus(mstrcanmsgname.data(),funcan);
  20. mpmsgradar = iv::modulecomm::RegisterSend(mstrradarmsgname.data(),100000,3);
  21. int nnothavedata = 0;
  22. iv::radar::radarobjectarray * pradar = new iv::radar::radarobjectarray;
  23. while(mbrun)
  24. {
  25. mWaitMutex.lock();
  26. mwc.wait(&mWaitMutex,100);
  27. mWaitMutex.unlock();
  28. if(mbUpdateCANMsg)
  29. {
  30. mMutex.lock();
  31. xmsg.CopyFrom(mCANMsg);
  32. mbUpdateCANMsg = false;
  33. mMutex.unlock();
  34. nnothavedata = 0;
  35. int nRtn;
  36. int i;
  37. for(i=0;i<xmsg.rawmsg_size();i++)
  38. {
  39. nRtn = DecodeCANMsg(*pradar,xmsg.mutable_rawmsg(i));
  40. if(nRtn == 1)
  41. {
  42. ShareRadarMsg(mpmsgradar,pradar);
  43. delete pradar;
  44. pradar = new iv::radar::radarobjectarray;
  45. }
  46. }
  47. //Decode
  48. }
  49. else
  50. {
  51. nnothavedata++;
  52. }
  53. if(nnothavedata == 100)
  54. {
  55. }
  56. if(nnothavedata == 1000)
  57. {
  58. }
  59. }
  60. iv::modulecomm::Unregister(mpmsgradar);
  61. iv::modulecomm::Unregister(mpmsgcan);
  62. }
  63. void ivdetection_radar::UpdateCANMsg(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  64. {
  65. (void )&index;
  66. (void )&dt;
  67. (void )strmemname;
  68. if(nSize<1)return;
  69. iv::can::canmsg xmsg;
  70. if(false == xmsg.ParseFromArray(strdata,nSize))
  71. {
  72. std::cout<<"esr Listencan0 fail."<<std::endl;
  73. return;
  74. }
  75. mMutex.lock();
  76. mCANMsg.CopyFrom(xmsg);
  77. mbUpdateCANMsg = true;
  78. mMutex.unlock();
  79. mwc.wakeAll();
  80. }
  81. void ivdetection_radar::ShareRadarMsg(void *pa, radar::radarobjectarray *pradar)
  82. {
  83. static qint64 oldrecvtime = 0;
  84. char * str = new char[pradar->ByteSize()];
  85. int nsize = pradar->ByteSize();
  86. if(pradar->SerializeToArray(str,nsize))
  87. {
  88. iv::modulecomm::ModuleSendMsg(pa,str,nsize);
  89. }
  90. else
  91. {
  92. std::cout<<"ivdetection_radar::ShareRadarMsg SerializeToArray error."<<std::endl;
  93. }
  94. if(((QDateTime::currentMSecsSinceEpoch() - oldrecvtime)>100)&&(oldrecvtime != 0))
  95. {
  96. // givlog->warn("radar interval is more than 100ms. value is %ld",QDateTime::currentMSecsSinceEpoch() - oldrecvtime);
  97. }
  98. oldrecvtime = QDateTime::currentMSecsSinceEpoch();
  99. // givlog->verbose("share time is %d ",gTime.elapsed());
  100. // qDebug("share time is %d ",gTime.elapsed());
  101. delete str;
  102. }
  103. }