mainwindow.cpp 15 KB

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