ivdecision.cpp 18 KB

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