123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- #include "stdafx.h"
- #include <atlcomtime.h>
- #include "CalibrationProcess.h"
- #include "DeviceConf_API.h"//create calib report
- #include "PixMatrix.h"
- #include "common_api.h"
- extern Log4CPP::Logger* //mLog::gLogger;
- #define MAX_STRING 1024
- const string STR_FXDFILE = "_DefectMapRef_DetMode1_0.fxd";
- const string STR_Manual_DefectFILE = "_DefectMapManual_DetMode1.fxd";
- const string STR_FXDFILEL = "_DefectMapRef_DetMode2_0.fxd"; //add20210402 长曝光模式 defect文件名
- const string STR_Manual_DefectFILEL = "_DefectMapManual_DetMode2.fxd"; //add20210402 长曝光模式 defect文件名
- const string STR_MARS_WORKDIR_PATH = "IRay\\work_dir\\Mars1717VS_";
- CalibrationProcess::CalibrationProcess():
- m_pZSKKPixMatrix(NULL),
- m_bDefectAccept(false),
- m_nOldDay(0),
- m_nTotalDefectLine(0),
- m_nTotalDefectColumn(0),
- m_nTotalDoubleDefectLine(0),
- m_nTotalDoubleDefectColumn(0),
- m_nTripleDoubleDefectLine(0),
- m_nTripleDoubleDefectColumn(0),
- m_nDefectLineMinGap(0),
- m_nDefectColumnMinGap(0),
- m_nTotalECV(0)
- {
- g_strAppPath = GetProcessDirectory();
- }
- CalibrationProcess::~CalibrationProcess()
- {
- }
- string CalibrationProcess::GetCalibDueDate(DeviceIndexStruct DeviceConf, string strCalibDate)
- {
- //mLog::Info( "GetCalibDueDate from {$}", strCalibDate.c_str());
- if (strCalibDate.size()<8)
- {
- return "0";
- }
- COleDateTime obCalibTime;
- string strYear = strCalibDate.substr(0, 4);
- int nYear = atoi(strYear.c_str());
- string strMonth = strCalibDate.substr(4, 2);
- int nMonth = atoi(strMonth.c_str());
- string strDay = strCalibDate.substr(6, 2);
- int nDay = atoi(strDay.c_str());
- string strLog;
- //mLog::Info( "Calibration Date:{$}{$}{$}", nYear, nMonth, nDay);
- obCalibTime.SetDate(nYear, nMonth, nDay);
- COleDateTimeSpan obSpanTime(DeviceConf.nCalibDueSetting, 0, 0, 0);
- COleDateTime obDueTime = obCalibTime + obSpanTime;
- //mLog::Info( "Calibration Due: {$}{$}{$}", obDueTime.GetYear(), obDueTime.GetMonth(), obDueTime.GetDay());
- char szTemp[MAX_STRING] = { 0 };
- sprintf_s(szTemp, "%d%.2d%.2d", obDueTime.GetYear(), obDueTime.GetMonth(), obDueTime.GetDay());
- //auto szTemp = std::to_string(obDueTime.GetYear()) + std::to_string(obDueTime.GetMonth()) + std::to_string(obDueTime.GetDay());
- //sprintf(szTemp, "{$}{$}{$}", , , );
- string strCalibDue = szTemp;
- //mLog::Info( "Calibration Due result: {$}", strCalibDue.c_str());
- return strCalibDue;
- }
- bool CalibrationProcess::CheckCalibartionDue(DeviceIndexStruct DeviceConf)
- {
- //mLog::Info( "[Checking Calibration Date]");
- COleDateTime obNowTime = COleDateTime::GetCurrentTime();
- if (DeviceConf.strCalibrationDate == " " && m_nOldDay != obNowTime.GetDay())
- {
- m_nOldDay = obNowTime.GetDay();
- //OnWarn(m_nDeviceIndex, WAR_FPD_LOAD_CORRECT_FILE, L"");
- return false;
- }
- //endif
- COleDateTime obCalibTime;
- string strYear = "";
- int nYear = 1970;
- string strMonth = "";
- int nMonth = 1;
- string strDay = "";
- int nDay = 1;
- if (DeviceConf.strCalibrationDate != " ")
- {
- strYear = DeviceConf.strCalibrationDate.substr(0, 4);
- strMonth = DeviceConf.strCalibrationDate.substr(4, 2);
- strDay = DeviceConf.strCalibrationDate.substr(6, 2);
- nYear = atoi(strYear.c_str());
- nMonth = atoi(strMonth.c_str());
- nDay = atoi(strDay.c_str());
- }
- obCalibTime.SetDate(nYear, nMonth, nDay);
- COleDateTimeSpan obSpanTime = obNowTime - obCalibTime;
- string strLog;
- //mLog::Info( "Current Date:{$}{$}{$}", obNowTime.GetYear(), obNowTime.GetMonth(), obNowTime.GetDay());
- //mLog::Info( "Calibration Date:{$}: year {$}, month {$}, day {$}", DeviceConf.strCalibrationDate, nYear, nMonth, nDay);
- double nSpanTimeTotalDays = obSpanTime.GetTotalDays();
- //mLog::Info( "nSpanTimeTotalDays :{$} , m_nOldDay {$}", nSpanTimeTotalDays, m_nOldDay);
- if ((nSpanTimeTotalDays >= DeviceConf.nCalibDueSetting) && (m_nOldDay != obNowTime.GetDay()))
- {
- //mLog::Info( "[Calibration File is out of Date]");
- //DeviceConf.strCalibrationDate = " ";//fixbug 12406
- m_nOldDay = obNowTime.GetDay();
- return false;
- }
- if (m_nOldDay != obNowTime.GetDay())
- {
- m_nOldDay = obNowTime.GetDay();
- //mLog::Info( "Calibration LTE m_nOldDay != obNowTime.GetDay()");
- }
- if (DeviceConf.strCalibrationLTEDate == " ")
- {
- //mLog::Info( "[Calibration LTE File is 0]");
- //OnWarn(m_nDeviceIndex, WAR_FPD_LOAD_CORRECT_FILE, L"");
- return false;
- }
- //endif
- strYear = DeviceConf.strCalibrationLTEDate.substr(0, 4);
- nYear = atoi(strYear.c_str());
- strMonth = DeviceConf.strCalibrationLTEDate.substr(4, 2);
- nMonth = atoi(strMonth.c_str());
- strDay = DeviceConf.strCalibrationLTEDate.substr(6, 2);
- nDay = atoi(strDay.c_str());
- obCalibTime.SetDate(nYear, nMonth, nDay);
- obSpanTime = obNowTime - obCalibTime;
- //mLog::Info( "[Checking LTE Calibration Date]");
- //mLog::Info( "Current Date:{$}{$}{$}", obNowTime.GetYear(), obNowTime.GetMonth(), obNowTime.GetDay());
- //mLog::Info( "Calibration LTE Date:{$}: year {$}, month {$}, day {$}", DeviceConf.strCalibrationLTEDate, nYear, nMonth, nDay);
- if (obSpanTime.GetTotalDays() >= DeviceConf.nCalibDueSetting)
- {
- //mLog::Info( "[LTE Calibration File is out of Date]");
- //DeviceConf.strCalibrationLTEDate = " ";//fixbug 12406
- //SendDetectorInfo();
- return false;
- }
- //endif
- m_nOldDay = obNowTime.GetDay();
- //mLog::Info( "[Calibration File is Normal]");
- return true;
- }
- bool CalibrationProcess::CheckCalibReportExist()
- {
- FILE * pFileReport;
- string strPath = g_strAppPath + "\\references\\FDCalibUIFToc.html";
- if ((pFileReport = fopen(strPath.c_str(), "r")) == NULL)
- {
- //mLog::Info( "Cannot Find {$}", strPath.c_str());
- return false;
- }
- fclose(pFileReport);
- strPath = g_strAppPath + "\\references\\FDCalibToc.html";
- if ((pFileReport = fopen(strPath.c_str(), "r")) == NULL)
- {
- //mLog::Info( "Cannot Find {$}", strPath.c_str());
- return false;
- }
- fclose(pFileReport);
- //mLog::Info( "calibration base report is existed");
- return true;
- }
- bool CalibrationProcess::GetCalibReportParam(bool bLTEenable, DeviceIndexStruct DeviceConf, string key, string & Value)
- {
- char szCalibFile[MAX_STRING] = { 0 };
- //endif
- if(!bLTEenable)
- {
- sprintf_s(szCalibFile, "references\\FDCalibReport_%s_fd%s%s_30.xml", DeviceConf.strPanelSerial.c_str(), DeviceConf.strDetectorModel.c_str(), DeviceConf.strDeviceName.c_str());
- }
- else
- {
- sprintf_s(szCalibFile, "references\\FDCalibReport_%s_fd%s%s_31.xml", DeviceConf.strPanelSerial.c_str(), DeviceConf.strDetectorModel.c_str(), DeviceConf.strDeviceName.c_str());
- }
- //mLog::Info( "{$}", szCalibFile);
- string strValue = "";
- bool bResult = GetCalibReport(szCalibFile, (char*)key.c_str(), Value);
- if (bResult)
- {
- }
- return true;
- }
- bool CalibrationProcess::UpdateFDUIFCalibList(bool bLTEenable, string strPanelSerial, string strPanelType)
- {
- //mLog::Info( "Begin to save FDCalibUIFToc.html");
- string strReferenceFile = "FDCalibReport_" + strPanelSerial + "_fd" + strPanelType + "_30.xml";
- //add20210402 增加长曝光校正报告(根据和西门子沟通,以_31结尾)处理
- if (bLTEenable) //0:STE;1:LTE
- {
- strReferenceFile = "FDCalibReport_" + strPanelSerial + "_fd" + strPanelType + "_31.xml";
- }
- //addend20210402
- //mLog::Info( "{$}", strReferenceFile.c_str());
- char *pszReportData = NULL;
- long lFileLength = 0;
- FILE * pFileReport;
- string strPath = g_strAppPath + "\\references\\FDCalibUIFToc.html";
- if ((pFileReport = fopen(strPath.c_str(), "r+")) == NULL)
- {
- //mLog::Info( "Cannot Find FDCalibUIFToc.html");
- return false;
- }
- fseek(pFileReport, 0, SEEK_END); ///将文件指针移动文件结尾
- lFileLength = ftell(pFileReport); ///求出当前文件指针距离文件开始的字节数
- fseek(pFileReport, 0, SEEK_SET); ///将文件指针移动文件头
- //mLog::Info( "FDCalibUIFToc.html Length is :{$}", lFileLength);
- pszReportData = new char[lFileLength];
- size_t nLen = fread(pszReportData, 1, lFileLength, pFileReport);
- if (nLen == 0)
- {
- delete[]pszReportData;
- fclose(pFileReport);
- //mLog::Info( "Read FDCalibUIFToc.html info Error nLen {$}", nLen);
- return false;
- }
- else
- {
- //mLog::Info( "Read FDCalibUIFToc.html info nLen {$}", nLen);
- }
- pszReportData[lFileLength - 1] = '\0';
- string strTemp = pszReportData;
- size_t nPos = strTemp.rfind("TR>");
- string strFirstHalfTemp = strTemp.substr(0, nPos + 3);
- string strLastHalfTemp = strTemp.substr(nPos + 3, strTemp.length() - nPos - 3);
- string strCalibList = strTemp;
- //mLog::Info( "{$}", pszReportData);
- if (strCalibList.find(strReferenceFile.c_str()) != wstring::npos)
- {
- //mLog::Info( "Current IS has this Calibration Report");
- return true;
- }
- string strNewCalibInfo = "<TR><TD width=\"30%\" align = \"LEFT\">Portable Detector on Floor (";
- strNewCalibInfo += strPanelSerial;
- strNewCalibInfo += ")</TD><TD width=\"70%\" align=\"CENTER\"><A HREF=\"javascript:top.fetchReport('6/";
- strNewCalibInfo += strReferenceFile;
- strNewCalibInfo += "')\">DR Radiography</A></TD></TR>";
- string strNewCalibInfo2 = strNewCalibInfo;
- strTemp = strFirstHalfTemp;
- strTemp += strNewCalibInfo2;
- strTemp += strLastHalfTemp;
- //mLog::Info( "{$}", strTemp.c_str());
- fseek(pFileReport, 0, SEEK_SET); ///将文件指针移动文件头
- size_t writelen = fwrite(strTemp.c_str(), 1, strTemp.length(), pFileReport);
- fclose(pFileReport);
- if (pszReportData)
- {
- delete[]pszReportData;
- pszReportData = NULL;
- }
- //mLog::Info( "Save FDCalibUIFToc.html Over");
- return true;
- }
- bool CalibrationProcess::UpdateFDCalibList(bool bLTEenable, string strPanelSerial, string strPanelType)
- {
- UpdateFDUIFCalibList(bLTEenable, strPanelSerial, strPanelType);
- //mLog::Info( "Begin to save FDCalibToc.html");
- string strReferenceFile = "FDCalibReport_" + strPanelSerial + "_fd" + strPanelType + "_30.xml";
- //add20210402 增加长曝光校正报告(根据和西门子沟通,以_31结尾)处理
- if (bLTEenable) //0:STE;1:LTE
- {
- strReferenceFile = "FDCalibReport_" + strPanelSerial + "_fd" + strPanelType + "_31.xml";
- }
- //addend20210402
- //mLog::Info( "{$}", strReferenceFile.c_str());
- char *pszReportData = NULL;
- long lFileLength = 0;
- FILE * pFileReport;
- string strPath = g_strAppPath + "\\references\\FDCalibToc.html";
- if ((pFileReport = fopen(strPath.c_str(), "r+")) == NULL)
- {
- //mLog::Info( "Cannot Find FDCalibToc.html");
- return false;
- }
- fseek(pFileReport, 0, SEEK_END); ///将文件指针移动文件结尾
- lFileLength = ftell(pFileReport); ///求出当前文件指针距离文件开始的字节数
- fseek(pFileReport, 0, SEEK_SET); ///将文件指针移动文件头
- //mLog::Info( "FDCalibToc.html Length is :{$}", lFileLength);
- pszReportData = new char[lFileLength];
- size_t nLen = fread(pszReportData, 1, lFileLength, pFileReport);
- if (nLen == 0)
- {
- delete[]pszReportData;
- fclose(pFileReport);
- //mLog::Info( "Read FDCalibToc.html info Error nLen {$}", nLen);
- return false;
- }
- else
- {
- //mLog::Info( "Read FDCalibToc.html info nLen {$}", nLen);
- }
- pszReportData[lFileLength - 1] = '\0';
- string strTemp = pszReportData;
- size_t nPos = strTemp.rfind("TR>");
- string strFirstHalfTemp = strTemp.substr(0, nPos + 3);
- string strLastHalfTemp = strTemp.substr(nPos + 3, strTemp.length() - nPos - 3);
- string strCalibList = strTemp;
- //mLog::Info( "{$}", pszReportData);
- if (strCalibList.find(strReferenceFile.c_str()) != wstring::npos)
- {
- //mLog::Info( "Current IS has this Calibration Report");
- return true;
- }
- string strNewCalibInfo = "<TR><TD width=\"30%\" align = \"LEFT\">Portable Detector on Floor (";
- strNewCalibInfo += strPanelSerial;
- strNewCalibInfo += ")</TD><TD width=\"70%\" align=\"CENTER\"><A HREF=\"";
- strNewCalibInfo += strReferenceFile;
- strNewCalibInfo += "\">DR Radiography</A></TD></TR>";
- string strNewCalibInfo2 = strNewCalibInfo;
- strTemp = strFirstHalfTemp;
- strTemp += strNewCalibInfo2;
- strTemp += strLastHalfTemp;
- //mLog::Info( "{$}", strTemp.c_str());
- fseek(pFileReport, 0, SEEK_SET); ///将文件指针移动文件头
- size_t writelen = fwrite(strTemp.c_str(), 1, strTemp.length(), pFileReport);
- fclose(pFileReport);
- if (pszReportData)
- {
- delete[]pszReportData;
- pszReportData = NULL;
- }
- //mLog::Info( "Save FDCalibToc.html Over");
- return true;
- }
|