#include "vehicle_patrol.h" #include #include #include #include "modulecomm.h" #include "gpsimu.pb.h" #include "licenseplate.pb.h" #include "startturnstile.pb.h" #include "turnstile.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); // funupdate = std::bind(&VehiclePatrolExceptionClient::ListenTurnstileMsg,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5); // shmTurnstile.mpa = iv::modulecomm::RegisterRecvPlus(shmTurnstile.mstrmsgname,funupdate); // shmStartTurnstile.mpa = iv::modulecomm::RegisterSend(shmStartTurnstile.mstrmsgname,shmStartTurnstile.mnBufferSize,shmStartTurnstile.mnBufferCount); } VehiclePatrolExceptionClient::~VehiclePatrolExceptionClient(void) { if(shmGPSIMU.mpa != nullptr)iv::modulecomm::Unregister(shmGPSIMU.mpa); requestInterruption(); while(this->isFinished() == false); } 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; } if(config["pic_front"]) { if(config["pic_front"]["msgname"]&&config["pic_front"]["buffersize"]&&config["pic_front"]["buffercount"]) { strmsgname = config["pic_front"]["msgname"].as(); strncpy(shmPicFront.mstrmsgname,strmsgname.data(),255); shmPicFront.mnBufferSize = config["pic_front"]["buffersize"].as(); shmPicFront.mnBufferCount = config["pic_front"]["buffercount"].as(); std::cout << "pic_front:" << shmPicFront.mstrmsgname << "," << shmPicFront.mnBufferSize << "," << shmPicFront.mnBufferCount << std::endl; } } else { strmsgname = "picfront"; strncpy(shmPicFront.mstrmsgname,strmsgname.data(),255); shmPicFront.mnBufferSize = 10000000; shmPicFront.mnBufferCount = 1; } if(config["pic_rear"]) { if(config["pic_rear"]["msgname"]&&config["pic_rear"]["buffersize"]&&config["pic_rear"]["buffercount"]) { strmsgname = config["pic_rear"]["msgname"].as(); strncpy(shmPicRear.mstrmsgname,strmsgname.data(),255); shmPicRear.mnBufferSize = config["pic_rear"]["buffersize"].as(); shmPicRear.mnBufferCount = config["pic_rear"]["buffercount"].as(); std::cout << "pic_rear:" << shmPicRear.mstrmsgname << "," << shmPicRear.mnBufferSize << "," << shmPicRear.mnBufferCount << std::endl; } } else { strmsgname = "picrear"; strncpy(shmPicRear.mstrmsgname,strmsgname.data(),255); shmPicRear.mnBufferSize = 10000000; shmPicRear.mnBufferCount = 1; } if(config["pic_left"]) { if(config["pic_left"]["msgname"]&&config["pic_left"]["buffersize"]&&config["pic_left"]["buffercount"]) { strmsgname = config["pic_left"]["msgname"].as(); strncpy(shmPicLeft.mstrmsgname,strmsgname.data(),255); shmPicLeft.mnBufferSize = config["pic_left"]["buffersize"].as(); shmPicLeft.mnBufferCount = config["pic_left"]["buffercount"].as(); std::cout << "pic_left:" << shmPicLeft.mstrmsgname << "," << shmPicLeft.mnBufferSize << "," << shmPicLeft.mnBufferCount << std::endl; } } else { strmsgname = "picleft"; strncpy(shmPicLeft.mstrmsgname,strmsgname.data(),255); shmPicLeft.mnBufferSize = 10000000; shmPicLeft.mnBufferCount = 1; } if(config["pic_right"]) { if(config["pic_right"]["msgname"]&&config["pic_right"]["buffersize"]&&config["pic_right"]["buffercount"]) { strmsgname = config["pic_right"]["msgname"].as(); strncpy(shmPicRight.mstrmsgname,strmsgname.data(),255); shmPicRight.mnBufferSize = config["pic_right"]["buffersize"].as(); shmPicRight.mnBufferCount = config["pic_right"]["buffercount"].as(); std::cout << "pic_right:" << shmPicRight.mstrmsgname << "," << shmPicRight.mnBufferSize << "," << shmPicRight.mnBufferCount << std::endl; } } else { strmsgname = "picright"; strncpy(shmPicRight.mstrmsgname,strmsgname.data(),255); shmPicRight.mnBufferSize = 10000000; shmPicRight.mnBufferCount = 1; } if(config["start_turnstile"]) { if(config["start_turnstile"]["msgname"]&&config["start_turnstile"]["buffersize"]&&config["start_turnstile"]["buffercount"]) { strmsgname = config["start_turnstile"]["msgname"].as(); strncpy(shmStartTurnstile.mstrmsgname,strmsgname.data(),255); shmStartTurnstile.mnBufferSize = config["start_turnstile"]["buffersize"].as(); shmStartTurnstile.mnBufferCount = config["start_turnstile"]["buffercount"].as(); std::cout << "start_turnstile:" << shmStartTurnstile.mstrmsgname << "," << shmStartTurnstile.mnBufferSize << "," << shmStartTurnstile.mnBufferCount << std::endl; } } else { strmsgname = "startturnstile"; strncpy(shmStartTurnstile.mstrmsgname,strmsgname.data(),255); shmStartTurnstile.mnBufferSize = 10000; shmStartTurnstile.mnBufferCount = 1; } if(config["turnstile"]) { if(config["turnstile"]["msgname"]&&config["turnstile"]["buffersize"]&&config["turnstile"]["buffercount"]) { strmsgname = config["turnstile"]["msgname"].as(); strncpy(shmTurnstile.mstrmsgname,strmsgname.data(),255); shmTurnstile.mnBufferSize = config["turnstile"]["buffersize"].as(); shmTurnstile.mnBufferCount = config["turnstile"]["buffercount"].as(); std::cout << "turnstile:" << shmTurnstile.mstrmsgname << "," << shmTurnstile.mnBufferSize << "," << shmTurnstile.mnBufferCount << std::endl; } } else { strmsgname = "turnstile"; strncpy(shmTurnstile.mstrmsgname,strmsgname.data(),255); shmTurnstile.mnBufferSize = 10000000; shmTurnstile.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()); org::jeecg::defsPatrol::grpc::GPSPoint tempPosition; //set isNeedTSGM isNeedTSGM = true; //set gateDestination gateDestination.set_latitude(39.0665855); gateDestination.set_longitude(117.3554362); timerTSGM.start(); while (!QThread::isInterruptionRequested()) { if(abs(xTime.elapsed() - lastTime)>=interval) { // do something mutex_GPSIMU.lock(); tempPosition.CopyFrom(currentPosition); double tempSpeed = currentSpeed; mutex_GPSIMU.unlock(); if(fabs(tempPosition.latitude()-gateDestination.latitude()) < 0.0001 && fabs(tempPosition.longitude()-gateDestination.longitude()) < 0.0001) { if(tempSpeed < 0.1 && statusTSGM == 0 && isNeedTSGM == true) { std::cout<<"Send startTurnstile"< pstr;pstr.reset(str); if(!xmsg.SerializeToArray(str,ndatasize)) { std::cout<<"StartTurnstile serialize error."< 80000) { //timeout std::cout<<"Turnstile timeout"< pstr;pstr.reset(str); if(!xmsg.SerializeToArray(str,ndatasize)) { std::cout<<"StartTurnstile serialize error."< 0.0001 || fabs(tempPosition.longitude()-gateDestination.longitude()) > 0.0001) { std::cout<<"Turnstile detect finish"< pstr;pstr.reset(str); if(!xmsg.SerializeToArray(str,ndatasize)) { std::cout<<"StartTurnstile serialize error."<