#include "vehicle_patrol.h" #include #include #include "modulecomm.h" #include "gpsimu.pb.h" extern std::string gstrserverip; extern std::string gstrpatrolPort; extern std::string gstrpatrolInterval; extern std::string gstrid; extern std::string gstrplateNumber; extern char stryamlpath[256]; using org::jeecg::defsPatrol::grpc::Empty; using org::jeecg::defsPatrol::grpc::GPSPoint; VehiclePatrolExceptionClient::VehiclePatrolExceptionClient(std::shared_ptr channel) { stub_ = VehiclePatrolException::NewStub(channel); dec_yaml(stryamlpath); ModuleFun funupdate = std::bind(&VehiclePatrolExceptionClient::ListenGPSIMUMsg,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5); shmGPSIMU.mpa = iv::modulecomm::RegisterRecvPlus(shmGPSIMU.mstrmsgname,funupdate); } VehiclePatrolExceptionClient::~VehiclePatrolExceptionClient(void) { } void VehiclePatrolExceptionClient::dec_yaml(const char *stryamlpath) { YAML::Node config; try { config = YAML::LoadFile(stryamlpath); } catch(YAML::BadFile &e) { std::cout<(); strncpy(shmGPSIMU.mstrmsgname,strmsgname.data(),255); shmGPSIMU.mnBufferSize = config["GPS_IMU"]["buffersize"].as(); shmGPSIMU.mnBufferCount = config["GPS_IMU"]["buffercount"].as(); std::cout << "GPS_IMU:" << shmGPSIMU.mstrmsgname << "," << shmGPSIMU.mnBufferSize << "," << shmGPSIMU.mnBufferCount << std::endl; } } else { strmsgname = "hcp2_gpsimu"; strncpy(shmGPSIMU.mstrmsgname,strmsgname.data(),255); shmGPSIMU.mnBufferSize = 10000; shmGPSIMU.mnBufferCount = 1; } return; } void VehiclePatrolExceptionClient::ListenGPSIMUMsg(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname) // need a lock { iv::gps::gpsimu xdata; if(!xdata.ParseFromArray(strdata,nSize)) { std::cout<<" ListenGPSIMUMsg parese error."<CopyFrom(violationPosition); request.set_isfsm(isFSM); request.set_firestatus(fireStatus); request.set_fireimage(fireImage.data(),fireImage.size()); request.set_firetime(fireTime); request.mutable_fireposition()->CopyFrom(firePosition); request.set_istsgm(isTSGM); request.set_gatestatus(gateStatus); request.set_gateimage(gateImage.data(),gateImage.size()); request.set_gatetime(gateTime); request.mutable_gateposition()->CopyFrom(gatePosition); request.set_platenumber(plateNumber); // 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; gpr_timespec timespec; timespec.tv_sec = 5; timespec.tv_nsec = 0; timespec.clock_type = GPR_TIMESPAN; context.set_deadline(timespec); // The actual RPC. Status status = stub_ -> uploadVehiclePatrolInfo(&context,request,&reply); // Act upon its status. if (status.ok()) { return "uploadVehiclePatrolInfo 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 "uploadVehiclePatrolInfo RPC failed"; } } void VehiclePatrolExceptionClient::updatePatrolData(void) { id = gstrid; // isTVR = true; // violationStatus = 2; // vehicleLicenseNumber = "津B654321"; // QFile xFile; // xFile.setFileName("/home/samuel/Pictures/123.jpg"); // if(xFile.open(QIODevice::ReadOnly)) // { // violationImage = xFile.readAll(); // } // xFile.close(); // violationTime = QDateTime::currentMSecsSinceEpoch(); // violationPosition.set_height(0.1); // violationPosition.set_latitude(39.0666552); // violationPosition.set_longitude(117.3542963); // isFSM = true; // fireStatus = 1; // xFile.setFileName("/home/samuel/Pictures/123.jpg"); // if(xFile.open(QIODevice::ReadOnly)) // { // fireImage = xFile.readAll(); // } // xFile.close(); // fireTime = QDateTime::currentMSecsSinceEpoch(); // firePosition.set_height(0.1); // firePosition.set_latitude(39.0667552); // firePosition.set_longitude(117.3542963); // isTSGM = true; // gateStatus = 2; // xFile.setFileName("/home/samuel/Pictures/123.jpg"); // if(xFile.open(QIODevice::ReadOnly)) // { // gateImage = xFile.readAll(); // } // xFile.close(); // gateTime = QDateTime::currentMSecsSinceEpoch(); // gatePosition.set_height(0.1); // gatePosition.set_latitude(39.0665552); // gatePosition.set_longitude(117.3542963); plateNumber = gstrplateNumber; } void VehiclePatrolExceptionClient::run() { QTime xTime; xTime.start(); int lastTime = xTime.elapsed(); uint64_t interval = std::atoi(gstrpatrolInterval.c_str()); while (true) { if(abs(xTime.elapsed() - lastTime)>=interval) { updatePatrolData(); std::string reply = uploadVehiclePatrolInfo(); std::cout<< reply <