mainwindow.cpp 24 KB

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