mainwindow.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include "pos_def.h"
  4. #include "remotectrlini.h"
  5. MainWindow * gw;
  6. //#include "QStringLiteral"
  7. #ifdef NVIDIA_AGX
  8. #include "opencv2/imgcodecs/legacy/constants_c.h" //OpenCV4 use this line
  9. #include <opencv2/imgproc/types_c.h> //OpenCV4 use this line
  10. #endif
  11. #include <opencv2/opencv.hpp>
  12. #include <opencv2/core.hpp>
  13. iv::gps::gpsimu ggpsimu;
  14. qint64 gTimeGPSIMUUpdate = 0;
  15. iv::vision::rawpic grawpic[CAMERA_NUM];
  16. qint64 gTimeRawPic[CAMERA_NUM] = {0,0,0,0};
  17. QMutex gMutexPic[CAMERA_NUM];
  18. extern std::string gstrmem_gpsimu;
  19. extern std::string gstrmem_pic[CAMERA_NUM];
  20. extern std::vector<iv::pos_def> gvectorpos;
  21. extern std::string gstryaml_path;
  22. class xodrobj
  23. {
  24. public:
  25. double flatsrc;
  26. double flonsrc;
  27. double fhgdsrc;
  28. double flat;
  29. double flon;
  30. int lane;
  31. };
  32. namespace iv {
  33. struct simpletrace
  34. {
  35. double gps_lat = 0;//纬度
  36. double gps_lng = 0;//经度
  37. double gps_x = 0;
  38. double gps_y = 0;
  39. double gps_z = 0;
  40. double ins_heading_angle = 0; //航向角
  41. };
  42. }
  43. std::vector<iv::simpletrace> gvectorsimplerace;
  44. QMutex gMutexTrace;
  45. qint64 gTimeTrace = 0;
  46. void * gpaframe;
  47. MainWindow::MainWindow(QWidget *parent)
  48. : QMainWindow(parent)
  49. , ui(new Ui::MainWindow)
  50. {
  51. m_translator = new QTranslator(this);
  52. QString strLanguageFile = ":/zh_CN.qm";
  53. if(ServiceRCIni.GetLanguage() == "Chinese")
  54. {
  55. strLanguageFile = ":/zh_CN.qm";
  56. }
  57. else
  58. {
  59. strLanguageFile = ":/en_CN.qm";
  60. }
  61. if (QFile(strLanguageFile).exists())
  62. {
  63. m_translator->load(strLanguageFile);
  64. qApp->installTranslator(m_translator);
  65. }
  66. gpaframe = iv::modulecomm::RegisterSend("h264frame",1000000,1);
  67. gw = this;
  68. ui->setupUi(this);
  69. mstrserverip = ServiceRCIni.GetServerIP();
  70. mstrserverport = ServiceRCIni.GetServerPort();
  71. mstruploadinterval = ServiceRCIni.GetInterval();
  72. mstrVehVIN = ServiceRCIni.GetVIN();
  73. mstrqueryMD5 = ServiceRCIni.GetQueryMD5();
  74. mstrctrlMD5 = ServiceRCIni.GetCtrlMD5();
  75. #ifndef Q_OS_WIN
  76. mpJRT = new JoyReadThread();
  77. mpJRT->start();
  78. #endif
  79. int i;
  80. CreateView();
  81. int nstation = gvectorpos.size();
  82. for(i=0;i<nstation;i++)
  83. {
  84. ui->comboBox_Station->addItem(gvectorpos[i].mstrstationname.data());
  85. }
  86. ui->radioButton_auto->setChecked(true);
  87. mpa = iv::modulecomm::RegisterSend("remotectrl",10000,1);
  88. mpTimerManual = new QTimer(this);
  89. connect(mpTimerManual,SIGNAL(timeout()),this,SLOT(onTimerManual()));
  90. mpTimerRemote = new QTimer(this);
  91. connect(mpTimerRemote,SIGNAL(timeout()),this,SLOT(onTimerRemote()));
  92. mpTimerRemote->start(50);
  93. mpTimerUpdateView = new QTimer(this);
  94. connect(mpTimerUpdateView,SIGNAL(timeout()),this,SLOT(onTimerUpdateView()));
  95. mpTimerUpdateView->start(1000);
  96. QTimer * timer = new QTimer(this);
  97. connect(timer,SIGNAL(timeout()),this,SLOT(onTimerUpdatePic()));
  98. timer->start(1000);
  99. mpadst = iv::modulecomm::RegisterSend("xodrreq",1000,1);
  100. mgrpcpc = new grpcpc(gstryaml_path);
  101. mgrpcpc->setserverip(mstrserverip);
  102. mgrpcpc->setserverport(mstrserverport);
  103. mgrpcpc->setqueryinterval(mstruploadinterval);
  104. mgrpcpc->setVIN(mstrVehVIN);
  105. mgrpcpc->setqueryMD5(mstrqueryMD5);
  106. mgrpcpc->setctrlMD5(mstrctrlMD5);
  107. mgrpcpc->start();
  108. for(i=0;i<NUM_CAM;i++)
  109. {
  110. mpImageCam[i] = new QImage(640, 360, QImage::Format_RGB32);
  111. mbCamUpdate[i] = false;
  112. mph264decode[i] = new ivh264framedecode(mnframewidth,mnframeheight);
  113. mpthreadframe[i] = new std::thread(&MainWindow::threadframe,this,i);
  114. mpthreadpic[i] = new std::thread(&MainWindow::threadpic,this,i);
  115. }
  116. mpthreadinfo = new std::thread(&MainWindow::threadinfo,this);
  117. mstrVIN = mgrpcpc->GetVIN().data();
  118. mstrVIN = " VIN:"+ mstrVIN+" ";
  119. // mppicdlg = new DialogPic(this);
  120. // mppicdlg->setModal(false);
  121. // connect(mppicdlg,SIGNAL(finished(int)),this,SLOT(onCloseDlg()));
  122. // mpbigpicdlg = new DialogBigPic(this);
  123. // mpbigpicdlg->setModal(false);
  124. // connect(mpbigpicdlg,SIGNAL(finished(int)),this,SLOT(onCloseBigDlg()));
  125. QLabel * pLabel = new QLabel();
  126. pLabel->setFixedWidth(600);
  127. pLabel->setText("Latency");
  128. mpLabelLatency = pLabel;
  129. ui->statusbar->addPermanentWidget(pLabel);
  130. ui->horizontalSlider_wheelspeed->setRange(1,30);
  131. connect(this,SIGNAL(CamUpdate(int)),this,SLOT(onCamUpdate(int)));
  132. // mpbaiduapp = new pluginapp(this->winId(),"baidu","baidumapshow","/home/yuchuli/qt/modularization/src/plugin/build-baidumapshow-Debug");
  133. // mppicshow = new pluginapp(this->winId(),"main","plugin_picshow","/home/yuchuli/qt/modularization/src/plugin/build-plugin_picshow-Debug");
  134. // mppicshow->SetAttr("rawpicmsgname",gstrmem_pic[0].data(),gstrmem_pic[0].size());
  135. setWindowTitle(mstrProgName +mstrVIN+ mstrGPSTime + mstrPicTime);
  136. }
  137. MainWindow::~MainWindow()
  138. {
  139. mbThreadrun = false;
  140. int i;
  141. mpthreadinfo->join();
  142. for(i=0;i<NUM_CAM;i++)
  143. {
  144. // mph264decode[i] = new ivh264framedecode(mnframewidth,mnframeheight);
  145. mpthreadframe[i]->join();
  146. mpthreadpic[i]->join();
  147. }
  148. delete ui;
  149. }
  150. void MainWindow::CreateView()
  151. {
  152. // mMapview = new QWebEngineView(ui->centralwidget);
  153. // qDebug((QDir::currentPath()).toLatin1().data());
  154. // mMapview->load(QUrl(QString("file:///%1/%2").arg(QApplication::applicationDirPath()).arg("BaiDuMap.html")));
  155. // mMapview->setGeometry(10,10,800,800);
  156. // mMapview->page()->runJavaScript("theLocation(117.355,39.066);"); //117.355,39.066
  157. mpWheel = new Speed(ui->groupBox_rem);
  158. mpWheel->settitle(QStringLiteral("方向盘"));
  159. mpWheel->setminvalue(550);
  160. mpWheel->setmaxvalue(-550);
  161. mpAcc = new Speed(ui->groupBox_rem);
  162. mpAcc->settitle(QStringLiteral("油门"));
  163. mpAcc->updatevalue(0);
  164. mpAcc->setminvalue(-100);
  165. mpAcc->setmaxvalue(100);
  166. mpBrake = new Speed(ui->groupBox_rem);
  167. mpBrake->settitle(QStringLiteral("刹车"));
  168. mpBrake->updatevalue(0);
  169. mpBrake->setminvalue(0);
  170. mpBrake->setmaxvalue(100);
  171. mmyview = new MyView(ui->centralwidget);
  172. mmyview->setObjectName(QStringLiteral("graphicsView"));
  173. mmyview->setGeometry(QRect(30, 30, 600, 600));
  174. mmyview->setCacheMode(mmyview->CacheBackground);
  175. mmyviewLeft = new MyView(ui->centralwidget);
  176. mmyviewLeft->setObjectName(QStringLiteral("graphicsView"));
  177. mmyviewLeft->setGeometry(QRect(30, 30, 600, 600));
  178. mmyviewLeft->setCacheMode(mmyviewLeft->CacheBackground);
  179. mmyviewRear = new MyView(ui->centralwidget);
  180. mmyviewRear->setObjectName(QStringLiteral("graphicsView"));
  181. mmyviewRear->setGeometry(QRect(30, 30, 600, 600));
  182. mmyviewRear->setCacheMode(mmyviewRear->CacheBackground);
  183. mmyviewRight = new MyView(ui->centralwidget);
  184. mmyviewRight->setObjectName(QStringLiteral("graphicsView"));
  185. mmyviewRight->setGeometry(QRect(30, 30, 600, 600));
  186. mmyviewRight->setCacheMode(mmyviewRight->CacheBackground);
  187. mscene = new QGraphicsScene;
  188. mpsceneImg[0] = mscene;
  189. mpsceneImg[1] = new QGraphicsScene;
  190. mpsceneImg[2] = new QGraphicsScene;
  191. mpsceneImg[3] = new QGraphicsScene;
  192. mpviewImg[0] = mmyview;
  193. mpviewImg[1] = mmyviewRear;
  194. mpviewImg[2] = mmyviewLeft;
  195. mpviewImg[3] = mmyviewRight;
  196. ui->radioButton_Null->setChecked(true);
  197. }
  198. void MainWindow::keyPressEvent(QKeyEvent *event)
  199. {
  200. //按键按下,key值放入容器,如果是长按触发的repeat就不判断
  201. if(!event->isAutoRepeat())
  202. mPressKeys.insert(event->key());
  203. }
  204. void MainWindow::keyReleaseEvent(QKeyEvent *event)
  205. {
  206. if(event->key() == Qt::Key_Escape)
  207. {
  208. showNormal();
  209. }
  210. if(!event->isAutoRepeat())mPressKeys.remove(event->key());
  211. qDebug("key count is %d",mPressKeys.count());
  212. }
  213. void MainWindow::resizeEvent(QResizeEvent *event)
  214. {
  215. (void)event;
  216. QSize sizemain = ui->centralwidget->size();
  217. qDebug("size x = %d y=%d",sizemain.width(),sizemain.height());
  218. // mMapview->setVisible(false);
  219. // mMapview->setGeometry(10,10,sizemain.width()/2,sizemain.height()*3/5);
  220. // mpbaiduapp->SetGeometry(10,30,sizemain.width()/2,sizemain.height()*3/5);
  221. int nMode = 1;
  222. ui->lineEdit_lat->setVisible(false);
  223. ui->lineEdit_lon->setVisible(false);
  224. ui->pushButton_test->setVisible(false);
  225. if(nMode == 0)
  226. {
  227. mmyview->setGeometry(10+sizemain.width()/2+10,10,sizemain.width()/2-30,sizemain.height()*3/5);
  228. int nfrontpos_x = sizemain.width()/6;
  229. int nfrontpos_y = sizemain.height()/3;
  230. int nfrontsize_x = sizemain.width()*2/3;
  231. int nfrontsize_y = sizemain.height() * 2/3;
  232. mmyview->setGeometry(nfrontpos_x,nfrontpos_y,nfrontsize_x,nfrontsize_y);
  233. int nleftpos_x = 0;
  234. int nleftpos_y = 0;
  235. int nleftsize_x = sizemain.width()/3;
  236. int nleftsize_y = sizemain.height()/3;
  237. mmyviewLeft->setGeometry(nleftpos_x,nleftpos_y,nleftsize_x,nleftsize_y);
  238. int nrearpos_x = sizemain.width()/3;
  239. int nrearpos_y = 0;
  240. int nrearsize_x = sizemain.width()/3;
  241. int nrearsize_y = sizemain.height()/3;
  242. mmyviewRear->setGeometry(nrearpos_x,nrearpos_y,nrearsize_x,nrearsize_y);
  243. int nrightpos_x = sizemain.width() * 2/3;
  244. int nrightpos_y = 0;
  245. int nrightsize_x = sizemain.width()/3;
  246. int nrightsize_y = sizemain.height()/3;
  247. mmyviewRight->setGeometry(nrightpos_x,nrightpos_y,nrightsize_x,nrightsize_y);
  248. // mppicshow->SetGeometry(10+sizemain.width()/2+10,10,sizemain.width()/2-30,sizemain.height()*3/5);
  249. // ui->lineEdit_lat->setGeometry(sizemain.width()-100,10,90,30);
  250. // ui->lineEdit_lon->setGeometry(sizemain.width()-100,50,90,30);
  251. // ui->pushButton_test->setGeometry(sizemain.width()-100,90,90,30);
  252. // mpWheel->setGeometry(sizemain.width()/2 + 20,10,200,200);
  253. int grouppos_x = sizemain.width()*5/6;
  254. int grouppos_y = sizemain.height()/3;
  255. int grouppos_width = sizemain.width()*1/6;
  256. int grouppos_height = sizemain.height() * 2/3;
  257. // int speed_width = grouppos_height-40;
  258. // if((speed_width*3 + 150)>grouppos_width)speed_width = (grouppos_width - 150)/3;
  259. int speed_width = grouppos_width;
  260. if(speed_width*3 > (sizemain.height()/2))speed_width = sizemain.height()/6;
  261. mpWheel->setGeometry(0,sizemain.height()/6 ,speed_width,speed_width);
  262. mpBrake->setGeometry(0,sizemain.height()/6 + sizemain.height()/6,speed_width,speed_width);
  263. mpAcc->setGeometry(0 ,sizemain.height()/6 + sizemain.height()/3,speed_width,speed_width);
  264. ui->groupBox_rem->setGeometry(grouppos_x,grouppos_y,grouppos_width,grouppos_height);
  265. int groupmap_x = 0;
  266. int groupmap_y = sizemain.height()*1/3;
  267. int groupmap_width = sizemain.width()/6;
  268. int groupmap_height = sizemain.height()*1/10;
  269. ui->comboBox_Station->setGeometry(10,30,groupmap_width*3/5,30);
  270. ui->pushButton_Go->setGeometry(20 + groupmap_width*3/5,30,groupmap_width*2/5 - 30,30);
  271. ui->groupBox_map->setGeometry(groupmap_x,groupmap_y,groupmap_width,groupmap_height);
  272. int groupgps_x = 0;
  273. int groupgps_y = sizemain.height()/2;
  274. int groupgps_width = sizemain.width()/6;
  275. int groupgps_height = sizemain.height()/2;
  276. ui->groupBox_gps->setGeometry(groupgps_x,groupgps_y,groupgps_width,groupgps_height);
  277. int lablewidth =groupgps_width*3/10;// (groupgps_width-50)*2/10;
  278. int lewidth = groupgps_width*6/10;
  279. int leheight = 26;
  280. int nypos = 40;
  281. ui->label_gpsins->setGeometry(10,nypos,lablewidth,leheight);
  282. ui->lineEdit_gpsins->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  283. nypos = nypos + leheight*11/10;
  284. ui->label_gpsrtk->setGeometry(10,nypos,lablewidth,leheight);
  285. ui->lineEdit_gpsrtk->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  286. nypos = nypos + leheight*11/10;
  287. ui->label_gpslon->setGeometry(10,nypos,lablewidth,leheight);
  288. ui->lineEdit_gpslon->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  289. nypos = nypos + leheight*11/10;
  290. ui->label_gpslat->setGeometry(10,nypos,lablewidth,leheight);
  291. ui->lineEdit_gpslat->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  292. nypos = nypos + leheight*11/10;
  293. ui->label_gpsheading->setGeometry(10,nypos,lablewidth,leheight);
  294. ui->lineEdit_gpsheading->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  295. nypos = nypos + leheight*11/10;
  296. ui->label_gpsheight->setGeometry(10,nypos,lablewidth,leheight);
  297. ui->lineEdit_gpsheight->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  298. nypos = nypos + leheight*11/10;
  299. ui->label_gpsspeed->setGeometry(10,nypos,lablewidth,leheight);
  300. ui->lineEdit_gpsspeed->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  301. nypos = nypos + leheight*11/10;
  302. ui->label_gpssat->setGeometry(10,nypos,lablewidth,leheight);
  303. ui->lineEdit_gpssat->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  304. double fscale = (sizemain.width()*2/3)*1.0/mnframewidth;
  305. double fscale2 = (sizemain.height()*2/3)*1.0/mnframeheight;
  306. if(fscale > fscale2) fscale = fscale2;
  307. fscale = fscale * 0.99;
  308. mmyview->viewscaleto(fscale);
  309. int i;
  310. for(i=1;i<NUM_CAM;i++)
  311. {
  312. fscale = (sizemain.width()*1/3)*1.0/mnframewidth;
  313. fscale2 = (sizemain.height()*1/3)*1.0/mnframeheight;
  314. if(fscale > fscale2) fscale = fscale2;
  315. fscale = fscale * 0.99;
  316. mpviewImg[i]->viewscaleto(fscale);
  317. }
  318. }
  319. if(nMode == 1)
  320. {
  321. int nfrontpos_x = sizemain.width()*2/5;
  322. int nfrontpos_y = 0;
  323. int nfrontsize_x = sizemain.width()*1/5;
  324. int nfrontsize_y = sizemain.height();
  325. mmyview->setGeometry(nfrontpos_x,nfrontpos_y,nfrontsize_x,nfrontsize_y);
  326. int nleftpos_x = 0;
  327. int nleftpos_y = 0;
  328. int nleftsize_x = sizemain.width()*1/5;
  329. int nleftsize_y = sizemain.height();
  330. mmyviewLeft->setGeometry(nleftpos_x,nleftpos_y,nleftsize_x,nleftsize_y);
  331. // int nrearpos_x = sizemain.width()/3;
  332. // int nrearpos_y = 0;
  333. // int nrearsize_x = sizemain.width()/3;
  334. // int nrearsize_y = sizemain.height()/3;
  335. // mmyviewRear->setGeometry(nrearpos_x,nrearpos_y,nrearsize_x,nrearsize_y);
  336. mmyviewRear->setVisible(false);
  337. int nrightpos_x = sizemain.width() * 4/5;
  338. int nrightpos_y = 0;
  339. int nrightsize_x = sizemain.width()*1/5;
  340. int nrightsize_y = sizemain.height();
  341. mmyviewRight->setGeometry(nrightpos_x,nrightpos_y,nrightsize_x,nrightsize_y);
  342. // mppicshow->SetGeometry(10+sizemain.width()/2+10,10,sizemain.width()/2-30,sizemain.height()*3/5);
  343. // ui->lineEdit_lat->setGeometry(sizemain.width()-100,10,90,30);
  344. // ui->lineEdit_lon->setGeometry(sizemain.width()-100,50,90,30);
  345. // ui->pushButton_test->setGeometry(sizemain.width()-100,90,90,30);
  346. // mpWheel->setGeometry(sizemain.width()/2 + 20,10,200,200);
  347. int grouppos_x = sizemain.width()*1/5;
  348. int grouppos_y = sizemain.height()/2;
  349. int grouppos_width = sizemain.width()*1/5;
  350. int grouppos_height = sizemain.height() * 1/2;
  351. // int speed_width = grouppos_height-40;
  352. // if((speed_width*3 + 150)>grouppos_width)speed_width = (grouppos_width - 150)/3;
  353. int speed_width = grouppos_width;
  354. if(speed_width*3 > (sizemain.height()/2))speed_width = sizemain.height()/6;
  355. mpWheel->setGeometry(0,sizemain.height()/6 ,speed_width,speed_width);
  356. mpBrake->setGeometry(0,sizemain.height()/6 + sizemain.height()/6,speed_width,speed_width);
  357. mpAcc->setGeometry(0 ,sizemain.height()/6 + sizemain.height()/3,speed_width,speed_width);
  358. ui->groupBox_rem->setGeometry(grouppos_x,grouppos_y,grouppos_width,grouppos_height);
  359. int groupmap_x = sizemain.width()*1/5;
  360. int groupmap_y = sizemain.height();
  361. int groupmap_width = sizemain.width()/5;
  362. int groupmap_height = sizemain.height();
  363. ui->comboBox_Station->setGeometry(10,30,groupmap_width*3/5,30);
  364. ui->pushButton_Go->setGeometry(20 + groupmap_width*3/5,30,groupmap_width*2/5 - 30,30);
  365. ui->groupBox_map->setGeometry(groupmap_x,groupmap_y,groupmap_width,groupmap_height);
  366. int groupgps_x = sizemain.width()*1/5;
  367. int groupgps_y = sizemain.height()/2;
  368. int groupgps_width = sizemain.width()/5;
  369. int groupgps_height = sizemain.height()/2;
  370. ui->groupBox_gps->setGeometry(groupgps_x,groupgps_y,groupgps_width,groupgps_height);
  371. int lablewidth =groupgps_width*3/10;// (groupgps_width-50)*2/10;
  372. int lewidth = groupgps_width*6/10;
  373. int leheight = 26;
  374. int nypos = 40;
  375. ui->label_gpsins->setGeometry(10,nypos,lablewidth,leheight);
  376. ui->lineEdit_gpsins->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  377. nypos = nypos + leheight*11/10;
  378. ui->label_gpsrtk->setGeometry(10,nypos,lablewidth,leheight);
  379. ui->lineEdit_gpsrtk->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  380. nypos = nypos + leheight*11/10;
  381. ui->label_gpslon->setGeometry(10,nypos,lablewidth,leheight);
  382. ui->lineEdit_gpslon->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  383. nypos = nypos + leheight*11/10;
  384. ui->label_gpslat->setGeometry(10,nypos,lablewidth,leheight);
  385. ui->lineEdit_gpslat->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  386. nypos = nypos + leheight*11/10;
  387. ui->label_gpsheading->setGeometry(10,nypos,lablewidth,leheight);
  388. ui->lineEdit_gpsheading->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  389. nypos = nypos + leheight*11/10;
  390. ui->label_gpsheight->setGeometry(10,nypos,lablewidth,leheight);
  391. ui->lineEdit_gpsheight->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  392. nypos = nypos + leheight*11/10;
  393. ui->label_gpsspeed->setGeometry(10,nypos,lablewidth,leheight);
  394. ui->lineEdit_gpsspeed->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  395. nypos = nypos + leheight*11/10;
  396. ui->label_gpssat->setGeometry(10,nypos,lablewidth,leheight);
  397. ui->lineEdit_gpssat->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  398. double fscale = (sizemain.width()*1/5)*1.0/mnframewidth;
  399. double fscale2 = (sizemain.height()*1/1)*1.0/mnframeheight;
  400. if(fscale > fscale2) fscale = fscale2;
  401. fscale = fscale * 0.99;
  402. mmyview->viewscaleto(fscale);
  403. int i;
  404. for(i=1;i<NUM_CAM;i++)
  405. {
  406. fscale = (sizemain.width()*1/5)*1.0/mnframewidth;
  407. fscale2 = (sizemain.height()*1/1)*1.0/mnframeheight;
  408. if(fscale > fscale2) fscale = fscale2;
  409. fscale = fscale * 0.99;
  410. mpviewImg[i]->viewscaleto(fscale);
  411. }
  412. }
  413. }
  414. void MainWindow::on_pushButton_test_clicked()
  415. {
  416. double flat = ui->lineEdit_lat->text().toDouble();
  417. double flon = ui->lineEdit_lon->text().toDouble();
  418. char strscript[256];
  419. snprintf(strscript,255,"theLocation(%11.7f,%11.7f);",flon,flat);
  420. // mMapview->page()->runJavaScript(strscript);
  421. }
  422. void MainWindow::on_radioButton_manual_clicked()
  423. {
  424. ui->radioButton_manual->setChecked(true);
  425. mPressKeys.clear();
  426. mfAcc = 0;
  427. mfWheel = 0;
  428. mfBrake = 0;
  429. mpWheel->updatevalue(mfWheel);
  430. mpAcc->updatevalue(mfAcc);
  431. mpBrake->updatevalue(mfBrake);
  432. mManualTime.restart();
  433. mnLastTime = mManualTime.elapsed();
  434. mpTimerManual->start(10);
  435. }
  436. void MainWindow::onTimerManual()
  437. {
  438. static qint64 nLastKeepKeyTime = 0;
  439. const qint64 nKeepTime = 3000; //if press c key, 5 seconds. in keep mode.
  440. double fOldWheel = mfWheel;
  441. double fOldAcc = mfAcc;
  442. double fOldBrake = mfBrake;
  443. int timediff = mManualTime.elapsed() - mnLastTime;
  444. mnLastTime = mManualTime.elapsed();
  445. bool bInKeepMode = false;
  446. int nOldShift = mnShift;
  447. #ifndef Q_OS_WIN
  448. if(mpJRT->isOK())
  449. {
  450. mfWheel = mpJRT->GetWheel() * (-100.0)/32768.0;
  451. mfAcc = ((mpJRT->GetAcc()-32767.0)/65535)*(-100.0);
  452. mfBrake = ((mpJRT->GetBrake()-32767.0)/65535)*(-100.0);
  453. if(mfWheel != fOldWheel)mpWheel->updatevalue(mfWheel);
  454. if(mfAcc != fOldAcc)mpAcc->updatevalue(mfAcc);
  455. if(mfBrake != fOldBrake)mpBrake->updatevalue(mfBrake);
  456. int x = mpJRT->GetShift();
  457. if(x > 0)mnShift = 1;
  458. if(x == 0)mnShift = 0;
  459. if(x < 0)mnShift = -1;
  460. if(mnShift != nOldShift)
  461. {
  462. switch (mnShift) {
  463. case 1:
  464. ui->radioButton_Drive->setChecked(true);
  465. break;
  466. case 0:
  467. ui->radioButton_Null->setChecked(true);
  468. break;
  469. case -1:
  470. ui->radioButton_Rear->setChecked(true);
  471. break;
  472. default:
  473. break;
  474. }
  475. }
  476. return;
  477. }
  478. #endif
  479. if(mPressKeys.contains(Qt::Key_C)||(mPressKeys.contains(Qt::Key_A))||(mPressKeys.contains(Qt::Key_D))||(mPressKeys.contains(Qt::Key_W))||(mPressKeys.contains(Qt::Key_S)))
  480. {
  481. nLastKeepKeyTime = QDateTime::currentMSecsSinceEpoch();
  482. }
  483. if(abs(QDateTime::currentMSecsSinceEpoch() - nLastKeepKeyTime) < nKeepTime)
  484. {
  485. bInKeepMode = true;
  486. }
  487. if(mPressKeys.contains(Qt::Key_A)&&(mPressKeys.contains((Qt::Key_D))))
  488. {
  489. mfWheel = mfWheel;
  490. }
  491. else
  492. {
  493. if(mPressKeys.contains(Qt::Key_A))
  494. {
  495. // if(mfWheel<0)mfWheel = 0;
  496. // else
  497. // {
  498. mfWheel = mfWheel + timediff*mfWheelSpeed/1000;
  499. if(mfWheel < -100)mfWheel = -100;
  500. if(mfWheel > 100 )mfWheel = 100;
  501. // }
  502. }
  503. if(mPressKeys.contains(Qt::Key_D))
  504. {
  505. // if(mfWheel>0)mfWheel = 0;
  506. // else
  507. // {
  508. mfWheel = mfWheel - timediff*mfWheelSpeed/1000;
  509. if(mfWheel < -100)mfWheel = -100;
  510. if(mfWheel > 100 )mfWheel = 100;
  511. // }
  512. }
  513. }
  514. if(mPressKeys.contains(Qt::Key_Z))
  515. {
  516. mfWheel = 0;
  517. }
  518. if(!mPressKeys.contains(Qt::Key_A)&&(!mPressKeys.contains((Qt::Key_D)))&&(bInKeepMode == false))
  519. {
  520. if(mfWheel != 0)
  521. {
  522. if(mfWheel > 0)mfWheel = mfWheel - timediff*mfWheelAutoDownSpeed/1000;
  523. else mfWheel = mfWheel + timediff*mfWheelAutoDownSpeed/1000;
  524. if(fabs(mfWheel)< 10)mfWheel =0;
  525. }
  526. }
  527. if(mnVehMode == 2) //ACC BRAKE
  528. {
  529. if(mPressKeys.contains(Qt::Key_W)&&(mPressKeys.contains((Qt::Key_S))))
  530. {
  531. mfAcc = 0;
  532. mfBrake = mfBrake + timediff*mfBrakeSpeed/1000;
  533. if(mfBrake<0)mfBrake = 0;
  534. if(mfBrake > 100)mfBrake = 100;
  535. }
  536. else
  537. {
  538. if(mPressKeys.contains(Qt::Key_W))
  539. {
  540. mfBrake = 0;
  541. mfAcc = mfAcc + timediff*mfAccSpeed/1000;
  542. if(mfAcc<0)mfAcc = 0;
  543. if(mfAcc > 100)mfAcc = 100;
  544. }
  545. if(mPressKeys.contains(Qt::Key_S))
  546. {
  547. mfAcc = 0;
  548. mfBrake = mfBrake + timediff*mfBrakeSpeed/1000;
  549. if(mfBrake<0)mfBrake = 0;
  550. if(mfBrake > 100)mfBrake = 100;
  551. }
  552. }
  553. }
  554. else //Speed Mode
  555. {
  556. if(mPressKeys.contains(Qt::Key_W)&&(mPressKeys.contains((Qt::Key_S))))
  557. {
  558. if(mfAcc > 0)
  559. {
  560. mfAcc = mfAcc - 10*timediff*mfAccSpeed/1000;
  561. if(mfAcc<0)mfAcc = 0;
  562. }
  563. else
  564. {
  565. mfBrake = mfBrake + timediff*mfBrakeSpeed/1000;
  566. if(mfBrake<0)mfBrake = 0;
  567. if(mfBrake > 100)mfBrake = 100;
  568. }
  569. }
  570. else
  571. {
  572. if(mPressKeys.contains(Qt::Key_W))
  573. {
  574. mfBrake = 0;
  575. mfAcc = mfAcc + timediff*mfAccSpeed/1000;
  576. if(mfAcc<0)mfAcc = 0;
  577. if(mfAcc > 100)mfAcc = 100;
  578. }
  579. if(mPressKeys.contains(Qt::Key_S))
  580. {
  581. if(mfAcc > 0)
  582. {
  583. mfAcc = mfAcc - 10*timediff*mfAccSpeed/1000;
  584. if(mfAcc<0)mfAcc = 0;
  585. }
  586. else
  587. {
  588. mfBrake = mfBrake + timediff*mfBrakeSpeed/1000;
  589. if(mfBrake<0)mfBrake = 0;
  590. if(mfBrake > 100)mfBrake = 100;
  591. }
  592. }
  593. }
  594. }
  595. if(!mPressKeys.contains(Qt::Key_W)&&(!mPressKeys.contains((Qt::Key_S)))&&(bInKeepMode == false))
  596. {
  597. if(mfBrake != 0)
  598. {
  599. // mfBrake = mfBrake - timediff*mfBrakeAutoDownSpeed/1000;
  600. // if(mfBrake<0)mfBrake = 0;
  601. // if(mfBrake > 100)mfBrake = 100;
  602. }
  603. if(mfAcc != 0)
  604. {
  605. mfAcc = mfAcc - timediff*mfAccAutoDownSpeed/1000;
  606. if(mfAcc<0)mfAcc = 0;
  607. if(mfAcc > 100)mfAcc = 100;
  608. }
  609. }
  610. if(mfWheel != fOldWheel)mpWheel->updatevalue(mfWheel*5.5);
  611. if(mfAcc != fOldAcc)mpAcc->updatevalue(mfAcc);
  612. if(mfBrake != fOldBrake)mpBrake->updatevalue(mfBrake);
  613. }
  614. void MainWindow::on_radioButton_auto_clicked()
  615. {
  616. ui->radioButton_auto->setChecked(true);
  617. mPressKeys.clear();
  618. mpTimerManual->stop();
  619. }
  620. void MainWindow::onTimerRemote()
  621. {
  622. if(ui->radioButton_auto->isChecked())
  623. {
  624. mremotectrl.set_ntype(iv::remotectrl_CtrlType_AUTO);
  625. // mfAcc = 0;
  626. // mfBrake = 0;
  627. // mfWheel =0;
  628. // mpWheel->updatevalue(mfWheel);
  629. // mpAcc->updatevalue(mfAcc);
  630. // mpBrake->updatevalue(mfBrake);
  631. }
  632. else
  633. {
  634. mremotectrl.set_ntype(iv::remotectrl_CtrlType_REMOTE);
  635. }
  636. mremotectrl.set_acc(mfAcc);
  637. mremotectrl.set_brake(mfBrake);
  638. mremotectrl.set_wheel(mfWheel);
  639. mremotectrl.set_shift(mnShift);
  640. int nsersize = mremotectrl.ByteSize();
  641. char * strbuf = new char[nsersize];
  642. if(mremotectrl.SerializeToArray(strbuf,nsersize))
  643. {
  644. mgrpcpc->SetCtrlMsg("remotectrl",strbuf,nsersize);
  645. // iv::modulecomm::ModuleSendMsg(mpa,strbuf,nsersize);
  646. }
  647. delete strbuf;
  648. }
  649. void MainWindow::onTimerUpdatePic()
  650. {
  651. static qint64 time_pic = 0;
  652. static qint64 time_trace = 0;
  653. static int pos = 0;
  654. static std::vector<iv::simpletrace> xvectorsimpletrace;
  655. if(gTimeTrace != time_trace)
  656. {
  657. time_trace = gTimeTrace;
  658. gMutexTrace.lock();
  659. xvectorsimpletrace = gvectorsimplerace;
  660. gMutexTrace.unlock();
  661. pos = 0;
  662. if(xvectorsimpletrace.size()> 0)
  663. {
  664. QJsonArray num_json,num2_json; //声明QJsonArray
  665. QJsonDocument num_document,num2_document; //将QJsonArray改为QJsonDocument类
  666. QByteArray num_byteArray,num2_byteArray; //
  667. int i=0;
  668. for(i=0;i<xvectorsimpletrace.size();i++) //将数组传入压入num_json
  669. {
  670. num_json.append(xvectorsimpletrace[i].gps_lng);
  671. num2_json.append(xvectorsimpletrace[i].gps_lat);
  672. }
  673. num_document.setArray(num_json);
  674. num2_document.setArray(num2_json);
  675. num_byteArray = num_document.toJson(QJsonDocument::Compact);
  676. num2_byteArray = num2_document.toJson(QJsonDocument::Compact);
  677. QString numJson(num_byteArray); //再转为QString
  678. QString num2Json(num2_byteArray); //再转为QString
  679. QString cmd = QString("settrace(\"%1\",\"%2\")").arg(numJson).arg(num2Json);
  680. // mMapview->page()->runJavaScript(cmd);
  681. }
  682. }
  683. // if(pos<xvectorsimpletrace.size())
  684. // {
  685. // if(pos == 0)
  686. // {
  687. // mMapview->page()->runJavaScript("clear()");
  688. // }
  689. // char strscript[256];
  690. // snprintf(strscript,255,"mapLocation(%11.7f,%11.7f);",xvectorsimpletrace[pos].gps_lng,xvectorsimpletrace[pos].gps_lat);
  691. // mMapview->page()->runJavaScript(strscript);
  692. // pos++;
  693. // }
  694. }
  695. void MainWindow::onTimerUpdateView()
  696. {
  697. static qint64 time_gps = 0;
  698. unsigned int i;
  699. char strlatency[1000];
  700. char strtem[100];
  701. snprintf(strlatency,1000,"Latency(Up|FrameRate|Down): ");
  702. snprintf(strtem,100,"FT(%d|%d|%d) ",mgrpcpc->GetPicLatency(0),mgrpcpc->GetFrameRate(0),mgrpcpc->GetPicDownLatency(0));strncat(strlatency,strtem,1000);
  703. snprintf(strtem,100,"RR(%d|%d|%d) ",mgrpcpc->GetPicLatency(1),mgrpcpc->GetFrameRate(1),mgrpcpc->GetPicDownLatency(1));strncat(strlatency,strtem,1000);
  704. snprintf(strtem,100,"LT(%d|%d|%d) ",mgrpcpc->GetPicLatency(2),mgrpcpc->GetFrameRate(2),mgrpcpc->GetPicDownLatency(2));strncat(strlatency,strtem,1000);
  705. snprintf(strtem,100,"RT(%d|%d|%d) ",mgrpcpc->GetPicLatency(3),mgrpcpc->GetFrameRate(3),mgrpcpc->GetPicDownLatency(3));strncat(strlatency,strtem,1000);
  706. mpLabelLatency->setText(strlatency);
  707. if(gTimeGPSIMUUpdate != time_gps)
  708. {
  709. time_gps = gTimeGPSIMUUpdate;
  710. char strscript[256];
  711. snprintf(strscript,255,"theLocation(%11.7f,%11.7f,%11.3f);",ggpsimu.lon(),ggpsimu.lat(),ggpsimu.heading());
  712. // mMapview->page()->runJavaScript(strscript);
  713. iv::gps::gpsimu xgpsimu;
  714. xgpsimu.CopyFrom(ggpsimu);
  715. ui->lineEdit_gpsins->setText(QString::number(xgpsimu.ins_state()));
  716. ui->lineEdit_gpsrtk->setText(QString::number(xgpsimu.rtk_state()));
  717. ui->lineEdit_gpslon->setText(QString::number(xgpsimu.lon(),'f',7));
  718. ui->lineEdit_gpslat->setText(QString::number(xgpsimu.lat(),'f',7));
  719. ui->lineEdit_gpsheading->setText(QString::number(xgpsimu.heading(),'f',2));
  720. ui->lineEdit_gpsheight->setText(QString::number(xgpsimu.height(),'f',2));
  721. ui->lineEdit_gpsspeed->setText(QString::number(xgpsimu.speed(),'f',2));
  722. ui->lineEdit_gpssat->setText(QString::number(xgpsimu.satnum1()));
  723. mstrGPSTime = QDateTime::fromMSecsSinceEpoch(xgpsimu.msgtime()).toString("GPS: yyyy-MM-dd hh:mm:ss ");
  724. setWindowTitle(mstrProgName + mstrVIN + mstrGPSTime + mstrPicTime);
  725. }
  726. }
  727. void MainWindow::onCamUpdate(int ncampos, QImage image)
  728. {
  729. int i = ncampos;
  730. // ui->label_pic->setPixmap(QPixmap::fromImage(image));
  731. mpsceneImg[i]->clear();
  732. // mpsceneImg[i]->addPixmap(QPixmap::fromImage(image));
  733. mpsceneImg[i]->addPixmap(QPixmap::fromImage(image));
  734. mpviewImg[i]->setScene(mpsceneImg[i]);
  735. mpviewImg[i]->show();
  736. }
  737. void MainWindow::paintEvent(QPaintEvent *)
  738. {
  739. int i;
  740. QTime xTime;
  741. xTime;
  742. xTime.start();
  743. int nupdate = 0;
  744. for(i=0;i<NUM_CAM;i++)
  745. {
  746. // continue;
  747. if(mbCamUpdate[i])
  748. {
  749. nupdate++;
  750. // xTime.start();
  751. // std::cout<<" copy image. "<<std::endl;
  752. mMutexCam[i].lock();
  753. // QImage image = mpImageCam[i]->copy();
  754. mbCamUpdate[i] = false;
  755. // QImage image = mpPicView->GetImage();
  756. mpsceneImg[i]->clear();
  757. // mpsceneImg[i]->addPixmap(QPixmap::fromImage(image));
  758. mpsceneImg[i]->addPixmap(QPixmap::fromImage(*mpImageCam[i]));
  759. mpviewImg[i]->setScene(mpsceneImg[i]);
  760. mpviewImg[i]->show();
  761. mMutexCam[i].unlock();
  762. // std::cout<<" update a image use. "<<xTime.elapsed()<<std::endl;
  763. }
  764. }
  765. // std::cout<<" time upadate time: "<<xTime.elapsed()<<" update cout:"<<nupdate<<std::endl;
  766. }
  767. void MainWindow::on_pushButton_Go_clicked()
  768. {
  769. if(ui->comboBox_Station->currentIndex() < 0)return;
  770. int index = ui->comboBox_Station->currentIndex();
  771. if(index<0 || index>= gvectorpos.size())
  772. {
  773. std::cout<<"out range."<<std::endl;
  774. return;
  775. }
  776. iv::pos_def xpos = gvectorpos[index];
  777. double lon,lat;
  778. lon = xpos.mflon;
  779. lat = xpos.mflat;
  780. xodrobj xo;
  781. xo.flon = lon;
  782. xo.flat = lat;
  783. xo.lane = 3;
  784. mgrpcpc->SetCtrlMsg("xodrreq",(char *)&xo,sizeof(xodrobj));
  785. // iv::modulecomm::ModuleSendMsg(mpadst,(char *)&xo,sizeof(xodrobj));
  786. }
  787. void MainWindow::on_comboBox_Station_currentIndexChanged(int index)
  788. {
  789. if(index<0 || index>= gvectorpos.size())
  790. {
  791. std::cout<<"out range."<<std::endl;
  792. return;
  793. }
  794. iv::pos_def xpos = gvectorpos[index];
  795. char strscript[256];
  796. snprintf(strscript,255,"objLocation(%11.7f,%11.7f);",xpos.mflon,xpos.mflat);
  797. // mMapview->page()->runJavaScript(strscript);
  798. }
  799. void MainWindow::on_checkBox_Drive_stateChanged(int arg1)
  800. {
  801. }
  802. void MainWindow::on_checkBox_Drive_clicked()
  803. {
  804. }
  805. void MainWindow::on_checkBox_Null_clicked()
  806. {
  807. }
  808. void MainWindow::on_checkBox_Rear_clicked()
  809. {
  810. }
  811. void MainWindow::on_radioButton_Drive_clicked()
  812. {
  813. mnShift = 1;
  814. // on_radioButton_picfront_clicked();
  815. }
  816. void MainWindow::on_radioButton_Null_clicked()
  817. {
  818. mnShift = 0;
  819. }
  820. void MainWindow::onCloseDlg()
  821. {
  822. qDebug("cloase");
  823. }
  824. void MainWindow::on_checkBox_clicked()
  825. {
  826. }
  827. void MainWindow::saveavi(int index)
  828. {
  829. (void)index;
  830. }
  831. void MainWindow::onCloseBigDlg()
  832. {
  833. }
  834. void MainWindow::on_actionSet_Query_Pass_triggered()
  835. {
  836. DialogSetPassWord xdlg(DialogSetPassWord_Type::QUERY,mstrqueryMD5,this);
  837. if(xdlg.exec() == xdlg.Accepted)
  838. {
  839. mgrpcpc->setqueryMD5(ServiceRCIni.GetQueryMD5());
  840. mstrqueryMD5 = ServiceRCIni.GetQueryMD5();
  841. }
  842. }
  843. void MainWindow::on_actionSetting_triggered()
  844. {
  845. DialogSetting xdlg(this);
  846. if(xdlg.exec() == QDialog::Accepted)
  847. {
  848. mgrpcpc->setVIN(ServiceRCIni.GetVIN());
  849. mstrVehVIN = ServiceRCIni.GetVIN();
  850. }
  851. }
  852. void MainWindow::on_actionSet_Ctrl_Pass_triggered()
  853. {
  854. DialogSetPassWord xdlg(DialogSetPassWord_Type::CTRL,mstrctrlMD5,this);
  855. if(xdlg.exec() == xdlg.Accepted)
  856. {
  857. mgrpcpc->setctrlMD5(ServiceRCIni.GetCtrlMD5());
  858. mstrctrlMD5 = ServiceRCIni.GetCtrlMD5();
  859. }
  860. }
  861. void MainWindow::threadinfo()
  862. {
  863. int nrtn;
  864. iv::cloud::cloudmsg xcloudmsg;
  865. while(mbThreadrun)
  866. {
  867. nrtn = mgrpcpc->GetQueryMsg(xcloudmsg,1000);
  868. if(nrtn == 1)
  869. {
  870. int i;
  871. for(i=0;i<xcloudmsg.xclouddata_size();i++)
  872. {
  873. iv::cloud::cloudunit * punit = xcloudmsg.mutable_xclouddata(i);
  874. if(punit->msgname() == "hcp2_gpsimu")
  875. {
  876. iv::gps::gpsimu xgpsimu;
  877. if(!xgpsimu.ParseFromArray(punit->data().data(),punit->data().size()))
  878. {
  879. std::cout<<"ListenRaw Parse error."<<std::endl;
  880. continue;
  881. }
  882. ggpsimu.CopyFrom(xgpsimu);
  883. gTimeGPSIMUUpdate = QDateTime::currentMSecsSinceEpoch();
  884. }
  885. }
  886. // std::cout<<" receive info msg. "<<std::endl;
  887. }
  888. }
  889. }
  890. void MainWindow::threadframe(int ncamppos)
  891. {
  892. iv::h264rawframedata xframe;
  893. while(mbThreadrun)
  894. {
  895. // std::this_thread::sleep_for(std::chrono::milliseconds(100));
  896. // continue;
  897. int nrtn;
  898. nrtn = mgrpcpc->Consumeh264frame(ncamppos,xframe,10);
  899. if(nrtn == 1)
  900. {
  901. // std::cout<<"recv a frame."<<std::endl;
  902. iv::rawframedata xrawframe;
  903. xrawframe.mpstr_ptr = xframe.mpstr_ptr;
  904. xrawframe.ndatasize = xframe.mdatasize;
  905. mph264decode[ncamppos]->addframedata(xrawframe);
  906. }
  907. }
  908. }
  909. void MainWindow::threadpic(int ncampos)
  910. {
  911. while(mbThreadrun)
  912. {
  913. int nindex = mph264decode[ncampos]->GetUpdatedIndex(10);
  914. if(nindex<0)continue;
  915. // std::cout<<" recv a yuv."<<std::endl;
  916. iv::framedecodebuf * pbuf = mph264decode[ncampos]->LockReadBuff(nindex);
  917. int cy = pbuf->frameheight;
  918. int cx = pbuf->framewidth;
  919. cv::Mat rgbImg(cy, cx,CV_8UC3);
  920. #ifndef USE_QSV
  921. cv::cvtColor(pbuf->myuvImg, rgbImg, CV_YUV2RGB_I420);
  922. #endif
  923. #ifdef USE_QSV
  924. cv::cvtColor(pbuf->myuvImg, rgbImg, CV_YUV2RGB_NV12);
  925. #endif
  926. mph264decode[ncampos]->UnlockReadBuff(nindex);
  927. QImage image2 = QImage((uchar*)(rgbImg.data), rgbImg.cols, rgbImg.rows, QImage::Format_RGB888);
  928. mMutexCam[ncampos].lock();
  929. // emit CamUpdate(ncampos,image2);
  930. *mpImageCam[ncampos] = image2.copy();
  931. mbCamUpdate[ncampos] = true;
  932. mMutexCam[ncampos].unlock();
  933. emit CamUpdate(ncampos);
  934. // cv::cvtColor(rgbImg, rgbImg, CV_BGR2RGB);
  935. // QImage image2 = QImage((uchar*)(rgbImg.data), rgbImg.cols, rgbImg.rows, QImage::Format_RGB888);
  936. }
  937. }
  938. void MainWindow::onCamUpdate(int ncampos)
  939. {
  940. (void)ncampos;
  941. static int64_t nlastupdate =0;
  942. int64_t nnow = std::chrono::system_clock::now().time_since_epoch().count()/1000000;
  943. if(abs(nnow - nlastupdate)>30)
  944. {
  945. nlastupdate = std::chrono::system_clock::now().time_since_epoch().count()/1000000;
  946. update();
  947. }
  948. }
  949. void MainWindow::on_actionFullScreem_triggered()
  950. {
  951. showFullScreen();
  952. }
  953. void MainWindow::on_actionNormal_triggered()
  954. {
  955. showNormal();
  956. }
  957. void MainWindow::on_horizontalSlider_wheelspeed_sliderMoved(int position)
  958. {
  959. (void)position;
  960. mfWheelSpeed = mfWheelBaseSpeed * ui->horizontalSlider_wheelspeed->value();
  961. }
  962. void MainWindow::on_horizontalSlider_wheelspeed_valueChanged(int value)
  963. {
  964. (void)value;
  965. mfWheelSpeed = mfWheelBaseSpeed * ui->horizontalSlider_wheelspeed->value();
  966. }