Browse Source

change modulecomm. add feature, when msg is old than 3 seconds, skip this message.

yuchuli 1 year ago
parent
commit
85b407c05b
1 changed files with 10 additions and 0 deletions
  1. 10 0
      src/common/modulecomm/shm/procsm.cpp

+ 10 - 0
src/common/modulecomm/shm/procsm.cpp

@@ -862,7 +862,17 @@ int procsm::readmsg(unsigned int index, char *str, unsigned int nMaxSize,unsigne
           //         qDebug("read pos = %d",(phh+nPos)->mnPos);
                    nRtn = (phh+nPos)->mnLen;
   //                 pdt->setDate(QDate(2030,1,1));
+                   const int nms_msgkeep = 3000; //message must in 3 seconds read.
                    pdt->setMSecsSinceEpoch((phh+nPos)->sendtime/1000000);
+
+                   int64_t nms_now = std::chrono::system_clock::now().time_since_epoch().count()/1000000;
+                   int64_t nms_send = (phh+nPos)->sendtime/1000000;
+                   if(abs(nms_now - nms_send)> nms_msgkeep)
+                   {
+                       nRtn = 0;
+                       std::cout<<" message very old. skip it. diff is: "<<(nms_now - nms_send)<<std::endl;
+                   }
+
 //                   (phh+nPos)->GetDate(pdt);
            //        memcpy(pdt,&((phh+nPos)->mdt),sizeof(QDateTime));
                 }