123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- #include "vehicle_upload.h"
- #include <QDateTime>
- #include <QFile>
- extern std::string gstrserverip;
- extern std::string gstruploadPort;
- extern std::string gstruploadInterval;
- extern std::string gstrid;
- extern std::string gstrplateNumber;
- using org::jeecg::defsDetails::grpc::Empty; ///< other message
- using org::jeecg::defsDetails::grpc::GPSPoint;
- using org::jeecg::defsDetails::grpc::MapPoint;
- using org::jeecg::defsDetails::grpc::ShiftStatus; ///< other enum
- using org::jeecg::defsDetails::grpc::CtrlMode;
- DataExchangeClient::DataExchangeClient(std::shared_ptr<Channel> channel)
- {
- stub_ = DataExchange::NewStub(channel);
- uploadTimer = new QTimer();
- connect(uploadTimer,SIGNAL(timeout()),this,SLOT(uploadTimeout()));
- uploadTimer->start(std::atoi(gstruploadInterval.c_str()));
- }
- DataExchangeClient::~DataExchangeClient(void)
- {
- delete uploadTimer;
- }
- std::string DataExchangeClient::uploadVehicleInfo(void)
- {
- // Data we are sending to the server.
- UplinkRequest request;
- request.set_id(id);
- request.set_timestamp(timeStamp);
- request.set_soc(SOC);
- request.set_statusfeedback(statusFeedback);
- request.set_mileage(mileage);
- request.set_speed(speed);
- request.set_shiftfeedback(shiftFeedback);
- request.set_steeringwheelanglefeedback(steeringWheelAngleFeedback);
- request.set_throttlefeedback(throttleFeedback);
- request.set_brakefeedback(brakeFeedback);
- request.set_gpsrtkstatus(GPSRTKStatus);
- request.mutable_positionfeedback()->CopyFrom(positionFeedback);
- request.set_pitch(pitch);
- request.set_roll(roll);
- request.set_heading(heading);
- request.set_cameraimagefront(cameraImageFront.data(),cameraImageFront.size());
- request.set_cameraimagerear(cameraImageRear.data(),cameraImageRear.size());
- request.set_cameraimageleft(cameraImageLeft.data(),cameraImageLeft.size());
- request.set_cameraimageright(cameraImageRight.data(),cameraImageRight.size());
- request.set_sensorstatusgpsimu(sensorStatusGPSIMU);
- request.set_sensorstatuslidar(sensorStatusLidar);
- request.set_sensorstatusradar(sensorStatusRadar);
- request.set_sensorstatuscamfront(sensorStatusCamFront);
- request.set_sensorstatuscamrear(sensorStatusCamRear);
- request.set_sensorstatuscamleft(sensorStatusCamLeft);
- request.set_sensorstatuscamright(sensorStatusCamRight);
- request.set_isarrived(isArrived);
- request.set_platenumber(plateNumber);
- request.set_modefeedback(modeFeedback);
- // Container for the data we expect from the server.
- ResponseMessage reply;
- // Context for the client. It could be used to convey extra information to
- // the server and/or tweak certain RPC behaviors.
- ClientContext context;
- // The actual RPC.
- Status status = stub_ -> uploadVehicleInfo(&context, request, &reply);
- // Act upon its status.
- if (status.ok()) {
- destinationPosition.CopyFrom(reply.destinationposition());
- // std::cout<<"lat:"<<destinationPosition.latitude()<<"lon:"<<destinationPosition.longitude()<<"height:"<<destinationPosition.height()<<std::endl;
- return "uploadVehicleInfo RPC successed";
- } else {
- std::cout << status.error_code() << ": " << status.error_message()
- << std::endl;
- return "uploadVehicleInfo RPC failed";
- }
- }
- std::string DataExchangeClient::uploadPath(void)
- {
- // Data we are sending to the server.
- UploadPathRequest request;
- request.set_id(id);
- request.set_patrolpathid(patrolPathID);
- for(int i = 0;i < pathPoints.size();i++)
- {
- request.add_pathpoints();
- request.mutable_pathpoints(i)->operator =(pathPoints.at(i));
- }
- // Container for the data we expect from the server.
- Empty reply;
- // Context for the client. It could be used to convey extra information to
- // the server and/or tweak certain RPC behaviors.
- ClientContext context;
- // The actual RPC.
- Status status = stub_ -> uploadPath(&context,request,&reply);
- // Act upon its status.
- if (status.ok()) {
- if(reply.id() == gstrid)
- {
- std::cout<<"Path uploaded by car id:"<<reply.id()<<std::endl;
- }
- return "uploadPath RPC successed";
- } else {
- std::cout << status.error_code() << ": " << status.error_message()
- << std::endl;
- return "uploadPath RPC failed";
- }
- }
- void DataExchangeClient::updateData(void)
- {
- id = gstrid;
- timeStamp = QDateTime::currentMSecsSinceEpoch();
- SOC = 86.5;
- statusFeedback = VehicleStatus::STATUS_REMOTE;
- mileage = 123.45; // kilometer
- speed = 0.1; // 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/samuel/Pictures/123.jpg");
- // if(xFile.open(QIODevice::ReadOnly))
- // {
- // cameraImageFront = xFile.readAll();
- // }
- // xFile.close();
- // xFile.setFileName("/home/samuel/Pictures/123.jpg");
- // if(xFile.open(QIODevice::ReadOnly))
- // {
- // cameraImageRear = xFile.readAll();
- // }
- // xFile.close();
- // xFile.setFileName("/home/samuel/Pictures/123.jpg");
- // if(xFile.open(QIODevice::ReadOnly))
- // {
- // cameraImageLeft = xFile.readAll();
- // }
- // xFile.close();
- // xFile.setFileName("/home/samuel/Pictures/123.jpg");
- // if(xFile.open(QIODevice::ReadOnly))
- // {
- // cameraImageRight = xFile.readAll();
- // }
- // xFile.close();
- sensorStatusGPSIMU = false; //0 GPS-IMU ok 1 GPS-IMU error
- sensorStatusLidar = false;
- sensorStatusRadar = false;
- sensorStatusCamFront = false;
- sensorStatusCamRear = false;
- sensorStatusCamLeft = false;
- sensorStatusCamRight = false;
- isArrived = 0; //0 no destination 1 not arrived 2 arrived
- plateNumber = gstrplateNumber;
- modeFeedback = CtrlMode::CMD_REMOTE; //mode Feedback
- }
- void DataExchangeClient::updatePath(std::string pathID, QVector<MapPoint> points)
- {
- id = gstrid;
- patrolPathID = pathID;
- pathPoints.clear();
- for(int i = 0;i < points.size();i++)
- {
- pathPoints.append(points.value(i));
- // std::cout<<pathPoints.at(i).index()<<std::endl;
- }
- }
- void DataExchangeClient::uploadTimeout(void)
- {
- updateData();
- std::string reply = uploadVehicleInfo();
- std::cout<< reply <<std::endl;
- }
|