main.cpp 4.9 KB

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