瀏覽代碼

fix(grpc_BS):change yaml file decoding methord

HAPO-9# 3 年之前
父節點
當前提交
90fc756f3f

+ 12 - 112
src/driver/driver_cloud_grpc_client_BS/main.cpp

@@ -1,17 +1,21 @@
 #include <QCoreApplication>
 #include <QCoreApplication>
 
 
-#include "ivversion.h"
+#include <QFile>
+#include <QString>
+#include <QStringList>
+#include <QMetaType>
 
 
 #include <yaml-cpp/yaml.h>
 #include <yaml-cpp/yaml.h>
+
 #include "vehicle_upload.h"
 #include "vehicle_upload.h"
 #include "vehicle_control.h"
 #include "vehicle_control.h"
 #include "vehicle_patrol.h"
 #include "vehicle_patrol.h"
+
+#include "ivversion.h"
 #include "modulecomm.h"
 #include "modulecomm.h"
 
 
-#include <QFile>
-#include <QString>
-#include <QStringList>
-#include <QMetaType>
+#ifndef IV_MSGUNIT
+#define IV_MSGUNIT
 
 
 namespace iv {
 namespace iv {
 struct msgunit
 struct msgunit
@@ -28,6 +32,8 @@ struct msgunit
 };
 };
 }
 }
 
 
+#endif
+
 uint8_t gShift_Status = 3; //3 p 4 r 5 n 6 d
 uint8_t gShift_Status = 3; //3 p 4 r 5 n 6 d
 uint8_t gCtrlMode_Status = 0; //0 auto 1 remote 2 stop 3 platform
 uint8_t gCtrlMode_Status = 0; //0 auto 1 remote 2 stop 3 platform
 
 
@@ -42,14 +48,7 @@ std::string gstruploadMapInterval = "1000";
 std::string gstrid = "1234567890123456789H";
 std::string gstrid = "1234567890123456789H";
 std::string gstrplateNumber = "津A123456";
 std::string gstrplateNumber = "津A123456";
 
 
-iv::msgunit shmPicFront;
-iv::msgunit shmPicRear;
-iv::msgunit shmPicLeft;
-iv::msgunit shmPicRight;
-iv::msgunit shmRemoteCtrl;
-iv::msgunit shmChassis;
-iv::msgunit shmGPSIMU;
-iv::msgunit shmPlatformFeedback;
+char stryamlpath[256];
 
 
 void dec_yaml(const char * stryamlpath)
 void dec_yaml(const char * stryamlpath)
 {
 {
@@ -114,104 +113,6 @@ void dec_yaml(const char * stryamlpath)
         gstrplateNumber = config["plateNumber"].as<std::string>();
         gstrplateNumber = config["plateNumber"].as<std::string>();
     }
     }
 
 
-    std::string strmsgname;
-
-    if(config["pic_front"])
-    {
-        if(config["pic_front"]["msgname"]&&config["pic_front"]["buffersize"]&&config["pic_front"]["buffercount"])
-        {
-            strmsgname = config["pic_front"]["msgname"].as<std::string>();
-            strncpy(shmPicFront.mstrmsgname,strmsgname.data(),255);
-            shmPicFront.mnBufferSize = config["pic_front"]["buffersize"].as<int>();
-            shmPicFront.mnBufferCount = config["pic_front"]["buffercount"].as<int>();
-//            std::cout << shmPicFront.mstrmsgname << shmPicFront.mnBufferSize << shmPicFront.mnBufferCount << std::endl;
-        }
-    }
-
-    if(config["pic_rear"])
-    {
-        if(config["pic_rear"]["msgname"]&&config["pic_rear"]["buffersize"]&&config["pic_rear"]["buffercount"])
-        {
-            strmsgname = config["pic_rear"]["msgname"].as<std::string>();
-            strncpy(shmPicRear.mstrmsgname,strmsgname.data(),255);
-            shmPicRear.mnBufferSize = config["pic_rear"]["buffersize"].as<int>();
-            shmPicRear.mnBufferCount = config["pic_rear"]["buffercount"].as<int>();
-//            std::cout << shmPicRear.mstrmsgname << shmPicRear.mnBufferSize << shmPicRear.mnBufferCount << std::endl;
-        }
-    }
-
-    if(config["pic_left"])
-    {
-        if(config["pic_left"]["msgname"]&&config["pic_left"]["buffersize"]&&config["pic_left"]["buffercount"])
-        {
-            strmsgname = config["pic_left"]["msgname"].as<std::string>();
-            strncpy(shmPicLeft.mstrmsgname,strmsgname.data(),255);
-            shmPicLeft.mnBufferSize = config["pic_left"]["buffersize"].as<int>();
-            shmPicLeft.mnBufferCount = config["pic_left"]["buffercount"].as<int>();
-//            std::cout << shmPicLeft.mstrmsgname << shmPicLeft.mnBufferSize << shmPicLeft.mnBufferCount << std::endl;
-        }
-    }
-
-    if(config["pic_right"])
-    {
-        if(config["pic_right"]["msgname"]&&config["pic_right"]["buffersize"]&&config["pic_right"]["buffercount"])
-        {
-            strmsgname = config["pic_right"]["msgname"].as<std::string>();
-            strncpy(shmPicRight.mstrmsgname,strmsgname.data(),255);
-            shmPicRight.mnBufferSize = config["pic_right"]["buffersize"].as<int>();
-            shmPicRight.mnBufferCount = config["pic_right"]["buffercount"].as<int>();
-//            std::cout << shmPicRight.mstrmsgname << shmPicRight.mnBufferSize << shmPicRight.mnBufferCount << std::endl;
-        }
-    }
-
-    if(config["remote_ctrl"])
-    {
-        if(config["remote_ctrl"]["msgname"]&&config["remote_ctrl"]["buffersize"]&&config["remote_ctrl"]["buffercount"])
-        {
-            strmsgname = config["remote_ctrl"]["msgname"].as<std::string>();
-            strncpy(shmRemoteCtrl.mstrmsgname,strmsgname.data(),255);
-            shmRemoteCtrl.mnBufferSize = config["remote_ctrl"]["buffersize"].as<int>();
-            shmRemoteCtrl.mnBufferCount = config["remote_ctrl"]["buffercount"].as<int>();
-//            std::cout << shmRemoteCtrl.mstrmsgname << shmRemoteCtrl.mnBufferSize << shmRemoteCtrl.mnBufferCount << std::endl;
-        }
-    }
-
-    if(config["chassis"])
-    {
-        if(config["chassis"]["msgname"]&&config["chassis"]["buffersize"]&&config["chassis"]["buffercount"])
-        {
-            strmsgname = config["chassis"]["msgname"].as<std::string>();
-            strncpy(shmChassis.mstrmsgname,strmsgname.data(),255);
-            shmChassis.mnBufferSize = config["chassis"]["buffersize"].as<int>();
-            shmChassis.mnBufferCount = config["chassis"]["buffercount"].as<int>();
-//            std::cout << shmChassis.mstrmsgname << shmChassis.mnBufferSize << shmChassis.mnBufferCount << std::endl;
-        }
-    }
-
-    if(config["platform_feedback"])
-    {
-        if(config["platform_feedback"]["msgname"]&&config["platform_feedback"]["buffersize"]&&config["platform_feedback"]["buffercount"])
-        {
-            strmsgname = config["platform_feedback"]["msgname"].as<std::string>();
-            strncpy(shmPlatformFeedback.mstrmsgname,strmsgname.data(),255);
-            shmPlatformFeedback.mnBufferSize = config["platform_feedback"]["buffersize"].as<int>();
-            shmPlatformFeedback.mnBufferCount = config["platform_feedback"]["buffercount"].as<int>();
-//            std::cout << shmPlatformFeedback.mstrmsgname << shmPlatformFeedback.mnBufferSize << shmPlatformFeedback.mnBufferCount << std::endl;
-        }
-    }
-
-    if(config["GPS_IMU"])
-    {
-        if(config["GPS_IMU"]["msgname"]&&config["GPS_IMU"]["buffersize"]&&config["GPS_IMU"]["buffercount"])
-        {
-            strmsgname = config["GPS_IMU"]["msgname"].as<std::string>();
-            strncpy(shmGPSIMU.mstrmsgname,strmsgname.data(),255);
-            shmGPSIMU.mnBufferSize = config["GPS_IMU"]["buffersize"].as<int>();
-            shmGPSIMU.mnBufferCount = config["GPS_IMU"]["buffercount"].as<int>();
-//            std::cout << shmGPSIMU.mstrmsgname << shmGPSIMU.mnBufferSize << shmGPSIMU.mnBufferCount << std::endl;
-        }
-    }
-
     return;
     return;
 }
 }
 
 
@@ -220,7 +121,6 @@ int main(int argc, char *argv[])
     showversion("driver_cloud_grpc_client_BS");
     showversion("driver_cloud_grpc_client_BS");
     QCoreApplication a(argc, argv);
     QCoreApplication a(argc, argv);
 
 
-    char stryamlpath[256];
     if(argc<2)
     if(argc<2)
     {
     {
         snprintf(stryamlpath,255,"driver_cloud_grpc_client_BS.yaml");
         snprintf(stryamlpath,255,"driver_cloud_grpc_client_BS.yaml");

+ 47 - 17
src/driver/driver_cloud_grpc_client_BS/vehicle_control.cpp

@@ -10,26 +10,11 @@ extern std::string gstruploadMapInterval;
 extern std::string gstrid;
 extern std::string gstrid;
 extern std::string gstrplateNumber;
 extern std::string gstrplateNumber;
 
 
+extern char stryamlpath[256];
+
 extern uint8_t gShift_Status; //3 p 4 r 5 n 6 d
 extern uint8_t gShift_Status; //3 p 4 r 5 n 6 d
 extern uint8_t gCtrlMode_Status; //0 auto 1 remote 2 stop 3 platform
 extern uint8_t gCtrlMode_Status; //0 auto 1 remote 2 stop 3 platform
 
 
-namespace iv {
-struct msgunit
-{
-    char mstrmsgname[256];
-    int mnBufferSize = 10000;
-    int mnBufferCount = 1;
-    void * mpa;
-    std::shared_ptr<char> mpstrmsgdata;
-    int mndatasize = 0;
-    bool mbRefresh = false;
-    bool mbImportant = false;
-    int mnkeeptime = 100;
-};
-}
-
-extern iv::msgunit shmRemoteCtrl;
-
 using org::jeecg::defsControl::grpc::Empty; ///< other message
 using org::jeecg::defsControl::grpc::Empty; ///< other message
 using org::jeecg::defsControl::grpc::GPSPoint;
 using org::jeecg::defsControl::grpc::GPSPoint;
 using org::jeecg::defsControl::grpc::MapPoint;
 using org::jeecg::defsControl::grpc::MapPoint;
@@ -41,6 +26,7 @@ VehicleControlClient::VehicleControlClient(std::shared_ptr<Channel> channel)
 {
 {
     stub_ = VehicleControl::NewStub(channel);
     stub_ = VehicleControl::NewStub(channel);
 
 
+    dec_yaml(stryamlpath);
     shmRemoteCtrl.mpa = iv::modulecomm::RegisterSend(shmRemoteCtrl.mstrmsgname,shmRemoteCtrl.mnBufferSize,shmRemoteCtrl.mnBufferCount);
     shmRemoteCtrl.mpa = iv::modulecomm::RegisterSend(shmRemoteCtrl.mstrmsgname,shmRemoteCtrl.mnBufferSize,shmRemoteCtrl.mnBufferCount);
 }
 }
 
 
@@ -49,6 +35,50 @@ VehicleControlClient::~VehicleControlClient(void)
 
 
 }
 }
 
 
+void VehicleControlClient::dec_yaml(const char *stryamlpath)
+{
+    YAML::Node config;
+    try
+    {
+        config = YAML::LoadFile(stryamlpath);
+    }
+    catch(YAML::BadFile &e)
+    {
+        std::cout<<e.what()<<std::endl;
+        qDebug("yaml file load fail.");
+        return;
+    }
+    catch(YAML::ParserException &e)
+    {
+        std::cout<<e.what()<<std::endl;
+        qDebug("yaml file is malformed.");
+        return;
+    }
+
+    std::string strmsgname;
+
+    if(config["remote_ctrl"])
+    {
+        if(config["remote_ctrl"]["msgname"]&&config["remote_ctrl"]["buffersize"]&&config["remote_ctrl"]["buffercount"])
+        {
+            strmsgname = config["remote_ctrl"]["msgname"].as<std::string>();
+            strncpy(shmRemoteCtrl.mstrmsgname,strmsgname.data(),255);
+            shmRemoteCtrl.mnBufferSize = config["remote_ctrl"]["buffersize"].as<int>();
+            shmRemoteCtrl.mnBufferCount = config["remote_ctrl"]["buffercount"].as<int>();
+//            std::cout << shmRemoteCtrl.mstrmsgname << shmRemoteCtrl.mnBufferSize << shmRemoteCtrl.mnBufferCount << std::endl;
+        }
+    }
+    else
+    {
+        strmsgname = "remotectrl";
+        strncpy(shmRemoteCtrl.mstrmsgname,strmsgname.data(),255);
+        shmRemoteCtrl.mnBufferSize = 10000;
+        shmRemoteCtrl.mnBufferCount = 1;
+    }
+
+    return;
+}
+
 std::string VehicleControlClient::vehicleControl(void)
 std::string VehicleControlClient::vehicleControl(void)
 {
 {
     // Data we are sending to the server.
     // Data we are sending to the server.

+ 24 - 0
src/driver/driver_cloud_grpc_client_BS/vehicle_control.h

@@ -11,11 +11,32 @@
 #include <memory>
 #include <memory>
 #include <string>
 #include <string>
 
 
+#include <yaml-cpp/yaml.h>
 #include <grpcpp/grpcpp.h>
 #include <grpcpp/grpcpp.h>
 
 
 #include "VehicleControl_service.grpc.pb.h"
 #include "VehicleControl_service.grpc.pb.h"
 #include "VehicleControl.grpc.pb.h"
 #include "VehicleControl.grpc.pb.h"
 
 
+#ifndef IV_MSGUNIT
+#define IV_MSGUNIT
+
+namespace iv {
+struct msgunit
+{
+    char mstrmsgname[256];
+    int mnBufferSize = 10000;
+    int mnBufferCount = 1;
+    void * mpa;
+    std::shared_ptr<char> mpstrmsgdata;
+    int mndatasize = 0;
+    bool mbRefresh = false;
+    bool mbImportant = false;
+    int mnkeeptime = 100;
+};
+}
+
+#endif
+
 using grpc::Channel;
 using grpc::Channel;
 using grpc::ClientContext;
 using grpc::ClientContext;
 using grpc::Status;
 using grpc::Status;
@@ -36,6 +57,7 @@ public:
 
 
     std::string vehicleControl(void);
     std::string vehicleControl(void);
     void updateControlData(void);
     void updateControlData(void);
+    void dec_yaml(const char * stryamlpath);
 
 
 protected:
 protected:
     void run();
     void run();
@@ -43,6 +65,8 @@ protected:
 private:
 private:
     std::unique_ptr<VehicleControl::Stub> stub_;
     std::unique_ptr<VehicleControl::Stub> stub_;
 
 
+    iv::msgunit shmRemoteCtrl;
+
     org::jeecg::defsControl::grpc::ShiftStatus shiftCMD = org::jeecg::defsControl::grpc::ShiftStatus::SHIFT_PARKING;
     org::jeecg::defsControl::grpc::ShiftStatus shiftCMD = org::jeecg::defsControl::grpc::ShiftStatus::SHIFT_PARKING;
     double steeringWheelAngleCMD = 0;
     double steeringWheelAngleCMD = 0;
     double throttleCMD = 0;
     double throttleCMD = 0;

+ 95 - 45
src/driver/driver_cloud_grpc_client_BS/vehicle_patrol.cpp

@@ -2,12 +2,17 @@
 
 
 #include <QFile>
 #include <QFile>
 
 
+#include "modulecomm.h"
+#include "gpsimu.pb.h"
+
 extern std::string gstrserverip;
 extern std::string gstrserverip;
 extern std::string gstrpatrolPort;
 extern std::string gstrpatrolPort;
 extern std::string gstrpatrolInterval;
 extern std::string gstrpatrolInterval;
 extern std::string gstrid;
 extern std::string gstrid;
 extern std::string gstrplateNumber;
 extern std::string gstrplateNumber;
 
 
+extern char stryamlpath[256];
+
 using org::jeecg::defsPatrol::grpc::Empty;
 using org::jeecg::defsPatrol::grpc::Empty;
 using org::jeecg::defsPatrol::grpc::GPSPoint;
 using org::jeecg::defsPatrol::grpc::GPSPoint;
 
 
@@ -21,6 +26,50 @@ VehiclePatrolExceptionClient::~VehiclePatrolExceptionClient(void)
 
 
 }
 }
 
 
+void VehiclePatrolExceptionClient::dec_yaml(const char *stryamlpath)
+{
+    YAML::Node config;
+    try
+    {
+        config = YAML::LoadFile(stryamlpath);
+    }
+    catch(YAML::BadFile &e)
+    {
+        std::cout<<e.what()<<std::endl;
+        qDebug("yaml file load fail.");
+        return;
+    }
+    catch(YAML::ParserException &e)
+    {
+        std::cout<<e.what()<<std::endl;
+        qDebug("yaml file is malformed.");
+        return;
+    }
+
+    std::string strmsgname;
+
+    if(config["GPS_IMU"])
+    {
+        if(config["GPS_IMU"]["msgname"]&&config["GPS_IMU"]["buffersize"]&&config["GPS_IMU"]["buffercount"])
+        {
+            strmsgname = config["GPS_IMU"]["msgname"].as<std::string>();
+            strncpy(shmGPSIMU.mstrmsgname,strmsgname.data(),255);
+            shmGPSIMU.mnBufferSize = config["GPS_IMU"]["buffersize"].as<int>();
+            shmGPSIMU.mnBufferCount = config["GPS_IMU"]["buffercount"].as<int>();
+//            std::cout << shmGPSIMU.mstrmsgname << shmGPSIMU.mnBufferSize << shmGPSIMU.mnBufferCount << std::endl;
+        }
+    }
+    else
+    {
+        strmsgname = "hcp2_gpsimu";
+        strncpy(shmGPSIMU.mstrmsgname,strmsgname.data(),255);
+        shmGPSIMU.mnBufferSize = 10000;
+        shmGPSIMU.mnBufferCount = 1;
+    }
+
+    return;
+}
+
 std::string VehiclePatrolExceptionClient::uploadVehiclePatrolInfo(void)
 std::string VehiclePatrolExceptionClient::uploadVehiclePatrolInfo(void)
 {
 {
     // Data we are sending to the server.
     // Data we are sending to the server.
@@ -80,52 +129,53 @@ std::string VehiclePatrolExceptionClient::uploadVehiclePatrolInfo(void)
 void VehiclePatrolExceptionClient::updatePatrolData(void)
 void VehiclePatrolExceptionClient::updatePatrolData(void)
 {
 {
     id = gstrid;
     id = gstrid;
-    isTVR = true;
-    violationStatus = 2;
-    vehicleLicenseNumber = "津B654321";
-
-    QFile xFile;
-    xFile.setFileName("/home/samuel/Pictures/123.jpg");
-    if(xFile.open(QIODevice::ReadOnly))
-    {
-        violationImage = xFile.readAll();
-    }
-    xFile.close();
-
-    violationTime = QDateTime::currentMSecsSinceEpoch();
-    violationPosition.set_height(0.1);
-    violationPosition.set_latitude(39.0666552);
-    violationPosition.set_longitude(117.3542963);
-
-    isFSM = true;
-    fireStatus = 1;
-
-    xFile.setFileName("/home/samuel/Pictures/123.jpg");
-    if(xFile.open(QIODevice::ReadOnly))
-    {
-        fireImage = xFile.readAll();
-    }
-    xFile.close();
-
-    fireTime = QDateTime::currentMSecsSinceEpoch();
-    firePosition.set_height(0.1);
-    firePosition.set_latitude(39.0667552);
-    firePosition.set_longitude(117.3542963);
-
-    isTSGM = true;
-    gateStatus = 2;
-
-    xFile.setFileName("/home/samuel/Pictures/123.jpg");
-    if(xFile.open(QIODevice::ReadOnly))
-    {
-        gateImage = xFile.readAll();
-    }
-    xFile.close();
 
 
-    gateTime = QDateTime::currentMSecsSinceEpoch();
-    gatePosition.set_height(0.1);
-    gatePosition.set_latitude(39.0665552);
-    gatePosition.set_longitude(117.3542963);
+//    isTVR = true;
+//    violationStatus = 2;
+//    vehicleLicenseNumber = "津B654321";
+
+//    QFile xFile;
+//    xFile.setFileName("/home/samuel/Pictures/123.jpg");
+//    if(xFile.open(QIODevice::ReadOnly))
+//    {
+//        violationImage = xFile.readAll();
+//    }
+//    xFile.close();
+
+//    violationTime = QDateTime::currentMSecsSinceEpoch();
+//    violationPosition.set_height(0.1);
+//    violationPosition.set_latitude(39.0666552);
+//    violationPosition.set_longitude(117.3542963);
+
+//    isFSM = true;
+//    fireStatus = 1;
+
+//    xFile.setFileName("/home/samuel/Pictures/123.jpg");
+//    if(xFile.open(QIODevice::ReadOnly))
+//    {
+//        fireImage = xFile.readAll();
+//    }
+//    xFile.close();
+
+//    fireTime = QDateTime::currentMSecsSinceEpoch();
+//    firePosition.set_height(0.1);
+//    firePosition.set_latitude(39.0667552);
+//    firePosition.set_longitude(117.3542963);
+
+//    isTSGM = true;
+//    gateStatus = 2;
+
+//    xFile.setFileName("/home/samuel/Pictures/123.jpg");
+//    if(xFile.open(QIODevice::ReadOnly))
+//    {
+//        gateImage = xFile.readAll();
+//    }
+//    xFile.close();
+
+//    gateTime = QDateTime::currentMSecsSinceEpoch();
+//    gatePosition.set_height(0.1);
+//    gatePosition.set_latitude(39.0665552);
+//    gatePosition.set_longitude(117.3542963);
 
 
     plateNumber = gstrplateNumber;
     plateNumber = gstrplateNumber;
 }
 }

+ 25 - 1
src/driver/driver_cloud_grpc_client_BS/vehicle_patrol.h

@@ -11,11 +11,31 @@
 #include <memory>
 #include <memory>
 #include <string>
 #include <string>
 
 
+#include <yaml-cpp/yaml.h>
 #include <grpcpp/grpcpp.h>
 #include <grpcpp/grpcpp.h>
 
 
 #include "VehiclePatrol_service.grpc.pb.h"
 #include "VehiclePatrol_service.grpc.pb.h"
 #include "VehiclePatrol.grpc.pb.h"
 #include "VehiclePatrol.grpc.pb.h"
-#include "modulecommext.h"
+
+#ifndef IV_MSGUNIT
+#define IV_MSGUNIT
+
+namespace iv {
+struct msgunit
+{
+    char mstrmsgname[256];
+    int mnBufferSize = 10000;
+    int mnBufferCount = 1;
+    void * mpa;
+    std::shared_ptr<char> mpstrmsgdata;
+    int mndatasize = 0;
+    bool mbRefresh = false;
+    bool mbImportant = false;
+    int mnkeeptime = 100;
+};
+}
+
+#endif
 
 
 using grpc::Channel;
 using grpc::Channel;
 using grpc::ClientContext;
 using grpc::ClientContext;
@@ -36,12 +56,16 @@ public:
     std::string uploadVehiclePatrolInfo(void);
     std::string uploadVehiclePatrolInfo(void);
     void updatePatrolData(void);
     void updatePatrolData(void);
 
 
+    void dec_yaml(const char * stryamlpath);
+
 protected:
 protected:
     void run();
     void run();
 
 
 private:
 private:
     std::unique_ptr<VehiclePatrolException::Stub> stub_;
     std::unique_ptr<VehiclePatrolException::Stub> stub_;
 
 
+    iv::msgunit shmGPSIMU;
+
     std::string id;
     std::string id;
 
 
     bool isTVR; //Traffic Violation Recognition
     bool isTVR; //Traffic Violation Recognition

+ 161 - 23
src/driver/driver_cloud_grpc_client_BS/vehicle_upload.cpp

@@ -17,32 +17,11 @@ extern std::string gstruploadInterval;
 extern std::string gstrid;
 extern std::string gstrid;
 extern std::string gstrplateNumber;
 extern std::string gstrplateNumber;
 
 
+extern char stryamlpath[256];
+
 extern uint8_t gShift_Status;//3 p 4 r 5 n 6 d
 extern uint8_t gShift_Status;//3 p 4 r 5 n 6 d
 extern uint8_t gCtrlMode_Status; //0 auto 1 remote 2 stop 3 platform
 extern uint8_t gCtrlMode_Status; //0 auto 1 remote 2 stop 3 platform
 
 
-namespace iv {
-struct msgunit
-{
-    char mstrmsgname[256];
-    int mnBufferSize = 10000;
-    int mnBufferCount = 1;
-    void * mpa;
-    std::shared_ptr<char> mpstrmsgdata;
-    int mndatasize = 0;
-    bool mbRefresh = false;
-    bool mbImportant = false;
-    int mnkeeptime = 100;
-};
-}
-
-extern iv::msgunit shmPicFront;
-extern iv::msgunit shmPicRear;
-extern iv::msgunit shmPicLeft;
-extern iv::msgunit shmPicRight;
-extern iv::msgunit shmChassis;
-extern iv::msgunit shmGPSIMU;
-extern iv::msgunit shmPlatformFeedback;
-
 using org::jeecg::defsDetails::grpc::Empty; ///< other message
 using org::jeecg::defsDetails::grpc::Empty; ///< other message
 using org::jeecg::defsDetails::grpc::GPSPoint;
 using org::jeecg::defsDetails::grpc::GPSPoint;
 using org::jeecg::defsDetails::grpc::MapPoint;
 using org::jeecg::defsDetails::grpc::MapPoint;
@@ -93,6 +72,7 @@ DataExchangeClient::DataExchangeClient(std::shared_ptr<Channel> channel)
 
 
     stub_ = DataExchange::NewStub(channel);
     stub_ = DataExchange::NewStub(channel);
 
 
+    dec_yaml(stryamlpath);
     shmPicFront.mpa = iv::modulecomm::RegisterRecv(shmPicFront.mstrmsgname,ListenFrontData);
     shmPicFront.mpa = iv::modulecomm::RegisterRecv(shmPicFront.mstrmsgname,ListenFrontData);
     shmPicRear.mpa = iv::modulecomm::RegisterRecv(shmPicRear.mstrmsgname,ListenRearData);
     shmPicRear.mpa = iv::modulecomm::RegisterRecv(shmPicRear.mstrmsgname,ListenRearData);
     shmPicLeft.mpa = iv::modulecomm::RegisterRecv(shmPicLeft.mstrmsgname,ListenLeftData);
     shmPicLeft.mpa = iv::modulecomm::RegisterRecv(shmPicLeft.mstrmsgname,ListenLeftData);
@@ -107,6 +87,164 @@ DataExchangeClient::~DataExchangeClient(void)
 
 
 }
 }
 
 
+void DataExchangeClient::dec_yaml(const char *stryamlpath)
+{
+    YAML::Node config;
+    try
+    {
+        config = YAML::LoadFile(stryamlpath);
+    }
+    catch(YAML::BadFile &e)
+    {
+        std::cout<<e.what()<<std::endl;
+        qDebug("yaml file load fail.");
+        return;
+    }
+    catch(YAML::ParserException &e)
+    {
+        std::cout<<e.what()<<std::endl;
+        qDebug("yaml file is malformed.");
+        return;
+    }
+
+    std::string strmsgname;
+
+    if(config["pic_front"])
+    {
+        if(config["pic_front"]["msgname"]&&config["pic_front"]["buffersize"]&&config["pic_front"]["buffercount"])
+        {
+            strmsgname = config["pic_front"]["msgname"].as<std::string>();
+            strncpy(shmPicFront.mstrmsgname,strmsgname.data(),255);
+            shmPicFront.mnBufferSize = config["pic_front"]["buffersize"].as<int>();
+            shmPicFront.mnBufferCount = config["pic_front"]["buffercount"].as<int>();
+//            std::cout << shmPicFront.mstrmsgname << shmPicFront.mnBufferSize << shmPicFront.mnBufferCount << std::endl;
+        }
+    }
+    else
+    {
+        strmsgname = "picfront";
+        strncpy(shmPicFront.mstrmsgname,strmsgname.data(),255);
+        shmPicFront.mnBufferSize = 10000000;
+        shmPicFront.mnBufferCount = 1;
+    }
+
+    if(config["pic_rear"])
+    {
+        if(config["pic_rear"]["msgname"]&&config["pic_rear"]["buffersize"]&&config["pic_rear"]["buffercount"])
+        {
+            strmsgname = config["pic_rear"]["msgname"].as<std::string>();
+            strncpy(shmPicRear.mstrmsgname,strmsgname.data(),255);
+            shmPicRear.mnBufferSize = config["pic_rear"]["buffersize"].as<int>();
+            shmPicRear.mnBufferCount = config["pic_rear"]["buffercount"].as<int>();
+//            std::cout << shmPicRear.mstrmsgname << shmPicRear.mnBufferSize << shmPicRear.mnBufferCount << std::endl;
+        }
+    }
+    else
+    {
+        strmsgname = "picrear";
+        strncpy(shmPicRear.mstrmsgname,strmsgname.data(),255);
+        shmPicRear.mnBufferSize = 10000000;
+        shmPicRear.mnBufferCount = 1;
+    }
+
+    if(config["pic_left"])
+    {
+        if(config["pic_left"]["msgname"]&&config["pic_left"]["buffersize"]&&config["pic_left"]["buffercount"])
+        {
+            strmsgname = config["pic_left"]["msgname"].as<std::string>();
+            strncpy(shmPicLeft.mstrmsgname,strmsgname.data(),255);
+            shmPicLeft.mnBufferSize = config["pic_left"]["buffersize"].as<int>();
+            shmPicLeft.mnBufferCount = config["pic_left"]["buffercount"].as<int>();
+//            std::cout << shmPicLeft.mstrmsgname << shmPicLeft.mnBufferSize << shmPicLeft.mnBufferCount << std::endl;
+        }
+    }
+    else
+    {
+        strmsgname = "picleft";
+        strncpy(shmPicLeft.mstrmsgname,strmsgname.data(),255);
+        shmPicLeft.mnBufferSize = 10000000;
+        shmPicLeft.mnBufferCount = 1;
+    }
+
+    if(config["pic_right"])
+    {
+        if(config["pic_right"]["msgname"]&&config["pic_right"]["buffersize"]&&config["pic_right"]["buffercount"])
+        {
+            strmsgname = config["pic_right"]["msgname"].as<std::string>();
+            strncpy(shmPicRight.mstrmsgname,strmsgname.data(),255);
+            shmPicRight.mnBufferSize = config["pic_right"]["buffersize"].as<int>();
+            shmPicRight.mnBufferCount = config["pic_right"]["buffercount"].as<int>();
+//            std::cout << shmPicRight.mstrmsgname << shmPicRight.mnBufferSize << shmPicRight.mnBufferCount << std::endl;
+        }
+    }
+    else
+    {
+        strmsgname = "picright";
+        strncpy(shmPicRight.mstrmsgname,strmsgname.data(),255);
+        shmPicRight.mnBufferSize = 10000000;
+        shmPicRight.mnBufferCount = 1;
+    }
+
+    if(config["chassis"])
+    {
+        if(config["chassis"]["msgname"]&&config["chassis"]["buffersize"]&&config["chassis"]["buffercount"])
+        {
+            strmsgname = config["chassis"]["msgname"].as<std::string>();
+            strncpy(shmChassis.mstrmsgname,strmsgname.data(),255);
+            shmChassis.mnBufferSize = config["chassis"]["buffersize"].as<int>();
+            shmChassis.mnBufferCount = config["chassis"]["buffercount"].as<int>();
+//            std::cout << shmChassis.mstrmsgname << shmChassis.mnBufferSize << shmChassis.mnBufferCount << std::endl;
+        }
+    }
+    else
+    {
+        strmsgname = "chassis";
+        strncpy(shmChassis.mstrmsgname,strmsgname.data(),255);
+        shmChassis.mnBufferSize = 10000;
+        shmChassis.mnBufferCount = 1;
+    }
+
+    if(config["platform_feedback"])
+    {
+        if(config["platform_feedback"]["msgname"]&&config["platform_feedback"]["buffersize"]&&config["platform_feedback"]["buffercount"])
+        {
+            strmsgname = config["platform_feedback"]["msgname"].as<std::string>();
+            strncpy(shmPlatformFeedback.mstrmsgname,strmsgname.data(),255);
+            shmPlatformFeedback.mnBufferSize = config["platform_feedback"]["buffersize"].as<int>();
+            shmPlatformFeedback.mnBufferCount = config["platform_feedback"]["buffercount"].as<int>();
+//            std::cout << shmPlatformFeedback.mstrmsgname << shmPlatformFeedback.mnBufferSize << shmPlatformFeedback.mnBufferCount << std::endl;
+        }
+    }
+    else
+    {
+        strmsgname = "platformFeedback";
+        strncpy(shmPlatformFeedback.mstrmsgname,strmsgname.data(),255);
+        shmPlatformFeedback.mnBufferSize = 10000;
+        shmPlatformFeedback.mnBufferCount = 1;
+    }
+
+    if(config["GPS_IMU"])
+    {
+        if(config["GPS_IMU"]["msgname"]&&config["GPS_IMU"]["buffersize"]&&config["GPS_IMU"]["buffercount"])
+        {
+            strmsgname = config["GPS_IMU"]["msgname"].as<std::string>();
+            strncpy(shmGPSIMU.mstrmsgname,strmsgname.data(),255);
+            shmGPSIMU.mnBufferSize = config["GPS_IMU"]["buffersize"].as<int>();
+            shmGPSIMU.mnBufferCount = config["GPS_IMU"]["buffercount"].as<int>();
+//            std::cout << shmGPSIMU.mstrmsgname << shmGPSIMU.mnBufferSize << shmGPSIMU.mnBufferCount << std::endl;
+        }
+    }
+    else
+    {
+        strmsgname = "hcp2_gpsimu";
+        strncpy(shmGPSIMU.mstrmsgname,strmsgname.data(),255);
+        shmGPSIMU.mnBufferSize = 10000;
+        shmGPSIMU.mnBufferCount = 1;
+    }
+
+    return;
+}
+
 void DataExchangeClient::ListenFrontPicMsg(const char * strdata,const unsigned int nSize) // need a lock
 void DataExchangeClient::ListenFrontPicMsg(const char * strdata,const unsigned int nSize) // need a lock
 {
 {
     iv::vision::rawpic xdata;
     iv::vision::rawpic xdata;

+ 31 - 0
src/driver/driver_cloud_grpc_client_BS/vehicle_upload.h

@@ -12,11 +12,32 @@
 #include <memory>
 #include <memory>
 #include <string>
 #include <string>
 
 
+#include <yaml-cpp/yaml.h>
 #include <grpcpp/grpcpp.h>
 #include <grpcpp/grpcpp.h>
 
 
 #include "VehicleUpload_service.grpc.pb.h"
 #include "VehicleUpload_service.grpc.pb.h"
 #include "VehicleUpload.grpc.pb.h"
 #include "VehicleUpload.grpc.pb.h"
 
 
+#ifndef IV_MSGUNIT
+#define IV_MSGUNIT
+
+namespace iv {
+struct msgunit
+{
+    char mstrmsgname[256];
+    int mnBufferSize = 10000;
+    int mnBufferCount = 1;
+    void * mpa;
+    std::shared_ptr<char> mpstrmsgdata;
+    int mndatasize = 0;
+    bool mbRefresh = false;
+    bool mbImportant = false;
+    int mnkeeptime = 100;
+};
+}
+
+#endif
+
 using grpc::Channel;
 using grpc::Channel;
 using grpc::ClientContext;
 using grpc::ClientContext;
 using grpc::Status;
 using grpc::Status;
@@ -42,6 +63,8 @@ public:
     void updateData(uint64_t timeInterval_ms);
     void updateData(uint64_t timeInterval_ms);
     void updatePath(std::string pathID,QVector<org::jeecg::defsDetails::grpc::MapPoint> points);
     void updatePath(std::string pathID,QVector<org::jeecg::defsDetails::grpc::MapPoint> points);
 
 
+    void dec_yaml(const char * stryamlpath);
+
     void ListenFrontPicMsg(const char * strdata,const unsigned int nSize);
     void ListenFrontPicMsg(const char * strdata,const unsigned int nSize);
     void ListenRearPicMsg(const char * strdata,const unsigned int nSize);
     void ListenRearPicMsg(const char * strdata,const unsigned int nSize);
     void ListenLeftPicMsg(const char * strdata,const unsigned int nSize);
     void ListenLeftPicMsg(const char * strdata,const unsigned int nSize);
@@ -56,6 +79,14 @@ protected:
 private:
 private:
     std::unique_ptr<DataExchange::Stub> stub_;
     std::unique_ptr<DataExchange::Stub> stub_;
 
 
+    iv::msgunit shmPicFront;
+    iv::msgunit shmPicRear;
+    iv::msgunit shmPicLeft;
+    iv::msgunit shmPicRight;
+    iv::msgunit shmChassis;
+    iv::msgunit shmGPSIMU;
+    iv::msgunit shmPlatformFeedback;
+
     std::string id;
     std::string id;
     uint64_t timeStamp = QDateTime::currentMSecsSinceEpoch();
     uint64_t timeStamp = QDateTime::currentMSecsSinceEpoch();
     double SOC; //0.0-100.0%
     double SOC; //0.0-100.0%