jiaolili vor 3 Jahren
Ursprung
Commit
4331fdef4e

+ 18 - 0
src/include/proto/v2r.proto

@@ -0,0 +1,18 @@
+syntax = "proto2";
+
+package iv.v2r;
+
+message v2r
+{
+	optional int32 radioLightType   = 1;//红绿灯类型
+	optional int32 radioLightRemain	= 2;//当前灯剩余时间
+	optional float radioBroadcastGpsLat	= 3;//实时路况广播lat
+	optional float radioBroadcastGpsLon	= 4;//实时路况广播lon
+	optional int32	radioBroadcastRange	= 5;//实时路况广播辐射范围
+	optional int32	radioBroadcastTrafficType	= 6;//实时路况广播交通状况类型
+	optional int32	radioBroadcastSpeedLimit	= 7;//实时路况广播限速值
+	optional int32	radioWarningType	= 8;//碰撞预警类型
+	optional int32	radioWarningSpeedLimit	= 9;//碰撞预警限速值
+	optional int32	radioIdentiStart= 10;//拥堵识别开启指令	
+};
+

+ 46 - 0
src/v2x/CommunicatePlatform/CommunicatePlatform.pro

@@ -0,0 +1,46 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2021-09-08T15:59:39
+#
+#-------------------------------------------------
+
+QT       += core gui
+QT       += network
+QT       += serialport
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = CommunicatePlatform
+TEMPLATE = app
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which has been marked as deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+#DEFINES += QT_NO_DEBUG_OUTPUT
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+CONFIG += c++11
+
+SOURCES += \
+        main.cpp \
+        mainwindow.cpp \
+    radio.cpp \
+    tbox.cpp
+
+HEADERS += \
+        mainwindow.h \
+    common.h \
+    radio.h \
+    tbox.h
+
+FORMS += \
+        mainwindow.ui
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target

+ 27 - 0
src/v2x/CommunicatePlatform/common.h

@@ -0,0 +1,27 @@
+#ifndef COMMON_H
+#define COMMON_H
+#include <QDebug>
+//Start Get init param
+//QString strpath = "/v2xTcpClient.xml";
+
+//iv::xmlparam::Xmlparam xp(strpath.toStdString());
+
+//std::string strCarVIN = xp.GetParam("carVIN","catarc001");
+//QString qstrCarVIN = QString::fromStdString(strCarVIN);
+//std::string strHostIP = xp.GetParam("hostIP","47.95.196.28");
+//std::string strHostPort = xp.GetParam("hostPort","12123");
+extern std::string strHostIP = "127.0.0.1";
+extern int iHostPort = 6666;
+extern std::string VIN = "LMWHP1S27J1005905";
+//////////////////////////////
+//         应答标识 TBOX         //
+/////////////////////////////
+#define resuccess (0x01)//成功
+#define reerror (0x02)//错误
+#define VINrepetition (0x03)//VIN重复
+#define reserves (0x40)//保留
+#define comment (0xFE)//命令
+#define CommentcarFormationInfo (0x02)
+#define CommentVinChange (0x0A)
+////////////////////////////////////////
+#endif // COMMON_H

+ 11 - 0
src/v2x/CommunicatePlatform/main.cpp

@@ -0,0 +1,11 @@
+#include "mainwindow.h"
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+    QApplication a(argc, argv);
+    MainWindow w;
+    w.show();
+
+    return a.exec();
+}

+ 206 - 0
src/v2x/CommunicatePlatform/mainwindow.cpp

@@ -0,0 +1,206 @@
+#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();
+}
+
+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;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_radio->upVirtualVehicle(structVirtualVehicle);
+    }
+
+    //m_radio
+}
+void MainWindow::getRandomNum()
+{
+    int randId=qrand()%10000;
+    for(int i=0;i<m_vectorRandom.size();i++) {
+        if(randId==m_vectorRandom[i]) {
+            getRandomNum();
+        }
+    }
+    m_vectorRandom.push_back(randId);
+}
+
+void MainWindow::setEnRadio(bool en)
+{
+    if(en) {
+        ui->lineEdit_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");
+    }
+}

+ 44 - 0
src/v2x/CommunicatePlatform/mainwindow.h

@@ -0,0 +1,44 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+#include "tbox.h"
+#include <QMainWindow>
+#include "radio.h"
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    explicit MainWindow(QWidget *parent = nullptr);
+    ~MainWindow();
+
+private:
+    Ui::MainWindow *ui;
+    Tbox *m_tbox;
+    Radio *m_radio;
+    Memory m_structM;
+    std::vector<int> m_vectorRandom;
+    std::vector<std::string> m_vectorVin;
+public:
+    void initTboxMemory();
+    void enableTbox();
+    void disableTbox();
+    void initUi();
+    void initRadio();
+    void getRandomNum();
+    void setEnRadio(bool en);
+private slots:
+    void on_pushButton_connect_clicked();
+    void on_pushButton_vinChange_clicked(); 
+    void on_checkBox_trafficBroadcast_stateChanged(int arg1);
+    void on_checkBox_collisionWarning_stateChanged(int arg1);
+    void on_checkBox_busyRoad_stateChanged(int arg1);
+    void on_checkBox_dangerousDrive_stateChanged(int arg1);
+    void on_pushButton_setVirtualVehicle_clicked();
+    void on_pushButton_radioConnect_clicked();
+};
+
+#endif // MAINWINDOW_H

+ 534 - 0
src/v2x/CommunicatePlatform/mainwindow.ui

@@ -0,0 +1,534 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>1019</width>
+    <height>603</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralWidget">
+   <widget class="QLabel" name="label">
+    <property name="geometry">
+     <rect>
+      <x>350</x>
+      <y>40</y>
+      <width>81</width>
+      <height>31</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>TBOX状态:</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_enableTox">
+    <property name="geometry">
+     <rect>
+      <x>430</x>
+      <y>50</y>
+      <width>113</width>
+      <height>25</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_2">
+    <property name="geometry">
+     <rect>
+      <x>680</x>
+      <y>40</y>
+      <width>81</width>
+      <height>31</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>电台状态:</string>
+    </property>
+   </widget>
+   <widget class="QLineEdit" name="lineEdit_enableRadio">
+    <property name="geometry">
+     <rect>
+      <x>760</x>
+      <y>50</y>
+      <width>113</width>
+      <height>25</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string/>
+    </property>
+   </widget>
+   <widget class="QGroupBox" name="groupBox">
+    <property name="geometry">
+     <rect>
+      <x>340</x>
+      <y>20</y>
+      <width>311</width>
+      <height>501</height>
+     </rect>
+    </property>
+    <property name="title">
+     <string>Tbox</string>
+    </property>
+    <widget class="QPushButton" name="pushButton_connect">
+     <property name="geometry">
+      <rect>
+       <x>20</x>
+       <y>420</y>
+       <width>89</width>
+       <height>25</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>connect</string>
+     </property>
+    </widget>
+    <widget class="QPushButton" name="pushButton_vinChange">
+     <property name="geometry">
+      <rect>
+       <x>20</x>
+       <y>460</y>
+       <width>91</width>
+       <height>25</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>VIN SET</string>
+     </property>
+    </widget>
+    <widget class="QLineEdit" name="lineEdit_VIN">
+     <property name="geometry">
+      <rect>
+       <x>120</x>
+       <y>460</y>
+       <width>181</width>
+       <height>25</height>
+      </rect>
+     </property>
+    </widget>
+   </widget>
+   <widget class="QGroupBox" name="groupBox_2">
+    <property name="geometry">
+     <rect>
+      <x>670</x>
+      <y>20</y>
+      <width>321</width>
+      <height>501</height>
+     </rect>
+    </property>
+    <property name="title">
+     <string>电台</string>
+    </property>
+    <widget class="QLabel" name="label_4">
+     <property name="geometry">
+      <rect>
+       <x>20</x>
+       <y>150</y>
+       <width>101</width>
+       <height>17</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>路况信息广播:</string>
+     </property>
+    </widget>
+    <widget class="QLabel" name="label_5">
+     <property name="geometry">
+      <rect>
+       <x>20</x>
+       <y>180</y>
+       <width>101</width>
+       <height>17</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>路口碰撞预警:</string>
+     </property>
+    </widget>
+    <widget class="QLabel" name="label_6">
+     <property name="geometry">
+      <rect>
+       <x>20</x>
+       <y>210</y>
+       <width>101</width>
+       <height>17</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>交通拥堵识别:</string>
+     </property>
+    </widget>
+    <widget class="QLabel" name="label_7">
+     <property name="geometry">
+      <rect>
+       <x>20</x>
+       <y>450</y>
+       <width>101</width>
+       <height>17</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>危险驾驶识别:</string>
+     </property>
+    </widget>
+    <widget class="QCheckBox" name="checkBox_trafficBroadcast">
+     <property name="geometry">
+      <rect>
+       <x>140</x>
+       <y>150</y>
+       <width>92</width>
+       <height>23</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>开启</string>
+     </property>
+    </widget>
+    <widget class="QCheckBox" name="checkBox_collisionWarning">
+     <property name="geometry">
+      <rect>
+       <x>140</x>
+       <y>180</y>
+       <width>92</width>
+       <height>23</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>开启</string>
+     </property>
+    </widget>
+    <widget class="QCheckBox" name="checkBox_busyRoad">
+     <property name="geometry">
+      <rect>
+       <x>140</x>
+       <y>210</y>
+       <width>92</width>
+       <height>23</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>开启</string>
+     </property>
+    </widget>
+    <widget class="QCheckBox" name="checkBox_dangerousDrive">
+     <property name="geometry">
+      <rect>
+       <x>140</x>
+       <y>450</y>
+       <width>92</width>
+       <height>23</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>开启</string>
+     </property>
+    </widget>
+    <widget class="QPushButton" name="pushButton_setVirtualVehicle">
+     <property name="geometry">
+      <rect>
+       <x>220</x>
+       <y>210</y>
+       <width>89</width>
+       <height>25</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>set</string>
+     </property>
+    </widget>
+    <widget class="QLineEdit" name="lineEdit_virtualVehicleNum">
+     <property name="geometry">
+      <rect>
+       <x>110</x>
+       <y>250</y>
+       <width>51</width>
+       <height>25</height>
+      </rect>
+     </property>
+    </widget>
+    <widget class="QLabel" name="label_8">
+     <property name="geometry">
+      <rect>
+       <x>20</x>
+       <y>250</y>
+       <width>81</width>
+       <height>17</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>仿真车数量:</string>
+     </property>
+    </widget>
+    <widget class="QLineEdit" name="lineEdit_latMin">
+     <property name="geometry">
+      <rect>
+       <x>90</x>
+       <y>290</y>
+       <width>71</width>
+       <height>25</height>
+      </rect>
+     </property>
+    </widget>
+    <widget class="QLabel" name="label_9">
+     <property name="geometry">
+      <rect>
+       <x>20</x>
+       <y>290</y>
+       <width>81</width>
+       <height>17</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>纬度min:</string>
+     </property>
+    </widget>
+    <widget class="QLineEdit" name="lineEdit_latMax">
+     <property name="geometry">
+      <rect>
+       <x>240</x>
+       <y>290</y>
+       <width>71</width>
+       <height>25</height>
+      </rect>
+     </property>
+    </widget>
+    <widget class="QLabel" name="label_10">
+     <property name="geometry">
+      <rect>
+       <x>170</x>
+       <y>290</y>
+       <width>81</width>
+       <height>17</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>纬度max:</string>
+     </property>
+    </widget>
+    <widget class="QLineEdit" name="lineEdit_lngMax">
+     <property name="geometry">
+      <rect>
+       <x>240</x>
+       <y>330</y>
+       <width>71</width>
+       <height>25</height>
+      </rect>
+     </property>
+    </widget>
+    <widget class="QLabel" name="label_11">
+     <property name="geometry">
+      <rect>
+       <x>170</x>
+       <y>330</y>
+       <width>71</width>
+       <height>17</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>经度max:</string>
+     </property>
+    </widget>
+    <widget class="QLineEdit" name="lineEdit_lngMin">
+     <property name="geometry">
+      <rect>
+       <x>90</x>
+       <y>330</y>
+       <width>71</width>
+       <height>25</height>
+      </rect>
+     </property>
+    </widget>
+    <widget class="QLabel" name="label_12">
+     <property name="geometry">
+      <rect>
+       <x>20</x>
+       <y>330</y>
+       <width>71</width>
+       <height>17</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>经度min:</string>
+     </property>
+    </widget>
+    <widget class="QLineEdit" name="lineEdit_speedMax">
+     <property name="geometry">
+      <rect>
+       <x>240</x>
+       <y>370</y>
+       <width>71</width>
+       <height>25</height>
+      </rect>
+     </property>
+    </widget>
+    <widget class="QLabel" name="label_13">
+     <property name="geometry">
+      <rect>
+       <x>170</x>
+       <y>370</y>
+       <width>81</width>
+       <height>17</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>车速max:</string>
+     </property>
+    </widget>
+    <widget class="QLineEdit" name="lineEdit_speedMin">
+     <property name="geometry">
+      <rect>
+       <x>90</x>
+       <y>370</y>
+       <width>71</width>
+       <height>25</height>
+      </rect>
+     </property>
+    </widget>
+    <widget class="QLabel" name="label_14">
+     <property name="geometry">
+      <rect>
+       <x>20</x>
+       <y>370</y>
+       <width>81</width>
+       <height>17</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>车速min:</string>
+     </property>
+    </widget>
+    <widget class="QLineEdit" name="lineEdit_yawMin">
+     <property name="geometry">
+      <rect>
+       <x>90</x>
+       <y>410</y>
+       <width>71</width>
+       <height>25</height>
+      </rect>
+     </property>
+    </widget>
+    <widget class="QLabel" name="label_15">
+     <property name="geometry">
+      <rect>
+       <x>10</x>
+       <y>410</y>
+       <width>81</width>
+       <height>17</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>航向角min:</string>
+     </property>
+    </widget>
+    <widget class="QLabel" name="label_16">
+     <property name="geometry">
+      <rect>
+       <x>170</x>
+       <y>410</y>
+       <width>81</width>
+       <height>17</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>航向角max:</string>
+     </property>
+    </widget>
+    <widget class="QLineEdit" name="lineEdit_yawMax">
+     <property name="geometry">
+      <rect>
+       <x>250</x>
+       <y>410</y>
+       <width>71</width>
+       <height>25</height>
+      </rect>
+     </property>
+    </widget>
+    <widget class="QPushButton" name="pushButton_radioConnect">
+     <property name="geometry">
+      <rect>
+       <x>20</x>
+       <y>80</y>
+       <width>89</width>
+       <height>25</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>connect</string>
+     </property>
+    </widget>
+   </widget>
+   <widget class="QTextEdit" name="textEdit">
+    <property name="geometry">
+     <rect>
+      <x>20</x>
+      <y>50</y>
+      <width>291</width>
+      <height>361</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QPushButton" name="pushButton_clear">
+    <property name="geometry">
+     <rect>
+      <x>100</x>
+      <y>440</y>
+      <width>89</width>
+      <height>25</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>clear</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_3">
+    <property name="geometry">
+     <rect>
+      <x>20</x>
+      <y>20</y>
+      <width>121</width>
+      <height>17</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>共享内存数据:</string>
+    </property>
+   </widget>
+   <zorder>groupBox</zorder>
+   <zorder>groupBox_2</zorder>
+   <zorder>label</zorder>
+   <zorder>lineEdit_enableTox</zorder>
+   <zorder>label_2</zorder>
+   <zorder>lineEdit_enableRadio</zorder>
+   <zorder>textEdit</zorder>
+   <zorder>pushButton_clear</zorder>
+   <zorder>label_3</zorder>
+  </widget>
+  <widget class="QMenuBar" name="menuBar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>1019</width>
+     <height>28</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QToolBar" name="mainToolBar">
+   <attribute name="toolBarArea">
+    <enum>TopToolBarArea</enum>
+   </attribute>
+   <attribute name="toolBarBreak">
+    <bool>false</bool>
+   </attribute>
+  </widget>
+  <widget class="QStatusBar" name="statusBar"/>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>

+ 537 - 0
src/v2x/CommunicatePlatform/radio.cpp

@@ -0,0 +1,537 @@
+#include "radio.h"
+//#include <string.h>
+Radio::Radio()
+{
+    m_bSerialOpen = false;
+    m_bEnConnect=false;
+    serialPortInit();
+    timer = new QTimer(this);
+    connect(timer,SIGNAL(timeout()),SLOT(heartBeat()));
+    timer->start(1000);
+    m_iResponse = -1;
+    m_iVirtualVehicle = -1;
+    m_bEnTrafficBroadcast=false;
+    m_bEnCollisionWarning=false;
+    m_bEnBusyRoad=false;
+    m_bEnDangerDrive=false;
+    m_bEnUpRespond=false;
+}
+Radio::~Radio()
+{
+    if (m_serialPort_Radio->isOpen())
+        {
+            m_serialPort_Radio->close();
+        }
+    delete m_serialPort_Radio;
+}
+void Radio::setVin(std::string vin)
+{
+    m_sVin=vin;
+}
+
+void Radio::getTrafficBroadcast(bool en)
+{
+    m_bEnTrafficBroadcast=en;
+}
+
+void Radio::getCollisonWarning(bool en)
+{
+    m_bEnCollisionWarning=en;
+}
+
+void Radio::getBusyRoad(bool en)
+{
+    m_bEnBusyRoad=en;
+}
+
+void Radio::getDangerDrive(bool en)
+{
+    m_bEnDangerDrive=en;
+}
+
+void Radio::outLight(lightMessage light)
+{
+    if(m_bEnBusyRoad|m_bEnCollisionWarning|m_bEnDangerDrive|m_bEnTrafficBroadcast) {
+    //protobuffer ui
+    }
+    //protobuffer control
+}
+
+void Radio::outRealtimeTraffic(realtimeTrafficMessage realtimeTraffic)
+{
+    if(m_bEnTrafficBroadcast) {
+        //protobuffer ui
+    }
+    //protobuffer control
+}
+
+void Radio::outCollisionWarning(collisionEarlyWarningMessage collisionWarning)
+{
+    if(m_bEnCollisionWarning) {
+        //protobuffer ui
+    }
+    //protobuffer control
+
+}
+
+void Radio::outCongestionIdenti(congestionIdentificationMessage congestionIdenti)
+{
+    if(m_bEnBusyRoad) {
+        //protobuffer ui
+    }
+}
+
+void Radio::setEnConnect(bool en)
+{
+    m_bEnConnect=en;
+}
+void Radio::serialPortInit()
+{
+//    QStringList m_serialPortName;
+//    foreach(const QSerialPortInfo &info,QSerialPortInfo::availablePorts())
+//    {
+//        m_serialPortName << info.portName();
+//        qDebug()<<"serialPortName:"<<info.portName();
+//    }
+
+    m_serialPort_Radio = new QSerialPort();
+    //m_serialPort_Radio->setPortName("/dev/ttyUSB1");
+    m_serialPort_Radio->setPortName("/dev/pts/1");
+    m_serialPort_Radio->setBaudRate(QSerialPort::Baud115200);
+    m_serialPort_Radio->setParity(QSerialPort::NoParity);
+    m_serialPort_Radio->setDataBits(QSerialPort::Data8);
+    m_serialPort_Radio->setStopBits(QSerialPort::OneStop);
+    m_serialPort_Radio->setFlowControl(QSerialPort::NoFlowControl);
+    m_serialPort_Radio->setReadBufferSize(0);
+    connect(m_serialPort_Radio,SIGNAL(readyRead()),this,SLOT(receiveData()));
+}
+void Radio::openSerial()
+{
+    if(m_serialPort_Radio->open(QSerialPort::ReadWrite)) {
+        m_bSerialOpen = true;
+    }
+}
+void Radio::closeSerial()
+{
+    if(m_serialPort_Radio->isOpen())//如果串口已经打开了
+    {
+        m_serialPort_Radio->clear();
+        m_serialPort_Radio->close();
+        m_bSerialOpen = false;
+    }
+}
+void Radio::heartBeat()
+{
+    if(m_bEnConnect) {
+        if(m_bSerialOpen==false) {
+            openSerial();
+        } else {
+            upDataStream();
+            //if no answer,shake hands three times
+            if(m_iResponse!=-1) {
+                m_iResponse++;
+                if((m_iResponse==3)||(m_iResponse==6)||(m_iResponse==9)) {
+                    upRespondMessageRaw();
+                }
+                if(m_iResponse>=9) {
+                    m_iResponse = -1;
+                }
+            }
+            if(m_iVirtualVehicle!=-1) {
+                m_iVirtualVehicle++;
+                if((m_iVirtualVehicle==3)||(m_iVirtualVehicle==6)||(m_iVirtualVehicle==9)) {
+                    upVirtualVehicleRaw();
+                }
+                if(m_iVirtualVehicle>=9) {
+                    m_iVirtualVehicle = -1;
+                }
+            }
+            ///////////////////////////////////////////////////////
+            if(m_bEnUpRespond) {
+                upRespondMessage();
+                m_bEnUpRespond=false;
+            }
+
+        }
+    } else {
+        if(m_bSerialOpen) {
+            closeSerial();
+        }
+    }
+}
+void Radio::upDataStream()
+{
+    char sendBuf[100];
+    memset(sendBuf,0,100);
+    upVehicleBaseInfo carFormationInfo;
+    std::string vin=m_sVin;
+    vin.copy(carFormationInfo.vin, vin.length(), 0);
+
+    carFormationInfo.vehicleType=0x01;//0x01:轿车;0x02:货车;0x03:客车;0x04:挂车;0x05:摩托车;“0xFE”表示异常,“0xFF”表示无效
+    float flng,flat;
+    flng = (m_structMGpsImu.gps_lng*1000000);
+    flat = (m_structMGpsImu.gps_lat*1000000);
+    int lng,lat;
+    lng=int(flng);
+    lat=int(flat);
+    carFormationInfo.lng[0] = (lng>>24)&0xff;
+    carFormationInfo.lng[1] = (lng>>16)&0xff;
+    carFormationInfo.lng[2] = (lng>>8)&0xff;
+    carFormationInfo.lng[3] = (lng)&0xff;
+
+    carFormationInfo.lat[0] = (lat>>24)&0xff;
+    carFormationInfo.lat[1] = (lat>>16)&0xff;
+    carFormationInfo.lat[2] = (lat>>8)&0xff;
+    carFormationInfo.lat[3] = (lat)&0xff;
+    int ispeed;
+    ispeed = int(m_structMGpsImu.speed);
+    unsigned char speed=(ispeed)&0xff;
+    carFormationInfo.speed = speed;
+    int yaw=int(m_structMGpsImu.yaw);
+    carFormationInfo.yaw[0] = (yaw>>24)&0xff;
+    carFormationInfo.yaw[1] = (yaw>>16)&0xff;
+    carFormationInfo.yaw[2] = (yaw>>8)&0xff;
+    carFormationInfo.yaw[3] = (yaw)&0xff;
+    float fele=m_structMControl.eleVoltage*100.0;
+    int iele = int(fele);
+    unsigned char electrical=(iele)&0xff;
+    carFormationInfo.electricalVoltage=electrical;
+    float faccx=m_structMGpsImu.accx*10.0;
+    int iaccx=int(faccx);
+    carFormationInfo.acc_x=(iaccx)&0xff;
+    float faccy=m_structMGpsImu.accy*10.0;
+    int iaccy=int(faccy);
+    carFormationInfo.acc_y=(iaccy)&0xff;
+    unsigned char error=m_structMControl.error;
+    carFormationInfo.error=error;
+    int dataLen = sizeof(upVehicleBaseInfo )/sizeof(unsigned char);
+    int headLen = PackagetHeadInfo(0x00,VehicleBaseInfo,comment,dataLen);//jiaolili,featureID need clear
+    memcpy(sendBuf,&packageDataHead,headLen);
+    memcpy(sendBuf+headLen,&carFormationInfo,dataLen);
+    sendBuf[headLen+dataLen] = BCCEncode(sendBuf,headLen+dataLen);
+    m_serialPort_Radio->write(sendBuf,headLen+dataLen+1);
+    m_serialPort_Radio->flush();
+    //m_serialPort_Radio->write("sendBuf");
+}
+void Radio::upVirtualVehicle(virtualVehicleM virtualVehicle)
+{
+    m_iVirtualVehicle=-1;
+    m_structMVirtualVehicle=virtualVehicle;
+    upVirtualVehicleRaw();
+}
+void Radio::upVirtualVehicleRaw()
+{
+    char sendBuf[100];
+    memset(sendBuf,0,100);
+    upVirtualVehicleInfo virtualVehicleInfo;
+    std::string vin=m_structMVirtualVehicle.vin;
+    vin.copy(virtualVehicleInfo.vin, 17, 0);
+
+    float flng,flat;
+    flng = (m_structMVirtualVehicle.gps_lng*1000000);
+    flat = (m_structMVirtualVehicle.gps_lat*1000000);
+    int lng,lat;
+    lng=int(flng);
+    lat=int(flat);
+    virtualVehicleInfo.lng[0] = (lng>>24)&0xff;
+    virtualVehicleInfo.lng[1] = (lng>>16)&0xff;
+    virtualVehicleInfo.lng[2] = (lng>>8)&0xff;
+    virtualVehicleInfo.lng[3] = (lng)&0xff;
+
+    virtualVehicleInfo.lat[0] = (lat>>24)&0xff;
+    virtualVehicleInfo.lat[1] = (lat>>16)&0xff;
+    virtualVehicleInfo.lat[2] = (lat>>8)&0xff;
+    virtualVehicleInfo.lat[3] = (lat)&0xff;
+    int ispeed;
+    ispeed = int(m_structMVirtualVehicle.speed);
+    unsigned char speed=(ispeed)&0xff;
+    virtualVehicleInfo.speed = speed;
+    int yaw=int(m_structMVirtualVehicle.yaw);
+    virtualVehicleInfo.yaw[0] = (yaw>>24)&0xff;
+    virtualVehicleInfo.yaw[1] = (yaw>>16)&0xff;
+    virtualVehicleInfo.yaw[2] = (yaw>>8)&0xff;
+    virtualVehicleInfo.yaw[3] = (yaw)&0xff;
+
+    int dataLen = sizeof(upVirtualVehicleInfo)/sizeof(unsigned char);
+    int headLen = PackagetHeadInfo(0x00,VirtualVehicle,comment,dataLen);//jiaolili,featureID need clear
+    memcpy(sendBuf,&packageDataHead,headLen);
+    memcpy(sendBuf+headLen,&virtualVehicleInfo,dataLen);
+    sendBuf[headLen+dataLen] = BCCEncode(sendBuf,headLen+dataLen);
+    m_serialPort_Radio->write(sendBuf,headLen+dataLen+1);
+    m_serialPort_Radio->flush();
+    //m_serialPort_Radio->write("sendBuf");
+}
+void Radio::upRespondMessage()
+{
+    m_iResponse=-1;
+    upRespondMessageRaw();
+}
+void Radio::upRespondMessageRaw()
+{
+    char sendBuf[100];
+    memset(sendBuf,0,100);
+    upResponseInfo responseInfo;
+    std::string vin=m_sVin;
+    vin.copy(responseInfo.vin, vin.length(), 0);
+    responseInfo.reponseType = m_responseType;
+    int dataLen = sizeof(upResponseInfo)/sizeof(unsigned char);
+    int headLen = PackagetHeadInfo(0x00,ResponseMessage,comment,dataLen);//jiaolili,featureID need clear
+    memcpy(sendBuf,&packageDataHead,headLen);
+    memcpy(sendBuf+headLen,&responseInfo,dataLen);
+    sendBuf[headLen+dataLen] = BCCEncode(sendBuf,headLen+dataLen);
+    m_serialPort_Radio->write(sendBuf,headLen+dataLen+1);
+    m_serialPort_Radio->flush();
+    //m_serialPort_Radio->write("sendBuf");
+}
+int Radio::PackagetHeadInfo( unsigned char featureID,unsigned char commendID, unsigned char respondID,int dataLen)
+{
+    packageDataHead.startSymbol1 = '$';
+    packageDataHead.startSymbol2 = '$';
+    packageDataHead.driveTestSysSymbol[0]=0xFF;//jiaolili,need clear when testing
+    packageDataHead.driveTestSysSymbol[1]=0xFF;//jiaolili,need clear when testing
+    packageDataHead.featureSymbol = featureID;
+    packageDataHead.commentSymbol  = commendID;
+    packageDataHead.responseSymbol = respondID;
+    packageDataHead.encryptionType = 0x01;
+    //秒级时间戳(十位)
+    long timestamp = QDateTime::currentMSecsSinceEpoch() / 1000;
+    packageDataHead.timeStamp[0]=(timestamp>>56)&0xff;
+    packageDataHead.timeStamp[1]=(timestamp>>48)&0xff;
+    packageDataHead.timeStamp[2]=(timestamp>>40)&0xff;
+    packageDataHead.timeStamp[3]=(timestamp>>32)&0xff;
+    packageDataHead.timeStamp[4]=(timestamp>>24)&0xff;
+    packageDataHead.timeStamp[5]=(timestamp>>16)&0xff;
+    packageDataHead.timeStamp[6]=(timestamp>>8)&0xff;
+    packageDataHead.timeStamp[7]=(timestamp)&0xff;
+    packageDataHead.dataLength[0] = (dataLen >> 8) & 0xFF;
+    packageDataHead.dataLength[1] = dataLen & 0xFF;
+    int headLen = sizeof(packageDataHead)/sizeof(unsigned char);
+    return headLen;
+}
+void Radio::receiveData()
+{
+    qint64 rLen = m_serialPort_Radio->bytesAvailable();
+    qDebug() << "rLen:"<<rLen;
+    if (rLen <= 0) {
+        return;
+    }
+    char *_data = new char[rLen + 1];
+    if (_data == NULL) {
+        return;
+    }
+    memset(_data, 0, rLen + 1);
+    //socket_mutex.lock();
+    int ret = m_serialPort_Radio->read(_data, rLen);
+    //socket_mutex.unlock();
+    if(ret <= 0)
+    {
+        qDebug() << "read error";
+        return;
+    }
+    QByteArray data(_data, ret);
+
+    delete [] _data;
+    // 数据拆开
+    ReceiveDecode(data);
+    replyMessage();
+}
+
+char Radio::BCCEncode(char sbuf[],int len)//计算校验
+{
+    if(sbuf == NULL || len < 4)
+        return false;
+    char BBCcode;
+    BBCcode = sbuf[2];
+    for (int i = 3; i < len; i++) {
+        BBCcode = BBCcode^sbuf[i];
+    }
+    return BBCcode;
+}
+bool Radio::BCCDecode(char sbuf[], int len)
+{
+    if(sbuf == NULL || len < 4)
+        return false;
+    char BBCcode;
+    BBCcode = sbuf[2];
+    for (int i = 3; i < len-1; i++) {
+        BBCcode = BBCcode^sbuf[i];
+    }
+    if (BBCcode == sbuf[len-1])
+        return true;
+    else
+        return false;
+}
+void Radio::replyMessage()
+{
+    //queue_mutex.lock();
+    if(readData.isEmpty())
+    {
+        //queue_mutex.unlock();
+        return;
+    }
+
+    QByteArray data = readData.dequeue();
+    //queue_mutex.unlock();
+
+    int len = data.size();
+
+    char *recvBuf = data.data();
+    if(len < 21 || recvBuf == NULL)
+    {
+        qDebug() << "len error";
+        return;
+    }
+
+    qDebug() <<"len:"<<len;
+    qDebug() <<"recvBuf: "<<recvBuf;
+
+    bool is_checkok = false;
+    is_checkok = BCCDecode(recvBuf,len);
+    if(is_checkok==false) {
+        qDebug() << "check error";
+        return;
+    } else {
+        qDebug() << "check ok";
+    }
+    switch(recvBuf[5]) {
+        case TrafficLight: {
+            lightMessage light;
+            light.lightType=recvBuf[18];
+            light.timeRemaining=(((recvBuf[19]<<8)&0xFF00)|((recvBuf[20])&0xFF));
+            outLight(light);
+            break;
+        }
+        case RealtimeTraffic: {        
+            realtimeTrafficMessage realtimeTraffic;
+            realtimeTraffic.lng=(((recvBuf[18]<<24)&0xFF000000)|((recvBuf[19]<<16)&0xFF0000)|((recvBuf[20]<<8)&0xFF00)|((recvBuf[21])&0xFF));
+            realtimeTraffic.lat=(((recvBuf[22]<<24)&0xFF000000)|((recvBuf[23]<<16)&0xFF0000)|((recvBuf[24]<<8)&0xFF00)|((recvBuf[25])&0xFF));
+            realtimeTraffic.scope=(((recvBuf[26]<<8)&0xFF00)|((recvBuf[27])&0xFF));
+            realtimeTraffic.trafficInfo=recvBuf[28];
+            realtimeTraffic.speedLimit=(recvBuf[29]&0xFF);
+            outRealtimeTraffic(realtimeTraffic);
+            break;
+        }
+        case CollisionEarlyWarning: {
+            collisionEarlyWarningMessage collisionWarning;
+            std::string *str;
+            memcpy(str, recvBuf+18, 17);
+            collisionWarning.isEnable=true;
+            collisionWarning.vin=*str;
+            collisionWarning.warningType=recvBuf[35];
+            collisionWarning.speedLimit=recvBuf[36];
+            if(collisionWarning.vin==m_sVin) {
+                outCollisionWarning(collisionWarning);
+                responseCollisionEarlyWarning(collisionWarning);
+                m_responseType=collisionWarning.warningType;
+                m_bEnUpRespond=true;
+                //upRespondMessage();
+            } else {
+                qDebug()<<"[CollisionEarlyWarning] vin error"<<endl;
+            }
+            break;
+        }
+        case CongestionIdentification: {
+            congestionIdentificationMessage congestionIdenti;
+            std::string *str;
+            memcpy(str, recvBuf+18, 17);
+            congestionIdenti.isEnable=true;
+            congestionIdenti.vin=*str;
+            congestionIdenti.openCommand=recvBuf[35];
+            if(congestionIdenti.vin==m_sVin) {
+                responseCongestionIdentification(congestionIdenti);
+                outCongestionIdenti(congestionIdenti);
+            } else {
+                qDebug()<<"[CongestionIdentification] vin error"<<endl;
+            }
+            break;
+        }
+        case ResponseMessage: {
+            m_iResponse = -1;
+            break;
+        }
+        case VirtualVehicle: {
+            m_iVirtualVehicle = -1;
+            break;
+        }
+        default:
+            break;
+    }
+}
+void Radio::responseCollisionEarlyWarning(collisionEarlyWarningMessage collisionWarning)
+{
+    char sendBuf[100];
+    memset(sendBuf,0,100);
+    responseCollisionEarlyWarningInfo responseCollisionWarningInfo;
+    std::string vin=m_sVin;
+    vin.copy(responseCollisionWarningInfo.vin, vin.length(), 0);
+    responseCollisionWarningInfo.warningType = collisionWarning.warningType;
+    responseCollisionWarningInfo.speedLimit = (collisionWarning.speedLimit)&0xFF;
+    int dataLen = sizeof(responseCollisionEarlyWarningInfo)/sizeof(unsigned char);
+    int headLen = PackagetHeadInfo(0x00,CollisionEarlyWarning,resuccess,dataLen);//jiaolili,featureID need clear
+    memcpy(sendBuf,&packageDataHead,headLen);
+    memcpy(sendBuf+headLen,&responseCollisionWarningInfo,dataLen);
+    sendBuf[headLen+dataLen] = BCCEncode(sendBuf,headLen+dataLen);
+    m_serialPort_Radio->write(sendBuf,headLen+dataLen+1);
+    m_serialPort_Radio->flush();
+}
+void Radio::responseCongestionIdentification(congestionIdentificationMessage congestionIdenti)
+{
+
+    char sendBuf[100];
+    memset(sendBuf,0,100);
+    responseCongestionIdentificationInfo responseCongestionInfo;
+    std::string vin=m_sVin;
+    vin.copy(responseCongestionInfo.vin, vin.length(), 0);
+    responseCongestionInfo.openCommand = congestionIdenti.openCommand;
+
+    int dataLen = sizeof(responseCongestionIdentificationInfo)/sizeof(unsigned char);
+    int headLen = PackagetHeadInfo(0x00,CongestionIdentification,resuccess,dataLen);//jiaolili,featureID need clear
+    memcpy(sendBuf,&packageDataHead,headLen);
+    memcpy(sendBuf+headLen,&responseCongestionInfo,dataLen);
+    sendBuf[headLen+dataLen] = BCCEncode(sendBuf,headLen+dataLen);
+    m_serialPort_Radio->write(sendBuf,headLen+dataLen+1);
+    m_serialPort_Radio->flush();
+
+
+}
+void Radio::ReceiveDecode(QByteArray &data)
+{
+    static int BATH_LENTH = 21;
+    // 防包太大
+    if (data.size() > 2048) {
+        qDebug() << "size too large";
+        return;
+    }
+    //  ##
+    char first;
+    char second;
+    // 寻找报文开头
+    while (data.size() >= BATH_LENTH) {
+        while (1) {
+            first = data[0];
+            second = data[1];
+            if (first == '$' && second == '$') {
+                break;
+            }
+            // 删除一个字符
+            data.remove(0, 1);
+            if (data.size() < BATH_LENTH)
+                return;
+        }
+        int high = data.at(16);
+        int low = data.at(17);
+        int dataLen = (high << 8) | low;
+        qDebug() << "dataLen:" << dataLen;
+        // 长度不对
+        if ((dataLen + sizeof(packageDataHead)) > data.size()) {
+            qDebug() << "message len error";
+            return;
+        }
+        QByteArray temp = data.left(sizeof(packageDataHead) + dataLen + 1);
+        //queue_mutex.lock();
+        readData.enqueue(temp);
+        //queue_mutex.unlock();
+        data.remove(0, sizeof(packageDataHead) + dataLen + 1);//need check,20210915,jiaolili
+    }
+}
+

+ 175 - 0
src/v2x/CommunicatePlatform/radio.h

@@ -0,0 +1,175 @@
+#ifndef RADIO_H
+#define RADIO_H
+#include <QSerialPort>
+#include <QTimer>
+#include <QQueue>
+#include <QDebug>
+#include <QDateTime>
+#define TrafficLight (0x01)
+#define RealtimeTraffic (0x02)
+#define CollisionEarlyWarning (0x03)
+#define CongestionIdentification (0x04)
+#define VehicleBaseInfo (0x80)
+#define ResponseMessage (0x81)
+#define VirtualVehicle (0x82)
+#define comment (0xFE)//命令
+#define resuccess (0x01)//成功
+#define reerror (0x02)//错误
+struct virtualVehicleM
+{
+    std::string vin;
+    double gps_lng;//real value
+    double gps_lat;
+    float speed;//real value
+    float yaw;//real value
+};
+struct gpsImuM
+{
+    float gps_lng;//real value
+    float gps_lat;
+    float speed;//real value
+    float yaw;//real value
+    float accx;//real value
+    float accy;
+};
+struct controlM
+{
+    float eleVoltage;//100%=1.00
+    unsigned char error;//0x01 error 0x02 normal
+};
+struct realtimeTrafficMessage
+{
+    int lng;
+    int lat;
+    int scope;
+    unsigned char trafficInfo;//0x01:塌方;0x02:施工;0x03:道路结冰;0x04:前方限速;“0xFE”表示异常,“0xFF”表示无效
+    int speedLimit;
+};
+struct collisionEarlyWarningMessage
+{
+    bool isEnable;
+    std::string vin;
+    unsigned char warningType;//0x01:减速;0x02:停车;“0xFE”表示异常,“0xFF”表示无效
+    int speedLimit;
+};
+struct congestionIdentificationMessage
+{
+    bool isEnable;
+    std::string vin;
+    unsigned char openCommand;//0x01:开启;“0xFE”表示异常,“0xFF”表示无效
+};
+struct lightMessage
+{
+    unsigned char lightType;//0x01:绿灯;0x02:红灯;0x03:黄灯;
+    int timeRemaining;
+};
+struct responseCollisionEarlyWarningInfo
+{
+    char vin[17];//车辆识别码
+    unsigned char warningType;
+    unsigned char speedLimit;
+};
+struct responseCongestionIdentificationInfo
+{
+    char vin[17];//车辆识别码
+    unsigned char openCommand;
+};
+struct upVehicleBaseInfo
+{
+    char vin[17];//车辆识别码
+    unsigned char vehicleType;//0x01:轿车;0x02:货车;0x03:客车;0x04:挂车;0x05:摩托车;“0xFE”表示异常,“0xFF”表示无效
+    unsigned char lng[4];//*1000000
+    unsigned char lat[4];
+    unsigned char speed;
+    unsigned char yaw[4];
+    unsigned char electricalVoltage;
+    unsigned char acc_x;//-6.0~6.0(表示0m/s2~4m/s2),最小计量单元:0.1 m/s2;
+    unsigned char acc_y;
+    unsigned char error;
+};
+struct  upVirtualVehicleInfo
+{
+    char vin[17];//车辆识别码
+    unsigned char lng[4];//*1000000
+    unsigned char lat[4];
+    unsigned char speed;
+    unsigned char yaw[4];
+};
+struct upResponseInfo
+{
+    char vin[17];//车辆识别码
+    unsigned char reponseType;//0x01:减速;0x02:停车;“0xFE”表示异常,“0xFF”表示无效
+};
+struct radioDataPackageHead//数据包结构
+{
+    unsigned char startSymbol1;//起始符1
+    unsigned char startSymbol2;//起始符2
+    unsigned char driveTestSysSymbol[2];//路测系统编码
+    unsigned char featureSymbol;//功能识别码
+    unsigned char commentSymbol;//命令标识
+    unsigned char responseSymbol;//应答标识
+    unsigned char encryptionType;//数据加密方式
+    unsigned char timeStamp[8];//时间戳
+    char dataLength[2];//数据单元长度
+    // unsigned char *data;//数据单元
+    // unsigned char verifyCode;//校验码
+};
+class Radio:public QObject
+{
+Q_OBJECT
+public:
+    Radio();
+    ~Radio();
+    void serialPortInit();   
+    void openSerial();
+    void closeSerial();
+    void upDataStream();
+    void upVirtualVehicle(virtualVehicleM virtualVehicle);
+    void upRespondMessage();
+
+    void responseCollisionEarlyWarning(collisionEarlyWarningMessage collisionWarning);
+    void responseCongestionIdentification(congestionIdentificationMessage congestionIdenti);
+    char BCCEncode(char sbuf[],int len);//计算校验
+    bool BCCDecode(char sbuf[], int len);
+    int PackagetHeadInfo( unsigned char featureID,unsigned char commendID, unsigned char respondID,int dataLen);
+    void ReceiveDecode(QByteArray &data);
+    void replyMessage();
+    void setVin(std::string vin);
+    void getTrafficBroadcast(bool en);
+    void getCollisonWarning(bool en);
+    void getBusyRoad(bool en);
+    void getDangerDrive(bool en);
+    void outLight(lightMessage light);
+    void outRealtimeTraffic(realtimeTrafficMessage realtimeTraffic);
+    void outCollisionWarning(collisionEarlyWarningMessage collisionWarning);
+    void outCongestionIdenti(congestionIdentificationMessage congestionIdenti);
+    void setEnConnect(bool en);
+private:
+    QSerialPort *m_serialPort_Radio;
+    bool m_bSerialOpen;
+    QTimer *timer;
+    bool m_bEnConnect;
+    QQueue<QByteArray> readData;
+    radioDataPackageHead packageDataHead;
+    int m_iResponse;
+    int m_iVirtualVehicle;
+    std::string m_sVin;
+    gpsImuM m_structMGpsImu;
+    controlM m_structMControl;
+    virtualVehicleM m_structMVirtualVehicle;
+    unsigned char m_responseType;
+    bool m_bEnTrafficBroadcast;
+    bool m_bEnCollisionWarning;
+    bool m_bEnBusyRoad;
+    bool m_bEnDangerDrive;
+    bool m_bEnUpRespond;
+private slots:
+    void receiveData();
+    void heartBeat();
+private:
+    void upVirtualVehicleRaw();
+    void upRespondMessageRaw();
+
+};
+
+#endif // RADIO_H

+ 323 - 0
src/v2x/CommunicatePlatform/tbox.cpp

@@ -0,0 +1,323 @@
+#include "tbox.h"
+#include "common.h"
+Tbox::Tbox()
+{
+    server=new QTcpServer(this);
+    connect(server,SIGNAL(newConnection()),this,SLOT(newConnectionSlot()));
+    timer = new QTimer(this);
+    connect(timer,SIGNAL(timeout()),SLOT(heartBeat()));
+    timer->start(1000);
+    m_bEnablePlatform = false;
+    m_bIsConnect = false;
+    m_iVinChange = -1;
+    //m_bEnConnect=false;
+    m_bEnConnect=false;
+    m_strVin=VIN;
+}
+void Tbox::heartBeat()
+{
+    qDebug()<<"消息:Into hearbeat!"<<endl;
+    if(m_bEnConnect) {
+        if(!m_bEnablePlatform) {
+            connectPlatform();
+        }
+        if(m_bIsConnect) {
+            upDataStream();
+        }
+        //if no answer,shake hands three times
+        if(m_iVinChange!=-1) {
+            m_iVinChange++;
+            if((m_iVinChange==3)||(m_iVinChange==6)||(m_iVinChange==9)) {
+                upVinChangeDataRaw();
+            }
+            if(m_iVinChange>=9) {
+                m_iVinChange = -1;
+            }
+        }
+        ///////////////////////////////////////////////////////
+    } else {
+        if(m_bEnablePlatform) {
+            disconnectPlatform();
+        }
+    }
+    m_bEnablePlatform = m_bEnConnect;
+}
+void Tbox::replyMessage()
+{
+    //queue_mutex.lock();
+    if(readData.isEmpty())
+    {
+        //queue_mutex.unlock();
+        return;
+    }
+
+    QByteArray data = readData.dequeue();
+    //queue_mutex.unlock();
+
+    int len = data.size();
+
+    char *recvBuf = data.data();
+    if(len < 31 || recvBuf == NULL)
+    {
+        qDebug() << "len error";
+        return;
+    }
+
+    qDebug() <<"len:"<<len;
+    qDebug() <<"recvBuf: "<<recvBuf;
+
+    bool is_checkok = false;
+    is_checkok = BCCDecode(recvBuf,len);
+    if(is_checkok==false) {
+        qDebug() << "check error";
+    } else {
+        qDebug() << "check ok";
+    }
+    if(recvBuf[2]==0x0A) {
+    //232302fe4c4d574850315332374a31303035393035010017000000006142e3393b9aca0077359400140000000c63028c
+    //if(recvBuf[2]==0x02) {
+        m_iVinChange=-1;
+    }
+}
+
+void Tbox::ReceiveDecode(QByteArray &data)
+{
+    static int BATH_LENTH = 31;
+    // 防包太大
+    if (data.size() > 2048) {
+        qDebug() << "size too large";
+        return;
+    }
+    //  ##
+    char first;
+    char second;
+    // 寻找报文开头
+    while (data.size() >= BATH_LENTH) {
+        while (1) {
+            first = data[0];
+            second = data[1];
+            if (first == '#' && second == '#') {
+                break;
+            }
+            // 删除一个字符
+            data.remove(0, 1);
+            if (data.size() < BATH_LENTH)
+                return;
+        }
+        int high = data.at(22);
+        int low = data.at(23);
+        int dataLen = (high << 8) | low;
+        qDebug() << "dataLen:" << dataLen;
+        // 长度不对
+        if ((dataLen + sizeof(packageDataHead)) > data.size()) {
+            qDebug() << "message len error";
+            return;
+        }
+        QByteArray temp = data.left(sizeof(packageDataHead) + dataLen + 1);
+        //queue_mutex.lock();
+        readData.enqueue(temp);
+        //queue_mutex.unlock();
+        data.remove(0, sizeof(packageDataHead) + dataLen + 1);//need check,20210915,jiaolili
+    }
+}
+void Tbox::upVinChangeDataRaw()
+{    
+    char sendBuf[100];
+    memset(sendBuf,0,100);
+    CarVinChangeData carVinChangeInfo;
+    //秒级时间戳(十位)
+    long timestamp = QDateTime::currentMSecsSinceEpoch() / 1000;
+    qDebug()<<timestamp<<endl;
+    carVinChangeInfo.time[0]=(timestamp>>56)&0xff;
+    carVinChangeInfo.time[1]=(timestamp>>48)&0xff;
+    carVinChangeInfo.time[2]=(timestamp>>40)&0xff;
+    carVinChangeInfo.time[3]=(timestamp>>32)&0xff;
+    carVinChangeInfo.time[4]=(timestamp>>24)&0xff;
+    carVinChangeInfo.time[5]=(timestamp>>16)&0xff;
+    carVinChangeInfo.time[6]=(timestamp>>8)&0xff;
+    carVinChangeInfo.time[7]=(timestamp)&0xff;
+//    char vin[]="LMWHP1S27J1005905";//shared memory
+//    int nvinlen=strlen(vin);
+//    if(nvinlen > 17)
+//        nvinlen = 17;
+//    memcpy(carVinChangeInfo.vin, vin, nvinlen);
+    std::string vin=m_strVin;
+    vin.copy(carVinChangeInfo.vin, vin.length(), 0);
+    int dataLen = sizeof(CarVinChangeData)/sizeof(unsigned char);
+    int headLen = PackagetHeadInfo(CommentVinChange,dataLen);
+    memcpy(sendBuf,&packageDataHead,headLen);
+    memcpy(sendBuf+headLen,&carVinChangeInfo,dataLen);
+    sendBuf[headLen+dataLen] = BCCEncode(sendBuf,headLen+dataLen);
+    client->write(sendBuf,headLen+dataLen+1);
+    client->flush();
+}
+void Tbox::setTboxNewVin(std::string str)
+{
+    m_strVin=str;
+    if(m_bIsConnect) {
+        upVinChangeData();
+    }
+}
+void Tbox::upVinChangeData()
+{
+    upVinChangeDataRaw();
+    m_iVinChange=0;
+}
+void Tbox::upDataStream()
+{    
+    char sendBuf[100];
+    memset(sendBuf,0,100);
+    CarFormationInfoData carFormationInfo;
+    //秒级时间戳(十位)
+    long timestamp = QDateTime::currentMSecsSinceEpoch() / 1000;
+    qDebug()<<timestamp<<endl;
+    carFormationInfo.time[0]=(timestamp>>56)&0xff;
+    carFormationInfo.time[1]=(timestamp>>48)&0xff;
+    carFormationInfo.time[2]=(timestamp>>40)&0xff;
+    carFormationInfo.time[3]=(timestamp>>32)&0xff;
+    carFormationInfo.time[4]=(timestamp>>24)&0xff;
+    carFormationInfo.time[5]=(timestamp>>16)&0xff;
+    carFormationInfo.time[6]=(timestamp>>8)&0xff;
+    carFormationInfo.time[7]=(timestamp)&0xff;
+    float flng,flat;
+    flng = (m_structM.gps_lng*1000000);
+    flat = m_structM.gps_lat*1000000;
+    int lng,lat;
+    lng=int(flng);
+    lat=int(flat);
+    carFormationInfo.gps_lng[0] = (lng>>24)&0xff;
+    carFormationInfo.gps_lng[1] = (lng>>16)&0xff;
+    carFormationInfo.gps_lng[2] = (lng>>8)&0xff;
+    carFormationInfo.gps_lng[3] = (lng)&0xff;
+
+    carFormationInfo.gps_lat[0] = (lat>>24)&0xff;
+    carFormationInfo.gps_lat[1] = (lat>>16)&0xff;
+    carFormationInfo.gps_lat[2] = (lat>>8)&0xff;
+    carFormationInfo.gps_lat[3] = (lat)&0xff;
+    int ispeed;
+    ispeed = int(m_structM.speed);
+    unsigned char speed=(ispeed)&0xff;
+    carFormationInfo.car_speed = speed;
+    int yaw=int(m_structM.yaw);
+    carFormationInfo.car_yaw[0] = (yaw>>24)&0xff;
+    carFormationInfo.car_yaw[1] = (yaw>>16)&0xff;
+    carFormationInfo.car_yaw[2] = (yaw>>8)&0xff;
+    carFormationInfo.car_yaw[3] = (yaw)&0xff;
+    float fele=m_structM.ele_voltage*100.0;
+    int iele = int(fele);
+    unsigned char electrical=(iele)&0xff;
+    carFormationInfo.electrical_voltage=electrical;
+    unsigned char error=m_structM.error;
+    carFormationInfo.error=error;
+    int dataLen = sizeof(CarFormationInfoData)/sizeof(unsigned char);
+    int headLen = PackagetHeadInfo(CommentcarFormationInfo,dataLen);
+    memcpy(sendBuf,&packageDataHead,headLen);
+    memcpy(sendBuf+headLen,&carFormationInfo,dataLen);
+    sendBuf[headLen+dataLen] = BCCEncode(sendBuf,headLen+dataLen);
+    client->write(sendBuf,headLen+dataLen+1);
+    client->flush();
+}
+void Tbox::connectPlatform()
+{
+    server->listen(QHostAddress::Any,6666);
+}
+
+void Tbox::disconnectPlatform()
+{
+    server->close();
+    //修改status
+    m_bIsConnect=false;
+}
+int Tbox::PackagetHeadInfo( unsigned char commendID, int dataLen)
+{
+    packageDataHead.startSymbol1 = '#';
+    packageDataHead.startSymbol2 = '#';
+    packageDataHead.commentSymbol  = commendID;
+    packageDataHead.responseSymbol = comment;
+    std::string vin=m_strVin;
+    vin.copy(packageDataHead.vin, vin.length(), 0);
+    packageDataHead.encryptionType = 0x01;
+    packageDataHead.dataLength[0] = (dataLen >> 8) & 0xFF;
+    packageDataHead.dataLength[1] = dataLen & 0xFF;
+    int headLen = sizeof(packageDataHead)/sizeof(unsigned char);
+    return headLen;
+}
+char Tbox::BCCEncode(char sbuf[],int len)//计算校验
+{
+    if(sbuf == NULL || len < 4)
+        return false;
+    char BBCcode;
+    BBCcode = sbuf[2];
+    for (int i = 3; i < len; i++) {
+        BBCcode = BBCcode^sbuf[i];
+    }
+    return BBCcode;
+}
+bool Tbox::BCCDecode(char sbuf[], int len)
+{
+    if(sbuf == NULL || len < 4)
+        return false;
+    char BBCcode;
+    BBCcode = sbuf[2];
+    for (int i = 3; i < len-1; i++) {
+        BBCcode = BBCcode^sbuf[i];
+    }
+    if (BBCcode == sbuf[len-1])
+        return true;
+    else
+        return false;
+}
+void Tbox::setTboxConnectEnable(bool isEnable)
+{
+    m_bEnConnect = isEnable;
+}
+void Tbox::setTboxMemmory(Memory m)
+{
+    m_structM = m;
+}
+void Tbox::newConnectionSlot()
+{
+    qDebug()<<"new connection";
+    client=server->nextPendingConnection();
+    QString ip=client->peerAddress().toString().split("::ffff:")[1];
+    qDebug()<<ip<<" 连接成功\n"<<endl;
+    connect(client,&QTcpSocket::readyRead,this,&Tbox::readDataSlot);
+    connect(client,&QTcpSocket::disconnected,this,&Tbox::disconnectedSlot);
+    //修改status
+    m_bIsConnect = true;
+    qDebug()<<"连接成功\n"<<endl;
+
+}
+void Tbox::readDataSlot()
+{
+    qint64 rLen = client->bytesAvailable();
+    qDebug() << "rLen:"<<rLen;
+    if (rLen <= 0) {
+        return;
+    }
+    char *_data = new char[rLen + 1];
+    if (_data == NULL) {
+        return;
+    }
+    memset(_data, 0, rLen + 1);
+    //socket_mutex.lock();
+    int ret = client->read(_data, rLen);
+    //socket_mutex.unlock();
+    if(ret <= 0)
+    {
+        qDebug() << "read error";
+        return;
+    }
+    QByteArray data(_data, ret);
+
+    delete [] _data;
+    // 数据拆开
+    ReceiveDecode(data);
+    replyMessage();
+}
+void Tbox::disconnectedSlot()
+{
+    //修改status
+    m_bIsConnect = false;
+    qDebug()<<"client disconnected!\n"<<endl;
+}

+ 82 - 0
src/v2x/CommunicatePlatform/tbox.h

@@ -0,0 +1,82 @@
+#ifndef TBOX_H
+#define TBOX_H
+#include <QTcpSocket>
+#include <QTcpServer>
+#include <QTimer>
+#include <QDateTime>
+#include <QQueue>
+struct DataPackageHead//数据包结构
+{
+    unsigned char startSymbol1;//起始符1
+    unsigned char startSymbol2;//起始符2
+    unsigned char commentSymbol;//命令标识
+    unsigned char responseSymbol;//应答标识
+    char vin[17];//车辆识别码
+    unsigned char encryptionType;//数据加密方式
+    char dataLength[2];//数据单元长度
+    // unsigned char *data;//数据单元
+    // unsigned char verifyCode;//校验码
+};
+struct CarFormationInfoData  //车况数据
+{
+    unsigned char time[8];//本报文时间戳。格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。
+    unsigned char gps_lng[4];//经度 有效值范围:0~180;精确到小数点后6位;“0xFF,0xFF,0xFF,0xFE”表示异常,“0xFF,0xFF,0xFF,0xFF”表示无效
+    unsigned char gps_lat[4];//维度 有效值范围:0~180;精确到小数点后6位;“0xFF,0xFF,0xFF,0xFE”表示异常,“0xFF,0xFF,0xFF,0xFF”表示无效
+    unsigned char car_speed;//车速 有效值范围:0~200(表示0km/h~200km/h),最小计量单元:1km/h;“0xFE”表示异常,“0xFF”表示无效
+    unsigned char car_yaw[4];//航向角 有效值范围:0~360(表示0°~360°);“0xFF,0xFF,0xFF,0xFE”表示异常,“0xFF,0xFF,0xFF,0xFF”表示无效
+    unsigned char electrical_voltage;//电量 有效值范围:0~100(表示0%~100%),最小计量单元:1%;“0xFE”表示异常,“0xFF”表示无效
+    unsigned char error;//车辆故障状态 0x01:存在故障;0x02:不存在故障;“0xFE”表示异常,“0xFF”表示无效
+};
+struct CarVinChangeData  //车况数据
+{
+    unsigned char time[8];//本报文时间戳。格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。
+    char vin[17];//车辆识别码
+};
+struct Memory
+{
+    float gps_lng;
+    float gps_lat;
+    float speed;
+    float yaw;
+    float ele_voltage;
+    unsigned char error;
+};
+class Tbox:public QObject
+{
+    Q_OBJECT
+public:
+    Tbox();
+    void connectPlatform();
+    void disconnectPlatform();
+    void upDataStream();
+    void upVinChangeData();
+    void upVinChangeDataRaw();
+    int PackagetHeadInfo(unsigned char commendID, int dataLen);
+    char BCCEncode(char sbuf[],int len);//计算校验
+    bool BCCDecode(char sbuf[], int len);
+    void ReceiveDecode(QByteArray &data);
+    void replyMessage();
+    void setTboxConnectEnable(bool isEnable);
+    void setTboxMemmory(Memory m);
+    void setTboxNewVin(std::string str);
+    //void setTboxUpData();
+private:
+    QTcpServer *server;
+    QTcpSocket *client;
+    QTimer *timer;
+    bool m_bIsConnect;
+    bool m_bEnablePlatform;
+    DataPackageHead packageDataHead;
+    int m_iVinChange;
+    QQueue<QByteArray> readData;
+    bool m_bEnConnect;
+    std::string m_strVin;
+    Memory m_structM;
+private slots:    
+    void heartBeat();
+    void newConnectionSlot();
+    void readDataSlot();
+    void disconnectedSlot();
+};
+
+#endif // TBOX_H