|
@@ -0,0 +1,358 @@
|
|
|
+#include "mainwindow.h"
|
|
|
+#include "ui_mainwindow.h"
|
|
|
+
|
|
|
+iv::Ivlog *givlog;
|
|
|
+unsigned int gv2xEn = true;
|
|
|
+int starSig = 0x2323;
|
|
|
+int cmdSig = 0x03;
|
|
|
+int askSig = 0xfe;
|
|
|
+std::string msgID = "000000000000000000";
|
|
|
+int encrytion = 0x01;
|
|
|
+int dataRate = 0;
|
|
|
+int dataSizeL = 0x00;
|
|
|
+int dataSizeH = 0xd6;
|
|
|
+
|
|
|
+MainWindow::MainWindow(QWidget *parent) :
|
|
|
+ QMainWindow(parent),
|
|
|
+ ui(new Ui::MainWindow)
|
|
|
+{
|
|
|
+ ui->setupUi(this);
|
|
|
+ //Start Get init param
|
|
|
+ QString strpath = QCoreApplication::applicationDirPath();
|
|
|
+ qDebug()<<strpath;
|
|
|
+ strpath = strpath + "/v2xTcpClientWL.xml";
|
|
|
+
|
|
|
+ iv::xmlparam::Xmlparam xp(strpath.toStdString());
|
|
|
+
|
|
|
+ std::string carVIN = xp.GetParam("carVIN","A1S2D3F4G5H6J7126");
|
|
|
+ const char* id = carVIN.data();
|
|
|
+ qDebug()<<id;
|
|
|
+ int len = sizeof(upPack.carVIN);
|
|
|
+ memcpy(upPack.carVIN, id, len);
|
|
|
+// mscarID = QString::fromStdString(strCarVIN);
|
|
|
+
|
|
|
+// std::string strHostIP = xp.GetParam("hostIP","127.0.0.1");
|
|
|
+// std::string strHostPort = xp.GetParam("hostPort","1200");
|
|
|
+ std::string strHostIP = xp.GetParam("hostIP","123.127.164.24");
|
|
|
+ std::string strHostPort = xp.GetParam("hostPort","5600");
|
|
|
+
|
|
|
+ socket=new QTcpSocket();
|
|
|
+ ui->lineEdit_ip->setText(QString::fromStdString(strHostIP));
|
|
|
+ ui->lineEdit_port->setText(QString::fromStdString(strHostPort));
|
|
|
+ ui->pushButton_connect->setEnabled(false);
|
|
|
+
|
|
|
+ givlog = new iv::Ivlog("v2x");
|
|
|
+ connect(socket, &QTcpSocket::readyRead, this, &MainWindow::socket_Read_Data);
|
|
|
+ connect(socket, &QTcpSocket::disconnected, this, &MainWindow::socket_Disconnected);
|
|
|
+
|
|
|
+ /* ShareMemory Register BEGIN */
|
|
|
+ //ShareMem: 车辆地盘状态
|
|
|
+ ModuleFun funchassis =std::bind(&MainWindow::UpdateChassis,this,std::placeholders::_1,\
|
|
|
+ std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,\
|
|
|
+ std::placeholders::_5);
|
|
|
+ mpMemchassis = iv::modulecomm::RegisterRecvPlus("chassis",funchassis);
|
|
|
+ //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);
|
|
|
+
|
|
|
+ /* ShareMemory Register END */
|
|
|
+
|
|
|
+ //heart beat,jiaolili,20210207
|
|
|
+ m_bEnablePlatform=false;
|
|
|
+ m_bIsConnect=false;
|
|
|
+ m_iHeartbeatCount=0;
|
|
|
+ QTimer *timer = new QTimer(this);
|
|
|
+ connect(timer,SIGNAL(timeout()),SLOT(heartBeat()));
|
|
|
+ timer->start(100);
|
|
|
+ ///////////////////////////////////////////
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+MainWindow::~MainWindow()
|
|
|
+{
|
|
|
+ delete this->socket;
|
|
|
+ delete ui;
|
|
|
+}
|
|
|
+void MainWindow::heartBeat()
|
|
|
+{
|
|
|
+ if(gv2xEn) {
|
|
|
+ if(!m_bEnablePlatform) {
|
|
|
+ connectPlatform();
|
|
|
+ }
|
|
|
+ if(m_bIsConnect) {
|
|
|
+ upDataStream();
|
|
|
+ } else {
|
|
|
+ connectPlatform();
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ if(m_bEnablePlatform) {
|
|
|
+ disconnectPlatform();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ m_bEnablePlatform = gv2xEn;
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::upDataStream()
|
|
|
+{
|
|
|
+ upVehicleStatus();
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::socket_Disconnected()
|
|
|
+{
|
|
|
+
|
|
|
+ //修改按键文字
|
|
|
+ m_bIsConnect=false;
|
|
|
+ ui->pushButton_connect->setText("connect");
|
|
|
+ ui->textEdit_messages->insertPlainText("服务器消息:Disconnected");
|
|
|
+}
|
|
|
+void MainWindow::connectPlatform()
|
|
|
+{
|
|
|
+ QString IP;
|
|
|
+ int port;
|
|
|
+ //获取IP地址
|
|
|
+ IP = ui->lineEdit_ip->text();
|
|
|
+ //获取端口号
|
|
|
+ port = ui->lineEdit_port->text().toInt();
|
|
|
+ ui->textEdit_messages->setText("");
|
|
|
+ ui->textEdit_messages->insertPlainText("正在连接"+ui->lineEdit_ip->text()+":"+ui->lineEdit_port->text()+"\n");
|
|
|
+ //取消已有的连接
|
|
|
+ socket->abort();
|
|
|
+ //连接服务器
|
|
|
+ socket->connectToHost(IP, port);
|
|
|
+ //等待连接成功
|
|
|
+ if(!socket->waitForConnected(30000)) {
|
|
|
+ ui->textEdit_messages->insertPlainText("连接失败\n");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ m_bIsConnect = true;
|
|
|
+ ui->textEdit_messages->insertPlainText("连接成功\n");
|
|
|
+ //修改按键文字
|
|
|
+ ui->pushButton_connect->setText("disconnect");
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::disconnectPlatform()
|
|
|
+{
|
|
|
+ //断开连接
|
|
|
+ ui->textEdit_messages->setText("断开连接\n");
|
|
|
+ socket->disconnectFromHost();
|
|
|
+ //修改按键文字
|
|
|
+ ui->pushButton_connect->setText("connect");
|
|
|
+ m_bIsConnect=false;
|
|
|
+}
|
|
|
+void MainWindow::on_pushButton_connect_clicked()
|
|
|
+{
|
|
|
+ if(ui->pushButton_connect->text() == tr("connect"))
|
|
|
+ {
|
|
|
+ QString IP;
|
|
|
+ int port;
|
|
|
+
|
|
|
+ //获取IP地址
|
|
|
+ IP = ui->lineEdit_ip->text();
|
|
|
+ //获取端口号
|
|
|
+ port = ui->lineEdit_port->text().toInt();
|
|
|
+ ui->textEdit_messages->setText("");
|
|
|
+ ui->textEdit_messages->insertPlainText("正在连接"+ui->lineEdit_ip->text()+":"+ui->lineEdit_port->text()+"\n");
|
|
|
+ //取消已有的连接
|
|
|
+ socket->abort();
|
|
|
+ //连接服务器
|
|
|
+ socket->connectToHost(IP, port);
|
|
|
+ //等待连接成功
|
|
|
+ if(!socket->waitForConnected(30000))
|
|
|
+ {
|
|
|
+ QMessageBox::warning(this,tr("消息"),tr("连接失败!请重新连接"),QMessageBox::Yes);
|
|
|
+ ui->textEdit_messages->insertPlainText("连接失败\n");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ui->textEdit_messages->insertPlainText("连接成功\n");
|
|
|
+ QMessageBox::information(this,tr("消息"),tr("连接成功"),QMessageBox::Yes);
|
|
|
+
|
|
|
+
|
|
|
+ //修改按键文字
|
|
|
+ ui->pushButton_connect->setText("disconnect");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //断开连接
|
|
|
+ ui->textEdit_messages->setText("断开连接\n");
|
|
|
+ socket->disconnectFromHost();
|
|
|
+ //修改按键文字
|
|
|
+ ui->pushButton_connect->setText("connect");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void MainWindow::on_textEdit_messages_textChanged()
|
|
|
+{
|
|
|
+ ui->textEdit_messages->moveCursor(QTextCursor::End);
|
|
|
+}
|
|
|
+
|
|
|
+#include <QDateTime>
|
|
|
+QString MainWindow::getTimeStamp()
|
|
|
+{
|
|
|
+ qint64 time = QDateTime::currentMSecsSinceEpoch();
|
|
|
+ QString str=QString::number(time);
|
|
|
+ return str;
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::socket_Read_Data()
|
|
|
+{
|
|
|
+ return;
|
|
|
+}
|
|
|
+void MainWindow::upVehicleStatus()
|
|
|
+{
|
|
|
+ QByteArray time_stamp=getTimeStamp().toLatin1();
|
|
|
+ memcpy(upPack.timeStamp, time_stamp.data(), sizeof(upPack.timeStamp));
|
|
|
+ int tmp = mflon * 10000000;
|
|
|
+ mlocation.lonL0 = tmp & 0xFF;
|
|
|
+ mlocation.lonL1 = tmp>>8 & 0xFF;
|
|
|
+ mlocation.lonH0 = tmp>>16 & 0xFF;
|
|
|
+ mlocation.lonH1 = tmp>>24 & 0xFF;
|
|
|
+ tmp = mflat * 10000000;
|
|
|
+ mlocation.latL0 = tmp & 0xFF;
|
|
|
+ mlocation.latL1 = tmp>>8 & 0xFF;
|
|
|
+ mlocation.latH0 = tmp>>16 & 0xFF;
|
|
|
+ mlocation.latH1 = tmp>>24 & 0xFF;
|
|
|
+ tmp = (int)(mfEpsAngle/500.0 + 250);
|
|
|
+ mdecision.epsAngleL = tmp & 0xFF;
|
|
|
+ mdecision.epsAngleH = tmp>>8 & 0xFF;
|
|
|
+ tmp = (int)mfspeed * 100;
|
|
|
+ mvehPerfData.speedL = tmp & 0xFF;
|
|
|
+ mvehPerfData.speedH = tmp>>8 & 0xFF;
|
|
|
+ tmp = (int)(mfAcc * 100 / 980);
|
|
|
+ mvehPerfData.hAccL = tmp & 0xFF;
|
|
|
+ mvehPerfData.hAccH = tmp>>8 & 0xFF;
|
|
|
+ tmp = -1 * mvehPerfData.vAccL;
|
|
|
+ mvehPerfData.vAccL = tmp & 0xFF; //临时
|
|
|
+ mvehPerfData.vAccH = tmp>>8 & 0xFF; //临时
|
|
|
+ tmp = (int)mfheading*80;
|
|
|
+ mvehPerfData.headingL0 = tmp & 0xFF;
|
|
|
+ mvehPerfData.headingL1 = tmp>>8 & 0xFF;
|
|
|
+ mvehPerfData.headingH0 = tmp>>16 & 0xFF;
|
|
|
+ mvehPerfData.headingH1 = tmp>>24 & 0xFF;
|
|
|
+ mvehStData.ctrlMode = 1;
|
|
|
+ mvehStData.meilageL0 = 0xE3;
|
|
|
+ mvehStData.meilageL1 = 0xFF;
|
|
|
+ mvehStData.meilageH0 = 0;
|
|
|
+ mvehStData.meilageH1 = 0;
|
|
|
+ mcomponsData.ADSysSt = 1;
|
|
|
+// char str[10000];
|
|
|
+// memcpy(str,mlocation,sizeof(LocationData));
|
|
|
+ char *sendBuf = new char[1000];
|
|
|
+ int length = 0;
|
|
|
+ int lenHead = sizeof(UpdatePack)/sizeof(unsigned char);
|
|
|
+ int lenLocation = sizeof(mlocation)/sizeof(unsigned char);
|
|
|
+ int lenDecision = sizeof(mdecision)/sizeof(unsigned char);
|
|
|
+ int lenVehPerfData = sizeof(mvehPerfData)/sizeof(unsigned char);
|
|
|
+ int lenVehStData = sizeof(mvehStData)/sizeof(unsigned char);
|
|
|
+ int lenComponsData = sizeof(mcomponsData)/sizeof(unsigned char);
|
|
|
+ length = lenLocation + lenDecision + lenVehPerfData + lenVehStData +lenComponsData;
|
|
|
+ upPack.dataSizeH = length>>8 & 0xFF;
|
|
|
+ upPack.dataSizeL = length & 0xFF;
|
|
|
+ memcpy(sendBuf,&upPack,lenHead);
|
|
|
+ length = lenHead;
|
|
|
+ memcpy(sendBuf+length,&mlocation,lenLocation);
|
|
|
+ length = length + lenLocation;
|
|
|
+ memcpy(sendBuf+length,&mdecision,lenDecision);
|
|
|
+ length = length + lenDecision;
|
|
|
+ memcpy(sendBuf+length,&mvehPerfData,lenVehPerfData);
|
|
|
+ length = length + lenVehPerfData;
|
|
|
+ memcpy(sendBuf+length,&mvehStData,lenVehStData);
|
|
|
+ length = length + lenVehStData;
|
|
|
+ memcpy(sendBuf+length,&mcomponsData,lenComponsData);
|
|
|
+ length = length + lenComponsData;
|
|
|
+
|
|
|
+ socket->write(sendBuf,length);
|
|
|
+ if(!socket->waitForBytesWritten(3000))
|
|
|
+ {
|
|
|
+ qDebug()<<"realtimeinfo send error";
|
|
|
+ }
|
|
|
+ //debug
|
|
|
+
|
|
|
+ qDebug()<<QDateTime::currentDateTimeUtc() <<"lon"<<mflon<<"lat"<<mflat<<"eps"<<mfEpsAngle \
|
|
|
+ <<"speed"<<mfspeed<<"acc"<<mfAcc<<"heading"<<mfheading;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void MainWindow::UpdateChassis(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
|
|
|
+{
|
|
|
+ mistCanCar = 0;
|
|
|
+ iv::chassis xchassis;
|
|
|
+ static int ncount = 0;
|
|
|
+ if(!xchassis.ParseFromArray(strdata,nSize))
|
|
|
+ {
|
|
|
+ std::cout<<"v2xTcpClient::UpdateChassis ParseFrom Array Error."<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(xchassis.has_drivemode())
|
|
|
+ {
|
|
|
+ micarMode = xchassis.drivemode();
|
|
|
+ }
|
|
|
+ if(xchassis.has_vel())
|
|
|
+ mfspeed = xchassis.vel();
|
|
|
+ if(xchassis.has_angle_feedback())
|
|
|
+ mfEpsAngle = xchassis.angle_feedback();
|
|
|
+ if((xchassis.has_soc()))
|
|
|
+ {
|
|
|
+ miSOC = xchassis.soc();
|
|
|
+ }
|
|
|
+ if(xchassis.has_accstep())
|
|
|
+ mfAcc = xchassis.accstep();
|
|
|
+}
|
|
|
+
|
|
|
+//接收GPS数据
|
|
|
+void MainWindow::UpdateGPSIMU(const char * strdata,const unsigned int nSize,const unsigned int index,\
|
|
|
+ const QDateTime * dt,const char * strmemname)
|
|
|
+{
|
|
|
+
|
|
|
+ iv::gps::gpsimu xgpsimu;
|
|
|
+ if(!xgpsimu.ParseFromArray(strdata,nSize))
|
|
|
+ {
|
|
|
+ givlog->warn("ADCIntelligentVehicle::UpdateGPSIMU parse error. nSize is %d",nSize);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ mflat = xgpsimu.lat();
|
|
|
+ mflon = xgpsimu.lon();
|
|
|
+ mfheading = xgpsimu.heading();
|
|
|
+ mpdata.gps_lat = xgpsimu.lat();
|
|
|
+ mpdata.gps_lng = xgpsimu.lon();
|
|
|
+ mpdata.ins_heading_angle = xgpsimu.heading();
|
|
|
+ mpdata.rtk_status = xgpsimu.rtk_state();
|
|
|
+ mpdata.ins_status = xgpsimu.ins_state();
|
|
|
+ mpdata.vel_D = xgpsimu.vd(); //地向速度,单位(米/秒)
|
|
|
+ mpdata.vel_E = xgpsimu.ve(); //东向速度,单位(米/秒)
|
|
|
+ mpdata.vel_N = xgpsimu.vn(); //北向速度,单位(米/秒)
|
|
|
+
|
|
|
+ // 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;
|
|
|
+}
|
|
|
+
|
|
|
+int toUnicode(const char* str)
|
|
|
+{
|
|
|
+ return str[0] + (str[1] ? toUnicode(str + 1) : 0);
|
|
|
+}
|
|
|
+
|
|
|
+constexpr inline int U(const char* str)
|
|
|
+{
|
|
|
+ return str[0] + (str[1] ? U(str + 1) : 0);
|
|
|
+}
|
|
|
+int GetTypeString(const char* obsType)
|
|
|
+{
|
|
|
+ switch (toUnicode(obsType))
|
|
|
+ {
|
|
|
+ case U("unknown"):
|
|
|
+ return 0;
|
|
|
+ case U("car"):
|
|
|
+ return 1;
|
|
|
+ case U("bike"):
|
|
|
+ return 5;
|
|
|
+ case U("pedestrian"):
|
|
|
+ return 3;
|
|
|
+ default:
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+}
|