123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939 |
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QtMath>
- extern std::string gstrcarvin;
- extern std::string gstrobuvin;
- extern iv::Ivlog * gIvlog;
- 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);
- sendProto_flag=false;
- initUI();
- initMemory();
- initproto();
- initLight1();
- initLight2();
- }
- 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/zhixing-red.png");
- redimg = redimg.scaled(66,66,Qt::IgnoreAspectRatio);
- greenimg.load(":/light/light/zhixing-green.png");
- greenimg = greenimg.scaled(66,66,Qt::IgnoreAspectRatio);
- yellowimg.load(":/light/light/zhixing-yellow.png");
- yellowimg = yellowimg.scaled(66,66,Qt::IgnoreAspectRatio);
- blackimg.load(":/light/light/zhixing-black.png");
- blackimg = blackimg.scaled(66,66,Qt::IgnoreAspectRatio);
- QString strpath = QCoreApplication::applicationDirPath();
- //strpath = strpath + "/v2xTcpClientWL.xml";
- strpath = "./v2xTcpClient.xml";
- iv::xmlparam::Xmlparam xp(strpath.toStdString());
- 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);
- 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);
- 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);
- 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);
- std::string visionsend = xp.GetParam("OpenVisionSend","0");
- visionsendstate=std::stoi(visionsend);
- visionflag=visionsendstate;
- m_pc5->setVin(strCarVIN);
- m_pc5->setobuNewVin(obunum);
- m_pc5->setSerial(localsetIP,localsetport);
- m_tbox->setTboxNewVin(strCarVIN);
- m_tbox->setIPandPort(IP,port);
- }
- void MainWindow::initLight1()
- {
- ui->label_33->setPixmap(QPixmap::fromImage(blackimg));
- ui->label_38->setPixmap(QPixmap::fromImage(blackimg));
- ui->label_35->setPixmap(QPixmap::fromImage(blackimg));
- ui->lcdgreen->display(0);
- ui->lcdyellow->display(0);
- ui->lcdred->display(0);
- }
- void MainWindow::initLight2()
- {
- ui->label_39->setPixmap(QPixmap::fromImage(blackimg));
- ui->label_40->setPixmap(QPixmap::fromImage(blackimg));
- ui->label_41->setPixmap(QPixmap::fromImage(blackimg));
- ui->lcdgreen_2->display(0);
- ui->lcdyellow_2->display(0);
- ui->lcdred_2->display(0);
- }
- void MainWindow::heartBeat()
- {
- protobuf.Clear();
- //-----------------------------------------send runflag---------------------------------------------------------
- if (mRunmodEn)
- {
- bool runmod=m_tbox->upRunMod();
- //qDebug()<<runmod;
- outmbpause(runmod);
- sendProto_flag=true;
- }
- //-----------------------------------------获取连接状态---------------------------------------------------------
- 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 (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)
- {
- visionflag=false; //stop vision result upload of traffic light information
- ui->cross_lighthead->setText(QString("%1").arg(light.light1head));
- switch (int(light.light1Type))
- {
- case 1:
- initLight1();
- ui->lcdgreen->display((int)light.light1timeRemaining);
- ui->label_38->setPixmap(QPixmap::fromImage(greenimg));
- break;
- case 2:
- initLight1();
- ui->lcdred->display((int)light.light1timeRemaining);
- ui->label_35->setPixmap(QPixmap::fromImage(redimg));
- break;
- case 3:
- initLight1();
- ui->lcdyellow->display((int)light.light1timeRemaining);
- ui->label_33->setPixmap(QPixmap::fromImage(yellowimg));
- break;
- default:
- initLight1();
- break;
- }
- ui->vertical_lighthead->setText(QString("%1").arg(light.light2head));
- switch (int(light.light2Type))
- {
- case 1:
- initLight2();
- ui->lcdgreen_2->display((int)light.light2timeRemaining);
- ui->label_39->setPixmap(QPixmap::fromImage(greenimg));
- break;
- case 2:
- initLight2();
- ui->lcdred_2->display((int)light.light2timeRemaining);
- ui->label_41->setPixmap(QPixmap::fromImage(redimg));
- break;
- case 3:
- initLight2();
- ui->lcdyellow_2->display((int)light.light2timeRemaining);
- ui->label_40->setPixmap(QPixmap::fromImage(yellowimg));
- break;
- default:
- initLight2();
- 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;
- }
- outLight(onelight);
- sendProto_flag=true;
- }
- else
- {
- ui->cross_lighthead->setText("");
- ui->vertical_lighthead->setText("");
- initLight1();
- initLight2();
- 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("连接丢失");
- }
- }
- 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 = float(xgpsimu.acce_y());
- }
- if(isSend)
- {
- seneor_m.gps_flag=0x01;
- mGPSs=3;
- setTboxMemoryRaw();
- m_tbox->setSensorMemmory(seneor_m);
- 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)
- {
- iv::radar::radarobject xradarobject;
- if(!xradarobject.ParseFromArray(strdata,nSize))
- {
- return;
- }
- 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;
- //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);
- 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);
- }
- 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::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_runmod_en_clicked()
- {
- if(mRunmodEn==1)
- {
- ui->button_runmod_en->setStyleSheet("background-color: gray");
- mRunmodEn = 0;
- }
- else
- {
- ui->button_runmod_en->setStyleSheet("background-color: green");
- mRunmodEn = 1;
- }
- if (!mplatformEn)
- {
- ui->button_runmod_en->setStyleSheet("background-color: red");
- mRunmodEn = 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_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::Normal,
- Q_NULLPTR, &ok);
- if (ok && !text.isEmpty())
- {
- std::string scode = text.toStdString();
- if (scode=="catarc")
- {
- ui->show_debug->setStyleSheet("background-color: green");
- mshowdebugEn = 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;
- }
|