mainwindow.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <iostream>
  4. extern char gstr_memname[256];
  5. //std::string gstrItem[] = {"Pitch","Roll","Heading","gyro_x","gyro_y","gyro_z","acce_x","acce_y",
  6. // "acce_z","lat","lon","hgt","vn","ve","vd","state","time","type",
  7. // "latstd","lonstd","hstd","vnstd","vestd","vdstd","rollstd",
  8. // "pitchstd","yawstd","temp","posstate","headstate","satnum","wheeldata"};
  9. std::string gstrItem[] = {"Pitch","Roll","Heading",
  10. "lat","lon","hgt","vn","ve","vd","insstate","rtkstate","satnum",
  11. "gyro_x","gyro_y","gyro_z","acc_x","acc_y","acc_z"};
  12. std::string gstrDiffItem[] ={"PitchDiff","RollDiff","HeadingDiff","latdiff","londiff","hgtdiff",
  13. "vndiff","vediff","vddiff","avglatdiff","avglondiff","avghgtdiff",
  14. "maxPitchDiff","maxRollDiff","maxHeadDiff",
  15. "maxlatdiff","maxlondiff","maxhgtdiff"};
  16. double gdiff[18];
  17. int gdiffcount = 0;
  18. double gdifftotal[6];
  19. std::string gstrCount[] = {"Total","Posstd","Velstd","Posestd","Devtemp","GPSState","WheelData"};
  20. int gcountRaw[] = {0,0,0,0,0,0,0,0};
  21. int gcountFusion[] = {0,0,0,0,0,0,0,0};
  22. MainWindow * gw;
  23. void ListenRaw(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  24. {
  25. iv::gps::gpsimu xgpsimu;
  26. if(!xgpsimu.ParseFromArray(strdata,nSize))
  27. {
  28. std::cout<<"ListenRaw Parse error."<<std::endl;
  29. }
  30. gw->mMutexraw.lock();
  31. while(gw->mqueueraw.size() > 1000)
  32. {
  33. gw->mqueueraw.pop();
  34. }
  35. gw->mqueueraw.push(xgpsimu);
  36. gcountRaw[0]++;
  37. switch (xgpsimu.type()) {
  38. case 0:
  39. gcountRaw[1]++;
  40. break;
  41. case 1:
  42. gcountRaw[2]++;
  43. break;
  44. case 2:
  45. gcountRaw[3]++;
  46. break;
  47. case 22:
  48. gcountRaw[4]++;
  49. break;
  50. case 32:
  51. gcountRaw[5]++;
  52. break;
  53. case 33:
  54. gcountRaw[6]++;
  55. break;
  56. default:
  57. break;
  58. }
  59. gw->mMutexraw.unlock();
  60. }
  61. void ListenFusion(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  62. {
  63. iv::gps::gpsimu xgpsimu;
  64. if(!xgpsimu.ParseFromArray(strdata,nSize))
  65. {
  66. std::cout<<"ListenRaw Parse error."<<std::endl;
  67. }
  68. gw->mMutexfusion.lock();
  69. while(gw->mqueuefusion.size() > 1000)
  70. {
  71. gw->mqueuefusion.pop();
  72. }
  73. gw->mqueuefusion.push(xgpsimu);
  74. gcountRaw[0]++;
  75. switch (xgpsimu.type()) {
  76. case 0:
  77. gcountRaw[1]++;
  78. break;
  79. case 1:
  80. gcountRaw[2]++;
  81. break;
  82. case 2:
  83. gcountRaw[3]++;
  84. break;
  85. case 22:
  86. gcountRaw[4]++;
  87. break;
  88. case 32:
  89. gcountRaw[5]++;
  90. break;
  91. case 33:
  92. gcountRaw[6]++;
  93. break;
  94. default:
  95. break;
  96. }
  97. gw->mMutexfusion.unlock();
  98. }
  99. MainWindow::MainWindow(QWidget *parent) :
  100. QMainWindow(parent),
  101. ui(new Ui::MainWindow)
  102. {
  103. ui->setupUi(this);
  104. gw = this;
  105. CreateView();
  106. void * paraw = iv::modulecomm::RegisterRecv(gstr_memname,ListenRaw);
  107. void * pafusion = iv::modulecomm::RegisterRecv("fusion_gpsimu",ListenFusion);
  108. QTimer * timer = new QTimer(this);
  109. connect(timer,SIGNAL(timeout()),this,SLOT(onTimer()));
  110. timer->start(5);
  111. setWindowTitle("view_gps");
  112. }
  113. MainWindow::~MainWindow()
  114. {
  115. delete ui;
  116. }
  117. void MainWindow::CreateView()
  118. {
  119. QTabWidget * p = new QTabWidget(ui->centralWidget);
  120. p->setGeometry(30,30,300,300);
  121. CreateTab1View(p);
  122. // CreateTab2View(p);
  123. // CreateTab3View(p);
  124. mTabMain = p;
  125. }
  126. void MainWindow::CreateTab1View(QTabWidget * p)
  127. {
  128. QGroupBox * pGroup = new QGroupBox();
  129. pGroup->setGeometry(0,0,1300,800);
  130. const int TWidth = 1300;
  131. const int nRowDis = 50;
  132. const int nColDis = 200;
  133. const int nIWidth = 95;
  134. const int nIHeight = 30;
  135. int i;
  136. int j;
  137. i=1;j = 0;
  138. int index = 0;
  139. for(auto x : gstrItem)
  140. {
  141. QLabel * pLabel;
  142. QLineEdit * pLineEdit;
  143. pLabel = new QLabel(pGroup);
  144. std::string strname = x;
  145. pLabel->setText(strname.data());
  146. pLineEdit = new QLineEdit(pGroup);
  147. pLabel->setGeometry(10+j*nColDis,i*nRowDis,nIWidth,nIHeight);
  148. pLineEdit->setGeometry(10+j*nColDis+nColDis/2,i*nRowDis,nIWidth,nIHeight);
  149. pLabel->setAlignment(Qt::AlignRight|Qt::AlignCenter);
  150. mpLabelRaw[index] = pLabel;
  151. mpLERaw[index] = pLineEdit;
  152. j++;
  153. if((j+1)*nColDis>TWidth)
  154. {
  155. j= 0;
  156. i++;
  157. }
  158. index++;
  159. }
  160. i++;
  161. i++;
  162. j = 0;
  163. mnCountIndexBase = index;
  164. QScrollArea * pScroll = new QScrollArea();
  165. pScroll->setWidget(pGroup);
  166. p->addTab(pScroll,"gpsimu");
  167. }
  168. void MainWindow::CreateTab2View(QTabWidget * p)
  169. {
  170. QGroupBox * pGroup = new QGroupBox();
  171. pGroup->setGeometry(0,0,1300,800);
  172. const int TWidth = 1300;
  173. const int nRowDis = 50;
  174. const int nColDis = 200;
  175. const int nIWidth = 95;
  176. const int nIHeight = 30;
  177. int i;
  178. int j;
  179. i=1;j = 0;
  180. int index = 0;
  181. for(auto x : gstrItem)
  182. {
  183. QLabel * pLabel;
  184. QLineEdit * pLineEdit;
  185. pLabel = new QLabel(pGroup);
  186. std::string strname = x;
  187. pLabel->setText(strname.data());
  188. pLineEdit = new QLineEdit(pGroup);
  189. pLabel->setGeometry(10+j*nColDis,i*nRowDis,nIWidth,nIHeight);
  190. pLineEdit->setGeometry(10+j*nColDis+nColDis/2,i*nRowDis,nIWidth,nIHeight);
  191. pLabel->setAlignment(Qt::AlignRight|Qt::AlignCenter);
  192. mpLabelFusion[index] = pLabel;
  193. mpLEFusion[index] = pLineEdit;
  194. j++;
  195. if((j+1)*nColDis>TWidth)
  196. {
  197. j= 0;
  198. i++;
  199. }
  200. index++;
  201. }
  202. i++;i++;j= 0;
  203. for(auto x : gstrCount)
  204. {
  205. QLabel * pLabel;
  206. QLineEdit * pLineEdit;
  207. pLabel = new QLabel(pGroup);
  208. std::string strname = x;
  209. pLabel->setText(strname.data());
  210. pLineEdit = new QLineEdit(pGroup);
  211. pLabel->setGeometry(10+j*nColDis,i*nRowDis,nIWidth,nIHeight);
  212. pLineEdit->setGeometry(10+j*nColDis+nColDis/2,i*nRowDis,nIWidth,nIHeight);
  213. pLabel->setAlignment(Qt::AlignRight|Qt::AlignCenter);
  214. mpLabelFusion[index] = pLabel;
  215. mpLEFusion[index] = pLineEdit;
  216. j++;
  217. if((j+1)*nColDis>TWidth)
  218. {
  219. j= 0;
  220. i++;
  221. }
  222. index++;
  223. }
  224. QScrollArea * pScroll = new QScrollArea();
  225. pScroll->setWidget(pGroup);
  226. p->addTab(pScroll,"Fusion");
  227. }
  228. void MainWindow::CreateTab3View(QTabWidget * p)
  229. {
  230. QGroupBox * pGroup = new QGroupBox();
  231. pGroup->setGeometry(0,0,1300,800);
  232. const int TWidth = 1300;
  233. const int nRowDis = 50;
  234. const int nColDis = 200;
  235. const int nIWidth = 95;
  236. const int nIHeight = 30;
  237. int i;
  238. int j;
  239. i=1;j = 0;
  240. int index = 0;
  241. for(auto x : gstrDiffItem)
  242. {
  243. QLabel * pLabel;
  244. QLineEdit * pLineEdit;
  245. pLabel = new QLabel(pGroup);
  246. std::string strname = x;
  247. pLabel->setText(strname.data());
  248. pLineEdit = new QLineEdit(pGroup);
  249. pLabel->setGeometry(10+j*nColDis,i*nRowDis,nIWidth,nIHeight);
  250. pLineEdit->setGeometry(10+j*nColDis+nColDis/2,i*nRowDis,nIWidth,nIHeight);
  251. pLabel->setAlignment(Qt::AlignRight|Qt::AlignCenter);
  252. mpLabelDiff[index] = pLabel;
  253. mpLEDiff[index] = pLineEdit;
  254. j++;
  255. if((j+1)*nColDis>TWidth)
  256. {
  257. j= 0;
  258. i++;
  259. }
  260. index++;
  261. }
  262. QScrollArea * pScroll = new QScrollArea();
  263. pScroll->setWidget(pGroup);
  264. p->addTab(pScroll,"Diff");
  265. }
  266. void MainWindow::resizeEvent(QResizeEvent *event)
  267. {
  268. // qDebug("resize");
  269. QSize sizemain = ui->centralWidget->size();
  270. // qDebug("size x = %d y=%d",sizemain.width(),sizemain.height());
  271. AdjustWPos(sizemain);
  272. }
  273. void MainWindow::AdjustWPos(QSize sizemain)
  274. {
  275. mTabMain->setGeometry(10,10,sizemain.width() - 20,sizemain.height()-10);
  276. }
  277. inline void MainWindow::SetLEView(int nTab, const char *strName, double value, const char * strvalue,const int nType)
  278. {
  279. int i;
  280. QLineEdit * pLE = 0;
  281. int nBase = 0;
  282. if(nType == 3)nBase = mnCountIndexBase;
  283. if(nTab == 0)
  284. {
  285. i = 0;
  286. if(nBase == 0)
  287. {
  288. for(auto x : gstrItem)
  289. {
  290. std::string str = x;
  291. const char * y = str.data();
  292. if(strcmp(str.data(), strName) == 0)
  293. {
  294. pLE = mpLERaw[i+nBase];
  295. break;
  296. }
  297. i++;
  298. }
  299. }
  300. else
  301. {
  302. for(auto x : gstrCount)
  303. {
  304. std::string str = x;
  305. const char * y = str.data();
  306. if(strcmp(str.data(), strName) == 0)
  307. {
  308. pLE = mpLERaw[i+nBase];
  309. break;
  310. }
  311. i++;
  312. }
  313. }
  314. }
  315. if(nTab == 1)
  316. {
  317. i = 0;
  318. if(nBase == 0)
  319. {
  320. for(auto x : gstrItem)
  321. {
  322. std::string str = x;
  323. if(strcmp(str.data(),strName) == 0)
  324. {
  325. pLE = mpLEFusion[i+nBase];
  326. break;
  327. }
  328. i++;
  329. }
  330. }
  331. else
  332. {
  333. for(auto x : gstrCount)
  334. {
  335. std::string str = x;
  336. const char * y = str.data();
  337. if(strcmp(str.data(), strName) == 0)
  338. {
  339. pLE = mpLEFusion[i+nBase];
  340. break;
  341. }
  342. i++;
  343. }
  344. }
  345. }
  346. if(nTab == 2)
  347. {
  348. i = 0;
  349. for(auto x : gstrDiffItem)
  350. {
  351. std::string str = x;
  352. if(strcmp(str.data(), strName) == 0)
  353. {
  354. pLE = mpLEFusion[i];
  355. break;
  356. }
  357. i++;
  358. }
  359. }
  360. if(pLE == 0)
  361. {
  362. return;
  363. }
  364. if(nType == 0)
  365. {
  366. pLE->setText(QString::number(value));
  367. }
  368. if(nType == 1)
  369. {
  370. pLE->setText(QString::number(value,'f',7));
  371. }
  372. if(nType == 2)
  373. {
  374. pLE->setText(strvalue);
  375. }
  376. if(nType == 3)
  377. {
  378. pLE->setText(QString::number(value));
  379. }
  380. }
  381. void MainWindow::UpdateCompView()
  382. {
  383. const int tab = 2;
  384. int i;
  385. for(i=0;i<18;i++)SetLEView(tab,gstrDiffItem[i].data(),gdiff[i]);
  386. }
  387. void MainWindow::UpdateGPSView(const int tab,iv::gps::gpsimu xgpsimu)
  388. {
  389. SetLEView(tab,gstrItem[0].data(),xgpsimu.pitch());
  390. SetLEView(tab,gstrItem[1].data(),xgpsimu.roll());
  391. SetLEView(tab,gstrItem[2].data(),xgpsimu.heading());
  392. SetLEView(tab,gstrItem[3].data(),xgpsimu.lat(),0,1);
  393. SetLEView(tab,gstrItem[4].data(),xgpsimu.lon(),0,1);
  394. SetLEView(tab,gstrItem[5].data(),xgpsimu.height());
  395. SetLEView(tab,gstrItem[6].data(),xgpsimu.vn());
  396. SetLEView(tab,gstrItem[7].data(),xgpsimu.ve());
  397. SetLEView(tab,gstrItem[8].data(),xgpsimu.vd());
  398. SetLEView(tab,gstrItem[9].data(),xgpsimu.ins_state());
  399. SetLEView(tab,gstrItem[10].data(),xgpsimu.rtk_state());
  400. SetLEView(tab,gstrItem[11].data(),xgpsimu.satnum1());
  401. SetLEView(tab,gstrItem[12].data(),xgpsimu.gyro_x());
  402. SetLEView(tab,gstrItem[13].data(),xgpsimu.gyro_y());
  403. SetLEView(tab,gstrItem[14].data(),xgpsimu.gyro_z());
  404. SetLEView(tab,gstrItem[15].data(),xgpsimu.acce_x());
  405. SetLEView(tab,gstrItem[16].data(),xgpsimu.acce_y());
  406. SetLEView(tab,gstrItem[17].data(),xgpsimu.acce_z());
  407. if(fabs(xgpsimu.acce_z()+1.0)>0.1)
  408. {
  409. qDebug("acc is %f gyro z is %f h:%f",xgpsimu.acce_z(),xgpsimu.gyro_z(),
  410. xgpsimu.height());
  411. }
  412. if(fabs(xgpsimu.vd())>0.5)
  413. {
  414. qDebug("vd is %f",xgpsimu.vd());
  415. }
  416. // qDebug("state is %d %d %d",xgpsimu.gps_state().pos_state(),xgpsimu.gps_state().heading_state(),xgpsimu.gps_state().satnum());
  417. // SetLEView(tab,gstrItem[12].data(),xgpsimu.);
  418. }
  419. void MainWindow::CompareData(iv::gps::gpsimu gi, iv::gps::gpsimu gf)
  420. {
  421. gdiff[0] = fabs(gf.pitch() - gi.pitch());
  422. gdiff[1] = fabs(gf.roll() - gi.roll());
  423. gdiff[2] = fabs(gf.heading() - gi.heading());
  424. gdiff[3] = fabs(gf.lat() - gi.lat());
  425. gdiff[4] = fabs(gf.lon() - gi.lon());
  426. gdiff[5] = fabs(gf.height() - gi.height());
  427. gdiff[6] = fabs(gf.vn() - gi.vn());
  428. gdiff[7] = fabs(gf.ve() - gi.ve());
  429. gdiff[8] = fabs(gf.vd() - gi.vd());
  430. gdiffcount++;
  431. gdifftotal[0] += gdiff[3];
  432. gdifftotal[1] += gdiff[4];
  433. gdifftotal[2] += gdiff[5];
  434. gdiff[9] = gdifftotal[0]/gdiffcount;
  435. gdiff[10] = gdifftotal[1]/gdiffcount;
  436. gdiff[11] = gdifftotal[2]/gdiffcount;
  437. int i;
  438. for(i=0;i<6;i++)
  439. if(gdiff[i] > gdiff[12+i])gdiff[12+i]= gdiff[i];
  440. }
  441. void MainWindow::onTimer()
  442. {
  443. static int nLastRaw = 0;
  444. static int nLastFusion = 0;
  445. bool bRawGet = false;
  446. bool bFusionGet = false;
  447. iv::gps::gpsimu rawgpsimu,fusiongpsimu;
  448. if(nLastRaw < gcountRaw[0])
  449. {
  450. mMutexraw.lock();
  451. while(mqueueraw.size() > 0)
  452. {
  453. rawgpsimu = mqueueraw.front();
  454. mqueueraw.pop();
  455. mqueuecpraw.push(rawgpsimu);
  456. bRawGet = true;
  457. }
  458. nLastRaw = gcountRaw[0];
  459. mMutexraw.unlock();
  460. }
  461. if(nLastFusion < gcountFusion[0])
  462. {
  463. mMutexfusion.lock();
  464. while(mqueuefusion.size() > 0)
  465. {
  466. rawgpsimu = mqueuefusion.front();
  467. mqueuefusion.pop();
  468. mqueuecpfusion.push(fusiongpsimu);
  469. bFusionGet = true;
  470. }
  471. nLastFusion = gcountFusion[0];
  472. mMutexfusion.unlock();
  473. }
  474. if(bRawGet)UpdateGPSView(0,rawgpsimu);
  475. // if(bFusionGet)UpdateGPSView(1,fusiongpsimu);
  476. // if(bRawGet && bFusionGet)
  477. // {
  478. // while((mqueuecpfusion.size()>0)&&(mqueuecpraw.size()>0))
  479. // {
  480. // iv::gps::gpsimu gi,fi;
  481. // gi = mqueuecpraw.front();
  482. // fi = mqueuecpfusion.front();
  483. // if(gi.time() == fi.time())
  484. // {
  485. // //Compare
  486. // CompareData(gi,fi);
  487. // mqueuecpfusion.pop();
  488. // mqueuecpraw.pop();
  489. // continue;
  490. // }
  491. // if(gi.time() > fi.time())
  492. // {
  493. // mqueuecpfusion.pop();
  494. // }
  495. // if(gi.time() < fi.time())
  496. // {
  497. // mqueuecpraw.pop();
  498. // }
  499. // }
  500. // }
  501. }