intercomm.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef INTERCOMM_H
  2. #define INTERCOMM_H
  3. #include <QDateTime>
  4. #include "vector"
  5. #include <functional>
  6. #include <thread>
  7. typedef void (* SMCallBack)(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
  8. using namespace std::placeholders;
  9. typedef std::function<void(const char * ,const unsigned int , const unsigned int , QDateTime * ,const char *)> ModuleFun;
  10. class procinter_info
  11. {
  12. public:
  13. unsigned int mFirst;
  14. unsigned int mNext;
  15. unsigned int mCap;
  16. unsigned int mLock;
  17. unsigned int mnBufSize;
  18. };
  19. class procinter_head
  20. {
  21. public:
  22. unsigned short mYear;
  23. unsigned char mMonth;
  24. unsigned char mDay;
  25. unsigned char mHour;
  26. unsigned char mMinute;
  27. unsigned char mSec;
  28. unsigned short mMSec;
  29. unsigned int mindex;
  30. unsigned int mnPos;
  31. unsigned int mnLen;
  32. public:
  33. void SetDate(QDateTime dt)
  34. {
  35. mYear = dt.date().year();
  36. mMonth = dt.date().month();
  37. mDay = dt.date().day();
  38. mHour = dt.time().hour();
  39. mMinute = dt.time().minute();
  40. mSec = dt.time().second();
  41. mMSec = dt.time().msec();
  42. }
  43. void GetDate(QDateTime * pdt)
  44. {
  45. QDate dt;
  46. dt.setDate(mYear,mMonth,mDay);
  47. QTime time;
  48. time.setHMS(mHour,mMinute,mSec,mMSec);
  49. pdt->setDate(dt);
  50. pdt->setTime(time);
  51. }
  52. };
  53. namespace iv {
  54. class intercomm
  55. {
  56. public:
  57. intercomm(const char * strsmname,const unsigned int nBufSize,const unsigned int nMaxPacCount,const int nMode);
  58. ~intercomm();
  59. int listenmsg(SMCallBack pCall);
  60. int listenmsg(ModuleFun xFun);
  61. void stoplisten();
  62. void pausecomm();
  63. void continuecomm();
  64. const static int ModeRead = 1;
  65. const static int ModeWrite = 0;
  66. int writemsg(const char * str,const unsigned int nSize);
  67. private:
  68. char mstrsmname[256];
  69. int mnMode;
  70. void * mpa;
  71. void * mplistenunit;
  72. private:
  73. void listernrun();
  74. bool mblistenrun = true;
  75. bool mbPause = false;
  76. std::thread * mplistenthread = 0;
  77. procinter_info * mpinfo;
  78. procinter_head * mphead;
  79. private:
  80. int readmsg(unsigned int index,char * str,unsigned int nMaxSize,unsigned int * nRead,QDateTime * pdt);
  81. int MoveMem(const unsigned int nSize);
  82. unsigned int getcurrentnext();
  83. };
  84. }
  85. #endif // INTERCOMM_H