mainwindow.cpp 26 KB

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