浏览代码

change proto

jiaolili 3 年之前
父节点
当前提交
73e472b41e

+ 9 - 9
src/include/proto/v2r.proto

@@ -2,17 +2,17 @@ syntax = "proto2";
 
 package iv.v2r;
 
-message v2r
+message v2r_send
 {
-	optional int32 radioLightType   = 1;//红绿灯类型
-	optional int32 radioLightRemain	= 2;//当前灯剩余时间
+	optional int32 radioLightType   = 1;//红绿灯类型 1:绿灯 2:红灯 3:黄灯 254:异常 255:无效
+	optional int32 radioLightRemain	= 2;//当前灯剩余时间 单位:S
 	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;//拥堵识别开启指令	
+	optional int32	radioBroadcastRange	= 5;//实时路况广播辐射范围 有效范围1-1000,单位:M ,65534:异常 65535:无效
+	optional int32	radioBroadcastTrafficType	= 6;//实时路况广播交通状况类型 1:塌方 2:施工 3:道路结冰 4: 前方限速 254:异常 255:无效
+	optional int32	radioBroadcastSpeedLimit	= 7;//实时路况广播限速值 有效范围1-120,单位:KM/H 254:异常 255:无效
+	optional int32	radioWarningType	= 8;//碰撞预警类型 1:减速 2:停车 254:异常 255:无效
+	optional int32	radioWarningSpeedLimit	= 9;//碰撞预警限速值 有效范围1-120,单位:KM/H 254:异常 255:无效
+	optional int32	radioIdentiStart= 10;//拥堵识别开启指令	1:开启 254:异常 255:无效
 };
 

+ 18 - 5
src/v2x/CommunicatePlatform/CommunicatePlatform.pro

@@ -22,20 +22,33 @@ DEFINES += QT_DEPRECATED_WARNINGS
 # 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
+INCLUDEPATH += $$PWD/../../../include/
+LIBS += -L$$PWD/../../../bin/ -lxmlparam -lmodulecomm -livlog -livfault -lprotobuf
+
+INCLUDEPATH += $$PWD/../../include/msgtype
 
 CONFIG += c++11
 
+
 SOURCES += \
         main.cpp \
         mainwindow.cpp \
-    radio.cpp \
-    tbox.cpp
+        radio.cpp \
+        tbox.cpp \
+        ../../include/msgtype/v2r.pb.cc \
+        ../../include/msgtype/chassis.pb.cc \
+        ../../include/msgtype/gpsimu.pb.cc \
+        ../../include/msgtype/hmi.pb.cc
 
 HEADERS += \
         mainwindow.h \
-    common.h \
-    radio.h \
-    tbox.h
+        common.h \
+        radio.h \
+        tbox.h \
+        ../../include/msgtype/v2r.pb.h \
+        ../../include/msgtype/chassis.pb.h \
+        ../../include/msgtype/gpsimu.pb.h \
+        ../../include/msgtype/hmi.pb.h
 
 FORMS += \
         mainwindow.ui

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

@@ -12,6 +12,12 @@ MainWindow::MainWindow(QWidget *parent) :
     initUi();
     //enableTbox();
     initRadio();
+    //20211009,jiaolili
+    mivlog = new iv::Ivlog("v2x");
+    //ShareMem: gps
+    ModuleFun fungpsimu =std::bind(&MainWindow::UpdateGPSIMU,this,std::placeholders::_1, \
+                                   std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
+    mpMemGps = iv::modulecomm::RegisterRecvPlus("hcp2_gpsimu",fungpsimu);
 }
 
 MainWindow::~MainWindow()
@@ -204,3 +210,37 @@ void MainWindow::on_pushButton_radioConnect_clicked()
         ui->pushButton_radioConnect->setText("connect");
     }
 }
+//接收GPS数据
+void MainWindow::UpdateGPSIMU(const char * strdata,const unsigned int nSize,const unsigned int index,\
+                              const QDateTime * dt,const char * strmemname)
+{
+    double accX,accY,lat,lon,heading,rtk,ins,vd,ve,vn;
+    iv::gps::gpsimu  xgpsimu;
+    if(!xgpsimu.ParseFromArray(strdata,nSize))
+    {
+        mivlog->warn("ADCIntelligentVehicle::UpdateGPSIMU parse error. nSize is %d",nSize);
+        return;
+    }
+
+    lat = xgpsimu.lat();
+    lon = xgpsimu.lon();
+    heading = xgpsimu.heading();
+
+    rtk = xgpsimu.rtk_state();
+    ins = xgpsimu.ins_state();
+    vd = xgpsimu.vd();    //地向速度,单位(米/秒)
+    ve = xgpsimu.ve();    //东向速度,单位(米/秒)
+    vn = xgpsimu.vn();    //北向速度,单位(米/秒)
+    if(xgpsimu.has_acce_x())
+    {
+        accX = xgpsimu.acce_x();
+    }
+    if(xgpsimu.has_acce_y())
+    {
+        accY = xgpsimu.acce_y();
+    }
+//     mfAcc = (float)sqrt(pow(accX,2)+pow(accY,2));
+
+ //   mfspeed = sqrt(pow(data->vel_E,2)+pow(data->vel_N,2)) * 3.6;  //double pow(double x, double y) 返回 x 的 y 次幂,即 xy。
+    //mistGPS = 0;
+}

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

@@ -22,6 +22,10 @@ private:
     Memory m_structM;
     std::vector<int> m_vectorRandom;
     std::vector<std::string> m_vectorVin;
+    //20211009,jiaolili
+    void * mpMemGps;
+    iv::Ivlog *mivlog;
+    ///////////////////////////////
 public:
     void initTboxMemory();
     void enableTbox();
@@ -30,6 +34,8 @@ public:
     void initRadio();
     void getRandomNum();
     void setEnRadio(bool en);
+    void UpdateGPSIMU(const char * strdata,const unsigned int nSize,const unsigned int index,\
+                                  const QDateTime * dt,const char * strmemname);
 private slots:
     void on_pushButton_connect_clicked();
     void on_pushButton_vinChange_clicked(); 

+ 44 - 10
src/v2x/CommunicatePlatform/radio.cpp

@@ -15,6 +15,11 @@ Radio::Radio()
     m_bEnBusyRoad=false;
     m_bEnDangerDrive=false;
     m_bEnUpRespond=false;
+    //20211009,jiaolili
+    mivlog = new iv::Ivlog("v2r");
+    //shareMem:send
+    mpmem_radio_send_addr = iv::modulecomm::RegisterSend("v2r_send",100,1);
+    /////////////////////////////
 }
 Radio::~Radio()
 {
@@ -52,32 +57,61 @@ void Radio::getDangerDrive(bool en)
 void Radio::outLight(lightMessage light)
 {
     if(m_bEnBusyRoad|m_bEnCollisionWarning|m_bEnDangerDrive|m_bEnTrafficBroadcast) {
-    //protobuffer ui
+        iv::v2r::v2r_send protobuf;
+        protobuf.set_radiolighttype(light.lightType);
+        protobuf.set_radiolightremain(light.timeRemaining);
+        sendProto(protobuf);
     }
-    //protobuffer control
-}
 
+}
+void Radio::sendProto(iv::v2r::v2r_send radio_protobuf_send)
+{
+    char * strser;
+    bool bser;
+    int nbytesize;
+    nbytesize = radio_protobuf_send.ByteSize();
+    strser = new char[nbytesize];
+    bser = radio_protobuf_send.SerializeToArray(strser,nbytesize);
+    if(bser)
+        iv::modulecomm::ModuleSendMsg(mpmem_radio_send_addr,strser,nbytesize);
+    else
+    {
+        mivlog->error("sendData","[%s:] radio serialize error.",__func__);
+//        gfault->SetFaultState(1, 0, "radio serialize err");
+    }
+    delete strser;
+}
 void Radio::outRealtimeTraffic(realtimeTrafficMessage realtimeTraffic)
 {
     if(m_bEnTrafficBroadcast) {
-        //protobuffer ui
-    }
-    //protobuffer control
+        iv::v2r::v2r_send protobuf;
+        float lat=((float)realtimeTraffic.lat)/1000000.0;
+        float lon=((float)realtimeTraffic.lng)/1000000.0;
+        protobuf.set_radiobroadcastgpslat(lat);
+        protobuf.set_radiobroadcastgpslat(lon);
+        protobuf.set_radiobroadcastrange(realtimeTraffic.scope);
+        protobuf.set_radiobroadcasttraffictype(realtimeTraffic.trafficInfo);
+        protobuf.set_radiobroadcastspeedlimit(realtimeTraffic.speedLimit);
+        sendProto(protobuf);
+    }    
 }
 
 void Radio::outCollisionWarning(collisionEarlyWarningMessage collisionWarning)
 {
     if(m_bEnCollisionWarning) {
-        //protobuffer ui
+        iv::v2r::v2r_send protobuf;
+        protobuf.set_radiowarningtype(collisionWarning.warningType);
+        protobuf.set_radiowarningspeedlimit(collisionWarning.speedLimit);
+        sendProto(protobuf);
     }
-    //protobuffer control
-
 }
 
 void Radio::outCongestionIdenti(congestionIdentificationMessage congestionIdenti)
 {
     if(m_bEnBusyRoad) {
-        //protobuffer ui
+        iv::v2r::v2r_send protobuf;
+        protobuf.set_radioidentistart(congestionIdenti.openCommand);
+        sendProto(protobuf);
     }
 }
 

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

@@ -5,6 +5,13 @@
 #include <QQueue>
 #include <QDebug>
 #include <QDateTime>
+#include "v2r.pb.h"
+#include "chassis.pb.h"
+#include "gpsimu.pb.h"
+#include "hmi.pb.h"
+#include "modulecomm.h"
+#include "xmlparam.h"
+#include "ivlog.h"
 #define TrafficLight (0x01)
 #define RealtimeTraffic (0x02)
 #define CollisionEarlyWarning (0x03)
@@ -144,6 +151,7 @@ public:
     void outCollisionWarning(collisionEarlyWarningMessage collisionWarning);
     void outCongestionIdenti(congestionIdentificationMessage congestionIdenti);
     void setEnConnect(bool en);
+    void sendProto(iv::v2r::v2r_send radio_protobuf_send);
 private:
     QSerialPort *m_serialPort_Radio;
     bool m_bSerialOpen;
@@ -163,6 +171,11 @@ private:
     bool m_bEnBusyRoad;
     bool m_bEnDangerDrive;
     bool m_bEnUpRespond;
+    //test 20211009
+    //void * mpMemGps;
+    iv::Ivlog *mivlog;
+    void * mpmem_radio_send_addr = nullptr; //电台发送给brain数据地址
+    //////////
 private slots:
     void receiveData();
     void heartBeat();

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

@@ -76,6 +76,7 @@ void Tbox::replyMessage()
     if(recvBuf[2]==0x0A) {
     //232302fe4c4d574850315332374a31303035393035010017000000006142e3393b9aca0077359400140000000c63028c
     //if(recvBuf[2]==0x02) {
+        qDebug() << "receive vin change return";
         m_iVinChange=-1;
     }
 }