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

fix(grpc_BS):fix new version module communicate error

孙嘉城 4 роки тому
батько
коміт
05c81d59fe

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

@@ -35,10 +35,7 @@ VehicleControlClient::VehicleControlClient(std::shared_ptr<Channel> channel)
 {
     stub_ = VehicleControl::NewStub(channel);
 
-    mpa = new iv::modulecommext::modulecommmsg<iv::remotectrl>();
-
-    std::cout<<shmRemoteCtrl.mstrmsgname<<"---"<<shmRemoteCtrl.mnBufferSize<<"---"<<shmRemoteCtrl.mnBufferCount<<std::endl;
-    mpa->RegisterSend(shmRemoteCtrl.mstrmsgname,shmRemoteCtrl.mnBufferSize,shmRemoteCtrl.mnBufferCount);
+    shmRemoteCtrl.mpa = iv::modulecomm::RegisterSend(shmRemoteCtrl.mstrmsgname,shmRemoteCtrl.mnBufferSize,shmRemoteCtrl.mnBufferCount);
 }
 
 VehicleControlClient::~VehicleControlClient(void)
@@ -46,11 +43,6 @@ VehicleControlClient::~VehicleControlClient(void)
 
 }
 
-void VehicleControlClient::VehicleControlClientSend(void)
-{
-
-}
-
 std::string VehicleControlClient::vehicleControl(void)
 {
     // Data we are sending to the server.
@@ -110,10 +102,10 @@ void VehicleControlClient::updateControlData(void)
     std::cout<<"throttle:"<<throttleCMD<<std::endl;
     std::cout<<"brake:"<<brakeCMD<<std::endl;
 #endif
-    std::cout<<"\n"<<"shift:"<<shiftCMD<<std::endl;
-    std::cout<<"steeringWheelAngle:"<<steeringWheelAngleCMD<<std::endl;
-    std::cout<<"throttle:"<<throttleCMD<<std::endl;
-    std::cout<<"brake:"<<brakeCMD<<"\n"<<std::endl;
+//    std::cout<<"\n"<<"shift:"<<shiftCMD<<std::endl;
+//    std::cout<<"steeringWheelAngle:"<<steeringWheelAngleCMD<<std::endl;
+//    std::cout<<"throttle:"<<throttleCMD<<std::endl;
+//    std::cout<<"brake:"<<brakeCMD<<"\n"<<std::endl;
     iv::remotectrl xmsg;
     if(modeCMD == CtrlMode::CMD_REMOTE || modeCMD == CtrlMode::CMD_CLOUD_PLATFORM)
         xmsg.set_ntype(iv::remotectrl::CtrlType::remotectrl_CtrlType_REMOTE);
@@ -150,7 +142,15 @@ void VehicleControlClient::updateControlData(void)
         xmsg.set_shift(0);
     }
 
-    mpa->ModuleSendMsg(xmsg);
+    int ndatasize = xmsg.ByteSize();
+    char * str = new char[ndatasize];
+    std::shared_ptr<char> pstr;pstr.reset(str);
+    if(!xmsg.SerializeToArray(str,ndatasize))
+    {
+        std::cout<<"MainWindow::on_horizontalSlider_valueChanged serialize error."<<std::endl;
+        return;
+    }
+    iv::modulecomm::ModuleSendMsg(shmRemoteCtrl.mpa,str,ndatasize);
 }
 
 void VehicleControlClient::run()

+ 1 - 4
src/driver/driver_cloud_grpc_client_BS/vehicle_control.h

@@ -16,7 +16,7 @@
 #include "VehicleControl_service.grpc.pb.h"
 #include "VehicleControl.grpc.pb.h"
 
-#include "modulecommext.h"
+#include "modulecomm.h"
 #include "remotectrl.pb.h"
 
 using grpc::Channel;
@@ -40,9 +40,6 @@ public:
     std::string vehicleControl(void);
     void updateControlData(void);
 
-    void VehicleControlClientSend();
-    iv::modulecommext::modulecommmsg<iv::remotectrl> * mpa;
-
 protected:
     void run();
 

+ 18 - 13
src/driver/driver_cloud_grpc_client_BS/vehicle_upload.cpp

@@ -36,14 +36,20 @@ using org::jeecg::defsDetails::grpc::MapPoint;
 using org::jeecg::defsDetails::grpc::ShiftStatus; ///< other enum
 using org::jeecg::defsDetails::grpc::CtrlMode;
 
+DataExchangeClient * gDataExchangeClient;
+
+void ListenData(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
+{
+    gDataExchangeClient->ListenPicMsg(strdata,nSize);
+}
+
 DataExchangeClient::DataExchangeClient(std::shared_ptr<Channel> channel)
 {
-    stub_ = DataExchange::NewStub(channel);
+    gDataExchangeClient = this;
 
-    mpa = new iv::modulecommext::modulecommmsg<iv::vision::rawpic>();
+    stub_ = DataExchange::NewStub(channel);
 
-    ModuleExtFun funext = std::bind(&DataExchangeClient::ListenPicMsg,this,std::placeholders::_1);
-    mpa->RegisterRecvPlus(shmPicFront.mstrmsgname,funext);
+    shmPicFront.mpa = iv::modulecomm::RegisterRecv(shmPicFront.mstrmsgname,ListenData);
 }
 
 DataExchangeClient::~DataExchangeClient(void)
@@ -51,20 +57,19 @@ DataExchangeClient::~DataExchangeClient(void)
 
 }
 
-void DataExchangeClient::CameraPicRecv()
+void DataExchangeClient::ListenPicMsg(const char * strdata,const unsigned int nSize) // need a lock
 {
+    iv::vision::rawpic xdata;
+    if(!xdata.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<" MainWindow::UpdateSlider parese error."<<std::endl;
+        return;
+    }
 
-}
-
-void DataExchangeClient::ListenPicMsg(google::protobuf::Message &xmsg) // need a lock
-{
-    iv::vision::rawpic  xdata;
-    xdata.CopyFrom(xmsg);
     gMutex_ImageFront.lock();
     cameraImageFront.clear();
-    cameraImageFront.append(xdata.picdata().data());
+    cameraImageFront.fromStdString(xdata.picdata());
     gMutex_ImageFront.unlock();
-//    qDebug("fastrtps: %lld",xdata.time());
 }
 
 std::string DataExchangeClient::uploadVehicleInfo(void)

+ 3 - 7
src/driver/driver_cloud_grpc_client_BS/vehicle_upload.h

@@ -16,7 +16,8 @@
 
 #include "VehicleUpload_service.grpc.pb.h"
 #include "VehicleUpload.grpc.pb.h"
-#include "modulecommext.h"
+
+#include "modulecomm.h"
 #include "rawpic.pb.h"
 
 using grpc::Channel;
@@ -44,17 +45,12 @@ public:
     void updateData(void);
     void updatePath(std::string pathID,QVector<org::jeecg::defsDetails::grpc::MapPoint> points);
 
-    void CameraPicRecv();
-    iv::modulecommext::modulecommmsg<iv::vision::rawpic> * mpa;
-
+    void ListenPicMsg(const char * strdata,const unsigned int nSize);
 
 protected:
     void run();
 
 private:
-
-    void ListenPicMsg(google::protobuf::Message & xmsg);
-
     std::unique_ptr<DataExchange::Stub> stub_;
 
     std::string id;