CalibrationProcess.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. #include "stdafx.h"
  2. #include <atlcomtime.h>
  3. #include "CalibrationProcess.h"
  4. #include "DeviceConf_API.h"//create calib report
  5. #include "PixMatrix.h"
  6. #include "common_api.h"
  7. extern Log4CPP::Logger* //mLog::gLogger;
  8. #define MAX_STRING 1024
  9. const string STR_FXDFILE = "_DefectMapRef_DetMode1_0.fxd";
  10. const string STR_Manual_DefectFILE = "_DefectMapManual_DetMode1.fxd";
  11. const string STR_FXDFILEL = "_DefectMapRef_DetMode2_0.fxd"; //add20210402 长曝光模式 defect文件名
  12. const string STR_Manual_DefectFILEL = "_DefectMapManual_DetMode2.fxd"; //add20210402 长曝光模式 defect文件名
  13. const string STR_MARS_WORKDIR_PATH = "IRay\\work_dir\\Mars1717VS_";
  14. CalibrationProcess::CalibrationProcess():
  15. m_pZSKKPixMatrix(NULL),
  16. m_bDefectAccept(false),
  17. m_nOldDay(0),
  18. m_nTotalDefectLine(0),
  19. m_nTotalDefectColumn(0),
  20. m_nTotalDoubleDefectLine(0),
  21. m_nTotalDoubleDefectColumn(0),
  22. m_nTripleDoubleDefectLine(0),
  23. m_nTripleDoubleDefectColumn(0),
  24. m_nDefectLineMinGap(0),
  25. m_nDefectColumnMinGap(0),
  26. m_nTotalECV(0)
  27. {
  28. g_strAppPath = GetProcessDirectory();
  29. }
  30. CalibrationProcess::~CalibrationProcess()
  31. {
  32. }
  33. string CalibrationProcess::GetCalibDueDate(DeviceIndexStruct DeviceConf, string strCalibDate)
  34. {
  35. //mLog::Info( "GetCalibDueDate from {$}", strCalibDate.c_str());
  36. if (strCalibDate.size()<8)
  37. {
  38. return "0";
  39. }
  40. COleDateTime obCalibTime;
  41. string strYear = strCalibDate.substr(0, 4);
  42. int nYear = atoi(strYear.c_str());
  43. string strMonth = strCalibDate.substr(4, 2);
  44. int nMonth = atoi(strMonth.c_str());
  45. string strDay = strCalibDate.substr(6, 2);
  46. int nDay = atoi(strDay.c_str());
  47. string strLog;
  48. //mLog::Info( "Calibration Date:{$}{$}{$}", nYear, nMonth, nDay);
  49. obCalibTime.SetDate(nYear, nMonth, nDay);
  50. COleDateTimeSpan obSpanTime(DeviceConf.nCalibDueSetting, 0, 0, 0);
  51. COleDateTime obDueTime = obCalibTime + obSpanTime;
  52. //mLog::Info( "Calibration Due: {$}{$}{$}", obDueTime.GetYear(), obDueTime.GetMonth(), obDueTime.GetDay());
  53. char szTemp[MAX_STRING] = { 0 };
  54. sprintf_s(szTemp, "%d%.2d%.2d", obDueTime.GetYear(), obDueTime.GetMonth(), obDueTime.GetDay());
  55. //auto szTemp = std::to_string(obDueTime.GetYear()) + std::to_string(obDueTime.GetMonth()) + std::to_string(obDueTime.GetDay());
  56. //sprintf(szTemp, "{$}{$}{$}", , , );
  57. string strCalibDue = szTemp;
  58. //mLog::Info( "Calibration Due result: {$}", strCalibDue.c_str());
  59. return strCalibDue;
  60. }
  61. bool CalibrationProcess::CheckCalibartionDue(DeviceIndexStruct DeviceConf)
  62. {
  63. //mLog::Info( "[Checking Calibration Date]");
  64. COleDateTime obNowTime = COleDateTime::GetCurrentTime();
  65. if (DeviceConf.strCalibrationDate == " " && m_nOldDay != obNowTime.GetDay())
  66. {
  67. m_nOldDay = obNowTime.GetDay();
  68. //OnWarn(m_nDeviceIndex, WAR_FPD_LOAD_CORRECT_FILE, L"");
  69. return false;
  70. }
  71. //endif
  72. COleDateTime obCalibTime;
  73. string strYear = "";
  74. int nYear = 1970;
  75. string strMonth = "";
  76. int nMonth = 1;
  77. string strDay = "";
  78. int nDay = 1;
  79. if (DeviceConf.strCalibrationDate != " ")
  80. {
  81. strYear = DeviceConf.strCalibrationDate.substr(0, 4);
  82. strMonth = DeviceConf.strCalibrationDate.substr(4, 2);
  83. strDay = DeviceConf.strCalibrationDate.substr(6, 2);
  84. nYear = atoi(strYear.c_str());
  85. nMonth = atoi(strMonth.c_str());
  86. nDay = atoi(strDay.c_str());
  87. }
  88. obCalibTime.SetDate(nYear, nMonth, nDay);
  89. COleDateTimeSpan obSpanTime = obNowTime - obCalibTime;
  90. string strLog;
  91. //mLog::Info( "Current Date:{$}{$}{$}", obNowTime.GetYear(), obNowTime.GetMonth(), obNowTime.GetDay());
  92. //mLog::Info( "Calibration Date:{$}: year {$}, month {$}, day {$}", DeviceConf.strCalibrationDate, nYear, nMonth, nDay);
  93. double nSpanTimeTotalDays = obSpanTime.GetTotalDays();
  94. //mLog::Info( "nSpanTimeTotalDays :{$} , m_nOldDay {$}", nSpanTimeTotalDays, m_nOldDay);
  95. if ((nSpanTimeTotalDays >= DeviceConf.nCalibDueSetting) && (m_nOldDay != obNowTime.GetDay()))
  96. {
  97. //mLog::Info( "[Calibration File is out of Date]");
  98. //DeviceConf.strCalibrationDate = " ";//fixbug 12406
  99. m_nOldDay = obNowTime.GetDay();
  100. return false;
  101. }
  102. if (m_nOldDay != obNowTime.GetDay())
  103. {
  104. m_nOldDay = obNowTime.GetDay();
  105. //mLog::Info( "Calibration LTE m_nOldDay != obNowTime.GetDay()");
  106. }
  107. if (DeviceConf.strCalibrationLTEDate == " ")
  108. {
  109. //mLog::Info( "[Calibration LTE File is 0]");
  110. //OnWarn(m_nDeviceIndex, WAR_FPD_LOAD_CORRECT_FILE, L"");
  111. return false;
  112. }
  113. //endif
  114. strYear = DeviceConf.strCalibrationLTEDate.substr(0, 4);
  115. nYear = atoi(strYear.c_str());
  116. strMonth = DeviceConf.strCalibrationLTEDate.substr(4, 2);
  117. nMonth = atoi(strMonth.c_str());
  118. strDay = DeviceConf.strCalibrationLTEDate.substr(6, 2);
  119. nDay = atoi(strDay.c_str());
  120. obCalibTime.SetDate(nYear, nMonth, nDay);
  121. obSpanTime = obNowTime - obCalibTime;
  122. //mLog::Info( "[Checking LTE Calibration Date]");
  123. //mLog::Info( "Current Date:{$}{$}{$}", obNowTime.GetYear(), obNowTime.GetMonth(), obNowTime.GetDay());
  124. //mLog::Info( "Calibration LTE Date:{$}: year {$}, month {$}, day {$}", DeviceConf.strCalibrationLTEDate, nYear, nMonth, nDay);
  125. if (obSpanTime.GetTotalDays() >= DeviceConf.nCalibDueSetting)
  126. {
  127. //mLog::Info( "[LTE Calibration File is out of Date]");
  128. //DeviceConf.strCalibrationLTEDate = " ";//fixbug 12406
  129. //SendDetectorInfo();
  130. return false;
  131. }
  132. //endif
  133. m_nOldDay = obNowTime.GetDay();
  134. //mLog::Info( "[Calibration File is Normal]");
  135. return true;
  136. }
  137. bool CalibrationProcess::CheckCalibReportExist()
  138. {
  139. FILE * pFileReport;
  140. string strPath = g_strAppPath + "\\references\\FDCalibUIFToc.html";
  141. if ((pFileReport = fopen(strPath.c_str(), "r")) == NULL)
  142. {
  143. //mLog::Info( "Cannot Find {$}", strPath.c_str());
  144. return false;
  145. }
  146. fclose(pFileReport);
  147. strPath = g_strAppPath + "\\references\\FDCalibToc.html";
  148. if ((pFileReport = fopen(strPath.c_str(), "r")) == NULL)
  149. {
  150. //mLog::Info( "Cannot Find {$}", strPath.c_str());
  151. return false;
  152. }
  153. fclose(pFileReport);
  154. //mLog::Info( "calibration base report is existed");
  155. return true;
  156. }
  157. bool CalibrationProcess::GetCalibReportParam(bool bLTEenable, DeviceIndexStruct DeviceConf, string key, string & Value)
  158. {
  159. char szCalibFile[MAX_STRING] = { 0 };
  160. //endif
  161. if(!bLTEenable)
  162. {
  163. sprintf_s(szCalibFile, "references\\FDCalibReport_%s_fd%s%s_30.xml", DeviceConf.strPanelSerial.c_str(), DeviceConf.strDetectorModel.c_str(), DeviceConf.strDeviceName.c_str());
  164. }
  165. else
  166. {
  167. sprintf_s(szCalibFile, "references\\FDCalibReport_%s_fd%s%s_31.xml", DeviceConf.strPanelSerial.c_str(), DeviceConf.strDetectorModel.c_str(), DeviceConf.strDeviceName.c_str());
  168. }
  169. //mLog::Info( "{$}", szCalibFile);
  170. string strValue = "";
  171. bool bResult = GetCalibReport(szCalibFile, (char*)key.c_str(), Value);
  172. if (bResult)
  173. {
  174. }
  175. return true;
  176. }
  177. bool CalibrationProcess::UpdateFDUIFCalibList(bool bLTEenable, string strPanelSerial, string strPanelType)
  178. {
  179. //mLog::Info( "Begin to save FDCalibUIFToc.html");
  180. string strReferenceFile = "FDCalibReport_" + strPanelSerial + "_fd" + strPanelType + "_30.xml";
  181. //add20210402 增加长曝光校正报告(根据和西门子沟通,以_31结尾)处理
  182. if (bLTEenable) //0:STE;1:LTE
  183. {
  184. strReferenceFile = "FDCalibReport_" + strPanelSerial + "_fd" + strPanelType + "_31.xml";
  185. }
  186. //addend20210402
  187. //mLog::Info( "{$}", strReferenceFile.c_str());
  188. char *pszReportData = NULL;
  189. long lFileLength = 0;
  190. FILE * pFileReport;
  191. string strPath = g_strAppPath + "\\references\\FDCalibUIFToc.html";
  192. if ((pFileReport = fopen(strPath.c_str(), "r+")) == NULL)
  193. {
  194. //mLog::Info( "Cannot Find FDCalibUIFToc.html");
  195. return false;
  196. }
  197. fseek(pFileReport, 0, SEEK_END); ///将文件指针移动文件结尾
  198. lFileLength = ftell(pFileReport); ///求出当前文件指针距离文件开始的字节数
  199. fseek(pFileReport, 0, SEEK_SET); ///将文件指针移动文件头
  200. //mLog::Info( "FDCalibUIFToc.html Length is :{$}", lFileLength);
  201. pszReportData = new char[lFileLength];
  202. size_t nLen = fread(pszReportData, 1, lFileLength, pFileReport);
  203. if (nLen == 0)
  204. {
  205. delete[]pszReportData;
  206. fclose(pFileReport);
  207. //mLog::Info( "Read FDCalibUIFToc.html info Error nLen {$}", nLen);
  208. return false;
  209. }
  210. else
  211. {
  212. //mLog::Info( "Read FDCalibUIFToc.html info nLen {$}", nLen);
  213. }
  214. pszReportData[lFileLength - 1] = '\0';
  215. string strTemp = pszReportData;
  216. size_t nPos = strTemp.rfind("TR>");
  217. string strFirstHalfTemp = strTemp.substr(0, nPos + 3);
  218. string strLastHalfTemp = strTemp.substr(nPos + 3, strTemp.length() - nPos - 3);
  219. string strCalibList = strTemp;
  220. //mLog::Info( "{$}", pszReportData);
  221. if (strCalibList.find(strReferenceFile.c_str()) != wstring::npos)
  222. {
  223. //mLog::Info( "Current IS has this Calibration Report");
  224. return true;
  225. }
  226. string strNewCalibInfo = "<TR><TD width=\"30%\" align = \"LEFT\">Portable Detector on Floor (";
  227. strNewCalibInfo += strPanelSerial;
  228. strNewCalibInfo += ")</TD><TD width=\"70%\" align=\"CENTER\"><A HREF=\"javascript:top.fetchReport('6/";
  229. strNewCalibInfo += strReferenceFile;
  230. strNewCalibInfo += "')\">DR Radiography</A></TD></TR>";
  231. string strNewCalibInfo2 = strNewCalibInfo;
  232. strTemp = strFirstHalfTemp;
  233. strTemp += strNewCalibInfo2;
  234. strTemp += strLastHalfTemp;
  235. //mLog::Info( "{$}", strTemp.c_str());
  236. fseek(pFileReport, 0, SEEK_SET); ///将文件指针移动文件头
  237. size_t writelen = fwrite(strTemp.c_str(), 1, strTemp.length(), pFileReport);
  238. fclose(pFileReport);
  239. if (pszReportData)
  240. {
  241. delete[]pszReportData;
  242. pszReportData = NULL;
  243. }
  244. //mLog::Info( "Save FDCalibUIFToc.html Over");
  245. return true;
  246. }
  247. bool CalibrationProcess::UpdateFDCalibList(bool bLTEenable, string strPanelSerial, string strPanelType)
  248. {
  249. UpdateFDUIFCalibList(bLTEenable, strPanelSerial, strPanelType);
  250. //mLog::Info( "Begin to save FDCalibToc.html");
  251. string strReferenceFile = "FDCalibReport_" + strPanelSerial + "_fd" + strPanelType + "_30.xml";
  252. //add20210402 增加长曝光校正报告(根据和西门子沟通,以_31结尾)处理
  253. if (bLTEenable) //0:STE;1:LTE
  254. {
  255. strReferenceFile = "FDCalibReport_" + strPanelSerial + "_fd" + strPanelType + "_31.xml";
  256. }
  257. //addend20210402
  258. //mLog::Info( "{$}", strReferenceFile.c_str());
  259. char *pszReportData = NULL;
  260. long lFileLength = 0;
  261. FILE * pFileReport;
  262. string strPath = g_strAppPath + "\\references\\FDCalibToc.html";
  263. if ((pFileReport = fopen(strPath.c_str(), "r+")) == NULL)
  264. {
  265. //mLog::Info( "Cannot Find FDCalibToc.html");
  266. return false;
  267. }
  268. fseek(pFileReport, 0, SEEK_END); ///将文件指针移动文件结尾
  269. lFileLength = ftell(pFileReport); ///求出当前文件指针距离文件开始的字节数
  270. fseek(pFileReport, 0, SEEK_SET); ///将文件指针移动文件头
  271. //mLog::Info( "FDCalibToc.html Length is :{$}", lFileLength);
  272. pszReportData = new char[lFileLength];
  273. size_t nLen = fread(pszReportData, 1, lFileLength, pFileReport);
  274. if (nLen == 0)
  275. {
  276. delete[]pszReportData;
  277. fclose(pFileReport);
  278. //mLog::Info( "Read FDCalibToc.html info Error nLen {$}", nLen);
  279. return false;
  280. }
  281. else
  282. {
  283. //mLog::Info( "Read FDCalibToc.html info nLen {$}", nLen);
  284. }
  285. pszReportData[lFileLength - 1] = '\0';
  286. string strTemp = pszReportData;
  287. size_t nPos = strTemp.rfind("TR>");
  288. string strFirstHalfTemp = strTemp.substr(0, nPos + 3);
  289. string strLastHalfTemp = strTemp.substr(nPos + 3, strTemp.length() - nPos - 3);
  290. string strCalibList = strTemp;
  291. //mLog::Info( "{$}", pszReportData);
  292. if (strCalibList.find(strReferenceFile.c_str()) != wstring::npos)
  293. {
  294. //mLog::Info( "Current IS has this Calibration Report");
  295. return true;
  296. }
  297. string strNewCalibInfo = "<TR><TD width=\"30%\" align = \"LEFT\">Portable Detector on Floor (";
  298. strNewCalibInfo += strPanelSerial;
  299. strNewCalibInfo += ")</TD><TD width=\"70%\" align=\"CENTER\"><A HREF=\"";
  300. strNewCalibInfo += strReferenceFile;
  301. strNewCalibInfo += "\">DR Radiography</A></TD></TR>";
  302. string strNewCalibInfo2 = strNewCalibInfo;
  303. strTemp = strFirstHalfTemp;
  304. strTemp += strNewCalibInfo2;
  305. strTemp += strLastHalfTemp;
  306. //mLog::Info( "{$}", strTemp.c_str());
  307. fseek(pFileReport, 0, SEEK_SET); ///将文件指针移动文件头
  308. size_t writelen = fwrite(strTemp.c_str(), 1, strTemp.length(), pFileReport);
  309. fclose(pFileReport);
  310. if (pszReportData)
  311. {
  312. delete[]pszReportData;
  313. pszReportData = NULL;
  314. }
  315. //mLog::Info( "Save FDCalibToc.html Over");
  316. return true;
  317. }