main.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #include <QCoreApplication>
  2. #include <iostream>
  3. #include <QDateTime>
  4. #include <math.h>
  5. #include <thread>
  6. #include "modulecomm.h"
  7. #include "xmlparam.h"
  8. #include "ivlog.h"
  9. #include "ivfault.h"
  10. #include "ivversion.h"
  11. #include "ivbacktrace.h"
  12. iv::Ivlog * givlog;
  13. iv::Ivfault * givfault;
  14. #include "canmsg.pb.h"
  15. #include "decodechassis.h"
  16. void * gpa ;
  17. QTime gTime;
  18. namespace iv {
  19. enum VehicleTypeDef {GE3,VV7,MIDCAR,PROBLUE,MIDBUS,HAPO,UNKNOWN, YUHESEN,HUNTER} gVehicleType; //车辆类型//20210903,增加hunter 1+x采集车
  20. }
  21. int gnRadarState = 0;
  22. /**
  23. * @brief Listencan0
  24. * Listen CAN Message
  25. * @param strdata pointer to module communication buffer
  26. * @param nSize Message Size
  27. * @param index Message index
  28. * @param dt Share DateTime
  29. * @param strmemname Message Name of Share
  30. * @retval
  31. **/
  32. void Listencan0(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  33. {
  34. if(nSize<1)return;
  35. iv::can::canmsg xmsg;
  36. if(false == xmsg.ParseFromArray(strdata,nSize))
  37. {
  38. std::cout<<"esr Listencan0 fail."<<std::endl;
  39. return;
  40. }
  41. int nRtn = 0;
  42. switch (iv::gVehicleType) {
  43. case iv::GE3:
  44. nRtn = ProcGE3Chassis(gpa,&xmsg);
  45. break;
  46. case iv::VV7:
  47. nRtn = ProcVV7Chassis(gpa,&xmsg);
  48. break;
  49. case iv::PROBLUE:
  50. nRtn = ProcPROBLUEChassis(gpa,&xmsg);
  51. break;
  52. case iv::MIDCAR:
  53. nRtn = ProcMIDCARChassis(gpa,&xmsg);
  54. break;
  55. case iv::MIDBUS:
  56. nRtn = ProcMIDBUSChassis(gpa,&xmsg);
  57. break;
  58. case iv::HAPO:
  59. nRtn = ProcHAPOChassis(gpa,&xmsg);
  60. break;
  61. case iv::YUHESEN:
  62. nRtn = ProcYUHESENChassis(gpa,&xmsg);
  63. break;
  64. case iv::HUNTER:
  65. nRtn = ProcHUNTERChassis(gpa,&xmsg);
  66. break;
  67. default:
  68. break;
  69. }
  70. if(nRtn == 1)gnRadarState = 100;
  71. // DecodeRadar(xmsg);
  72. // qDebug("can size is %d",xmsg.rawmsg_size());
  73. // xt = QDateTime::currentMSecsSinceEpoch();
  74. // qDebug("latence = %ld ",xt-pic.time());
  75. }
  76. /**
  77. * @brief threadstate
  78. * Update Fault State
  79. * @retval
  80. **/
  81. void threadstate()
  82. {
  83. while(1)
  84. {
  85. std::this_thread::sleep_for(std::chrono::milliseconds(10));
  86. if(gnRadarState > -100)gnRadarState--;
  87. if(gnRadarState > 0)
  88. {
  89. givfault->SetFaultState(0,0,"OK");
  90. }
  91. else
  92. {
  93. if(gnRadarState > -100)
  94. {
  95. givfault->SetFaultState(1,1,"无底盘数据");
  96. }
  97. else
  98. {
  99. givfault->SetFaultState(1,2,"底盘无响应");
  100. }
  101. }
  102. }
  103. }
  104. int main(int argc, char *argv[])
  105. {
  106. RegisterIVBackTrace();
  107. showversion("detection_chassis");
  108. QCoreApplication a(argc, argv);
  109. gTime.start();
  110. QString strpath = QCoreApplication::applicationDirPath();
  111. if(argc < 2)
  112. strpath = strpath + "/detection_chassis.xml";
  113. else
  114. strpath = argv[1];
  115. std::cout<<strpath.toStdString()<<std::endl;
  116. iv::xmlparam::Xmlparam xp(strpath.toStdString());
  117. std::string strmemcan = xp.GetParam("canrecv","canrecv0_31510000E80");
  118. std::string strvehicletype = xp.GetParam("vehicletype","HUNTER");
  119. std::string strmodulename = xp.GetParam("modulename","chassis"); //chassismsgname
  120. std::string strchassismsgname = xp.GetParam("chassismsgname","chassis");
  121. iv::gVehicleType = iv::UNKNOWN;
  122. if(strncmp(strvehicletype.data(),"GE3",255) == 0)
  123. {
  124. iv::gVehicleType = iv::GE3;
  125. }
  126. if(strncmp(strvehicletype.data(),"VV7",255) == 0)
  127. {
  128. iv::gVehicleType = iv::VV7;
  129. }
  130. if(strncmp(strvehicletype.data(),"PROBLUE",255) == 0)
  131. {
  132. iv::gVehicleType = iv::PROBLUE;
  133. }
  134. if(strncmp(strvehicletype.data(),"MIDCAR",255) == 0)
  135. {
  136. iv::gVehicleType = iv::MIDCAR;
  137. }
  138. if(strncmp(strvehicletype.data(),"MIDBUS",255) == 0)
  139. {
  140. iv::gVehicleType = iv::MIDBUS;
  141. }
  142. if(strncmp(strvehicletype.data(),"HAPO",255) == 0)
  143. {
  144. iv::gVehicleType = iv::HAPO;
  145. }
  146. if(strncmp(strvehicletype.data(),"YUHESEN",255) == 0)
  147. {
  148. iv::gVehicleType = iv::YUHESEN;
  149. }
  150. if(strncmp(strvehicletype.data(),"HUNTER",255) == 0)//20210903,CXW
  151. {
  152. iv::gVehicleType = iv::HUNTER;
  153. }
  154. //iv::gVehicleType = iv::MIDBUS;
  155. givlog = new iv::Ivlog(strmodulename.data());
  156. givfault = new iv::Ivfault(strmodulename.data());
  157. givfault->SetFaultState(1,1,"初始化");
  158. givlog->info("Initialized");
  159. gpa = iv::modulecomm::RegisterSend(strchassismsgname.data(),1000,1);
  160. void * pa = iv::modulecomm::RegisterRecv(strmemcan.data(),Listencan0);
  161. std::thread threadfault(threadstate);
  162. return a.exec();
  163. }