#include "stdafx.h" #include #include "CalibrationProcess.h" #include "DeviceConf_API.h"//create calib report #include "PixMatrix.h" #include "common_api.h" extern Log4CPP::Logger* 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) { 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; Info( "Calibration Date:{$}{$}{$}", nYear, nMonth, nDay); obCalibTime.SetDate(nYear, nMonth, nDay); COleDateTimeSpan obSpanTime(DeviceConf.nCalibDueSetting, 0, 0, 0); COleDateTime obDueTime = obCalibTime + obSpanTime; 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; Info( "Calibration Due result: {$}", strCalibDue.c_str()); return strCalibDue; } bool CalibrationProcess::CheckCalibartionDue(DeviceIndexStruct DeviceConf) { 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; Info( "Current Date:{$}{$}{$}", obNowTime.GetYear(), obNowTime.GetMonth(), obNowTime.GetDay()); Info( "Calibration Date:{$}: year {$}, month {$}, day {$}", DeviceConf.strCalibrationDate, nYear, nMonth, nDay); double nSpanTimeTotalDays = obSpanTime.GetTotalDays(); Info( "nSpanTimeTotalDays :{$} , m_nOldDay {$}", nSpanTimeTotalDays, m_nOldDay); if ((nSpanTimeTotalDays >= DeviceConf.nCalibDueSetting) && (m_nOldDay != obNowTime.GetDay())) { 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(); Info( "Calibration LTE m_nOldDay != obNowTime.GetDay()"); } if (DeviceConf.strCalibrationLTEDate == " ") { 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; Info( "[Checking LTE Calibration Date]"); Info( "Current Date:{$}{$}{$}", obNowTime.GetYear(), obNowTime.GetMonth(), obNowTime.GetDay()); Info( "Calibration LTE Date:{$}: year {$}, month {$}, day {$}", DeviceConf.strCalibrationLTEDate, nYear, nMonth, nDay); if (obSpanTime.GetTotalDays() >= DeviceConf.nCalibDueSetting) { Info( "[LTE Calibration File is out of Date]"); //DeviceConf.strCalibrationLTEDate = " ";//fixbug 12406 //SendDetectorInfo(); return false; } //endif m_nOldDay = obNowTime.GetDay(); 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) { Info( "Cannot Find {$}", strPath.c_str()); return false; } fclose(pFileReport); strPath = g_strAppPath + "\\references\\FDCalibToc.html"; if ((pFileReport = fopen(strPath.c_str(), "r")) == NULL) { Info( "Cannot Find {$}", strPath.c_str()); return false; } fclose(pFileReport); 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()); } 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) { 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 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) { Info( "Cannot Find FDCalibUIFToc.html"); return false; } fseek(pFileReport, 0, SEEK_END); ///将文件指针移动文件结尾 lFileLength = ftell(pFileReport); ///求出当前文件指针距离文件开始的字节数 fseek(pFileReport, 0, SEEK_SET); ///将文件指针移动文件头 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); Info( "Read FDCalibUIFToc.html info Error nLen {$}", nLen); return false; } else { 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; Info( "{$}", pszReportData); if (strCalibList.find(strReferenceFile.c_str()) != wstring::npos) { Info( "Current IS has this Calibration Report"); return true; } string strNewCalibInfo = "Portable Detector on Floor ("; strNewCalibInfo += strPanelSerial; strNewCalibInfo += ")DR Radiography"; string strNewCalibInfo2 = strNewCalibInfo; strTemp = strFirstHalfTemp; strTemp += strNewCalibInfo2; strTemp += strLastHalfTemp; 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; } Info( "Save FDCalibUIFToc.html Over"); return true; } bool CalibrationProcess::UpdateFDCalibList(bool bLTEenable, string strPanelSerial, string strPanelType) { UpdateFDUIFCalibList(bLTEenable, strPanelSerial, strPanelType); 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 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) { Info( "Cannot Find FDCalibToc.html"); return false; } fseek(pFileReport, 0, SEEK_END); ///将文件指针移动文件结尾 lFileLength = ftell(pFileReport); ///求出当前文件指针距离文件开始的字节数 fseek(pFileReport, 0, SEEK_SET); ///将文件指针移动文件头 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); Info( "Read FDCalibToc.html info Error nLen {$}", nLen); return false; } else { 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; Info( "{$}", pszReportData); if (strCalibList.find(strReferenceFile.c_str()) != wstring::npos) { Info( "Current IS has this Calibration Report"); return true; } string strNewCalibInfo = "Portable Detector on Floor ("; strNewCalibInfo += strPanelSerial; strNewCalibInfo += ")DR Radiography"; string strNewCalibInfo2 = strNewCalibInfo; strTemp = strFirstHalfTemp; strTemp += strNewCalibInfo2; strTemp += strLastHalfTemp; 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; } Info( "Save FDCalibToc.html Over"); return true; }