|
@@ -1,6 +1,10 @@
|
|
|
#include "mainwindow.h"
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
|
+#include "gpsimu.pb.h"
|
|
|
+
|
|
|
+#include "groupctrl.pb.h"
|
|
|
+
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
|
QMainWindow(parent),
|
|
|
ui(new Ui::MainWindow)
|
|
@@ -12,15 +16,235 @@ MainWindow::MainWindow(QWidget *parent) :
|
|
|
mpgrpcclient_ptr1 = std::shared_ptr<grpcclient>(new grpcclient(""));
|
|
|
mpgrpcclient_ptr2 = std::shared_ptr<grpcclient>(new grpcclient(""));
|
|
|
|
|
|
- mpgrpcclient_ptr1->SetServerPort("127.0.0.1","50061");
|
|
|
- mpgrpcclient_ptr2->SetServerPort("127.0.0.1","50061");
|
|
|
+ mpgrpcclient_ptr1->SetServerPort("223.84.137.240","50061");
|
|
|
+ mpgrpcclient_ptr2->SetServerPort("223.84.137.240","50061");
|
|
|
|
|
|
mpgrpcclient_ptr1->SetNodeId("10001","1");
|
|
|
mpgrpcclient_ptr2->SetNodeId("10002","2");
|
|
|
|
|
|
+ mpgrpcclient_ptr1->SetShareMode(grpcclient::Mode_Inter);
|
|
|
+ mpgrpcclient_ptr2->SetShareMode(grpcclient::Mode_Inter);
|
|
|
+
|
|
|
+ mpgrpcclient_ptr1->start();
|
|
|
+ mpgrpcclient_ptr2->start();
|
|
|
+
|
|
|
+ mpthread1 = new std::thread(&MainWindow::thread1recv,this);
|
|
|
+ mpthread2 = new std::thread(&MainWindow::thread2recv,this);
|
|
|
+
|
|
|
+ mpSpeed1 = new Speed(ui->centralWidget);
|
|
|
+ mpSpeed2 = new Speed(ui->centralWidget);
|
|
|
+
|
|
|
+ mpSpeed1->setGeometry(1100,100,300,300);
|
|
|
+ mpSpeed2->setGeometry(1100,500,300,300);
|
|
|
+
|
|
|
+ mpSpeed1->setminvalue(0);
|
|
|
+ mpSpeed1->setmaxvalue(100);
|
|
|
+
|
|
|
+ mpSpeed2->setminvalue(0);
|
|
|
+ mpSpeed2->setmaxvalue(100);
|
|
|
+
|
|
|
+ mpSpeed1->settitle("1号车");
|
|
|
+ mpSpeed1->setunits("km/h");
|
|
|
+
|
|
|
+ mpSpeed2->settitle("2号车");
|
|
|
+ mpSpeed2->setunits("km/h");
|
|
|
+
|
|
|
+ mpTimer = new QTimer(this);
|
|
|
+ connect(mpTimer,SIGNAL(timeout()),this,SLOT(onTimer()));
|
|
|
+ mpTimer->start(100);
|
|
|
+
|
|
|
+ ui->radioButton_40kmh->setChecked(true);
|
|
|
+ ui->radioButton_origin->setChecked(true);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
{
|
|
|
+ mbrecv = false;
|
|
|
+ mpthread1->join();
|
|
|
+ mpthread2->join();
|
|
|
delete ui;
|
|
|
}
|
|
|
+
|
|
|
+void MainWindow::thread1recv()
|
|
|
+{
|
|
|
+ while(mbrecv)
|
|
|
+ {
|
|
|
+ iv::swapmsgbuff xswap;
|
|
|
+ if( mpgrpcclient_ptr1->GetSwapBuffData(xswap,10) == 1)
|
|
|
+ {
|
|
|
+ if(xswap.mstrmsgname == "hcp2_gpsimu")
|
|
|
+ {
|
|
|
+ iv::gps::gpsimu xgpsimu;
|
|
|
+ if(xgpsimu.ParseFromArray(xswap.mpdata_ptr.get(),xswap.mndatalen))
|
|
|
+ {
|
|
|
+ if(xgpsimu.has_speed())
|
|
|
+ mfSpeed1 = xgpsimu.speed() * 3.6;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ mfSpeed1 = sqrt(pow(xgpsimu.ve(),2) + pow(xgpsimu.vn(),2)) * 3.6;
|
|
|
+ }
|
|
|
+
|
|
|
+ // std::cout<<" speed1: "<<mfSpeed1<<std::endl;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::thread2recv()
|
|
|
+{
|
|
|
+ while(mbrecv)
|
|
|
+ {
|
|
|
+ iv::swapmsgbuff xswap;
|
|
|
+ if( mpgrpcclient_ptr2->GetSwapBuffData(xswap,10) == 1)
|
|
|
+ {
|
|
|
+ if(xswap.mstrmsgname == "hcp2_gpsimu")
|
|
|
+ {
|
|
|
+ iv::gps::gpsimu xgpsimu;
|
|
|
+ if(xgpsimu.ParseFromArray(xswap.mpdata_ptr.get(),xswap.mndatalen))
|
|
|
+ {
|
|
|
+ if(xgpsimu.has_speed())
|
|
|
+ mfSpeed2 = xgpsimu.speed() * 3.6;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ mfSpeed2 = sqrt(pow(xgpsimu.ve(),2) + pow(xgpsimu.vn(),2)) * 3.6;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::onTimer()
|
|
|
+{
|
|
|
+ mpSpeed1->updatevalue(mfSpeed1);
|
|
|
+ mpSpeed2->updatevalue(mfSpeed2);
|
|
|
+
|
|
|
+ bool bChangeEn = true;
|
|
|
+ if((mfSpeed1> mfSpeedChangeLim) || (mfSpeed2 > mfSpeedChangeLim))
|
|
|
+ {
|
|
|
+ bChangeEn = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(bChangeEn)
|
|
|
+ {
|
|
|
+ ui->radioButton_frontleft->setEnabled(true);
|
|
|
+ ui->radioButton_rearleft->setEnabled(true);
|
|
|
+ ui->radioButton_frontright->setEnabled(true);
|
|
|
+ ui->radioButton_rearright->setEnabled(true);
|
|
|
+ ui->radioButton_sameleft->setEnabled(true);
|
|
|
+ ui->radioButton_sameright->setEnabled(true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ui->radioButton_frontleft->setEnabled(false);
|
|
|
+ ui->radioButton_rearleft->setEnabled(false);
|
|
|
+ ui->radioButton_frontright->setEnabled(false);
|
|
|
+ ui->radioButton_rearright->setEnabled(false);
|
|
|
+ ui->radioButton_sameleft->setEnabled(false);
|
|
|
+ ui->radioButton_sameright->setEnabled(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!ui->radioButton_origin->isChecked())
|
|
|
+ {
|
|
|
+ ui->radioButton_15kmh->setEnabled(false);
|
|
|
+ ui->radioButton_20kmh->setEnabled(false);
|
|
|
+ ui->radioButton_30kmh->setEnabled(false);
|
|
|
+ ui->radioButton_40kmh->setEnabled(false);
|
|
|
+ ui->radioButton_60kmh->setEnabled(false);
|
|
|
+ ui->radioButton_80kmh->setEnabled(false);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ui->radioButton_15kmh->setEnabled(true);
|
|
|
+ ui->radioButton_20kmh->setEnabled(true);
|
|
|
+ ui->radioButton_30kmh->setEnabled(true);
|
|
|
+ ui->radioButton_40kmh->setEnabled(true);
|
|
|
+ ui->radioButton_60kmh->setEnabled(true);
|
|
|
+ ui->radioButton_80kmh->setEnabled(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ double fGroupSpeed = 40;
|
|
|
+ double fFrontChange = 0.0;
|
|
|
+ double fRearChange = 0.0;
|
|
|
+ fGroupSpeed = GetGroupSpeed();
|
|
|
+ GetChange(fFrontChange,fRearChange);
|
|
|
+ iv::group::groupctrl xctrl;
|
|
|
+ xctrl.set_fgroupspeed(fGroupSpeed);
|
|
|
+ xctrl.set_ffrontchange(fFrontChange);
|
|
|
+ xctrl.set_frearchange(fRearChange);
|
|
|
+
|
|
|
+ int nbytesize = xctrl.ByteSize();
|
|
|
+ std::shared_ptr<char> pstr_ptr = std::shared_ptr<char>(new char[nbytesize]);
|
|
|
+ if(xctrl.SerializeToArray(pstr_ptr.get(),nbytesize))
|
|
|
+ {
|
|
|
+ mpgrpcclient_ptr1->UpdateData(pstr_ptr.get(),nbytesize,"groupctrl");
|
|
|
+ mpgrpcclient_ptr2->UpdateData(pstr_ptr.get(),nbytesize,"groupctrl");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cout<<"serialize fail."<<std::endl;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+double MainWindow::GetGroupSpeed()
|
|
|
+{
|
|
|
+ if(ui->radioButton_5kmh)return 5.0;
|
|
|
+ if(ui->radioButton_10kmh)return 10.0;
|
|
|
+ if(ui->radioButton_15kmh)return 15.0;
|
|
|
+ if(ui->radioButton_20kmh)return 20.0;
|
|
|
+ if(ui->radioButton_30kmh)return 30.0;
|
|
|
+ if(ui->radioButton_40kmh)return 40.0;
|
|
|
+ if(ui->radioButton_60kmh)return 60.0;
|
|
|
+ if(ui->radioButton_80kmh)return 80.0;
|
|
|
+ return 40.0;
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::GetChange(double & fFrontChange, double & fRearChange)
|
|
|
+{
|
|
|
+ fFrontChange = 0.0;
|
|
|
+ fRearChange = 0.0;
|
|
|
+ double fChange = 3.5;
|
|
|
+ if(ui->radioButton_origin)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(ui->radioButton_frontleft)
|
|
|
+ {
|
|
|
+ fFrontChange = fChange * ( 1.0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(ui->radioButton_rearleft)
|
|
|
+ {
|
|
|
+ fRearChange = fChange * ( 1.0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(ui->radioButton_frontright)
|
|
|
+ {
|
|
|
+ fFrontChange = fChange * ( -1.0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(ui->radioButton_rearright)
|
|
|
+ {
|
|
|
+ fRearChange = fChange * ( -1.0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(ui->radioButton_sameleft)
|
|
|
+ {
|
|
|
+ fFrontChange = fChange * ( 1.0);
|
|
|
+ fRearChange = fChange * ( 1.0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(ui->radioButton_sameright)
|
|
|
+ {
|
|
|
+ fFrontChange = fChange * ( -1.0);
|
|
|
+ fRearChange = fChange * ( -1.0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+}
|