adcintelligentshow.cpp 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492
  1. #include "adcintelligentshow.h"
  2. #include "ui_adcintelligentshow.h"
  3. #include <QSound>
  4. #include <QtMath>
  5. #include <QMessageBox>
  6. #include <QInputDialog>
  7. #include "pos_def.h"
  8. extern std::vector<iv::pos_def> gvectorpos;
  9. extern std::string gstrdefaultlane;
  10. ADCIntelligentShow * gAShow;
  11. #include "grpcclientthread.h"
  12. #ifdef Android
  13. extern grpcclientthread * ggt;
  14. #endif
  15. const double PI = 3.1415926535898;
  16. class xodrobj
  17. {
  18. public:
  19. double flatsrc;
  20. double flonsrc;
  21. double fhgdsrc;
  22. double flat;
  23. double flon;
  24. int lane;
  25. };
  26. void Listengpsimu(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  27. {
  28. (void)&index;
  29. (void)dt;
  30. (void)strmemname;
  31. // ggpsimu->UpdateGPSIMU(strdata,nSize);
  32. iv::gps::gpsimu xgpsimu;
  33. if(!xgpsimu.ParseFromArray(strdata,nSize))
  34. {
  35. std::cout<<"ListenRaw Parse error."<<std::endl;
  36. return;
  37. }
  38. gAShow->UpdateGPSIMU(&xgpsimu);
  39. // qDebug(" gps time is %ld",QDateTime::currentMSecsSinceEpoch());
  40. }
  41. void ListenOBS(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  42. {
  43. (void)&index;
  44. (void)dt;
  45. (void)strmemname;
  46. std::shared_ptr<std::vector<iv::ObstacleBasic>> lidar_obs(new std::vector<iv::ObstacleBasic>);
  47. iv::ObstacleBasic * pdata = (iv::ObstacleBasic *)strdata;
  48. int nCount = nSize/sizeof(iv::ObstacleBasic);
  49. int i;
  50. for(i=0;i<nCount;i++)
  51. {
  52. iv::ObstacleBasic temp;
  53. memcpy(&temp,pdata,sizeof(iv::ObstacleBasic));
  54. lidar_obs->push_back(temp);
  55. pdata++;
  56. }
  57. gAShow->UpdateOBS(lidar_obs);
  58. // gw->UpdateOBS(lidar_obs);
  59. }
  60. void ListenRadar(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  61. {
  62. (void)&index;
  63. (void)dt;
  64. (void)strmemname;
  65. if(nSize<1)return;
  66. iv::radar::radarobjectarray xobj;
  67. if(false == xobj.ParseFromArray(strdata,nSize))
  68. {
  69. std::cout<<"ListenenRadar fail."<<std::endl;
  70. return;
  71. }
  72. gAShow->UpdateRADAR(&xobj);
  73. }
  74. void ListenDection(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  75. {
  76. (void)&index;
  77. (void)dt;
  78. (void)strmemname;
  79. iv::brain::decition xdecision;
  80. if(!xdecision.ParseFromArray(strdata,nSize))
  81. {
  82. std::cout<<" ListenDection error. Parse error."<<std::endl;
  83. return;
  84. }
  85. gAShow->UpdateDection(xdecision);
  86. }
  87. void ListenFusion(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  88. {
  89. (void)&index;
  90. (void)dt;
  91. (void)strmemname;
  92. iv::fusion::fusionobjectarray xfusionarray;
  93. if(!xfusionarray.ParseFromArray(strdata, static_cast<int>(nSize) ))
  94. {
  95. qDebug("listen fusion fail.");
  96. return;
  97. }
  98. gAShow->UpdateFusion(xfusionarray);
  99. }
  100. void ListenBrainState(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  101. {
  102. (void)&index;
  103. (void)dt;
  104. (void)strmemname;
  105. iv::brain::brainstate xbrainstate;
  106. if(!xbrainstate.ParseFromArray(strdata,nSize))
  107. {
  108. std::cout<<"ListenBrainState Parse error."<<std::endl;
  109. return;
  110. }
  111. gAShow->UpdateBrainState(xbrainstate);
  112. }
  113. void ListenVehInfo(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  114. {
  115. (void)&index;
  116. (void)dt;
  117. (void)strmemname;
  118. iv::veh::vehinfo xvehinfo;
  119. if(!xvehinfo.ParseFromArray(strdata,nSize))
  120. {
  121. std::cout<<"ListenVehInfo Parse error."<<std::endl;
  122. return;
  123. }
  124. gAShow->UpdateOTAVehInfo(xvehinfo);
  125. }
  126. void ListenTraceMap(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  127. {
  128. (void)&index;
  129. (void)dt;
  130. (void)strmemname;
  131. gAShow->UpdateMap(strdata,nSize);
  132. }
  133. #ifdef Android
  134. void ADCIntelligentShow::AndroidSetMsg(const char * msgname , const char *strdata, const unsigned int nDataLen)
  135. {
  136. // qDebug("msg: %s ",msgname);
  137. if(strncmp(msgname,"hcp2_gpsimu",256) == 0)
  138. {
  139. Listengpsimu(strdata,nDataLen,0,0,0);
  140. }
  141. if(strncmp(msgname,"tracemap",256) == 0)
  142. {
  143. ListenTraceMap(strdata,nDataLen,0,0,0);
  144. }
  145. if(strncmp(msgname,"lidar_obs",256) == 0)
  146. {
  147. ListenOBS(strdata,nDataLen,0,0,0);
  148. }
  149. if(strncmp(msgname,"brainstate",256) == 0)
  150. {
  151. ListenBrainState(strdata,nDataLen,0,0,0);
  152. }
  153. if(strncmp(msgname,"deciton",256) == 0)
  154. {
  155. ListenDection(strdata,nDataLen,0,0,0);
  156. }
  157. if(strncmp(msgname,"radar",256) == 0)
  158. {
  159. ListenRadar(strdata,nDataLen,0,0,0);
  160. }
  161. if(strncmp(msgname,"otavehinfo",256) == 0)
  162. {
  163. ListenVehInfo(strdata,nDataLen,0,0,0);
  164. }
  165. if(strncmp(msgname,"li_ra_fusion",256) == 0)
  166. {
  167. // qDebug("li ra fusion.");
  168. ListenFusion(strdata,nDataLen,0,0,0);
  169. }
  170. }
  171. #endif
  172. ADCIntelligentShow::ADCIntelligentShow(QWidget *parent) :
  173. QMainWindow(parent),
  174. ui(new Ui::ADCIntelligentShow)
  175. {
  176. gAShow = this;
  177. ui->setupUi(this);
  178. ui->pushButton->setEnabled(false);
  179. mpivmapview = new ivmapview();
  180. mpivmapview->start();
  181. //样式 3-26
  182. qApp->setStyleSheet("QPushButton#pushButton_2\n{\nborder-image: url(:/new/pic/restart1.png);\n}"
  183. "QPushButton#pushButton_2:hover\n{border-image: url(:/new/pic/restart4.png);\n}"
  184. "QPushButton#pushButton_2:pressed\n{ border-image: url(:/new/pic/restart3.png); \n}"
  185. "QPushButton#park:pressed\n{border-image: url(:/new/pic/park_press.png);\n}"
  186. "QPushButton#pushButton_Setting\n{ border-image: url(:/new/pic/setting.png); \n}"
  187. "QPushButton#pushButton_Setting:pressed\n{ border-image: url(:/new/pic/setting2.png); \n}"
  188. "QCheckBox#checkBox::indicator\n{width: 110px;height: 110px;\n}"
  189. "QCheckBox#checkBox::indicator:unchecked\n{ border-image:url(:/new/pic/call_gray1.png);\n}"
  190. "QCheckBox#checkBox::indicator:checked\n{ border-image:url(:/new/pic/call1.png);\n}"
  191. "QCheckBox#checkBox_2::indicator\n{width: 110px;height: 110px;\n}"
  192. "QCheckBox#checkBox_2::indicator:unchecked\n{ border-image:url(:/new/pic/mulcar_gray.png);\n}"
  193. "QCheckBox#checkBox_2::indicator:checked\n{ border-image:url(:/new/pic/mulcar.png);\n}");
  194. QDesktopWidget *desktopWidget = QApplication::desktop();
  195. QRect screenRect = desktopWidget->screenGeometry();
  196. resize(screenRect.width(),screenRect.height());
  197. loadMapFromFile("map.txt");
  198. image = new QImage(900*2,900*2,QImage::Format_RGB32);
  199. painter = new QPainter(image);
  200. myview = new MyView(ui->widget_2);
  201. myview->setObjectName("graphicsView");
  202. myview->setGeometry(QRect(100,20,900,1000));
  203. myview->setCacheMode(myview->CacheBackground);
  204. scene = new QGraphicsScene;
  205. myview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  206. myview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  207. DataUI = new DataToUI;
  208. socket = new QUdpSocket;
  209. socket->bind(9999,QUdpSocket::ShareAddress);
  210. // connect(socket,SIGNAL(readyRead()),this,SLOT(onRecv()));
  211. lidarsock = new QUdpSocket;
  212. lidarsock->bind(9997);
  213. // connect(lidarsock,SIGNAL(readyRead()),this,SLOT(onlidarRecv()));
  214. mbHaveData = false;
  215. recvFlag = 0;
  216. connect(&mTimer,SIGNAL(timeout()),this,SLOT(onTimer()));
  217. // mTimer.start(500);
  218. connect(&connTimer,SIGNAL(timeout()),this,SLOT(onconnTimer()));
  219. connTimer.start(1000);
  220. for(int i = 0;i<128;i++)
  221. {
  222. DataUI->mInfo.point[i] = 0.0;
  223. }
  224. mlidarpoint.lidar_size = 0;
  225. for(int i=0;i<10000;i++)
  226. {
  227. mlidarpoint.lidar_point[i] = 0.0;
  228. }
  229. //DataUI->mInfo.lidar_size = 0;
  230. ///added by kkcai, 2019-11-28
  231. // ui->label_3->hide();
  232. // ui->label_4->hide();
  233. ///////////////////////////////////////////////////////////////////////////
  234. ///added by kkcai, 2019-12-02
  235. soundAlarm = new QSound(":/new/pic/alarm.wav");
  236. connect(this, SIGNAL(sigAlarm()), this, SLOT(slotAlarm()));
  237. #ifndef Android
  238. void * pa;
  239. pa = iv::modulecomm::RegisterRecv("hcp2_gpsimu",Listengpsimu);
  240. mpagps = pa;
  241. pa = iv::modulecomm::RegisterRecv("tracemap",ListenTraceMap);
  242. mpatracemap = pa;
  243. pa = iv::modulecomm::RegisterRecv("lidar_obs",ListenOBS);
  244. mpalidarobs = pa;
  245. pa = iv::modulecomm::RegisterRecv("brainstate",ListenBrainState);
  246. mpabrainstate = pa;
  247. pa = iv::modulecomm::RegisterRecv("deciton",ListenDection);
  248. mpadecision = pa;
  249. pa = iv::modulecomm::RegisterRecv("radar",ListenRadar);
  250. mparadar = pa;
  251. pa = iv::modulecomm::RegisterRecv("otavehinfo",ListenVehInfo);
  252. pa = iv::modulecomm::RegisterRecv("li_ra_fusion",ListenFusion);
  253. mpadst = iv::modulecomm::RegisterSend("xodrreq",1000,1);
  254. mpapad = iv::modulecomm::RegisterSend("pad",1000,1);
  255. mndefaultlane = atoi(gstrdefaultlane.data());
  256. #endif
  257. connect(this,SIGNAL(signalGPSIMU()),this,SLOT(onUpdateGPSIMU()));
  258. connect(this,SIGNAL(signalbrainstate()),this,SLOT(onUpdateBrainState()));
  259. connect(this,SIGNAL(signaldection()),this,SLOT(onUpdateDection()));
  260. QTimer * timerpainter = new QTimer(this);
  261. connect(timerpainter,SIGNAL(timeout()),this,SLOT(onTimerPainter()));
  262. timerpainter->start(100);
  263. ui->pushButton_go->setStyleSheet("background: green; color: white;");
  264. ui->pushButton_AddStation->setStyleSheet("background: green; color: white;");
  265. ui->pushButton_DelStation->setStyleSheet("background: green; color: white;");
  266. // ui->pushButton_prestation->setStyleSheet("background: green; color: white;");
  267. // ui->pushButton_nextstation->setStyleSheet("background: green; color: white;border-image: url(:/new/pic/button_gray.png);");
  268. ui->label_station->setStyleSheet("background: transparent; color: white;font: 50px 'Arial';");
  269. ui->label_station->setText("");
  270. ui->label_vehinfo->setStyleSheet("color: rgb(220, 220, 220);font: 15px 'Arial';");
  271. ui->label_vehinfo->setText("No Vehicle Type & VIN Info");
  272. if(gvectorpos.size()>0)
  273. {
  274. mnStationIndex = 0;
  275. ui->label_station->setText(gvectorpos[0].mstrstationname.data());
  276. }
  277. mpDS = new DialogSetting(this);
  278. connect(mpDS,SIGNAL(signalswith(int)),this,SLOT(onSwitchClick(int)));
  279. connect(mpDS,SIGNAL(signalMode(int)),this,SLOT(onModeClick(int)));
  280. connect(this,SIGNAL(signalvehinfoupdate()),this,SLOT(onOTAVehInfoUpdate()));
  281. // ui->pushButton_go->setStyleSheet("color: red");
  282. ///////////////////////////////////////////////////////////////////////
  283. ///added by kkcai, 2019-12-02
  284. // ui->checkBox->hide();
  285. // ui->checkBox_2->hide();
  286. // ui->park->hide();
  287. ///////////////////////////////////////////////////////////////////////
  288. #ifdef ANDROID
  289. ui->run->setStyleSheet("color: rgb(220, 220, 220);font: 30px 'Arial';");
  290. ui->map->setStyleSheet("color: rgb(220, 220, 220);font: 30px 'Arial';");
  291. ui->can->setStyleSheet("color: rgb(220, 220, 220);font: 30px 'Arial';");
  292. ui->local->setStyleSheet("color: rgb(220, 220, 220);font: 30px 'Arial';");
  293. ui->label_9->setStyleSheet("color: rgb(220, 220, 220);font: 30px 'Arial';");
  294. ui->label_11->setStyleSheet("color: rgb(220, 220, 220);font: 30px 'Arial';");
  295. ui->label_12->setStyleSheet("color: rgb(220, 220, 220);font: 30px 'Arial';");
  296. ui->label_13->setStyleSheet("color: rgb(220, 220, 220);font: 30px 'Arial';");
  297. ui->label_14->setStyleSheet("color: rgb(220, 220, 220);font: 30px 'Arial';");
  298. ui->label_15->setStyleSheet("color: rgb(220, 220, 220);font: 30px 'Arial';");
  299. ui->label_16->setStyleSheet("color: rgb(220, 220, 220);font: 30px 'Arial';");
  300. ui->label_17->setStyleSheet("color: rgb(220, 220, 220);font: 30px 'Arial';");
  301. ui->label_6->setStyleSheet("font: 50px 'Arial';color: rgb(255, 255, 255);");
  302. ui->label->setStyleSheet("font: 75 150px '微软雅黑';color: rgb(238, 238, 238);");
  303. ui->radar->setStyleSheet("color: rgb(220, 220, 220);font: 30px 'Arial';");
  304. ui->lidar->setStyleSheet("color: rgb(220, 220, 220);font: 30px 'Arial';");
  305. ui->acc->setStyleSheet("color: rgb(255, 255, 255);background-color: transparent;border-radius:10px;font: 23px 'Arial';border:7px groove rgb(0,45,70);");
  306. ui->swerve->setStyleSheet("color: rgb(255, 255, 255);background-color: transparent;border-radius:10px;font: 23px 'Arial';border:7px groove rgb(0,45,70);");
  307. ui->lng->setStyleSheet("color: rgb(255, 255, 255);background-color: transparent;border-radius:10px;font: 23px 'Arial';border:7px groove rgb(0,45,70);");
  308. ui->lat->setStyleSheet("color: rgb(255, 255, 255);background-color: transparent;border-radius:10px;font: 23px 'Arial';border:7px groove rgb(0,45,70);");
  309. ui->radarob->setStyleSheet("color: rgb(255, 255, 255);background-color: transparent;border-radius:10px;font: 23px 'Arial';border:7px groove rgb(0,45,70);");
  310. ui->lidarob->setStyleSheet("color: rgb(255, 255, 255);background-color: transparent;border-radius:10px;font: 23px 'Arial';border:7px groove rgb(0,45,70);");
  311. ui->allob->setStyleSheet("color: rgb(255, 255, 255);background-color: transparent;border-radius:10px;font: 23px 'Arial';border:7px groove rgb(0,45,70);");
  312. ui->break_1->setStyleSheet("color: rgb(255, 255, 255);background-color: transparent;border-radius:10px;font: 23px 'Arial';border:7px groove rgb(0,45,70);");
  313. #endif
  314. }
  315. ADCIntelligentShow::~ADCIntelligentShow()
  316. {
  317. iv::modulecomm::Unregister(mpabrainstate);
  318. iv::modulecomm::Unregister(mpadecision);
  319. iv::modulecomm::Unregister(mpagps);
  320. iv::modulecomm::Unregister(mpalidarobs);
  321. iv::modulecomm::Unregister(mpapad);
  322. iv::modulecomm::Unregister(mparadar);
  323. iv::modulecomm::Unregister(mpatracemap);
  324. iv::modulecomm::Unregister(mpadst);
  325. // std::this_thread::sleep_for(std::chrono::milliseconds(50));
  326. delete ui;
  327. if(soundAlarm){
  328. delete soundAlarm;
  329. soundAlarm = nullptr;
  330. }
  331. }
  332. void ADCIntelligentShow::resizeEvent(QResizeEvent *event)
  333. {
  334. (void)event;
  335. QSize sizemain = ui->centralWidget->size();
  336. ui->widget_2->setGeometry(730,0,sizemain.width()-730,sizemain.height()-0);
  337. myview->setGeometry(0,150,sizemain.width()-730-0,sizemain.height()-150);
  338. #ifndef Android
  339. ui->pushButton_prestation->setGeometry(50,30,100,50);
  340. ui->label_station->setGeometry(160,30,200,50);
  341. ui->pushButton_nextstation->setGeometry(380,30,100,50);
  342. ui->pushButton_go->setGeometry(490,30,100,50);
  343. ui->pushButton_AddStation->setGeometry(600,30,100,50);
  344. ui->pushButton_DelStation->setGeometry(730,30,100,50);
  345. #else
  346. // ui->pushButton_prestation->setGeometry(30,30,150,100);
  347. // ui->label_station->setGeometry(190,30,260,100);
  348. // ui->pushButton_nextstation->setGeometry(460,30,150,100);
  349. // ui->pushButton_go->setGeometry(630,30,150,100);
  350. ui->pushButton_prestation->setGeometry(50,30,100,100);
  351. ui->label_station->setGeometry(160,30,500,100);
  352. ui->pushButton_nextstation->setGeometry(680,30,100,100);
  353. ui->pushButton_go->setGeometry(830,30,150,100);
  354. ui->pushButton_AddStation->setGeometry(1050,30,150,100);
  355. ui->pushButton_DelStation->setGeometry(1230,30,150,100);
  356. #endif
  357. }
  358. void ADCIntelligentShow::onTimer()
  359. {
  360. if(!mbHaveData)
  361. {
  362. ui->pushButton->setEnabled(false);
  363. }
  364. mbHaveData = false;
  365. update();
  366. }
  367. void ADCIntelligentShow::on_pushButton_clicked()
  368. {
  369. std::cout<<"click "<<std::endl;
  370. iv::hmi::hmimsg xhmi;
  371. xhmi.set_mbbochemode(false);
  372. xhmi.set_mbbusmode(false);
  373. if(mbRunning)
  374. xhmi.set_mbpause(true);
  375. else
  376. xhmi.set_mbpause(false);
  377. int nsize = xhmi.ByteSize();
  378. char * str = new char[nsize];
  379. if(xhmi.SerializeToArray(str,1000))
  380. {
  381. #ifndef Android
  382. iv::modulecomm::ModuleSendMsg(mpapad,str,nsize);
  383. #else
  384. ggt->UpdateData(str,nsize,"pad");
  385. #endif
  386. }
  387. else
  388. {
  389. std::cout<<"ADCIntelligentShow::on_pushButton_clicked serialize error."<<std::endl;
  390. }
  391. delete str;
  392. QApplication::beep();
  393. return;
  394. if(DataUI->mInfo.is_run == 0x00)
  395. {
  396. int xRun = 1;
  397. socket->writeDatagram((char *)&xRun,4,QHostAddress::Broadcast,9998);
  398. }
  399. if(DataUI->mInfo.is_run == 0x01)
  400. {
  401. int xRun = 0;
  402. socket->writeDatagram((char *)&xRun,4,QHostAddress::Broadcast,9998);
  403. }
  404. QApplication::beep();
  405. }
  406. void ADCIntelligentShow::onRecv()
  407. {
  408. while(socket->hasPendingDatagrams())
  409. {
  410. QByteArray data;
  411. data.resize(socket->pendingDatagramSize());
  412. socket->readDatagram(data.data(),data.size());
  413. recvFlag++;
  414. // packageHead packHead;
  415. qDebug("size = %d",data.size());
  416. //if(data.size() == sizeof(DataToUI))
  417. //{
  418. memcpy(DataUI,data.data(),data.size());
  419. qDebug("size:%d",DataUI->mHead.size);
  420. ////////////////////////
  421. /// 程序状态/////////////
  422. ///////////////////////
  423. qDebug("speed:%g",DataUI->mInfo.speed);
  424. ui->label->setText(QString::number((DataUI->mInfo.speed),'f',1));
  425. if(DataUI->mInfo.is_mapLoad==0x01)
  426. ui->mapimg->setStyleSheet("background-image: url(:/new/pic/green.png);");
  427. else
  428. ui->mapimg->setStyleSheet("background-image: url(:/new/pic/red.png);");
  429. if(DataUI->mInfo.is_initSuccess==0x01)
  430. ui->canimg->setStyleSheet("background-image: url(:/new/pic/green.png);");
  431. else
  432. ui->canimg->setStyleSheet("background-image: url(:/new/pic/red.png);");
  433. ui->acc->setText(QString::number(DataUI->mInfo.accelerate,'f',1));
  434. ui->swerve->setText(QString::number(DataUI->mInfo.swerve,'f',1));
  435. ui->lng->setText(QString::number(DataUI->mInfo.gps_lng,'f',6));
  436. ui->lat->setText(QString::number(DataUI->mInfo.gps_lat,'f',6));
  437. ui->radarob->setText(QString::number(DataUI->mInfo.radarobs,'f',2));
  438. ui->lidarob->setText(QString::number(DataUI->mInfo.lidarobs,'f',2));
  439. ui->allob->setText(QString::number(DataUI->mInfo.obs,'f',2));
  440. //add
  441. ui->break_1->setText(QString::number(DataUI->mInfo.brake,'f',2));
  442. if(DataUI->mInfo.lidarStatus == 0x01)
  443. ui->lidarimg->setStyleSheet("background-image: url(:/new/pic/red.png);");
  444. else
  445. ui->lidarimg->setStyleSheet("background-image: url(:/new/pic/green.png);");
  446. /*
  447. if(DataUI->mInfo.radarStatus == 0x01)
  448. ui->radarimg->setStyleSheet("background-image: url(:/new/pic/green.png);");
  449. else
  450. ui->radarimg->setStyleSheet("background-image: url(:/new/pic/red.png);");
  451. */
  452. if(DataUI->mInfo.radarStatus == 0x01)
  453. ui->radarimg->setStyleSheet("background-image: url(:/new/pic/red.png);");
  454. else
  455. ui->radarimg->setStyleSheet("background-image: url(:/new/pic/green.png);");
  456. if(DataUI->mInfo.RTKstatus == 6)
  457. {
  458. ui->local->setText(QStringLiteral("定位:")+QString::number(DataUI->mInfo.RTKstatus));
  459. ui->local->setStyleSheet("color: rgb(220, 220, 220); font: 15pt 'Arial';");
  460. ui->localimg->setStyleSheet("background-image: url(:/new/pic/green.png);");
  461. }
  462. else
  463. {
  464. ui->local->setText(QStringLiteral("定位:")+QString::number(DataUI->mInfo.RTKstatus));
  465. ui->local->setStyleSheet("color: rgb(220, 220, 220); font: 15pt 'Arial';");
  466. ui->localimg->setStyleSheet("background-image: url(:/new/pic/red.png);");
  467. }
  468. if(DataUI->mInfo.is_mapLoad==0x00||DataUI->mInfo.is_initSuccess==0x00)
  469. {
  470. ui->pushButton->setEnabled(false);
  471. ui->pushButton->setStyleSheet("border-image: url(:/new/pic/button_gray.png);");
  472. }
  473. else
  474. {
  475. ui->pushButton->setEnabled(true);
  476. ui->pushButton->setStyleSheet("border-image: url(:/new/pic/button_green.png);");
  477. if(DataUI->mInfo.is_run==0x01)
  478. {
  479. ui->runimg->setStyleSheet("background-image: url(:/new/pic/green.png);");
  480. ui->pushButton->setStyleSheet("border-image: url(:/new/pic/button_stop.png);");
  481. }
  482. else
  483. {
  484. ui->runimg->setStyleSheet("background-image: url(:/new/pic/red.png);");
  485. ui->pushButton->setStyleSheet("border-image: url(:/new/pic/button_green.png);");
  486. }
  487. }
  488. if(DataUI->mInfo.parkSatus == 0x00)
  489. {
  490. ui->park->setText(QStringLiteral("不可泊车"));
  491. ui->park->setStyleSheet("background-image: url(:/new/pic/red.png);");
  492. ui->park->setEnabled(false);
  493. ui->park->setStyleSheet("border-image: url(:/new/pic/park_gray.png)");
  494. }
  495. else if(DataUI->mInfo.parkSatus == 0x01)
  496. {
  497. ui->park->setText(QStringLiteral("可泊车"));
  498. ui->park->setStyleSheet("background-image: url(:/new/pic/green.png);");
  499. ui->park->setEnabled(true);
  500. ui->park->setStyleSheet("border-image: url(:/new/pic/park.png)");
  501. }
  502. else if(DataUI->mInfo.parkSatus == 0x02)
  503. {
  504. ui->park->setText(QStringLiteral("泊车"));
  505. ui->park->setStyleSheet("background-color: rgb(211, 211, 0); font: 15pt 'Arial';");
  506. ui->park->setEnabled(false);
  507. ui->park->setStyleSheet("border-image: url(:/new/pic/park_gray.png)");
  508. }
  509. mbHaveData = true;
  510. // if(p->mInfo.)
  511. data.clear();
  512. // }
  513. // memcpy(&packHead,data.data(),sizeof(packHead));
  514. }
  515. update();
  516. }
  517. void ADCIntelligentShow::onconnTimer()
  518. {
  519. qint64 xTime = QDateTime::currentMSecsSinceEpoch();
  520. if(recvFlag!=0)
  521. {
  522. //ui->connect->setText(QStringLiteral("已连接"));
  523. ui->connect->setStyleSheet("image: url(:/new/pic/connect.png);");
  524. if((abs(xTime - mnTimeGPS)>1000) &&(mnstylegps != 0))
  525. {
  526. ui->lng->setText(" ");
  527. ui->lat->setText(" ");
  528. ui->label->setText(QString::number(0));
  529. ui->localimg->setStyleSheet("background-image: url(:/new/pic/red.png);");
  530. mnstylegps = 0;
  531. }
  532. if((abs(xTime - mnTimeLidar)>1000) &&(mnstylelidar != 1))
  533. {
  534. ui->lidarimg->setStyleSheet("background-image: url(:/new/pic/red.png);");
  535. mnstylelidar = 1;
  536. }
  537. if((abs(xTime - mnTimeLidar)<1000) &&(mnstylelidar != 2))
  538. {
  539. ui->lidarimg->setStyleSheet("background-image: url(:/new/pic/green.png);");
  540. mnstylelidar = 2;
  541. }
  542. if((abs(xTime - mnTimeRADAR)>1000) && (mnstyleradar != 1))
  543. {
  544. ui->radarimg->setStyleSheet("background-image: url(:/new/pic/red.png);");
  545. mnstyleradar = 1;
  546. }
  547. if((abs(xTime - mnTimeRADAR)<1000) && (mnstyleradar != 2))
  548. {
  549. ui->radarimg->setStyleSheet("background-image: url(:/new/pic/green.png);");
  550. mnstyleradar = 2;
  551. }
  552. if(abs(xTime- mnTimeDection)>1000)
  553. {
  554. ui->acc->setText(" ");
  555. ui->swerve->setText(" ");
  556. ui->break_1->setText(" ");
  557. if(mnstylepark != 0)
  558. {
  559. ui->park->setText(QStringLiteral("不可泊车"));
  560. ui->park->setStyleSheet("background-image: url(:/new/pic/red.png);");
  561. ui->park->setEnabled(false);
  562. ui->park->setStyleSheet("border-image: url(:/new/pic/park_gray.png)");
  563. mnstylepark = 0;
  564. }
  565. }
  566. if(navigation_data.size()>0)
  567. {
  568. ui->mapimg->setStyleSheet("background-image: url(:/new/pic/green.png);");
  569. }
  570. else
  571. {
  572. ui->mapimg->setStyleSheet("background-image: url(:/new/pic/red.png);");
  573. }
  574. }
  575. else
  576. {
  577. //ui->connect->setText(QStringLiteral("未连接"));
  578. ui->connect->setStyleSheet("image: url(:/new/pic/connect_grey.png);");
  579. ui->pushButton->setEnabled(false);
  580. ui->pushButton->setStyleSheet("border-image: url(:/new/pic/button_gray.png);");
  581. ui->label->setText(QString::number(0));
  582. ui->runimg->setStyleSheet("background-image: url(:/new/pic/blue.png);");
  583. ui->mapimg->setStyleSheet("background-image: url(:/new/pic/blue.png);");
  584. ui->canimg->setStyleSheet("background-image: url(:/new/pic/blue.png);");
  585. ui->localimg->setStyleSheet("background-image: url(:/new/pic/blue.png);");
  586. ui->acc->setText(" ");
  587. ui->swerve->setText(" ");
  588. ui->lng->setText(" ");
  589. ui->lat->setText(" ");
  590. ui->radarob->setText(" ");
  591. ui->lidarob->setText(" ");
  592. ui->allob->setText(" ");
  593. ui->lidarimg->setStyleSheet("background-image: url(:/new/pic/blue.png);");
  594. ui->radarimg->setStyleSheet("background-image: url(:/new/pic/blue.png);");
  595. ui->park->setText(QStringLiteral("不可泊车"));
  596. ui->park->setStyleSheet("background-image: url(:/new/pic/red.png);");
  597. ui->park->setEnabled(false);
  598. ui->park->setStyleSheet("border-image: url(:/new/pic/park_gray.png)");
  599. mnstylegps = 0;
  600. mnstylelidar = 0;
  601. mnstylebrain = 0;
  602. mnstyleradar = 0;
  603. mnstylepark = 0;
  604. }
  605. // ui->acc->setText("-0.11111111");
  606. // ui->lat->setText("39.00000001");
  607. // ui->label_station->setText("TEXT.");
  608. recvFlag = 0;
  609. }
  610. void ADCIntelligentShow::onTimerPainter()
  611. {
  612. update();
  613. }
  614. //刷新
  615. void ADCIntelligentShow::paintEvent(QPaintEvent *)
  616. {
  617. // 绘制背景图
  618. mpainter_background = new QPainter(this);
  619. mpainter_background->drawPixmap(0, 0, this->width(), this->height(), QPixmap(":/new/pic/background2.jpg"));
  620. delete mpainter_background;
  621. if(mpivmapview->IsHaveNew())
  622. {
  623. QImage image = mpivmapview->GetImage();
  624. scene->clear();
  625. scene->addPixmap(QPixmap::fromImage(image));
  626. myview->setScene(scene);
  627. myview->show();
  628. }
  629. return;
  630. }
  631. bool ADCIntelligentShow::loadMapFromFile(std::string fileName) {
  632. std::ifstream fis(fileName);//获取文件
  633. std::string line;
  634. std::vector<std::string> des;
  635. if (fis.is_open() == false)
  636. return false;
  637. try {
  638. while (getline(fis, line)) {//开始一行一行的读数据
  639. des.clear();
  640. SplitString(line,des,"\t");
  641. //boost::split(des, line, boost::is_any_of("\t"));
  642. //if (des.size() != 10)
  643. // throw "error";
  644. if(des.size() < 10)
  645. throw "error";
  646. GPS_INS *data =new GPS_INS;
  647. data->index = atoi(des[0].c_str());
  648. data->gps_lng = atof(des[1].c_str());
  649. data->gps_lat = atof(des[2].c_str());
  650. data->speed_mode = atoi(des[3].c_str());
  651. data->mode2 = atoi(des[4].c_str());
  652. data->ins_heading_angle = atof(des[5].c_str());
  653. data->runMode = atoi(des[6].c_str());
  654. data->roadMode = atoi(des[7].c_str());
  655. data->roadSum = atoi(des[8].c_str());
  656. data->roadOri = atoi(des[9].c_str());
  657. //des[10].c_str() is the width of the road, and is no use.
  658. //Modified by map. 2019-12-02
  659. // gps2xy(data->gps_lat, data->gps_lng, &data->gps_x, &data->gps_y);
  660. GaussProjCal(data->gps_lng, data->gps_lat, &data->gps_x, &data->gps_y);
  661. //data->speed = 5; //调试用 所有点速度都设为5km/h
  662. //LOG2(data->gps_x, data->gps_y);
  663. //ODS("x %.20lf y %.20lf\n", data->gps_x, data->gps_y);
  664. // iv::decition::BLH2XYZ(*data); //重新转下大地坐标
  665. // navigation_data.push_back(data);
  666. }
  667. }
  668. catch (...) {
  669. fis.close();
  670. return false;
  671. }
  672. fis.close();
  673. return true;
  674. }
  675. //高斯投影由经纬度(Unit:DD)反算大地坐标(含带号,Unit:Metres)
  676. void ADCIntelligentShow::GaussProjCal(double longitude, double latitude, double *X, double *Y)
  677. {
  678. int ProjNo = 0; int ZoneWide; ////带宽
  679. double longitude1, latitude1, longitude0, X0, Y0, xval, yval;
  680. double a, f, e2, ee, NN, T, C, A, M, iPI;
  681. iPI = 0.0174532925199433; ////3.1415926535898/180.0;
  682. ZoneWide = 6; ////6度带宽
  683. a = 6378245.0; f = 1.0 / 298.3; //54年北京坐标系参数
  684. ////a=6378140.0; f=1/298.257; //80年西安坐标系参数
  685. ProjNo = (int)(longitude / ZoneWide);
  686. longitude0 = ProjNo * ZoneWide + ZoneWide / 2;
  687. longitude0 = longitude0 * iPI;
  688. //latitude0 = 0;
  689. longitude1 = longitude * iPI; //经度转换为弧度
  690. latitude1 = latitude * iPI; //纬度转换为弧度
  691. e2 = 2 * f - f * f;
  692. ee = e2 * (1.0 - e2);
  693. NN = a / sqrt(1.0 - e2 * sin(latitude1)*sin(latitude1));
  694. T = tan(latitude1)*tan(latitude1);
  695. C = ee * cos(latitude1)*cos(latitude1);
  696. A = (longitude1 - longitude0)*cos(latitude1);
  697. M = a * ((1 - e2 / 4 - 3 * e2*e2 / 64 - 5 * e2*e2*e2 / 256)*latitude1 -
  698. (3 * e2 / 8 + 3 * e2*e2 / 32 + 45 * e2*e2*e2 / 1024)*sin(2 * latitude1)
  699. + (15 * e2*e2 / 256 + 45 * e2*e2*e2 / 1024)*sin(4 * latitude1) -
  700. (35 * e2*e2*e2 / 3072)*sin(6 * latitude1));
  701. xval = NN * (A + (1 - T + C)*A*A*A / 6 + (5 - 18 * T + T * T + 72 * C - 58 * ee)*A*A*A*A*A / 120);
  702. yval = M + NN * tan(latitude1)*(A*A / 2 + (5 - T + 9 * C + 4 * C*C)*A*A*A*A / 24
  703. + (61 - 58 * T + T * T + 600 * C - 330 * ee)*A*A*A*A*A*A / 720);
  704. X0 = 1000000L * (ProjNo + 1) + 500000L;
  705. Y0 = 0;
  706. xval = xval + X0; yval = yval + Y0;
  707. *X = xval;
  708. *Y = yval;
  709. }
  710. void ADCIntelligentShow::SplitString(const string& s, vector<string>& v, const string& c)
  711. {
  712. string::size_type pos1, pos2;
  713. pos2 = s.find(c);
  714. pos1 = 0;
  715. while(string::npos != pos2)
  716. {
  717. v.push_back(s.substr(pos1, pos2-pos1));
  718. pos1 = pos2 + c.size();
  719. pos2 = s.find(c, pos1);
  720. }
  721. if(pos1 != s.length())
  722. v.push_back(s.substr(pos1));
  723. }
  724. void ADCIntelligentShow::on_park_clicked()
  725. {
  726. iv::hmi::hmimsg xhmi;
  727. xhmi.set_mbbochemode(true);
  728. xhmi.set_mbbusmode(false);
  729. xhmi.set_mbpause(false);
  730. // if(mbRunning)
  731. // xhmi.set_mbpause(true);
  732. // else
  733. // xhmi.set_mbpause(false);
  734. int nsize = xhmi.ByteSize();
  735. char * str = new char[nsize];
  736. if(xhmi.SerializeToArray(str,1000))
  737. {
  738. #ifndef Android
  739. iv::modulecomm::ModuleSendMsg(mpapad,str,nsize);
  740. #else
  741. ggt->UpdateData(str,nsize,"pad");
  742. #endif
  743. }
  744. else
  745. {
  746. std::cout<<"ADCIntelligentShow::on_pushButton_clicked serialize error."<<std::endl;
  747. }
  748. delete str;
  749. QApplication::beep();
  750. return;
  751. int xRun = 2;
  752. socket->writeDatagram((char *)&xRun,4,QHostAddress::Broadcast,9998);
  753. QApplication::beep();
  754. }
  755. void ADCIntelligentShow::onlidarRecv()
  756. {
  757. while(lidarsock->hasPendingDatagrams())
  758. {
  759. QByteArray data;
  760. data.resize(lidarsock->pendingDatagramSize());
  761. lidarsock->readDatagram(data.data(),data.size());
  762. // packageHead packHead;
  763. qDebug("size = %d",data.size());
  764. //if(data.size() == sizeof(DataToUI))
  765. //{
  766. memcpy(&mlidarpoint,data.data(),data.size());
  767. qDebug("size:%d",DataUI->mHead.size);
  768. }
  769. }
  770. ////一键叫车
  771. //void ADCIntelligentShow::on_onekey_clicked()
  772. //{
  773. // int res = QMessageBox::warning(NULL,"警告","确认是否一键叫车",QMessageBox::Yes,QMessageBox::No);
  774. // if(res==QMessageBox::Yes)
  775. // {
  776. // int xRun = 3;
  777. // socket->writeDatagram((char *)&xRun,4,QHostAddress::Broadcast,9998);
  778. // }
  779. // else
  780. // {
  781. // int xRun = 4;
  782. // socket->writeDatagram((char *)&xRun,4,QHostAddress::Broadcast,9998);
  783. // }
  784. //}
  785. void ADCIntelligentShow::on_pushButton_2_clicked()
  786. {
  787. std::cout<<"click "<<std::endl;
  788. iv::hmi::hmimsg xhmi;
  789. xhmi.set_mbbochemode(true);
  790. xhmi.set_mbbusmode(false);
  791. if(mbRunning)
  792. xhmi.set_mbpause(false);
  793. else
  794. xhmi.set_mbpause(true);
  795. int nsize = xhmi.ByteSize();
  796. char * str = new char[nsize];
  797. if(xhmi.SerializeToArray(str,1000))
  798. {
  799. #ifndef Android
  800. iv::modulecomm::ModuleSendMsg(mpapad,str,nsize);
  801. #else
  802. ggt->UpdateData(str,nsize,"pad");
  803. #endif
  804. }
  805. else
  806. {
  807. std::cout<<"ADCIntelligentShow::on_pushButton_clicked serialize error."<<std::endl;
  808. }
  809. delete str;
  810. QApplication::beep();
  811. return;
  812. //QMessageBox::styleSheet("background-color: rgb(140, 140, 140);");
  813. int res = QMessageBox::warning(NULL,"警告","确认是否重新启动",QMessageBox::Yes,QMessageBox::No);
  814. if(res==QMessageBox::Yes)
  815. {
  816. int xRun = 9;
  817. socket->writeDatagram((char *)&xRun,4,QHostAddress::Broadcast,9998);
  818. }
  819. }
  820. void ADCIntelligentShow::slotAlarm()
  821. {
  822. if(soundAlarm->isFinished())
  823. soundAlarm->play();
  824. }
  825. void ADCIntelligentShow::UpdateGPSIMU(iv::gps::gpsimu *pgpsimu)
  826. {
  827. iv::gps::gpsimu xgpsimu;
  828. xgpsimu.CopyFrom(*pgpsimu);
  829. mMutexGPSIMU.lock();
  830. mgpsimu.CopyFrom(*pgpsimu);
  831. mMutexGPSIMU.unlock();
  832. emit signalGPSIMU();
  833. mnTimeGPS = QDateTime::currentMSecsSinceEpoch();
  834. }
  835. void ADCIntelligentShow::UpdateOBS(std::shared_ptr<std::vector<iv::ObstacleBasic> > xobs)
  836. {
  837. recvFlag = 1;
  838. mpivmapview->setobs(xobs);
  839. mnTimeLidar = QDateTime::currentMSecsSinceEpoch();
  840. }
  841. void ADCIntelligentShow::onUpdateGPSIMU()
  842. {
  843. recvFlag = 1;
  844. iv::gps::gpsimu xgpsimu;
  845. mMutexGPSIMU.lock();
  846. xgpsimu.CopyFrom(mgpsimu);
  847. mMutexGPSIMU.unlock();
  848. mpivmapview->setgps(&xgpsimu);
  849. ui->lng->setText(QString::number(xgpsimu.lon(),'f',7));
  850. ui->lat->setText(QString::number(xgpsimu.lat(),'f',7));
  851. if(xgpsimu.rtk_state() == 6)
  852. {
  853. ui->local->setText(QStringLiteral("定位:")+QString::number(xgpsimu.rtk_state()));
  854. if(mnstylegps != 1)
  855. {
  856. ui->local->setStyleSheet("color: rgb(220, 220, 220); font: 30px 'Arial';");
  857. ui->localimg->setStyleSheet("background-image: url(:/new/pic/green.png);");
  858. mnstylegps = 1;
  859. }
  860. }
  861. else
  862. {
  863. ui->local->setText(QStringLiteral("定位:")+QString::number(xgpsimu.rtk_state()));
  864. if(mnstylegps != 2)
  865. {
  866. ui->local->setStyleSheet("color: rgb(220, 220, 220); font: 30px 'Arial';");
  867. ui->localimg->setStyleSheet("background-image: url(:/new/pic/red.png);");
  868. mnstylegps = 2;
  869. }
  870. }
  871. ui->label->setText(QString::number((sqrt(pow(xgpsimu.ve(),2)+pow(xgpsimu.vn(),2))*3.6),'f',1));
  872. }
  873. void ADCIntelligentShow::UpdateMap(const char *mapdata, const int mapdatasize)
  874. {
  875. std::cout<<"update map "<<std::endl;
  876. int gpsunitsize = sizeof(iv::MAP_GPS_INS);
  877. int nMapSize = mapdatasize/gpsunitsize;
  878. // std::cout<<"map size is "<<nMapSize<<std::endl;
  879. if(nMapSize < 1)return;
  880. bool bUpdate = false;
  881. if(nMapSize != navigation_data.size())
  882. {
  883. bUpdate = true;
  884. }
  885. else
  886. {
  887. iv::MAP_GPS_INS * p = (iv::MAP_GPS_INS *)mapdata;
  888. if((p->gps_lat == navigation_data.at(0).gps_lat)&&(p->ins_heading_angle == navigation_data.at(0).ins_heading_angle))
  889. {
  890. // qDebug("same map");
  891. bUpdate = false;
  892. }
  893. else
  894. {
  895. bUpdate = true;
  896. }
  897. }
  898. if(bUpdate)
  899. {
  900. int i;
  901. mMutexMap.lock();
  902. navigation_data.clear();
  903. for(i=0;i<nMapSize;i++)
  904. {
  905. iv::MAP_GPS_INS x;
  906. GaussProjCal(x.gps_lng,x.gps_lat,&x.gps_x,&x.gps_y);
  907. memcpy(&x,mapdata + i*gpsunitsize,gpsunitsize);
  908. navigation_data.push_back(x);
  909. }
  910. mMutexMap.unlock();
  911. mpivmapview->setmap(navigation_data);
  912. // mpasd->SaveState("map",mapdata,mapdatasize);
  913. }
  914. else
  915. {
  916. // qDebug("not need update");
  917. }
  918. }
  919. void ADCIntelligentShow::UpdateBrainState(iv::brain::brainstate xbrainstate)
  920. {
  921. recvFlag = 1;
  922. mMutexBrain.lock();
  923. mbrainstate.CopyFrom(xbrainstate);
  924. mMutexBrain.unlock();
  925. mnTimeBrain = QDateTime::currentMSecsSinceEpoch();
  926. emit signalbrainstate();
  927. }
  928. void ADCIntelligentShow::onUpdateBrainState()
  929. {
  930. recvFlag = 1;
  931. iv::brain::brainstate xbrainstate;
  932. mMutexBrain.lock();
  933. xbrainstate.CopyFrom(mbrainstate);
  934. mMutexBrain.unlock();
  935. ui->pushButton->setEnabled(true);
  936. if(xbrainstate.mbbrainrunning())
  937. {
  938. mbRunning = true;
  939. if(mnstylebrain != 2)
  940. {
  941. ui->runimg->setStyleSheet("background-image: url(:/new/pic/green.png);");
  942. ui->pushButton->setStyleSheet("border-image: url(:/new/pic/button_stop.png);");
  943. mnstylebrain = 2;
  944. }
  945. ui->radarob->setText(QString::number(xbrainstate.mfradarobs(),'f',2));
  946. ui->lidarob->setText(QString::number(xbrainstate.mflidarobs(),'f',2));
  947. ui->allob->setText(QString::number(xbrainstate.mfobs(),'f',2));
  948. }
  949. else
  950. {
  951. mbRunning = false;
  952. if(mnstylebrain != 1)
  953. {
  954. ui->runimg->setStyleSheet("background-image: url(:/new/pic/red.png);");
  955. ui->pushButton->setStyleSheet("border-image: url(:/new/pic/button_green.png);");
  956. mnstylebrain = 1;
  957. }
  958. ui->radarob->setText(" ");
  959. ui->lidarob->setText(" ");
  960. ui->allob->setText(" ");
  961. }
  962. if(xbrainstate.mbbocheenable())
  963. {
  964. if(mnstylepark != 2)
  965. {
  966. mnstylepark = 2;
  967. ui->park->setText(QStringLiteral("可泊车"));
  968. ui->park->setStyleSheet("background-image: url(:/new/pic/green.png);");
  969. ui->park->setEnabled(true);
  970. ui->park->setStyleSheet("border-image: url(:/new/pic/park.png)");
  971. }
  972. }
  973. else
  974. {
  975. if(mnstylepark != 1)
  976. {
  977. ui->park->setText(QStringLiteral("不可泊车"));
  978. ui->park->setStyleSheet("background-image: url(:/new/pic/red.png);");
  979. ui->park->setEnabled(false);
  980. ui->park->setStyleSheet("border-image: url(:/new/pic/park_gray.png)");
  981. mnstylepark = 1;
  982. }
  983. }
  984. }
  985. void ADCIntelligentShow::UpdateDection(iv::brain::decition xdecision )
  986. {
  987. mMutexDecision.lock();
  988. mdecision.CopyFrom(xdecision);
  989. mMutexDecision.unlock();
  990. emit signaldection();
  991. mnTimeDection = QDateTime::currentMSecsSinceEpoch();
  992. }
  993. void ADCIntelligentShow::onUpdateDection()
  994. {
  995. iv::brain::decition xdecision;
  996. mMutexDecision.lock();
  997. xdecision.CopyFrom(mdecision);
  998. mMutexDecision.unlock();
  999. ui->acc->setText(QString::number(xdecision.torque(),'f',1));
  1000. ui->swerve->setText(QString::number(xdecision.wheelangle(),'f',1));
  1001. ui->break_1->setText(QString::number(xdecision.brake(),'f',2));
  1002. }
  1003. void ADCIntelligentShow::UpdateRADAR(iv::radar::radarobjectarray *pxobj)
  1004. {
  1005. recvFlag = 1;
  1006. mMutexRadar.lock();
  1007. mradarobj.CopyFrom(*pxobj);
  1008. mMutexRadar.unlock();
  1009. mnTimeRADAR = QDateTime::currentMSecsSinceEpoch();
  1010. mpivmapview->setradar(pxobj);
  1011. }
  1012. void ADCIntelligentShow::UpdateOTAVehInfo(iv::veh::vehinfo &pvehinfo)
  1013. {
  1014. mMutexVehInfo.lock();
  1015. mvehinfo.CopyFrom(pvehinfo);
  1016. mMutexVehInfo.unlock();
  1017. mnVehInfoTime = QDateTime::currentMSecsSinceEpoch();
  1018. emit signalvehinfoupdate();
  1019. }
  1020. void ADCIntelligentShow::on_pushButton_nextstation_clicked()
  1021. {
  1022. if(gvectorpos.size()<1)return;
  1023. mnStationIndex++;
  1024. if(mnStationIndex>=gvectorpos.size())mnStationIndex = 0;
  1025. ui->label_station->setText(gvectorpos[mnStationIndex].mstrstationname.data());
  1026. }
  1027. void ADCIntelligentShow::on_pushButton_prestation_clicked()
  1028. {
  1029. if(gvectorpos.size()<1)return;
  1030. mnStationIndex--;
  1031. if(mnStationIndex<0)mnStationIndex = gvectorpos.size()-1;
  1032. ui->label_station->setText(gvectorpos[mnStationIndex].mstrstationname.data());
  1033. }
  1034. void ADCIntelligentShow::on_pushButton_go_clicked()
  1035. {
  1036. if(gvectorpos.size()<1)return;
  1037. qDebug("set plan.lon:%f lat:%f index:%d",gvectorpos[mnStationIndex].mflon,gvectorpos[mnStationIndex].mflat,mnStationIndex);
  1038. xodrobj xo;
  1039. xo.flon = gvectorpos[mnStationIndex].mflon;
  1040. xo.flat = gvectorpos[mnStationIndex].mflat;
  1041. xo.lane = mndefaultlane;
  1042. #ifndef Android
  1043. iv::modulecomm::ModuleSendMsg(mpadst,(char *)&xo,sizeof(xodrobj));
  1044. #else
  1045. ggt->UpdateData((char *)&xo,sizeof(xodrobj),"xodrreq");
  1046. #endif
  1047. }
  1048. void ADCIntelligentShow::onSwitchClick(int nswitch)
  1049. {
  1050. iv::hmi::hmimsg xhmi;
  1051. xhmi.set_mbbochemode(false);
  1052. xhmi.set_mbbusmode(false);
  1053. if(mbRunning)
  1054. xhmi.set_mbpause(false);
  1055. else
  1056. xhmi.set_mbpause(true);
  1057. switch (nswitch) {
  1058. case 0:
  1059. xhmi.set_mbchemen(true);
  1060. break;
  1061. case 1:
  1062. xhmi.set_mbchemen(false);
  1063. break;
  1064. case 2:
  1065. xhmi.set_mbjinguang(true);
  1066. break;
  1067. case 3:
  1068. xhmi.set_mbjinguang(false);
  1069. break;
  1070. case 4:
  1071. xhmi.set_mbyuanguang(true);
  1072. break;
  1073. case 5:
  1074. xhmi.set_mbyuanguang(false);
  1075. break;
  1076. default:
  1077. break;
  1078. }
  1079. int nsize = xhmi.ByteSize();
  1080. std::shared_ptr<char> pstr = std::shared_ptr<char>(new char[nsize]);
  1081. if(xhmi.SerializeToArray(pstr.get(),1000))
  1082. {
  1083. #ifndef Android
  1084. iv::modulecomm::ModuleSendMsg(mpapad,pstr.get(),nsize);
  1085. #else
  1086. ggt->UpdateData(pstr.get(),nsize,"pad");
  1087. #endif
  1088. }
  1089. else
  1090. {
  1091. std::cout<<"ADCIntelligentShow::on_pushButton_clicked serialize error."<<std::endl;
  1092. }
  1093. return;
  1094. }
  1095. void ADCIntelligentShow::onModeClick(int nMode)
  1096. {
  1097. iv::hmi::hmimsg xhmi;
  1098. xhmi.set_mbbochemode(false);
  1099. xhmi.set_mbbusmode(false);
  1100. if(mbRunning)
  1101. xhmi.set_mbpause(false);
  1102. else
  1103. xhmi.set_mbpause(true);
  1104. xhmi.set_mmode(nMode);
  1105. int nsize = xhmi.ByteSize();
  1106. std::shared_ptr<char> pstr = std::shared_ptr<char>(new char[nsize]);
  1107. if(xhmi.SerializeToArray(pstr.get(),1000))
  1108. {
  1109. #ifndef Android
  1110. iv::modulecomm::ModuleSendMsg(mpapad,pstr.get(),nsize);
  1111. #else
  1112. ggt->UpdateData(pstr.get(),nsize,"pad");
  1113. #endif
  1114. }
  1115. else
  1116. {
  1117. std::cout<<"ADCIntelligentShow::on_pushButton_clicked serialize error."<<std::endl;
  1118. }
  1119. return;
  1120. }
  1121. void ADCIntelligentShow::on_pushButton_Setting_clicked()
  1122. {
  1123. mpDS->show();
  1124. }
  1125. void ADCIntelligentShow::on_pushButton_AddStation_clicked()
  1126. {
  1127. bool ok;
  1128. QString strpass = QInputDialog::getText(this,tr("Check PassWord"),tr("password:"),QLineEdit::Password,
  1129. tr(""), &ok);
  1130. if(ok == false)
  1131. {
  1132. return;
  1133. }
  1134. if(strpass != "adc")
  1135. {
  1136. QMessageBox::warning(this,tr("Warning"),tr("Password Error."),QMessageBox::YesAll);
  1137. return;
  1138. }
  1139. QString strstationname = QInputDialog::getText(this,tr("Add Station"),tr("Station Name:"),QLineEdit::Normal,
  1140. tr(""), &ok);
  1141. if(ok == false)
  1142. {
  1143. return;
  1144. }
  1145. unsigned int i;
  1146. for(i=0;i<gvectorpos.size();i++)
  1147. {
  1148. if(gvectorpos[i].mstrstationname == strstationname.toStdString())
  1149. {
  1150. QMessageBox::warning(this,tr("Warning"),tr("Have Same Name Station"),QMessageBox::YesAll);
  1151. return;
  1152. }
  1153. }
  1154. iv::pos_def xpos;
  1155. if(mnTimeGPS == 0)
  1156. {
  1157. xpos.mflon = QInputDialog::getDouble(this,tr("Set Longitude"),tr("Longitude:"),119.0,0.0,180.0,7,&ok);
  1158. if(ok == false)
  1159. {
  1160. return;
  1161. }
  1162. xpos.mflat = QInputDialog::getDouble(this,tr("Set Latitude"),tr("Latitude:"),39.0,0.0,90.0,7,&ok);
  1163. if(ok == false)
  1164. {
  1165. return;
  1166. }
  1167. }
  1168. else
  1169. {
  1170. iv::gps::gpsimu xgpsimu;
  1171. mMutexGPSIMU.lock();
  1172. xgpsimu.CopyFrom(mgpsimu);
  1173. mMutexGPSIMU.unlock();
  1174. xpos.mflat = xgpsimu.lat();
  1175. xpos.mflon = xgpsimu.lon();
  1176. }
  1177. xpos.mstrstationname = strstationname.toStdString();
  1178. gvectorpos.push_back(xpos);
  1179. char strout[300];
  1180. snprintf(strout,300,"Add Station %s, Lon:%11.7f, Lat:%11.7f",xpos.mstrstationname.data(),xpos.mflon,xpos.mflat);
  1181. QMessageBox::information(this,tr("Info"),strout,QMessageBox::YesAll);
  1182. if(gvectorpos.size() == 1)
  1183. {
  1184. mnStationIndex = 0;
  1185. ui->label_station->setText(gvectorpos[0].mstrstationname.data());
  1186. }
  1187. WritePos();
  1188. // QMessageBox::information(this,"info","info",QMessageBox::YesAll);
  1189. }
  1190. void ADCIntelligentShow::on_pushButton_DelStation_clicked()
  1191. {
  1192. if(gvectorpos.size() == 0)
  1193. {
  1194. QMessageBox::warning(this,tr("Warning"),tr("No Station."),QMessageBox::YesAll);
  1195. return;
  1196. }
  1197. bool ok;
  1198. QString strpass = QInputDialog::getText(this,tr("Check PassWord"),tr("password:"),QLineEdit::Password,
  1199. tr(""), &ok);
  1200. if(ok == false)
  1201. {
  1202. return;
  1203. }
  1204. if(strpass != "adc")
  1205. {
  1206. QMessageBox::warning(this,tr("Warning"),tr("Password Error."),QMessageBox::YesAll);
  1207. return;
  1208. }
  1209. iv::pos_def xpos;
  1210. if(mnStationIndex >= static_cast<int>(gvectorpos.size()) )
  1211. {
  1212. return;
  1213. }
  1214. if(mnStationIndex<0)
  1215. {
  1216. return;
  1217. }
  1218. xpos = gvectorpos[static_cast<unsigned long >(mnStationIndex) ];
  1219. gvectorpos.erase(gvectorpos.begin()+mnStationIndex);
  1220. WritePos();
  1221. if(gvectorpos.size() == 0)
  1222. {
  1223. ui->label_station->setText("");
  1224. return;
  1225. }
  1226. if(mnStationIndex >= static_cast<int>(gvectorpos.size()) )
  1227. {
  1228. mnStationIndex = 0;
  1229. }
  1230. if(mnStationIndex<0)mnStationIndex = static_cast<int>(gvectorpos.size()-1) ;
  1231. ui->label_station->setText(gvectorpos[static_cast<unsigned long>(mnStationIndex)].mstrstationname.data());
  1232. char strout[300];
  1233. snprintf(strout,300,"Delete Station %s, Lon:%11.7f, Lat:%11.7f SuccessFully ",xpos.mstrstationname.data(),xpos.mflon,xpos.mflat);
  1234. QMessageBox::information(this,tr("Info"),strout,QMessageBox::YesAll);
  1235. }
  1236. bool ADCIntelligentShow::WritePos()
  1237. {
  1238. QString strfilepath;
  1239. // strfilepath = "pos.txt";
  1240. #ifndef Android
  1241. strfilepath = "pos.txt";
  1242. #else
  1243. strfilepath = "/storage/emulated/0/pos.txt";
  1244. #endif
  1245. QFile xFile;
  1246. xFile.setFileName(strfilepath);
  1247. if(!xFile.open(QIODevice::ReadWrite))
  1248. {
  1249. return false;
  1250. }
  1251. xFile.resize(0);
  1252. unsigned int i;
  1253. for(i=0;i<gvectorpos.size();i++)
  1254. {
  1255. char strline[1000];
  1256. snprintf(strline,1000,"%s\t%11.7f\t%11.7f\n",gvectorpos[i].mstrstationname.data(),gvectorpos[i].mflon,gvectorpos[i].mflat);
  1257. xFile.write(strline,static_cast<qint64>(strnlen(strline,1000)) );
  1258. }
  1259. xFile.close();
  1260. return true;
  1261. }
  1262. void ADCIntelligentShow::onOTAVehInfoUpdate()
  1263. {
  1264. iv::veh::vehinfo xvehinfo;
  1265. mMutexVehInfo.lock();
  1266. xvehinfo.CopyFrom(mvehinfo);
  1267. mMutexVehInfo.unlock();
  1268. char strout[1000];
  1269. snprintf(strout,1000,"Type:%s Version:%s VIN:%s",xvehinfo.type().data(),xvehinfo.version().data(),xvehinfo.vin().data());
  1270. ui->label_vehinfo->setText(strout);
  1271. }
  1272. void ADCIntelligentShow::UpdateFusion(iv::fusion::fusionobjectarray &xfusion)
  1273. {
  1274. mpivmapview->setfusion(xfusion);
  1275. mnTimeLidar = QDateTime::currentMSecsSinceEpoch();
  1276. }