123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- #include "vehicle_patrol.h"
- #include <QDateTime>
- #include <QFile>
- extern std::string gstrserverip;
- extern std::string gstrpatrolPort;
- extern std::string gstrpatrolInterval;
- extern std::string gstrid;
- extern std::string gstrplateNumber;
- using org::jeecg::defsPatrol::grpc::Empty;
- using org::jeecg::defsPatrol::grpc::GPSPoint;
- VehiclePatrolExceptionClient::VehiclePatrolExceptionClient(std::shared_ptr<Channel> channel)
- {
- stub_ = VehiclePatrolException::NewStub(channel);
- patrolTimer = new QTimer();
- connect(patrolTimer,SIGNAL(timeout()),this,SLOT(patrolTimeout()));
- // patrolTimer->start(std::atoi(gstrpatrolInterval.c_str()));
- }
- VehiclePatrolExceptionClient::~VehiclePatrolExceptionClient(void)
- {
- delete patrolTimer;
- }
- std::string VehiclePatrolExceptionClient::uploadVehiclePatrolInfo(void)
- {
- // Data we are sending to the server.
- PatrolRequest request;
- request.set_id(id);
- request.set_istvr(isTVR);
- request.set_violationstatus(violationStatus);
- request.set_vehiclelicensenumber(vehicleLicenseNumber);
- request.set_violationimage(violationImage.data(),violationImage.size());
- request.mutable_violationposition()->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;
- // 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;
- 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::patrolTimeout(void)
- {
- updatePatrolData();
- uploadVehiclePatrolInfo();
- }
|