Переглянути джерело

fix(grpc_BS):add some feedback info but not finished

孙嘉城 3 роки тому
батько
коміт
66fc47e477

+ 6 - 0
src/driver/driver_cloud_grpc_client_BS/driver_cloud_grpc_client_BS.pro

@@ -34,6 +34,9 @@ SOURCES += \
         vehicle_patrol.cpp \
         vehicle_upload.cpp \
         ../../include/msgtype/remotectrl.pb.cc \
+        ../../include/msgtype/chassis.pb.cc \
+        ../../include/msgtype/brainstate.pb.cc \
+        ../../include/msgtype/gpsimu.pb.cc \
         ../../include/msgtype/rawpic.pb.cc
 
 
@@ -81,6 +84,9 @@ HEADERS += \
         vehicle_patrol.h \
         vehicle_upload.h \
         ../../include/msgtype/remotectrl.pb.h \
+        ../../include/msgtype/chassis.pb.h \
+        ../../include/msgtype/brainstate.pb.h \
+        ../../include/msgtype/gpsimu.pb.h \
         ../../include/msgtype/rawpic.pb.h
 
 #before compile in ubuntu20.04 : sudo apt install libyaml-cpp-dev libgrpc++-dev

+ 14 - 14
src/driver/driver_cloud_grpc_client_BS/main.cpp

@@ -30,14 +30,14 @@ struct msgunit
 
 uint8_t gShift_Status = 3;//3 p 4 r 5 n 6 d
 
-std::string gstrserverip =  "139.9.235.66";//"123.57.212.138";
+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 gstrpatrolInterval = "500";
+std::string gstrpatrolInterval = "1000";
 std::string gstrcontrolInterval = "100";
-std::string gstruploadMapInterval = "500";
+std::string gstruploadMapInterval = "1000";
 std::string gstrid = "1234567890123456789H";
 std::string gstrplateNumber = "津A123456";
 
@@ -206,17 +206,17 @@ int main(int argc, char *argv[])
     vehicleuploaddata->start();
 
 //    std::cout<<control_str<<std::endl;
-    VehicleChangeCtrlModeClient *vehiclechangectrlmode = new VehicleChangeCtrlModeClient(grpc::CreateChannel(control_str, grpc::InsecureChannelCredentials()));
-    VehicleControlClient *vehiclecontrol = new VehicleControlClient(grpc::CreateChannel(control_str, grpc::InsecureChannelCredentials()));
-    qRegisterMetaType<org::jeecg::defsControl::grpc::CtrlMode>("org::jeecg::defsControl::grpc::CtrlMode"); ///< to solve the problem of signal and slot being in different threads
-    QObject::connect(vehiclechangectrlmode,&VehicleChangeCtrlModeClient::ctrlMode_Changed,vehiclecontrol,&VehicleControlClient::ctrlMode_Changed_Slot);
-    vehiclechangectrlmode->start();
-    vehiclecontrol->start();
-
-    VehicleUploadMapClient *vehicleuploadmap = new VehicleUploadMapClient(grpc::CreateChannel(control_str, grpc::InsecureChannelCredentials()));
-    QObject::connect(vehicleuploadmap,&VehicleUploadMapClient::patrolPOI_Recieved,vehicleuploaddata,&DataExchangeClient::patrolPOI_Recieved_Slot);
-    QObject::connect(vehicleuploaddata,&DataExchangeClient::uploadPath_Finished,vehicleuploadmap,&VehicleUploadMapClient::uploadPath_Finished_Slot);
-    vehicleuploadmap->start();
+//    VehicleChangeCtrlModeClient *vehiclechangectrlmode = new VehicleChangeCtrlModeClient(grpc::CreateChannel(control_str, grpc::InsecureChannelCredentials()));
+//    VehicleControlClient *vehiclecontrol = new VehicleControlClient(grpc::CreateChannel(control_str, grpc::InsecureChannelCredentials()));
+//    qRegisterMetaType<org::jeecg::defsControl::grpc::CtrlMode>("org::jeecg::defsControl::grpc::CtrlMode"); ///< to solve the problem of signal and slot being in different threads
+//    QObject::connect(vehiclechangectrlmode,&VehicleChangeCtrlModeClient::ctrlMode_Changed,vehiclecontrol,&VehicleControlClient::ctrlMode_Changed_Slot);
+//    vehiclechangectrlmode->start();
+//    vehiclecontrol->start();
+
+//    VehicleUploadMapClient *vehicleuploadmap = new VehicleUploadMapClient(grpc::CreateChannel(control_str, grpc::InsecureChannelCredentials()));
+//    QObject::connect(vehicleuploadmap,&VehicleUploadMapClient::patrolPOI_Recieved,vehicleuploaddata,&DataExchangeClient::patrolPOI_Recieved_Slot);
+//    QObject::connect(vehicleuploaddata,&DataExchangeClient::uploadPath_Finished,vehicleuploadmap,&VehicleUploadMapClient::uploadPath_Finished_Slot);
+//    vehicleuploadmap->start();
 
 //    std::cout<<patrol_str<<std::endl;
 //    VehiclePatrolExceptionClient vehiclepatrol(grpc::CreateChannel(patrol_str, grpc::InsecureChannelCredentials()));

+ 4 - 0
src/driver/driver_cloud_grpc_client_BS/vehicle_control.cpp

@@ -1,5 +1,8 @@
 #include "vehicle_control.h"
 
+#include "modulecomm.h"
+#include "remotectrl.pb.h"
+
 extern std::string gstrserverip;
 extern std::string gstrcontrolPort;
 extern std::string gstrcontrolInterval;
@@ -108,6 +111,7 @@ void VehicleControlClient::updateControlData(void)
 //    std::cout<<"steeringWheelAngle:"<<steeringWheelAngleCMD<<std::endl;
 //    std::cout<<"throttle:"<<throttleCMD<<std::endl;
 //    std::cout<<"brake:"<<brakeCMD<<"\n"<<std::endl;
+
     gShift_Status = shiftCMD;
 
     iv::remotectrl xmsg;

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

@@ -16,9 +16,6 @@
 #include "VehicleControl_service.grpc.pb.h"
 #include "VehicleControl.grpc.pb.h"
 
-#include "modulecomm.h"
-#include "remotectrl.pb.h"
-
 using grpc::Channel;
 using grpc::ClientContext;
 using grpc::Status;

+ 43 - 0
src/driver/driver_cloud_grpc_client_BS/vehicle_upload.cpp

@@ -4,6 +4,12 @@
 #include <QString>
 #include <QStringList>
 
+#include "modulecomm.h"
+#include "rawpic.pb.h"
+#include "chassis.pb.h"
+#include "brainstate.pb.h"
+#include "gpsimu.pb.h"
+
 extern std::string gstrserverip;
 extern std::string gstruploadPort;
 extern std::string gstruploadInterval;
@@ -26,6 +32,7 @@ struct msgunit
     int mnkeeptime = 100;
 };
 }
+
 extern iv::msgunit shmPicFront;
 extern iv::msgunit shmPicRear;
 extern iv::msgunit shmPicLeft;
@@ -337,6 +344,30 @@ void DataExchangeClient::run()
 {
     QTime xTime;
     xTime.start();
+
+    QFile mileageFile;
+    mileageFile.setFileName("./mileage.txt");
+    uint64_t fileWriteTime = xTime.elapsed();
+    if(mileageFile.exists())
+    {
+        if(mileageFile.open(QIODevice::ReadOnly | QIODevice::Text))
+        {
+            mileage = mileageFile.readAll().toDouble();
+            std::cout<<"file open success. mileage is "<<mileage<<std::endl;
+        }
+        mileageFile.close();
+    }
+    else
+    {
+        if(mileageFile.open(QIODevice::WriteOnly | QIODevice::Text))
+        {
+            QString strMileage = QString::number(mileage,'f',4);
+            mileageFile.write(strMileage.toUtf8());
+        }
+        mileageFile.flush();
+        mileageFile.close();
+    }
+
     uint64_t lastTime = xTime.elapsed();
     uint64_t interval = std::atoi(gstruploadInterval.c_str());
     while (true)
@@ -348,6 +379,18 @@ void DataExchangeClient::run()
             std::cout<< reply <<std::endl;
             lastTime = xTime.elapsed();
         }
+
+        if((xTime.elapsed() - fileWriteTime) >= 2500)
+        {
+            if(mileageFile.open(QIODevice::WriteOnly | QIODevice::Text))
+            {
+                QString strMileage = QString::number(mileage,'f',4);
+                mileageFile.write(strMileage.toUtf8());
+            }
+            mileageFile.flush();
+            mileageFile.close();
+            fileWriteTime = xTime.elapsed();
+        }
     }
 }
 

+ 2 - 4
src/driver/driver_cloud_grpc_client_BS/vehicle_upload.h

@@ -17,9 +17,6 @@
 #include "VehicleUpload_service.grpc.pb.h"
 #include "VehicleUpload.grpc.pb.h"
 
-#include "modulecomm.h"
-#include "rawpic.pb.h"
-
 using grpc::Channel;
 using grpc::ClientContext;
 using grpc::Status;
@@ -57,10 +54,11 @@ private:
     std::unique_ptr<DataExchange::Stub> stub_;
 
     std::string id;
-    uint64_t timeStamp;
+    uint64_t timeStamp = QDateTime::currentMSecsSinceEpoch();
     double SOC; //0.0-100.0%
     VehicleStatus statusFeedback = VehicleStatus::STATUS_EMERGENCY_STOP;
     double mileage; // kilometer
+    uint64_t timeMileageRecord = QDateTime::currentMSecsSinceEpoch();
     double speed; // m/s
     org::jeecg::defsDetails::grpc::ShiftStatus shiftFeedback = org::jeecg::defsDetails::grpc::ShiftStatus::SHIFT_PARKING;
     double steeringWheelAngleFeedback; //+/-540 degree