FPDErrorWarningProcess.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #include "stdafx.h"
  2. #include "FPDErrorWarningProcess.h"
  3. extern Log4CPP::Logger* gLogger;
  4. FPDErrorWarning::FPDErrorWarning(std::shared_ptr <CCOS::Dev::IOEventCenter> EventCenter, std::string DevInstance, std::string strAppPath)
  5. {
  6. m_MSGUnit.reset(new nDetail::MSGUnit(EventCenter, DevInstance));
  7. m_EventCenter = EventCenter;
  8. std::string strPath = "";
  9. strPath = strAppPath + "OEMDrivers\\Detector\\Conf\\PNLErrorInfor.xml";
  10. m_ErrRes.setFileName(strPath.c_str());
  11. strPath = strAppPath + "OEMDrivers\\Detector\\Conf\\PNLWarnInfor.xml";
  12. m_WarnRes.setFileName(strPath);
  13. m_WarnList.clear();
  14. m_ErrList.clear();
  15. }
  16. FPDErrorWarning::~FPDErrorWarning()
  17. {
  18. }
  19. int FPDErrorWarning::GetMessageLevel(const std::string& code)
  20. {
  21. int level = 1;
  22. if (code == ERR_FPD_TEMPHIGH_NOT_ACQ
  23. || code == ERR_FPD_TEMPLOW_NOT_ACQ
  24. || code == ERR_FPD_DOSE_HIGH
  25. || code == ERR_FPD_MAX_NUMBER
  26. || code == ERR_FPD_DOSE_OBJ
  27. || code == ERR_FPD_RESTART
  28. || code == ERR_FPD_DOSE_LOW
  29. || code == ERR_FPD_NOFPD
  30. || code == ERR_FPD_ACQ_FAILED
  31. || code == WAR_FPD_TEMPERATURE_HIGH
  32. || code == WAR_FPD_TEMPERTURE_LOW
  33. || code == WAR_FPD_BATTERY_LOW
  34. || code == WAR_FPD_EXCEED_CALB_TEMPER
  35. || code == WAR_FPD_EXCEED_CALB_TEMPER_HIGH
  36. || code == WAR_FPD_EXCEED_CALB_TEMPER_LOW)
  37. {
  38. level = 99;
  39. }
  40. else if (code == ERR_FPD_WIFI_LOW
  41. || code == ERR_FPD_DISCONNECT
  42. || code == ERR_FPD_BATTERY_LOW
  43. || code == ERR_FPD_POWEROFF
  44. || code == ERR_FPD_FATAL_ERROR
  45. || code == WAR_FPD_LOAD_CORRECT_FILE
  46. || code == WAR_FPD_WIFI_LOW)
  47. {
  48. level = 98;
  49. }
  50. return level;
  51. }
  52. void FPDErrorWarning::AddErrMsg(std::string code, std::string info)
  53. {
  54. Info("AddErrMsg {$}: {$}", code.c_str(), info.c_str());
  55. int level = GetMessageLevel(code);
  56. m_MSGUnit->AddErrorMessage(code.c_str(), level, info.c_str());
  57. }
  58. void FPDErrorWarning::DelErrMsg(std::string code)
  59. {
  60. int level = GetMessageLevel(code);
  61. Info("DelErrMsg {$}", code.c_str());
  62. m_MSGUnit->DelErrorMessage(code.c_str(), level, "");
  63. }
  64. void FPDErrorWarning::AddWarnMsg(std::string code, std::string info)
  65. {
  66. Info("AddWarnMsg {$}: {$}", code.c_str(), info.c_str());
  67. int level = GetMessageLevel(code);
  68. m_MSGUnit->AddWarnMessage(code.c_str(), level, info.c_str());
  69. }
  70. void FPDErrorWarning::DelWarnMsg(std::string code)
  71. {
  72. int level = GetMessageLevel(code);
  73. Info("DelWarnMsg {$}", code.c_str());
  74. m_MSGUnit->DelWarnMessage(code.c_str(), level, "");
  75. }
  76. void FPDErrorWarning::SendError( DeviceError obErr)
  77. {
  78. AddErrMsg(obErr.getCode(), obErr.getDescription());
  79. }
  80. void FPDErrorWarning::SendAllError()
  81. {
  82. Info("Send All Error");
  83. for (int i = 0; i < m_ErrList.size(); i++)
  84. {
  85. DeviceError stError;
  86. stError = m_ErrList.item(i);
  87. SendError( stError);
  88. }
  89. }
  90. void FPDErrorWarning::SendAllWarn()
  91. {
  92. Info("Send All Warn");
  93. for (int i = 0; i < m_WarnList.size(); i++)
  94. {
  95. auto stWar = m_WarnList.item(i);
  96. AddWarnMsg(stWar.getCode(), stWar.getDescription());
  97. }
  98. }
  99. void FPDErrorWarning::SyncErrorList()
  100. {
  101. SendAllError();
  102. SendAllWarn();
  103. }
  104. void FPDErrorWarning::ClearAllError()
  105. {
  106. //先清除原有探测器的ERROR
  107. Info("Clear All Error");
  108. if (0 == m_ErrList.size()) // 切换工作位时清除错误,会将发生器的错误无故清除
  109. {
  110. Info("There is no error in list. Omit Clear All Error");
  111. return;
  112. }
  113. for (int i = 0; i < m_ErrList.size(); i++)
  114. {
  115. DeviceError stError;
  116. stError = m_ErrList.item(i);
  117. OnErrorX(stError.getCode());
  118. }
  119. }
  120. void FPDErrorWarning::SendErrorX( std::string strErrorCode)
  121. {
  122. DelErrMsg(strErrorCode);
  123. }
  124. bool FPDErrorWarning::OnErrorX(std::string strErr)
  125. {
  126. if (m_ErrListTemp.isExist(strErr)) //清除一下初始化时的临时ErrorList
  127. {
  128. Info("Remove temp error");
  129. m_ErrListTemp.remove(strErr);
  130. }
  131. if (m_ErrList.isExist(strErr))
  132. {
  133. m_ErrList.remove(strErr);
  134. SendErrorX( strErr);
  135. return true;
  136. }
  137. return false;
  138. }
  139. void FPDErrorWarning::SendWarn( DeviceError stWar)
  140. {
  141. }
  142. bool FPDErrorWarning::IsErrorExist(std::string code)
  143. {
  144. return m_ErrList.isExist(code);
  145. }
  146. int FPDErrorWarning::GetExistErrorNum()
  147. {
  148. return m_ErrList.size();
  149. }
  150. void FPDErrorWarning::OnError(std::string strErrCode, std::string strErr)
  151. {
  152. if (IsErrorExist(strErrCode))
  153. {
  154. Info("Same Error,Omit");
  155. return;
  156. }
  157. DeviceError stErr;
  158. if (!m_ErrRes.getDeviceError(strErrCode, stErr))
  159. {
  160. Warn("Get Error Resouse Fault! ErrorCode:{$}", strErrCode);
  161. stErr.setCode(strErrCode);
  162. stErr.setName(strErrCode);
  163. }
  164. m_ErrList.add(stErr);
  165. std::string strDesc = stErr.getDescription() + strErr;
  166. stErr.setDescription(strDesc);
  167. AddErrMsg(stErr.getCode(), stErr.getDescription());
  168. }
  169. void FPDErrorWarning::OnWarn(std::string strWarnCode, std::string strWarn)
  170. {
  171. std::string strLog;
  172. DeviceError stWar;
  173. if (m_WarnList.isExist(strWarnCode))
  174. {
  175. Info("Same warn {$}", strWarnCode.c_str());
  176. return;
  177. }
  178. if (!m_WarnRes.getDeviceWarn(strWarnCode, stWar))
  179. {
  180. Warn(("Get Warn Resouse Fault! WarnCode:{$}"), strWarnCode);
  181. stWar.setCode(strWarnCode);
  182. stWar.setName(strWarnCode);
  183. stWar.setDescription(strWarn);
  184. }
  185. Info(("Send Warn Code:{$}"), strWarnCode);
  186. std::string strDesc = stWar.getDescription() + strWarn;
  187. stWar.setDescription(strDesc);
  188. m_WarnList.add(stWar);
  189. AddWarnMsg(stWar.getCode(), stWar.getDescription());
  190. }
  191. void FPDErrorWarning::OnWarnX(std::string strWarnCode)
  192. {
  193. if (strWarnCode == "") //清除一下初始化时的临时ErrorList
  194. {
  195. Info("OnWarnX have no code");
  196. return;
  197. }
  198. if (m_WarnList.isExist(strWarnCode))
  199. {
  200. m_WarnList.remove(strWarnCode);
  201. DelWarnMsg(strWarnCode);
  202. }
  203. }