فهرست منبع

Modify obu function

sunjiacheng 2 سال پیش
والد
کامیت
0e2715959a
4فایلهای تغییر یافته به همراه186 افزوده شده و 4 حذف شده
  1. 19 1
      src/include/proto/vbox.proto
  2. 14 0
      src/v2x/obuUdpClient/obuUdpClient.pro
  3. 147 3
      src/v2x/obuUdpClient/udpreciver.cpp
  4. 6 0
      src/v2x/obuUdpClient/udpreciver.h

+ 19 - 1
src/include/proto/vbox.proto

@@ -2,7 +2,7 @@ syntax = "proto2";
 
 package iv.vbox;
 
-message vbox
+message vbox_light
 {
 	required uint32 st_straight	= 1;
 	required uint32 st_left 	= 2;
@@ -14,4 +14,22 @@ message vbox
 	required uint32 time_turn 	= 8;
 };
 
+message vbox_obj_arr
+{
+	repeated vbox_obj obj = 1;
+}
+
+message vbox_obj
+{
+	required string id 	= 1;
+	required int32	objType = 2;
+	required double	vehL	= 3;
+	required double	vehW	= 4;
+	required double	vehH	= 5;
+	required double	lon	= 6;
+	required double	lat	= 7;
+	required double	ele	= 8;
+	required double	speed	= 9;
+	required double	heading = 10;
 
+}

+ 14 - 0
src/v2x/obuUdpClient/obuUdpClient.pro

@@ -16,8 +16,22 @@ DEFINES += QT_DEPRECATED_WARNINGS
 
 SOURCES += main.cpp \
     udpsender.cpp \
+    ../../include/msgtype/vbox.pb.cc \
     udpreciver.cpp
 
 HEADERS += \
+    ../../include/msgtype/vbox.pb.h \
     udpsender.h \
     udpreciver.h
+
+!include(../../../include/common.pri ) {
+    error( "Couldn't find the common.pri file!" )
+}
+
+!include(../../../include/ivprotobuf.pri ) {
+    error( "Couldn't find the ivprotobuf.pri file!" )
+}
+
+!include(../../../include/ivboost.pri ) {
+    error( "Couldn't find the ivboost.pri file!" )
+}

+ 147 - 3
src/v2x/obuUdpClient/udpreciver.cpp

@@ -1,10 +1,92 @@
 #include "udpreciver.h"
+#include "vbox.pb.h"
+
+iv::vbox::vbox_light gobjl;
+iv::vbox::vbox_obj_arr gobja;
+
+void * gpLight , * gpObj;
+
+void UdpReciver::ShareResultLights()
+{
+    lightLock.lock();
+    char * str = new char[gobja.ByteSize()];
+    int nsize = gobja.ByteSize();
+    if(gobja.SerializeToArray(str,nsize))
+    {
+        iv::modulecomm::ModuleSendMsg(gpObj,str,nsize);
+    }
+    gobjl.Clear();
+    lightLock.unlock();
+    delete[] str;
+    str = nullptr;
+}
+
+void UdpReciver::ShareResultObs()
+{
+    obsLock.lock();
+    char * str = new char[gobjl.ByteSize()];
+    int nsize = gobjl.ByteSize();
+    if(gobjl.SerializeToArray(str,nsize))
+    {
+        iv::modulecomm::ModuleSendMsg(gpLight,str,nsize);
+    }
+    gobja.Clear();
+    obsLock.unlock();
+
+    delete[] str;
+    str = nullptr;
+}
 
 UdpReciver::UdpReciver(QObject *parent, QString localhost, int port) : QObject(parent)
 {
     m_thread = new QThread();
     m_udpSocket = new QUdpSocket();
     //    localhost = "";
+
+    iv::vbox::vbox_light x;
+    x.set_st_straight(0);
+    x.set_st_left(0);
+    x.set_st_right(0);
+    x.set_st_turn(0);
+    x.set_time_straight(0);
+    x.set_time_left(0);
+    x.set_time_right(0);
+    x.set_time_turn(0);
+
+
+    gobjl.CopyFrom(x);
+
+    iv::vbox::vbox_obj_arr y;
+    iv::vbox::vbox_obj *obj;
+    obj = y.add_obj();
+    obj->set_allocated_id("");
+    obj->set_objtype(4);
+    obj->set_vehh(0);
+    obj->set_vehw(0);
+    obj->set_vehl(0);
+    obj->set_lon(0);
+    obj->set_lat(0);
+    obj->set_ele(0);
+    obj->set_speed(0);
+    obj->set_heading(0);
+    gobja.CopyFrom(y);
+
+    QString strpath = QCoreApplication::applicationDirPath();
+    if(argc < 2)
+        strpath = strpath + "/obuUdpClient.xml";
+    else
+        strpath = argv[1];
+    std::cout<<strpath.toStdString()<<std::endl;
+
+    iv::xmlparam::Xmlparam xp(strpath.toStdString());
+
+    std::string strmemsend_obj = xp.GetParam("vboxObj","vobxObj");
+    std::string strmemvbox_light = xp.GetParam("vboxLight","vboxLight");
+    std::string strmodulename = xp.GetParam("modulename","vbox_gaohong_net");
+
+    gpLight = iv::modulecomm::RegisterSend(strmemvbox_light.data(),100000,3);
+    gpObj = iv::modulecomm::RegisterSend(strmemsend_obj.data(),100000,1);
+
     init_port(localhost, port);
     connect(m_udpSocket, SIGNAL(readyRead()), this, SLOT(readDatagrams()), Qt::DirectConnection);
     this->moveToThread(m_thread);
@@ -43,6 +125,12 @@ void UdpReciver::readDatagrams()
 void UdpReciver::ReceiveDecode(QByteArray &data)
 {
     static int BATH_LENTH = 10;
+
+    iv::vbox::vbox_light objl;
+    iv::vbox::vbox_obj_arr obja;
+    iv::vbox::vbox_obj *obj;
+
+
     // 防包太大
     if (data.size() > 2048) {
         //qDebug() << "size too large";
@@ -75,35 +163,76 @@ void UdpReciver::ReceiveDecode(QByteArray &data)
             QJsonObject object = QJsonDocument::fromJson(jsonData).object();
 
             if(object.contains("LightsStates"))
+            {
                 int lightState = object.value("LightsStates");
+            }
 
-            if (object.contains("LightsInfo")) {
+            if (object.contains("LightsInfo"))
+            {
                 QJsonArray array = object.value("LightsInfo").toArray();
                 int size = array.size();
                 qDebug("lightsInfo size %d", size);
                 for(int i = 0; i < size; i++){
                     qDebug() << array.at(0).toString();
                     QJsonObject lightInfo = array.at(0).toObject();
-
+                    int lightFuncValue = 0;
                     if(lightInfo.contains("function"))
                     {
-                        int lightFuncValue = lightInfo.value("function");
+                        lightFuncValue = lightInfo.value("function");
                         qDebug("light fuction value: %d", lightFuncValue);
                     }
 
                     if(lightInfo.contains("LightsColor"))
                     {
                         int lightColorValue = lightInfo.value("LightsColor");
+                        switch (lightFuncValue)
+                        {
+                        case 1:
+                            objl.set_st_right(lightColorValue);
+                            break;
+                        case 2:
+                            objl.set_st_straight(lightColorValue);
+                            break;
+                        case 3:
+                            objl.set_st_turn(lightColorValue);
+                            break;
+                        case 4:
+                            objl.set_st_left(lightColorValue);
+                            break;
+                        default:
+                            break;
+                        }
                         qDebug("light Color value: %d", lightColorValue);
                     }
 
                     if(lightInfo.contains("RemainingTime"))
                     {
                         int lightRemTimeValue = lightInfo.value("RemainingTime");
+                        switch (lightFuncValue)
+                        {
+                        case 1:
+                            objl.set_time_right(lightRemTimeValue);
+                            break;
+                        case 2:
+                            objl.set_time_straight(lightRemTimeValue);
+                            break;
+                        case 3:
+                            objl.set_time_turn(lightRemTimeValue);
+                            break;
+                        case 4:
+                            objl.set_time_left(lightRemTimeValue);
+                            break;
+                        default:
+                            break;
+                        }
                         qDebug("light Remaining Time:%d", lightRemTimeValue);
                     }
 
                 }
+                lightLock.lock();
+                gobjl.CopyFrom(objl);
+                lightLock.unlock();
+                ShareResultLights();
             }
 
         }
@@ -121,6 +250,7 @@ void UdpReciver::ReceiveDecode(QByteArray &data)
                     qDebug() << array.at(0).toString();
                     QJsonObject obsObj = array.at(0).toObject();
 
+                    obj = obja.add_obj();
                     if(obsObj.contains("ID"))
                     {
                         string objID = obsObj.value("ID");
@@ -130,56 +260,70 @@ void UdpReciver::ReceiveDecode(QByteArray &data)
                     if(obsObj.contains("PtcType"))
                     {
                         int ptcType = obsObj.value("PtcType");
+                        obj->set_objtype(4);
                         qDebug("obs type value: %d", ptcType);
                     }
 
                     if(obsObj.contains("VehL"))
                     {
                         double dVehL = obsObj.value("VehL");
+                        obj->set_vehl(0);
                         qDebug("obs VehL :%f", dVehL);
                     }
                     if(obsObj.contains("VehW"))
                     {
                         double dVehW = obsObj.value("VehW");
+                        obj->set_vehw(0);
                         qDebug("obs VehW :%f", dVehW);
                     }
                     if(obsObj.contains("VehH"))
                     {
                         double dVehH = obsObj.value("VehH");
+                        obj->set_vehh(0);
                         qDebug("obs VehH :%f", dVehH);
                     }
 
                     if(obsObj.contains("PtcLon"))
                     {
                         double dPtcLon = obsObj.value("PtcLon");
+                        obj->set_lon(0);
                         qDebug("obs PtcLon :%f", dPtcLon);
                     }
 
                     if(obsObj.contains("PtcLat"))
                     {
                         double dPtcLat = obsObj.value("PtcLat");
+                        obj->set_lat(0);
                         qDebug("obs Ptc :%f", dPtcLat);
                     }
 
                     if(obsObj.contains("PtcEle"))
                     {
                         double dPtcEle = obsObj.value("PtcEle");
+                        obj->set_ele(0);
                         qDebug("obs PtcEle :%f", dPtcEle);
                     }
 
                     if(obsObj.contains("PtcSpeed"))
                     {
                         double dPtcSpeed = obsObj.value("PtcSpeed");
+                        obj->set_speed(0);
                         qDebug("obs PtcSpeed :%f", dPtcSpeed);
                     }
 
                     if(obsObj.contains("PtcHeading"))
                     {
                         double dPtcHeading = obsObj.value("PtcHeading");
+                        obj->set_heading(0);
                         qDebug("obs PtcHeading :%f", dPtcHeading);
                     }
 
                 }
+
+                obsLock.lock();
+                gobja.CopyFrom(obja);
+                obsLock.unlock();
+                ShareResultObs();
             }
 
         }

+ 6 - 0
src/v2x/obuUdpClient/udpreciver.h

@@ -5,6 +5,8 @@
 #include <QFile>
 #include <QJsonDocument>
 #include <QThread>
+#include <QMutex>
+
 class UdpReciver : public QObject
 {
     Q_OBJECT
@@ -22,7 +24,11 @@ private:
     int m_port;
     QByteArray m_data;
     QThread *m_thread;
+    QMutex lightLock;
+    QMutex obsLock;
     void ReceiveDecode(QByteArray &data);
+    void ShareResultLights();
+    void ShareResultObs();
 };