main.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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} gVehicleType; //车辆类型
  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. default:
  65. break;
  66. }
  67. if(nRtn == 1)gnRadarState = 100;
  68. // DecodeRadar(xmsg);
  69. // qDebug("can size is %d",xmsg.rawmsg_size());
  70. // xt = QDateTime::currentMSecsSinceEpoch();
  71. // qDebug("latence = %ld ",xt-pic.time());
  72. }
  73. /**
  74. * @brief threadstate
  75. * Update Fault State
  76. * @retval
  77. **/
  78. void threadstate()
  79. {
  80. while(1)
  81. {
  82. std::this_thread::sleep_for(std::chrono::milliseconds(10));
  83. if(gnRadarState > -100)gnRadarState--;
  84. if(gnRadarState > 0)
  85. {
  86. givfault->SetFaultState(0,0,"OK");
  87. }
  88. else
  89. {
  90. if(gnRadarState > -100)
  91. {
  92. givfault->SetFaultState(1,1,"无底盘数据");
  93. }
  94. else
  95. {
  96. givfault->SetFaultState(1,2,"底盘无响应");
  97. }
  98. }
  99. }
  100. }
  101. int main(int argc, char *argv[])
  102. {
  103. RegisterIVBackTrace();
  104. showversion("detection_chassis");
  105. QCoreApplication a(argc, argv);
  106. gTime.start();
  107. QString strpath = QCoreApplication::applicationDirPath();
  108. if(argc < 2)
  109. strpath = strpath + "/detection_chassis.xml";
  110. else
  111. strpath = argv[1];
  112. std::cout<<strpath.toStdString()<<std::endl;
  113. iv::xmlparam::Xmlparam xp(strpath.toStdString());
  114. std::string strmemcan = xp.GetParam("canrecv","canrecv0");
  115. std::string strvehicletype = xp.GetParam("vehicletype","GE3");
  116. std::string strmodulename = xp.GetParam("modulename","chassis"); //chassismsgname
  117. std::string strchassismsgname = xp.GetParam("chassismsgname","chassis");
  118. iv::gVehicleType = iv::UNKNOWN;
  119. if(strncmp(strvehicletype.data(),"GE3",255) == 0)
  120. {
  121. iv::gVehicleType = iv::GE3;
  122. }
  123. if(strncmp(strvehicletype.data(),"VV7",255) == 0)
  124. {
  125. iv::gVehicleType = iv::VV7;
  126. }
  127. if(strncmp(strvehicletype.data(),"PROBLUE",255) == 0)
  128. {
  129. iv::gVehicleType = iv::PROBLUE;
  130. }
  131. if(strncmp(strvehicletype.data(),"MIDCAR",255) == 0)
  132. {
  133. iv::gVehicleType = iv::MIDCAR;
  134. }
  135. if(strncmp(strvehicletype.data(),"MIDBUS",255) == 0)
  136. {
  137. iv::gVehicleType = iv::MIDBUS;
  138. }
  139. if(strncmp(strvehicletype.data(),"HAPO",255) == 0)
  140. {
  141. iv::gVehicleType = iv::HAPO;
  142. }
  143. if(strncmp(strvehicletype.data(),"YUHESEN",255) == 0)
  144. {
  145. iv::gVehicleType = iv::YUHESEN;
  146. }
  147. //iv::gVehicleType = iv::MIDBUS;
  148. givlog = new iv::Ivlog(strmodulename.data());
  149. givfault = new iv::Ivfault(strmodulename.data());
  150. givfault->SetFaultState(1,1,"初始化");
  151. givlog->info("Initialized");
  152. gpa = iv::modulecomm::RegisterSend(strchassismsgname.data(),1000,1);
  153. void * pa = iv::modulecomm::RegisterRecv(strmemcan.data(),Listencan0);
  154. std::thread threadfault(threadstate);
  155. return a.exec();
  156. }