sdi_datarecv_consumer.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. #include "sdi_datarecv_consumer.h"
  2. extern setupConfig_t setupConfig;
  3. extern iv::msgunit shmSonar;
  4. extern double gsoundVelocity;
  5. SDI_DataRecv_Consumer::SDI_DataRecv_Consumer(Byte_Qvector_Producer_Consumer *pBuf)
  6. {
  7. pBuffer = pBuf;
  8. }
  9. SDI_DataRecv_Consumer::~SDI_DataRecv_Consumer()
  10. {
  11. requestInterruption();
  12. while(this->isFinished() == false);
  13. }
  14. void SDI_DataRecv_Consumer::run()
  15. {
  16. QVector<uint8_t> tempData;
  17. BYTES2UINT bytes2uint;
  18. bytes2uint.wordData = 0xFF00;
  19. while (!QThread::isInterruptionRequested())
  20. {
  21. tempData = pBuffer->Consume_Element();
  22. uint16_t tempPtr = tempData.size();
  23. bytes2uint.byteData[1] = tempData.at(tempPtr - 1);
  24. bytes2uint.byteData[0] = tempData.at(tempPtr - 2);
  25. SDI_payload_size = bytes2uint.wordData;
  26. SDI_sensor_CNT = tempData.at(8);
  27. bytes2uint.byteData[0] = tempData.at(4);
  28. bytes2uint.byteData[1] = tempData.at(5);
  29. SDI_TX_Mask = bytes2uint.wordData;
  30. if(SDI_sensor_CNT == 4 && SDI_payload_size >= 0x0061)
  31. {
  32. if(SDI_TX_Mask == 0x0041)
  33. {
  34. if(tempData.at(9)==0x00&&tempData.at(39)==0x01&&tempData.at(61)==0x06&&tempData.at(91)==0x07)
  35. {
  36. Clear_Sensor_Data();
  37. uint8_t tempEchosCNT = tempData.at(10); // sensor 0
  38. for(unsigned int i=0;i<tempEchosCNT;i++)
  39. {
  40. bytes2uint.byteData[0] = tempData.at(4*i+11);
  41. bytes2uint.byteData[1] = tempData.at(4*i+12);
  42. sensorTOF_0.append(bytes2uint.wordData);
  43. sensorMagnitude_0.append(tempData.at(4*i+13));
  44. }
  45. tempEchosCNT = tempData.at(40); // sensor 1
  46. for(unsigned int i=0;i<tempEchosCNT;i++)
  47. {
  48. bytes2uint.byteData[0] = tempData.at(4*i+41);
  49. bytes2uint.byteData[1] = tempData.at(4*i+42);
  50. sensorTOF_1.append(bytes2uint.wordData);
  51. sensorMagnitude_1.append(tempData.at(4*i+43));
  52. }
  53. tempEchosCNT = tempData.at(62); // sensor 6
  54. for(unsigned int i=0;i<tempEchosCNT;i++)
  55. {
  56. bytes2uint.byteData[0] = tempData.at(4*i+63);
  57. bytes2uint.byteData[1] = tempData.at(4*i+64);
  58. sensorTOF_6.append(bytes2uint.wordData);
  59. sensorMagnitude_6.append(tempData.at(4*i+65));
  60. }
  61. tempEchosCNT = tempData.at(92); // sensor 7
  62. for(unsigned int i=0;i<tempEchosCNT;i++)
  63. {
  64. bytes2uint.byteData[0] = tempData.at(4*i+93);
  65. bytes2uint.byteData[1] = tempData.at(4*i+94);
  66. sensorTOF_7.append(bytes2uint.wordData);
  67. sensorMagnitude_7.append(tempData.at(4*i+95));
  68. }
  69. }
  70. else
  71. {
  72. std::cout<<"sensor ID is not correct, payload data may broken. "<<std::endl;
  73. }
  74. }
  75. else if(SDI_TX_Mask == 0x0820)
  76. {
  77. if(tempData.at(9)==0x04&&tempData.at(31)==0x05&&tempData.at(61)==0x0A&&tempData.at(83)==0x0B)
  78. {
  79. uint8_t tempEchosCNT = tempData.at(10); // sensor 4
  80. for(unsigned int i=0;i<tempEchosCNT;i++)
  81. {
  82. bytes2uint.byteData[0] = tempData.at(4*i+11);
  83. bytes2uint.byteData[1] = tempData.at(4*i+12);
  84. sensorTOF_4.append(bytes2uint.wordData);
  85. sensorMagnitude_4.append(tempData.at(4*i+13));
  86. }
  87. tempEchosCNT = tempData.at(32); // sensor 5
  88. for(unsigned int i=0;i<tempEchosCNT;i++)
  89. {
  90. bytes2uint.byteData[0] = tempData.at(4*i+33);
  91. bytes2uint.byteData[1] = tempData.at(4*i+34);
  92. sensorTOF_5.append(bytes2uint.wordData);
  93. sensorMagnitude_5.append(tempData.at(4*i+35));
  94. }
  95. tempEchosCNT = tempData.at(62); // sensor 10
  96. for(unsigned int i=0;i<tempEchosCNT;i++)
  97. {
  98. bytes2uint.byteData[0] = tempData.at(4*i+63);
  99. bytes2uint.byteData[1] = tempData.at(4*i+64);
  100. sensorTOF_10.append(bytes2uint.wordData);
  101. sensorMagnitude_10.append(tempData.at(4*i+65));
  102. }
  103. tempEchosCNT = tempData.at(84); // sensor 11
  104. for(unsigned int i=0;i<tempEchosCNT;i++)
  105. {
  106. bytes2uint.byteData[0] = tempData.at(4*i+85);
  107. bytes2uint.byteData[1] = tempData.at(4*i+86);
  108. sensorTOF_11.append(bytes2uint.wordData);
  109. sensorMagnitude_11.append(tempData.at(4*i+87));
  110. }
  111. this->ResultFilterAndPublish();
  112. }
  113. else
  114. {
  115. std::cout<<"sensor ID is not correct, payload data may broken. "<<std::endl;
  116. }
  117. }
  118. else
  119. {
  120. std::cout<<"TX Mask error. Sensor may broken?"<<std::endl;
  121. }
  122. }
  123. else if(SDI_sensor_CNT == 6 && SDI_payload_size >= 0x008D)
  124. {
  125. if(SDI_TX_Mask == 0x0082)
  126. {
  127. if(tempData.at(9)==0x00&&tempData.at(31)==0x01&&tempData.at(61)==0x02&&tempData.at(83)==0x06&&tempData.at(105)==0x07&&tempData.at(135)==0x08)
  128. {
  129. uint8_t tempEchosCNT = tempData.at(10); // sensor 0
  130. for(unsigned int i=0;i<tempEchosCNT;i++)
  131. {
  132. bytes2uint.byteData[0] = tempData.at(4*i+11);
  133. bytes2uint.byteData[1] = tempData.at(4*i+12);
  134. sensorTOF_0.append(bytes2uint.wordData);
  135. sensorMagnitude_0.append(tempData.at(4*i+13));
  136. }
  137. tempEchosCNT = tempData.at(32); // sensor 1
  138. for(unsigned int i=0;i<tempEchosCNT;i++)
  139. {
  140. bytes2uint.byteData[0] = tempData.at(4*i+33);
  141. bytes2uint.byteData[1] = tempData.at(4*i+34);
  142. sensorTOF_1.append(bytes2uint.wordData);
  143. sensorMagnitude_1.append(tempData.at(4*i+35));
  144. }
  145. tempEchosCNT = tempData.at(62); // sensor 2
  146. for(unsigned int i=0;i<tempEchosCNT;i++)
  147. {
  148. bytes2uint.byteData[0] = tempData.at(4*i+63);
  149. bytes2uint.byteData[1] = tempData.at(4*i+64);
  150. sensorTOF_2.append(bytes2uint.wordData);
  151. sensorMagnitude_2.append(tempData.at(4*i+65));
  152. }
  153. tempEchosCNT = tempData.at(84); // sensor 6
  154. for(unsigned int i=0;i<tempEchosCNT;i++)
  155. {
  156. bytes2uint.byteData[0] = tempData.at(4*i+85);
  157. bytes2uint.byteData[1] = tempData.at(4*i+86);
  158. sensorTOF_6.append(bytes2uint.wordData);
  159. sensorMagnitude_6.append(tempData.at(4*i+87));
  160. }
  161. tempEchosCNT = tempData.at(106); // sensor 7
  162. for(unsigned int i=0;i<tempEchosCNT;i++)
  163. {
  164. bytes2uint.byteData[0] = tempData.at(4*i+107);
  165. bytes2uint.byteData[1] = tempData.at(4*i+108);
  166. sensorTOF_7.append(bytes2uint.wordData);
  167. sensorMagnitude_7.append(tempData.at(4*i+109));
  168. }
  169. tempEchosCNT = tempData.at(136); // sensor 8
  170. for(unsigned int i=0;i<tempEchosCNT;i++)
  171. {
  172. bytes2uint.byteData[0] = tempData.at(4*i+137);
  173. bytes2uint.byteData[1] = tempData.at(4*i+138);
  174. sensorTOF_8.append(bytes2uint.wordData);
  175. sensorMagnitude_8.append(tempData.at(4*i+139));
  176. }
  177. }
  178. else
  179. {
  180. std::cout<<"sensor ID is not correct, payload data may broken. "<<std::endl;
  181. }
  182. }
  183. else if(SDI_TX_Mask == 0x0104)
  184. {
  185. if(tempData.at(9)==0x01&&tempData.at(31)==0x02&&tempData.at(61)==0x03&&tempData.at(83)==0x07&&tempData.at(105)==0x08&&tempData.at(135)==0x09)
  186. {
  187. uint8_t tempEchosCNT = tempData.at(10); // sensor 1
  188. for(unsigned int i=0;i<tempEchosCNT;i++)
  189. {
  190. bytes2uint.byteData[0] = tempData.at(4*i+11);
  191. bytes2uint.byteData[1] = tempData.at(4*i+12);
  192. sensorTOF_1.append(bytes2uint.wordData);
  193. sensorMagnitude_1.append(tempData.at(4*i+13));
  194. }
  195. tempEchosCNT = tempData.at(32); // sensor 2
  196. for(unsigned int i=0;i<tempEchosCNT;i++)
  197. {
  198. bytes2uint.byteData[0] = tempData.at(4*i+33);
  199. bytes2uint.byteData[1] = tempData.at(4*i+34);
  200. sensorTOF_2.append(bytes2uint.wordData);
  201. sensorMagnitude_2.append(tempData.at(4*i+35));
  202. }
  203. tempEchosCNT = tempData.at(62); // sensor 3
  204. for(unsigned int i=0;i<tempEchosCNT;i++)
  205. {
  206. bytes2uint.byteData[0] = tempData.at(4*i+63);
  207. bytes2uint.byteData[1] = tempData.at(4*i+64);
  208. sensorTOF_3.append(bytes2uint.wordData);
  209. sensorMagnitude_3.append(tempData.at(4*i+65));
  210. }
  211. tempEchosCNT = tempData.at(84); // sensor 7
  212. for(unsigned int i=0;i<tempEchosCNT;i++)
  213. {
  214. bytes2uint.byteData[0] = tempData.at(4*i+85);
  215. bytes2uint.byteData[1] = tempData.at(4*i+86);
  216. sensorTOF_7.append(bytes2uint.wordData);
  217. sensorMagnitude_7.append(tempData.at(4*i+87));
  218. }
  219. tempEchosCNT = tempData.at(106); // sensor 8
  220. for(unsigned int i=0;i<tempEchosCNT;i++)
  221. {
  222. bytes2uint.byteData[0] = tempData.at(4*i+107);
  223. bytes2uint.byteData[1] = tempData.at(4*i+108);
  224. sensorTOF_8.append(bytes2uint.wordData);
  225. sensorMagnitude_8.append(tempData.at(4*i+109));
  226. }
  227. tempEchosCNT = tempData.at(136); // sensor 9
  228. for(unsigned int i=0;i<tempEchosCNT;i++)
  229. {
  230. bytes2uint.byteData[0] = tempData.at(4*i+137);
  231. bytes2uint.byteData[1] = tempData.at(4*i+138);
  232. sensorTOF_9.append(bytes2uint.wordData);
  233. sensorMagnitude_9.append(tempData.at(4*i+139));
  234. }
  235. }
  236. else
  237. {
  238. std::cout<<"sensor ID is not correct, payload data may broken. "<<std::endl;
  239. }
  240. }
  241. else if(SDI_TX_Mask == 0x0208)
  242. {
  243. if(tempData.at(9)==0x02&&tempData.at(31)==0x03&&tempData.at(61)==0x04&&tempData.at(83)==0x08&&tempData.at(105)==0x09&&tempData.at(135)==0x0A)
  244. {
  245. uint8_t tempEchosCNT = tempData.at(10); // sensor 2
  246. for(unsigned int i=0;i<tempEchosCNT;i++)
  247. {
  248. bytes2uint.byteData[0] = tempData.at(4*i+11);
  249. bytes2uint.byteData[1] = tempData.at(4*i+12);
  250. sensorTOF_2.append(bytes2uint.wordData);
  251. sensorMagnitude_2.append(tempData.at(4*i+13));
  252. }
  253. tempEchosCNT = tempData.at(32); // sensor 3
  254. for(unsigned int i=0;i<tempEchosCNT;i++)
  255. {
  256. bytes2uint.byteData[0] = tempData.at(4*i+33);
  257. bytes2uint.byteData[1] = tempData.at(4*i+34);
  258. sensorTOF_3.append(bytes2uint.wordData);
  259. sensorMagnitude_3.append(tempData.at(4*i+35));
  260. }
  261. tempEchosCNT = tempData.at(62); // sensor 4
  262. for(unsigned int i=0;i<tempEchosCNT;i++)
  263. {
  264. bytes2uint.byteData[0] = tempData.at(4*i+63);
  265. bytes2uint.byteData[1] = tempData.at(4*i+64);
  266. sensorTOF_4.append(bytes2uint.wordData);
  267. sensorMagnitude_4.append(tempData.at(4*i+65));
  268. }
  269. tempEchosCNT = tempData.at(84); // sensor 8
  270. for(unsigned int i=0;i<tempEchosCNT;i++)
  271. {
  272. bytes2uint.byteData[0] = tempData.at(4*i+85);
  273. bytes2uint.byteData[1] = tempData.at(4*i+86);
  274. sensorTOF_8.append(bytes2uint.wordData);
  275. sensorMagnitude_8.append(tempData.at(4*i+87));
  276. }
  277. tempEchosCNT = tempData.at(106); // sensor 9
  278. for(unsigned int i=0;i<tempEchosCNT;i++)
  279. {
  280. bytes2uint.byteData[0] = tempData.at(4*i+107);
  281. bytes2uint.byteData[1] = tempData.at(4*i+108);
  282. sensorTOF_9.append(bytes2uint.wordData);
  283. sensorMagnitude_9.append(tempData.at(4*i+109));
  284. }
  285. tempEchosCNT = tempData.at(136); // sensor 10
  286. for(unsigned int i=0;i<tempEchosCNT;i++)
  287. {
  288. bytes2uint.byteData[0] = tempData.at(4*i+137);
  289. bytes2uint.byteData[1] = tempData.at(4*i+138);
  290. sensorTOF_10.append(bytes2uint.wordData);
  291. sensorMagnitude_10.append(tempData.at(4*i+139));
  292. }
  293. }
  294. else
  295. {
  296. std::cout<<"sensor ID is not correct, payload data may broken. "<<std::endl;
  297. }
  298. }
  299. else if(SDI_TX_Mask == 0x0410)
  300. {
  301. if(tempData.at(9)==0x03&&tempData.at(31)==0x04&&tempData.at(61)==0x05&&tempData.at(83)==0x09&&tempData.at(105)==0x0A&&tempData.at(135)==0x0B)
  302. {
  303. uint8_t tempEchosCNT = tempData.at(10); // sensor 3
  304. for(unsigned int i=0;i<tempEchosCNT;i++)
  305. {
  306. bytes2uint.byteData[0] = tempData.at(4*i+11);
  307. bytes2uint.byteData[1] = tempData.at(4*i+12);
  308. sensorTOF_3.append(bytes2uint.wordData);
  309. sensorMagnitude_3.append(tempData.at(4*i+13));
  310. }
  311. tempEchosCNT = tempData.at(32); // sensor 4
  312. for(unsigned int i=0;i<tempEchosCNT;i++)
  313. {
  314. bytes2uint.byteData[0] = tempData.at(4*i+33);
  315. bytes2uint.byteData[1] = tempData.at(4*i+34);
  316. sensorTOF_4.append(bytes2uint.wordData);
  317. sensorMagnitude_4.append(tempData.at(4*i+35));
  318. }
  319. tempEchosCNT = tempData.at(62); // sensor 5
  320. for(unsigned int i=0;i<tempEchosCNT;i++)
  321. {
  322. bytes2uint.byteData[0] = tempData.at(4*i+63);
  323. bytes2uint.byteData[1] = tempData.at(4*i+64);
  324. sensorTOF_5.append(bytes2uint.wordData);
  325. sensorMagnitude_5.append(tempData.at(4*i+65));
  326. }
  327. tempEchosCNT = tempData.at(84); // sensor 9
  328. for(unsigned int i=0;i<tempEchosCNT;i++)
  329. {
  330. bytes2uint.byteData[0] = tempData.at(4*i+85);
  331. bytes2uint.byteData[1] = tempData.at(4*i+86);
  332. sensorTOF_9.append(bytes2uint.wordData);
  333. sensorMagnitude_9.append(tempData.at(4*i+87));
  334. }
  335. tempEchosCNT = tempData.at(106); // sensor 10
  336. for(unsigned int i=0;i<tempEchosCNT;i++)
  337. {
  338. bytes2uint.byteData[0] = tempData.at(4*i+107);
  339. bytes2uint.byteData[1] = tempData.at(4*i+108);
  340. sensorTOF_10.append(bytes2uint.wordData);
  341. sensorMagnitude_10.append(tempData.at(4*i+109));
  342. }
  343. tempEchosCNT = tempData.at(136); // sensor 11
  344. for(unsigned int i=0;i<tempEchosCNT;i++)
  345. {
  346. bytes2uint.byteData[0] = tempData.at(4*i+137);
  347. bytes2uint.byteData[1] = tempData.at(4*i+138);
  348. sensorTOF_11.append(bytes2uint.wordData);
  349. sensorMagnitude_11.append(tempData.at(4*i+139));
  350. }
  351. }
  352. else
  353. {
  354. std::cout<<"sensor ID is not correct, payload data may broken. "<<std::endl;
  355. }
  356. }
  357. else
  358. {
  359. std::cout<<"TX Mask error. Sensor may broken?"<<std::endl;
  360. }
  361. }
  362. else
  363. {
  364. std::cout<<"number of working sensor is "<<(int)SDI_sensor_CNT<<"payload size is "<<(int)SDI_payload_size<<" may not correct. default is 4 and 6."<<std::endl;
  365. }
  366. }
  367. }
  368. void SDI_DataRecv_Consumer::Clear_Sensor_Data(void)
  369. {
  370. sensorTOF_0.clear();
  371. sensorTOF_1.clear();
  372. sensorTOF_2.clear();
  373. sensorTOF_3.clear();
  374. sensorTOF_4.clear();
  375. sensorTOF_5.clear();
  376. sensorTOF_6.clear();
  377. sensorTOF_7.clear();
  378. sensorTOF_8.clear();
  379. sensorTOF_9.clear();
  380. sensorTOF_10.clear();
  381. sensorTOF_11.clear();
  382. sensorMagnitude_0.clear();
  383. sensorMagnitude_1.clear();
  384. sensorMagnitude_2.clear();
  385. sensorMagnitude_3.clear();
  386. sensorMagnitude_4.clear();
  387. sensorMagnitude_5.clear();
  388. sensorMagnitude_6.clear();
  389. sensorMagnitude_7.clear();
  390. sensorMagnitude_8.clear();
  391. sensorMagnitude_9.clear();
  392. sensorMagnitude_10.clear();
  393. sensorMagnitude_11.clear();
  394. }
  395. void SDI_DataRecv_Consumer::ResultFilterAndPublish(void)
  396. {
  397. if(sensorTOF_0.size()!=0 && sensorMagnitude_0.size()!=0)
  398. this->BubbleSort(sensorTOF_0,sensorMagnitude_0);
  399. else
  400. return;
  401. if(sensorTOF_1.size()!=0 && sensorMagnitude_1.size()!=0)
  402. this->BubbleSort(sensorTOF_1,sensorMagnitude_1);
  403. else
  404. return;
  405. if(sensorTOF_2.size()!=0 && sensorMagnitude_2.size()!=0)
  406. this->BubbleSort(sensorTOF_2,sensorMagnitude_2);
  407. else
  408. return;
  409. if(sensorTOF_3.size()!=0 && sensorMagnitude_3.size()!=0)
  410. this->BubbleSort(sensorTOF_3,sensorMagnitude_3);
  411. else
  412. return;
  413. if(sensorTOF_4.size()!=0 && sensorMagnitude_4.size()!=0)
  414. this->BubbleSort(sensorTOF_4,sensorMagnitude_4);
  415. else
  416. return;
  417. if(sensorTOF_5.size()!=0 && sensorMagnitude_5.size()!=0)
  418. this->BubbleSort(sensorTOF_5,sensorMagnitude_5);
  419. else
  420. return;
  421. if(sensorTOF_6.size()!=0 && sensorMagnitude_6.size()!=0)
  422. this->BubbleSort(sensorTOF_6,sensorMagnitude_6);
  423. else
  424. return;
  425. if(sensorTOF_7.size()!=0 && sensorMagnitude_7.size()!=0)
  426. this->BubbleSort(sensorTOF_7,sensorMagnitude_7);
  427. else
  428. return;
  429. if(sensorTOF_8.size()!=0 && sensorMagnitude_8.size()!=0)
  430. this->BubbleSort(sensorTOF_8,sensorMagnitude_8);
  431. else
  432. return;
  433. if(sensorTOF_9.size()!=0 && sensorMagnitude_9.size()!=0)
  434. this->BubbleSort(sensorTOF_9,sensorMagnitude_9);
  435. else
  436. return;
  437. if(sensorTOF_10.size()!=0 && sensorMagnitude_10.size()!=0)
  438. this->BubbleSort(sensorTOF_10,sensorMagnitude_10);
  439. else
  440. return;
  441. if(sensorTOF_11.size()!=0 && sensorMagnitude_11.size()!=0)
  442. this->BubbleSort(sensorTOF_11,sensorMagnitude_11);
  443. else
  444. return;
  445. iv::ultrasonic::ultrasonic xmsg;
  446. for(int i=0;i<sensorTOF_0.size();i++)
  447. {
  448. if(sensorTOF_0.at(i)>0 && sensorMagnitude_0.at(i)>5)
  449. {
  450. xmsg.set_sigobjdist_flside((uint32_t)(gsoundVelocity * sensorTOF_0.at(i) * 51.2 / 2000.0)); // mm
  451. xmsg.set_sigsensor_front_ls(true);
  452. break;
  453. }
  454. else
  455. {
  456. xmsg.set_sigobjdist_flside(DIST_ERROR); // 50000 mm
  457. xmsg.set_sigsensor_front_ls(false);
  458. }
  459. }
  460. for(int i=0;i<sensorTOF_1.size();i++)
  461. {
  462. if(sensorTOF_1.at(i)>0 && sensorMagnitude_1.at(i)>5)
  463. {
  464. xmsg.set_sigobjdist_flcorner((uint32_t)(gsoundVelocity * sensorTOF_1.at(i) * 51.2 / 2000.0)); // mm
  465. xmsg.set_sigsensor_front_l(true);
  466. break;
  467. }
  468. else
  469. {
  470. xmsg.set_sigobjdist_flcorner(DIST_ERROR); // 50000 mm
  471. xmsg.set_sigsensor_front_l(false);
  472. }
  473. }
  474. for(int i=0;i<sensorTOF_2.size();i++)
  475. {
  476. if(sensorTOF_2.at(i)>0 && sensorMagnitude_2.at(i)>5)
  477. {
  478. xmsg.set_sigobjdist_flmiddle((uint32_t)(gsoundVelocity * sensorTOF_2.at(i) * 51.2 / 2000.0)); // mm
  479. xmsg.set_sigsensor_front_lm(true);
  480. break;
  481. }
  482. else
  483. {
  484. xmsg.set_sigobjdist_flmiddle(DIST_ERROR); // 50000 mm
  485. xmsg.set_sigsensor_front_lm(false);
  486. }
  487. }
  488. for(int i=0;i<sensorTOF_3.size();i++)
  489. {
  490. if(sensorTOF_3.at(i)>0 && sensorMagnitude_3.at(i)>5)
  491. {
  492. xmsg.set_sigobjdist_frmiddle((uint32_t)(gsoundVelocity * sensorTOF_3.at(i) * 51.2 / 2000.0)); // mm
  493. xmsg.set_sigsensor_front_rm(true);
  494. break;
  495. }
  496. else
  497. {
  498. xmsg.set_sigobjdist_frmiddle(DIST_ERROR); // 50000 mm
  499. xmsg.set_sigsensor_front_rm(false);
  500. }
  501. }
  502. for(int i=0;i<sensorTOF_4.size();i++)
  503. {
  504. if(sensorTOF_4.at(i)>0 && sensorMagnitude_4.at(i)>5)
  505. {
  506. xmsg.set_sigobjdist_frcorner((uint32_t)(gsoundVelocity * sensorTOF_4.at(i) * 51.2 / 2000.0)); // mm
  507. xmsg.set_sigsensor_front_r(true);
  508. break;
  509. }
  510. else
  511. {
  512. xmsg.set_sigobjdist_frcorner(DIST_ERROR); // 50000 mm
  513. xmsg.set_sigsensor_front_r(false);
  514. }
  515. }
  516. for(int i=0;i<sensorTOF_5.size();i++)
  517. {
  518. if(sensorTOF_5.at(i)>0 && sensorMagnitude_5.at(i)>5)
  519. {
  520. xmsg.set_sigobjdist_frside((uint32_t)(gsoundVelocity * sensorTOF_5.at(i) * 51.2 / 2000.0)); // mm
  521. xmsg.set_sigsensor_front_rs(true);
  522. break;
  523. }
  524. else
  525. {
  526. xmsg.set_sigobjdist_frside(DIST_ERROR); // 50000 mm
  527. xmsg.set_sigsensor_front_rs(false);
  528. }
  529. }
  530. for(int i=0;i<sensorTOF_6.size();i++)
  531. {
  532. if(sensorTOF_6.at(i)>0 && sensorMagnitude_6.at(i)>5)
  533. {
  534. xmsg.set_sigobjdist_rrside((uint32_t)(gsoundVelocity * sensorTOF_6.at(i) * 51.2 / 2000.0)); // mm
  535. xmsg.set_sigsensor_rear_rs(true);
  536. break;
  537. }
  538. else
  539. {
  540. xmsg.set_sigobjdist_rrside(DIST_ERROR); // 50000 mm
  541. xmsg.set_sigsensor_rear_rs(false);
  542. }
  543. }
  544. for(int i=0;i<sensorTOF_7.size();i++)
  545. {
  546. if(sensorTOF_7.at(i)>0 && sensorMagnitude_7.at(i)>5)
  547. {
  548. xmsg.set_sigobjdist_rrcorner((uint32_t)(gsoundVelocity * sensorTOF_7.at(i) * 51.2 / 2000.0)); // mm
  549. xmsg.set_sigsensor_rear_r(true);
  550. break;
  551. }
  552. else
  553. {
  554. xmsg.set_sigobjdist_rrcorner(DIST_ERROR); // 50000 mm
  555. xmsg.set_sigsensor_rear_r(false);
  556. }
  557. }
  558. for(int i=0;i<sensorTOF_8.size();i++)
  559. {
  560. if(sensorTOF_8.at(i)>0 && sensorMagnitude_8.at(i)>5)
  561. {
  562. xmsg.set_sigobjdist_rrmiddle((uint32_t)(gsoundVelocity * sensorTOF_8.at(i) * 51.2 / 2000.0)); // mm
  563. xmsg.set_sigsensor_rear_rm(true);
  564. break;
  565. }
  566. else
  567. {
  568. xmsg.set_sigobjdist_rrmiddle(DIST_ERROR); // 50000 mm
  569. xmsg.set_sigsensor_rear_rm(false);
  570. }
  571. }
  572. for(int i=0;i<sensorTOF_9.size();i++)
  573. {
  574. if(sensorTOF_9.at(i)>0 && sensorMagnitude_9.at(i)>5)
  575. {
  576. xmsg.set_sigobjdist_rlmiddle((uint32_t)(gsoundVelocity * sensorTOF_9.at(i) * 51.2 / 2000.0)); // mm
  577. xmsg.set_sigsensor_rear_lm(true);
  578. break;
  579. }
  580. else
  581. {
  582. xmsg.set_sigobjdist_rlmiddle(DIST_ERROR); // 50000 mm
  583. xmsg.set_sigsensor_rear_lm(false);
  584. }
  585. }
  586. for(int i=0;i<sensorTOF_10.size();i++)
  587. {
  588. if(sensorTOF_10.at(i)>0 && sensorMagnitude_10.at(i)>5)
  589. {
  590. xmsg.set_sigobjdist_rlcorner((uint32_t)(gsoundVelocity * sensorTOF_10.at(i) * 51.2 / 2000.0)); // mm
  591. xmsg.set_sigsensor_rear_l(true);
  592. break;
  593. }
  594. else
  595. {
  596. xmsg.set_sigobjdist_rlcorner(DIST_ERROR); // 50000 mm
  597. xmsg.set_sigsensor_rear_l(false);
  598. }
  599. }
  600. for(int i=0;i<sensorTOF_11.size();i++)
  601. {
  602. if(sensorTOF_11.at(i)>0 && sensorMagnitude_11.at(i)>5)
  603. {
  604. xmsg.set_sigobjdist_rlside((uint32_t)(gsoundVelocity * sensorTOF_11.at(i) * 51.2 / 2000.0)); // mm
  605. xmsg.set_sigsensor_rear_ls(true);
  606. break;
  607. }
  608. else
  609. {
  610. xmsg.set_sigobjdist_rlside(DIST_ERROR); // 50000 mm
  611. xmsg.set_sigsensor_rear_ls(false);
  612. }
  613. }
  614. xmsg.set_timestamp(QDateTime::currentMSecsSinceEpoch());
  615. int ndatasize = xmsg.ByteSize();
  616. char * strser = new char[ndatasize];
  617. std::shared_ptr<char> pstrser;
  618. pstrser.reset(strser);
  619. if(xmsg.SerializePartialToArray(strser,ndatasize))
  620. {
  621. iv::modulecomm::ModuleSendMsg(shmSonar.mpa,strser,ndatasize);
  622. }
  623. else
  624. {
  625. std::cout<<"ultrasonic data serialize error."<<std::endl;
  626. }
  627. }
  628. void SDI_DataRecv_Consumer::BubbleSort(QVector<uint16_t> &sensorTOF, QVector<uint16_t> &sensorMagnitude)
  629. {
  630. if(sensorTOF.size()<2||sensorMagnitude.size()<2)return;
  631. //notice vector size must >= 2
  632. int i = 0,j = 0;
  633. uint16_t tempTOF = 0;
  634. uint8_t tempMagnitude = 0;
  635. if(sensorTOF.size() == sensorMagnitude.size())
  636. {
  637. for(i=0;i<sensorTOF.size()-1;i++)
  638. {
  639. for(j=0;j<sensorTOF.size()-1-i;j++)
  640. {
  641. if(sensorTOF.at(j)>sensorTOF.at(j+1))
  642. {
  643. tempTOF = sensorTOF.at(j);
  644. sensorTOF[j] = sensorTOF.at(j+1);
  645. sensorTOF[j+1] = tempTOF;
  646. tempMagnitude = sensorMagnitude.at(j);
  647. sensorMagnitude[j] = sensorMagnitude.at(j+1);
  648. sensorMagnitude[j+1] = tempMagnitude;
  649. }
  650. }
  651. }
  652. }
  653. }