Browse Source

fix(grpc_BS):fix some decode yaml error.

fujiankuan 3 years ago
parent
commit
8d0c4699be

+ 1 - 1
src/driver/driver_cloud_grpc_client_BS/driver_cloud_grpc_client_BS.yaml

@@ -3,7 +3,7 @@ upload_port : 10591
 patrol_port : 10592
 control_port : 20591
 
-uploadinterval : 500 //ms
+uploadinterval : 100 #ms
 patrolinterval : 1000
 controlinterval : 100
 uploadmapinterval : 1000

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

@@ -41,7 +41,7 @@ std::string gstrserverip =  "111.33.136.150";//"123.57.212.138";
 std::string gstruploadPort = "10591";//"9000";
 std::string gstrpatrolPort = "10592";//"9000";
 std::string gstrcontrolPort = "20591";//"9000";
-std::string gstruploadInterval = "500";
+std::string gstruploadInterval = "100";
 std::string gstrpatrolInterval = "1000";
 std::string gstrcontrolInterval = "100";
 std::string gstruploadMapInterval = "1000";
@@ -74,43 +74,53 @@ void dec_yaml(const char * stryamlpath)
     if(config["server"])
     {
         gstrserverip = config["server"].as<std::string>();
+        std::cout<<"server:"<<gstrserverip<<std::endl;
     }
-    if(config["uploadPort"])
+    if(config["upload_port"])
     {
-        gstruploadPort = config["uploadPort"].as<std::string>();
+        gstruploadPort = config["upload_port"].as<std::string>();
+        std::cout<<"upload_port:"<<gstruploadPort<<std::endl;
     }
-    if(config["patrolPort"])
+    if(config["patrol_port"])
     {
-        gstrpatrolPort = config["patrolPort"].as<std::string>();
+        gstrpatrolPort = config["patrol_port"].as<std::string>();
+        std::cout<<"patrol_port:"<<gstrpatrolPort<<std::endl;
     }
-    if(config["controlPort"])
+    if(config["control_port"])
     {
-        gstrcontrolPort = config["controlPort"].as<std::string>();
+        gstrcontrolPort = config["control_port"].as<std::string>();
+        std::cout<<"control_port:"<<gstrcontrolPort<<std::endl;
     }
-    if(config["uploadInterval"])
+    if(config["uploadinterval"])
     {
-        gstruploadInterval = config["uploadInterval"].as<std::string>();
+        gstruploadInterval = config["uploadinterval"].as<std::string>();
+        std::cout<<"uploadinterval:"<<gstruploadInterval<<"ms"<<std::endl;
     }
-    if(config["patrolInterval"])
+    if(config["patrolinterval"])
     {
-        gstrpatrolInterval = config["patrolInterval"].as<std::string>();
+        gstrpatrolInterval = config["patrolinterval"].as<std::string>();
+        std::cout<<"patrolinterval:"<<gstrpatrolInterval<<"ms"<<std::endl;
     }
     if(config["controlinterval"])
     {
         gstrcontrolInterval = config["controlinterval"].as<std::string>();
+        std::cout<<"controlinterval:"<<gstrcontrolInterval<<"ms"<<std::endl;
     }
     if(config["uploadmapinterval"])
     {
         gstruploadMapInterval = config["uploadmapinterval"].as<std::string>();
+        std::cout<<"uploadmapinterval:"<<gstruploadMapInterval<<"ms"<<std::endl;
     }
 
     if(config["id"])
     {
         gstrid = config["id"].as<std::string>();
+        std::cout<<"id:"<<gstrid<<std::endl;
     }
     if(config["plateNumber"])
     {
         gstrplateNumber = config["plateNumber"].as<std::string>();
+        std::cout<<"plateNumber:"<<gstrplateNumber<<std::endl;
     }
 
     return;
@@ -160,7 +170,7 @@ int main(int argc, char *argv[])
     vehicleuploadmap->start();
 
 //    std::cout<<patrol_str<<std::endl;
-//    VehiclePatrolExceptionClient vehiclepatrol(grpc::CreateChannel(patrol_str, grpc::InsecureChannelCredentials()));
+    VehiclePatrolExceptionClient vehiclepatrol(grpc::CreateChannel(patrol_str, grpc::InsecureChannelCredentials()));
 //    vehiclepatrol.start();
 
     return a.exec();

+ 3 - 1
src/driver/driver_cloud_grpc_client_BS/vehicle_control.cpp

@@ -1,5 +1,7 @@
 #include "vehicle_control.h"
 
+#include <math.h>
+
 #include "modulecomm.h"
 #include "remotectrl.pb.h"
 
@@ -64,7 +66,7 @@ void VehicleControlClient::dec_yaml(const char *stryamlpath)
             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;
+            std::cout << "RemoteCtrl:" << shmRemoteCtrl.mstrmsgname << "," << shmRemoteCtrl.mnBufferSize << "," << shmRemoteCtrl.mnBufferCount << std::endl;
         }
     }
     else

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

@@ -1,6 +1,7 @@
 #include "vehicle_patrol.h"
 
 #include <QFile>
+#include <math.h>
 
 #include "modulecomm.h"
 #include "gpsimu.pb.h"
@@ -19,6 +20,11 @@ using org::jeecg::defsPatrol::grpc::GPSPoint;
 VehiclePatrolExceptionClient::VehiclePatrolExceptionClient(std::shared_ptr<Channel> channel)
 {
     stub_ = VehiclePatrolException::NewStub(channel);
+
+    dec_yaml(stryamlpath);
+
+    ModuleFun funupdate = std::bind(&VehiclePatrolExceptionClient::ListenGPSIMUMsg,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
+    shmGPSIMU.mpa = iv::modulecomm::RegisterRecvPlus(shmGPSIMU.mstrmsgname,funupdate);
 }
 
 VehiclePatrolExceptionClient::~VehiclePatrolExceptionClient(void)
@@ -56,7 +62,7 @@ void VehiclePatrolExceptionClient::dec_yaml(const char *stryamlpath)
             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;
+            std::cout << "GPS_IMU:" << shmGPSIMU.mstrmsgname << "," << shmGPSIMU.mnBufferSize << "," << shmGPSIMU.mnBufferCount << std::endl;
         }
     }
     else
@@ -70,6 +76,24 @@ void VehiclePatrolExceptionClient::dec_yaml(const char *stryamlpath)
     return;
 }
 
+void VehiclePatrolExceptionClient::ListenGPSIMUMsg(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname) // need a lock
+{
+    iv::gps::gpsimu xdata;
+    if(!xdata.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<" MainWindow::UpdateSlider parese error."<<std::endl;
+        return;
+    }
+
+    gMutex_GPSIMU.lock();
+    currentPosition.set_latitude(xdata.lat());
+    currentPosition.set_longitude(xdata.lon());
+    currentPosition.set_height(xdata.height());
+    gMutex_GPSIMU.unlock();
+
+}
+
+
 std::string VehiclePatrolExceptionClient::uploadVehiclePatrolInfo(void)
 {
     // Data we are sending to the server.

+ 6 - 0
src/driver/driver_cloud_grpc_client_BS/vehicle_patrol.h

@@ -6,6 +6,7 @@
 #include <QDateTime>
 #include <QVector>
 #include <QThread>
+#include <QMutex>
 
 #include <iostream>
 #include <memory>
@@ -58,6 +59,8 @@ public:
 
     void dec_yaml(const char * stryamlpath);
 
+    void ListenGPSIMUMsg(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
+
 protected:
     void run();
 
@@ -66,6 +69,9 @@ private:
 
     iv::msgunit shmGPSIMU;
 
+    QMutex gMutex_GPSIMU;
+    org::jeecg::defsPatrol::grpc::GPSPoint currentPosition;
+
     std::string id;
 
     bool isTVR; //Traffic Violation Recognition

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

@@ -87,7 +87,7 @@ void DataExchangeClient::dec_yaml(const char *stryamlpath)
             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;
+            std::cout << "pic_front:" << shmPicFront.mstrmsgname << "," << shmPicFront.mnBufferSize << "," << shmPicFront.mnBufferCount << std::endl;
         }
     }
     else
@@ -106,7 +106,7 @@ void DataExchangeClient::dec_yaml(const char *stryamlpath)
             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;
+            std::cout << "pic_rear:" << shmPicRear.mstrmsgname << "," << shmPicRear.mnBufferSize << "," << shmPicRear.mnBufferCount << std::endl;
         }
     }
     else
@@ -125,7 +125,7 @@ void DataExchangeClient::dec_yaml(const char *stryamlpath)
             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;
+            std::cout << "pic_left:" << shmPicLeft.mstrmsgname << "," << shmPicLeft.mnBufferSize << "," << shmPicLeft.mnBufferCount << std::endl;
         }
     }
     else
@@ -144,7 +144,7 @@ void DataExchangeClient::dec_yaml(const char *stryamlpath)
             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;
+            std::cout << "pic_right:" << shmPicRight.mstrmsgname << "," << shmPicRight.mnBufferSize << "," << shmPicRight.mnBufferCount << std::endl;
         }
     }
     else
@@ -163,7 +163,7 @@ void DataExchangeClient::dec_yaml(const char *stryamlpath)
             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;
+            std::cout << "chassis:" << shmChassis.mstrmsgname << "," << shmChassis.mnBufferSize << "," << shmChassis.mnBufferCount << std::endl;
         }
     }
     else
@@ -182,7 +182,7 @@ void DataExchangeClient::dec_yaml(const char *stryamlpath)
             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;
+            std::cout << "platform_feedback:" << shmPlatformFeedback.mstrmsgname << "," << shmPlatformFeedback.mnBufferSize << "," << shmPlatformFeedback.mnBufferCount << std::endl;
         }
     }
     else
@@ -201,7 +201,7 @@ void DataExchangeClient::dec_yaml(const char *stryamlpath)
             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;
+            std::cout << "GPS_IMU:" << shmGPSIMU.mstrmsgname << "," << shmGPSIMU.mnBufferSize << "," << shmGPSIMU.mnBufferCount << std::endl;
         }
     }
     else
@@ -448,7 +448,7 @@ std::string DataExchangeClient::uploadVehicleInfo(void)
     // Act upon its status.
     if (status.ok()) {
         destinationPosition.CopyFrom(reply.destinationposition());
-//        std::cout<<"lat:"<<destinationPosition.latitude()<<"lon:"<<destinationPosition.longitude()<<"height:"<<destinationPosition.height()<<std::endl;
+        std::cout<<"lat:"<<reply.destinationposition().latitude()<<"lon:"<<reply.destinationposition().longitude()<<"height:"<<reply.destinationposition().height()<<std::endl;
         return "uploadVehicleInfo RPC successed";
     } else {
         std::cout << status.error_code() << ": " << status.error_message()
@@ -511,23 +511,23 @@ void DataExchangeClient::updateData(uint64_t timeInterval_ms)
 {
     id = gstrid;
     timeStamp = QDateTime::currentMSecsSinceEpoch();
-    SOC = 87.5;
-    statusFeedback = VehicleStatus::STATUS_REMOTE;
+//    SOC = 87.5;
+//    statusFeedback = VehicleStatus::STATUS_REMOTE;
     gMutex_GPSIMU.lock();
     mileage += (speed * timeInterval_ms/1000.0)/1000.0; // kilometer
     gMutex_GPSIMU.unlock();
-    speed = 0.0; // m/s
-    shiftFeedback = ShiftStatus::SHIFT_DRIVE;
-    steeringWheelAngleFeedback = 1.23; //+/-540 degree
-    throttleFeedback = 0.12;
-    brakeFeedback = 0.34;
-    GPSRTKStatus = 6; //GPS-RTK status 0-6 6 is best
-    positionFeedback.set_latitude(39.0666552);
-    positionFeedback.set_longitude(117.3540963);
-    positionFeedback.set_height(0.84);
-    pitch = 0.03;
-    roll = 0.02;
-    heading = 198.4;
+//    speed = 0.0; // m/s
+//    shiftFeedback = ShiftStatus::SHIFT_DRIVE;
+//    steeringWheelAngleFeedback = 1.23; //+/-540 degree
+//    throttleFeedback = 0.12;
+//    brakeFeedback = 0.34;
+//    GPSRTKStatus = 6; //GPS-RTK status 0-6 6 is best
+//    positionFeedback.set_latitude(39.0666552);
+//    positionFeedback.set_longitude(117.3540963);
+//    positionFeedback.set_height(0.84);
+//    pitch = 0.03;
+//    roll = 0.02;
+//    heading = 198.4;
 
 //    QFile xFile;
 //    xFile.setFileName("/home/nvidia/Pictures/123.jpg");
@@ -608,6 +608,7 @@ void DataExchangeClient::run()
         {
             QString strMileage = QString::number(mileage,'f',4);
             mileageFile.write(strMileage.toUtf8());
+            std::cout<<"file not exist. mileage has been cleared. "<<mileage<<std::endl;
         }
         mileageFile.flush();
         mileageFile.close();
@@ -644,7 +645,7 @@ void DataExchangeClient::patrolPOI_Recieved_Slot(std::string pathID)
 {
     std::cout<<"patrol path calculating"<<std::endl;
     QFile mapfile;
-    mapfile.setFileName("/home/samuel/Documents/path2.txt");
+    mapfile.setFileName("/home/nvidia/Documents/path2.txt");
     QVector<org::jeecg::defsDetails::grpc::MapPoint> somePoints;
     if(mapfile.open(QIODevice::ReadOnly | QIODevice::Text))
     {

+ 1 - 1
src/driver/driver_cloud_grpc_client_BS/vehicle_upload.h

@@ -91,7 +91,7 @@ private:
     uint64_t timeStamp = QDateTime::currentMSecsSinceEpoch();
     double SOC; //0.0-100.0%
     VehicleStatus statusFeedback = VehicleStatus::STATUS_EMERGENCY_STOP;
-    double mileage; // kilometer
+    double mileage = 0.0; // kilometer
     uint64_t timeMileageRecord = QDateTime::currentMSecsSinceEpoch();
     double speed; // m/s
     org::jeecg::defsDetails::grpc::ShiftStatus shiftFeedback = org::jeecg::defsDetails::grpc::ShiftStatus::SHIFT_PARKING;