ソースを参照

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

yuchuli 1 年間 前
コミット
85b407c05b
1 ファイル変更10 行追加0 行削除
  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);
           //         qDebug("read pos = %d",(phh+nPos)->mnPos);
                    nRtn = (phh+nPos)->mnLen;
                    nRtn = (phh+nPos)->mnLen;
   //                 pdt->setDate(QDate(2030,1,1));
   //                 pdt->setDate(QDate(2030,1,1));
+                   const int nms_msgkeep = 3000; //message must in 3 seconds read.
                    pdt->setMSecsSinceEpoch((phh+nPos)->sendtime/1000000);
                    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);
 //                   (phh+nPos)->GetDate(pdt);
            //        memcpy(pdt,&((phh+nPos)->mdt),sizeof(QDateTime));
            //        memcpy(pdt,&((phh+nPos)->mdt),sizeof(QDateTime));
                 }
                 }