mainwindow.cpp 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869
  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. int camera_trafficlight_type=200;
  8. int camera_trafficlight_time=200;
  9. MainWindow::MainWindow(QWidget *parent) :
  10. QMainWindow(parent),
  11. ui(new Ui::MainWindow)
  12. {
  13. ui->setupUi(this);
  14. m_pc5=new PC5();
  15. m_tbox=new V2X();
  16. timer = new QTimer(this);
  17. connect(timer,SIGNAL(timeout()),SLOT(heartBeat()));
  18. //timer->start(1000);
  19. timer->start(500);
  20. timerV2V= new QTimer(this);
  21. connect(timerV2V,SIGNAL(timeout()),SLOT(V2VOUT()));
  22. timerV2V->start(100);
  23. sendProto_flag=false;
  24. initUI();
  25. initMemory();
  26. initproto();
  27. initLight1();
  28. initLight2();
  29. initLight3();
  30. initLight4();
  31. initFace();
  32. }
  33. void MainWindow::initMemory()
  34. {
  35. m_structMGpsImu.gps_lat=39.149170;
  36. m_structMGpsImu.gps_lng=117.094250;
  37. m_structMGpsImu.speed=0.0;
  38. m_structMGpsImu.yaw=0.0;
  39. m_structMGpsImu.accx=0.0;
  40. m_structMGpsImu.accy=0.0;
  41. seneor_m.lidar_left=0;
  42. seneor_m.lidar_mid=0;
  43. seneor_m.lidar_right=0;
  44. seneor_m.radar=0;
  45. seneor_m.gps_flag=0;
  46. seneor_m.camera_front=0;
  47. seneor_m.camera_back=0;
  48. seneor_m.camera_left=0;
  49. seneor_m.camera_right=0;
  50. m_tbox->setSensorMemmory(seneor_m);
  51. setTboxMemoryRaw();
  52. m_pc5->setGpsImuMemory(m_structMGpsImu);
  53. }
  54. void MainWindow::initproto()
  55. {
  56. mpmem_radio_send_addr = iv::modulecomm::RegisterSend("v2r_send",1000,3);
  57. ModuleFun fungpsimu =std::bind(&MainWindow::UpdateGps,this,std::placeholders::_1, \
  58. std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  59. mpMemGPS = iv::modulecomm::RegisterRecvPlus(gstrmemgps.data(),fungpsimu);
  60. // mpMemGPS = iv::modulecomm::RegisterRecv("hcp_gpsimu",iv::V2X::UpdateGps);
  61. ModuleFun funcamera =std::bind(&MainWindow::UpdateCAM,this,std::placeholders::_1, \
  62. std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  63. mpMemcamera=iv::modulecomm::RegisterRecvPlus(gstrmecamera.data(),funcamera);
  64. ModuleFun funlidar =std::bind(&MainWindow::UpdateLIDAR,this,std::placeholders::_1, \
  65. std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  66. mpMemlidar=iv::modulecomm::RegisterRecvPlus(gstrmelidar.data(),funlidar);
  67. ModuleFun funradar =std::bind(&MainWindow::UpdateRADAR,this,std::placeholders::_1, \
  68. std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  69. mpMemradar=iv::modulecomm::RegisterRecvPlus(gstrmeradar.data(),funradar);
  70. ModuleFun lightState =std::bind(&MainWindow::Updatelight,this,std::placeholders::_1, \
  71. std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
  72. vision_lightMem = iv::modulecomm::RegisterRecvPlus(gstrmemlight.data(),lightState);
  73. }
  74. void MainWindow::initUI()
  75. {
  76. redimg.load(":/light/light/light-red.png");
  77. redimg = redimg.scaled(66,66,Qt::IgnoreAspectRatio);
  78. greenimg.load(":/light/light/light-green.png");
  79. greenimg = greenimg.scaled(66,66,Qt::IgnoreAspectRatio);
  80. yellowimg.load(":/light/light/light-yellow.png");
  81. yellowimg = yellowimg.scaled(66,66,Qt::IgnoreAspectRatio);
  82. blackimg.load(":/light/light/light-black.png");
  83. blackimg = blackimg.scaled(66,66,Qt::IgnoreAspectRatio);
  84. nofaceimg.load(":/light/light/noface.png");
  85. nofaceimg = nofaceimg.scaled(60,50,Qt::IgnoreAspectRatio);
  86. facetoimg.load(":/light/light/faceto.png");
  87. facetoimg = facetoimg.scaled(60,50,Qt::IgnoreAspectRatio);
  88. QString strpath = QCoreApplication::applicationDirPath();
  89. //strpath = strpath + "/v2xTcpClientWL.xml";
  90. strpath = "./v2xTcpClient.xml";
  91. iv::xmlparam::Xmlparam xp(strpath.toStdString());
  92. std::string rsutype = xp.GetParam("OBU_Type","serial");
  93. if(rsutype=="eth")
  94. {
  95. m_pc5->eth_enable=true;
  96. std::string localIP = xp.GetParam("obuip","127.0.0.1");
  97. QString localsetIP =QString::fromStdString(localIP);
  98. std::string localPort = xp.GetParam("obuport","7777");
  99. int localsetport=std::stoi(localPort);
  100. m_pc5->setobu(localsetIP,localsetport);
  101. RSUTYPE=true;
  102. }
  103. else
  104. {
  105. m_pc5->eth_enable=false;
  106. std::string localIP = xp.GetParam("port_name","/dev/ttyUSB0");
  107. QString localsetIP =QString::fromStdString(localIP);
  108. std::string localPort = xp.GetParam("baud","9600");
  109. int localsetport=std::stoi(localPort);
  110. m_pc5->setSerial(localsetIP,localsetport);
  111. RSUTYPE=false;
  112. }
  113. std::string strCarVIN = xp.GetParam("carVIN","catarc001");
  114. ui->lineEdit->setText(QString::fromStdString(strCarVIN));
  115. std::string strObuVIN = xp.GetParam("obuNUM","1");
  116. ui->lineEdit_obu_vin->setText(QString::fromStdString(strObuVIN));
  117. int obunum=std::stoi(strObuVIN);
  118. std::string hostIP = xp.GetParam("hostIP","127.0.0.1");
  119. QString IP =QString::fromStdString(hostIP);
  120. ui->lineEdit_severip->setText(IP);
  121. std::string hostPort = xp.GetParam("hostPort","8000");
  122. int port=std::stoi(hostPort);
  123. gstrmemgps = xp.GetParam("gps","gpsimu");
  124. gstrmecamera = xp.GetParam("camera","rawpic");
  125. gstrmelidar = xp.GetParam("lidar","lidarstate");
  126. gstrmeradar = xp.GetParam("radar","radarobject");
  127. gstrmemlight = xp.GetParam("vision_light","lightarray");
  128. std::string Stophead1 = xp.GetParam("light1Stophead","0");
  129. light1Stophead=std::stod(Stophead1);
  130. std::string StopLat1 = xp.GetParam("light1StopLat","0");
  131. light1StopLat=std::stod(StopLat1);
  132. std::string StopLon1 = xp.GetParam("light1StopLon","0");
  133. light1StopLon=std::stod(StopLon1);
  134. ui->ea_long->setText(QString::fromStdString(StopLon1));
  135. ui->ea_lat->setText(QString::fromStdString(StopLat1));
  136. ui->ea_head->setText(QString::fromStdString(Stophead1));
  137. std::string Stophead2 = xp.GetParam("light2Stophead","0");
  138. light2Stophead=std::stod(Stophead2);
  139. std::string StopLat2 = xp.GetParam("light2StopLat","0");
  140. light2StopLat=std::stod(StopLat2);
  141. std::string StopLon2 = xp.GetParam("light2StopLon","0");
  142. light2StopLon=std::stod(StopLon2);
  143. ui->ns_long->setText(QString::fromStdString(StopLon2));
  144. ui->ns_lat->setText(QString::fromStdString(StopLat2));
  145. ui->ns_head->setText(QString::fromStdString(Stophead2));
  146. std::string visionsend = xp.GetParam("OpenVisionSend","0");
  147. visionsendstate=std::stoi(visionsend);
  148. visionflag=visionsendstate;
  149. m_pc5->setVin(strCarVIN);
  150. m_pc5->setobuNewVin(obunum);
  151. m_tbox->setTboxNewVin(strCarVIN);
  152. m_tbox->setIPandPort(IP,port);
  153. }
  154. void MainWindow::initLight1()
  155. {
  156. ui->label_39->setPixmap(QPixmap::fromImage(blackimg));
  157. ui->lcdgreen_2->display(0);
  158. // ui->label_7->setPixmap(QPixmap::fromImage(nofaceimg));
  159. // ui->label_18->setText('');
  160. // ui->vertical_lighthead->setText("");
  161. }
  162. void MainWindow::initLight2()
  163. {
  164. ui->label_40->setPixmap(QPixmap::fromImage(blackimg));
  165. ui->lcdgreen_3->display(0);
  166. // ui->label_14->setPixmap(QPixmap::fromImage(nofaceimg));
  167. // ui->label_17->setText('');
  168. // ui->vertical_lighthead_2->setText("");
  169. }
  170. void MainWindow::initLight3()
  171. {
  172. ui->label_41->setPixmap(QPixmap::fromImage(blackimg));
  173. ui->lcdgreen_4->display(0);
  174. // ui->label_15->setPixmap(QPixmap::fromImage(nofaceimg));
  175. // ui->label_18->setText('');
  176. // ui->vertical_lighthead_3->setText("");
  177. }
  178. void MainWindow::initLight4()
  179. {
  180. ui->label_42->setPixmap(QPixmap::fromImage(blackimg));
  181. ui->lcdgreen_5->display(0);
  182. // ui->label_16->setPixmap(QPixmap::fromImage(nofaceimg));
  183. // ui->label_20->setText('');
  184. // ui->vertical_lighthead_4->setText("");
  185. }
  186. void MainWindow::initFace()
  187. {
  188. ui->label_7->setPixmap(QPixmap::fromImage(nofaceimg));
  189. ui->label_18->setText("");
  190. ui->label_14->setPixmap(QPixmap::fromImage(nofaceimg));
  191. ui->label_17->setText("");
  192. ui->label_15->setPixmap(QPixmap::fromImage(nofaceimg));
  193. ui->label_19->setText("");
  194. ui->label_16->setPixmap(QPixmap::fromImage(nofaceimg));
  195. ui->label_20->setText("");
  196. }
  197. void MainWindow::V2VOUT()
  198. {
  199. //---------------------------------------V2V--------------------------------------------------------------------
  200. if (v2vEn)
  201. {
  202. try
  203. {
  204. QMap<QString,OBUCarFormation> V2VMessage=m_pc5->updateV2V();
  205. outV2VData(V2VMessage);
  206. }
  207. catch(...){
  208. qDebug()<<"...";
  209. }
  210. }
  211. }
  212. void MainWindow::heartBeat()
  213. {
  214. protobuf.Clear();
  215. //-----------------------------------------send runflag---------------------------------------------------------
  216. //qDebug()<<mv2xRunmodEn<<mpc5RunmodEn;
  217. if (mv2xRunmodEn)
  218. {
  219. bool runmod=m_tbox->upRunMod();
  220. //qDebug()<<runmod;
  221. outmbpause(runmod);
  222. sendProto_flag=true;
  223. mpc5RunmodEn=false;
  224. ui->button_pc5runmod_en->setStyleSheet("background-color: gray");
  225. }
  226. else if (mpc5RunmodEn)
  227. {
  228. bool runmod=m_pc5->upRunMod();
  229. //qDebug()<<runmod;
  230. outmbpause(runmod);
  231. sendProto_flag=true;
  232. mv2xRunmodEn=false;
  233. ui->button_v2xrunmod_en->setStyleSheet("background-color: gray");
  234. }
  235. else{
  236. outmbpause(false);
  237. sendProto_flag=true;
  238. }
  239. if (visionflag)
  240. {
  241. onelightMessage onelight;
  242. onelight.lightType= camera_trafficlight_type;
  243. if(onelight.lightType==2)
  244. {
  245. onelight.timeRemaining=5;
  246. }
  247. else if(onelight.lightType==3)
  248. {
  249. onelight.timeRemaining=3;
  250. }
  251. else if(onelight.lightType==1)
  252. {
  253. onelight.timeRemaining = 5;
  254. }
  255. //std::cout<<"######################: "<<camera_trafficlight_type<<" "<<onelight.timeRemaining<<std::endl;
  256. //onelight.timeRemaining= camera_trafficlight_time;
  257. outLight(onelight);
  258. sendProto_flag=true;
  259. }
  260. //-----------------------------------------获取连接状态--------------------------------------std::fmod-------------------
  261. if(mobuEn)
  262. {
  263. bool radio_flag=m_pc5->isLinked();//路测连接状态
  264. if (radio_flag)
  265. {
  266. ui->button_obu_en->setStyleSheet("background-color: green");
  267. }
  268. else
  269. {
  270. ui->button_obu_en->setStyleSheet("background-color: red");
  271. }
  272. if (mshowdebugEn)
  273. {
  274. QByteArray pc5_read=m_pc5->show_readdata();
  275. QByteArray pc5_error=m_pc5->show_error();
  276. ui->textBrowser_3->append(QTime::currentTime().toString("hh:mm:ss.zzz")+"接收:"+pc5_read);
  277. ui->textBrowser_4->append(QTime::currentTime().toString("hh:mm:ss.zzz")+":"+pc5_error);
  278. }
  279. if(mcusdatashowEn)
  280. {
  281. QByteArray cus_show=m_pc5->upCustomshow();
  282. if (cus_show.size()>0)
  283. {
  284. ui->textBrowser_5->append(QTime::currentTime().toString("hh:mm:ss.zzz")+"接收:"+cus_show);
  285. cus_show.clear();
  286. }
  287. }
  288. }
  289. if(v2vEn)
  290. {
  291. bool radio_flag=m_pc5->isLinked();//路测连接状态
  292. if (radio_flag)
  293. {
  294. ui->button_v2v_en->setStyleSheet("background-color: green");
  295. }
  296. else
  297. {
  298. ui->button_v2v_en->setStyleSheet("background-color: red");
  299. }
  300. if (mshowdebugEn)
  301. {
  302. QByteArray pc5_read=m_pc5->show_readdata();
  303. QByteArray pc5_error=m_pc5->show_error();
  304. ui->textBrowser_3->append(QTime::currentTime().toString("hh:mm:ss.zzz")+"接收:"+pc5_read);
  305. ui->textBrowser_4->append(QTime::currentTime().toString("hh:mm:ss.zzz")+":"+pc5_error);
  306. }
  307. }
  308. if (mplatformEn)
  309. {
  310. bool v2x_flag=m_tbox->isLinked();//云平台连接状态
  311. if (v2x_flag)
  312. {
  313. ui->button_platform_en->setStyleSheet("background-color: green");
  314. }
  315. else
  316. {
  317. ui->button_platform_en->setStyleSheet("background-color: red");
  318. }
  319. if (mshowdebugEn)
  320. {
  321. QByteArray v2x_read=m_tbox->show_readdata();
  322. QByteArray v2x_error=m_tbox->show_error();
  323. ui->textBrowser->append(QTime::currentTime().toString("hh:mm:ss.zzz")+"接收:"+v2x_read);
  324. ui->textBrowser_2->append(QTime::currentTime().toString("hh:mm:ss.zzz")+":"+v2x_error);
  325. }
  326. }
  327. //-----------------------------------------延时清空传感器状态---------------------------------------------------------
  328. if(mGPSs>0)
  329. {
  330. mGPSs--;
  331. if (mGPSs<=0)
  332. {
  333. seneor_m.gps_flag=0x00;
  334. m_tbox->setSensorMemmory(seneor_m);
  335. }
  336. }
  337. if(mCAMs>0)
  338. {
  339. mCAMs--;
  340. if(mCAMs<=0)
  341. {
  342. seneor_m.camera_back=0x00;
  343. seneor_m.camera_front=0x00;
  344. seneor_m.camera_left=0x00;
  345. seneor_m.camera_right=0x00;
  346. m_tbox->setSensorMemmory(seneor_m);
  347. }
  348. }
  349. if(mLIDARs>0)
  350. {
  351. mLIDARs--;
  352. if(mLIDARs<=0)
  353. {
  354. seneor_m.lidar_left=0x00;
  355. seneor_m.lidar_mid=0x00;
  356. seneor_m.lidar_right=0x00;
  357. m_tbox->setSensorMemmory(seneor_m);
  358. }
  359. }
  360. if(mRADARs>0)
  361. {
  362. mRADARs--;
  363. if (mRADARs<=0)
  364. {
  365. seneor_m.radar=0x00;
  366. m_tbox->setSensorMemmory(seneor_m);
  367. }
  368. }
  369. //---------------------------------------路况信息显示-----------------------------------------------------------
  370. if (mbTrafficInfoEn)
  371. {
  372. TrafficMessage=m_pc5->ui_RealtimeTraffic();
  373. if (TrafficMessage.isEnable)
  374. {
  375. QString event;
  376. ui->button_trafficInfoLight_st->setStyleSheet("background-color: green");
  377. switch(TrafficMessage.trafficInfo){
  378. case 0:
  379. event="无";
  380. ui->lineEd_trafficInfo->setText("正常行驶");
  381. break;
  382. case 3 :
  383. event="道路结冰";
  384. //ui->lineEd_trafficInfo->setText("减速至 " + QString::number(TrafficMessage.speedLimit) + "km/h");
  385. ui->lineEd_trafficInfo->setText("减速慢行");
  386. break;
  387. case 4 :
  388. event="限速";
  389. ui->lineEd_trafficInfo->setText("减速至 " + QString::number(TrafficMessage.speedLimit) + "km/h");
  390. break;
  391. case 1 :
  392. event="塌方";
  393. ui->lineEd_trafficInfo->setText("停车");
  394. break;
  395. case 2 :
  396. event="施工";
  397. ui->lineEd_trafficInfo->setText("停车");
  398. break;
  399. default:
  400. break;
  401. }
  402. ui->textBr_trafficInfo->append(QTime::currentTime().toString("hh:mm:ss.zzz") + \
  403. "\n\t事件范围[ 经度:" + QString::number(TrafficMessage.lng,'g',10) +\
  404. " 纬度:" + QString::number(TrafficMessage.lat,'g',10) + \
  405. " ]\n\t辐射范围: " + QString::number(TrafficMessage.scope) + "米" + \
  406. "\n\t事件类型: " + event);
  407. outRealtimeTraffic(TrafficMessage);
  408. sendProto_flag=true;
  409. }
  410. else
  411. {
  412. ui->button_trafficInfoLight_st->setStyleSheet("background-color: gray");
  413. ui->textBr_trafficInfo->append("等待接收");
  414. }
  415. }
  416. //-----------------------------------------碰撞预警显示---------------------------------------------------------
  417. if (mbFCWEn)
  418. {
  419. collisionWarning=m_pc5->ui_Warning();
  420. if (collisionWarning.isEnable)
  421. {
  422. ui->button_FWCLight_st->setStyleSheet("background-color: green");
  423. switch (collisionWarning.warningType)
  424. {
  425. case 1:
  426. ui->textBr_FCW->append(QTime::currentTime().toString("hh:mm:ss.zzz") + \
  427. "前方碰撞预警,减速至:" + QString::number(collisionWarning.speedLimit));
  428. break;
  429. case 2:
  430. ui->textBr_FCW->append(QTime::currentTime().toString("hh:mm:ss.zzz") + \
  431. "前方碰撞预警,停车");
  432. default:
  433. break;
  434. }
  435. outCollisionWarning(collisionWarning);
  436. sendProto_flag=true;
  437. }
  438. else
  439. {
  440. ui->button_FWCLight_st->setStyleSheet("background-color: gray");
  441. //ui->textBr_FCW->append("连接丢失");
  442. }
  443. }
  444. //--------------------------------------红绿灯显示------------------------------------------------------------
  445. light=m_pc5->ui_Light();
  446. if (light.isEnable && mobuEn)
  447. {
  448. visionflag=false; //stop vision result upload of traffic light information
  449. // qDebug()<<light.myface;
  450. switch (int(light.myface))
  451. {
  452. case 1:
  453. initFace();
  454. ui->label_7->setPixmap(QPixmap::fromImage(facetoimg));
  455. ui->label_18->setText("此时面向");
  456. break;
  457. case 2:
  458. initFace();
  459. ui->label_14->setPixmap(QPixmap::fromImage(facetoimg));
  460. ui->label_17->setText("此时面向");
  461. break;
  462. case 3:
  463. initFace();
  464. ui->label_15->setPixmap(QPixmap::fromImage(facetoimg));
  465. ui->label_19->setText("此时面向");
  466. break;
  467. case 4:
  468. initFace();
  469. ui->label_16->setPixmap(QPixmap::fromImage(facetoimg));
  470. ui->label_20->setText("此时面向");
  471. break;
  472. default:
  473. initFace();
  474. break;
  475. }
  476. ui->vertical_lighthead->setText(QString("%1").arg(light.light1head));
  477. switch (int(light.light1Type))
  478. {
  479. case 1:
  480. initLight1();
  481. ui->lcdgreen_2->display((int)light.light1timeRemaining);
  482. ui->label_39->setPixmap(QPixmap::fromImage(greenimg));
  483. break;
  484. case 2:
  485. initLight1();
  486. ui->lcdgreen_2->display((int)light.light1timeRemaining);
  487. ui->label_39->setPixmap(QPixmap::fromImage(redimg));
  488. break;
  489. case 3:
  490. initLight1();
  491. ui->lcdgreen_2->display((int)light.light1timeRemaining);
  492. ui->label_39->setPixmap(QPixmap::fromImage(yellowimg));
  493. break;
  494. default:
  495. initLight1();
  496. break;
  497. }
  498. ui->vertical_lighthead_2->setText(QString("%1").arg(light.light2head));
  499. switch (int(light.light2Type))
  500. {
  501. case 1:
  502. initLight2();
  503. ui->lcdgreen_3->display((int)light.light2timeRemaining);
  504. ui->label_40->setPixmap(QPixmap::fromImage(greenimg));
  505. break;
  506. case 2:
  507. initLight2();
  508. ui->lcdgreen_3->display((int)light.light2timeRemaining);
  509. ui->label_40->setPixmap(QPixmap::fromImage(redimg));
  510. break;
  511. case 3:
  512. initLight2();
  513. ui->lcdgreen_3->display((int)light.light2timeRemaining);
  514. ui->label_40->setPixmap(QPixmap::fromImage(yellowimg));
  515. break;
  516. default:
  517. initLight2();
  518. break;
  519. }
  520. ui->vertical_lighthead_3->setText(QString("%1").arg(light.light3head));
  521. switch (int(light.light3Type))
  522. {
  523. case 1:
  524. initLight3();
  525. ui->lcdgreen_4->display((int)light.light3timeRemaining);
  526. ui->label_41->setPixmap(QPixmap::fromImage(greenimg));
  527. break;
  528. case 2:
  529. initLight3();
  530. ui->lcdgreen_4->display((int)light.light3timeRemaining);
  531. ui->label_41->setPixmap(QPixmap::fromImage(redimg));
  532. break;
  533. case 3:
  534. initLight3();
  535. ui->lcdgreen_4->display((int)light.light3timeRemaining);
  536. ui->label_41->setPixmap(QPixmap::fromImage(yellowimg));
  537. break;
  538. default:
  539. initLight3();
  540. break;
  541. }
  542. ui->vertical_lighthead_4->setText(QString("%1").arg(light.light4head));
  543. switch (int(light.light4Type))
  544. {
  545. case 1:
  546. initLight4();
  547. ui->lcdgreen_5->display((int)light.light4timeRemaining);
  548. ui->label_42->setPixmap(QPixmap::fromImage(greenimg));
  549. break;
  550. case 2:
  551. initLight4();
  552. ui->lcdgreen_5->display((int)light.light4timeRemaining);
  553. ui->label_42->setPixmap(QPixmap::fromImage(redimg));
  554. break;
  555. case 3:
  556. initLight4();
  557. ui->lcdgreen_5->display((int)light.light4timeRemaining);
  558. ui->label_42->setPixmap(QPixmap::fromImage(yellowimg));
  559. break;
  560. default:
  561. initLight4();
  562. break;
  563. }
  564. onelightMessage onelight;
  565. // float yaw=m_structMGpsImu.yaw+180;
  566. // //qDebug()<<yaw<<light.light1head<<light.light1head;
  567. // if (yaw>=360)
  568. // {
  569. // yaw=yaw-360;
  570. // }
  571. // if (yaw<=light.light1head+30 and yaw>=light.light1head-30)//判断与正向红绿灯的朝向
  572. // {
  573. // onelight.isEnable=true;
  574. // onelight.lightType=light.light1Type;
  575. // onelight.timeRemaining=light.light1timeRemaining;
  576. // lightStopLat=light1StopLat;
  577. // lightStopLon=light1StopLon;
  578. // }
  579. // else if (yaw<=light.light2head+30 and yaw>=light.light2head-30)//判断与侧向红绿灯的朝向
  580. // {
  581. // onelight.isEnable=true;
  582. // onelight.lightType=light.light2Type;
  583. // onelight.timeRemaining=light.light2timeRemaining;
  584. // lightStopLat=light2StopLat;
  585. // lightStopLon=light2StopLon;
  586. // }
  587. // else//不面向红绿灯无效
  588. // {
  589. // onelight.lightType=0xff;
  590. // onelight.timeRemaining=0xff;
  591. // }
  592. if(!RSUTYPE)
  593. {
  594. float yaw=m_structMGpsImu.yaw+180;
  595. //qDebug()<<yaw<<light.light1head<<light.light1head;
  596. if (yaw>=360)
  597. {
  598. yaw=yaw-360;
  599. }
  600. double angleDifference1 = std::fmod(yaw-light.light1head+360,360);
  601. double angleDifference2 = std::fmod(yaw-light.light2head+360,360);
  602. if (angleDifference1<=30.0 || angleDifference1>=360.0-30.0)
  603. {
  604. onelight.isEnable=true;
  605. onelight.lightType=light.light1Type;
  606. onelight.timeRemaining=light.light1timeRemaining;
  607. lightStopLat=light1StopLat;
  608. lightStopLon=light1StopLon;
  609. light.myface=0x01;
  610. }
  611. else if (angleDifference2<=30.0 || angleDifference2>=360.0-30.0)
  612. {
  613. onelight.isEnable=true;
  614. onelight.lightType=light.light2Type;
  615. onelight.timeRemaining=light.light2timeRemaining;
  616. lightStopLat=light2StopLat;
  617. lightStopLon=light2StopLon;
  618. light.myface=0x02;
  619. }
  620. else
  621. {
  622. onelight.lightType=0xff;
  623. onelight.timeRemaining=0xff;
  624. }
  625. }
  626. if (RSUTYPE)
  627. {
  628. switch (int(light.myface))
  629. {
  630. case 1:
  631. onelight.isEnable=true;
  632. onelight.lightType=light.light1Type;
  633. onelight.timeRemaining=light.light1timeRemaining;
  634. lightStopLat=light1StopLat;
  635. lightStopLon=light1StopLon;
  636. break;
  637. case 2:
  638. onelight.isEnable=true;
  639. onelight.lightType=light.light2Type;
  640. onelight.timeRemaining=light.light2timeRemaining;
  641. lightStopLat=light2StopLat;
  642. lightStopLon=light2StopLon;
  643. break;
  644. case 3:
  645. onelight.isEnable=true;
  646. onelight.lightType=light.light3Type;
  647. onelight.timeRemaining=light.light1timeRemaining;
  648. lightStopLat=light1StopLat;
  649. lightStopLon=light1StopLon;
  650. break;
  651. case 4:
  652. onelight.isEnable=true;
  653. onelight.lightType=light.light4Type;
  654. onelight.timeRemaining=light.light2timeRemaining;
  655. lightStopLat=light2StopLat;
  656. lightStopLon=light2StopLon;
  657. break;
  658. default:
  659. onelight.lightType=0xff;
  660. onelight.timeRemaining=0xff;
  661. break;
  662. }
  663. }
  664. outLight(onelight);
  665. sendProto_flag=true;
  666. }
  667. else
  668. {
  669. initLight1();
  670. initLight2();
  671. initLight3();
  672. initLight4();
  673. initFace();
  674. ui->vertical_lighthead->setText("");
  675. ui->vertical_lighthead_2->setText("");
  676. ui->vertical_lighthead_3->setText("");
  677. ui->vertical_lighthead_4->setText("");
  678. if (visionsendstate)
  679. {
  680. visionflag=true;//start vision result upload of traffic light information
  681. }
  682. }
  683. //-----------------------------------------显示虚拟车发送---------------------------------------------------------
  684. congestionIdenti=m_pc5->ui_identification();
  685. if (congestionIdenti.isEnable)
  686. {
  687. ui->lineEdit_jamsMode->setText("虚拟车信息已发送");
  688. ui->button_jamsMode->setStyleSheet("background-color: green");
  689. outCongestionIdenti(congestionIdenti);
  690. sendProto_flag=true;
  691. }
  692. else
  693. {
  694. ui->lineEdit_jamsMode->setText("");
  695. ui->button_jamsMode->setStyleSheet("background-color: gray");
  696. }
  697. //------------------------------------------危险驾驶显示-------------------------------------------------------
  698. if (mbdriCrimsEn)
  699. {
  700. bool warn_driver=m_pc5->show_warn_driver();
  701. if (warn_driver)
  702. {
  703. ui->textBr_FCW_2->append(QTime::currentTime().toString("hh:mm:ss.zzz")+"进入危险驾驶模式");
  704. ui->button_DriCrimsLight_st->setStyleSheet("background-color: red");
  705. }
  706. else
  707. {
  708. ui->button_DriCrimsLight_st->setStyleSheet("background-color: gray");
  709. //ui->textBr_FCW->append("连接丢失");
  710. }
  711. }
  712. //------------------------------------sendproto--------------------------------------------------------------------
  713. if (sendProto_flag)
  714. {
  715. sendProto(protobuf);
  716. sendProto_flag=false;
  717. }
  718. }
  719. //------------------------------------------共享内存读取------------------------------------------------------------------
  720. void MainWindow::setTboxMemoryRaw()//云平台信息写入
  721. {
  722. Memory tboxM;
  723. tboxM.gps_lng=m_structMGpsImu.gps_lng;
  724. tboxM.gps_lat=m_structMGpsImu.gps_lat;
  725. tboxM.speed=m_structMGpsImu.speed;
  726. tboxM.yaw=m_structMGpsImu.yaw;
  727. // tboxM.ele_voltage=m_structChassisRaw.soc;
  728. // tboxM.error=getError();
  729. m_tbox->setTboxMemmory(tboxM);
  730. }
  731. void MainWindow::UpdateGps(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  732. {
  733. bool isSend=false;
  734. double heading,ve,vn;
  735. iv::gps::gpsimu xgpsimu;
  736. //qDebug()<<111;
  737. if(!xgpsimu.ParseFromArray(strdata,nSize))
  738. {
  739. // mivlog->warn("ADCIntelligentVehicle::UpdateGPSIMU parse error. nSize is %d",nSize);
  740. return;
  741. }
  742. if(xgpsimu.has_lat())
  743. {
  744. isSend=true;
  745. m_structMGpsImu.gps_lat=xgpsimu.lat();
  746. //qDebug()<<xgpsimu.lat();
  747. }
  748. if(xgpsimu.has_lon())
  749. {
  750. isSend=true;
  751. m_structMGpsImu.gps_lng=xgpsimu.lon();
  752. //qDebug()<<xgpsimu.lon();
  753. }
  754. if(xgpsimu.has_heading())
  755. {
  756. isSend=true;
  757. heading = xgpsimu.heading();
  758. if(heading<0)
  759. {
  760. heading = heading+360.0;
  761. }
  762. m_structMGpsImu.yaw=float(heading);
  763. }
  764. if((xgpsimu.has_ve())&&(xgpsimu.has_vn()))
  765. {
  766. isSend = true;
  767. ve = xgpsimu.ve(); //东向速度,单位(米/秒)
  768. vn = xgpsimu.vn(); //北向速度,单位(米/秒)
  769. m_structMGpsImu.speed=float(sqrt(ve*ve+vn*vn))* 3.6;
  770. }
  771. if(xgpsimu.has_acce_x())
  772. {
  773. isSend=true;
  774. m_structMGpsImu.accx=float(xgpsimu.acce_x());
  775. }
  776. if(xgpsimu.has_acce_y())
  777. {
  778. isSend=true;
  779. m_structMGpsImu.accy = (xgpsimu.acce_y());
  780. }
  781. if (xgpsimu.has_rtk_state())
  782. {
  783. if (xgpsimu.rtk_state()==6)
  784. {
  785. seneor_m.gps_flag=0x01;
  786. mGPSs=3;
  787. m_tbox->setSensorMemmory(seneor_m);
  788. }
  789. }
  790. if(isSend)
  791. {
  792. setTboxMemoryRaw();
  793. m_pc5->setGpsImuMemory(m_structMGpsImu);
  794. }
  795. }
  796. void MainWindow::UpdateCAM(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  797. {
  798. iv::vision::rawpic xrawpic;
  799. if(!xrawpic.ParseFromArray(strdata,nSize))
  800. {
  801. return;
  802. }
  803. seneor_m.camera_back=0x01;
  804. seneor_m.camera_front=0x01;
  805. seneor_m.camera_left=0x01;
  806. seneor_m.camera_right=0x01;
  807. mCAMs=5;
  808. m_tbox->setSensorMemmory(seneor_m);
  809. }
  810. void MainWindow::UpdateLIDAR(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  811. {
  812. // iv::fusion::fusionobject xfusionobject;
  813. // if(!xfusionobject.ParseFromArray(strdata,nSize))
  814. // {
  815. // return;
  816. // }
  817. unsigned int * pHeadSize = (unsigned int *)strdata;
  818. if(*pHeadSize > nSize)
  819. {
  820. std::cout<<"ListenPointCloud data is small headsize ="<<*pHeadSize<<" data size is"<<nSize<<std::endl;
  821. }
  822. seneor_m.lidar_left=0x01;
  823. seneor_m.lidar_mid=0x01;
  824. seneor_m.lidar_right=0x01;
  825. mLIDARs=3;
  826. m_tbox->setSensorMemmory(seneor_m);
  827. }
  828. void MainWindow::UpdateRADAR(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  829. {
  830. //qDebug()<<'recve radar';
  831. iv::radar::radarobject xradarobject;
  832. if(!xradarobject.ParseFromArray(strdata,nSize))
  833. {
  834. std::cout<<"radar data is small headsize ="<<std::endl;
  835. }
  836. seneor_m.radar=0x01;
  837. mRADARs=3;
  838. m_tbox->setSensorMemmory(seneor_m);
  839. }
  840. //转发视觉红绿灯识别的数据
  841. void MainWindow::Updatelight(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
  842. {
  843. iv::vision::Lightarray lightmessage;
  844. onelightMessage visionligth;
  845. if(lightmessage.ParseFromArray(strdata,nSize))
  846. {
  847. if (lightmessage.light(0).has_type() and visionflag)
  848. {
  849. visionligth.lightType=lightmessage.light(0).type();
  850. visionligth.timeRemaining=0xff;
  851. camera_trafficlight_type=visionligth.lightType;
  852. //qDebug()<<111;
  853. lightStopLat=light1StopLat;
  854. lightStopLon=light1StopLon;
  855. sendProto_flag=true;
  856. outLight(visionligth);
  857. }
  858. }
  859. }
  860. //--------------------------------------------共享内存写入--------------------------------------------------------------
  861. void MainWindow::outmbpause(bool runmod)
  862. {
  863. protobuf.set_mbpause(runmod);
  864. }
  865. void MainWindow::outLight(onelightMessage light1)
  866. {
  867. //iv::v2r::v2r_send protobuf;
  868. protobuf.set_radiolighttype(light1.lightType);
  869. if (visionflag)
  870. {
  871. if(light1.lightType==2)
  872. {
  873. light1.timeRemaining=5;
  874. }
  875. else if(light1.lightType==3)
  876. {
  877. light1.timeRemaining=3;
  878. }
  879. else if(light1.lightType==1)
  880. {
  881. light1.timeRemaining = 5;
  882. }
  883. }
  884. protobuf.set_radiolightremain(light1.timeRemaining);
  885. // if(visionflag)
  886. // {
  887. // float yaw=m_structMGpsImu.yaw+180;
  888. // if (yaw>=360)
  889. // {
  890. // yaw=yaw-360;
  891. // }
  892. // if (yaw<=light1Stophead+30 and yaw>=light1Stophead-30)//判断与正向红绿灯的朝向
  893. // {
  894. // lightStopLat=light1StopLat;
  895. // lightStopLon=light1StopLon;
  896. // }
  897. // else if (yaw<=light2Stophead+30 and yaw>=light2Stophead-30)//判断与侧向红绿灯的朝向
  898. // {
  899. // lightStopLat=light2StopLat;
  900. // lightStopLon=light2StopLon;
  901. // }
  902. // else{
  903. // lightStopLat=0xff;
  904. // lightStopLon=0xff;
  905. // }
  906. // protobuf.set_trafficlightstoplat(lightStopLat);
  907. // protobuf.set_trafficlightstoplon(lightStopLon);
  908. // //sendProto(protobuf);
  909. // }
  910. // if (visionflag)
  911. // {
  912. // float yaw=m_structMGpsImu.yaw+180;
  913. // if (yaw>=360)
  914. // {
  915. // yaw=yaw-360;
  916. // }
  917. // double angleDifference1 = std::fmod(yaw - light1Stophead + 360.0, 360.0);
  918. // double angleDifference2 = std::fmod(yaw - light2Stophead + 360.0, 360.0);
  919. // if (angleDifference1<=30.0 || angleDifference1>=360.0-30.0)
  920. // {
  921. // lightStopLat=light1StopLat;
  922. // lightStopLon=light1StopLon;
  923. // }
  924. // else if (angleDifference2<=30.0 || angleDifference2>=360.0-30.0)
  925. // {
  926. // lightStopLat=light2StopLat;
  927. // lightStopLon=light2StopLon;
  928. // }
  929. // else
  930. // {
  931. // lightStopLat=0xff;
  932. // lightStopLon=0xff;
  933. // }
  934. // }
  935. if(visionflag)
  936. {
  937. lightStopLat=light1StopLat;
  938. lightStopLon=light1StopLon;
  939. }
  940. protobuf.set_trafficlightstoplat(lightStopLat);
  941. protobuf.set_trafficlightstoplon(lightStopLon);
  942. //sendProto(protobuf);
  943. //qDebug()<<"outLight";
  944. }
  945. void MainWindow::outRealtimeTraffic(realtimeTrafficMessage realtimeTraffic)
  946. {
  947. double lat=((double)realtimeTraffic.lat);//1000000.0;
  948. double lon=((double)realtimeTraffic.lng);//1000000.0;
  949. protobuf.set_radiobroadcastgpslat(lat);
  950. protobuf.set_radiobroadcastgpslon(lon);
  951. protobuf.set_radiobroadcastrange(realtimeTraffic.scope);
  952. protobuf.set_radiobroadcasttraffictype(realtimeTraffic.trafficInfo);
  953. protobuf.set_radiobroadcastspeedlimit(realtimeTraffic.speedLimit);
  954. //sendProto(protobuf);
  955. //qDebug()<<"outRealtimeTraffic"<<lat<<lon<<realtimeTraffic.scope<<realtimeTraffic.trafficInfo<<realtimeTraffic.speedLimit;
  956. }
  957. void MainWindow::outCollisionWarning(collisionEarlyWarningMessage collisionWarning)
  958. {
  959. //iv::v2r::v2r_send protobuf;
  960. protobuf.set_radiowarningtype(collisionWarning.warningType);
  961. protobuf.set_radiowarningspeedlimit(collisionWarning.speedLimit);
  962. //qDebug()<<"[Radio]:warning type is "<<collisionWarning.warningType<<".speed limit is:"<<collisionWarning.speedLimit<<endl;
  963. //sendProto(protobuf);
  964. }
  965. void MainWindow::outCongestionIdenti(congestionIdentificationMessage congestionIdenti)
  966. {
  967. //iv::v2r::v2r_send protobuf;
  968. protobuf.set_radioidentistart(congestionIdenti.openCommand);
  969. //qDebug()<<"[Radio]:congestion identi open command is "<<congestionIdenti.openCommand<<endl;
  970. //sendProto(protobuf);
  971. }
  972. void MainWindow::outV2VData(QMap<QString, OBUCarFormation> V2VMessage)
  973. {
  974. int id=0;
  975. iv::fusion::fusionobjectarray out_v2v;
  976. out_v2v.Clear();
  977. std::string out;
  978. out.clear();
  979. if (v2vshow)
  980. {
  981. ui->v2vnumlineEdit->setText("车辆数:"+QString::number(V2VMessage.size()));
  982. ui->v2vcomboBox->clear();
  983. }
  984. for (auto it=V2VMessage.begin();it !=V2VMessage.end();++it)
  985. {
  986. iv::fusion::fusionobject v2v_object;
  987. iv::fusion::fusionobject *v2v_object_;
  988. OBUCarFormation V2Vcar=it.value();
  989. if (v2vshow)
  990. {
  991. ui->v2vcomboBox->addItem(V2Vcar.vin);
  992. }
  993. double lng=V2Vcar.gps_lng;
  994. double lat=V2Vcar.gps_lat;
  995. float yaw=V2Vcar.car_yaw;
  996. yaw=calculateRelativeAngle(m_structMGpsImu.yaw,yaw);
  997. float x=V2Vcar.car_length;
  998. float y=V2Vcar.car_width;
  999. float z=V2Vcar.car_height;
  1000. float centroid_x=V2Vcar.coordinate_front;
  1001. float centroid_y=V2Vcar.coordinate_left;
  1002. v2v_object.set_id(id);
  1003. v2v_object.set_type(0);
  1004. v2v_object.set_sensor_type(0);
  1005. v2v_object.set_yaw(yaw);
  1006. iv::fusion::Dimension dimension;
  1007. iv::fusion::Dimension *dimension_;
  1008. dimension.set_x(x);
  1009. dimension.set_y(y);
  1010. dimension.set_z(z);
  1011. dimension_ = v2v_object.mutable_dimensions();
  1012. dimension_->CopyFrom(dimension);
  1013. double now_x,now_y,gps_x,gps_y,car_x,car_y;
  1014. GaussProjCal(m_structMGpsImu.gps_lng,m_structMGpsImu.gps_lat,now_x,now_y);
  1015. GaussProjCal(lng,lat,gps_x,gps_y);
  1016. Coordinate_Transfer(gps_x,gps_y,now_x,now_y,m_structMGpsImu.yaw,car_x,car_y);
  1017. if (v2vshowmore)
  1018. {
  1019. if (V2Vcar.vin==ui->v2vcomboBox->currentText())
  1020. {
  1021. ui->textBr_v2vdata->setText(QTime::currentTime().toString("hh:mm:ss.zzz") + \
  1022. "\n\t位置[ 经度:" + QString::number(lng,'g',10) +\
  1023. " 纬度:" + QString::number(lat,'g',10) +\
  1024. " \n\t横向:" + QString::number(car_x)+ "m"+\
  1025. " 纵向:" + QString::number(car_y)+ "m"+ \
  1026. " ]\n\t航向: " + QString::number(V2Vcar.car_yaw) + "°" + \
  1027. "\n\t大小[ 长:" + QString::number(x) + "m"+\
  1028. " 宽:" + QString::number(y) + "m"+ \
  1029. " 高:" + QString::number(z) + "m"+ \
  1030. "]\n\t方向盘转角:"+QString::number(V2Vcar.steering_wheel_angle)+ "°");
  1031. QByteArray v2v_error=m_pc5->upV2Vdatashow();
  1032. ui->textBr_v2vdata_2->setText(QTime::currentTime().toString("hh:mm:ss.zzz")+":"+v2v_error);
  1033. }
  1034. }
  1035. iv::fusion::PointXYZ centroid;
  1036. iv::fusion::PointXYZ *centroid_;
  1037. centroid.set_x(car_x);
  1038. centroid.set_y(car_y);
  1039. centroid.set_z(0);
  1040. centroid_ = v2v_object.mutable_centroid();
  1041. centroid_->CopyFrom(centroid);
  1042. // int xp = (int)((x/0.2)/2.0);
  1043. // if(xp == 0)xp=1;
  1044. // int yp = (int)((y/0.2)/2.0);
  1045. // if(yp == 0)yp=1;
  1046. // int ix,iy;
  1047. // for(ix = 0; ix<(xp*2); ix++)
  1048. // {
  1049. // for(iy = 0; iy<(yp*2); iy++)
  1050. // {
  1051. // iv::fusion::NomalXYZ nomal_centroid;
  1052. // iv::fusion::NomalXYZ *nomal_centroid_;
  1053. // float nomal_x = ix*0.2 - xp*0.2;
  1054. // float nomal_y = iy*0.2 - yp*0.2;
  1055. // float nomal_z = 1.0;
  1056. // float s = nomal_x*cos(yaw)
  1057. // - nomal_y*sin(yaw);
  1058. // float t = nomal_x*sin(yaw)
  1059. // + nomal_y*cos(yaw);
  1060. // nomal_centroid.set_nomal_x(car_x + s);
  1061. // nomal_centroid.set_nomal_y(car_y + t);
  1062. // if(abs(car_x + s) <1.3 &&
  1063. // car_y + t <1.0) continue;
  1064. // else{
  1065. // nomal_centroid.set_nomal_x(car_x + s);
  1066. // nomal_centroid.set_nomal_y(car_y + t);
  1067. // //iv::fusion::fusionobject &fusion_obj = (iv::fusion::fusionobject &)lidar_radar_fusion_object_array.obj(i);
  1068. // nomal_centroid_ = v2v_object.add_nomal_centroid();
  1069. // nomal_centroid_->CopyFrom(nomal_centroid);
  1070. // }
  1071. // }
  1072. // }
  1073. v2v_object_ = out_v2v.add_obj();
  1074. v2v_object_->CopyFrom(v2v_object);
  1075. id++;
  1076. }
  1077. if (v2vshow==1)
  1078. {
  1079. v2vshow=0;
  1080. ui->button_v2vshow_en->setStyleSheet("background-color: gray");
  1081. }
  1082. if(out_v2v.obj_size()==0)
  1083. {
  1084. iv::fusion::fusionobject fake_obj;
  1085. iv::fusion::fusionobject *fake_obj_;
  1086. iv::fusion::PointXYZ fake_cen;
  1087. iv::fusion::PointXYZ *fake_cen_;
  1088. fake_cen.set_x(10000);
  1089. fake_cen.set_y(10000);
  1090. fake_cen.set_z(10000);
  1091. fake_cen_ = fake_obj.mutable_centroid();
  1092. fake_cen_ ->CopyFrom(fake_cen);
  1093. fake_obj_ = out_v2v.add_obj();
  1094. fake_obj_->CopyFrom(fake_obj);
  1095. out = out_v2v.SerializeAsString();
  1096. }
  1097. else{
  1098. out = out_v2v.SerializeAsString();
  1099. }
  1100. //qDebug()<<out_v2v.obj_size();
  1101. iv::modulecomm::ModuleSendMsg(gfu,out.data(),out.length());
  1102. }
  1103. void MainWindow::sendProto(iv::v2r::v2r_send radio_protobuf_send)
  1104. {
  1105. char * strser;
  1106. bool bser;
  1107. int nbytesize;
  1108. nbytesize = radio_protobuf_send.ByteSize();
  1109. strser = new char[nbytesize];
  1110. bser = radio_protobuf_send.SerializeToArray(strser,nbytesize);
  1111. if(bser)
  1112. {
  1113. //qDebug()<<"[Radio]:ready send protobuffer"<<endl;
  1114. iv::modulecomm::ModuleSendMsg(mpmem_radio_send_addr,strser,nbytesize);
  1115. //qDebug()<<"[Radio]:has sended protobuffer"<<endl;
  1116. } else
  1117. {
  1118. //qDebug()<<"proto fail"<<endl;
  1119. //mivlog->error("sendData","[%s:] radio serialize error.",__func__);
  1120. // gfault->SetFaultState(1, 0, "radio serialize err");
  1121. }
  1122. delete strser;
  1123. }
  1124. //--------------------------------------------按钮使能控制---------------------------------------------------------------
  1125. //云平台使能控制
  1126. void MainWindow::on_button_platform_en_clicked()
  1127. {
  1128. if(mplatformEn)
  1129. {
  1130. ui->button_platform_en->setStyleSheet("background-color: gray");
  1131. mplatformEn = false;
  1132. m_tbox->setTboxConnectEnable(false);
  1133. }
  1134. else
  1135. {
  1136. ui->button_platform_en->setStyleSheet("background-color: green");
  1137. mplatformEn = true;
  1138. m_tbox->setTboxConnectEnable(true);
  1139. }
  1140. }
  1141. //路测设备使能控制
  1142. void MainWindow::on_button_obu_en_clicked()
  1143. {
  1144. if(mobuEn==1)
  1145. {
  1146. ui->button_obu_en->setStyleSheet("background-color: gray");
  1147. mobuEn = 0;
  1148. m_pc5->setConnectEnable(false);
  1149. }
  1150. else
  1151. {
  1152. ui->button_obu_en->setStyleSheet("background-color: green");
  1153. mobuEn = 1;
  1154. m_pc5->setConnectEnable(true);
  1155. }
  1156. }
  1157. void MainWindow::on_button_v2v_en_clicked()
  1158. {
  1159. if(v2vEn==1)
  1160. {
  1161. ui->button_v2v_en->setStyleSheet("background-color: gray");
  1162. v2vEn = 0;
  1163. m_pc5->setConnectEnable2(false);
  1164. QMap<QString,OBUCarFormation> V2VMessage;
  1165. outV2VData(V2VMessage);
  1166. }
  1167. else
  1168. {
  1169. ui->button_v2v_en->setStyleSheet("background-color: green");
  1170. v2vEn = 1;
  1171. m_pc5->setConnectEnable2(true);
  1172. }
  1173. }
  1174. //云平台控制启停使能控制
  1175. void MainWindow::on_button_v2xrunmod_en_clicked()
  1176. {
  1177. if (mpc5RunmodEn==0){
  1178. if(mv2xRunmodEn==1)
  1179. {
  1180. ui->button_v2xrunmod_en->setStyleSheet("background-color: gray");
  1181. mv2xRunmodEn = 0;
  1182. }
  1183. else
  1184. {
  1185. ui->button_v2xrunmod_en->setStyleSheet("background-color: green");
  1186. mv2xRunmodEn = 1;
  1187. }
  1188. if (!mplatformEn)
  1189. {
  1190. ui->button_v2xrunmod_en->setStyleSheet("background-color: red");
  1191. mv2xRunmodEn = 0;
  1192. }
  1193. }
  1194. }
  1195. void MainWindow::on_button_pc5runmod_en_clicked()
  1196. {
  1197. if (mv2xRunmodEn==0){
  1198. if(mpc5RunmodEn==1)
  1199. {
  1200. ui->button_pc5runmod_en->setStyleSheet("background-color: gray");
  1201. mpc5RunmodEn = 0;
  1202. }
  1203. else
  1204. {
  1205. ui->button_pc5runmod_en->setStyleSheet("background-color: green");
  1206. mpc5RunmodEn = 1;
  1207. }
  1208. if (!mobuEn)
  1209. {
  1210. ui->button_pc5runmod_en->setStyleSheet("background-color: red");
  1211. mpc5RunmodEn = 0;
  1212. }
  1213. }
  1214. }
  1215. void MainWindow::on_button_car_vin_set_clicked()
  1216. {
  1217. bool ok;
  1218. QString text = QInputDialog::getText(this, tr("输入车辆VIN:"),
  1219. tr("VIN:"), QLineEdit::Normal,
  1220. Q_NULLPTR, &ok);
  1221. if (ok && !text.isEmpty())
  1222. {
  1223. gstrcarvin = text.toStdString();
  1224. ui->lineEdit->setText(text);
  1225. m_tbox->setTboxNewVin(gstrcarvin);
  1226. m_pc5->setVin(gstrcarvin);
  1227. }
  1228. }
  1229. void MainWindow::on_button_obu_vin_set_clicked()
  1230. {
  1231. bool ok;
  1232. QString text = QInputDialog::getText(this, tr("输入路侧VIN:"),
  1233. tr("VIN:"), QLineEdit::Normal,
  1234. Q_NULLPTR, &ok);
  1235. if (ok && !text.isEmpty())
  1236. {
  1237. int gstrobuvin = text.toInt();
  1238. ui->lineEdit_obu_vin->setText(text);
  1239. m_pc5->setobuNewVin(gstrobuvin);
  1240. }
  1241. }
  1242. void MainWindow::on_button_trafficInfo_en_clicked()
  1243. {
  1244. if(mbTrafficInfoEn==1)
  1245. {
  1246. ui->button_trafficInfo_en->setStyleSheet("background-color: gray");
  1247. mbTrafficInfoEn = 0;
  1248. }
  1249. else
  1250. {
  1251. ui->button_trafficInfo_en->setStyleSheet("background-color: green");
  1252. mbTrafficInfoEn = 1;
  1253. }
  1254. }
  1255. void MainWindow::on_button_FCW_en_clicked()
  1256. {
  1257. if(mbFCWEn==1)
  1258. {
  1259. ui->button_FCW_en->setStyleSheet("background-color: gray");
  1260. mbFCWEn = 0;
  1261. }
  1262. else
  1263. {
  1264. ui->button_FCW_en->setStyleSheet("background-color: green");
  1265. mbFCWEn = 1;
  1266. }
  1267. }
  1268. void MainWindow::on_button_DriCrims_en_clicked()
  1269. {
  1270. if(mbdriCrimsEn==1)
  1271. {
  1272. ui->button_DriCrims_en->setStyleSheet("background-color: gray");
  1273. mbdriCrimsEn = 0;
  1274. }
  1275. else
  1276. {
  1277. ui->button_DriCrims_en->setStyleSheet("background-color: green");
  1278. mbdriCrimsEn = 1;
  1279. }
  1280. }
  1281. void MainWindow::on_button_v2vshow_en_clicked()
  1282. {
  1283. if(v2vshow==1)
  1284. {
  1285. ui->button_v2vshow_en->setStyleSheet("background-color: gray");
  1286. v2vshow = 0;
  1287. }
  1288. else
  1289. {
  1290. ui->button_v2vshow_en->setStyleSheet("background-color: green");
  1291. v2vshow = 1;
  1292. }
  1293. }
  1294. void MainWindow::on_button_v2vshowmore_en_clicked()
  1295. {
  1296. if(v2vshowmore==1)
  1297. {
  1298. ui->button_v2vshowmore_en->setStyleSheet("background-color: gray");
  1299. v2vshowmore = 0;
  1300. }
  1301. else
  1302. {
  1303. ui->button_v2vshowmore_en->setStyleSheet("background-color: green");
  1304. v2vshowmore = 1;
  1305. }
  1306. }
  1307. void MainWindow::on_button_SimCar_en_clicked()
  1308. {
  1309. ui_set_virtualVehicleM struct_ui_VirtualVehicle;
  1310. struct_ui_VirtualVehicle.lngMax= ui->lineEdit_jamsLon_up->text().toDouble();
  1311. struct_ui_VirtualVehicle.lngMin= ui->lineEdit_jamsLon_low->text().toDouble();
  1312. struct_ui_VirtualVehicle.latMax=ui->lineEdit_jamsLat_Up->text().toDouble();
  1313. struct_ui_VirtualVehicle.latMin=ui->lineEdit_jamsLat_low->text().toDouble();
  1314. struct_ui_VirtualVehicle.yawMax=ui->lineEdit_jamsHead_up->text().toDouble();
  1315. struct_ui_VirtualVehicle.yawMin=ui->lineEdit_jamsHead_low->text().toDouble();
  1316. struct_ui_VirtualVehicle.virtualVehicleNum= int(ui->lineEdit_jamsCarNum->text().toInt());
  1317. struct_ui_VirtualVehicle.speedMax=ui->lineEdit_jamsSpeed_up->text().toDouble();
  1318. struct_ui_VirtualVehicle.speedMin=ui->lineEdit_jamsSpeed_low->text().toDouble();
  1319. m_pc5->my_ui_set=struct_ui_VirtualVehicle;
  1320. //m_pc5->upVirtualVehicle(struct_ui_VirtualVehicle);
  1321. // virtualVehicleM structVirtualVehicle;
  1322. // int randId=qrand()%10000;
  1323. // m_vectorRandom.push_back(randId);
  1324. // for(int i=1;i<virtualVehicleNum;i++) {
  1325. // getRandomNum();
  1326. // }
  1327. // for(int i=0;i<virtualVehicleNum;i++) {
  1328. // structVirtualVehicle.vin = m_vectorVin[i];
  1329. // structVirtualVehicle.gps_lat=latMin+((double(m_vectorRandom[i]))/10000.0)*(latMax-latMin);
  1330. // structVirtualVehicle.gps_lng=lngMin+((double(m_vectorRandom[i]))/10000.0)*(lngMax-lngMin);
  1331. // structVirtualVehicle.speed=speedMin+((float(m_vectorRandom[i]))/10000.0)*(speedMax-speedMin);
  1332. // structVirtualVehicle.yaw=yawMin+((float(m_vectorRandom[i]))/10000.0)*(yawMax-yawMin);
  1333. // m_pc5->upVirtualVehicle(structVirtualVehicle);
  1334. // }
  1335. }
  1336. //void MainWindow::on_button_SimCar_en_clicked()
  1337. //{
  1338. // double lngMax= ui->lineEdit_jamsLon_up->text().toDouble();
  1339. // double lngMin= ui->lineEdit_jamsLon_low->text().toDouble();
  1340. // double latMax=ui->lineEdit_jamsLat_Up->text().toDouble();
  1341. // double latMin=ui->lineEdit_jamsLat_low->text().toDouble();
  1342. // float yawMax=ui->lineEdit_jamsHead_up->text().toDouble();
  1343. // float yawMin=ui->lineEdit_jamsHead_low->text().toDouble();
  1344. // int virtualVehicleNum= int(ui->lineEdit_jamsCarNum->text().toInt());
  1345. // float speedMax=ui->lineEdit_jamsSpeed_up->text().toDouble();
  1346. // float speedMin=ui->lineEdit_jamsSpeed_low->text().toDouble();
  1347. // virtualVehicleM structVirtualVehicle;
  1348. // int randId=qrand()%10000;
  1349. // m_vectorRandom.push_back(randId);
  1350. // for(int i=1;i<virtualVehicleNum;i++) {
  1351. // getRandomNum();
  1352. // }
  1353. // for(int i=0;i<virtualVehicleNum;i++) {
  1354. // structVirtualVehicle.vin = m_vectorVin[i];
  1355. // structVirtualVehicle.gps_lat=latMin+((double(m_vectorRandom[i]))/10000.0)*(latMax-latMin);
  1356. // structVirtualVehicle.gps_lng=lngMin+((double(m_vectorRandom[i]))/10000.0)*(lngMax-lngMin);
  1357. // structVirtualVehicle.speed=speedMin+((float(m_vectorRandom[i]))/10000.0)*(speedMax-speedMin);
  1358. // structVirtualVehicle.yaw=yawMin+((float(m_vectorRandom[i]))/10000.0)*(yawMax-yawMin);
  1359. // m_pc5->upVirtualVehicle(structVirtualVehicle);
  1360. // }
  1361. //}
  1362. void MainWindow::on_show_debug_clicked()
  1363. {
  1364. if(mshowdebugEn==1)
  1365. {
  1366. ui->show_debug->setStyleSheet("background-color: gray");
  1367. mshowdebugEn = 0;
  1368. }
  1369. else
  1370. {
  1371. bool ok;
  1372. QString text = QInputDialog::getText(this, tr("scode:"),
  1373. tr("scode:"), QLineEdit::Password,
  1374. Q_NULLPTR, &ok);
  1375. if (ok && !text.isEmpty())
  1376. {
  1377. std::string scode = text.toStdString();
  1378. if (scode=="catarc")
  1379. {
  1380. ui->show_debug->setStyleSheet("background-color: green");
  1381. mshowdebugEn = 1;
  1382. }
  1383. }
  1384. }
  1385. }
  1386. void MainWindow::on_ea_collect_clicked()
  1387. {
  1388. double lat=m_structMGpsImu.gps_lat;
  1389. double lon=m_structMGpsImu.gps_lng;
  1390. float head=m_structMGpsImu.yaw+180;
  1391. if (head>=360){
  1392. head=head-360;
  1393. }
  1394. light1StopLat=lat;
  1395. light1StopLon=lon;
  1396. light1Stophead=head;
  1397. ui->ea_long->setText(QString::number(lon,'g',10));
  1398. ui->ea_lat->setText(QString::number(lat,'g',10));
  1399. ui->ea_head->setText(QString::number(head,'g',10));
  1400. QFile inputFile("./v2xTcpClient.xml"); // 替换成你的XML文件路径
  1401. if (!inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
  1402. qDebug() << "Failed to open the XML file for reading.";
  1403. }
  1404. QTextStream inputStream(&inputFile);
  1405. QString xmlContent = inputStream.readAll();
  1406. inputFile.close();
  1407. // 2. 使用正则表达式查找和替换参数值
  1408. QMap<QString, QString> parameterMap;
  1409. parameterMap["light1Stophead"] = ui->ea_head->text();
  1410. parameterMap["light1StopLat"] = ui->ea_lat->text();
  1411. parameterMap["light1StopLon"] = ui->ea_long->text();
  1412. // 3. 遍历映射并使用正则表达式查找和替换参数值
  1413. for (const QString &paramName : parameterMap.keys()) {
  1414. QRegExp regex("name=\"" + paramName + "\" value=\"[^\"]+\"");
  1415. const QString &newValue = parameterMap[paramName];
  1416. int pos = 0;
  1417. while ((pos = regex.indexIn(xmlContent, pos)) != -1) {
  1418. xmlContent.replace(pos, regex.matchedLength(), "name=\"" + paramName + "\" value=\"" + newValue + "\"");
  1419. pos += regex.matchedLength();
  1420. }
  1421. }
  1422. // 3. 创建一个临时文件用于保存更新后的XML
  1423. QFile outputFile("temp_updated_xml_file.xml");
  1424. if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
  1425. qDebug() << "Failed to open the temporary output XML file for writing.";
  1426. }
  1427. QTextStream outputStream(&outputFile);
  1428. // 4. 重新写入XML文件内容,包括修改后的参数
  1429. outputStream << xmlContent;
  1430. // 5. 关闭文件
  1431. outputFile.close();
  1432. // 6. 删除原始XML文件
  1433. QFile::remove("v2xTcpClient.xml");
  1434. // 7. 重命名临时文件为原始XML文件名
  1435. QFile::rename("temp_updated_xml_file.xml", "v2xTcpClient.xml");
  1436. qDebug() << "XML file has been updated with the original attribute order and parameter change.";
  1437. }
  1438. void MainWindow::on_ns_collect_clicked()
  1439. {
  1440. double lat=m_structMGpsImu.gps_lat;
  1441. double lon=m_structMGpsImu.gps_lng;
  1442. float head=m_structMGpsImu.yaw+180;
  1443. if (head>=360){
  1444. head=head-360;
  1445. }
  1446. light2StopLat=lat;
  1447. light2StopLon=lon;
  1448. light2Stophead=head;
  1449. ui->ns_long->setText(QString::number(lon,'g',10));
  1450. ui->ns_lat->setText(QString::number(lat,'g',10));
  1451. ui->ns_head->setText(QString::number(head,'g',10));
  1452. QFile inputFile("./v2xTcpClient.xml"); // 替换成你的XML文件路径
  1453. if (!inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
  1454. qDebug() << "Failed to open the XML file for reading.";
  1455. }
  1456. QTextStream inputStream(&inputFile);
  1457. QString xmlContent = inputStream.readAll();
  1458. inputFile.close();
  1459. // 2. 使用正则表达式查找和替换参数值
  1460. QMap<QString, QString> parameterMap;
  1461. parameterMap["light2Stophead"] = ui->ns_head->text();
  1462. parameterMap["light2StopLat"] = ui->ns_lat->text();
  1463. parameterMap["light2StopLon"] = ui->ns_long->text();
  1464. // 3. 遍历映射并使用正则表达式查找和替换参数值
  1465. for (const QString &paramName : parameterMap.keys()) {
  1466. QRegExp regex("name=\"" + paramName + "\" value=\"[^\"]+\"");
  1467. const QString &newValue = parameterMap[paramName];
  1468. int pos = 0;
  1469. while ((pos = regex.indexIn(xmlContent, pos)) != -1) {
  1470. xmlContent.replace(pos, regex.matchedLength(), "name=\"" + paramName + "\" value=\"" + newValue + "\"");
  1471. pos += regex.matchedLength();
  1472. }
  1473. }
  1474. // 3. 创建一个临时文件用于保存更新后的XML
  1475. QFile outputFile("temp_updated_xml_file.xml");
  1476. if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
  1477. qDebug() << "Failed to open the temporary output XML file for writing.";
  1478. }
  1479. QTextStream outputStream(&outputFile);
  1480. // 4. 重新写入XML文件内容,包括修改后的参数
  1481. outputStream << xmlContent;
  1482. // 5. 关闭文件
  1483. outputFile.close();
  1484. // 6. 删除原始XML文件
  1485. QFile::remove("v2xTcpClient.xml");
  1486. // 7. 重命名临时文件为原始XML文件名
  1487. QFile::rename("temp_updated_xml_file.xml", "v2xTcpClient.xml");
  1488. qDebug() << "XML file has been updated with the original attribute order and parameter change.";
  1489. }
  1490. void MainWindow::on_ea_cf_clicked()
  1491. {
  1492. double x,y,head;
  1493. x= ui->ea_cf_x->text().toDouble();
  1494. // x=-x;
  1495. y= ui->ea_cf_y->text().toDouble();
  1496. head=m_structMGpsImu.yaw;
  1497. if (head>90)
  1498. {
  1499. head=360-(head-90);
  1500. }
  1501. else{
  1502. head=90-head;
  1503. }
  1504. double now_x,now_y,lat,lon,aim_x,aim_y,aim_lat,aim_lon,dis,add_x,add_y;
  1505. GaussProjCal(m_structMGpsImu.gps_lng,m_structMGpsImu.gps_lat,now_x,now_y);
  1506. add_x=y*qCos(qDegreesToRadians(head))+x*qSin(qDegreesToRadians(head));
  1507. add_y=y*qSin(qDegreesToRadians(head))-x*qCos(qDegreesToRadians(head));
  1508. aim_x=now_x+add_x;
  1509. aim_y=now_y+add_y;
  1510. GaussProjInvCal(aim_x,aim_y,&aim_lon,&aim_lat);
  1511. QFile inputFile("./v2xTcpClient.xml"); // 替换成你的XML文件路径
  1512. if (!inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
  1513. qDebug() << "Failed to open the XML file for reading.";
  1514. }
  1515. QTextStream inputStream(&inputFile);
  1516. QString xmlContent = inputStream.readAll();
  1517. inputFile.close();
  1518. // 2. 使用正则表达式查找和替换参数值
  1519. QMap<QString, QString> parameterMap;
  1520. parameterMap["light_CF_Lat"] = QString::number(aim_lat,'g',10);
  1521. parameterMap["light_CF_Lon"] = QString::number(aim_lon,'g',10);
  1522. // 3. 遍历映射并使用正则表达式查找和替换参数值
  1523. for (const QString &paramName : parameterMap.keys()) {
  1524. QRegExp regex("name=\"" + paramName + "\" value=\"[^\"]+\"");
  1525. const QString &newValue = parameterMap[paramName];
  1526. int pos = 0;
  1527. while ((pos = regex.indexIn(xmlContent, pos)) != -1) {
  1528. xmlContent.replace(pos, regex.matchedLength(), "name=\"" + paramName + "\" value=\"" + newValue + "\"");
  1529. pos += regex.matchedLength();
  1530. }
  1531. }
  1532. // 3. 创建一个临时文件用于保存更新后的XML
  1533. QFile outputFile("temp_updated_xml_file.xml");
  1534. if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
  1535. qDebug() << "Failed to open the temporary output XML file for writing.";
  1536. }
  1537. QTextStream outputStream(&outputFile);
  1538. // 4. 重新写入XML文件内容,包括修改后的参数
  1539. outputStream << xmlContent;
  1540. // 5. 关闭文件
  1541. outputFile.close();
  1542. // 6. 删除原始XML文件
  1543. QFile::remove("v2xTcpClient.xml");
  1544. // 7. 重命名临时文件为原始XML文件名
  1545. QFile::rename("temp_updated_xml_file.xml", "v2xTcpClient.xml");
  1546. qDebug() << "XML file has been updated with the original attribute order and parameter change.";
  1547. }
  1548. void MainWindow::on_ns_cf_clicked()
  1549. {
  1550. double x,y,head;
  1551. x= ui->ns_cf_x->text().toDouble();
  1552. x=-x;
  1553. y= ui->ns_cf_y->text().toDouble();
  1554. head=m_structMGpsImu.yaw;
  1555. if (head>90)
  1556. {
  1557. head=360-(head-90);
  1558. }
  1559. else{
  1560. head=90-head;
  1561. }
  1562. double now_x,now_y,lat,lon,aim_x,aim_y,aim_lat,aim_lon,dis,add_x,add_y;
  1563. GaussProjCal(m_structMGpsImu.gps_lng,m_structMGpsImu.gps_lat,now_x,now_y);
  1564. add_x=y*qCos(qDegreesToRadians(head))+x*qSin(qDegreesToRadians(head));
  1565. add_y=y*qSin(qDegreesToRadians(head))-x*qCos(qDegreesToRadians(head));
  1566. aim_x=now_x+add_x;
  1567. aim_y=now_y+add_y;
  1568. GaussProjInvCal(aim_x,aim_y,&aim_lon,&aim_lat);
  1569. QFile inputFile("./v2xTcpClient.xml"); // 替换成你的XML文件路径
  1570. if (!inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
  1571. qDebug() << "Failed to open the XML file for reading.";
  1572. }
  1573. QTextStream inputStream(&inputFile);
  1574. QString xmlContent = inputStream.readAll();
  1575. inputFile.close();
  1576. // 2. 使用正则表达式查找和替换参数值
  1577. QMap<QString, QString> parameterMap;
  1578. parameterMap["light_CF_Lat"] = QString::number(aim_lat,'g',10);
  1579. parameterMap["light_CF_Lon"] = QString::number(aim_lon,'g',10);
  1580. // 3. 遍历映射并使用正则表达式查找和替换参数值
  1581. for (const QString &paramName : parameterMap.keys()) {
  1582. QRegExp regex("name=\"" + paramName + "\" value=\"[^\"]+\"");
  1583. const QString &newValue = parameterMap[paramName];
  1584. int pos = 0;
  1585. while ((pos = regex.indexIn(xmlContent, pos)) != -1) {
  1586. xmlContent.replace(pos, regex.matchedLength(), "name=\"" + paramName + "\" value=\"" + newValue + "\"");
  1587. pos += regex.matchedLength();
  1588. }
  1589. }
  1590. // 3. 创建一个临时文件用于保存更新后的XML
  1591. QFile outputFile("temp_updated_xml_file.xml");
  1592. if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
  1593. qDebug() << "Failed to open the temporary output XML file for writing.";
  1594. }
  1595. QTextStream outputStream(&outputFile);
  1596. // 4. 重新写入XML文件内容,包括修改后的参数
  1597. outputStream << xmlContent;
  1598. // 5. 关闭文件
  1599. outputFile.close();
  1600. // 6. 删除原始XML文件
  1601. QFile::remove("v2xTcpClient.xml");
  1602. // 7. 重命名临时文件为原始XML文件名
  1603. QFile::rename("temp_updated_xml_file.xml", "v2xTcpClient.xml");
  1604. qDebug() << "XML file has been updated with the original attribute order and parameter change.";
  1605. }
  1606. void MainWindow::on_button_pc5send_clicked()
  1607. {
  1608. QString send_data=ui->plainTextEdit->toPlainText();
  1609. m_pc5->CustomDataSend(send_data);
  1610. }
  1611. void MainWindow::on_button_pc5show_clicked()
  1612. {
  1613. if (mcusdatashowEn==1)
  1614. {
  1615. ui->button_pc5show->setStyleSheet("background-color: gray");
  1616. mcusdatashowEn=0;
  1617. }
  1618. else
  1619. {
  1620. ui->button_pc5show->setStyleSheet("background-color: green");
  1621. mcusdatashowEn=1;
  1622. }
  1623. }
  1624. MainWindow::~MainWindow()
  1625. {
  1626. timer->stop();
  1627. iv::modulecomm::Unregister(mpMemGPS);
  1628. iv::modulecomm::Unregister(mpMemcamera);
  1629. iv::modulecomm::Unregister(mpMemlidar);
  1630. iv::modulecomm::Unregister(mpMemradar);
  1631. iv::modulecomm::Unregister(vision_lightMem);
  1632. delete ui;
  1633. }