ivdecision.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. #include "ivdecision.h"
  2. #include "gnss_coordinate_convert.h"
  3. #include "decition_type.h"
  4. #include "decition.pb.h"
  5. namespace iv {
  6. ivdecision::ivdecision()
  7. {
  8. }
  9. void ivdecision::modulerun()
  10. {
  11. ModuleFun fungps = std::bind(&iv::ivdecision::UpdateGPS,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  12. mpagpsmsg = iv::modulecomm::RegisterRecvPlus(mstrgpsmsgname.data(),fungps);
  13. ModuleFun funlidar = std::bind(&iv::ivdecision::UpdateLIDAR,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  14. mpalidarmsg = iv::modulecomm::RegisterRecvPlus(mstrlidarmsgname.data(),funlidar);
  15. ModuleFun funradar = std::bind(&iv::ivdecision::UpdateRADAR,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  16. mparadarmsg = iv::modulecomm::RegisterRecvPlus(mstrradarmsgname.data(),funradar);
  17. ModuleFun funmap = std::bind(&iv::ivdecision::UpdateMAP,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  18. mpamapmsg = iv::modulecomm::RegisterRecvPlus(mstrmapmsgname.data(),funmap);
  19. ModuleFun funmobileye = std::bind(&iv::ivdecision::UpdateMobileye,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  20. mpamobileyemsg = iv::modulecomm::RegisterRecvPlus(mstrmobileyemsgname.data(),funmobileye);
  21. ModuleFun funhmi = std::bind(&iv::ivdecision::UpdateHMI,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  22. mpahmimsg = iv::modulecomm::RegisterRecvPlus(mstrhmimsgname.data(),funhmi);
  23. mpapadmsg = iv::modulecomm::RegisterRecvPlus(mstrpadmsgname.data(),funhmi);
  24. ModuleFun funp900 = std::bind(&iv::ivdecision::Updatep900,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  25. mpap900msg = iv::modulecomm::RegisterRecvPlus(mstrp900msgname.data(),funp900);
  26. ModuleFun funv2x = std::bind(&iv::ivdecision::Updatev2x,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  27. mpav2xmsg = iv::modulecomm::RegisterRecvPlus(mstrv2xmsgname.data(),funv2x);
  28. ModuleFun funultra = std::bind(&iv::ivdecision::Updateultrasonic,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  29. mpaultramsg = iv::modulecomm::RegisterRecvPlus(mstrultramsgname.data(),funultra);
  30. ModuleFun funvbox = std::bind(&iv::ivdecision::UpdateVbox,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  31. mpavboxmsg = iv::modulecomm::RegisterRecvPlus(mstrvboxmsgname.data(),funvbox);
  32. ModuleFun funchassis = std::bind(&iv::ivdecision::UpdatepChassis,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  33. mpachassismsg = iv::modulecomm::RegisterRecvPlus(mstrchassismsgname.data(),funchassis);
  34. mpaDecition = iv::modulecomm::RegisterSend(mstrdecisionmsgname.data(),10*sizeof(iv::decition::DecitionBasic),1);
  35. mpaVechicleState = iv::modulecomm::RegisterSend(mstrbrainstatemsgname.data(),10000,10);
  36. iv::brain::brainstate xbs;
  37. iv::brain::decition xdecition;
  38. qint64 nSpace = 10;
  39. qint64 nLastDecTime = 0;
  40. while(mbrun)
  41. {
  42. if((QDateTime::currentMSecsSinceEpoch() - nLastDecTime)<nSpace)
  43. {
  44. std::this_thread::sleep_for(std::chrono::milliseconds(2));
  45. continue;
  46. }
  47. nLastDecTime = QDateTime::currentMSecsSinceEpoch();
  48. std::cout<<"running."<<std::endl;
  49. int nrtn = getdecision(xdecition,xbs);
  50. if(nrtn == 1)
  51. {
  52. sharemsg(xdecition,xbs);
  53. }
  54. //RunDecision
  55. //ShareMsg
  56. }
  57. iv::modulecomm::Unregister(mpaVechicleState);
  58. iv::modulecomm::Unregister(mpaDecition);
  59. iv::modulecomm::Unregister(mpachassismsg);
  60. iv::modulecomm::Unregister(mpavboxmsg);
  61. iv::modulecomm::Unregister(mpaultramsg);
  62. iv::modulecomm::Unregister(mpav2xmsg);
  63. iv::modulecomm::Unregister(mpap900msg);
  64. iv::modulecomm::Unregister(mpapadmsg);
  65. iv::modulecomm::Unregister(mpahmimsg);
  66. iv::modulecomm::Unregister(mpamobileyemsg);
  67. iv::modulecomm::Unregister(mpamapmsg);
  68. iv::modulecomm::Unregister(mparadarmsg);
  69. iv::modulecomm::Unregister(mpalidarmsg);
  70. iv::modulecomm::Unregister(mpagpsmsg);
  71. }
  72. void ivdecision::sharemsg(brain::decition &xdecition, brain::brainstate &xbs)
  73. {
  74. unsigned int nsize = static_cast<unsigned int>(xdecition.ByteSize());
  75. char * str = new char[nsize];
  76. std::shared_ptr<char> pstr;
  77. pstr.reset(str);
  78. if(xdecition.SerializeToArray(str,static_cast<int>(nsize) ))
  79. {
  80. // if(ServiceCarStatus.mbRunPause == false)
  81. // {
  82. iv::modulecomm::ModuleSendMsg(mpaDecition,str,nsize);
  83. // }
  84. }
  85. else
  86. {
  87. std::cout<<"iv::decition::BrainDecition::ShareDecition serialize error."<<std::endl;
  88. }
  89. nsize = static_cast<unsigned int>(xbs.ByteSize());
  90. str = new char[nsize];
  91. // std::shared_ptr<char> pstr;
  92. pstr.reset(str);
  93. if(xbs.SerializeToArray(str,static_cast<int>(nsize)))
  94. {
  95. iv::modulecomm::ModuleSendMsg(mpaVechicleState,str,nsize);
  96. }
  97. else
  98. {
  99. std::cout<<"iv::decition::BrainDecition::ShareBrainstate serialize error."<<std::endl;
  100. }
  101. }
  102. void ivdecision::UpdateGPS(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  103. {
  104. (void )&index;
  105. (void )&dt;
  106. (void )strmemname;
  107. if(nSize<1)return;
  108. iv::gps::gpsimu xgpsimu;
  109. if(!xgpsimu.ParseFromArray(strdata,nSize))
  110. {
  111. std::cout<<"ivdecision::UpdateGPSMsg error."<<std::endl;
  112. return;
  113. }
  114. iv::GPSData data(new iv::GPS_INS);
  115. data->ins_status = xgpsimu.ins_state();
  116. data->rtk_status = xgpsimu.rtk_state();
  117. data->accel_x = xgpsimu.acce_x();
  118. data->accel_y = xgpsimu.acce_y();
  119. data->accel_z = xgpsimu.acce_z();
  120. data->ang_rate_x = xgpsimu.gyro_x();
  121. data->ang_rate_y = xgpsimu.gyro_y();
  122. data->ang_rate_z = xgpsimu.gyro_z();
  123. data->gps_lat = xgpsimu.lat();
  124. data->gps_lng = xgpsimu.lon();
  125. data->gps_z = xgpsimu.height();
  126. data->ins_heading_angle = xgpsimu.heading();
  127. data->ins_pitch_angle = xgpsimu.pitch();
  128. data->ins_roll_angle = xgpsimu.roll();
  129. data->speed = sqrt(pow(xgpsimu.ve(),2)+pow(xgpsimu.vn(),2)) * 3.6;
  130. GaussProjCal(data->gps_lng, data->gps_lat, &data->gps_x, &data->gps_y);
  131. mMutexGPS.lock();
  132. iv::gps::gpsimu * pgpsimu = new iv::gps::gpsimu;
  133. pgpsimu->CopyFrom(xgpsimu);
  134. mGPSIMUptr.reset(pgpsimu);
  135. mNowGPS = data;
  136. mnGPSUpdateTime = QDateTime::currentMSecsSinceEpoch();
  137. mMutexGPS.unlock();
  138. }
  139. bool ivdecision::GetGPS(GPSData &xGPSData)
  140. {
  141. if((QDateTime::currentMSecsSinceEpoch() - mnGPSUpdateTime)>mnNewThresh)
  142. {
  143. xGPSData = NULL;
  144. return false;
  145. }
  146. xGPSData = mNowGPS;
  147. return true;
  148. }
  149. void ivdecision::UpdateRADAR(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  150. {
  151. (void )&index;
  152. (void )&dt;
  153. (void )strmemname;
  154. if(nSize<1)return;
  155. iv::radar::radarobjectarray * pradar = new iv::radar::radarobjectarray;
  156. if(!pradar->ParseFromArray(strdata,nSize))
  157. {
  158. std::cout<<"ivdecision::UpdateRADARMsg Parse Error"<<std::endl;
  159. return;
  160. }
  161. mMutexRADAR.lock();
  162. mRADAR.reset(pradar);
  163. mnRADARUpdateTime = QDateTime::currentMSecsSinceEpoch();
  164. mMutexRADAR.unlock();
  165. }
  166. bool ivdecision::GetRADAR(std::shared_ptr<radar::radarobjectarray> &xRADAR)
  167. {
  168. if((QDateTime::currentMSecsSinceEpoch() - mnRADARUpdateTime)>mnNewThresh)
  169. {
  170. xRADAR = NULL;
  171. return false;
  172. }
  173. xRADAR = mRADAR;
  174. return true;
  175. }
  176. void ivdecision::UpdateLIDAR(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  177. {
  178. (void )&index;
  179. (void )&dt;
  180. (void )strmemname;
  181. if(nSize<1)return;
  182. unsigned int nCount = nSize/sizeof(iv::ObstacleBasic);
  183. std::shared_ptr<std::vector<iv::ObstacleBasic>> lidar_obs = std::shared_ptr<std::vector<iv::ObstacleBasic>>(new std::vector<iv::ObstacleBasic>);
  184. lidar_obs->resize(nCount);
  185. memcpy(lidar_obs->data(),strdata,nCount*sizeof(iv::ObstacleBasic));
  186. mMutexLIDAR.lock();
  187. mlidar_obs = lidar_obs;
  188. mnLIDARUpdateTime = QDateTime::currentMSecsSinceEpoch();
  189. mMutexLIDAR.unlock();
  190. }
  191. bool ivdecision::GetLIDARGrid(LidarGridPtr &lidargridptr)
  192. {
  193. if((QDateTime::currentMSecsSinceEpoch() - mnLIDARUpdateTime)>mnNewThresh)
  194. {
  195. lidargridptr = NULL;
  196. return false;
  197. }
  198. LidarGridPtr ptr = (Obs_grid *)malloc(sizeof(Obs_grid[iv::grx][iv::gry]));
  199. memset(ptr, 0, sizeof(Obs_grid[iv::grx][iv::gry]));
  200. for (int i = 0; i <iv::grx; i++)//复制到指针数组
  201. {
  202. for (int j = 0; j <iv::gry; j++)
  203. {
  204. // ptr[i * (iv::gry) + j].high = obs_grid[i][j].high;
  205. // ptr[i * (iv::gry) + j].low = obs_grid[i][j].low;
  206. ptr[i * (iv::gry) + j].ob = 0;
  207. // ptr[i * (iv::gry) + j].obshight = obs_grid[i][j].obshight;
  208. // ptr[i * (iv::gry) + j].pointcount = obs_grid[i][j].pointcount;
  209. }
  210. }
  211. mMutexLIDAR.lock();
  212. for(unsigned int i=0;i<mlidar_obs->size();i++)
  213. {
  214. iv::ObstacleBasic xobs = mlidar_obs->at(i);
  215. int dx,dy;
  216. dx = (xobs.nomal_x + gridwide * (double)centerx)/gridwide;
  217. dy = (xobs.nomal_y + gridwide * (double)centery)/gridwide;
  218. if((dx>=0)&&(dx<iv::grx)&&(dy>=0)&&(dy<iv::gry))
  219. {
  220. ptr[dx*(iv::gry) +dy].high = xobs.high;
  221. ptr[dx*(iv::gry) +dy].low = xobs.low;
  222. ptr[dx*(iv::gry) + dy].ob = 2;
  223. ptr[dx*(iv::gry) + dy].obshight = xobs.nomal_z;
  224. ptr[dx*(iv::gry) + dy].pointcount = 5;
  225. }
  226. }
  227. lidargridptr = ptr;
  228. mMutexLIDAR.unlock();
  229. return true;
  230. }
  231. bool ivdecision::GetLIDARObs(std::shared_ptr<std::vector<ObstacleBasic> > &xlidar_obs)
  232. {
  233. if((QDateTime::currentMSecsSinceEpoch() - mnLIDARUpdateTime)>mnNewThresh)
  234. {
  235. xlidar_obs = NULL;
  236. return false;
  237. }
  238. mMutexLIDAR.lock();
  239. xlidar_obs = mlidar_obs;
  240. mMutexLIDAR.unlock();
  241. return true;
  242. }
  243. void ivdecision::UpdateMAP(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  244. {
  245. (void )&index;
  246. (void )&dt;
  247. (void )strmemname;
  248. if(nSize<1)return;
  249. // std::cout<<"update map "<<std::endl;
  250. int gpsunitsize = sizeof(iv::GPS_INS);
  251. int nMapSize = nSize/gpsunitsize;
  252. // std::cout<<"map size is "<<nMapSize<<std::endl;
  253. if(nMapSize < 1)return;
  254. bool bUpdate = true;
  255. // if(nMapSize != mnavigation_data.size())
  256. // {
  257. // bUpdate = true;
  258. // }
  259. // else
  260. // {
  261. // iv::GPS_INS * p = (iv::GPS_INS *)mapdata;
  262. // if((p->gps_lat == navigation_data.at(0)->gps_lat)&&(p->ins_heading_angle == navigation_data.at(0)->ins_heading_angle))
  263. // {
  264. // // qDebug("same map");
  265. // bUpdate = false;
  266. // }
  267. // else
  268. // {
  269. // bUpdate = true;
  270. // }
  271. // }
  272. if(bUpdate)
  273. {
  274. mMutexMAP.lock();
  275. mnavigation_data.clear();
  276. // mnavigation_data.resize(nMapSize);
  277. int i;
  278. for(i=0;i<nMapSize;i++)
  279. {
  280. iv::GPS_INS x;
  281. memcpy(&x,strdata + i*gpsunitsize,gpsunitsize);
  282. iv::GPSData data(new iv::GPS_INS);
  283. *data = x;
  284. mnavigation_data.push_back(data);
  285. }
  286. // memcpy(mnavigation_data.data(),strdata,nMapSize * sizeof(iv::GPS_INS));
  287. mnMAPUpdateTime = QDateTime::currentMSecsSinceEpoch();
  288. mMutexMAP.unlock();
  289. }
  290. else
  291. {
  292. }
  293. }
  294. bool ivdecision::IsMAPUpdate(qint64 &nLastUpdateTime)
  295. {
  296. if(mnavigation_data.size()<1)
  297. {
  298. return false;
  299. }
  300. if(nLastUpdateTime != mnMAPUpdateTime)
  301. {
  302. return true;
  303. }
  304. return false;
  305. }
  306. bool ivdecision::GetMAP(std::vector<GPSData> &navigation_data, qint64 &nLastUpdateTime)
  307. {
  308. if(mnavigation_data.size()<1)
  309. {
  310. return false;
  311. }
  312. mMutexMAP.unlock();
  313. nLastUpdateTime = mnMAPUpdateTime;
  314. navigation_data = mnavigation_data;
  315. mMutexMAP.unlock();
  316. return true;
  317. }
  318. void ivdecision::UpdateMobileye(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  319. {
  320. (void )&index;
  321. (void )&dt;
  322. (void )strmemname;
  323. if(nSize<1)return;
  324. std::shared_ptr<iv::mobileye::mobileye> xmobileye = std::shared_ptr<iv::mobileye::mobileye>(new iv::mobileye::mobileye);
  325. if(!xmobileye->ParseFromArray(strdata,nSize))
  326. {
  327. std::cout<<"ivdecision::UpdateMobileye Parse Error."<<std::endl;
  328. return;
  329. }
  330. mMutexmobileye.lock();
  331. mmobileye = xmobileye;
  332. mnmobileyeUpdateTime = QDateTime::currentMSecsSinceEpoch();
  333. mMutexmobileye.unlock();
  334. }
  335. bool ivdecision::GetMobileye(std::shared_ptr<mobileye::mobileye> &xmobileye)
  336. {
  337. if((QDateTime::currentMSecsSinceEpoch() - mnmobileyeUpdateTime)>mnNewThresh)
  338. {
  339. xmobileye = NULL;
  340. return false;
  341. }
  342. mMutexmobileye.lock();
  343. xmobileye = mmobileye;
  344. mMutexmobileye.unlock();
  345. return true;
  346. }
  347. void ivdecision::UpdateHMI(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  348. {
  349. (void )&index;
  350. (void )&dt;
  351. (void )strmemname;
  352. if(nSize<1)return;
  353. std::shared_ptr<iv::hmi::hmimsg> xhmiptr = std::shared_ptr<iv::hmi::hmimsg>(new iv::hmi::hmimsg);
  354. if(!xhmiptr->ParseFromArray(strdata,nSize))
  355. {
  356. std::cout<<"ivdecision::UpdateHMI Parse Error."<<std::endl;
  357. return;
  358. }
  359. mMutexHMI.lock();
  360. mHMImsg = xhmiptr;
  361. mnHMIUpdateTime = QDateTime::currentMSecsSinceEpoch();
  362. mMutexHMI.unlock();
  363. }
  364. bool ivdecision::GetHMImsg(std::shared_ptr<hmi::hmimsg> &xhmimsg)
  365. {
  366. if((QDateTime::currentMSecsSinceEpoch() - mnHMIUpdateTime)>mnNewThresh)
  367. {
  368. xhmimsg = NULL;
  369. return false;
  370. }
  371. mMutexHMI.lock();
  372. xhmimsg = mHMImsg;
  373. mMutexHMI.unlock();
  374. return true;
  375. }
  376. void ivdecision::UpdateVbox(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  377. {
  378. (void )&index;
  379. (void )&dt;
  380. (void )strmemname;
  381. std::shared_ptr<iv::vbox::vbox> vbox_ptr = std::shared_ptr<iv::vbox::vbox>(new iv::vbox::vbox);
  382. if(!vbox_ptr->ParseFromArray(strdata,nSize))
  383. {
  384. std::cout<<"vdecision::UpdateVbox Parse Error"<<std::endl;
  385. return;
  386. }
  387. mMutexvbox.lock();
  388. mvboxmsg = vbox_ptr;
  389. mnvboxUpdateTime = QDateTime::currentMSecsSinceEpoch();
  390. mMutexvbox.unlock();
  391. }
  392. bool ivdecision::Getvboxmsg(std::shared_ptr<vbox::vbox> &xvboxmsg)
  393. {
  394. if((QDateTime::currentMSecsSinceEpoch() - mnvboxUpdateTime)>mnNewThresh)
  395. {
  396. xvboxmsg = NULL;
  397. return false;
  398. }
  399. mMutexvbox.lock();
  400. xvboxmsg = mvboxmsg;
  401. mMutexvbox.unlock();
  402. return true;
  403. }
  404. void ivdecision::Updatev2x(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  405. {
  406. (void )&index;
  407. (void )&dt;
  408. (void )strmemname;
  409. std::shared_ptr<iv::v2x::v2x> xv2x_ptr = std::shared_ptr<iv::v2x::v2x>(new iv::v2x::v2x);
  410. if(!xv2x_ptr->ParseFromArray(strdata,nSize))
  411. {
  412. std::cout<<"ivdecision::Updatev2x Parse Error."<<std::endl;
  413. return;
  414. }
  415. mMutexv2x.lock();
  416. mv2xmsg = xv2x_ptr;
  417. mnv2xUpdateTime = QDateTime::currentMSecsSinceEpoch();
  418. mMutexv2x.unlock();
  419. }
  420. bool ivdecision::Getv2xmsg(std::shared_ptr<v2x::v2x> &xv2xmsg)
  421. {
  422. if((QDateTime::currentMSecsSinceEpoch() - mnv2xUpdateTime)>mnNewThresh)
  423. {
  424. xv2xmsg = NULL;
  425. return false;
  426. }
  427. mMutexv2x.lock();
  428. xv2xmsg = mv2xmsg;
  429. mMutexv2x.unlock();
  430. return true;
  431. }
  432. void ivdecision::Updateultrasonic(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  433. {
  434. (void )&index;
  435. (void )&dt;
  436. (void )strmemname;
  437. std::shared_ptr<iv::ultrasonic::ultrasonic> xultrasonic_ptr
  438. = std::shared_ptr<iv::ultrasonic::ultrasonic>(new iv::ultrasonic::ultrasonic);
  439. if(!xultrasonic_ptr->ParseFromArray(strdata,nSize))
  440. {
  441. std::cout<<"ivdecision::Updateultrasonic Parse Error."<<std::endl;
  442. return;
  443. }
  444. mMutexultrasonic.lock();
  445. multrasonicmsg = xultrasonic_ptr;
  446. mnultrasonicUpdateTime = QDateTime::currentMSecsSinceEpoch();
  447. mMutexultrasonic.unlock();
  448. }
  449. bool ivdecision::Getultrasonic(std::shared_ptr<ultrasonic::ultrasonic> &xultramsg)
  450. {
  451. if((QDateTime::currentMSecsSinceEpoch() - mnultrasonicUpdateTime)>mnNewThresh)
  452. {
  453. xultramsg = NULL;
  454. return false;
  455. }
  456. mMutexultrasonic.lock();
  457. xultramsg = multrasonicmsg;
  458. mMutexultrasonic.unlock();
  459. return true;
  460. }
  461. void ivdecision::Updatep900(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  462. {
  463. (void )&index;
  464. (void )&dt;
  465. (void )strmemname;
  466. std::shared_ptr<iv::radio::radio_send> xp900_ptr
  467. = std::shared_ptr<iv::radio::radio_send>(new iv::radio::radio_send);
  468. if(!xp900_ptr->ParseFromArray(strdata,nSize))
  469. {
  470. std::cout<<"ivdecision::Updatep900 Parse Error."<<std::endl;
  471. return;
  472. }
  473. mMutexp900.lock();
  474. mp900msg = xp900_ptr;
  475. mnp900UpdateTime = QDateTime::currentMSecsSinceEpoch();
  476. mMutexp900.unlock();
  477. }
  478. bool ivdecision::Getp900(std::shared_ptr<iv::radio::radio_send> & xp900msg)
  479. {
  480. if((QDateTime::currentMSecsSinceEpoch() - mnp900UpdateTime)>mnNewThresh)
  481. {
  482. xp900msg = NULL;
  483. return false;
  484. }
  485. mMutexp900.lock();
  486. xp900msg = mp900msg;
  487. mMutexp900.unlock();
  488. return true;
  489. }
  490. void ivdecision::UpdatepChassis(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  491. {
  492. (void )&index;
  493. (void )&dt;
  494. (void )strmemname;
  495. std::shared_ptr<iv::chassis> xchassis_ptr
  496. = std::shared_ptr<iv::chassis>(new iv::chassis);
  497. if(!xchassis_ptr->ParseFromArray(strdata,nSize))
  498. {
  499. std::cout<<"ivdecision::UpdatepChassis Parse Error."<<std::endl;
  500. return;
  501. }
  502. mMutexchassis.lock();
  503. mchassismsg = xchassis_ptr;
  504. mnchassisUpdateTime = QDateTime::currentMSecsSinceEpoch();
  505. mMutexchassis.unlock();
  506. }
  507. bool ivdecision::Getchassis(std::shared_ptr<iv::chassis> & xchassismsg)
  508. {
  509. if((QDateTime::currentMSecsSinceEpoch() - mnchassisUpdateTime)>mnNewThresh)
  510. {
  511. xchassismsg = NULL;
  512. return false;
  513. }
  514. mMutexchassis.lock();
  515. xchassismsg = mchassismsg;
  516. mMutexchassis.unlock();
  517. return true;
  518. }
  519. }