main.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <QCoreApplication>
  2. #include <thread>
  3. #include "modulecomm.h"
  4. void * gpa;
  5. std::chrono::time_point<std::chrono::steady_clock, std::chrono::duration<double,std::nano>> t1,t2;
  6. void testcall(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  7. {
  8. qint64 sendtime;
  9. t2 = std::chrono::steady_clock::now();
  10. double dr_ns = std::chrono::duration<double,std::nano>(t2-t1).count();
  11. memcpy(&sendtime,strdata,8);
  12. qDebug("lat is %d ns is %f ",QDateTime::currentMSecsSinceEpoch() - sendtime,dr_ns);
  13. }
  14. void threadsend()
  15. {
  16. char * strdata = new char[3000000];
  17. while(1)
  18. {
  19. std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  20. qint64 ntime = QDateTime::currentMSecsSinceEpoch();
  21. memcpy(strdata,&ntime,8);
  22. iv::modulecomm::ModuleSendMsg(gpa,strdata,2000000);
  23. t1 = std::chrono::steady_clock::now();
  24. qDebug("send msg.");
  25. }
  26. }
  27. int main(int argc, char *argv[])
  28. {
  29. QCoreApplication a(argc, argv);
  30. gpa = iv::modulecomm::RegisterSend("test1",3000000,1,iv::modulecomm::ModuleComm_INTERIOR);
  31. iv::modulecomm::RegisterRecv("test1",testcall,iv::modulecomm::ModuleComm_INTERIOR);
  32. std::thread * xthread = new std::thread(threadsend);
  33. return a.exec();
  34. }