#include "mainwindow.h" #include "ui_mainwindow.h" #include 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 V2VMessage=m_pc5->updateV2V(); outV2VData(V2VMessage); } catch(...){ qDebug()<<"..."; } } } void MainWindow::heartBeat() { protobuf.Clear(); //-----------------------------------------send runflag--------------------------------------------------------- //qDebug()<upRunMod(); //qDebug()<button_pc5runmod_en->setStyleSheet("background-color: gray"); } else if (mpc5RunmodEn) { bool runmod=m_pc5->upRunMod(); //qDebug()<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<<"######################: "<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()<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()<=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()<=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()<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"<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 ="<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"< 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(qRadiansToDegrees(yaw)) + "°" + \ "\n\t大小[ 长:" + QString::number(x) + "m"+\ " 宽:" + QString::number(y) + "m"+ \ " 高:" + QString::number(z) + "m"+ \ "]\n\t方向盘转角:"+QString::number(V2Vcar.steering_wheel_angle)+ "°"); } } 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()<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 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;iupVirtualVehicle(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;iupVirtualVehicle(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 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 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; 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=x*qCos(qDegreesToRadians(head))+y*qSin(qDegreesToRadians(head)); add_y=x*qSin(qDegreesToRadians(head))-y*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 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; 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=x*qCos(qDegreesToRadians(head))+y*qSin(qDegreesToRadians(head)); add_y=x*qSin(qDegreesToRadians(head))-y*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 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; }