WatchDogClassImpl.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef WATCHDOG_H
  2. #define WATCHDOG_H
  3. #include "wintypes.h"
  4. #include <map>
  5. #include <list>
  6. #include <vector>
  7. #include <deque>
  8. #include "TraceManager.h"
  9. #include "CommDef.h"
  10. #include "WatchDogClass.h"
  11. #include <iostream>
  12. #include <string.h>
  13. #include <sys/types.h>
  14. #include <sys/stat.h>
  15. #include <fcntl.h>
  16. #include <sys/ioctl.h>
  17. #include <linux/watchdog.h>
  18. #include <unistd.h>
  19. #include "TimerCtrl.h"
  20. //#include "IOPort.h"
  21. #include "CkLog.h"
  22. #include "Algorithm.h"
  23. typedef unsigned int UINT;
  24. typedef unsigned int MMRESULT;
  25. #define _TIMER_DELAY (178 * 1000)
  26. #define WATCHDOG "/dev/watchdog"
  27. #define WATCHDOG0 "/dev/watchdog0"
  28. #define WATCHDOG1 "/dev/watchdog1"
  29. //编译版本
  30. #define FILE_VERSION 1
  31. #pragma pack(push,1)
  32. class WatchDogClassImpl:public WatchDogClass
  33. {
  34. public:
  35. WatchDogClassImpl();
  36. ~WatchDogClassImpl();
  37. //DeviceBaseClass
  38. virtual ErrorCodeEnum GetDevCategory(DevCategoryInfo &devCategory);
  39. virtual ErrorCodeEnum Reset();
  40. virtual ErrorCodeEnum DevClose();
  41. virtual ErrorCodeEnum GetLastErr(DevErrorInfo &devErrInfo);
  42. //WatchDogClass
  43. // Initialization,make preparation for working.
  44. //
  45. virtual ErrorCodeEnum DevOpen();
  46. //
  47. // Conifgure watchdog.
  48. // Watchdog start to work in [dwDelay] second.It must be feed in every [dwTimeout]
  49. // period or it will restart the computer.
  50. // Arguments:
  51. // - dwDelay:time to start watching(in second)
  52. // - dwTimeout:max time period to feed dog(in second)
  53. //
  54. virtual ErrorCodeEnum StartWatch(DWORD dwDelay, DWORD dwTimeout);
  55. //
  56. // Stop watchdog.
  57. //
  58. virtual ErrorCodeEnum StopWatch();
  59. //
  60. // Feed watchdog.
  61. //
  62. virtual ErrorCodeEnum RefreshDog();
  63. private:
  64. bool m_bDevOpen;
  65. bool m_bDelayTimer;
  66. bool m_bWDTTimer;
  67. //WDTTimer
  68. DWORD m_dwTimeOut;
  69. DWORD m_dwRealTimeOut;
  70. DWORD m_dwWDTDelayTime;
  71. //DelayTimer
  72. DWORD m_dwDelay;
  73. DWORD m_dwDelayRemain;
  74. DWORD m_dwDelayTime;
  75. //DelayTimerID
  76. timer_t m_mmDelayTimerID;
  77. //WDTTimerOutID
  78. timer_t m_mmWDTTimerID;
  79. //CHAR m_szErrMsg[MAX_DEV_ERR_MSG];
  80. CHAR m_szErrMsg[MAX_DEV_ERROR_MSG_LEN];
  81. //void SaveErrorInfo(CHAR* errMsg, int errCode=95555);
  82. void SaveErrorInfo(CHAR* errMsg, int errCode, const CHAR* strFunc = NULL, int nLine = 0);
  83. std::string m_LogFileNamePath;
  84. int m_wfd;
  85. CTimerCtrl *m_TimerCtrl;
  86. //int m_nLogLevel;
  87. // IOPort* m_pMB330CRM;
  88. //ILog* m_pLog;
  89. // IIniFile* m_pIniFile;
  90. //ILevelLog* m_pLevelLog;
  91. private:
  92. int string_format(std::string &str, const std::string fmt, ...);
  93. //TimerProc
  94. static void DelayTimer(sigval_t ptr);
  95. //WDTProc
  96. static void WDTTimer(sigval_t ptr);
  97. };
  98. #endif // WATCHDOG_H
  99. #pragma pack(pop)