procsm_if.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef PROCSM_IF_H
  2. #define PROCSM_IF_H
  3. #include <QThread>
  4. #include <QTimer>
  5. #include <QWaitCondition>
  6. #include <QMutex>
  7. #include <functional>
  8. #ifdef USEDBUS
  9. #include <QtDBus/QDBusMessage>
  10. #include <QtDBus/QDBusConnection>
  11. #endif
  12. #include "procsm.h"
  13. typedef void (* SMCallBack)(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
  14. using namespace std::placeholders;
  15. typedef std::function<void(const char * ,const unsigned int , const unsigned int , QDateTime * ,const char *)> ModuleFun;
  16. class procsm_if_readthread:public QThread
  17. {
  18. Q_OBJECT
  19. public:
  20. #ifdef USELCM
  21. #endif
  22. procsm_if_readthread(procsm * pPSM,SMCallBack pCall,const char * strsmname);
  23. procsm_if_readthread(procsm * pPSM,ModuleFun xFun,const char * strsmname);
  24. void puaseread();
  25. void continueread();
  26. private slots:
  27. #ifdef USEDBUS
  28. void onNewMsg(int x);
  29. #endif
  30. private:
  31. #ifdef USELCM
  32. lcm::LCM mlcm;
  33. void handlerMethod(const lcm::ReceiveBuffer *rbuf,const std::string &channel);
  34. int mxindex = 0;
  35. #endif
  36. void run();
  37. procsm * mpPSM;
  38. SMCallBack mpCall;
  39. ModuleFun mFun;
  40. char mstrsmname[256];
  41. QWaitCondition mwc;
  42. QMutex mWaitMutex;
  43. bool mbFunPlus = false;
  44. bool mbRun = true;
  45. bool mbDBUSOK = true;
  46. };
  47. class procsm_if
  48. {
  49. public:
  50. procsm_if(const char * strsmname,const unsigned int nBufSize,const unsigned int nMaxPacCount,const int nMode);
  51. ~procsm_if();
  52. int writemsg(const char * str,const unsigned int nSize);
  53. int listenmsg(SMCallBack pCall);
  54. int listenmsg(ModuleFun xFun);
  55. void stoplisten();
  56. void pausecomm();
  57. void continuecomm();
  58. private:
  59. procsm * mpPSM;
  60. int mnType;
  61. procsm_if_readthread * mpReadThread;
  62. QTimer mTimer;
  63. char mstrsmname[256];
  64. bool mbRun = true;
  65. #ifdef USELCM
  66. lcm::LCM mlcm;
  67. void handlerMethod(const lcm::ReceiveBuffer *rbuf,const std::string &channel);
  68. #endif
  69. };
  70. #endif // PROCSM_IF_H