12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322 |
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "pos_def.h"
- #include "remotectrlini.h"
- MainWindow * gw;
- //#include "QStringLiteral"
- #ifdef NVIDIA_AGX
- #include "opencv2/imgcodecs/legacy/constants_c.h" //OpenCV4 use this line
- #include <opencv2/imgproc/types_c.h> //OpenCV4 use this line
- #endif
- #include <opencv2/opencv.hpp>
- #include <opencv2/core.hpp>
- iv::gps::gpsimu ggpsimu;
- qint64 gTimeGPSIMUUpdate = 0;
- iv::vision::rawpic grawpic[CAMERA_NUM];
- qint64 gTimeRawPic[CAMERA_NUM] = {0,0,0,0};
- QMutex gMutexPic[CAMERA_NUM];
- extern std::string gstrmem_gpsimu;
- extern std::string gstrmem_pic[CAMERA_NUM];
- extern std::vector<iv::pos_def> gvectorpos;
- extern std::string gstryaml_path;
- class xodrobj
- {
- public:
- double flatsrc;
- double flonsrc;
- double fhgdsrc;
- double flat;
- double flon;
- int lane;
- };
- namespace iv {
- struct simpletrace
- {
- double gps_lat = 0;//纬度
- double gps_lng = 0;//经度
- double gps_x = 0;
- double gps_y = 0;
- double gps_z = 0;
- double ins_heading_angle = 0; //航向角
- };
- }
- std::vector<iv::simpletrace> gvectorsimplerace;
- QMutex gMutexTrace;
- qint64 gTimeTrace = 0;
- void * gpaframe;
- MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
- , ui(new Ui::MainWindow)
- {
- m_translator = new QTranslator(this);
- QString strLanguageFile = ":/zh_CN.qm";
- if(ServiceRCIni.GetLanguage() == "Chinese")
- {
- strLanguageFile = ":/zh_CN.qm";
- }
- else
- {
- strLanguageFile = ":/en_CN.qm";
- }
- if (QFile(strLanguageFile).exists())
- {
- m_translator->load(strLanguageFile);
- qApp->installTranslator(m_translator);
- }
- gpaframe = iv::modulecomm::RegisterSend("h264frame",1000000,1);
- gw = this;
- ui->setupUi(this);
- mstrserverip = ServiceRCIni.GetServerIP();
- mstrserverport = ServiceRCIni.GetServerPort();
- mstruploadinterval = ServiceRCIni.GetInterval();
- mstrVehVIN = ServiceRCIni.GetVIN();
- mstrqueryMD5 = ServiceRCIni.GetQueryMD5();
- mstrctrlMD5 = ServiceRCIni.GetCtrlMD5();
- mpJRT = new JoyReadThread();
- mpJRT->start();
- int i;
- CreateView();
- int nstation = gvectorpos.size();
- for(i=0;i<nstation;i++)
- {
- ui->comboBox_Station->addItem(gvectorpos[i].mstrstationname.data());
- }
- ui->radioButton_auto->setChecked(true);
- mpa = iv::modulecomm::RegisterSend("remotectrl",10000,1);
- mpTimerManual = new QTimer(this);
- connect(mpTimerManual,SIGNAL(timeout()),this,SLOT(onTimerManual()));
- mpTimerRemote = new QTimer(this);
- connect(mpTimerRemote,SIGNAL(timeout()),this,SLOT(onTimerRemote()));
- mpTimerRemote->start(50);
- mpTimerUpdateView = new QTimer(this);
- connect(mpTimerUpdateView,SIGNAL(timeout()),this,SLOT(onTimerUpdateView()));
- mpTimerUpdateView->start(1000);
- QTimer * timer = new QTimer(this);
- connect(timer,SIGNAL(timeout()),this,SLOT(onTimerUpdatePic()));
- timer->start(1000);
- mpadst = iv::modulecomm::RegisterSend("xodrreq",1000,1);
- mgrpcpc = new grpcpc(gstryaml_path);
- mgrpcpc->setserverip(mstrserverip);
- mgrpcpc->setserverport(mstrserverport);
- mgrpcpc->setqueryinterval(mstruploadinterval);
- mgrpcpc->setVIN(mstrVehVIN);
- mgrpcpc->setqueryMD5(mstrqueryMD5);
- mgrpcpc->setctrlMD5(mstrctrlMD5);
- mgrpcpc->StartRTSP();
- mgrpcpc->start();
- for(i=0;i<NUM_CAM;i++)
- {
- mpImageCam[i] = new QImage(640, 360, QImage::Format_RGB32);
- mbCamUpdate[i] = false;
- mph264decode[i] = new ivh264framedecode(mnframewidth,mnframeheight);
- mpthreadframe[i] = new std::thread(&MainWindow::threadframe,this,i);
- mpthreadpic[i] = new std::thread(&MainWindow::threadpic,this,i);
- }
- mpthreadinfo = new std::thread(&MainWindow::threadinfo,this);
- mstrVIN = mgrpcpc->GetVIN().data();
- mstrVIN = " VIN:"+ mstrVIN+" ";
- // mppicdlg = new DialogPic(this);
- // mppicdlg->setModal(false);
- // connect(mppicdlg,SIGNAL(finished(int)),this,SLOT(onCloseDlg()));
- // mpbigpicdlg = new DialogBigPic(this);
- // mpbigpicdlg->setModal(false);
- // connect(mpbigpicdlg,SIGNAL(finished(int)),this,SLOT(onCloseBigDlg()));
- QLabel * pLabel = new QLabel();
- pLabel->setFixedWidth(600);
- pLabel->setText("Latency");
- mpLabelLatency = pLabel;
- ui->statusbar->addPermanentWidget(pLabel);
- ui->horizontalSlider_wheelspeed->setRange(1,30);
- connect(this,SIGNAL(CamUpdate(int)),this,SLOT(onCamUpdate(int)));
- // mpbaiduapp = new pluginapp(this->winId(),"baidu","baidumapshow","/home/yuchuli/qt/modularization/src/plugin/build-baidumapshow-Debug");
- // mppicshow = new pluginapp(this->winId(),"main","plugin_picshow","/home/yuchuli/qt/modularization/src/plugin/build-plugin_picshow-Debug");
- // mppicshow->SetAttr("rawpicmsgname",gstrmem_pic[0].data(),gstrmem_pic[0].size());
- setWindowTitle(mstrProgName +mstrVIN+ mstrGPSTime + mstrPicTime);
- }
- MainWindow::~MainWindow()
- {
- mpJRT->requestInterruption();
- mbThreadrun = false;
- int i;
- mpthreadinfo->join();
- for(i=0;i<NUM_CAM;i++)
- {
- // mph264decode[i] = new ivh264framedecode(mnframewidth,mnframeheight);
- mpthreadframe[i]->join();
- mpthreadpic[i]->join();
- }
- std::cout<<" ~MainWindow. "<<std::endl;
- delete ui;
- }
- void MainWindow::CreateView()
- {
- // mMapview = new QWebEngineView(ui->centralwidget);
- // qDebug((QDir::currentPath()).toLatin1().data());
- // mMapview->load(QUrl(QString("file:///%1/%2").arg(QApplication::applicationDirPath()).arg("BaiDuMap.html")));
- // mMapview->setGeometry(10,10,800,800);
- // mMapview->page()->runJavaScript("theLocation(117.355,39.066);"); //117.355,39.066
- mpWheel = new Speed(ui->groupBox_rem);
- mpWheel->settitle(QStringLiteral("方向盘"));
- mpWheel->setminvalue(450);
- mpWheel->setmaxvalue(-450);
- mpAcc = new Speed(ui->groupBox_rem);
- mpAcc->settitle(QStringLiteral("油门"));
- mpAcc->updatevalue(0);
- mpAcc->setminvalue(-100);
- mpAcc->setmaxvalue(100);
- mpBrake = new Speed(ui->groupBox_rem);
- mpBrake->settitle(QStringLiteral("刹车"));
- mpBrake->updatevalue(0);
- mpBrake->setminvalue(0);
- mpBrake->setmaxvalue(100);
- mpVehSpeed = new Speed(ui->centralwidget);
- mpVehSpeed->settitle(QStringLiteral("车速(km/h)"));
- mpVehSpeed->updatevalue(0);
- mpVehSpeed->setminvalue(0);
- mpVehSpeed->setmaxvalue(30);
- mmyview = new MyView(ui->centralwidget);
- mmyview->setObjectName(QStringLiteral("graphicsView"));
- mmyview->setGeometry(QRect(30, 30, 600, 600));
- mmyview->setCacheMode(mmyview->CacheBackground);
- mmyviewLeft = new MyView(ui->centralwidget);
- mmyviewLeft->setObjectName(QStringLiteral("graphicsView"));
- mmyviewLeft->setGeometry(QRect(30, 30, 600, 600));
- mmyviewLeft->setCacheMode(mmyviewLeft->CacheBackground);
- mmyviewRear = new MyView(ui->centralwidget);
- mmyviewRear->setObjectName(QStringLiteral("graphicsView"));
- mmyviewRear->setGeometry(QRect(30, 30, 600, 600));
- mmyviewRear->setCacheMode(mmyviewRear->CacheBackground);
- mmyviewRight = new MyView(ui->centralwidget);
- mmyviewRight->setObjectName(QStringLiteral("graphicsView"));
- mmyviewRight->setGeometry(QRect(30, 30, 600, 600));
- mmyviewRight->setCacheMode(mmyviewRight->CacheBackground);
- mscene = new QGraphicsScene;
- mpsceneImg[0] = mscene;
- mpsceneImg[1] = new QGraphicsScene;
- mpsceneImg[2] = new QGraphicsScene;
- mpsceneImg[3] = new QGraphicsScene;
- mpviewImg[0] = mmyview;
- mpviewImg[1] = mmyviewRear;
- mpviewImg[2] = mmyviewLeft;
- mpviewImg[3] = mmyviewRight;
- ui->radioButton_Null->setChecked(true);
- }
- void MainWindow::keyPressEvent(QKeyEvent *event)
- {
- //按键按下,key值放入容器,如果是长按触发的repeat就不判断
- if(!event->isAutoRepeat())
- mPressKeys.insert(event->key());
- }
- void MainWindow::keyReleaseEvent(QKeyEvent *event)
- {
- if((event->key() == Qt::Key_Escape)||(event->key() == Qt::Key_F11))
- {
- showNormal();
- ui->menubar->setVisible(true);
- ui->statusbar->setVisible(true);
- }
- if(!event->isAutoRepeat())mPressKeys.remove(event->key());
- qDebug("key count is %d",mPressKeys.count());
- }
- void MainWindow::resizeEvent(QResizeEvent *event)
- {
- (void)event;
- QSize sizemain = ui->centralwidget->size();
- qDebug("size x = %d y=%d",sizemain.width(),sizemain.height());
- // mMapview->setVisible(false);
- // mMapview->setGeometry(10,10,sizemain.width()/2,sizemain.height()*3/5);
- // mpbaiduapp->SetGeometry(10,30,sizemain.width()/2,sizemain.height()*3/5);
- int nMode = 1;
- if(sizemain.height()>0)
- {
- if((sizemain.width()/sizemain.height())<3)
- {
- nMode = 0;
- }
- }
- ui->lineEdit_lat->setVisible(false);
- ui->lineEdit_lon->setVisible(false);
- ui->pushButton_test->setVisible(false);
- if(nMode == 0)
- {
- mpVehSpeed->setVisible(false);
- mmyview->setGeometry(10+sizemain.width()/2+10,10,sizemain.width()/2-30,sizemain.height()*3/5);
- int nfrontpos_x = sizemain.width()/6;
- int nfrontpos_y = sizemain.height()/3;
- int nfrontsize_x = sizemain.width()*2/3;
- int nfrontsize_y = sizemain.height() * 2/3;
- mmyview->setGeometry(nfrontpos_x,nfrontpos_y,nfrontsize_x,nfrontsize_y);
- int nleftpos_x = 0;
- int nleftpos_y = 0;
- int nleftsize_x = sizemain.width()/3;
- int nleftsize_y = sizemain.height()/3;
- mmyviewLeft->setGeometry(nleftpos_x,nleftpos_y,nleftsize_x,nleftsize_y);
- int nrearpos_x = sizemain.width()/3;
- int nrearpos_y = 0;
- int nrearsize_x = sizemain.width()/3;
- int nrearsize_y = sizemain.height()/3;
- mmyviewRear->setGeometry(nrearpos_x,nrearpos_y,nrearsize_x,nrearsize_y);
- int nrightpos_x = sizemain.width() * 2/3;
- int nrightpos_y = 0;
- int nrightsize_x = sizemain.width()/3;
- int nrightsize_y = sizemain.height()/3;
- mmyviewRight->setGeometry(nrightpos_x,nrightpos_y,nrightsize_x,nrightsize_y);
- // mppicshow->SetGeometry(10+sizemain.width()/2+10,10,sizemain.width()/2-30,sizemain.height()*3/5);
- // ui->lineEdit_lat->setGeometry(sizemain.width()-100,10,90,30);
- // ui->lineEdit_lon->setGeometry(sizemain.width()-100,50,90,30);
- // ui->pushButton_test->setGeometry(sizemain.width()-100,90,90,30);
- // mpWheel->setGeometry(sizemain.width()/2 + 20,10,200,200);
- int grouppos_x = sizemain.width()*5/6;
- int grouppos_y = sizemain.height()/3;
- int grouppos_width = sizemain.width()*1/6;
- int grouppos_height = sizemain.height() * 2/3;
- // int speed_width = grouppos_height-40;
- // if((speed_width*3 + 150)>grouppos_width)speed_width = (grouppos_width - 150)/3;
- int speed_width = grouppos_width;
- if(speed_width*3 > (sizemain.height()/2))speed_width = sizemain.height()/6;
- mpWheel->setGeometry(0,sizemain.height()/6 ,speed_width,speed_width);
- mpBrake->setGeometry(0,sizemain.height()/6 + sizemain.height()/6,speed_width,speed_width);
- mpAcc->setGeometry(0 ,sizemain.height()/6 + sizemain.height()/3,speed_width,speed_width);
- ui->groupBox_rem->setGeometry(grouppos_x,grouppos_y,grouppos_width,grouppos_height);
- int groupmap_x = 0;
- int groupmap_y = sizemain.height()*1/3;
- int groupmap_width = sizemain.width()/6;
- int groupmap_height = sizemain.height()*1/10;
- ui->comboBox_Station->setGeometry(10,30,groupmap_width*3/5,30);
- ui->pushButton_Go->setGeometry(20 + groupmap_width*3/5,30,groupmap_width*2/5 - 30,30);
- ui->groupBox_map->setGeometry(groupmap_x,groupmap_y,groupmap_width,groupmap_height);
- int groupgps_x = 0;
- int groupgps_y = sizemain.height()/2;
- int groupgps_width = sizemain.width()/6;
- int groupgps_height = sizemain.height()/2;
- ui->groupBox_gps->setGeometry(groupgps_x,groupgps_y,groupgps_width,groupgps_height);
- int lablewidth =groupgps_width*3/10;// (groupgps_width-50)*2/10;
- int lewidth = groupgps_width*6/10;
- int leheight = 26;
- int nypos = 40;
- ui->label_gpsins->setGeometry(10,nypos,lablewidth,leheight);
- ui->lineEdit_gpsins->setGeometry(20+lablewidth,nypos,lewidth,leheight);
- nypos = nypos + leheight*11/10;
- ui->label_gpsrtk->setGeometry(10,nypos,lablewidth,leheight);
- ui->lineEdit_gpsrtk->setGeometry(20+lablewidth,nypos,lewidth,leheight);
- nypos = nypos + leheight*11/10;
- ui->label_gpslon->setGeometry(10,nypos,lablewidth,leheight);
- ui->lineEdit_gpslon->setGeometry(20+lablewidth,nypos,lewidth,leheight);
- nypos = nypos + leheight*11/10;
- ui->label_gpslat->setGeometry(10,nypos,lablewidth,leheight);
- ui->lineEdit_gpslat->setGeometry(20+lablewidth,nypos,lewidth,leheight);
- nypos = nypos + leheight*11/10;
- ui->label_gpsheading->setGeometry(10,nypos,lablewidth,leheight);
- ui->lineEdit_gpsheading->setGeometry(20+lablewidth,nypos,lewidth,leheight);
- nypos = nypos + leheight*11/10;
- ui->label_gpsheight->setGeometry(10,nypos,lablewidth,leheight);
- ui->lineEdit_gpsheight->setGeometry(20+lablewidth,nypos,lewidth,leheight);
- nypos = nypos + leheight*11/10;
- ui->label_gpsspeed->setGeometry(10,nypos,lablewidth,leheight);
- ui->lineEdit_gpsspeed->setGeometry(20+lablewidth,nypos,lewidth,leheight);
- nypos = nypos + leheight*11/10;
- ui->label_gpssat->setGeometry(10,nypos,lablewidth,leheight);
- ui->lineEdit_gpssat->setGeometry(20+lablewidth,nypos,lewidth,leheight);
- double fscale = (sizemain.width()*2/3)*1.0/mnframewidth;
- double fscale2 = (sizemain.height()*2/3)*1.0/mnframeheight;
- if(fscale > fscale2) fscale = fscale2;
- fscale = fscale * 0.99;
- mmyview->viewscaleto(fscale);
- int i;
- for(i=1;i<NUM_CAM;i++)
- {
- fscale = (sizemain.width()*1/3)*1.0/mnframewidth;
- fscale2 = (sizemain.height()*1/3)*1.0/mnframeheight;
- if(fscale > fscale2) fscale = fscale2;
- fscale = fscale * 0.99;
- mpviewImg[i]->viewscaleto(fscale);
- }
- }
- if(nMode == 1)
- {
- mpVehSpeed->setVisible(true);
- double fViewWidth = sizemain.width();
- int nfrontpos_x = static_cast<int>(fViewWidth/2.0 - fViewWidth * mfWide_View_CenterRatio * 0.5) ;
- int nfrontpos_y = 0;
- int nfrontsize_x = static_cast<int>(fViewWidth * mfWide_View_CenterRatio ) ;
- int nfrontsize_y = sizemain.height();
- int nleftpos_x = static_cast<int>(static_cast<double>(nfrontpos_x) - static_cast<double>(nfrontsize_x) * mfWide_View_LRRatio);
- int nleftpos_y = 0;
- int nleftsize_x = static_cast<int>( static_cast<double>(nfrontsize_x) * mfWide_View_LRRatio);
- int nleftsize_y = static_cast<int>( static_cast<double>(nfrontsize_y) * mfWide_View_LRRatio);
- int nrightpos_x = static_cast<int>(static_cast<double>(nfrontpos_x) + static_cast<double>(nfrontsize_x) );
- int nrightpos_y = 0;
- int nrightsize_x = static_cast<int>( static_cast<double>(nfrontsize_x) * mfWide_View_LRRatio);
- int nrightsize_y = static_cast<int>( static_cast<double>(nfrontsize_y) * mfWide_View_LRRatio);
- mmyview->setGeometry(nfrontpos_x,nfrontpos_y,nfrontsize_x,nfrontsize_y);
- mmyviewLeft->setGeometry(nleftpos_x,nleftpos_y,nleftsize_x,nleftsize_y);
- // int nrearpos_x = sizemain.width()/3;
- // int nrearpos_y = 0;
- // int nrearsize_x = sizemain.width()/3;
- // int nrearsize_y = sizemain.height()/3;
- // mmyviewRear->setGeometry(nrearpos_x,nrearpos_y,nrearsize_x,nrearsize_y);
- mmyviewRear->setVisible(false);
- mmyviewRight->setGeometry(nrightpos_x,nrightpos_y,nrightsize_x,nrightsize_y);
- // mppicshow->SetGeometry(10+sizemain.width()/2+10,10,sizemain.width()/2-30,sizemain.height()*3/5);
- // ui->lineEdit_lat->setGeometry(sizemain.width()-100,10,90,30);
- // ui->lineEdit_lon->setGeometry(sizemain.width()-100,50,90,30);
- // ui->pushButton_test->setGeometry(sizemain.width()-100,90,90,30);
- // mpWheel->setGeometry(sizemain.width()/2 + 20,10,200,200);
- int grouppos_x = static_cast<int>(fViewWidth*0.2) ;
- int grouppos_y = nleftsize_y;
- int grouppos_width = nfrontpos_x - grouppos_x;
- int grouppos_height = sizemain.height() - grouppos_y;
- // int speed_width = grouppos_height-40;
- // if((speed_width*3 + 150)>grouppos_width)speed_width = (grouppos_width - 150)/3;
- int speed_width = grouppos_height - 130;
- if(speed_width*3 > (grouppos_width))speed_width = (grouppos_width)/3;
- mpWheel->setGeometry(0,130 ,speed_width,speed_width);
- mpBrake->setGeometry(grouppos_width*1/3,130,speed_width,speed_width);
- mpAcc->setGeometry(grouppos_width*2/3 ,130,speed_width,speed_width);
- ui->groupBox_rem->setGeometry(grouppos_x,grouppos_y,grouppos_width,grouppos_height);
- int vehspeed_x = nfrontpos_x + nfrontsize_x + 10;
- int vehspeed_y = nrightsize_y + 10;
- int vehspeed_width = 200;
- int vehspeed_height = nfrontsize_y - nrightsize_y-10;
- if(vehspeed_height>vehspeed_width)vehspeed_height = vehspeed_width;
- else vehspeed_width = vehspeed_height;
- mpVehSpeed->setGeometry(vehspeed_x,vehspeed_y,vehspeed_width,vehspeed_height);
- int groupmap_x = static_cast<int>(static_cast<double>(nfrontpos_x) + static_cast<double>(nfrontsize_x) + static_cast<double>(nrightsize_x)) ;
- int groupmap_y = 0;//sizemain.height();
- int groupmap_width = static_cast<int>(fViewWidth - static_cast<double>(nfrontpos_x) - static_cast<double>(nfrontsize_x) - static_cast<double>(nrightsize_x));
- int groupmap_height = sizemain.height();// sizemain.height();
- ui->comboBox_Station->setGeometry(10,30,groupmap_width*3/5,30);
- ui->pushButton_Go->setGeometry(20 + groupmap_width*3/5,30,groupmap_width*2/5 - 30,30);
- ui->groupBox_map->setGeometry(groupmap_x,groupmap_y,groupmap_width,groupmap_height);
- int groupgps_x = 0;
- int groupgps_y = 0;//sizemain.height()/2;
- int groupgps_width = static_cast<int>(fViewWidth*0.2) ;
- int groupgps_height = 160;//sizemain.height()/2;
- int lablewidth =groupgps_width*3/20;// (groupgps_width-50)*2/10;
- int lewidth = groupgps_width*5/20;
- int leheight = 26;
- ui->groupBox_gps->setGeometry(groupgps_x,groupgps_y,groupgps_width,groupgps_height);
- int nypos = 40;
- ui->label_gpsins->setGeometry(10,nypos,lablewidth,leheight);
- ui->lineEdit_gpsins->setGeometry(20+lablewidth,nypos,lewidth,leheight);
- // nypos = nypos + leheight*11/10;
- ui->label_gpsrtk->setGeometry(groupgps_width/2,nypos,lablewidth,leheight);
- ui->lineEdit_gpsrtk->setGeometry(groupgps_width/2+10+lablewidth,nypos,lewidth,leheight);
- nypos = nypos + leheight*11/10;
- ui->label_gpslon->setGeometry(10,nypos,lablewidth,leheight);
- ui->lineEdit_gpslon->setGeometry(20+lablewidth,nypos,lewidth,leheight);
- // nypos = nypos + leheight*11/10;
- ui->label_gpslat->setGeometry(groupgps_width/2,nypos,lablewidth,leheight);
- ui->lineEdit_gpslat->setGeometry(groupgps_width/2+10+lablewidth,nypos,lewidth,leheight);
- nypos = nypos + leheight*11/10;
- ui->label_gpsheading->setGeometry(10,nypos,lablewidth,leheight);
- ui->lineEdit_gpsheading->setGeometry(20+lablewidth,nypos,lewidth,leheight);
- // nypos = nypos + leheight*11/10;
- ui->label_gpsheight->setGeometry(groupgps_width/2,nypos,lablewidth,leheight);
- ui->lineEdit_gpsheight->setGeometry(groupgps_width/2+10+lablewidth,nypos,lewidth,leheight);
- nypos = nypos + leheight*11/10;
- ui->label_gpsspeed->setGeometry(10,nypos,lablewidth,leheight);
- ui->lineEdit_gpsspeed->setGeometry(20+lablewidth,nypos,lewidth,leheight);
- // nypos = nypos + leheight*11/10;
- ui->label_gpssat->setGeometry(groupgps_width/2,nypos,lablewidth,leheight);
- ui->lineEdit_gpssat->setGeometry(groupgps_width/2+10+lablewidth,nypos,lewidth,leheight);
- double fscale = (sizemain.width()*1/5)*1.0/mnframewidth;
- double fscale2 = (sizemain.height()*1/1)*1.0/mnframeheight;
- if(fscale > fscale2) fscale = fscale2;
- fscale = fscale * 0.99;
- mmyview->viewscaleto(fscale);
- int i;
- for(i=1;i<NUM_CAM;i++)
- {
- fscale = (sizemain.width()*1/5)*1.0/mnframewidth;
- fscale2 = (sizemain.height()*1/1)*1.0/mnframeheight;
- if(fscale > fscale2) fscale = fscale2;
- fscale = fscale * 0.99;
- mpviewImg[i]->viewscaleto(fscale);
- }
- }
- mbNeedSetBack = true;
- }
- void MainWindow::on_pushButton_test_clicked()
- {
- double flat = ui->lineEdit_lat->text().toDouble();
- double flon = ui->lineEdit_lon->text().toDouble();
- char strscript[256];
- snprintf(strscript,255,"theLocation(%11.7f,%11.7f);",flon,flat);
- // mMapview->page()->runJavaScript(strscript);
- }
- void MainWindow::on_radioButton_manual_clicked()
- {
- ui->radioButton_manual->setChecked(true);
- mPressKeys.clear();
- mfAcc = 0;
- mfWheel = 0;
- mfBrake = 0;
- mpWheel->updatevalue(mfWheel);
- mpAcc->updatevalue(mfAcc);
- mpBrake->updatevalue(mfBrake);
- mManualTime.restart();
- mnLastTime = mManualTime.elapsed();
- mpTimerManual->start(10);
- mbNeedSetBack = true;
- }
- void MainWindow::onTimerManual()
- {
- static qint64 nLastKeepKeyTime = 0;
- const qint64 nKeepTime = 3000; //if press c key, 5 seconds. in keep mode.
- double fOldWheel = mfWheel;
- double fOldAcc = mfAcc;
- double fOldBrake = mfBrake;
- int timediff = mManualTime.elapsed() - mnLastTime;
- mnLastTime = mManualTime.elapsed();
- bool bInKeepMode = false;
- int nOldShift = mnShift;
- if(mpJRT->isOK())
- {
- mfWheel = mpJRT->GetWheel() * (-100.0)/32768.0;
- mfAcc = ((mpJRT->GetAcc()-32767.0)/65535)*(-100.0);
- mfBrake = ((mpJRT->GetBrake()-32767.0)/65535)*(-100.0);
- if(mfWheel != fOldWheel)mpWheel->updatevalue(mfWheel*5.5);
- if(mfAcc != fOldAcc)mpAcc->updatevalue(mfAcc);
- if(mfBrake != fOldBrake)mpBrake->updatevalue(mfBrake);
- int x = mpJRT->GetShift();
- if(x > 0)mnShift = 1;
- if(x == 0)mnShift = 0;
- if(x < 0)mnShift = -1;
- if(mnShift != nOldShift)
- {
- switch (mnShift) {
- case 1:
- ui->radioButton_Drive->setChecked(true);
- break;
- case 0:
- ui->radioButton_Null->setChecked(true);
- break;
- case -1:
- ui->radioButton_Rear->setChecked(true);
- break;
- default:
- break;
- }
- }
- return;
- }
- if(mPressKeys.contains(Qt::Key_C)||(mPressKeys.contains(Qt::Key_A))||(mPressKeys.contains(Qt::Key_D))||(mPressKeys.contains(Qt::Key_W))||(mPressKeys.contains(Qt::Key_S)))
- {
- nLastKeepKeyTime = QDateTime::currentMSecsSinceEpoch();
- }
- if(abs(QDateTime::currentMSecsSinceEpoch() - nLastKeepKeyTime) < nKeepTime)
- {
- bInKeepMode = true;
- }
- if(mPressKeys.contains(Qt::Key_A)&&(mPressKeys.contains((Qt::Key_D))))
- {
- mfWheel = mfWheel;
- }
- else
- {
- if(mPressKeys.contains(Qt::Key_A))
- {
- // if(mfWheel<0)mfWheel = 0;
- // else
- // {
- mfWheel = mfWheel + timediff*mfWheelSpeed/1000;
- if(mfWheel < -100)mfWheel = -100;
- if(mfWheel > 100 )mfWheel = 100;
- // }
- }
- if(mPressKeys.contains(Qt::Key_D))
- {
- // if(mfWheel>0)mfWheel = 0;
- // else
- // {
- mfWheel = mfWheel - timediff*mfWheelSpeed/1000;
- if(mfWheel < -100)mfWheel = -100;
- if(mfWheel > 100 )mfWheel = 100;
- // }
- }
- }
- if(mPressKeys.contains(Qt::Key_Z))
- {
- mfWheel = 0;
- }
- if(!mPressKeys.contains(Qt::Key_A)&&(!mPressKeys.contains((Qt::Key_D)))&&(bInKeepMode == false))
- {
- if(mfWheel != 0)
- {
- if(mfWheel > 0)mfWheel = mfWheel - timediff*mfWheelAutoDownSpeed/1000;
- else mfWheel = mfWheel + timediff*mfWheelAutoDownSpeed/1000;
- if(fabs(mfWheel)< 10)mfWheel =0;
- }
- }
- if(mnVehMode == 2) //ACC BRAKE
- {
- if(mPressKeys.contains(Qt::Key_W)&&(mPressKeys.contains((Qt::Key_S))))
- {
- mfAcc = 0;
- mfBrake = mfBrake + timediff*mfBrakeSpeed/1000;
- if(mfBrake<0)mfBrake = 0;
- if(mfBrake > 100)mfBrake = 100;
- }
- else
- {
- if(mPressKeys.contains(Qt::Key_W))
- {
- mfBrake = 0;
- mfAcc = mfAcc + timediff*mfAccSpeed/1000;
- if(mfAcc<0)mfAcc = 0;
- if(mfAcc > 100)mfAcc = 100;
- }
- if(mPressKeys.contains(Qt::Key_S))
- {
- mfAcc = 0;
- mfBrake = mfBrake + timediff*mfBrakeSpeed/1000;
- if(mfBrake<0)mfBrake = 0;
- if(mfBrake > 100)mfBrake = 100;
- }
- }
- }
- else //Speed Mode
- {
- if(mPressKeys.contains(Qt::Key_W)&&(mPressKeys.contains((Qt::Key_S))))
- {
- if(mfAcc > 0)
- {
- mfAcc = mfAcc - 10*timediff*mfAccSpeed/1000;
- if(mfAcc<0)mfAcc = 0;
- }
- else
- {
- mfBrake = mfBrake + timediff*mfBrakeSpeed/1000;
- if(mfBrake<0)mfBrake = 0;
- if(mfBrake > 100)mfBrake = 100;
- }
- }
- else
- {
- if(mPressKeys.contains(Qt::Key_W))
- {
- mfBrake = 0;
- mfAcc = mfAcc + timediff*mfAccSpeed/1000;
- if(mfAcc<0)mfAcc = 0;
- if(mfAcc > 100)mfAcc = 100;
- }
- if(mPressKeys.contains(Qt::Key_S))
- {
- if(mfAcc > 0)
- {
- mfAcc = mfAcc - 10*timediff*mfAccSpeed/1000;
- if(mfAcc<0)mfAcc = 0;
- }
- else
- {
- mfBrake = mfBrake + timediff*mfBrakeSpeed/1000;
- if(mfBrake<0)mfBrake = 0;
- if(mfBrake > 100)mfBrake = 100;
- }
- }
- }
- }
- if(!mPressKeys.contains(Qt::Key_W)&&(!mPressKeys.contains((Qt::Key_S)))&&(bInKeepMode == false))
- {
- if(mfBrake != 0)
- {
- // mfBrake = mfBrake - timediff*mfBrakeAutoDownSpeed/1000;
- // if(mfBrake<0)mfBrake = 0;
- // if(mfBrake > 100)mfBrake = 100;
- }
- if(mfAcc != 0)
- {
- mfAcc = mfAcc - timediff*mfAccAutoDownSpeed/1000;
- if(mfAcc<0)mfAcc = 0;
- if(mfAcc > 100)mfAcc = 100;
- }
- }
- if(mfWheel != fOldWheel)mpWheel->updatevalue(mfWheel*4.5);
- if(mfAcc != fOldAcc)mpAcc->updatevalue(mfAcc);
- if(mfBrake != fOldBrake)mpBrake->updatevalue(mfBrake);
- }
- void MainWindow::on_radioButton_auto_clicked()
- {
- ui->radioButton_auto->setChecked(true);
- mPressKeys.clear();
- mpTimerManual->stop();
- mbNeedSetBack = true;
- }
- void MainWindow::onTimerRemote()
- {
- if(ui->radioButton_auto->isChecked())
- {
- mremotectrl.set_ntype(iv::remotectrl_CtrlType_AUTO);
- // mfAcc = 0;
- // mfBrake = 0;
- // mfWheel =0;
- // mpWheel->updatevalue(mfWheel);
- // mpAcc->updatevalue(mfAcc);
- // mpBrake->updatevalue(mfBrake);
- }
- else
- {
- mremotectrl.set_ntype(iv::remotectrl_CtrlType_REMOTE);
- }
- mremotectrl.set_acc(mfAcc);
- mremotectrl.set_brake(mfBrake);
- mremotectrl.set_wheel(mfWheel);
- mremotectrl.set_shift(mnShift);
- int nsersize = mremotectrl.ByteSize();
- char * strbuf = new char[nsersize];
- if(mremotectrl.SerializeToArray(strbuf,nsersize))
- {
- mgrpcpc->SetCtrlMsg("remotectrl",strbuf,nsersize);
- // iv::modulecomm::ModuleSendMsg(mpa,strbuf,nsersize);
- }
- delete strbuf;
- }
- void MainWindow::onTimerUpdatePic()
- {
- static qint64 time_pic = 0;
- static qint64 time_trace = 0;
- static int pos = 0;
- static std::vector<iv::simpletrace> xvectorsimpletrace;
- if(gTimeTrace != time_trace)
- {
- time_trace = gTimeTrace;
- gMutexTrace.lock();
- xvectorsimpletrace = gvectorsimplerace;
- gMutexTrace.unlock();
- pos = 0;
- if(xvectorsimpletrace.size()> 0)
- {
- QJsonArray num_json,num2_json; //声明QJsonArray
- QJsonDocument num_document,num2_document; //将QJsonArray改为QJsonDocument类
- QByteArray num_byteArray,num2_byteArray; //
- int i=0;
- for(i=0;i<xvectorsimpletrace.size();i++) //将数组传入压入num_json
- {
- num_json.append(xvectorsimpletrace[i].gps_lng);
- num2_json.append(xvectorsimpletrace[i].gps_lat);
- }
- num_document.setArray(num_json);
- num2_document.setArray(num2_json);
- num_byteArray = num_document.toJson(QJsonDocument::Compact);
- num2_byteArray = num2_document.toJson(QJsonDocument::Compact);
- QString numJson(num_byteArray); //再转为QString
- QString num2Json(num2_byteArray); //再转为QString
- QString cmd = QString("settrace(\"%1\",\"%2\")").arg(numJson).arg(num2Json);
- // mMapview->page()->runJavaScript(cmd);
- }
- }
- // if(pos<xvectorsimpletrace.size())
- // {
- // if(pos == 0)
- // {
- // mMapview->page()->runJavaScript("clear()");
- // }
- // char strscript[256];
- // snprintf(strscript,255,"mapLocation(%11.7f,%11.7f);",xvectorsimpletrace[pos].gps_lng,xvectorsimpletrace[pos].gps_lat);
- // mMapview->page()->runJavaScript(strscript);
- // pos++;
- // }
- }
- void MainWindow::onTimerUpdateView()
- {
- static qint64 time_gps = 0;
- unsigned int i;
- char strlatency[1000];
- char strtem[100];
- snprintf(strlatency,1000,"Latency(Up|FrameRate|Down): ");
- snprintf(strtem,100,"FT(%d|%d|%d) ",mgrpcpc->GetPicLatency(0),mgrpcpc->GetFrameRate(0),mgrpcpc->GetPicDownLatency(0));strncat(strlatency,strtem,1000);
- snprintf(strtem,100,"RR(%d|%d|%d) ",mgrpcpc->GetPicLatency(1),mgrpcpc->GetFrameRate(1),mgrpcpc->GetPicDownLatency(1));strncat(strlatency,strtem,1000);
- snprintf(strtem,100,"LT(%d|%d|%d) ",mgrpcpc->GetPicLatency(2),mgrpcpc->GetFrameRate(2),mgrpcpc->GetPicDownLatency(2));strncat(strlatency,strtem,1000);
- snprintf(strtem,100,"RT(%d|%d|%d) ",mgrpcpc->GetPicLatency(3),mgrpcpc->GetFrameRate(3),mgrpcpc->GetPicDownLatency(3));strncat(strlatency,strtem,1000);
- mpLabelLatency->setText(strlatency);
- if(gTimeGPSIMUUpdate != time_gps)
- {
- time_gps = gTimeGPSIMUUpdate;
- char strscript[256];
- snprintf(strscript,255,"theLocation(%11.7f,%11.7f,%11.3f);",ggpsimu.lon(),ggpsimu.lat(),ggpsimu.heading());
- // mMapview->page()->runJavaScript(strscript);
- iv::gps::gpsimu xgpsimu;
- xgpsimu.CopyFrom(ggpsimu);
- ui->lineEdit_gpsins->setText(QString::number(xgpsimu.ins_state()));
- ui->lineEdit_gpsrtk->setText(QString::number(xgpsimu.rtk_state()));
- ui->lineEdit_gpslon->setText(QString::number(xgpsimu.lon(),'f',7));
- ui->lineEdit_gpslat->setText(QString::number(xgpsimu.lat(),'f',7));
- ui->lineEdit_gpsheading->setText(QString::number(xgpsimu.heading(),'f',2));
- ui->lineEdit_gpsheight->setText(QString::number(xgpsimu.height(),'f',2));
- ui->lineEdit_gpsspeed->setText(QString::number(xgpsimu.speed(),'f',2));
- ui->lineEdit_gpssat->setText(QString::number(xgpsimu.satnum1()));
- mstrGPSTime = QDateTime::fromMSecsSinceEpoch(xgpsimu.msgtime()).toString("GPS: yyyy-MM-dd hh:mm:ss ");
- setWindowTitle(mstrProgName + mstrVIN + mstrGPSTime + mstrPicTime);
- mpVehSpeed->updatevalue(xgpsimu.speed()*3.6);
- }
- }
- void MainWindow::onCamUpdate(int ncampos, QImage image)
- {
- int i = ncampos;
- // ui->label_pic->setPixmap(QPixmap::fromImage(image));
- mpsceneImg[i]->clear();
- // mpsceneImg[i]->addPixmap(QPixmap::fromImage(image));
- mpsceneImg[i]->addPixmap(QPixmap::fromImage(image));
- mpviewImg[i]->setScene(mpsceneImg[i]);
- mpviewImg[i]->show();
- }
- void MainWindow::paintEvent(QPaintEvent *)
- {
- QTime xTime;
- static int mnDraw = 10;
- if(mbNeedSetBack == true)
- {
- mnDraw = 10;
- mbNeedSetBack = false;
- }
- if(mnDraw>0)
- {
- mpainter_background = new QPainter(this);
- mpainter_background->drawPixmap(0, 0, this->width(), this->height(), QPixmap(":/pic/background2.jpg"));
- delete mpainter_background;
- mnDraw--;
- }
- int i;
- xTime.start();
- int nupdate = 0;
- for(i=0;i<NUM_CAM;i++)
- {
- // continue;
- if(mbCamUpdate[i])
- {
- nupdate++;
- // xTime.start();
- // std::cout<<" copy image. "<<std::endl;
- mMutexCam[i].lock();
- // QImage image = mpImageCam[i]->copy();
- mbCamUpdate[i] = false;
- // QImage image = mpPicView->GetImage();
- mpsceneImg[i]->clear();
- // mpsceneImg[i]->addPixmap(QPixmap::fromImage(image));
- mpsceneImg[i]->addPixmap(QPixmap::fromImage(*mpImageCam[i]));
- mpviewImg[i]->setScene(mpsceneImg[i]);
- mpviewImg[i]->show();
- mMutexCam[i].unlock();
- // std::cout<<" update a image use. "<<xTime.elapsed()<<std::endl;
- }
- }
- // std::cout<<" time upadate time: "<<xTime.elapsed()<<" update cout:"<<nupdate<<std::endl;
- }
- void MainWindow::on_pushButton_Go_clicked()
- {
- if(ui->comboBox_Station->currentIndex() < 0)return;
- int index = ui->comboBox_Station->currentIndex();
- if(index<0 || index>= gvectorpos.size())
- {
- std::cout<<"out range."<<std::endl;
- return;
- }
- iv::pos_def xpos = gvectorpos[index];
- double lon,lat;
- lon = xpos.mflon;
- lat = xpos.mflat;
- xodrobj xo;
- xo.flon = lon;
- xo.flat = lat;
- xo.lane = 3;
- mgrpcpc->SetCtrlMsg("xodrreq",(char *)&xo,sizeof(xodrobj));
- // iv::modulecomm::ModuleSendMsg(mpadst,(char *)&xo,sizeof(xodrobj));
- }
- void MainWindow::on_comboBox_Station_currentIndexChanged(int index)
- {
- if(index<0 || index>= gvectorpos.size())
- {
- std::cout<<"out range."<<std::endl;
- return;
- }
- iv::pos_def xpos = gvectorpos[index];
- char strscript[256];
- snprintf(strscript,255,"objLocation(%11.7f,%11.7f);",xpos.mflon,xpos.mflat);
- // mMapview->page()->runJavaScript(strscript);
- mbNeedSetBack = true;
- }
- void MainWindow::on_checkBox_Drive_stateChanged(int arg1)
- {
- }
- void MainWindow::on_checkBox_Drive_clicked()
- {
- }
- void MainWindow::on_checkBox_Null_clicked()
- {
- }
- void MainWindow::on_checkBox_Rear_clicked()
- {
- mbNeedSetBack = true;
- }
- void MainWindow::on_radioButton_Drive_clicked()
- {
- mnShift = 1;
- mbNeedSetBack = true;
- // on_radioButton_picfront_clicked();
- }
- void MainWindow::on_radioButton_Null_clicked()
- {
- mnShift = 0;
- mbNeedSetBack = true;
- }
- void MainWindow::onCloseDlg()
- {
- qDebug("cloase");
- }
- void MainWindow::on_checkBox_clicked()
- {
- }
- void MainWindow::saveavi(int index)
- {
- (void)index;
- }
- void MainWindow::onCloseBigDlg()
- {
- }
- void MainWindow::on_actionSet_Query_Pass_triggered()
- {
- DialogSetPassWord xdlg(DialogSetPassWord_Type::QUERY,mstrqueryMD5,this);
- if(xdlg.exec() == xdlg.Accepted)
- {
- mgrpcpc->setqueryMD5(ServiceRCIni.GetQueryMD5());
- mstrqueryMD5 = ServiceRCIni.GetQueryMD5();
- }
- }
- void MainWindow::on_actionSetting_triggered()
- {
- DialogSetting xdlg(this);
- if(xdlg.exec() == QDialog::Accepted)
- {
- mgrpcpc->setVIN(ServiceRCIni.GetVIN());
- mstrVehVIN = ServiceRCIni.GetVIN();
- }
- }
- void MainWindow::on_actionSet_Ctrl_Pass_triggered()
- {
- DialogSetPassWord xdlg(DialogSetPassWord_Type::CTRL,mstrctrlMD5,this);
- if(xdlg.exec() == xdlg.Accepted)
- {
- mgrpcpc->setctrlMD5(ServiceRCIni.GetCtrlMD5());
- mstrctrlMD5 = ServiceRCIni.GetCtrlMD5();
- }
- }
- void MainWindow::threadinfo()
- {
- int nrtn;
- iv::cloud::cloudmsg xcloudmsg;
- while(mbThreadrun)
- {
- nrtn = mgrpcpc->GetQueryMsg(xcloudmsg,1000);
- if(nrtn == 1)
- {
- int i;
- for(i=0;i<xcloudmsg.xclouddata_size();i++)
- {
- iv::cloud::cloudunit * punit = xcloudmsg.mutable_xclouddata(i);
- if(punit->msgname() == "hcp2_gpsimu")
- {
- iv::gps::gpsimu xgpsimu;
- if(!xgpsimu.ParseFromArray(punit->data().data(),punit->data().size()))
- {
- std::cout<<"ListenRaw Parse error."<<std::endl;
- continue;
- }
- ggpsimu.CopyFrom(xgpsimu);
- gTimeGPSIMUUpdate = QDateTime::currentMSecsSinceEpoch();
- }
- }
- // std::cout<<" receive info msg. "<<std::endl;
- }
- }
- }
- void MainWindow::threadframe(int ncamppos)
- {
- iv::h264rawframedata xframe;
- while(mbThreadrun)
- {
- // std::this_thread::sleep_for(std::chrono::milliseconds(100));
- // continue;
- int nrtn;
- nrtn = mgrpcpc->Consumeh264frame(ncamppos,xframe,10);
- if(nrtn == 1)
- {
- // std::cout<<"recv a frame."<<std::endl;
- iv::rawframedata xrawframe;
- xrawframe.mpstr_ptr = xframe.mpstr_ptr;
- xrawframe.ndatasize = xframe.mdatasize;
- mph264decode[ncamppos]->addframedata(xrawframe);
- }
- }
- }
- void MainWindow::threadpic(int ncampos)
- {
- while(mbThreadrun)
- {
- int nindex = mph264decode[ncampos]->GetUpdatedIndex(10);
- if(nindex<0)continue;
- // std::cout<<" recv a yuv."<<std::endl;
- iv::framedecodebuf * pbuf = mph264decode[ncampos]->LockReadBuff(nindex);
- int cy = pbuf->frameheight;
- int cx = pbuf->framewidth;
- cv::Mat rgbImg(cy, cx,CV_8UC3);
- if((cy!=mnframeheight) || (cx != mnframewidth))
- {
- mnframeheight = cy;
- mnframewidth = cx;
- resizeEvent(NULL);
- }
- #ifndef USE_QSV
- cv::cvtColor(pbuf->myuvImg, rgbImg, CV_YUV2RGB_I420);
- #endif
- #ifdef USE_QSV
- cv::cvtColor(pbuf->myuvImg, rgbImg, CV_YUV2RGB_NV12);
- #endif
- mph264decode[ncampos]->UnlockReadBuff(nindex);
- QImage image2 = QImage((uchar*)(rgbImg.data), rgbImg.cols, rgbImg.rows, QImage::Format_RGB888);
- mMutexCam[ncampos].lock();
- // emit CamUpdate(ncampos,image2);
- *mpImageCam[ncampos] = image2.copy();
- mbCamUpdate[ncampos] = true;
- mMutexCam[ncampos].unlock();
- emit CamUpdate(ncampos);
- // cv::cvtColor(rgbImg, rgbImg, CV_BGR2RGB);
- // QImage image2 = QImage((uchar*)(rgbImg.data), rgbImg.cols, rgbImg.rows, QImage::Format_RGB888);
- }
- }
- void MainWindow::onCamUpdate(int ncampos)
- {
- (void)ncampos;
- static int64_t nlastupdate =0;
- int64_t nnow = std::chrono::system_clock::now().time_since_epoch().count()/1000000;
- if(abs(nnow - nlastupdate)>30)
- {
- nlastupdate = std::chrono::system_clock::now().time_since_epoch().count()/1000000;
- update();
- }
- }
- void MainWindow::on_actionFullScreem_triggered()
- {
- showFullScreen();
- ui->menubar->setVisible(false);
- ui->statusbar->setVisible(false);
- mbNeedSetBack = true;
- }
- void MainWindow::on_actionNormal_triggered()
- {
- showNormal();
- }
- void MainWindow::on_horizontalSlider_wheelspeed_sliderMoved(int position)
- {
- (void)position;
- mfWheelSpeed = mfWheelBaseSpeed * ui->horizontalSlider_wheelspeed->value();
- mbNeedSetBack = true;
- }
- void MainWindow::on_horizontalSlider_wheelspeed_valueChanged(int value)
- {
- (void)value;
- mfWheelSpeed = mfWheelBaseSpeed * ui->horizontalSlider_wheelspeed->value();
- mbNeedSetBack = true;
- }
|