123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869 |
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QtMath>
- extern std::string gstrcarvin;
- extern std::string gstrobuvin;
- extern iv::Ivlog * gIvlog;
- int camera_trafficlight_type=200;
- int camera_trafficlight_time=200;
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- m_pc5=new PC5();
- m_tbox=new V2X();
- timer = new QTimer(this);
- connect(timer,SIGNAL(timeout()),SLOT(heartBeat()));
- //timer->start(1000);
- timer->start(500);
- timerV2V= new QTimer(this);
- connect(timerV2V,SIGNAL(timeout()),SLOT(V2VOUT()));
- timerV2V->start(100);
- sendProto_flag=false;
- initUI();
- initMemory();
- initproto();
- initLight1();
- initLight2();
- initLight3();
- initLight4();
- initFace();
- }
- void MainWindow::initMemory()
- {
- m_structMGpsImu.gps_lat=39.149170;
- m_structMGpsImu.gps_lng=117.094250;
- m_structMGpsImu.speed=0.0;
- m_structMGpsImu.yaw=0.0;
- m_structMGpsImu.accx=0.0;
- m_structMGpsImu.accy=0.0;
- seneor_m.lidar_left=0;
- seneor_m.lidar_mid=0;
- seneor_m.lidar_right=0;
- seneor_m.radar=0;
- seneor_m.gps_flag=0;
- seneor_m.camera_front=0;
- seneor_m.camera_back=0;
- seneor_m.camera_left=0;
- seneor_m.camera_right=0;
- m_tbox->setSensorMemmory(seneor_m);
- setTboxMemoryRaw();
- m_pc5->setGpsImuMemory(m_structMGpsImu);
- }
- void MainWindow::initproto()
- {
- mpmem_radio_send_addr = iv::modulecomm::RegisterSend("v2r_send",1000,3);
- ModuleFun fungpsimu =std::bind(&MainWindow::UpdateGps,this,std::placeholders::_1, \
- std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
- mpMemGPS = iv::modulecomm::RegisterRecvPlus(gstrmemgps.data(),fungpsimu);
- // mpMemGPS = iv::modulecomm::RegisterRecv("hcp_gpsimu",iv::V2X::UpdateGps);
- ModuleFun funcamera =std::bind(&MainWindow::UpdateCAM,this,std::placeholders::_1, \
- std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
- mpMemcamera=iv::modulecomm::RegisterRecvPlus(gstrmecamera.data(),funcamera);
- ModuleFun funlidar =std::bind(&MainWindow::UpdateLIDAR,this,std::placeholders::_1, \
- std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
- mpMemlidar=iv::modulecomm::RegisterRecvPlus(gstrmelidar.data(),funlidar);
- ModuleFun funradar =std::bind(&MainWindow::UpdateRADAR,this,std::placeholders::_1, \
- std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
- mpMemradar=iv::modulecomm::RegisterRecvPlus(gstrmeradar.data(),funradar);
- ModuleFun lightState =std::bind(&MainWindow::Updatelight,this,std::placeholders::_1, \
- std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
- vision_lightMem = iv::modulecomm::RegisterRecvPlus(gstrmemlight.data(),lightState);
- }
- void MainWindow::initUI()
- {
- redimg.load(":/light/light/light-red.png");
- redimg = redimg.scaled(66,66,Qt::IgnoreAspectRatio);
- greenimg.load(":/light/light/light-green.png");
- greenimg = greenimg.scaled(66,66,Qt::IgnoreAspectRatio);
- yellowimg.load(":/light/light/light-yellow.png");
- yellowimg = yellowimg.scaled(66,66,Qt::IgnoreAspectRatio);
- blackimg.load(":/light/light/light-black.png");
- blackimg = blackimg.scaled(66,66,Qt::IgnoreAspectRatio);
- nofaceimg.load(":/light/light/noface.png");
- nofaceimg = nofaceimg.scaled(60,50,Qt::IgnoreAspectRatio);
- facetoimg.load(":/light/light/faceto.png");
- facetoimg = facetoimg.scaled(60,50,Qt::IgnoreAspectRatio);
- QString strpath = QCoreApplication::applicationDirPath();
- //strpath = strpath + "/v2xTcpClientWL.xml";
- strpath = "./v2xTcpClient.xml";
- iv::xmlparam::Xmlparam xp(strpath.toStdString());
- std::string rsutype = xp.GetParam("OBU_Type","serial");
- if(rsutype=="eth")
- {
- m_pc5->eth_enable=true;
- std::string localIP = xp.GetParam("obuip","127.0.0.1");
- QString localsetIP =QString::fromStdString(localIP);
- std::string localPort = xp.GetParam("obuport","7777");
- int localsetport=std::stoi(localPort);
- m_pc5->setobu(localsetIP,localsetport);
- RSUTYPE=true;
- }
- else
- {
- m_pc5->eth_enable=false;
- std::string localIP = xp.GetParam("port_name","/dev/ttyUSB0");
- QString localsetIP =QString::fromStdString(localIP);
- std::string localPort = xp.GetParam("baud","9600");
- int localsetport=std::stoi(localPort);
- m_pc5->setSerial(localsetIP,localsetport);
- RSUTYPE=false;
- }
- std::string strCarVIN = xp.GetParam("carVIN","catarc001");
- ui->lineEdit->setText(QString::fromStdString(strCarVIN));
- std::string strObuVIN = xp.GetParam("obuNUM","1");
- ui->lineEdit_obu_vin->setText(QString::fromStdString(strObuVIN));
- int obunum=std::stoi(strObuVIN);
- std::string hostIP = xp.GetParam("hostIP","127.0.0.1");
- QString IP =QString::fromStdString(hostIP);
- ui->lineEdit_severip->setText(IP);
- std::string hostPort = xp.GetParam("hostPort","8000");
- int port=std::stoi(hostPort);
- gstrmemgps = xp.GetParam("gps","gpsimu");
- gstrmecamera = xp.GetParam("camera","rawpic");
- gstrmelidar = xp.GetParam("lidar","lidarstate");
- gstrmeradar = xp.GetParam("radar","radarobject");
- gstrmemlight = xp.GetParam("vision_light","lightarray");
- std::string Stophead1 = xp.GetParam("light1Stophead","0");
- light1Stophead=std::stod(Stophead1);
- std::string StopLat1 = xp.GetParam("light1StopLat","0");
- light1StopLat=std::stod(StopLat1);
- std::string StopLon1 = xp.GetParam("light1StopLon","0");
- light1StopLon=std::stod(StopLon1);
- ui->ea_long->setText(QString::fromStdString(StopLon1));
- ui->ea_lat->setText(QString::fromStdString(StopLat1));
- ui->ea_head->setText(QString::fromStdString(Stophead1));
- std::string Stophead2 = xp.GetParam("light2Stophead","0");
- light2Stophead=std::stod(Stophead2);
- std::string StopLat2 = xp.GetParam("light2StopLat","0");
- light2StopLat=std::stod(StopLat2);
- std::string StopLon2 = xp.GetParam("light2StopLon","0");
- light2StopLon=std::stod(StopLon2);
- ui->ns_long->setText(QString::fromStdString(StopLon2));
- ui->ns_lat->setText(QString::fromStdString(StopLat2));
- ui->ns_head->setText(QString::fromStdString(Stophead2));
- std::string visionsend = xp.GetParam("OpenVisionSend","0");
- visionsendstate=std::stoi(visionsend);
- visionflag=visionsendstate;
- m_pc5->setVin(strCarVIN);
- m_pc5->setobuNewVin(obunum);
- m_tbox->setTboxNewVin(strCarVIN);
- m_tbox->setIPandPort(IP,port);
- }
- void MainWindow::initLight1()
- {
- ui->label_39->setPixmap(QPixmap::fromImage(blackimg));
- ui->lcdgreen_2->display(0);
- // ui->label_7->setPixmap(QPixmap::fromImage(nofaceimg));
- // ui->label_18->setText('');
- // ui->vertical_lighthead->setText("");
- }
- void MainWindow::initLight2()
- {
- ui->label_40->setPixmap(QPixmap::fromImage(blackimg));
- ui->lcdgreen_3->display(0);
- // ui->label_14->setPixmap(QPixmap::fromImage(nofaceimg));
- // ui->label_17->setText('');
- // ui->vertical_lighthead_2->setText("");
- }
- void MainWindow::initLight3()
- {
- ui->label_41->setPixmap(QPixmap::fromImage(blackimg));
- ui->lcdgreen_4->display(0);
- // ui->label_15->setPixmap(QPixmap::fromImage(nofaceimg));
- // ui->label_18->setText('');
- // ui->vertical_lighthead_3->setText("");
- }
- void MainWindow::initLight4()
- {
- ui->label_42->setPixmap(QPixmap::fromImage(blackimg));
- ui->lcdgreen_5->display(0);
- // ui->label_16->setPixmap(QPixmap::fromImage(nofaceimg));
- // ui->label_20->setText('');
- // ui->vertical_lighthead_4->setText("");
- }
- void MainWindow::initFace()
- {
- ui->label_7->setPixmap(QPixmap::fromImage(nofaceimg));
- ui->label_18->setText("");
- ui->label_14->setPixmap(QPixmap::fromImage(nofaceimg));
- ui->label_17->setText("");
- ui->label_15->setPixmap(QPixmap::fromImage(nofaceimg));
- ui->label_19->setText("");
- ui->label_16->setPixmap(QPixmap::fromImage(nofaceimg));
- ui->label_20->setText("");
- }
- void MainWindow::V2VOUT()
- {
- //---------------------------------------V2V--------------------------------------------------------------------
- if (v2vEn)
- {
- try
- {
- QMap<QString,OBUCarFormation> V2VMessage=m_pc5->updateV2V();
- outV2VData(V2VMessage);
- }
- catch(...){
- qDebug()<<"...";
- }
- }
- }
- void MainWindow::heartBeat()
- {
- protobuf.Clear();
- //-----------------------------------------send runflag---------------------------------------------------------
- //qDebug()<<mv2xRunmodEn<<mpc5RunmodEn;
- if (mv2xRunmodEn)
- {
- bool runmod=m_tbox->upRunMod();
- //qDebug()<<runmod;
- outmbpause(runmod);
- sendProto_flag=true;
- mpc5RunmodEn=false;
- ui->button_pc5runmod_en->setStyleSheet("background-color: gray");
- }
- else if (mpc5RunmodEn)
- {
- bool runmod=m_pc5->upRunMod();
- //qDebug()<<runmod;
- outmbpause(runmod);
- sendProto_flag=true;
- mv2xRunmodEn=false;
- ui->button_v2xrunmod_en->setStyleSheet("background-color: gray");
- }
- else{
- outmbpause(false);
- sendProto_flag=true;
- }
- if (visionflag)
- {
- onelightMessage onelight;
- onelight.lightType= camera_trafficlight_type;
- if(onelight.lightType==2)
- {
- onelight.timeRemaining=5;
- }
- else if(onelight.lightType==3)
- {
- onelight.timeRemaining=3;
- }
- else if(onelight.lightType==1)
- {
- onelight.timeRemaining = 5;
- }
- //std::cout<<"######################: "<<camera_trafficlight_type<<" "<<onelight.timeRemaining<<std::endl;
- //onelight.timeRemaining= camera_trafficlight_time;
- outLight(onelight);
- sendProto_flag=true;
- }
- //-----------------------------------------获取连接状态--------------------------------------std::fmod-------------------
- if(mobuEn)
- {
- bool radio_flag=m_pc5->isLinked();//路测连接状态
- if (radio_flag)
- {
- ui->button_obu_en->setStyleSheet("background-color: green");
- }
- else
- {
- ui->button_obu_en->setStyleSheet("background-color: red");
- }
- if (mshowdebugEn)
- {
- QByteArray pc5_read=m_pc5->show_readdata();
- QByteArray pc5_error=m_pc5->show_error();
- ui->textBrowser_3->append(QTime::currentTime().toString("hh:mm:ss.zzz")+"接收:"+pc5_read);
- ui->textBrowser_4->append(QTime::currentTime().toString("hh:mm:ss.zzz")+":"+pc5_error);
- }
- if(mcusdatashowEn)
- {
- QByteArray cus_show=m_pc5->upCustomshow();
- if (cus_show.size()>0)
- {
- ui->textBrowser_5->append(QTime::currentTime().toString("hh:mm:ss.zzz")+"接收:"+cus_show);
- cus_show.clear();
- }
- }
- }
- if(v2vEn)
- {
- bool radio_flag=m_pc5->isLinked();//路测连接状态
- if (radio_flag)
- {
- ui->button_v2v_en->setStyleSheet("background-color: green");
- }
- else
- {
- ui->button_v2v_en->setStyleSheet("background-color: red");
- }
- if (mshowdebugEn)
- {
- QByteArray pc5_read=m_pc5->show_readdata();
- QByteArray pc5_error=m_pc5->show_error();
- ui->textBrowser_3->append(QTime::currentTime().toString("hh:mm:ss.zzz")+"接收:"+pc5_read);
- ui->textBrowser_4->append(QTime::currentTime().toString("hh:mm:ss.zzz")+":"+pc5_error);
- }
- }
- if (mplatformEn)
- {
- bool v2x_flag=m_tbox->isLinked();//云平台连接状态
- if (v2x_flag)
- {
- ui->button_platform_en->setStyleSheet("background-color: green");
- }
- else
- {
- ui->button_platform_en->setStyleSheet("background-color: red");
- }
- if (mshowdebugEn)
- {
- QByteArray v2x_read=m_tbox->show_readdata();
- QByteArray v2x_error=m_tbox->show_error();
- ui->textBrowser->append(QTime::currentTime().toString("hh:mm:ss.zzz")+"接收:"+v2x_read);
- ui->textBrowser_2->append(QTime::currentTime().toString("hh:mm:ss.zzz")+":"+v2x_error);
- }
- }
- //-----------------------------------------延时清空传感器状态---------------------------------------------------------
- if(mGPSs>0)
- {
- mGPSs--;
- if (mGPSs<=0)
- {
- seneor_m.gps_flag=0x00;
- m_tbox->setSensorMemmory(seneor_m);
- }
- }
- if(mCAMs>0)
- {
- mCAMs--;
- if(mCAMs<=0)
- {
- seneor_m.camera_back=0x00;
- seneor_m.camera_front=0x00;
- seneor_m.camera_left=0x00;
- seneor_m.camera_right=0x00;
- m_tbox->setSensorMemmory(seneor_m);
- }
- }
- if(mLIDARs>0)
- {
- mLIDARs--;
- if(mLIDARs<=0)
- {
- seneor_m.lidar_left=0x00;
- seneor_m.lidar_mid=0x00;
- seneor_m.lidar_right=0x00;
- m_tbox->setSensorMemmory(seneor_m);
- }
- }
- if(mRADARs>0)
- {
- mRADARs--;
- if (mRADARs<=0)
- {
- seneor_m.radar=0x00;
- m_tbox->setSensorMemmory(seneor_m);
- }
- }
- //---------------------------------------路况信息显示-----------------------------------------------------------
- if (mbTrafficInfoEn)
- {
- TrafficMessage=m_pc5->ui_RealtimeTraffic();
- if (TrafficMessage.isEnable)
- {
- QString event;
- ui->button_trafficInfoLight_st->setStyleSheet("background-color: green");
- switch(TrafficMessage.trafficInfo){
- case 0:
- event="无";
- ui->lineEd_trafficInfo->setText("正常行驶");
- break;
- case 3 :
- event="道路结冰";
- //ui->lineEd_trafficInfo->setText("减速至 " + QString::number(TrafficMessage.speedLimit) + "km/h");
- ui->lineEd_trafficInfo->setText("减速慢行");
- break;
- case 4 :
- event="限速";
- ui->lineEd_trafficInfo->setText("减速至 " + QString::number(TrafficMessage.speedLimit) + "km/h");
- break;
- case 1 :
- event="塌方";
- ui->lineEd_trafficInfo->setText("停车");
- break;
- case 2 :
- event="施工";
- ui->lineEd_trafficInfo->setText("停车");
- break;
- default:
- break;
- }
- ui->textBr_trafficInfo->append(QTime::currentTime().toString("hh:mm:ss.zzz") + \
- "\n\t事件范围[ 经度:" + QString::number(TrafficMessage.lng,'g',10) +\
- " 纬度:" + QString::number(TrafficMessage.lat,'g',10) + \
- " ]\n\t辐射范围: " + QString::number(TrafficMessage.scope) + "米" + \
- "\n\t事件类型: " + event);
- outRealtimeTraffic(TrafficMessage);
- sendProto_flag=true;
- }
- else
- {
- ui->button_trafficInfoLight_st->setStyleSheet("background-color: gray");
- ui->textBr_trafficInfo->append("等待接收");
- }
- }
- //-----------------------------------------碰撞预警显示---------------------------------------------------------
- if (mbFCWEn)
- {
- collisionWarning=m_pc5->ui_Warning();
- if (collisionWarning.isEnable)
- {
- ui->button_FWCLight_st->setStyleSheet("background-color: green");
- switch (collisionWarning.warningType)
- {
- case 1:
- ui->textBr_FCW->append(QTime::currentTime().toString("hh:mm:ss.zzz") + \
- "前方碰撞预警,减速至:" + QString::number(collisionWarning.speedLimit));
- break;
- case 2:
- ui->textBr_FCW->append(QTime::currentTime().toString("hh:mm:ss.zzz") + \
- "前方碰撞预警,停车");
- default:
- break;
- }
- outCollisionWarning(collisionWarning);
- sendProto_flag=true;
- }
- else
- {
- ui->button_FWCLight_st->setStyleSheet("background-color: gray");
- //ui->textBr_FCW->append("连接丢失");
- }
- }
- //--------------------------------------红绿灯显示------------------------------------------------------------
- light=m_pc5->ui_Light();
- if (light.isEnable && mobuEn)
- {
- visionflag=false; //stop vision result upload of traffic light information
- // qDebug()<<light.myface;
- switch (int(light.myface))
- {
- case 1:
- initFace();
- ui->label_7->setPixmap(QPixmap::fromImage(facetoimg));
- ui->label_18->setText("此时面向");
- break;
- case 2:
- initFace();
- ui->label_14->setPixmap(QPixmap::fromImage(facetoimg));
- ui->label_17->setText("此时面向");
- break;
- case 3:
- initFace();
- ui->label_15->setPixmap(QPixmap::fromImage(facetoimg));
- ui->label_19->setText("此时面向");
- break;
- case 4:
- initFace();
- ui->label_16->setPixmap(QPixmap::fromImage(facetoimg));
- ui->label_20->setText("此时面向");
- break;
- default:
- initFace();
- break;
- }
- ui->vertical_lighthead->setText(QString("%1").arg(light.light1head));
- switch (int(light.light1Type))
- {
- case 1:
- initLight1();
- ui->lcdgreen_2->display((int)light.light1timeRemaining);
- ui->label_39->setPixmap(QPixmap::fromImage(greenimg));
- break;
- case 2:
- initLight1();
- ui->lcdgreen_2->display((int)light.light1timeRemaining);
- ui->label_39->setPixmap(QPixmap::fromImage(redimg));
- break;
- case 3:
- initLight1();
- ui->lcdgreen_2->display((int)light.light1timeRemaining);
- ui->label_39->setPixmap(QPixmap::fromImage(yellowimg));
- break;
- default:
- initLight1();
- break;
- }
- ui->vertical_lighthead_2->setText(QString("%1").arg(light.light2head));
- switch (int(light.light2Type))
- {
- case 1:
- initLight2();
- ui->lcdgreen_3->display((int)light.light2timeRemaining);
- ui->label_40->setPixmap(QPixmap::fromImage(greenimg));
- break;
- case 2:
- initLight2();
- ui->lcdgreen_3->display((int)light.light2timeRemaining);
- ui->label_40->setPixmap(QPixmap::fromImage(redimg));
- break;
- case 3:
- initLight2();
- ui->lcdgreen_3->display((int)light.light2timeRemaining);
- ui->label_40->setPixmap(QPixmap::fromImage(yellowimg));
- break;
- default:
- initLight2();
- break;
- }
- ui->vertical_lighthead_3->setText(QString("%1").arg(light.light3head));
- switch (int(light.light3Type))
- {
- case 1:
- initLight3();
- ui->lcdgreen_4->display((int)light.light3timeRemaining);
- ui->label_41->setPixmap(QPixmap::fromImage(greenimg));
- break;
- case 2:
- initLight3();
- ui->lcdgreen_4->display((int)light.light3timeRemaining);
- ui->label_41->setPixmap(QPixmap::fromImage(redimg));
- break;
- case 3:
- initLight3();
- ui->lcdgreen_4->display((int)light.light3timeRemaining);
- ui->label_41->setPixmap(QPixmap::fromImage(yellowimg));
- break;
- default:
- initLight3();
- break;
- }
- ui->vertical_lighthead_4->setText(QString("%1").arg(light.light4head));
- switch (int(light.light4Type))
- {
- case 1:
- initLight4();
- ui->lcdgreen_5->display((int)light.light4timeRemaining);
- ui->label_42->setPixmap(QPixmap::fromImage(greenimg));
- break;
- case 2:
- initLight4();
- ui->lcdgreen_5->display((int)light.light4timeRemaining);
- ui->label_42->setPixmap(QPixmap::fromImage(redimg));
- break;
- case 3:
- initLight4();
- ui->lcdgreen_5->display((int)light.light4timeRemaining);
- ui->label_42->setPixmap(QPixmap::fromImage(yellowimg));
- break;
- default:
- initLight4();
- break;
- }
- onelightMessage onelight;
- // float yaw=m_structMGpsImu.yaw+180;
- // //qDebug()<<yaw<<light.light1head<<light.light1head;
- // if (yaw>=360)
- // {
- // yaw=yaw-360;
- // }
- // if (yaw<=light.light1head+30 and yaw>=light.light1head-30)//判断与正向红绿灯的朝向
- // {
- // onelight.isEnable=true;
- // onelight.lightType=light.light1Type;
- // onelight.timeRemaining=light.light1timeRemaining;
- // lightStopLat=light1StopLat;
- // lightStopLon=light1StopLon;
- // }
- // else if (yaw<=light.light2head+30 and yaw>=light.light2head-30)//判断与侧向红绿灯的朝向
- // {
- // onelight.isEnable=true;
- // onelight.lightType=light.light2Type;
- // onelight.timeRemaining=light.light2timeRemaining;
- // lightStopLat=light2StopLat;
- // lightStopLon=light2StopLon;
- // }
- // else//不面向红绿灯无效
- // {
- // onelight.lightType=0xff;
- // onelight.timeRemaining=0xff;
- // }
- if(!RSUTYPE)
- {
- float yaw=m_structMGpsImu.yaw+180;
- //qDebug()<<yaw<<light.light1head<<light.light1head;
- if (yaw>=360)
- {
- yaw=yaw-360;
- }
- double angleDifference1 = std::fmod(yaw-light.light1head+360,360);
- double angleDifference2 = std::fmod(yaw-light.light2head+360,360);
- if (angleDifference1<=30.0 || angleDifference1>=360.0-30.0)
- {
- onelight.isEnable=true;
- onelight.lightType=light.light1Type;
- onelight.timeRemaining=light.light1timeRemaining;
- lightStopLat=light1StopLat;
- lightStopLon=light1StopLon;
- light.myface=0x01;
- }
- else if (angleDifference2<=30.0 || angleDifference2>=360.0-30.0)
- {
- onelight.isEnable=true;
- onelight.lightType=light.light2Type;
- onelight.timeRemaining=light.light2timeRemaining;
- lightStopLat=light2StopLat;
- lightStopLon=light2StopLon;
- light.myface=0x02;
- }
- else
- {
- onelight.lightType=0xff;
- onelight.timeRemaining=0xff;
- }
- }
- if (RSUTYPE)
- {
- switch (int(light.myface))
- {
- case 1:
- onelight.isEnable=true;
- onelight.lightType=light.light1Type;
- onelight.timeRemaining=light.light1timeRemaining;
- lightStopLat=light1StopLat;
- lightStopLon=light1StopLon;
- break;
- case 2:
- onelight.isEnable=true;
- onelight.lightType=light.light2Type;
- onelight.timeRemaining=light.light2timeRemaining;
- lightStopLat=light2StopLat;
- lightStopLon=light2StopLon;
- break;
- case 3:
- onelight.isEnable=true;
- onelight.lightType=light.light3Type;
- onelight.timeRemaining=light.light1timeRemaining;
- lightStopLat=light1StopLat;
- lightStopLon=light1StopLon;
- break;
- case 4:
- onelight.isEnable=true;
- onelight.lightType=light.light4Type;
- onelight.timeRemaining=light.light2timeRemaining;
- lightStopLat=light2StopLat;
- lightStopLon=light2StopLon;
- break;
- default:
- onelight.lightType=0xff;
- onelight.timeRemaining=0xff;
- break;
- }
- }
- outLight(onelight);
- sendProto_flag=true;
- }
- else
- {
- initLight1();
- initLight2();
- initLight3();
- initLight4();
- initFace();
- ui->vertical_lighthead->setText("");
- ui->vertical_lighthead_2->setText("");
- ui->vertical_lighthead_3->setText("");
- ui->vertical_lighthead_4->setText("");
- if (visionsendstate)
- {
- visionflag=true;//start vision result upload of traffic light information
- }
- }
- //-----------------------------------------显示虚拟车发送---------------------------------------------------------
- congestionIdenti=m_pc5->ui_identification();
- if (congestionIdenti.isEnable)
- {
- ui->lineEdit_jamsMode->setText("虚拟车信息已发送");
- ui->button_jamsMode->setStyleSheet("background-color: green");
- outCongestionIdenti(congestionIdenti);
- sendProto_flag=true;
- }
- else
- {
- ui->lineEdit_jamsMode->setText("");
- ui->button_jamsMode->setStyleSheet("background-color: gray");
- }
- //------------------------------------------危险驾驶显示-------------------------------------------------------
- if (mbdriCrimsEn)
- {
- bool warn_driver=m_pc5->show_warn_driver();
- if (warn_driver)
- {
- ui->textBr_FCW_2->append(QTime::currentTime().toString("hh:mm:ss.zzz")+"进入危险驾驶模式");
- ui->button_DriCrimsLight_st->setStyleSheet("background-color: red");
- }
- else
- {
- ui->button_DriCrimsLight_st->setStyleSheet("background-color: gray");
- //ui->textBr_FCW->append("连接丢失");
- }
- }
- //------------------------------------sendproto--------------------------------------------------------------------
- if (sendProto_flag)
- {
- sendProto(protobuf);
- sendProto_flag=false;
- }
- }
- //------------------------------------------共享内存读取------------------------------------------------------------------
- void MainWindow::setTboxMemoryRaw()//云平台信息写入
- {
- Memory tboxM;
- tboxM.gps_lng=m_structMGpsImu.gps_lng;
- tboxM.gps_lat=m_structMGpsImu.gps_lat;
- tboxM.speed=m_structMGpsImu.speed;
- tboxM.yaw=m_structMGpsImu.yaw;
- // tboxM.ele_voltage=m_structChassisRaw.soc;
- // tboxM.error=getError();
- m_tbox->setTboxMemmory(tboxM);
- }
- void MainWindow::UpdateGps(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
- {
- bool isSend=false;
- double heading,ve,vn;
- iv::gps::gpsimu xgpsimu;
- //qDebug()<<111;
- if(!xgpsimu.ParseFromArray(strdata,nSize))
- {
- // mivlog->warn("ADCIntelligentVehicle::UpdateGPSIMU parse error. nSize is %d",nSize);
- return;
- }
- if(xgpsimu.has_lat())
- {
- isSend=true;
- m_structMGpsImu.gps_lat=xgpsimu.lat();
- //qDebug()<<xgpsimu.lat();
- }
- if(xgpsimu.has_lon())
- {
- isSend=true;
- m_structMGpsImu.gps_lng=xgpsimu.lon();
- //qDebug()<<xgpsimu.lon();
- }
- if(xgpsimu.has_heading())
- {
- isSend=true;
- heading = xgpsimu.heading();
- if(heading<0)
- {
- heading = heading+360.0;
- }
- m_structMGpsImu.yaw=float(heading);
- }
- if((xgpsimu.has_ve())&&(xgpsimu.has_vn()))
- {
- isSend = true;
- ve = xgpsimu.ve(); //东向速度,单位(米/秒)
- vn = xgpsimu.vn(); //北向速度,单位(米/秒)
- m_structMGpsImu.speed=float(sqrt(ve*ve+vn*vn))* 3.6;
- }
- if(xgpsimu.has_acce_x())
- {
- isSend=true;
- m_structMGpsImu.accx=float(xgpsimu.acce_x());
- }
- if(xgpsimu.has_acce_y())
- {
- isSend=true;
- m_structMGpsImu.accy = (xgpsimu.acce_y());
- }
- if (xgpsimu.has_rtk_state())
- {
- if (xgpsimu.rtk_state()==6)
- {
- seneor_m.gps_flag=0x01;
- mGPSs=3;
- m_tbox->setSensorMemmory(seneor_m);
- }
- }
- if(isSend)
- {
- setTboxMemoryRaw();
- m_pc5->setGpsImuMemory(m_structMGpsImu);
- }
- }
- void MainWindow::UpdateCAM(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
- {
- iv::vision::rawpic xrawpic;
- if(!xrawpic.ParseFromArray(strdata,nSize))
- {
- return;
- }
- seneor_m.camera_back=0x01;
- seneor_m.camera_front=0x01;
- seneor_m.camera_left=0x01;
- seneor_m.camera_right=0x01;
- mCAMs=5;
- m_tbox->setSensorMemmory(seneor_m);
- }
- void MainWindow::UpdateLIDAR(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
- {
- // iv::fusion::fusionobject xfusionobject;
- // if(!xfusionobject.ParseFromArray(strdata,nSize))
- // {
- // return;
- // }
- unsigned int * pHeadSize = (unsigned int *)strdata;
- if(*pHeadSize > nSize)
- {
- std::cout<<"ListenPointCloud data is small headsize ="<<*pHeadSize<<" data size is"<<nSize<<std::endl;
- }
- seneor_m.lidar_left=0x01;
- seneor_m.lidar_mid=0x01;
- seneor_m.lidar_right=0x01;
- mLIDARs=3;
- m_tbox->setSensorMemmory(seneor_m);
- }
- void MainWindow::UpdateRADAR(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
- {
- //qDebug()<<'recve radar';
- iv::radar::radarobject xradarobject;
- if(!xradarobject.ParseFromArray(strdata,nSize))
- {
- std::cout<<"radar data is small headsize ="<<std::endl;
- }
- seneor_m.radar=0x01;
- mRADARs=3;
- m_tbox->setSensorMemmory(seneor_m);
- }
- //转发视觉红绿灯识别的数据
- void MainWindow::Updatelight(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
- {
- iv::vision::Lightarray lightmessage;
- onelightMessage visionligth;
- if(lightmessage.ParseFromArray(strdata,nSize))
- {
- if (lightmessage.light(0).has_type() and visionflag)
- {
- visionligth.lightType=lightmessage.light(0).type();
- visionligth.timeRemaining=0xff;
- camera_trafficlight_type=visionligth.lightType;
- //qDebug()<<111;
- lightStopLat=light1StopLat;
- lightStopLon=light1StopLon;
- sendProto_flag=true;
- outLight(visionligth);
- }
- }
- }
- //--------------------------------------------共享内存写入--------------------------------------------------------------
- void MainWindow::outmbpause(bool runmod)
- {
- protobuf.set_mbpause(runmod);
- }
- void MainWindow::outLight(onelightMessage light1)
- {
- //iv::v2r::v2r_send protobuf;
- protobuf.set_radiolighttype(light1.lightType);
- if (visionflag)
- {
- if(light1.lightType==2)
- {
- light1.timeRemaining=5;
- }
- else if(light1.lightType==3)
- {
- light1.timeRemaining=3;
- }
- else if(light1.lightType==1)
- {
- light1.timeRemaining = 5;
- }
- }
- protobuf.set_radiolightremain(light1.timeRemaining);
- // if(visionflag)
- // {
- // float yaw=m_structMGpsImu.yaw+180;
- // if (yaw>=360)
- // {
- // yaw=yaw-360;
- // }
- // if (yaw<=light1Stophead+30 and yaw>=light1Stophead-30)//判断与正向红绿灯的朝向
- // {
- // lightStopLat=light1StopLat;
- // lightStopLon=light1StopLon;
- // }
- // else if (yaw<=light2Stophead+30 and yaw>=light2Stophead-30)//判断与侧向红绿灯的朝向
- // {
- // lightStopLat=light2StopLat;
- // lightStopLon=light2StopLon;
- // }
- // else{
- // lightStopLat=0xff;
- // lightStopLon=0xff;
- // }
- // protobuf.set_trafficlightstoplat(lightStopLat);
- // protobuf.set_trafficlightstoplon(lightStopLon);
- // //sendProto(protobuf);
- // }
- // if (visionflag)
- // {
- // float yaw=m_structMGpsImu.yaw+180;
- // if (yaw>=360)
- // {
- // yaw=yaw-360;
- // }
- // double angleDifference1 = std::fmod(yaw - light1Stophead + 360.0, 360.0);
- // double angleDifference2 = std::fmod(yaw - light2Stophead + 360.0, 360.0);
- // if (angleDifference1<=30.0 || angleDifference1>=360.0-30.0)
- // {
- // lightStopLat=light1StopLat;
- // lightStopLon=light1StopLon;
- // }
- // else if (angleDifference2<=30.0 || angleDifference2>=360.0-30.0)
- // {
- // lightStopLat=light2StopLat;
- // lightStopLon=light2StopLon;
- // }
- // else
- // {
- // lightStopLat=0xff;
- // lightStopLon=0xff;
- // }
- // }
- if(visionflag)
- {
- lightStopLat=light1StopLat;
- lightStopLon=light1StopLon;
- }
- protobuf.set_trafficlightstoplat(lightStopLat);
- protobuf.set_trafficlightstoplon(lightStopLon);
- //sendProto(protobuf);
- //qDebug()<<"outLight";
- }
- void MainWindow::outRealtimeTraffic(realtimeTrafficMessage realtimeTraffic)
- {
- double lat=((double)realtimeTraffic.lat);//1000000.0;
- double lon=((double)realtimeTraffic.lng);//1000000.0;
- protobuf.set_radiobroadcastgpslat(lat);
- protobuf.set_radiobroadcastgpslon(lon);
- protobuf.set_radiobroadcastrange(realtimeTraffic.scope);
- protobuf.set_radiobroadcasttraffictype(realtimeTraffic.trafficInfo);
- protobuf.set_radiobroadcastspeedlimit(realtimeTraffic.speedLimit);
- //sendProto(protobuf);
- //qDebug()<<"outRealtimeTraffic"<<lat<<lon<<realtimeTraffic.scope<<realtimeTraffic.trafficInfo<<realtimeTraffic.speedLimit;
- }
- void MainWindow::outCollisionWarning(collisionEarlyWarningMessage collisionWarning)
- {
- //iv::v2r::v2r_send protobuf;
- protobuf.set_radiowarningtype(collisionWarning.warningType);
- protobuf.set_radiowarningspeedlimit(collisionWarning.speedLimit);
- //qDebug()<<"[Radio]:warning type is "<<collisionWarning.warningType<<".speed limit is:"<<collisionWarning.speedLimit<<endl;
- //sendProto(protobuf);
- }
- void MainWindow::outCongestionIdenti(congestionIdentificationMessage congestionIdenti)
- {
- //iv::v2r::v2r_send protobuf;
- protobuf.set_radioidentistart(congestionIdenti.openCommand);
- //qDebug()<<"[Radio]:congestion identi open command is "<<congestionIdenti.openCommand<<endl;
- //sendProto(protobuf);
- }
- void MainWindow::outV2VData(QMap<QString, OBUCarFormation> V2VMessage)
- {
- int id=0;
- iv::fusion::fusionobjectarray out_v2v;
- out_v2v.Clear();
- std::string out;
- out.clear();
- if (v2vshow)
- {
- ui->v2vnumlineEdit->setText("车辆数:"+QString::number(V2VMessage.size()));
- ui->v2vcomboBox->clear();
- }
- for (auto it=V2VMessage.begin();it !=V2VMessage.end();++it)
- {
- iv::fusion::fusionobject v2v_object;
- iv::fusion::fusionobject *v2v_object_;
- OBUCarFormation V2Vcar=it.value();
- if (v2vshow)
- {
- ui->v2vcomboBox->addItem(V2Vcar.vin);
- }
- double lng=V2Vcar.gps_lng;
- double lat=V2Vcar.gps_lat;
- float yaw=V2Vcar.car_yaw;
- yaw=calculateRelativeAngle(m_structMGpsImu.yaw,yaw);
- float x=V2Vcar.car_length;
- float y=V2Vcar.car_width;
- float z=V2Vcar.car_height;
- float centroid_x=V2Vcar.coordinate_front;
- float centroid_y=V2Vcar.coordinate_left;
- v2v_object.set_id(id);
- v2v_object.set_type(0);
- v2v_object.set_sensor_type(0);
- v2v_object.set_yaw(yaw);
- iv::fusion::Dimension dimension;
- iv::fusion::Dimension *dimension_;
- dimension.set_x(x);
- dimension.set_y(y);
- dimension.set_z(z);
- dimension_ = v2v_object.mutable_dimensions();
- dimension_->CopyFrom(dimension);
- double now_x,now_y,gps_x,gps_y,car_x,car_y;
- GaussProjCal(m_structMGpsImu.gps_lng,m_structMGpsImu.gps_lat,now_x,now_y);
- GaussProjCal(lng,lat,gps_x,gps_y);
- Coordinate_Transfer(gps_x,gps_y,now_x,now_y,m_structMGpsImu.yaw,car_x,car_y);
- if (v2vshowmore)
- {
- if (V2Vcar.vin==ui->v2vcomboBox->currentText())
- {
- ui->textBr_v2vdata->setText(QTime::currentTime().toString("hh:mm:ss.zzz") + \
- "\n\t位置[ 经度:" + QString::number(lng,'g',10) +\
- " 纬度:" + QString::number(lat,'g',10) +\
- " \n\t横向:" + QString::number(car_x)+ "m"+\
- " 纵向:" + QString::number(car_y)+ "m"+ \
- " ]\n\t航向: " + QString::number(V2Vcar.car_yaw) + "°" + \
- "\n\t大小[ 长:" + QString::number(x) + "m"+\
- " 宽:" + QString::number(y) + "m"+ \
- " 高:" + QString::number(z) + "m"+ \
- "]\n\t方向盘转角:"+QString::number(V2Vcar.steering_wheel_angle)+ "°");
- QByteArray v2v_error=m_pc5->upV2Vdatashow();
- ui->textBr_v2vdata_2->setText(QTime::currentTime().toString("hh:mm:ss.zzz")+":"+v2v_error);
- }
- }
- iv::fusion::PointXYZ centroid;
- iv::fusion::PointXYZ *centroid_;
- centroid.set_x(car_x);
- centroid.set_y(car_y);
- centroid.set_z(0);
- centroid_ = v2v_object.mutable_centroid();
- centroid_->CopyFrom(centroid);
- // int xp = (int)((x/0.2)/2.0);
- // if(xp == 0)xp=1;
- // int yp = (int)((y/0.2)/2.0);
- // if(yp == 0)yp=1;
- // int ix,iy;
- // for(ix = 0; ix<(xp*2); ix++)
- // {
- // for(iy = 0; iy<(yp*2); iy++)
- // {
- // iv::fusion::NomalXYZ nomal_centroid;
- // iv::fusion::NomalXYZ *nomal_centroid_;
- // float nomal_x = ix*0.2 - xp*0.2;
- // float nomal_y = iy*0.2 - yp*0.2;
- // float nomal_z = 1.0;
- // float s = nomal_x*cos(yaw)
- // - nomal_y*sin(yaw);
- // float t = nomal_x*sin(yaw)
- // + nomal_y*cos(yaw);
- // nomal_centroid.set_nomal_x(car_x + s);
- // nomal_centroid.set_nomal_y(car_y + t);
- // if(abs(car_x + s) <1.3 &&
- // car_y + t <1.0) continue;
- // else{
- // nomal_centroid.set_nomal_x(car_x + s);
- // nomal_centroid.set_nomal_y(car_y + t);
- // //iv::fusion::fusionobject &fusion_obj = (iv::fusion::fusionobject &)lidar_radar_fusion_object_array.obj(i);
- // nomal_centroid_ = v2v_object.add_nomal_centroid();
- // nomal_centroid_->CopyFrom(nomal_centroid);
- // }
- // }
- // }
- v2v_object_ = out_v2v.add_obj();
- v2v_object_->CopyFrom(v2v_object);
- id++;
- }
- if (v2vshow==1)
- {
- v2vshow=0;
- ui->button_v2vshow_en->setStyleSheet("background-color: gray");
- }
- if(out_v2v.obj_size()==0)
- {
- iv::fusion::fusionobject fake_obj;
- iv::fusion::fusionobject *fake_obj_;
- iv::fusion::PointXYZ fake_cen;
- iv::fusion::PointXYZ *fake_cen_;
- fake_cen.set_x(10000);
- fake_cen.set_y(10000);
- fake_cen.set_z(10000);
- fake_cen_ = fake_obj.mutable_centroid();
- fake_cen_ ->CopyFrom(fake_cen);
- fake_obj_ = out_v2v.add_obj();
- fake_obj_->CopyFrom(fake_obj);
- out = out_v2v.SerializeAsString();
- }
- else{
- out = out_v2v.SerializeAsString();
- }
- //qDebug()<<out_v2v.obj_size();
- iv::modulecomm::ModuleSendMsg(gfu,out.data(),out.length());
- }
- void MainWindow::sendProto(iv::v2r::v2r_send radio_protobuf_send)
- {
- char * strser;
- bool bser;
- int nbytesize;
- nbytesize = radio_protobuf_send.ByteSize();
- strser = new char[nbytesize];
- bser = radio_protobuf_send.SerializeToArray(strser,nbytesize);
- if(bser)
- {
- //qDebug()<<"[Radio]:ready send protobuffer"<<endl;
- iv::modulecomm::ModuleSendMsg(mpmem_radio_send_addr,strser,nbytesize);
- //qDebug()<<"[Radio]:has sended protobuffer"<<endl;
- } else
- {
- //qDebug()<<"proto fail"<<endl;
- //mivlog->error("sendData","[%s:] radio serialize error.",__func__);
- // gfault->SetFaultState(1, 0, "radio serialize err");
- }
- delete strser;
- }
- //--------------------------------------------按钮使能控制---------------------------------------------------------------
- //云平台使能控制
- void MainWindow::on_button_platform_en_clicked()
- {
- if(mplatformEn)
- {
- ui->button_platform_en->setStyleSheet("background-color: gray");
- mplatformEn = false;
- m_tbox->setTboxConnectEnable(false);
- }
- else
- {
- ui->button_platform_en->setStyleSheet("background-color: green");
- mplatformEn = true;
- m_tbox->setTboxConnectEnable(true);
- }
- }
- //路测设备使能控制
- void MainWindow::on_button_obu_en_clicked()
- {
- if(mobuEn==1)
- {
- ui->button_obu_en->setStyleSheet("background-color: gray");
- mobuEn = 0;
- m_pc5->setConnectEnable(false);
- }
- else
- {
- ui->button_obu_en->setStyleSheet("background-color: green");
- mobuEn = 1;
- m_pc5->setConnectEnable(true);
- }
- }
- void MainWindow::on_button_v2v_en_clicked()
- {
- if(v2vEn==1)
- {
- ui->button_v2v_en->setStyleSheet("background-color: gray");
- v2vEn = 0;
- m_pc5->setConnectEnable2(false);
- QMap<QString,OBUCarFormation> V2VMessage;
- outV2VData(V2VMessage);
- }
- else
- {
- ui->button_v2v_en->setStyleSheet("background-color: green");
- v2vEn = 1;
- m_pc5->setConnectEnable2(true);
- }
- }
- //云平台控制启停使能控制
- void MainWindow::on_button_v2xrunmod_en_clicked()
- {
- if (mpc5RunmodEn==0){
- if(mv2xRunmodEn==1)
- {
- ui->button_v2xrunmod_en->setStyleSheet("background-color: gray");
- mv2xRunmodEn = 0;
- }
- else
- {
- ui->button_v2xrunmod_en->setStyleSheet("background-color: green");
- mv2xRunmodEn = 1;
- }
- if (!mplatformEn)
- {
- ui->button_v2xrunmod_en->setStyleSheet("background-color: red");
- mv2xRunmodEn = 0;
- }
- }
- }
- void MainWindow::on_button_pc5runmod_en_clicked()
- {
- if (mv2xRunmodEn==0){
- if(mpc5RunmodEn==1)
- {
- ui->button_pc5runmod_en->setStyleSheet("background-color: gray");
- mpc5RunmodEn = 0;
- }
- else
- {
- ui->button_pc5runmod_en->setStyleSheet("background-color: green");
- mpc5RunmodEn = 1;
- }
- if (!mobuEn)
- {
- ui->button_pc5runmod_en->setStyleSheet("background-color: red");
- mpc5RunmodEn = 0;
- }
- }
- }
- void MainWindow::on_button_car_vin_set_clicked()
- {
- bool ok;
- QString text = QInputDialog::getText(this, tr("输入车辆VIN:"),
- tr("VIN:"), QLineEdit::Normal,
- Q_NULLPTR, &ok);
- if (ok && !text.isEmpty())
- {
- gstrcarvin = text.toStdString();
- ui->lineEdit->setText(text);
- m_tbox->setTboxNewVin(gstrcarvin);
- m_pc5->setVin(gstrcarvin);
- }
- }
- void MainWindow::on_button_obu_vin_set_clicked()
- {
- bool ok;
- QString text = QInputDialog::getText(this, tr("输入路侧VIN:"),
- tr("VIN:"), QLineEdit::Normal,
- Q_NULLPTR, &ok);
- if (ok && !text.isEmpty())
- {
- int gstrobuvin = text.toInt();
- ui->lineEdit_obu_vin->setText(text);
- m_pc5->setobuNewVin(gstrobuvin);
- }
- }
- void MainWindow::on_button_trafficInfo_en_clicked()
- {
- if(mbTrafficInfoEn==1)
- {
- ui->button_trafficInfo_en->setStyleSheet("background-color: gray");
- mbTrafficInfoEn = 0;
- }
- else
- {
- ui->button_trafficInfo_en->setStyleSheet("background-color: green");
- mbTrafficInfoEn = 1;
- }
- }
- void MainWindow::on_button_FCW_en_clicked()
- {
- if(mbFCWEn==1)
- {
- ui->button_FCW_en->setStyleSheet("background-color: gray");
- mbFCWEn = 0;
- }
- else
- {
- ui->button_FCW_en->setStyleSheet("background-color: green");
- mbFCWEn = 1;
- }
- }
- void MainWindow::on_button_DriCrims_en_clicked()
- {
- if(mbdriCrimsEn==1)
- {
- ui->button_DriCrims_en->setStyleSheet("background-color: gray");
- mbdriCrimsEn = 0;
- }
- else
- {
- ui->button_DriCrims_en->setStyleSheet("background-color: green");
- mbdriCrimsEn = 1;
- }
- }
- void MainWindow::on_button_v2vshow_en_clicked()
- {
- if(v2vshow==1)
- {
- ui->button_v2vshow_en->setStyleSheet("background-color: gray");
- v2vshow = 0;
- }
- else
- {
- ui->button_v2vshow_en->setStyleSheet("background-color: green");
- v2vshow = 1;
- }
- }
- void MainWindow::on_button_v2vshowmore_en_clicked()
- {
- if(v2vshowmore==1)
- {
- ui->button_v2vshowmore_en->setStyleSheet("background-color: gray");
- v2vshowmore = 0;
- }
- else
- {
- ui->button_v2vshowmore_en->setStyleSheet("background-color: green");
- v2vshowmore = 1;
- }
- }
- void MainWindow::on_button_SimCar_en_clicked()
- {
- ui_set_virtualVehicleM struct_ui_VirtualVehicle;
- struct_ui_VirtualVehicle.lngMax= ui->lineEdit_jamsLon_up->text().toDouble();
- struct_ui_VirtualVehicle.lngMin= ui->lineEdit_jamsLon_low->text().toDouble();
- struct_ui_VirtualVehicle.latMax=ui->lineEdit_jamsLat_Up->text().toDouble();
- struct_ui_VirtualVehicle.latMin=ui->lineEdit_jamsLat_low->text().toDouble();
- struct_ui_VirtualVehicle.yawMax=ui->lineEdit_jamsHead_up->text().toDouble();
- struct_ui_VirtualVehicle.yawMin=ui->lineEdit_jamsHead_low->text().toDouble();
- struct_ui_VirtualVehicle.virtualVehicleNum= int(ui->lineEdit_jamsCarNum->text().toInt());
- struct_ui_VirtualVehicle.speedMax=ui->lineEdit_jamsSpeed_up->text().toDouble();
- struct_ui_VirtualVehicle.speedMin=ui->lineEdit_jamsSpeed_low->text().toDouble();
- m_pc5->my_ui_set=struct_ui_VirtualVehicle;
- //m_pc5->upVirtualVehicle(struct_ui_VirtualVehicle);
- // virtualVehicleM structVirtualVehicle;
- // int randId=qrand()%10000;
- // m_vectorRandom.push_back(randId);
- // for(int i=1;i<virtualVehicleNum;i++) {
- // getRandomNum();
- // }
- // for(int i=0;i<virtualVehicleNum;i++) {
- // structVirtualVehicle.vin = m_vectorVin[i];
- // structVirtualVehicle.gps_lat=latMin+((double(m_vectorRandom[i]))/10000.0)*(latMax-latMin);
- // structVirtualVehicle.gps_lng=lngMin+((double(m_vectorRandom[i]))/10000.0)*(lngMax-lngMin);
- // structVirtualVehicle.speed=speedMin+((float(m_vectorRandom[i]))/10000.0)*(speedMax-speedMin);
- // structVirtualVehicle.yaw=yawMin+((float(m_vectorRandom[i]))/10000.0)*(yawMax-yawMin);
- // m_pc5->upVirtualVehicle(structVirtualVehicle);
- // }
- }
- //void MainWindow::on_button_SimCar_en_clicked()
- //{
- // double lngMax= ui->lineEdit_jamsLon_up->text().toDouble();
- // double lngMin= ui->lineEdit_jamsLon_low->text().toDouble();
- // double latMax=ui->lineEdit_jamsLat_Up->text().toDouble();
- // double latMin=ui->lineEdit_jamsLat_low->text().toDouble();
- // float yawMax=ui->lineEdit_jamsHead_up->text().toDouble();
- // float yawMin=ui->lineEdit_jamsHead_low->text().toDouble();
- // int virtualVehicleNum= int(ui->lineEdit_jamsCarNum->text().toInt());
- // float speedMax=ui->lineEdit_jamsSpeed_up->text().toDouble();
- // float speedMin=ui->lineEdit_jamsSpeed_low->text().toDouble();
- // virtualVehicleM structVirtualVehicle;
- // int randId=qrand()%10000;
- // m_vectorRandom.push_back(randId);
- // for(int i=1;i<virtualVehicleNum;i++) {
- // getRandomNum();
- // }
- // for(int i=0;i<virtualVehicleNum;i++) {
- // structVirtualVehicle.vin = m_vectorVin[i];
- // structVirtualVehicle.gps_lat=latMin+((double(m_vectorRandom[i]))/10000.0)*(latMax-latMin);
- // structVirtualVehicle.gps_lng=lngMin+((double(m_vectorRandom[i]))/10000.0)*(lngMax-lngMin);
- // structVirtualVehicle.speed=speedMin+((float(m_vectorRandom[i]))/10000.0)*(speedMax-speedMin);
- // structVirtualVehicle.yaw=yawMin+((float(m_vectorRandom[i]))/10000.0)*(yawMax-yawMin);
- // m_pc5->upVirtualVehicle(structVirtualVehicle);
- // }
- //}
- void MainWindow::on_show_debug_clicked()
- {
- if(mshowdebugEn==1)
- {
- ui->show_debug->setStyleSheet("background-color: gray");
- mshowdebugEn = 0;
- }
- else
- {
- bool ok;
- QString text = QInputDialog::getText(this, tr("scode:"),
- tr("scode:"), QLineEdit::Password,
- Q_NULLPTR, &ok);
- if (ok && !text.isEmpty())
- {
- std::string scode = text.toStdString();
- if (scode=="catarc")
- {
- ui->show_debug->setStyleSheet("background-color: green");
- mshowdebugEn = 1;
- }
- }
- }
- }
- void MainWindow::on_ea_collect_clicked()
- {
- double lat=m_structMGpsImu.gps_lat;
- double lon=m_structMGpsImu.gps_lng;
- float head=m_structMGpsImu.yaw+180;
- if (head>=360){
- head=head-360;
- }
- light1StopLat=lat;
- light1StopLon=lon;
- light1Stophead=head;
- ui->ea_long->setText(QString::number(lon,'g',10));
- ui->ea_lat->setText(QString::number(lat,'g',10));
- ui->ea_head->setText(QString::number(head,'g',10));
- QFile inputFile("./v2xTcpClient.xml"); // 替换成你的XML文件路径
- if (!inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
- qDebug() << "Failed to open the XML file for reading.";
- }
- QTextStream inputStream(&inputFile);
- QString xmlContent = inputStream.readAll();
- inputFile.close();
- // 2. 使用正则表达式查找和替换参数值
- QMap<QString, QString> parameterMap;
- parameterMap["light1Stophead"] = ui->ea_head->text();
- parameterMap["light1StopLat"] = ui->ea_lat->text();
- parameterMap["light1StopLon"] = ui->ea_long->text();
- // 3. 遍历映射并使用正则表达式查找和替换参数值
- for (const QString ¶mName : parameterMap.keys()) {
- QRegExp regex("name=\"" + paramName + "\" value=\"[^\"]+\"");
- const QString &newValue = parameterMap[paramName];
- int pos = 0;
- while ((pos = regex.indexIn(xmlContent, pos)) != -1) {
- xmlContent.replace(pos, regex.matchedLength(), "name=\"" + paramName + "\" value=\"" + newValue + "\"");
- pos += regex.matchedLength();
- }
- }
- // 3. 创建一个临时文件用于保存更新后的XML
- QFile outputFile("temp_updated_xml_file.xml");
- if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
- qDebug() << "Failed to open the temporary output XML file for writing.";
- }
- QTextStream outputStream(&outputFile);
- // 4. 重新写入XML文件内容,包括修改后的参数
- outputStream << xmlContent;
- // 5. 关闭文件
- outputFile.close();
- // 6. 删除原始XML文件
- QFile::remove("v2xTcpClient.xml");
- // 7. 重命名临时文件为原始XML文件名
- QFile::rename("temp_updated_xml_file.xml", "v2xTcpClient.xml");
- qDebug() << "XML file has been updated with the original attribute order and parameter change.";
- }
- void MainWindow::on_ns_collect_clicked()
- {
- double lat=m_structMGpsImu.gps_lat;
- double lon=m_structMGpsImu.gps_lng;
- float head=m_structMGpsImu.yaw+180;
- if (head>=360){
- head=head-360;
- }
- light2StopLat=lat;
- light2StopLon=lon;
- light2Stophead=head;
- ui->ns_long->setText(QString::number(lon,'g',10));
- ui->ns_lat->setText(QString::number(lat,'g',10));
- ui->ns_head->setText(QString::number(head,'g',10));
- QFile inputFile("./v2xTcpClient.xml"); // 替换成你的XML文件路径
- if (!inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
- qDebug() << "Failed to open the XML file for reading.";
- }
- QTextStream inputStream(&inputFile);
- QString xmlContent = inputStream.readAll();
- inputFile.close();
- // 2. 使用正则表达式查找和替换参数值
- QMap<QString, QString> parameterMap;
- parameterMap["light2Stophead"] = ui->ns_head->text();
- parameterMap["light2StopLat"] = ui->ns_lat->text();
- parameterMap["light2StopLon"] = ui->ns_long->text();
- // 3. 遍历映射并使用正则表达式查找和替换参数值
- for (const QString ¶mName : parameterMap.keys()) {
- QRegExp regex("name=\"" + paramName + "\" value=\"[^\"]+\"");
- const QString &newValue = parameterMap[paramName];
- int pos = 0;
- while ((pos = regex.indexIn(xmlContent, pos)) != -1) {
- xmlContent.replace(pos, regex.matchedLength(), "name=\"" + paramName + "\" value=\"" + newValue + "\"");
- pos += regex.matchedLength();
- }
- }
- // 3. 创建一个临时文件用于保存更新后的XML
- QFile outputFile("temp_updated_xml_file.xml");
- if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
- qDebug() << "Failed to open the temporary output XML file for writing.";
- }
- QTextStream outputStream(&outputFile);
- // 4. 重新写入XML文件内容,包括修改后的参数
- outputStream << xmlContent;
- // 5. 关闭文件
- outputFile.close();
- // 6. 删除原始XML文件
- QFile::remove("v2xTcpClient.xml");
- // 7. 重命名临时文件为原始XML文件名
- QFile::rename("temp_updated_xml_file.xml", "v2xTcpClient.xml");
- qDebug() << "XML file has been updated with the original attribute order and parameter change.";
- }
- void MainWindow::on_ea_cf_clicked()
- {
- double x,y,head;
- x= ui->ea_cf_x->text().toDouble();
- // x=-x;
- y= ui->ea_cf_y->text().toDouble();
- head=m_structMGpsImu.yaw;
- if (head>90)
- {
- head=360-(head-90);
- }
- else{
- head=90-head;
- }
- double now_x,now_y,lat,lon,aim_x,aim_y,aim_lat,aim_lon,dis,add_x,add_y;
- GaussProjCal(m_structMGpsImu.gps_lng,m_structMGpsImu.gps_lat,now_x,now_y);
- add_x=y*qCos(qDegreesToRadians(head))+x*qSin(qDegreesToRadians(head));
- add_y=y*qSin(qDegreesToRadians(head))-x*qCos(qDegreesToRadians(head));
- aim_x=now_x+add_x;
- aim_y=now_y+add_y;
- GaussProjInvCal(aim_x,aim_y,&aim_lon,&aim_lat);
- QFile inputFile("./v2xTcpClient.xml"); // 替换成你的XML文件路径
- if (!inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
- qDebug() << "Failed to open the XML file for reading.";
- }
- QTextStream inputStream(&inputFile);
- QString xmlContent = inputStream.readAll();
- inputFile.close();
- // 2. 使用正则表达式查找和替换参数值
- QMap<QString, QString> parameterMap;
- parameterMap["light_CF_Lat"] = QString::number(aim_lat,'g',10);
- parameterMap["light_CF_Lon"] = QString::number(aim_lon,'g',10);
- // 3. 遍历映射并使用正则表达式查找和替换参数值
- for (const QString ¶mName : parameterMap.keys()) {
- QRegExp regex("name=\"" + paramName + "\" value=\"[^\"]+\"");
- const QString &newValue = parameterMap[paramName];
- int pos = 0;
- while ((pos = regex.indexIn(xmlContent, pos)) != -1) {
- xmlContent.replace(pos, regex.matchedLength(), "name=\"" + paramName + "\" value=\"" + newValue + "\"");
- pos += regex.matchedLength();
- }
- }
- // 3. 创建一个临时文件用于保存更新后的XML
- QFile outputFile("temp_updated_xml_file.xml");
- if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
- qDebug() << "Failed to open the temporary output XML file for writing.";
- }
- QTextStream outputStream(&outputFile);
- // 4. 重新写入XML文件内容,包括修改后的参数
- outputStream << xmlContent;
- // 5. 关闭文件
- outputFile.close();
- // 6. 删除原始XML文件
- QFile::remove("v2xTcpClient.xml");
- // 7. 重命名临时文件为原始XML文件名
- QFile::rename("temp_updated_xml_file.xml", "v2xTcpClient.xml");
- qDebug() << "XML file has been updated with the original attribute order and parameter change.";
- }
- void MainWindow::on_ns_cf_clicked()
- {
- double x,y,head;
- x= ui->ns_cf_x->text().toDouble();
- x=-x;
- y= ui->ns_cf_y->text().toDouble();
- head=m_structMGpsImu.yaw;
- if (head>90)
- {
- head=360-(head-90);
- }
- else{
- head=90-head;
- }
- double now_x,now_y,lat,lon,aim_x,aim_y,aim_lat,aim_lon,dis,add_x,add_y;
- GaussProjCal(m_structMGpsImu.gps_lng,m_structMGpsImu.gps_lat,now_x,now_y);
- add_x=y*qCos(qDegreesToRadians(head))+x*qSin(qDegreesToRadians(head));
- add_y=y*qSin(qDegreesToRadians(head))-x*qCos(qDegreesToRadians(head));
- aim_x=now_x+add_x;
- aim_y=now_y+add_y;
- GaussProjInvCal(aim_x,aim_y,&aim_lon,&aim_lat);
- QFile inputFile("./v2xTcpClient.xml"); // 替换成你的XML文件路径
- if (!inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
- qDebug() << "Failed to open the XML file for reading.";
- }
- QTextStream inputStream(&inputFile);
- QString xmlContent = inputStream.readAll();
- inputFile.close();
- // 2. 使用正则表达式查找和替换参数值
- QMap<QString, QString> parameterMap;
- parameterMap["light_CF_Lat"] = QString::number(aim_lat,'g',10);
- parameterMap["light_CF_Lon"] = QString::number(aim_lon,'g',10);
- // 3. 遍历映射并使用正则表达式查找和替换参数值
- for (const QString ¶mName : parameterMap.keys()) {
- QRegExp regex("name=\"" + paramName + "\" value=\"[^\"]+\"");
- const QString &newValue = parameterMap[paramName];
- int pos = 0;
- while ((pos = regex.indexIn(xmlContent, pos)) != -1) {
- xmlContent.replace(pos, regex.matchedLength(), "name=\"" + paramName + "\" value=\"" + newValue + "\"");
- pos += regex.matchedLength();
- }
- }
- // 3. 创建一个临时文件用于保存更新后的XML
- QFile outputFile("temp_updated_xml_file.xml");
- if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
- qDebug() << "Failed to open the temporary output XML file for writing.";
- }
- QTextStream outputStream(&outputFile);
- // 4. 重新写入XML文件内容,包括修改后的参数
- outputStream << xmlContent;
- // 5. 关闭文件
- outputFile.close();
- // 6. 删除原始XML文件
- QFile::remove("v2xTcpClient.xml");
- // 7. 重命名临时文件为原始XML文件名
- QFile::rename("temp_updated_xml_file.xml", "v2xTcpClient.xml");
- qDebug() << "XML file has been updated with the original attribute order and parameter change.";
- }
- void MainWindow::on_button_pc5send_clicked()
- {
- QString send_data=ui->plainTextEdit->toPlainText();
- m_pc5->CustomDataSend(send_data);
- }
- void MainWindow::on_button_pc5show_clicked()
- {
- if (mcusdatashowEn==1)
- {
- ui->button_pc5show->setStyleSheet("background-color: gray");
- mcusdatashowEn=0;
- }
- else
- {
- ui->button_pc5show->setStyleSheet("background-color: green");
- mcusdatashowEn=1;
- }
- }
- MainWindow::~MainWindow()
- {
- timer->stop();
- iv::modulecomm::Unregister(mpMemGPS);
- iv::modulecomm::Unregister(mpMemcamera);
- iv::modulecomm::Unregister(mpMemlidar);
- iv::modulecomm::Unregister(mpMemradar);
- iv::modulecomm::Unregister(vision_lightMem);
- delete ui;
- }
|