#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { m_tbox=new Tbox(); initTboxMemory(); m_radio=new Radio(); ui->setupUi(this); initUi(); //enableTbox(); initRadio(); //20211009,jiaolili mivlog = new iv::Ivlog("v2x"); //ShareMem: gps ModuleFun fungpsimu =std::bind(&MainWindow::UpdateGPSIMU,this,std::placeholders::_1, \ std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5); mpMemGps = iv::modulecomm::RegisterRecvPlus("hcp2_gpsimu",fungpsimu); //ShareMem: ui ModuleFun funUI =std::bind(&MainWindow::UpdateUI,this,std::placeholders::_1, \ std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5); mpMemUI = iv::modulecomm::RegisterRecvPlus("hcp2_gpsimu",funUI); } MainWindow::~MainWindow() { delete ui; } void MainWindow::initUi() { ui->lineEdit_enableTox->setText("Init status"); ui->lineEdit_enableRadio->setText("Init status"); } void MainWindow::initRadio() { std::string str="12345678912345678"; int randId0,randId1,randId2,randId3,randId4,randId5,randId6,randId7,randId8,randId9,randId10,randId11,randId12,randId13,randId14,randId15,randId16; for(int i=0;i<1000;i++) { randId0=qrand()%10; randId1=qrand()%10; randId2=qrand()%10; randId3=qrand()%10; randId4=qrand()%10; randId5=qrand()%10; randId6=qrand()%10; randId7=qrand()%10; randId8=qrand()%10; randId9=qrand()%10; randId10=qrand()%10; randId11=qrand()%10; randId12=qrand()%10; randId13=qrand()%10; randId14=qrand()%10; randId15=qrand()%10; randId16=qrand()%10; char c[17]={char('0'+randId0), char('0'+randId1), char('0'+randId2), char('0'+randId3), char('0'+randId4), char('0'+randId5), char('0'+randId6), char('0'+randId7), char('0'+randId8), char('0'+randId9), char('0'+randId10), char('0'+randId11), char('0'+randId12), char('0'+randId13), char('0'+randId14), char('0'+randId15), char('0'+randId16)}; str=c; m_vectorVin.push_back(str); } } void MainWindow::enableTbox() { ui->lineEdit_enableTox->setText("OPEN"); m_tbox->setTboxConnectEnable(true); } void MainWindow::disableTbox() { ui->lineEdit_enableTox->setText("CLOSE"); m_tbox->setTboxConnectEnable(false); } void MainWindow::initTboxMemory() { m_structM.gps_lng=137.0; m_structM.gps_lat=39.0; m_structM.speed=20.0; m_structM.yaw=12.0; m_structM.ele_voltage=90.0; m_structM.error=0x02; m_tbox->setTboxMemmory(m_structM); m_tbox->setTboxConnectEnable(false); } void MainWindow::on_pushButton_connect_clicked() { if(ui->pushButton_connect->text() == tr("connect")) { enableTbox(); //修改按键文字 ui->pushButton_connect->setText("disconnect"); } else { disableTbox(); //修改按键文字 ui->pushButton_connect->setText("connect"); } } void MainWindow::on_pushButton_vinChange_clicked() { std::string str=ui->lineEdit_VIN->text().toStdString(); m_tbox->setTboxNewVin(str); } void MainWindow::on_checkBox_trafficBroadcast_stateChanged(int arg1) { if(arg1==2) { m_radio->getTrafficBroadcast(true); } else { m_radio->getTrafficBroadcast(false); } } void MainWindow::on_checkBox_collisionWarning_stateChanged(int arg1) { if(arg1==2) { m_radio->getCollisonWarning(true); } else { m_radio->getCollisonWarning(false); } } void MainWindow::on_checkBox_busyRoad_stateChanged(int arg1) { if(arg1==2) { m_radio->getBusyRoad(true); } else { m_radio->getBusyRoad(false); } } void MainWindow::on_checkBox_dangerousDrive_stateChanged(int arg1) { if(arg1==2) { m_radio->getDangerDrive(true); } else { m_radio->getDangerDrive(false); } } void MainWindow::on_pushButton_setVirtualVehicle_clicked() { int virtualVehicleNum=ui->lineEdit_virtualVehicleNum->text().toInt(); double latMax=ui->lineEdit_latMax->text().toDouble(); double latMin=ui->lineEdit_latMin->text().toDouble(); double lngMax=ui->lineEdit_lngMax->text().toDouble(); double lngMin=ui->lineEdit_lngMin->text().toDouble(); float speedMax=ui->lineEdit_speedMax->text().toFloat(); float speedMin=ui->lineEdit_speedMin->text().toFloat(); float yawMax=ui->lineEdit_yawMax->text().toFloat(); float yawMin=ui->lineEdit_yawMin->text().toFloat(); int randId=qrand()%10000; m_vectorRandom.push_back(randId); virtualVehicleM structVirtualVehicle; for(int i=1;iupVirtualVehicle(structVirtualVehicle); } //m_radio } void MainWindow::getRandomNum() { int randId=qrand()%10000; for(int i=0;ilineEdit_enableRadio->setText("OPEN"); } else { ui->lineEdit_enableRadio->setText("CLOSE"); } m_radio->setEnConnect(en); } void MainWindow::on_pushButton_radioConnect_clicked() { if(ui->pushButton_radioConnect->text() == tr("connect")) { setEnRadio(true); //修改按键文字 ui->pushButton_radioConnect->setText("disconnect"); } else { setEnRadio(false); //修改按键文字 ui->pushButton_radioConnect->setText("connect"); } } //接收GPS数据 void MainWindow::UpdateGPSIMU(const char * strdata,const unsigned int nSize,const unsigned int index,\ const QDateTime * dt,const char * strmemname) { double accX,accY,lat,lon,heading,rtk,ins,vd,ve,vn; iv::gps::gpsimu xgpsimu; if(!xgpsimu.ParseFromArray(strdata,nSize)) { mivlog->warn("ADCIntelligentVehicle::UpdateGPSIMU parse error. nSize is %d",nSize); return; } lat = xgpsimu.lat(); lon = xgpsimu.lon(); heading = xgpsimu.heading(); rtk = xgpsimu.rtk_state(); ins = xgpsimu.ins_state(); vd = xgpsimu.vd(); //地向速度,单位(米/秒) ve = xgpsimu.ve(); //东向速度,单位(米/秒) vn = xgpsimu.vn(); //北向速度,单位(米/秒) if(xgpsimu.has_acce_x()) { accX = xgpsimu.acce_x(); } if(xgpsimu.has_acce_y()) { accY = xgpsimu.acce_y(); } // mfAcc = (float)sqrt(pow(accX,2)+pow(accY,2)); // mfspeed = sqrt(pow(data->vel_E,2)+pow(data->vel_N,2)) * 3.6; //double pow(double x, double y) 返回 x 的 y 次幂,即 xy。 //mistGPS = 0; } //UI DATA void MainWindow::UpdateUI(const char * strdata,const unsigned int nSize,const unsigned int index,\ const QDateTime * dt,const char * strmemname) { double accX,accY,lat,lon,heading,rtk,ins,vd,ve,vn; iv::hmi::hmimsg xhmi; if(!xhmi.ParseFromArray(strdata,nSize)) { mivlog->warn("ADCIntelligentVehicle::UpdateGPSIMU parse error. nSize is %d",nSize); return; } if(xhmi.has_obuen()) { bool enRadio=xhmi.obuen(); setEnRadio(enRadio); } if(xhmi.has_platformen()) { bool enTbox=xhmi.platformen(); if(enTbox) { enableTbox(); } else { disableTbox(); } } if(xhmi.has_platformen()) { bool enTbox=xhmi.platformen(); if(enTbox) { enableTbox(); } else { disableTbox(); } } if(xhmi.has_rodeinfoen()) { bool enRadioBroadcast = xhmi.rodeinfoen(); m_radio->getTrafficBroadcast(enRadioBroadcast); ui->checkBox_trafficBroadcast->setChecked(enRadioBroadcast); } if(xhmi.has_rodefcwen()) { bool enRadioWarning = xhmi.rodefcwen(); m_radio->getCollisonWarning(enRadioWarning); ui->checkBox_collisionWarning->setChecked(enRadioWarning); } if(xhmi.has_roadjamsen()) { } }