123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #ifndef INTERCOMM_H
- #define INTERCOMM_H
- #include <QDateTime>
- #include "vector"
- #include <functional>
- #include <thread>
- typedef void (* SMCallBack)(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
- using namespace std::placeholders;
- typedef std::function<void(const char * ,const unsigned int , const unsigned int , QDateTime * ,const char *)> ModuleFun;
- class procinter_info
- {
- public:
- unsigned int mFirst;
- unsigned int mNext;
- unsigned int mCap;
- unsigned int mLock;
- unsigned int mnBufSize;
- };
- class procinter_head
- {
- public:
- unsigned short mYear;
- unsigned char mMonth;
- unsigned char mDay;
- unsigned char mHour;
- unsigned char mMinute;
- unsigned char mSec;
- unsigned short mMSec;
- unsigned int mindex;
- unsigned int mnPos;
- unsigned int mnLen;
- public:
- void SetDate(QDateTime dt)
- {
- mYear = dt.date().year();
- mMonth = dt.date().month();
- mDay = dt.date().day();
- mHour = dt.time().hour();
- mMinute = dt.time().minute();
- mSec = dt.time().second();
- mMSec = dt.time().msec();
- }
- void GetDate(QDateTime * pdt)
- {
- QDate dt;
- dt.setDate(mYear,mMonth,mDay);
- QTime time;
- time.setHMS(mHour,mMinute,mSec,mMSec);
- pdt->setDate(dt);
- pdt->setTime(time);
- }
- };
- namespace iv {
- class intercomm
- {
- public:
- intercomm(const char * strsmname,const unsigned int nBufSize,const unsigned int nMaxPacCount,const int nMode);
- ~intercomm();
- int listenmsg(SMCallBack pCall);
- int listenmsg(ModuleFun xFun);
- void stoplisten();
- void pausecomm();
- void continuecomm();
- const static int ModeRead = 1;
- const static int ModeWrite = 0;
- int writemsg(const char * str,const unsigned int nSize);
- private:
- char mstrsmname[256];
- int mnMode;
- void * mpa;
- void * mplistenunit;
- private:
- void listernrun();
- bool mblistenrun = true;
- bool mbPause = false;
- std::thread * mplistenthread = 0;
- procinter_info * mpinfo;
- procinter_head * mphead;
- private:
- int readmsg(unsigned int index,char * str,unsigned int nMaxSize,unsigned int * nRead,QDateTime * pdt);
- int MoveMem(const unsigned int nSize);
- unsigned int getcurrentnext();
- };
- }
- #endif // INTERCOMM_H
|