Browse Source

feat(grpc_BS):add turnstile recognition, but it has not been tested yet.

孙嘉城 3 years ago
parent
commit
4ab19e6e0e

+ 6 - 2
src/driver/driver_cloud_grpc_client_BS/driver_cloud_grpc_client_BS.pro

@@ -39,7 +39,9 @@ SOURCES += \
         ../../include/msgtype/chassis.pb.cc \
         ../../include/msgtype/gpsimu.pb.cc \
         ../../include/msgtype/platform_feedback.pb.cc \
-        ../../include/msgtype/rawpic.pb.cc
+        ../../include/msgtype/rawpic.pb.cc \
+        ../../include/msgtype/startturnstile.pb.cc \
+        ../../include/msgtype/turnstile.pb.cc
 
 
 # Default rules for deployment.
@@ -88,6 +90,8 @@ HEADERS += \
         ../../include/msgtype/chassis.pb.h \
         ../../include/msgtype/gpsimu.pb.h \
         ../../include/msgtype/platform_feedback.pb.h \
-        ../../include/msgtype/rawpic.pb.h
+        ../../include/msgtype/rawpic.pb.h \
+        ../../include/msgtype/startturnstile.pb.h \
+        ../../include/msgtype/turnstile.pb.h
 
 #before compile in ubuntu20.04 : sudo apt install libyaml-cpp-dev libgrpc++-dev

+ 9 - 0
src/driver/driver_cloud_grpc_client_BS/driver_cloud_grpc_client_BS.yaml

@@ -43,3 +43,12 @@ GPS_IMU:
   msgname: hcp2_gpsimu
   buffersize: 10000
   buffercount: 1
+start_turnstile:
+  msgname: startturnstile
+  buffersize: 10000
+  buffercount: 1
+turnstile:
+  msgname: turnstile
+  buffersize: 10000000
+  buffercount: 1
+

+ 245 - 2
src/driver/driver_cloud_grpc_client_BS/vehicle_patrol.cpp

@@ -5,6 +5,9 @@
 
 #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;
@@ -25,6 +28,10 @@ VehiclePatrolExceptionClient::VehiclePatrolExceptionClient(std::shared_ptr<Chann
 
     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)
@@ -75,6 +82,120 @@ void VehiclePatrolExceptionClient::dec_yaml(const char *stryamlpath)
         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<std::string>();
+            strncpy(shmPicFront.mstrmsgname,strmsgname.data(),255);
+            shmPicFront.mnBufferSize = config["pic_front"]["buffersize"].as<int>();
+            shmPicFront.mnBufferCount = config["pic_front"]["buffercount"].as<int>();
+            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<std::string>();
+            strncpy(shmPicRear.mstrmsgname,strmsgname.data(),255);
+            shmPicRear.mnBufferSize = config["pic_rear"]["buffersize"].as<int>();
+            shmPicRear.mnBufferCount = config["pic_rear"]["buffercount"].as<int>();
+            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<std::string>();
+            strncpy(shmPicLeft.mstrmsgname,strmsgname.data(),255);
+            shmPicLeft.mnBufferSize = config["pic_left"]["buffersize"].as<int>();
+            shmPicLeft.mnBufferCount = config["pic_left"]["buffercount"].as<int>();
+            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<std::string>();
+            strncpy(shmPicRight.mstrmsgname,strmsgname.data(),255);
+            shmPicRight.mnBufferSize = config["pic_right"]["buffersize"].as<int>();
+            shmPicRight.mnBufferCount = config["pic_right"]["buffercount"].as<int>();
+            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<std::string>();
+            strncpy(shmStartTurnstile.mstrmsgname,strmsgname.data(),255);
+            shmStartTurnstile.mnBufferSize = config["start_turnstile"]["buffersize"].as<int>();
+            shmStartTurnstile.mnBufferCount = config["start_turnstile"]["buffercount"].as<int>();
+            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<std::string>();
+            strncpy(shmTurnstile.mstrmsgname,strmsgname.data(),255);
+            shmTurnstile.mnBufferSize = config["turnstile"]["buffersize"].as<int>();
+            shmTurnstile.mnBufferCount = config["turnstile"]["buffercount"].as<int>();
+            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;
 }
 
@@ -87,14 +208,45 @@ void VehiclePatrolExceptionClient::ListenGPSIMUMsg(const char * strdata,const un
         return;
     }
 
-    gMutex_GPSIMU.lock();
+    double speed = sqrt(xdata.ve()*xdata.ve() + xdata.vn()*xdata.vn() + xdata.vd()*xdata.vd());
+
+    mutex_GPSIMU.lock();
     currentPosition.set_latitude(xdata.lat());
     currentPosition.set_longitude(xdata.lon());
     currentPosition.set_height(xdata.height());
-    gMutex_GPSIMU.unlock();
+    currentSpeed = speed;
+    mutex_GPSIMU.unlock();
 
 }
 
+void VehiclePatrolExceptionClient::ListenTurnstileMsg(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname) // need a lock
+{
+    iv::vision::turnstile xdata;
+    if(!xdata.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<" ListenTurnstileMsg parese error."<<std::endl;
+        return;
+    }
+
+    if(statusTSGM == 1)
+    {
+        //set TSGM resul
+        isTSGM = true;
+        if(xdata.state() == false)
+            gateStatus = 1; //0 no gate 1 gate close 2 gate open
+        else
+            gateStatus = 2;
+        gateImage.clear();
+        gateImage.append(xdata.pic().picdata().data(),xdata.pic().picdata().size());
+        gateTime = QDateTime::currentMSecsSinceEpoch(); //time when get gateImage
+        mutex_GPSIMU.lock();
+        gatePosition.CopyFrom(currentPosition); //positon when get gateImage
+        mutex_GPSIMU.unlock();
+
+        timerTSGM.restart();
+        statusTSGM = 2;
+    }
+}
 
 std::string VehiclePatrolExceptionClient::uploadVehiclePatrolInfo(void)
 {
@@ -212,10 +364,101 @@ void VehiclePatrolExceptionClient::run()
     xTime.start();
     int lastTime = xTime.elapsed();
     uint64_t interval = std::atoi(gstrpatrolInterval.c_str());
+    //set isNeedTSGM
+    //set gateDestination
+    timerTSGM.start();
     while (!QThread::isInterruptionRequested())
     {
         if(abs(xTime.elapsed() - lastTime)>=interval)
         {
+            // do something
+            mutex_GPSIMU.lock();
+            org::jeecg::defsPatrol::grpc::GPSPoint tempPosition;
+            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)
+                {
+                    iv::vision::startturnstile xmsg;
+
+                    xmsg.set_time(QDateTime::currentMSecsSinceEpoch());
+                    xmsg.set_cameraname(shmPicLeft.mstrmsgname);
+                    xmsg.set_start(true);
+
+                    int ndatasize = xmsg.ByteSize();
+                    char * str = new char[ndatasize];
+                    std::shared_ptr<char> pstr;pstr.reset(str);
+                    if(!xmsg.SerializeToArray(str,ndatasize))
+                    {
+                        std::cout<<"StartTurnstile serialize error."<<std::endl;
+                        return;
+                    }
+                    iv::modulecomm::ModuleSendMsg(shmStartTurnstile.mpa,str,ndatasize);
+                    statusTSGM = 1;
+                    timerTSGM.restart();
+                }
+            }
+
+            if(statusTSGM == 1 && timerTSGM.elapsed() > 60000)
+            {
+                //timeout
+                iv::vision::startturnstile xmsg;
+
+                xmsg.set_time(QDateTime::currentMSecsSinceEpoch());
+                xmsg.set_cameraname(shmPicLeft.mstrmsgname);
+                xmsg.set_start(false);
+
+                int ndatasize = xmsg.ByteSize();
+                char * str = new char[ndatasize];
+                std::shared_ptr<char> pstr;pstr.reset(str);
+                if(!xmsg.SerializeToArray(str,ndatasize))
+                {
+                    std::cout<<"StartTurnstile serialize error."<<std::endl;
+                    return;
+                }
+                iv::modulecomm::ModuleSendMsg(shmStartTurnstile.mpa,str,ndatasize);
+
+                isTSGM = false;
+                gateStatus = 0;
+                gateImage.clear();
+                gateTime = QDateTime::currentMSecsSinceEpoch();
+                mutex_GPSIMU.lock();
+                gatePosition.CopyFrom(currentPosition);
+                mutex_GPSIMU.unlock();
+
+                timerTSGM.restart();
+                statusTSGM = 3;
+            }
+
+            if(statusTSGM == 2 || statusTSGM == 3)
+            {
+                if(fabs(tempPosition.latitude()-gateDestination.latitude()) > 0.0001 && fabs(tempPosition.longitude()-gateDestination.longitude()) > 0.0001)
+                {
+                    iv::vision::startturnstile xmsg;
+
+                    xmsg.set_time(QDateTime::currentMSecsSinceEpoch());
+                    xmsg.set_cameraname(shmPicLeft.mstrmsgname);
+                    xmsg.set_start(false);
+
+                    int ndatasize = xmsg.ByteSize();
+                    char * str = new char[ndatasize];
+                    std::shared_ptr<char> pstr;pstr.reset(str);
+                    if(!xmsg.SerializeToArray(str,ndatasize))
+                    {
+                        std::cout<<"StartTurnstile serialize error."<<std::endl;
+                        return;
+                    }
+                    iv::modulecomm::ModuleSendMsg(shmStartTurnstile.mpa,str,ndatasize);
+
+                    timerTSGM.restart();
+                    statusTSGM = 0;
+                }
+            }
+
+
             updatePatrolData();
             std::string reply = uploadVehiclePatrolInfo();
             std::cout<< reply <<std::endl;

+ 19 - 5
src/driver/driver_cloud_grpc_client_BS/vehicle_patrol.h

@@ -60,6 +60,7 @@ public:
     void dec_yaml(const char * stryamlpath);
 
     void ListenGPSIMUMsg(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
+    void ListenTurnstileMsg(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
 
 protected:
     void run();
@@ -68,31 +69,44 @@ private:
     std::unique_ptr<VehiclePatrolException::Stub> stub_;
 
     iv::msgunit shmGPSIMU;
-
-    QMutex gMutex_GPSIMU;
+    iv::msgunit shmPicFront;
+    iv::msgunit shmPicRear;
+    iv::msgunit shmPicLeft;
+    iv::msgunit shmPicRight;
+    iv::msgunit shmStartTurnstile;
+    iv::msgunit shmTurnstile;
+
+    QMutex mutex_GPSIMU;
     org::jeecg::defsPatrol::grpc::GPSPoint currentPosition;
+    double currentSpeed;
 
     std::string id;
 
-    bool isTVR; //Traffic Violation Recognition
+    bool isTVR = false; //Traffic Violation Recognition
     int32_t violationStatus; //0 no violation 1 overspeed 2 illegal parking 3 direction wrong 4 run the red light
     std::string vehicleLicenseNumber;
     QByteArray violationImage;
     uint64_t violationTime; //time when get violationImage
     org::jeecg::defsPatrol::grpc::GPSPoint violationPosition; //positon when get violationImage
 
-    bool isFSM; //Fire and Smoke Monitor
+    bool isFSM = false; //Fire and Smoke Monitor
     int32_t fireStatus; //0 no fire 1 has fire
     QByteArray fireImage;
     uint64_t fireTime; //time when get fireImage
     org::jeecg::defsPatrol::grpc::GPSPoint firePosition; //positon when get fireImage
 
-    bool isTSGM; //Turn Stile Gate Monitor
+    bool isTSGM = false; //Turn Stile Gate Monitor
     int32_t gateStatus; //0 no gate 1 gate close 2 gate open
     QByteArray gateImage;
     uint64_t gateTime; //time when get gateImage
     org::jeecg::defsPatrol::grpc::GPSPoint gatePosition; //positon when get gateImage
 
+    bool isNeedTSGM = false;
+    QTime timerTSGM;
+    uint8_t statusTSGM = 0; //0 ready 1 wait for result 2 has result 3 timeout but no result
+    org::jeecg::defsPatrol::grpc::GPSPoint gateDestination;
+
+
     std::string plateNumber;
 };