mainwindow.cpp 40 KB

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