mainwindow.cpp 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include "pos_def.h"
  4. MainWindow * gw;
  5. //#include "QStringLiteral"
  6. #ifdef NVIDIA_AGX
  7. #include "opencv2/imgcodecs/legacy/constants_c.h" //OpenCV4 use this line
  8. #include <opencv2/imgproc/types_c.h> //OpenCV4 use this line
  9. #endif
  10. #include <opencv2/opencv.hpp>
  11. #include <opencv2/core.hpp>
  12. iv::gps::gpsimu ggpsimu;
  13. qint64 gTimeGPSIMUUpdate = 0;
  14. iv::vision::rawpic grawpic[CAMERA_NUM];
  15. qint64 gTimeRawPic[CAMERA_NUM] = {0,0,0,0};
  16. QMutex gMutexPic[CAMERA_NUM];
  17. extern std::string gstrmem_gpsimu;
  18. extern std::string gstrmem_pic[CAMERA_NUM];
  19. extern std::vector<iv::pos_def> gvectorpos;
  20. extern std::string gstryaml_path;
  21. class xodrobj
  22. {
  23. public:
  24. double flatsrc;
  25. double flonsrc;
  26. double fhgdsrc;
  27. double flat;
  28. double flon;
  29. int lane;
  30. };
  31. namespace iv {
  32. struct simpletrace
  33. {
  34. double gps_lat = 0;//纬度
  35. double gps_lng = 0;//经度
  36. double gps_x = 0;
  37. double gps_y = 0;
  38. double gps_z = 0;
  39. double ins_heading_angle = 0; //航向角
  40. };
  41. }
  42. std::vector<iv::simpletrace> gvectorsimplerace;
  43. QMutex gMutexTrace;
  44. qint64 gTimeTrace = 0;
  45. void Listenpic(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  46. {
  47. if(nSize<1000)return;
  48. iv::vision::rawpic pic;
  49. if(false == pic.ParseFromArray(strdata,nSize))
  50. {
  51. std::cout<<"picview Listenpic fail."<<std::endl;
  52. return;
  53. }
  54. int indexpic = -1;
  55. for(int i =0;i<CAMERA_NUM;i++)
  56. {
  57. if(strncmp(strmemname,gstrmem_pic[i].data(),256) == 0)
  58. {
  59. indexpic = i;
  60. break;
  61. }
  62. }
  63. if(indexpic >= 0)
  64. {
  65. gMutexPic[indexpic].lock();
  66. grawpic[indexpic].CopyFrom(pic);
  67. gTimeRawPic[indexpic] = QDateTime::currentMSecsSinceEpoch();
  68. gMutexPic[indexpic].unlock();
  69. gw->saveavi(indexpic);
  70. }
  71. }
  72. void Listensimpletrace(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  73. {
  74. int npoint = nSize/sizeof(iv::simpletrace);
  75. if(npoint < 1)
  76. {
  77. std::cout<<"simple trace is very smalll"<<std::endl;
  78. return;
  79. }
  80. gMutexTrace.lock();
  81. gvectorsimplerace.clear();
  82. gvectorsimplerace.resize(npoint);
  83. memcpy(gvectorsimplerace.data(),strdata,npoint*sizeof(iv::simpletrace));
  84. gTimeTrace = QDateTime::currentMSecsSinceEpoch();
  85. gMutexTrace.unlock();
  86. }
  87. void Listengpsimu(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  88. {
  89. // ggpsimu->UpdateGPSIMU(strdata,nSize);
  90. iv::gps::gpsimu xgpsimu;
  91. if(!xgpsimu.ParseFromArray(strdata,nSize))
  92. {
  93. std::cout<<"ListenRaw Parse error."<<std::endl;
  94. }
  95. ggpsimu.CopyFrom(xgpsimu);
  96. gTimeGPSIMUUpdate = QDateTime::currentMSecsSinceEpoch();
  97. }
  98. MainWindow::MainWindow(QWidget *parent)
  99. : QMainWindow(parent)
  100. , ui(new Ui::MainWindow)
  101. {
  102. gw = this;
  103. ui->setupUi(this);
  104. // int * pax = 0;
  105. // *pax = 1;
  106. mpJRT = new JoyReadThread();
  107. mpJRT->start();
  108. void * pa = iv::modulecomm::RegisterRecv(gstrmem_gpsimu.data(),Listengpsimu);
  109. int i;
  110. for(i=0;i<CAMERA_NUM;i++)
  111. pa = iv::modulecomm::RegisterRecv(gstrmem_pic[i].data(),Listenpic);
  112. CreateView();
  113. mpPicView = new IVPicView();
  114. mpPicView->start();
  115. int nstation = gvectorpos.size();
  116. for(i=0;i<nstation;i++)
  117. {
  118. ui->comboBox_Station->addItem(gvectorpos[i].mstrstationname.data());
  119. }
  120. ui->radioButton_auto->setChecked(true);
  121. mpa = iv::modulecomm::RegisterSend("remotectrl",10000,1);
  122. mpTimerManual = new QTimer(this);
  123. connect(mpTimerManual,SIGNAL(timeout()),this,SLOT(onTimerManual()));
  124. mpTimerRemote = new QTimer(this);
  125. connect(mpTimerRemote,SIGNAL(timeout()),this,SLOT(onTimerRemote()));
  126. mpTimerRemote->start(10);
  127. mpTimerUpdateView = new QTimer(this);
  128. connect(mpTimerUpdateView,SIGNAL(timeout()),this,SLOT(onTimerUpdateView()));
  129. mpTimerUpdateView->start(1000);
  130. QTimer * timer = new QTimer(this);
  131. connect(timer,SIGNAL(timeout()),this,SLOT(onTimerUpdatePic()));
  132. timer->start(10);
  133. mpadst = iv::modulecomm::RegisterSend("xodrreq",1000,1);
  134. mpasimpletrace = iv::modulecomm::RegisterRecv("simpletrace",Listensimpletrace);
  135. mgrpcpc = new grpcpc(gstryaml_path);
  136. mgrpcpc->start();
  137. mstrVIN = mgrpcpc->GetVIN().data();
  138. mstrVIN = " VIN:"+ mstrVIN+" ";
  139. mpPicSave[0] = new ivpicsave("./","front",mstrVIN.toStdString());
  140. mpPicSave[1] = new ivpicsave("./","rear",mstrVIN.toStdString());
  141. mpPicSave[2] = new ivpicsave("./","left",mstrVIN.toStdString());
  142. mpPicSave[3] = new ivpicsave("./","right",mstrVIN.toStdString());
  143. for(i=0;i<4;i++)
  144. {
  145. mpPicSave[i]->start();
  146. }
  147. mppicdlg = new DialogPic(this);
  148. mppicdlg->setModal(false);
  149. connect(mppicdlg,SIGNAL(finished(int)),this,SLOT(onCloseDlg()));
  150. mpbigpicdlg = new DialogBigPic(this);
  151. mpbigpicdlg->setModal(false);
  152. connect(mpbigpicdlg,SIGNAL(finished(int)),this,SLOT(onCloseBigDlg()));
  153. mpProgLatency = new QProgressBar();
  154. ui->statusbar->addPermanentWidget(mpProgLatency);
  155. QLabel * pLabel = new QLabel();
  156. pLabel->setFixedWidth(150);
  157. pLabel->setText("Latency");
  158. mpLabelLatency = pLabel;
  159. ui->statusbar->addPermanentWidget(pLabel);
  160. mpProgLatency->setRange(0,500);
  161. mpProgLatency->setValue(0);
  162. mpProgLatency->setTextVisible(false);
  163. mpProgLatency->setFixedWidth(200);
  164. mpProgLatency->setStyleSheet("QProgressBar{background:white} QProgressBar:chunk{background:green}");
  165. mpProgServerLatency = new QProgressBar();
  166. ui->statusbar->addPermanentWidget(mpProgServerLatency);
  167. pLabel = new QLabel();
  168. pLabel->setFixedWidth(150);
  169. pLabel->setText("Server Latency");
  170. mpLabelServerLatency = pLabel;
  171. ui->statusbar->addPermanentWidget(pLabel);
  172. mpProgServerLatency->setRange(0,500);
  173. mpProgServerLatency->setValue(0);
  174. mpProgServerLatency->setTextVisible(false);
  175. mpProgServerLatency->setFixedWidth(200);
  176. mpProgServerLatency->setStyleSheet("QProgressBar{background:white} QProgressBar:chunk{background:green}");
  177. // mpProgLatency->setGeometry(0,0,300,30);
  178. pLabel = new QLabel();
  179. pLabel->setText(" ");
  180. pLabel->setFixedWidth(50);
  181. ui->statusbar->addPermanentWidget(pLabel);
  182. pLabel = new QLabel();
  183. pLabel->setText("Connecting to server....");
  184. pLabel->setFixedWidth(200);
  185. ui->statusbar->addPermanentWidget(pLabel);
  186. mpLabelState = pLabel;
  187. mpLabelState->setStyleSheet("QLabel{color: red}");
  188. setWindowTitle(mstrProgName +mstrVIN+ mstrGPSTime + mstrPicTime);
  189. }
  190. MainWindow::~MainWindow()
  191. {
  192. delete ui;
  193. }
  194. void MainWindow::CreateView()
  195. {
  196. mMapview = new QWebEngineView(ui->centralwidget);
  197. // qDebug((QDir::currentPath()).toLatin1().data());
  198. mMapview->load(QUrl(QString("file:///%1/%2").arg(QApplication::applicationDirPath()).arg("BaiDuMap.html")));
  199. mMapview->setGeometry(10,10,800,800);
  200. // mMapview->page()->runJavaScript("theLocation(117.355,39.066);"); //117.355,39.066
  201. mpWheel = new Speed(ui->groupBox_rem);
  202. mpWheel->settitle(QStringLiteral("方向盘"));
  203. mpAcc = new Speed(ui->groupBox_rem);
  204. mpAcc->settitle(QStringLiteral("油门"));
  205. mpAcc->updatevalue(0);
  206. mpAcc->setminvalue(0);
  207. mpAcc->setmaxvalue(100);
  208. mpBrake = new Speed(ui->groupBox_rem);
  209. mpBrake->settitle(QStringLiteral("刹车"));
  210. mpBrake->updatevalue(0);
  211. mpBrake->setminvalue(0);
  212. mpBrake->setmaxvalue(100);
  213. mmyview = new MyView(ui->centralwidget);
  214. mmyview->setObjectName(QStringLiteral("graphicsView"));
  215. mmyview->setGeometry(QRect(30, 30, 600, 600));
  216. mmyview->setCacheMode(mmyview->CacheBackground);
  217. mscene = new QGraphicsScene;
  218. ui->radioButton_Null->setChecked(true);
  219. ui->radioButton_picfront->setChecked(true);
  220. }
  221. void MainWindow::keyPressEvent(QKeyEvent *event)
  222. {
  223. //按键按下,key值放入容器,如果是长按触发的repeat就不判断
  224. if(!event->isAutoRepeat())
  225. mPressKeys.insert(event->key());
  226. }
  227. void MainWindow::keyReleaseEvent(QKeyEvent *event)
  228. {
  229. if(!event->isAutoRepeat())mPressKeys.remove(event->key());
  230. qDebug("key count is %d",mPressKeys.count());
  231. }
  232. void MainWindow::resizeEvent(QResizeEvent *event)
  233. {
  234. QSize sizemain = ui->centralwidget->size();
  235. qDebug("size x = %d y=%d",sizemain.width(),sizemain.height());
  236. mMapview->setGeometry(10,10,sizemain.width()/2,sizemain.height()*3/5);
  237. mmyview->setGeometry(10+sizemain.width()/2+10,10,sizemain.width()/2-30,sizemain.height()*3/5);
  238. ui->lineEdit_lat->setGeometry(sizemain.width()-100,10,90,30);
  239. ui->lineEdit_lon->setGeometry(sizemain.width()-100,50,90,30);
  240. ui->pushButton_test->setGeometry(sizemain.width()-100,90,90,30);
  241. // mpWheel->setGeometry(sizemain.width()/2 + 20,10,200,200);
  242. int grouppos_x = 10;
  243. int grouppos_y = 20 + sizemain.height() *3/5;
  244. int grouppos_width = sizemain.width()*6/10;
  245. int grouppos_height = sizemain.height()*2/5 - 20;
  246. int speed_width = grouppos_height-40;
  247. if((speed_width*3 + 150)>grouppos_width)speed_width = (grouppos_width - 150)/3;
  248. mpWheel->setGeometry(100,30,speed_width,speed_width);
  249. mpBrake->setGeometry(120 + speed_width,30,speed_width,speed_width);
  250. mpAcc->setGeometry(140 + 2*speed_width,30,speed_width,speed_width);
  251. ui->groupBox_rem->setGeometry(grouppos_x,grouppos_y,grouppos_width,grouppos_height);
  252. int grouppic_x = 10 + sizemain.width()*6/10 + 10;
  253. int grouppic_y = 20 + sizemain.height() *3/5;
  254. int grouppic_width = sizemain.width()*4/10 - 30;
  255. int grouppic_height = sizemain.height()*1/10;
  256. ui->groupBox_picsel->setGeometry(grouppic_x,grouppic_y,grouppic_width,grouppic_height);
  257. int groupmap_x = 10 + sizemain.width()*6/10 + 10;
  258. int groupmap_y = 20 + sizemain.height() *7/10;
  259. int groupmap_width = sizemain.width()*4/10 - 30;
  260. int groupmap_height = sizemain.height()*1/10;
  261. ui->comboBox_Station->setGeometry(10,30,groupmap_width*3/5,30);
  262. ui->pushButton_Go->setGeometry(20 + groupmap_width*3/5,30,groupmap_width*2/5 - 30,30);
  263. ui->groupBox_map->setGeometry(groupmap_x,groupmap_y,groupmap_width,groupmap_height);
  264. int groupgps_x = 10 + sizemain.width()*6/10 + 10;
  265. int groupgps_y = 30 + sizemain.height() *8/10;
  266. int groupgps_width = sizemain.width()*4/10 - 30;
  267. int groupgps_height = sizemain.height()*2/10 - 30;
  268. ui->groupBox_gps->setGeometry(groupgps_x,groupgps_y,groupgps_width,groupgps_height);
  269. int lablewidth = (groupgps_width-50)*2/10;
  270. int lewidth = (groupgps_width-50)*3/10;
  271. int leheight = 26;
  272. int nypos = 40;
  273. ui->label_gpsins->setGeometry(10,nypos,lablewidth,leheight);
  274. ui->lineEdit_gpsins->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  275. ui->label_gpsrtk->setGeometry(30+lablewidth+lewidth,nypos,lablewidth,leheight);
  276. ui->lineEdit_gpsrtk->setGeometry(40+2*lablewidth +lewidth,nypos,lewidth,leheight);
  277. nypos = nypos + leheight*11/10;
  278. ui->label_gpslon->setGeometry(10,nypos,lablewidth,leheight);
  279. ui->lineEdit_gpslon->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  280. ui->label_gpslat->setGeometry(30+lablewidth+lewidth,nypos,lablewidth,leheight);
  281. ui->lineEdit_gpslat->setGeometry(40+2*lablewidth +lewidth,nypos,lewidth,leheight);
  282. nypos = nypos + leheight*11/10;
  283. ui->label_gpsheading->setGeometry(10,nypos,lablewidth,leheight);
  284. ui->lineEdit_gpsheading->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  285. ui->label_gpsheight->setGeometry(30+lablewidth+lewidth,nypos,lablewidth,leheight);
  286. ui->lineEdit_gpsheight->setGeometry(40+2*lablewidth +lewidth,nypos,lewidth,leheight);
  287. nypos = nypos + leheight*11/10;
  288. ui->label_gpsspeed->setGeometry(10,nypos,lablewidth,leheight);
  289. ui->lineEdit_gpsspeed->setGeometry(20+lablewidth,nypos,lewidth,leheight);
  290. ui->label_gpssat->setGeometry(30+lablewidth+lewidth,nypos,lablewidth,leheight);
  291. ui->lineEdit_gpssat->setGeometry(40+2*lablewidth +lewidth,nypos,lewidth,leheight);
  292. }
  293. void MainWindow::on_pushButton_test_clicked()
  294. {
  295. double flat = ui->lineEdit_lat->text().toDouble();
  296. double flon = ui->lineEdit_lon->text().toDouble();
  297. char strscript[256];
  298. snprintf(strscript,255,"theLocation(%11.7f,%11.7f);",flon,flat);
  299. mMapview->page()->runJavaScript(strscript);
  300. }
  301. void MainWindow::on_radioButton_manual_clicked()
  302. {
  303. ui->radioButton_manual->setChecked(true);
  304. mPressKeys.clear();
  305. mfAcc = 0;
  306. mfWheel = 0;
  307. mfBrake = 0;
  308. mpWheel->updatevalue(mfWheel);
  309. mpAcc->updatevalue(mfAcc);
  310. mpBrake->updatevalue(mfBrake);
  311. mManualTime.restart();
  312. mnLastTime = mManualTime.elapsed();
  313. mpTimerManual->start(10);
  314. }
  315. void MainWindow::onTimerManual()
  316. {
  317. double fOldWheel = mfWheel;
  318. double fOldAcc = mfAcc;
  319. double fOldBrake = mfBrake;
  320. int timediff = mManualTime.elapsed() - mnLastTime;
  321. mnLastTime = mManualTime.elapsed();
  322. int nOldShift = mnShift;
  323. if(mpJRT->isOK())
  324. {
  325. mfWheel = mpJRT->GetWheel() * (-100.0)/32768.0;
  326. mfAcc = ((mpJRT->GetAcc()-32767.0)/65535)*(-100.0);
  327. mfBrake = ((mpJRT->GetBrake()-32767.0)/65535)*(-100.0);
  328. if(mfWheel != fOldWheel)mpWheel->updatevalue(mfWheel);
  329. if(mfAcc != fOldAcc)mpAcc->updatevalue(mfAcc);
  330. if(mfBrake != fOldBrake)mpBrake->updatevalue(mfBrake);
  331. int x = mpJRT->GetShift();
  332. if(x > 0)mnShift = 1;
  333. if(x == 0)mnShift = 0;
  334. if(x < 0)mnShift = -1;
  335. if(mnShift != nOldShift)
  336. {
  337. switch (mnShift) {
  338. case 1:
  339. ui->radioButton_Drive->setChecked(true);
  340. ui->radioButton_picfront->setChecked(true);
  341. on_radioButton_picfront_clicked();
  342. break;
  343. case 0:
  344. ui->radioButton_Null->setChecked(true);
  345. break;
  346. case -1:
  347. ui->radioButton_Rear->setChecked(true);
  348. ui->radioButton_picrear->setChecked(true);
  349. on_radioButton_picrear_clicked();
  350. break;
  351. default:
  352. break;
  353. }
  354. }
  355. return;
  356. }
  357. if(mPressKeys.contains(Qt::Key_A)&&(mPressKeys.contains((Qt::Key_D))))
  358. {
  359. mfWheel = mfWheel;
  360. }
  361. else
  362. {
  363. if(mPressKeys.contains(Qt::Key_A))
  364. {
  365. if(mfWheel<0)mfWheel = 0;
  366. else
  367. {
  368. mfWheel = mfWheel + timediff*mfWheelSpeed/1000;
  369. if(mfWheel < -100)mfWheel = -100;
  370. if(mfWheel > 100 )mfWheel = 100;
  371. }
  372. }
  373. if(mPressKeys.contains(Qt::Key_D))
  374. {
  375. if(mfWheel>0)mfWheel = 0;
  376. else
  377. {
  378. mfWheel = mfWheel - timediff*mfWheelSpeed/1000;
  379. if(mfWheel < -100)mfWheel = -100;
  380. if(mfWheel > 100 )mfWheel = 100;
  381. }
  382. }
  383. }
  384. if(!mPressKeys.contains(Qt::Key_A)&&(!mPressKeys.contains((Qt::Key_D))))
  385. {
  386. if(mfWheel != 0)
  387. {
  388. if(mfWheel > 0)mfWheel = mfWheel - timediff*mfWheelAutoDownSpeed/1000;
  389. else mfWheel = mfWheel + timediff*mfWheelAutoDownSpeed/1000;
  390. if(fabs(mfWheel)< 10)mfWheel =0;
  391. }
  392. }
  393. if(mPressKeys.contains(Qt::Key_W)&&(mPressKeys.contains((Qt::Key_S))))
  394. {
  395. mfAcc = 0;
  396. mfBrake = mfBrake + timediff*mfBrakeSpeed/1000;
  397. if(mfBrake<0)mfBrake = 0;
  398. if(mfBrake > 100)mfBrake = 100;
  399. }
  400. else
  401. {
  402. if(mPressKeys.contains(Qt::Key_W))
  403. {
  404. mfBrake = 0;
  405. mfAcc = mfAcc + timediff*mfAccSpeed/1000;
  406. if(mfAcc<0)mfAcc = 0;
  407. if(mfAcc > 100)mfAcc = 100;
  408. }
  409. if(mPressKeys.contains(Qt::Key_S))
  410. {
  411. mfAcc = 0;
  412. mfBrake = mfBrake + timediff*mfBrakeSpeed/1000;
  413. if(mfBrake<0)mfBrake = 0;
  414. if(mfBrake > 100)mfBrake = 100;
  415. }
  416. }
  417. if(!mPressKeys.contains(Qt::Key_W)&&(!mPressKeys.contains((Qt::Key_S))))
  418. {
  419. if(mfBrake != 0)
  420. {
  421. mfBrake = mfBrake - timediff*mfBrakeAutoDownSpeed/1000;
  422. if(mfBrake<0)mfBrake = 0;
  423. if(mfBrake > 100)mfBrake = 100;
  424. }
  425. if(mfAcc != 0)
  426. {
  427. mfAcc = mfAcc - timediff*mfAccAutoDownSpeed/1000;
  428. if(mfAcc<0)mfAcc = 0;
  429. if(mfAcc > 100)mfAcc = 100;
  430. }
  431. }
  432. if(mfWheel != fOldWheel)mpWheel->updatevalue(mfWheel);
  433. if(mfAcc != fOldAcc)mpAcc->updatevalue(mfAcc);
  434. if(mfBrake != fOldBrake)mpBrake->updatevalue(mfBrake);
  435. }
  436. void MainWindow::on_radioButton_auto_clicked()
  437. {
  438. ui->radioButton_auto->setChecked(true);
  439. mPressKeys.clear();
  440. mpTimerManual->stop();
  441. }
  442. void MainWindow::onTimerRemote()
  443. {
  444. if(ui->radioButton_auto->isChecked())
  445. {
  446. mremotectrl.set_ntype(iv::remotectrl_CtrlType_AUTO);
  447. // mfAcc = 0;
  448. // mfBrake = 0;
  449. // mfWheel =0;
  450. // mpWheel->updatevalue(mfWheel);
  451. // mpAcc->updatevalue(mfAcc);
  452. // mpBrake->updatevalue(mfBrake);
  453. }
  454. else
  455. {
  456. mremotectrl.set_ntype(iv::remotectrl_CtrlType_REMOTE);
  457. }
  458. mremotectrl.set_acc(mfAcc);
  459. mremotectrl.set_brake(mfBrake);
  460. mremotectrl.set_wheel(mfWheel);
  461. mremotectrl.set_shift(mnShift);
  462. int nsersize = mremotectrl.ByteSize();
  463. char * strbuf = new char[nsersize];
  464. if(mremotectrl.SerializeToArray(strbuf,nsersize))
  465. {
  466. iv::modulecomm::ModuleSendMsg(mpa,strbuf,nsersize);
  467. }
  468. delete strbuf;
  469. }
  470. void MainWindow::onTimerUpdatePic()
  471. {
  472. static qint64 time_pic = 0;
  473. static qint64 time_trace = 0;
  474. static int pos = 0;
  475. static std::vector<iv::simpletrace> xvectorsimpletrace;
  476. if((mnSelPic>=0)&&(mnSelPic<4))
  477. {
  478. if((gTimeRawPic[mnSelPic] != time_pic) && (gTimeRawPic[mnSelPic] != 0))
  479. // if((gTimeRawPic[mnSelPic] != time_pic))
  480. {
  481. time_pic = gTimeRawPic[mnSelPic];
  482. iv::vision::rawpic xpic;
  483. gMutexPic[mnSelPic].lock();
  484. xpic.CopyFrom(grawpic[mnSelPic]);
  485. gMutexPic[mnSelPic].unlock();
  486. mpPicView->SetPic(xpic);
  487. }
  488. }
  489. if(mpPicView->IsHaveNew())update();
  490. if(gTimeTrace != time_trace)
  491. {
  492. time_trace = gTimeTrace;
  493. gMutexTrace.lock();
  494. xvectorsimpletrace = gvectorsimplerace;
  495. gMutexTrace.unlock();
  496. pos = 0;
  497. if(xvectorsimpletrace.size()> 0)
  498. {
  499. QJsonArray num_json,num2_json; //声明QJsonArray
  500. QJsonDocument num_document,num2_document; //将QJsonArray改为QJsonDocument类
  501. QByteArray num_byteArray,num2_byteArray; //
  502. int i=0;
  503. for(i=0;i<xvectorsimpletrace.size();i++) //将数组传入压入num_json
  504. {
  505. num_json.append(xvectorsimpletrace[i].gps_lng);
  506. num2_json.append(xvectorsimpletrace[i].gps_lat);
  507. }
  508. num_document.setArray(num_json);
  509. num2_document.setArray(num2_json);
  510. num_byteArray = num_document.toJson(QJsonDocument::Compact);
  511. num2_byteArray = num2_document.toJson(QJsonDocument::Compact);
  512. QString numJson(num_byteArray); //再转为QString
  513. QString num2Json(num2_byteArray); //再转为QString
  514. QString cmd = QString("settrace(\"%1\",\"%2\")").arg(numJson).arg(num2Json);
  515. mMapview->page()->runJavaScript(cmd);
  516. }
  517. }
  518. // if(pos<xvectorsimpletrace.size())
  519. // {
  520. // if(pos == 0)
  521. // {
  522. // mMapview->page()->runJavaScript("clear()");
  523. // }
  524. // char strscript[256];
  525. // snprintf(strscript,255,"mapLocation(%11.7f,%11.7f);",xvectorsimpletrace[pos].gps_lng,xvectorsimpletrace[pos].gps_lat);
  526. // mMapview->page()->runJavaScript(strscript);
  527. // pos++;
  528. // }
  529. }
  530. void MainWindow::onTimerUpdateView()
  531. {
  532. static qint64 time_gps = 0;
  533. qint64 nculatency = mgrpcpc->getculatency();
  534. if(nculatency != mncurculatency)
  535. {
  536. mncurculatency = nculatency;
  537. int nsheet = 0;
  538. if(mncurculatency >= 50)
  539. {
  540. if(mncurculatency >= 200)nsheet = 2;
  541. else nsheet = 1;
  542. }
  543. bool bNeedChangeSheet = false;
  544. if(nsheet != mnProgLatencySheet)
  545. {
  546. mnProgLatencySheet = nsheet;
  547. bNeedChangeSheet = true;
  548. }
  549. mpLabelLatency->setText("IV Latency: "+QString::number(mncurculatency)+"ms");
  550. int nprog = mncurculatency;
  551. if(nprog>500)nprog = 500;
  552. mpProgLatency->setValue(nprog);
  553. if(bNeedChangeSheet)
  554. {
  555. switch(mnProgLatencySheet)
  556. {
  557. case 0:
  558. mpProgLatency->setStyleSheet("QProgressBar{background:white} QProgressBar:chunk{background:green}");
  559. break;
  560. case 1:
  561. mpProgLatency->setStyleSheet("QProgressBar{background:white} QProgressBar:chunk{background:blue}");
  562. break;
  563. case 2:
  564. mpProgLatency->setStyleSheet("QProgressBar{background:white} QProgressBar:chunk{background:red}");
  565. break;
  566. }
  567. }
  568. }
  569. int nstate = mgrpcpc->getstate();
  570. if(nstate != mnstate)
  571. {
  572. mnstate = nstate;
  573. switch (mnstate) {
  574. case -100:
  575. mpLabelState->setText("Connecting to Server...");
  576. mpLabelState->setStyleSheet("QLabel{color: red}");
  577. break;
  578. case -2:
  579. mpLabelState->setText("Password Error...");
  580. mpLabelState->setStyleSheet("QLabel{color: red}");
  581. break;
  582. case -1:
  583. mpLabelState->setText("IV not login...");
  584. mpLabelState->setStyleSheet("QLabel{color: red}");
  585. break;
  586. case 0:
  587. mpLabelState->setText("IV OffLine.");
  588. mpLabelState->setStyleSheet("QLabel{color: red}");
  589. break;
  590. case 1:
  591. mpLabelState->setText("IV OK...");
  592. mpLabelState->setStyleSheet("QLabel{color: green}");
  593. break;
  594. default:
  595. break;
  596. }
  597. }
  598. qint64 nServerlatency = mgrpcpc->getserverlatency();
  599. if(nServerlatency != mncurServerlatency)
  600. {
  601. mncurServerlatency = nServerlatency;
  602. int nsheet = 0;
  603. if(mncurServerlatency >= 50)
  604. {
  605. if(mncurServerlatency >= 200)nsheet = 2;
  606. else nsheet = 1;
  607. }
  608. bool bNeedChangeSheet = false;
  609. if(nsheet != mnProgServerLatencySheet)
  610. {
  611. mnProgServerLatencySheet = nsheet;
  612. bNeedChangeSheet = true;
  613. }
  614. mpLabelServerLatency->setText("Server Latency: "+QString::number(mncurServerlatency)+"ms");
  615. int nprog = mncurServerlatency;
  616. if(nprog>500)nprog = 500;
  617. mpProgServerLatency->setValue(nprog);
  618. if(bNeedChangeSheet)
  619. {
  620. switch(mnProgServerLatencySheet)
  621. {
  622. case 0:
  623. mpProgServerLatency->setStyleSheet("QProgressBar{background:white} QProgressBar:chunk{background:green}");
  624. break;
  625. case 1:
  626. mpProgServerLatency->setStyleSheet("QProgressBar{background:white} QProgressBar:chunk{background:blue}");
  627. break;
  628. case 2:
  629. mpProgServerLatency->setStyleSheet("QProgressBar{background:white} QProgressBar:chunk{background:red}");
  630. break;
  631. }
  632. }
  633. }
  634. if(gTimeGPSIMUUpdate != time_gps)
  635. {
  636. time_gps = gTimeGPSIMUUpdate;
  637. char strscript[256];
  638. snprintf(strscript,255,"theLocation(%11.7f,%11.7f,%11.3f);",ggpsimu.lon(),ggpsimu.lat(),ggpsimu.heading());
  639. mMapview->page()->runJavaScript(strscript);
  640. iv::gps::gpsimu xgpsimu;
  641. xgpsimu.CopyFrom(ggpsimu);
  642. ui->lineEdit_gpsins->setText(QString::number(xgpsimu.ins_state()));
  643. ui->lineEdit_gpsrtk->setText(QString::number(xgpsimu.rtk_state()));
  644. ui->lineEdit_gpslon->setText(QString::number(xgpsimu.lon(),'f',7));
  645. ui->lineEdit_gpslat->setText(QString::number(xgpsimu.lat(),'f',7));
  646. ui->lineEdit_gpsheading->setText(QString::number(xgpsimu.heading(),'f',2));
  647. ui->lineEdit_gpsheight->setText(QString::number(xgpsimu.height(),'f',2));
  648. ui->lineEdit_gpsspeed->setText(QString::number(xgpsimu.speed(),'f',2));
  649. ui->lineEdit_gpssat->setText(QString::number(xgpsimu.satnum1()));
  650. mstrGPSTime = QDateTime::fromMSecsSinceEpoch(xgpsimu.msgtime()).toString("GPS: yyyy-MM-dd hh:mm:ss ");
  651. setWindowTitle(mstrProgName + mstrVIN + mstrGPSTime + mstrPicTime);
  652. }
  653. }
  654. void MainWindow::paintEvent(QPaintEvent *)
  655. {
  656. if(!mpPicView->IsHaveNew())
  657. {
  658. return;
  659. }
  660. else
  661. {
  662. QImage image = mpPicView->GetImage();
  663. mscene->clear();
  664. mscene->addPixmap(QPixmap::fromImage(image));
  665. mmyview->setScene(mscene);
  666. mmyview->show();
  667. }
  668. }
  669. void MainWindow::on_pushButton_Go_clicked()
  670. {
  671. if(ui->comboBox_Station->currentIndex() < 0)return;
  672. int index = ui->comboBox_Station->currentIndex();
  673. if(index<0 || index>= gvectorpos.size())
  674. {
  675. std::cout<<"out range."<<std::endl;
  676. return;
  677. }
  678. iv::pos_def xpos = gvectorpos[index];
  679. double lon,lat;
  680. lon = xpos.mflon;
  681. lat = xpos.mflat;
  682. xodrobj xo;
  683. xo.flon = lon;
  684. xo.flat = lat;
  685. xo.lane = 3;
  686. iv::modulecomm::ModuleSendMsg(mpadst,(char *)&xo,sizeof(xodrobj));
  687. }
  688. void MainWindow::on_comboBox_Station_currentIndexChanged(int index)
  689. {
  690. if(index<0 || index>= gvectorpos.size())
  691. {
  692. std::cout<<"out range."<<std::endl;
  693. return;
  694. }
  695. iv::pos_def xpos = gvectorpos[index];
  696. char strscript[256];
  697. snprintf(strscript,255,"objLocation(%11.7f,%11.7f);",xpos.mflon,xpos.mflat);
  698. mMapview->page()->runJavaScript(strscript);
  699. }
  700. void MainWindow::on_checkBox_Drive_stateChanged(int arg1)
  701. {
  702. }
  703. void MainWindow::on_checkBox_Drive_clicked()
  704. {
  705. }
  706. void MainWindow::on_checkBox_Null_clicked()
  707. {
  708. }
  709. void MainWindow::on_checkBox_Rear_clicked()
  710. {
  711. }
  712. void MainWindow::on_radioButton_Drive_clicked()
  713. {
  714. mnShift = 1;
  715. ui->radioButton_picfront->setChecked(true);
  716. on_radioButton_picfront_clicked();
  717. }
  718. void MainWindow::on_radioButton_Null_clicked()
  719. {
  720. mnShift = 0;
  721. }
  722. void MainWindow::on_radioButton_Rear_clicked()
  723. {
  724. mnShift = -1;
  725. ui->radioButton_picrear->setChecked(true);
  726. on_radioButton_picrear_clicked();
  727. }
  728. void MainWindow::on_radioButton_picfront_clicked()
  729. {
  730. mnSelPic = 0;
  731. mpbigpicdlg->setCamera(mnSelPic);
  732. }
  733. void MainWindow::on_radioButton_picrear_clicked()
  734. {
  735. mnSelPic = 1;
  736. mpbigpicdlg->setCamera(mnSelPic);
  737. }
  738. void MainWindow::on_radioButton_picleft_clicked()
  739. {
  740. mnSelPic = 2;
  741. mpbigpicdlg->setCamera(mnSelPic);
  742. }
  743. void MainWindow::on_radioButton_picright_clicked()
  744. {
  745. mnSelPic = 3;
  746. mpbigpicdlg->setCamera(mnSelPic);
  747. }
  748. void MainWindow::on_pushButton_AllPic_clicked()
  749. {
  750. mppicdlg->show();
  751. mppicdlg->setRefresh(true);
  752. }
  753. void MainWindow::onCloseDlg()
  754. {
  755. mppicdlg->setRefresh(false);
  756. qDebug("cloase");
  757. }
  758. void MainWindow::on_checkBox_clicked()
  759. {
  760. int i;
  761. if(ui->checkBox->isChecked())
  762. {
  763. for(i=0;i<4;i++)
  764. {
  765. mpPicSave[i]->startsave();
  766. }
  767. mbSavePic = true;
  768. }
  769. else
  770. {
  771. for(i=0;i<4;i++)
  772. {
  773. mpPicSave[i]->stopsave();
  774. }
  775. mbSavePic = false;
  776. }
  777. }
  778. void MainWindow::saveavi(int index)
  779. {
  780. // if(mbSavePic == false)return;
  781. gMutexPic[index].lock();
  782. mpPicSave[index]->SetPic(grawpic[index]);
  783. gMutexPic[index].unlock();
  784. }
  785. void MainWindow::on_pushButton_big_clicked()
  786. {
  787. mpbigpicdlg->show();
  788. mpbigpicdlg->setRefresh(true);
  789. }
  790. void MainWindow::onCloseBigDlg()
  791. {
  792. mpbigpicdlg->setRefresh(false);
  793. }
  794. void MainWindow::on_actionSet_FrameRate_triggered()
  795. {
  796. float framerate = mgrpcpc->getframerate();
  797. float oldfr = framerate;
  798. float fctrlfps = mgrpcpc->getctrlfps();
  799. float oldctrlfps = fctrlfps;
  800. DialogSetFrameRate xdialog(&framerate,&fctrlfps);
  801. xdialog.exec();
  802. if(oldfr != framerate)
  803. {
  804. mgrpcpc->setframerate(framerate);
  805. }
  806. if(oldctrlfps != fctrlfps)
  807. {
  808. mgrpcpc->setctrlfps(fctrlfps);
  809. }
  810. }
  811. void MainWindow::on_actionSet_Camera_triggered()
  812. {
  813. }