vehicle_upload.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #include "vehicle_upload.h"
  2. #include <QDateTime>
  3. #include <QFile>
  4. extern std::string gstrserverip;
  5. extern std::string gstruploadPort;
  6. extern std::string gstruploadInterval;
  7. extern std::string gstrid;
  8. extern std::string gstrplateNumber;
  9. using org::jeecg::defsDetails::grpc::Empty; ///< other message
  10. using org::jeecg::defsDetails::grpc::GPSPoint;
  11. using org::jeecg::defsDetails::grpc::MapPoint;
  12. using org::jeecg::defsDetails::grpc::ShiftStatus; ///< other enum
  13. using org::jeecg::defsDetails::grpc::CtrlMode;
  14. DataExchangeClient::DataExchangeClient(std::shared_ptr<Channel> channel)
  15. {
  16. stub_ = DataExchange::NewStub(channel);
  17. uploadTimer = new QTimer();
  18. connect(uploadTimer,SIGNAL(timeout()),this,SLOT(uploadTimeout()));
  19. uploadTimer->start(std::atoi(gstruploadInterval.c_str()));
  20. }
  21. DataExchangeClient::~DataExchangeClient(void)
  22. {
  23. delete uploadTimer;
  24. }
  25. std::string DataExchangeClient::uploadVehicleInfo(void)
  26. {
  27. // Data we are sending to the server.
  28. UplinkRequest request;
  29. request.set_id(id);
  30. request.set_timestamp(timeStamp);
  31. request.set_soc(SOC);
  32. request.set_statusfeedback(statusFeedback);
  33. request.set_mileage(mileage);
  34. request.set_speed(speed);
  35. request.set_shiftfeedback(shiftFeedback);
  36. request.set_steeringwheelanglefeedback(steeringWheelAngleFeedback);
  37. request.set_throttlefeedback(throttleFeedback);
  38. request.set_brakefeedback(brakeFeedback);
  39. request.set_gpsrtkstatus(GPSRTKStatus);
  40. request.mutable_positionfeedback()->CopyFrom(positionFeedback);
  41. request.set_pitch(pitch);
  42. request.set_roll(roll);
  43. request.set_heading(heading);
  44. request.set_cameraimagefront(cameraImageFront.data(),cameraImageFront.size());
  45. request.set_cameraimagerear(cameraImageRear.data(),cameraImageRear.size());
  46. request.set_cameraimageleft(cameraImageLeft.data(),cameraImageLeft.size());
  47. request.set_cameraimageright(cameraImageRight.data(),cameraImageRight.size());
  48. request.set_sensorstatusgpsimu(sensorStatusGPSIMU);
  49. request.set_sensorstatuslidar(sensorStatusLidar);
  50. request.set_sensorstatusradar(sensorStatusRadar);
  51. request.set_sensorstatuscamfront(sensorStatusCamFront);
  52. request.set_sensorstatuscamrear(sensorStatusCamRear);
  53. request.set_sensorstatuscamleft(sensorStatusCamLeft);
  54. request.set_sensorstatuscamright(sensorStatusCamRight);
  55. request.set_isarrived(isArrived);
  56. request.set_platenumber(plateNumber);
  57. request.set_modefeedback(modeFeedback);
  58. // Container for the data we expect from the server.
  59. ResponseMessage reply;
  60. // Context for the client. It could be used to convey extra information to
  61. // the server and/or tweak certain RPC behaviors.
  62. ClientContext context;
  63. // The actual RPC.
  64. Status status = stub_ -> uploadVehicleInfo(&context, request, &reply);
  65. // Act upon its status.
  66. if (status.ok()) {
  67. destinationPosition.CopyFrom(reply.destinationposition());
  68. // std::cout<<"lat:"<<destinationPosition.latitude()<<"lon:"<<destinationPosition.longitude()<<"height:"<<destinationPosition.height()<<std::endl;
  69. return "uploadVehicleInfo RPC successed";
  70. } else {
  71. std::cout << status.error_code() << ": " << status.error_message()
  72. << std::endl;
  73. return "uploadVehicleInfo RPC failed";
  74. }
  75. }
  76. std::string DataExchangeClient::uploadPath(void)
  77. {
  78. // Data we are sending to the server.
  79. UploadPathRequest request;
  80. request.set_id(id);
  81. request.set_patrolpathid(patrolPathID);
  82. for(int i = 0;i < pathPoints.size();i++)
  83. {
  84. request.add_pathpoints();
  85. request.mutable_pathpoints(i)->operator =(pathPoints.at(i));
  86. }
  87. // Container for the data we expect from the server.
  88. Empty reply;
  89. // Context for the client. It could be used to convey extra information to
  90. // the server and/or tweak certain RPC behaviors.
  91. ClientContext context;
  92. // The actual RPC.
  93. Status status = stub_ -> uploadPath(&context,request,&reply);
  94. // Act upon its status.
  95. if (status.ok()) {
  96. if(reply.id() == gstrid)
  97. {
  98. std::cout<<"Path uploaded by car id:"<<reply.id()<<std::endl;
  99. }
  100. return "uploadPath RPC successed";
  101. } else {
  102. std::cout << status.error_code() << ": " << status.error_message()
  103. << std::endl;
  104. return "uploadPath RPC failed";
  105. }
  106. }
  107. void DataExchangeClient::updateData(void)
  108. {
  109. id = gstrid;
  110. timeStamp = QDateTime::currentMSecsSinceEpoch();
  111. SOC = 86.5;
  112. statusFeedback = VehicleStatus::STATUS_REMOTE;
  113. mileage = 123.45; // kilometer
  114. speed = 0.1; // m/s
  115. shiftFeedback = ShiftStatus::SHIFT_DRIVE;
  116. steeringWheelAngleFeedback = 1.23; //+/-540 degree
  117. throttleFeedback = 0.12;
  118. brakeFeedback = 0.34;
  119. GPSRTKStatus = 6; //GPS-RTK status 0-6 6 is best
  120. positionFeedback.set_latitude(39.0666552);
  121. positionFeedback.set_longitude(117.3540963);
  122. positionFeedback.set_height(0.84);
  123. pitch = 0.03;
  124. roll = 0.02;
  125. heading = 198.4;
  126. // QFile xFile;
  127. // xFile.setFileName("/home/samuel/Pictures/123.jpg");
  128. // if(xFile.open(QIODevice::ReadOnly))
  129. // {
  130. // cameraImageFront = xFile.readAll();
  131. // }
  132. // xFile.close();
  133. // xFile.setFileName("/home/samuel/Pictures/123.jpg");
  134. // if(xFile.open(QIODevice::ReadOnly))
  135. // {
  136. // cameraImageRear = xFile.readAll();
  137. // }
  138. // xFile.close();
  139. // xFile.setFileName("/home/samuel/Pictures/123.jpg");
  140. // if(xFile.open(QIODevice::ReadOnly))
  141. // {
  142. // cameraImageLeft = xFile.readAll();
  143. // }
  144. // xFile.close();
  145. // xFile.setFileName("/home/samuel/Pictures/123.jpg");
  146. // if(xFile.open(QIODevice::ReadOnly))
  147. // {
  148. // cameraImageRight = xFile.readAll();
  149. // }
  150. // xFile.close();
  151. sensorStatusGPSIMU = false; //0 GPS-IMU ok 1 GPS-IMU error
  152. sensorStatusLidar = false;
  153. sensorStatusRadar = false;
  154. sensorStatusCamFront = false;
  155. sensorStatusCamRear = false;
  156. sensorStatusCamLeft = false;
  157. sensorStatusCamRight = false;
  158. isArrived = 0; //0 no destination 1 not arrived 2 arrived
  159. plateNumber = gstrplateNumber;
  160. modeFeedback = CtrlMode::CMD_REMOTE; //mode Feedback
  161. }
  162. void DataExchangeClient::updatePath(std::string pathID, QVector<MapPoint> points)
  163. {
  164. id = gstrid;
  165. patrolPathID = pathID;
  166. pathPoints.clear();
  167. for(int i = 0;i < points.size();i++)
  168. {
  169. pathPoints.append(points.value(i));
  170. // std::cout<<pathPoints.at(i).index()<<std::endl;
  171. }
  172. }
  173. void DataExchangeClient::uploadTimeout(void)
  174. {
  175. updateData();
  176. std::string reply = uploadVehicleInfo();
  177. std::cout<< reply <<std::endl;
  178. }