#include "vehicle_control.h" extern std::string gstrserverip; extern std::string gstrcontrolPort; extern std::string gstrcontrolInterval; extern std::string gstruploadMapInterval; extern std::string gstrid; extern std::string gstrplateNumber; extern uint8_t gShift_Status;//3 p 4 r 5 n 6 d namespace iv { struct msgunit { char mstrmsgname[256]; int mnBufferSize = 10000; int mnBufferCount = 1; void * mpa; std::shared_ptr mpstrmsgdata; int mndatasize = 0; bool mbRefresh = false; bool mbImportant = false; int mnkeeptime = 100; }; } extern iv::msgunit shmRemoteCtrl; using org::jeecg::defsControl::grpc::Empty; ///< other message using org::jeecg::defsControl::grpc::GPSPoint; using org::jeecg::defsControl::grpc::MapPoint; using org::jeecg::defsControl::grpc::CtrlMode; ///< other enum using org::jeecg::defsControl::grpc::ShiftStatus; VehicleControlClient::VehicleControlClient(std::shared_ptr channel) { stub_ = VehicleControl::NewStub(channel); shmRemoteCtrl.mpa = iv::modulecomm::RegisterSend(shmRemoteCtrl.mstrmsgname,shmRemoteCtrl.mnBufferSize,shmRemoteCtrl.mnBufferCount); } VehicleControlClient::~VehicleControlClient(void) { } std::string VehicleControlClient::vehicleControl(void) { // Data we are sending to the server. Empty request; request.set_id(gstrid); // Container for the data we expect from the server. ControlReply reply; // Context for the client. It could be used to convey extra information to // the server and/or tweak certain RPC behaviors. ClientContext context; gpr_timespec timespec; timespec.tv_sec = 1; timespec.tv_nsec = 0; timespec.clock_type = GPR_TIMESPAN; context.set_deadline(timespec); // The actual RPC. Status status = stub_ -> vehicleControl(&context,request,&reply); // Act upon its status. if (status.ok()) { if(reply.id() == gstrid) { shiftCMD = reply.shiftcmd(); steeringWheelAngleCMD = reply.steeringwheelanglecmd(); throttleCMD = reply.throttlecmd(); std::cout<<"throttle:"< 0)throttleCMD -= 1.5; // if(throttleCMD <= 0)throttleCMD = 0; // if(brakeCMD > 0)brakeCMD -= 1.5; // if(brakeCMD <= 0)brakeCMD = 0; } return "vehicleControl RPC successed"; } else { std::cout << status.error_code() << ": " << status.error_message() << std::endl; if(status.error_code() == 4) { std::cout << "vehicleControl RPC connect timeout" << std::endl; } return "vehicleControl RPC failed"; } } void VehicleControlClient::updateControlData(void) { #if 0 std::cout<<"shift:"< pstr;pstr.reset(str); if(!xmsg.SerializeToArray(str,ndatasize)) { std::cout<<"MainWindow::on_horizontalSlider_valueChanged serialize error."<=interval) { std::string reply = vehicleControl(); std::cout<< reply < channel) { stub_ = VehicleControl::NewStub(channel); } VehicleChangeCtrlModeClient::~VehicleChangeCtrlModeClient(void) { } std::string VehicleChangeCtrlModeClient::changeCtrlMode(void) { // Data we are sending to the server. Empty request; request.set_id(gstrid); // Container for the data we expect from the server. CtrlModeReply reply; // Context for the client. It could be used to convey extra information to // the server and/or tweastd::cout<<"shift:"< changeCtrlMode(&context,request,&reply); // Act upon its status. if (status.ok()) { if(reply.id() == gstrid) { modeCMD = reply.modecmd(); } return "changeCtrlMode RPC successed"; } else { std::cout << status.error_code() << ": " << status.error_message() << std::endl; if(status.error_code() == 4) { std::cout << "vehicleControl RPC connect timeout" << std::endl; } return "changeCtrlMode RPC failed"; } } void VehicleChangeCtrlModeClient::updateCtrolMode(void) { // std::cout<<"modeCMD:"<=interval) { std::string reply = changeCtrlMode(); std::cout<< reply < channel) { stub_ = VehicleControl::NewStub(channel); } VehicleUploadMapClient::~VehicleUploadMapClient(void) { } std::string VehicleUploadMapClient::uploadMap(void) { // Data we are sending to the server. Empty request; request.set_id(gstrid); // Container for the data we expect from the server. UploadMapReply reply; // Context for the client. It could be used to convey extra information to // the server and/or tweak certain RPC behaviors. ClientContext context; gpr_timespec timespec; timespec.tv_sec = 2; timespec.tv_nsec = 0; timespec.clock_type = GPR_TIMESPAN; context.set_deadline(timespec); // The actual RPC. Status status = stub_ -> UploadMap(&context,request,&reply); // Act upon its status. if (status.ok()) { if(reply.id() == gstrid) { // std::cout<=interval) { if(isNeedMap == false) { std::string reply = uploadMap(); // std::cout<< reply <