mainwindow.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QtMath>
  4. extern std::string gstrcarvin;
  5. extern std::string gstrobuvin;
  6. extern iv::Ivlog * gIvlog;
  7. MainWindow::MainWindow(QWidget *parent) :
  8. QMainWindow(parent),
  9. ui(new Ui::MainWindow)
  10. {
  11. ui->setupUi(this);
  12. m_pc5=new PC5();
  13. m_tbox=new V2X();
  14. timer = new QTimer(this);
  15. connect(timer,SIGNAL(timeout()),SLOT(heartBeat()));
  16. //timer->start(1000);
  17. timer->start(500);
  18. sendProto_flag=false;
  19. initUI();
  20. initMemory();
  21. initproto();
  22. initLight1();
  23. initLight2();
  24. }
  25. void MainWindow::initMemory()
  26. {
  27. m_structMGpsImu.gps_lat=39.149170;
  28. m_structMGpsImu.gps_lng=117.094250;
  29. m_structMGpsImu.speed=0.0;
  30. m_structMGpsImu.yaw=0.0;
  31. m_structMGpsImu.accx=0.0;
  32. m_structMGpsImu.accy=0.0;
  33. seneor_m.lidar_left=0;
  34. seneor_m.lidar_mid=0;
  35. seneor_m.lidar_right=0;
  36. seneor_m.radar=0;
  37. seneor_m.gps_flag=0;
  38. seneor_m.camera_front=0;
  39. seneor_m.camera_back=0;
  40. seneor_m.camera_left=0;
  41. seneor_m.camera_right=0;
  42. m_tbox->setSensorMemmory(seneor_m);
  43. setTboxMemoryRaw();
  44. m_pc5->setGpsImuMemory(m_structMGpsImu);
  45. }
  46. void MainWindow::initproto()
  47. {
  48. mpmem_radio_send_addr = iv::modulecomm::RegisterSend("v2r_send",1000,3);
  49. ModuleFun fungpsimu =std::bind(&MainWindow::UpdateGps,this,std::placeholders::_1, \
  50. std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  51. mpMemGPS = iv::modulecomm::RegisterRecvPlus(gstrmemgps.data(),fungpsimu);
  52. // mpMemGPS = iv::modulecomm::RegisterRecv("hcp_gpsimu",iv::V2X::UpdateGps);
  53. ModuleFun funcamera =std::bind(&MainWindow::UpdateCAM,this,std::placeholders::_1, \
  54. std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  55. mpMemcamera=iv::modulecomm::RegisterRecvPlus(gstrmecamera.data(),funcamera);
  56. ModuleFun funlidar =std::bind(&MainWindow::UpdateLIDAR,this,std::placeholders::_1, \
  57. std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  58. mpMemlidar=iv::modulecomm::RegisterRecvPlus(gstrmelidar.data(),funlidar);
  59. ModuleFun funradar =std::bind(&MainWindow::UpdateRADAR,this,std::placeholders::_1, \
  60. std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  61. mpMemradar=iv::modulecomm::RegisterRecvPlus(gstrmeradar.data(),funradar);
  62. ModuleFun lightState =std::bind(&MainWindow::Updatelight,this,std::placeholders::_1, \
  63. std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  64. vision_lightMem = iv::modulecomm::RegisterRecvPlus(gstrmemlight.data(),lightState);
  65. }
  66. void MainWindow::initUI()
  67. {
  68. redimg.load(":/light/light/zhixing-red.png");
  69. redimg = redimg.scaled(66,66,Qt::IgnoreAspectRatio);
  70. greenimg.load(":/light/light/zhixing-green.png");
  71. greenimg = greenimg.scaled(66,66,Qt::IgnoreAspectRatio);
  72. yellowimg.load(":/light/light/zhixing-yellow.png");
  73. yellowimg = yellowimg.scaled(66,66,Qt::IgnoreAspectRatio);
  74. blackimg.load(":/light/light/zhixing-black.png");
  75. blackimg = blackimg.scaled(66,66,Qt::IgnoreAspectRatio);
  76. QString strpath = QCoreApplication::applicationDirPath();
  77. //strpath = strpath + "/v2xTcpClientWL.xml";
  78. strpath = "./v2xTcpClient.xml";
  79. iv::xmlparam::Xmlparam xp(strpath.toStdString());
  80. std::string strCarVIN = xp.GetParam("carVIN","catarc001");
  81. ui->lineEdit->setText(QString::fromStdString(strCarVIN));
  82. std::string strObuVIN = xp.GetParam("obuNUM","1");
  83. ui->lineEdit_obu_vin->setText(QString::fromStdString(strObuVIN));
  84. int obunum=std::stoi(strObuVIN);
  85. std::string hostIP = xp.GetParam("hostIP","127.0.0.1");
  86. QString IP =QString::fromStdString(hostIP);
  87. ui->lineEdit_severip->setText(IP);
  88. std::string hostPort = xp.GetParam("hostPort","8000");
  89. int port=std::stoi(hostPort);
  90. std::string localIP = xp.GetParam("port_name","/dev/ttyUSB0");
  91. QString localsetIP =QString::fromStdString(localIP);
  92. std::string localPort = xp.GetParam("baud","9600");
  93. int localsetport=std::stoi(localPort);
  94. gstrmemgps = xp.GetParam("gps","gpsimu");
  95. gstrmecamera = xp.GetParam("camera","rawpic");
  96. gstrmelidar = xp.GetParam("lidar","lidarstate");
  97. gstrmeradar = xp.GetParam("radar","radarobject");
  98. gstrmemlight = xp.GetParam("vision_light","lightarray");
  99. std::string Stophead1 = xp.GetParam("light1Stophead","0");
  100. light1Stophead=std::stod(Stophead1);
  101. std::string StopLat1 = xp.GetParam("light1StopLat","0");
  102. light1StopLat=std::stod(StopLat1);
  103. std::string StopLon1 = xp.GetParam("light1StopLon","0");
  104. light1StopLon=std::stod(StopLon1);
  105. std::string Stophead2 = xp.GetParam("light2Stophead","0");
  106. light2Stophead=std::stod(Stophead2);
  107. std::string StopLat2 = xp.GetParam("light2StopLat","0");
  108. light2StopLat=std::stod(StopLat2);
  109. std::string StopLon2 = xp.GetParam("light2StopLon","0");
  110. light2StopLon=std::stod(StopLon2);
  111. std::string visionsend = xp.GetParam("OpenVisionSend","0");
  112. visionsendstate=std::stoi(visionsend);
  113. visionflag=visionsendstate;
  114. m_pc5->setVin(strCarVIN);
  115. m_pc5->setobuNewVin(obunum);
  116. m_pc5->setSerial(localsetIP,localsetport);
  117. m_tbox->setTboxNewVin(strCarVIN);
  118. m_tbox->setIPandPort(IP,port);
  119. }
  120. void MainWindow::initLight1()
  121. {
  122. ui->label_33->setPixmap(QPixmap::fromImage(blackimg));
  123. ui->label_38->setPixmap(QPixmap::fromImage(blackimg));
  124. ui->label_35->setPixmap(QPixmap::fromImage(blackimg));
  125. ui->lcdgreen->display(0);
  126. ui->lcdyellow->display(0);
  127. ui->lcdred->display(0);
  128. }
  129. void MainWindow::initLight2()
  130. {
  131. ui->label_39->setPixmap(QPixmap::fromImage(blackimg));
  132. ui->label_40->setPixmap(QPixmap::fromImage(blackimg));
  133. ui->label_41->setPixmap(QPixmap::fromImage(blackimg));
  134. ui->lcdgreen_2->display(0);
  135. ui->lcdyellow_2->display(0);
  136. ui->lcdred_2->display(0);
  137. }
  138. void MainWindow::heartBeat()
  139. {
  140. protobuf.Clear();
  141. //-----------------------------------------send runflag---------------------------------------------------------
  142. if (mRunmodEn)
  143. {
  144. bool runmod=m_tbox->upRunMod();
  145. //qDebug()<<runmod;
  146. outmbpause(runmod);
  147. sendProto_flag=true;
  148. }
  149. //-----------------------------------------获取连接状态---------------------------------------------------------
  150. if(mobuEn)
  151. {
  152. bool radio_flag=m_pc5->isLinked();//路测连接状态
  153. if (radio_flag)
  154. {
  155. ui->button_obu_en->setStyleSheet("background-color: green");
  156. }
  157. else
  158. {
  159. ui->button_obu_en->setStyleSheet("background-color: red");
  160. }
  161. if (mshowdebugEn)
  162. {
  163. QByteArray pc5_read=m_pc5->show_readdata();
  164. QByteArray pc5_error=m_pc5->show_error();
  165. ui->textBrowser_3->append(QTime::currentTime().toString("hh:mm:ss.zzz")+"接收:"+pc5_read);
  166. ui->textBrowser_4->append(QTime::currentTime().toString("hh:mm:ss.zzz")+":"+pc5_error);
  167. }
  168. }
  169. if (mplatformEn)
  170. {
  171. bool v2x_flag=m_tbox->isLinked();//云平台连接状态
  172. if (v2x_flag)
  173. {
  174. ui->button_platform_en->setStyleSheet("background-color: green");
  175. }
  176. else
  177. {
  178. ui->button_platform_en->setStyleSheet("background-color: red");
  179. }
  180. if (mshowdebugEn)
  181. {
  182. QByteArray v2x_read=m_tbox->show_readdata();
  183. QByteArray v2x_error=m_tbox->show_error();
  184. ui->textBrowser->append(QTime::currentTime().toString("hh:mm:ss.zzz")+"接收:"+v2x_read);
  185. ui->textBrowser_2->append(QTime::currentTime().toString("hh:mm:ss.zzz")+":"+v2x_error);
  186. }
  187. }
  188. //-----------------------------------------延时清空传感器状态---------------------------------------------------------
  189. if(mGPSs>0)
  190. {
  191. mGPSs--;
  192. if (mGPSs<=0)
  193. {
  194. seneor_m.gps_flag=0x00;
  195. m_tbox->setSensorMemmory(seneor_m);
  196. }
  197. }
  198. if(mCAMs>0)
  199. {
  200. mCAMs--;
  201. if(mCAMs<=0)
  202. {
  203. seneor_m.camera_back=0x00;
  204. seneor_m.camera_front=0x00;
  205. seneor_m.camera_left=0x00;
  206. seneor_m.camera_right=0x00;
  207. m_tbox->setSensorMemmory(seneor_m);
  208. }
  209. }
  210. if(mLIDARs>0)
  211. {
  212. mLIDARs--;
  213. if(mLIDARs<=0)
  214. {
  215. seneor_m.lidar_left=0x00;
  216. seneor_m.lidar_mid=0x00;
  217. seneor_m.lidar_right=0x00;
  218. m_tbox->setSensorMemmory(seneor_m);
  219. }
  220. }
  221. if(mRADARs>0)
  222. {
  223. mRADARs--;
  224. if (mRADARs<=0)
  225. {
  226. seneor_m.radar=0x00;
  227. m_tbox->setSensorMemmory(seneor_m);
  228. }
  229. }
  230. //---------------------------------------路况信息显示-----------------------------------------------------------
  231. if (mbTrafficInfoEn)
  232. {
  233. TrafficMessage=m_pc5->ui_RealtimeTraffic();
  234. if (TrafficMessage.isEnable)
  235. {
  236. QString event;
  237. ui->button_trafficInfoLight_st->setStyleSheet("background-color: green");
  238. switch(TrafficMessage.trafficInfo){
  239. case 0:
  240. event="无";
  241. ui->lineEd_trafficInfo->setText("正常行驶");
  242. break;
  243. case 3 :
  244. event="道路结冰";
  245. //ui->lineEd_trafficInfo->setText("减速至 " + QString::number(TrafficMessage.speedLimit) + "km/h");
  246. ui->lineEd_trafficInfo->setText("减速慢行");
  247. break;
  248. case 4:
  249. event="前方限速";
  250. ui->lineEd_trafficInfo->setText("减速至 " + QString::number(TrafficMessage.speedLimit) + "km/h");
  251. break;
  252. case 1 :
  253. event="塌方";
  254. ui->lineEd_trafficInfo->setText("停车");
  255. break;
  256. case 2 :
  257. event="施工";
  258. ui->lineEd_trafficInfo->setText("停车");
  259. break;
  260. default:
  261. break;
  262. }
  263. ui->textBr_trafficInfo->append(QTime::currentTime().toString("hh:mm:ss.zzz") + \
  264. "\n\t事件范围[ 经度:" + QString::number(TrafficMessage.lng,'g',10) +\
  265. " 纬度:" + QString::number(TrafficMessage.lat,'g',10) + \
  266. " ]\n\t辐射范围: " + QString::number(TrafficMessage.scope) + "米" + \
  267. "\n\t事件类型: " + event);
  268. outRealtimeTraffic(TrafficMessage);
  269. sendProto_flag=true;
  270. }
  271. else
  272. {
  273. ui->button_trafficInfoLight_st->setStyleSheet("background-color: gray");
  274. ui->textBr_trafficInfo->append("连接丢失");
  275. }
  276. }
  277. //-----------------------------------------碰撞预警显示---------------------------------------------------------
  278. if (mbFCWEn)
  279. {
  280. collisionWarning=m_pc5->ui_Warning();
  281. if (collisionWarning.isEnable)
  282. {
  283. ui->button_FWCLight_st->setStyleSheet("background-color: green");
  284. switch (collisionWarning.warningType)
  285. {
  286. case 1:
  287. ui->textBr_FCW->append(QTime::currentTime().toString("hh:mm:ss.zzz") + \
  288. "前方碰撞预警,减速至:" + QString::number(collisionWarning.speedLimit));
  289. break;
  290. case 2:
  291. ui->textBr_FCW->append(QTime::currentTime().toString("hh:mm:ss.zzz") + \
  292. "前方碰撞预警,停车");
  293. default:
  294. break;
  295. }
  296. outCollisionWarning(collisionWarning);
  297. sendProto_flag=true;
  298. }
  299. else
  300. {
  301. ui->button_FWCLight_st->setStyleSheet("background-color: gray");
  302. //ui->textBr_FCW->append("连接丢失");
  303. }
  304. }
  305. //--------------------------------------红绿灯显示------------------------------------------------------------
  306. light=m_pc5->ui_Light();
  307. if (light.isEnable)
  308. {
  309. visionflag=false; //stop vision result upload of traffic light information
  310. ui->cross_lighthead->setText(QString("%1").arg(light.light1head));
  311. switch (int(light.light1Type))
  312. {
  313. case 1:
  314. initLight1();
  315. ui->lcdgreen->display((int)light.light1timeRemaining);
  316. ui->label_38->setPixmap(QPixmap::fromImage(greenimg));
  317. break;
  318. case 2:
  319. initLight1();
  320. ui->lcdred->display((int)light.light1timeRemaining);
  321. ui->label_35->setPixmap(QPixmap::fromImage(redimg));
  322. break;
  323. case 3:
  324. initLight1();
  325. ui->lcdyellow->display((int)light.light1timeRemaining);
  326. ui->label_33->setPixmap(QPixmap::fromImage(yellowimg));
  327. break;
  328. default:
  329. initLight1();
  330. break;
  331. }
  332. ui->vertical_lighthead->setText(QString("%1").arg(light.light2head));
  333. switch (int(light.light2Type))
  334. {
  335. case 1:
  336. initLight2();
  337. ui->lcdgreen_2->display((int)light.light2timeRemaining);
  338. ui->label_39->setPixmap(QPixmap::fromImage(greenimg));
  339. break;
  340. case 2:
  341. initLight2();
  342. ui->lcdred_2->display((int)light.light2timeRemaining);
  343. ui->label_41->setPixmap(QPixmap::fromImage(redimg));
  344. break;
  345. case 3:
  346. initLight2();
  347. ui->lcdyellow_2->display((int)light.light2timeRemaining);
  348. ui->label_40->setPixmap(QPixmap::fromImage(yellowimg));
  349. break;
  350. default:
  351. initLight2();
  352. break;
  353. }
  354. onelightMessage onelight;
  355. float yaw=m_structMGpsImu.yaw+180;
  356. //qDebug()<<yaw<<light.light1head<<light.light1head;
  357. if (yaw>=360)
  358. {
  359. yaw=yaw-360;
  360. }
  361. if (yaw<=light.light1head+30 and yaw>=light.light1head-30)//判断与正向红绿灯的朝向
  362. {
  363. onelight.isEnable=true;
  364. onelight.lightType=light.light1Type;
  365. onelight.timeRemaining=light.light1timeRemaining;
  366. lightStopLat=light1StopLat;
  367. lightStopLon=light1StopLon;
  368. }
  369. else if (yaw<=light.light2head+30 and yaw>=light.light2head-30)//判断与侧向红绿灯的朝向
  370. {
  371. onelight.isEnable=true;
  372. onelight.lightType=light.light2Type;
  373. onelight.timeRemaining=light.light2timeRemaining;
  374. lightStopLat=light2StopLat;
  375. lightStopLon=light2StopLon;
  376. }
  377. else//不面向红绿灯无效
  378. {
  379. onelight.lightType=0xff;
  380. onelight.timeRemaining=0xff;
  381. }
  382. outLight(onelight);
  383. sendProto_flag=true;
  384. }
  385. else
  386. {
  387. ui->cross_lighthead->setText("");
  388. ui->vertical_lighthead->setText("");
  389. initLight1();
  390. initLight2();
  391. if (visionsendstate)
  392. {
  393. visionflag=true;//start vision result upload of traffic light information
  394. }
  395. }
  396. //-----------------------------------------显示虚拟车发送---------------------------------------------------------
  397. congestionIdenti=m_pc5->ui_identification();
  398. if (congestionIdenti.isEnable)
  399. {
  400. ui->lineEdit_jamsMode->setText("虚拟车信息已发送");
  401. ui->button_jamsMode->setStyleSheet("background-color: green");
  402. outCongestionIdenti(congestionIdenti);
  403. sendProto_flag=true;
  404. }
  405. else
  406. {
  407. ui->lineEdit_jamsMode->setText("");
  408. ui->button_jamsMode->setStyleSheet("background-color: gray");
  409. }
  410. //------------------------------------------危险驾驶显示-------------------------------------------------------
  411. if (mbdriCrimsEn)
  412. {
  413. bool warn_driver=m_pc5->show_warn_driver();
  414. if (warn_driver)
  415. {
  416. ui->textBr_FCW_2->append(QTime::currentTime().toString("hh:mm:ss.zzz")+"进入危险驾驶模式");
  417. ui->button_DriCrimsLight_st->setStyleSheet("background-color: red");
  418. }
  419. else
  420. {
  421. ui->button_DriCrimsLight_st->setStyleSheet("background-color: gray");
  422. //ui->textBr_FCW->append("连接丢失");
  423. }
  424. }
  425. if (sendProto_flag)
  426. {
  427. sendProto(protobuf);
  428. sendProto_flag=false;
  429. }
  430. }
  431. //------------------------------------------共享内存读取------------------------------------------------------------------
  432. void MainWindow::setTboxMemoryRaw()//云平台信息写入
  433. {
  434. Memory tboxM;
  435. tboxM.gps_lng=m_structMGpsImu.gps_lng;
  436. tboxM.gps_lat=m_structMGpsImu.gps_lat;
  437. tboxM.speed=m_structMGpsImu.speed;
  438. tboxM.yaw=m_structMGpsImu.yaw;
  439. // tboxM.ele_voltage=m_structChassisRaw.soc;
  440. // tboxM.error=getError();
  441. m_tbox->setTboxMemmory(tboxM);
  442. }
  443. void MainWindow::UpdateGps(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  444. {
  445. bool isSend=false;
  446. double heading,ve,vn;
  447. iv::gps::gpsimu xgpsimu;
  448. //qDebug()<<111;
  449. if(!xgpsimu.ParseFromArray(strdata,nSize))
  450. {
  451. // mivlog->warn("ADCIntelligentVehicle::UpdateGPSIMU parse error. nSize is %d",nSize);
  452. return;
  453. }
  454. if(xgpsimu.has_lat())
  455. {
  456. isSend=true;
  457. m_structMGpsImu.gps_lat=xgpsimu.lat();
  458. //qDebug()<<xgpsimu.lat();
  459. }
  460. if(xgpsimu.has_lon())
  461. {
  462. isSend=true;
  463. m_structMGpsImu.gps_lng=xgpsimu.lon();
  464. //qDebug()<<xgpsimu.lon();
  465. }
  466. if(xgpsimu.has_heading())
  467. {
  468. isSend=true;
  469. heading = xgpsimu.heading();
  470. if(heading<0)
  471. {
  472. heading = heading+360.0;
  473. }
  474. m_structMGpsImu.yaw=float(heading);
  475. }
  476. if((xgpsimu.has_ve())&&(xgpsimu.has_vn()))
  477. {
  478. isSend = true;
  479. ve = xgpsimu.ve(); //东向速度,单位(米/秒)
  480. vn = xgpsimu.vn(); //北向速度,单位(米/秒)
  481. m_structMGpsImu.speed=float(sqrt(ve*ve+vn*vn))* 3.6;
  482. }
  483. if(xgpsimu.has_acce_x())
  484. {
  485. isSend=true;
  486. m_structMGpsImu.accx=float(xgpsimu.acce_x());
  487. }
  488. if(xgpsimu.has_acce_y())
  489. {
  490. isSend=true;
  491. m_structMGpsImu.accy = float(xgpsimu.acce_y());
  492. }
  493. if(isSend)
  494. {
  495. seneor_m.gps_flag=0x01;
  496. mGPSs=3;
  497. setTboxMemoryRaw();
  498. m_tbox->setSensorMemmory(seneor_m);
  499. m_pc5->setGpsImuMemory(m_structMGpsImu);
  500. }
  501. }
  502. void MainWindow::UpdateCAM(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  503. {
  504. iv::vision::rawpic xrawpic;
  505. if(!xrawpic.ParseFromArray(strdata,nSize))
  506. {
  507. return;
  508. }
  509. seneor_m.camera_back=0x01;
  510. seneor_m.camera_front=0x01;
  511. seneor_m.camera_left=0x01;
  512. seneor_m.camera_right=0x01;
  513. mCAMs=5;
  514. m_tbox->setSensorMemmory(seneor_m);
  515. }
  516. void MainWindow::UpdateLIDAR(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  517. {
  518. // iv::fusion::fusionobject xfusionobject;
  519. // if(!xfusionobject.ParseFromArray(strdata,nSize))
  520. // {
  521. // return;
  522. // }
  523. unsigned int * pHeadSize = (unsigned int *)strdata;
  524. if(*pHeadSize > nSize)
  525. {
  526. std::cout<<"ListenPointCloud data is small headsize ="<<*pHeadSize<<" data size is"<<nSize<<std::endl;
  527. }
  528. seneor_m.lidar_left=0x01;
  529. seneor_m.lidar_mid=0x01;
  530. seneor_m.lidar_right=0x01;
  531. mLIDARs=3;
  532. m_tbox->setSensorMemmory(seneor_m);
  533. }
  534. void MainWindow::UpdateRADAR(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  535. {
  536. iv::radar::radarobject xradarobject;
  537. if(!xradarobject.ParseFromArray(strdata,nSize))
  538. {
  539. return;
  540. }
  541. seneor_m.radar=0x01;
  542. mRADARs=3;
  543. m_tbox->setSensorMemmory(seneor_m);
  544. }
  545. //转发视觉红绿灯识别的数据
  546. void MainWindow::Updatelight(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  547. {
  548. iv::vision::Lightarray lightmessage;
  549. onelightMessage visionligth;
  550. if(lightmessage.ParseFromArray(strdata,nSize))
  551. {
  552. if (lightmessage.light(0).has_type() and visionflag)
  553. {
  554. visionligth.lightType=lightmessage.light(0).type();
  555. visionligth.timeRemaining=0xff;
  556. //qDebug()<<111;
  557. lightStopLat=light1StopLat;
  558. lightStopLon=light1StopLon;
  559. sendProto_flag=true;
  560. outLight(visionligth);
  561. }
  562. }
  563. }
  564. //--------------------------------------------共享内存写入--------------------------------------------------------------
  565. void MainWindow::outmbpause(bool runmod)
  566. {
  567. protobuf.set_mbpause(runmod);
  568. }
  569. void MainWindow::outLight(onelightMessage light1)
  570. {
  571. //iv::v2r::v2r_send protobuf;
  572. protobuf.set_radiolighttype(light1.lightType);
  573. protobuf.set_radiolightremain(light1.timeRemaining);
  574. if(visionflag)
  575. {
  576. float yaw=m_structMGpsImu.yaw+180;
  577. if (yaw>=360)
  578. {
  579. yaw=yaw-360;
  580. }
  581. if (yaw<=light1Stophead+30 and yaw>=light1Stophead-30)//判断与正向红绿灯的朝向
  582. {
  583. lightStopLat=light1StopLat;
  584. lightStopLon=light1StopLon;
  585. }
  586. else if (yaw<=light2Stophead+30 and yaw>=light2Stophead-30)//判断与侧向红绿灯的朝向
  587. {
  588. lightStopLat=light2StopLat;
  589. lightStopLon=light2StopLon;
  590. }
  591. else{
  592. lightStopLat=0xff;
  593. lightStopLon=0xff;
  594. }
  595. protobuf.set_trafficlightstoplat(lightStopLat);
  596. protobuf.set_trafficlightstoplon(lightStopLon);
  597. //sendProto(protobuf);
  598. }
  599. protobuf.set_trafficlightstoplat(lightStopLat);
  600. protobuf.set_trafficlightstoplon(lightStopLon);
  601. //sendProto(protobuf);
  602. //qDebug()<<"outLight";
  603. }
  604. void MainWindow::outRealtimeTraffic(realtimeTrafficMessage realtimeTraffic)
  605. {
  606. double lat=((double)realtimeTraffic.lat);//1000000.0;
  607. double lon=((double)realtimeTraffic.lng);//1000000.0;
  608. protobuf.set_radiobroadcastgpslat(lat);
  609. protobuf.set_radiobroadcastgpslon(lon);
  610. protobuf.set_radiobroadcastrange(realtimeTraffic.scope);
  611. protobuf.set_radiobroadcasttraffictype(realtimeTraffic.trafficInfo);
  612. protobuf.set_radiobroadcastspeedlimit(realtimeTraffic.speedLimit);
  613. //sendProto(protobuf);
  614. //qDebug()<<"outRealtimeTraffic"<<lat<<lon<<realtimeTraffic.scope<<realtimeTraffic.trafficInfo<<realtimeTraffic.speedLimit;
  615. }
  616. void MainWindow::outCollisionWarning(collisionEarlyWarningMessage collisionWarning)
  617. {
  618. //iv::v2r::v2r_send protobuf;
  619. protobuf.set_radiowarningtype(collisionWarning.warningType);
  620. protobuf.set_radiowarningspeedlimit(collisionWarning.speedLimit);
  621. //qDebug()<<"[Radio]:warning type is "<<collisionWarning.warningType<<".speed limit is:"<<collisionWarning.speedLimit<<endl;
  622. //sendProto(protobuf);
  623. }
  624. void MainWindow::outCongestionIdenti(congestionIdentificationMessage congestionIdenti)
  625. {
  626. //iv::v2r::v2r_send protobuf;
  627. protobuf.set_radioidentistart(congestionIdenti.openCommand);
  628. //qDebug()<<"[Radio]:congestion identi open command is "<<congestionIdenti.openCommand<<endl;
  629. //sendProto(protobuf);
  630. }
  631. void MainWindow::sendProto(iv::v2r::v2r_send radio_protobuf_send)
  632. {
  633. char * strser;
  634. bool bser;
  635. int nbytesize;
  636. nbytesize = radio_protobuf_send.ByteSize();
  637. strser = new char[nbytesize];
  638. bser = radio_protobuf_send.SerializeToArray(strser,nbytesize);
  639. if(bser)
  640. {
  641. //qDebug()<<"[Radio]:ready send protobuffer"<<endl;
  642. iv::modulecomm::ModuleSendMsg(mpmem_radio_send_addr,strser,nbytesize);
  643. //qDebug()<<"[Radio]:has sended protobuffer"<<endl;
  644. } else
  645. {
  646. //qDebug()<<"proto fail"<<endl;
  647. //mivlog->error("sendData","[%s:] radio serialize error.",__func__);
  648. // gfault->SetFaultState(1, 0, "radio serialize err");
  649. }
  650. delete strser;
  651. }
  652. //--------------------------------------------按钮使能控制---------------------------------------------------------------
  653. //云平台使能控制
  654. void MainWindow::on_button_platform_en_clicked()
  655. {
  656. if(mplatformEn)
  657. {
  658. ui->button_platform_en->setStyleSheet("background-color: gray");
  659. mplatformEn = false;
  660. m_tbox->setTboxConnectEnable(false);
  661. }
  662. else
  663. {
  664. ui->button_platform_en->setStyleSheet("background-color: green");
  665. mplatformEn = true;
  666. m_tbox->setTboxConnectEnable(true);
  667. }
  668. }
  669. //路测设备使能控制
  670. void MainWindow::on_button_obu_en_clicked()
  671. {
  672. if(mobuEn==1)
  673. {
  674. ui->button_obu_en->setStyleSheet("background-color: gray");
  675. mobuEn = 0;
  676. m_pc5->setConnectEnable(false);
  677. }
  678. else
  679. {
  680. ui->button_obu_en->setStyleSheet("background-color: green");
  681. mobuEn = 1;
  682. m_pc5->setConnectEnable(true);
  683. }
  684. }
  685. //云平台控制启停使能控制
  686. void MainWindow::on_button_runmod_en_clicked()
  687. {
  688. if(mRunmodEn==1)
  689. {
  690. ui->button_runmod_en->setStyleSheet("background-color: gray");
  691. mRunmodEn = 0;
  692. }
  693. else
  694. {
  695. ui->button_runmod_en->setStyleSheet("background-color: green");
  696. mRunmodEn = 1;
  697. }
  698. if (!mplatformEn)
  699. {
  700. ui->button_runmod_en->setStyleSheet("background-color: red");
  701. mRunmodEn = 0;
  702. }
  703. }
  704. void MainWindow::on_button_car_vin_set_clicked()
  705. {
  706. bool ok;
  707. QString text = QInputDialog::getText(this, tr("输入车辆VIN:"),
  708. tr("VIN:"), QLineEdit::Normal,
  709. Q_NULLPTR, &ok);
  710. if (ok && !text.isEmpty())
  711. {
  712. gstrcarvin = text.toStdString();
  713. ui->lineEdit->setText(text);
  714. m_tbox->setTboxNewVin(gstrcarvin);
  715. m_pc5->setVin(gstrcarvin);
  716. }
  717. }
  718. void MainWindow::on_button_obu_vin_set_clicked()
  719. {
  720. bool ok;
  721. QString text = QInputDialog::getText(this, tr("输入路侧VIN:"),
  722. tr("VIN:"), QLineEdit::Normal,
  723. Q_NULLPTR, &ok);
  724. if (ok && !text.isEmpty())
  725. {
  726. int gstrobuvin = text.toInt();
  727. ui->lineEdit_obu_vin->setText(text);
  728. m_pc5->setobuNewVin(gstrobuvin);
  729. }
  730. }
  731. void MainWindow::on_button_trafficInfo_en_clicked()
  732. {
  733. if(mbTrafficInfoEn==1)
  734. {
  735. ui->button_trafficInfo_en->setStyleSheet("background-color: gray");
  736. mbTrafficInfoEn = 0;
  737. }
  738. else
  739. {
  740. ui->button_trafficInfo_en->setStyleSheet("background-color: green");
  741. mbTrafficInfoEn = 1;
  742. }
  743. }
  744. void MainWindow::on_button_FCW_en_clicked()
  745. {
  746. if(mbFCWEn==1)
  747. {
  748. ui->button_FCW_en->setStyleSheet("background-color: gray");
  749. mbFCWEn = 0;
  750. }
  751. else
  752. {
  753. ui->button_FCW_en->setStyleSheet("background-color: green");
  754. mbFCWEn = 1;
  755. }
  756. }
  757. void MainWindow::on_button_DriCrims_en_clicked()
  758. {
  759. if(mbdriCrimsEn==1)
  760. {
  761. ui->button_DriCrims_en->setStyleSheet("background-color: gray");
  762. mbdriCrimsEn = 0;
  763. }
  764. else
  765. {
  766. ui->button_DriCrims_en->setStyleSheet("background-color: green");
  767. mbdriCrimsEn = 1;
  768. }
  769. }
  770. void MainWindow::on_button_SimCar_en_clicked()
  771. {
  772. ui_set_virtualVehicleM struct_ui_VirtualVehicle;
  773. struct_ui_VirtualVehicle.lngMax= ui->lineEdit_jamsLon_up->text().toDouble();
  774. struct_ui_VirtualVehicle.lngMin= ui->lineEdit_jamsLon_low->text().toDouble();
  775. struct_ui_VirtualVehicle.latMax=ui->lineEdit_jamsLat_Up->text().toDouble();
  776. struct_ui_VirtualVehicle.latMin=ui->lineEdit_jamsLat_low->text().toDouble();
  777. struct_ui_VirtualVehicle.yawMax=ui->lineEdit_jamsHead_up->text().toDouble();
  778. struct_ui_VirtualVehicle.yawMin=ui->lineEdit_jamsHead_low->text().toDouble();
  779. struct_ui_VirtualVehicle.virtualVehicleNum= int(ui->lineEdit_jamsCarNum->text().toInt());
  780. struct_ui_VirtualVehicle.speedMax=ui->lineEdit_jamsSpeed_up->text().toDouble();
  781. struct_ui_VirtualVehicle.speedMin=ui->lineEdit_jamsSpeed_low->text().toDouble();
  782. m_pc5->my_ui_set=struct_ui_VirtualVehicle;
  783. //m_pc5->upVirtualVehicle(struct_ui_VirtualVehicle);
  784. // virtualVehicleM structVirtualVehicle;
  785. // int randId=qrand()%10000;
  786. // m_vectorRandom.push_back(randId);
  787. // for(int i=1;i<virtualVehicleNum;i++) {
  788. // getRandomNum();
  789. // }
  790. // for(int i=0;i<virtualVehicleNum;i++) {
  791. // structVirtualVehicle.vin = m_vectorVin[i];
  792. // structVirtualVehicle.gps_lat=latMin+((double(m_vectorRandom[i]))/10000.0)*(latMax-latMin);
  793. // structVirtualVehicle.gps_lng=lngMin+((double(m_vectorRandom[i]))/10000.0)*(lngMax-lngMin);
  794. // structVirtualVehicle.speed=speedMin+((float(m_vectorRandom[i]))/10000.0)*(speedMax-speedMin);
  795. // structVirtualVehicle.yaw=yawMin+((float(m_vectorRandom[i]))/10000.0)*(yawMax-yawMin);
  796. // m_pc5->upVirtualVehicle(structVirtualVehicle);
  797. // }
  798. }
  799. //void MainWindow::on_button_SimCar_en_clicked()
  800. //{
  801. // double lngMax= ui->lineEdit_jamsLon_up->text().toDouble();
  802. // double lngMin= ui->lineEdit_jamsLon_low->text().toDouble();
  803. // double latMax=ui->lineEdit_jamsLat_Up->text().toDouble();
  804. // double latMin=ui->lineEdit_jamsLat_low->text().toDouble();
  805. // float yawMax=ui->lineEdit_jamsHead_up->text().toDouble();
  806. // float yawMin=ui->lineEdit_jamsHead_low->text().toDouble();
  807. // int virtualVehicleNum= int(ui->lineEdit_jamsCarNum->text().toInt());
  808. // float speedMax=ui->lineEdit_jamsSpeed_up->text().toDouble();
  809. // float speedMin=ui->lineEdit_jamsSpeed_low->text().toDouble();
  810. // virtualVehicleM structVirtualVehicle;
  811. // int randId=qrand()%10000;
  812. // m_vectorRandom.push_back(randId);
  813. // for(int i=1;i<virtualVehicleNum;i++) {
  814. // getRandomNum();
  815. // }
  816. // for(int i=0;i<virtualVehicleNum;i++) {
  817. // structVirtualVehicle.vin = m_vectorVin[i];
  818. // structVirtualVehicle.gps_lat=latMin+((double(m_vectorRandom[i]))/10000.0)*(latMax-latMin);
  819. // structVirtualVehicle.gps_lng=lngMin+((double(m_vectorRandom[i]))/10000.0)*(lngMax-lngMin);
  820. // structVirtualVehicle.speed=speedMin+((float(m_vectorRandom[i]))/10000.0)*(speedMax-speedMin);
  821. // structVirtualVehicle.yaw=yawMin+((float(m_vectorRandom[i]))/10000.0)*(yawMax-yawMin);
  822. // m_pc5->upVirtualVehicle(structVirtualVehicle);
  823. // }
  824. //}
  825. void MainWindow::on_show_debug_clicked()
  826. {
  827. if(mshowdebugEn==1)
  828. {
  829. ui->show_debug->setStyleSheet("background-color: gray");
  830. mshowdebugEn = 0;
  831. }
  832. else
  833. {
  834. bool ok;
  835. QString text = QInputDialog::getText(this, tr("scode:"),
  836. tr("scode:"), QLineEdit::Normal,
  837. Q_NULLPTR, &ok);
  838. if (ok && !text.isEmpty())
  839. {
  840. std::string scode = text.toStdString();
  841. if (scode=="catarc")
  842. {
  843. ui->show_debug->setStyleSheet("background-color: green");
  844. mshowdebugEn = 1;
  845. }
  846. }
  847. }
  848. }
  849. MainWindow::~MainWindow()
  850. {
  851. timer->stop();
  852. iv::modulecomm::Unregister(mpMemGPS);
  853. iv::modulecomm::Unregister(mpMemcamera);
  854. iv::modulecomm::Unregister(mpMemlidar);
  855. iv::modulecomm::Unregister(mpMemradar);
  856. iv::modulecomm::Unregister(vision_lightMem);
  857. delete ui;
  858. }