XiuYuanCtrl.cpp 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788
  1. #include "stdafx.h"
  2. #include <tlhelp32.h>
  3. #include "sys\stat.h"
  4. #include <fstream> //文件流库函数
  5. #include <atlcomtime.h>
  6. #include "XiuYuanCtrl.h"
  7. #include "common_api.h"
  8. #include "CiniFile.h"
  9. #include "MyPingip.h"
  10. #include "CiniFile.h"
  11. extern Log4CPP::Logger* gLogger;
  12. #include <shlwapi.h>
  13. #pragma comment(lib, "Shlwapi.lib")
  14. #pragma comment(lib, "Version.lib")
  15. XiuYuanCtrl* g_pXiuYuanCtrl = nullptr;
  16. XiuYuanCtrl::XiuYuanCtrl()
  17. :m_hXiuYuanModule(nullptr),
  18. API_YI_Initialize_FPD_V4(nullptr),
  19. API_YI_FPD_Set_Work_Mode(nullptr),
  20. API_YI_FPD_Stop_Capture_Image(nullptr),
  21. API_YI_FPD_Get_Configure_Common(nullptr),
  22. API_YI_FPD_Set_Configure_Common(nullptr),
  23. API_YI_FPD_Get_Configure_SyncOut_Mode(nullptr),
  24. API_YI_FPD_Set_Configure_SyncOut_Mode(nullptr),
  25. API_YI_FPD_Restore_Factory_Settings(nullptr),
  26. API_YI_ImageReady_Callback_Register(nullptr),
  27. API_YI_SystemInfo_Callback_Register(nullptr),
  28. API_YI_Get_Callback_Image_Size(nullptr),
  29. API_YI_GetLastErrorCode(nullptr),
  30. API_YI_Set_Save_Log_Flag(nullptr),
  31. API_YI_GetLoacalIPs_V4(nullptr),
  32. API_YI_Set_Image_Save_State(nullptr),
  33. API_YI_Set_Image_Save_Path(nullptr),
  34. API_YI_FPD_Get_FPD_TYPE(nullptr),
  35. API_YI_FPD_Get_Invalid_Region(nullptr),
  36. API_YI_FPD_Capture_Image(nullptr),
  37. API_YI_FPD_Capture_Prepare(nullptr),
  38. API_YI_Load_Gain_Tmp_File(nullptr),
  39. API_YI_Load_Defect_Tmp_File(nullptr),
  40. API_YI_Load_Offset_Tmp_File(nullptr),
  41. API_YI_Load_AED_Offset_Tmp_File(nullptr),
  42. API_YI_Set_Correct_Type(nullptr),
  43. API_YI_FPD_FreeBuffer(nullptr),
  44. m_strAppPath{},
  45. m_strWorkPath{},
  46. m_strAcqMode{},
  47. m_nPanelCount{},
  48. m_nDetectorID(1),
  49. m_nDetectorIndex{},
  50. m_pZSKKCalib{},
  51. m_bInCalibrating(false),
  52. m_bInExposure(false),
  53. m_bSaveRaw(false),
  54. m_bTemperatureEnable(false),
  55. m_bBatteryEnable(false),
  56. m_bWifiEnable(false),
  57. m_bConnectStatus(false),
  58. m_pHardwareStatusThread(nullptr),
  59. m_hEndHWStatusThreadEvent(nullptr),
  60. m_hHWStatusThreadEndEvent(nullptr),
  61. m_eAppStatus(APP_STATUS_IDLE),
  62. m_nImageWidth{},
  63. m_nImageHeight{},
  64. m_nRawImgWidth{},
  65. m_nRawImgHeight{},
  66. m_nHeightOffset{},
  67. m_nWidthOffset{},
  68. m_nSyncMode{},
  69. m_nImgBits(16),
  70. m_nPixelPitch(150),
  71. m_pImgBuffer(nullptr),
  72. m_pRawImgBuffer(nullptr),
  73. m_hExitEvent(nullptr),
  74. m_hXiuYuanScanEnd(nullptr),
  75. m_hWindowOffEvent(nullptr),
  76. m_pOffsetThread(nullptr),
  77. m_pXWindowoffThread(nullptr),
  78. m_hScanEventThread(nullptr),
  79. m_nCalibStatus{},
  80. m_nDoseParam{},
  81. m_nCalibrationMode{},
  82. m_nDefectExpTimes{},
  83. m_nDefectTotalTimes{},
  84. m_nGainExpTimes{},
  85. m_nGainTotalFrames{},
  86. m_nDefectTotalFrames{},
  87. m_nExpWindowMode{},
  88. m_nXWindow{},
  89. m_bFreeBuffer(false),
  90. m_bStandbyFlag(false)
  91. {
  92. m_hInitThread = nullptr;
  93. m_hScanEventThread = nullptr;
  94. m_pDPC2PanelID = new map<nsDPC::FPDDeviceXiuYuan*, int>();
  95. m_pPanelID2DPC = new map<int, nsDPC::FPDDeviceXiuYuan*>();
  96. m_vecDetectorID.clear();
  97. m_eCaliType = CCOS_CALIBRATION_TYPE_NONE;
  98. for (int i = 0; i < XiuYuan_SCAN_NUM; i++)
  99. {
  100. m_hArrayEvent[i] = nullptr;
  101. }
  102. }
  103. XiuYuanCtrl::~XiuYuanCtrl()
  104. {
  105. OnEXIT();
  106. if (m_pImgBuffer)
  107. {
  108. delete[] m_pImgBuffer;
  109. m_pImgBuffer = nullptr;
  110. }
  111. if (m_pZSKKCalib)
  112. {
  113. delete m_pZSKKCalib;
  114. m_pZSKKCalib = nullptr;
  115. }
  116. delete m_pDPC2PanelID;
  117. m_pDPC2PanelID = nullptr;
  118. delete m_pPanelID2DPC;
  119. m_pPanelID2DPC = nullptr;
  120. }
  121. bool XiuYuanCtrl::OnEXIT()
  122. {
  123. SetEvent(m_hEndHWStatusThreadEvent);
  124. FINFO("Waiting HWStatus Thread End");
  125. int nResult = WaitForSingleObject(m_hHWStatusThreadEndEvent, 10000);
  126. if (WAIT_TIMEOUT == nResult)
  127. {
  128. FERROR("XiuYuan HWStatus Thread Quit Failed");
  129. }
  130. else
  131. {
  132. FINFO("XiuYuan HWStatus Thread Quit Success");
  133. }
  134. SetEvent(m_hExitEvent);
  135. FINFO("Waiting XiuYuan ScanEvent Thread End");
  136. nResult = WaitForSingleObject(m_hXiuYuanScanEnd, 2000);
  137. if (WAIT_TIMEOUT == nResult)
  138. {
  139. FERROR("XiuYuan ScanEvent Thread Quit Failed");
  140. }
  141. else
  142. {
  143. FINFO("XiuYuan ScanEvent Thread Quit Success");
  144. }
  145. DeleteHandle();
  146. FINFO("Free XiuYuan DLL");
  147. FreeXiuYuanDLL();
  148. return true;
  149. }
  150. void XiuYuanCtrl::DeleteHandle()
  151. {
  152. if (m_hExitEvent)
  153. {
  154. CloseHandle(m_hExitEvent);
  155. m_hExitEvent = nullptr;
  156. }
  157. if (m_hXiuYuanScanEnd)
  158. {
  159. CloseHandle(m_hXiuYuanScanEnd);
  160. m_hXiuYuanScanEnd = nullptr;
  161. }
  162. if (m_hHWStatusThreadEndEvent)
  163. {
  164. CloseHandle(m_hHWStatusThreadEndEvent);
  165. m_hHWStatusThreadEndEvent = nullptr;
  166. }
  167. if (m_pRawImgBuffer)
  168. {
  169. delete[] m_pRawImgBuffer;
  170. m_pRawImgBuffer = nullptr;
  171. }
  172. }
  173. bool XiuYuanCtrl::Init(string strAppPath)
  174. {
  175. std::string strDllPath;
  176. strDllPath = strAppPath + (string)m_ModeConfig["SDKPath"];
  177. m_strDetectorType = (string)m_ModeConfig["DeviceName"];
  178. m_strAppPath = strAppPath;
  179. FINFO("XiuYuanCtrl::Init {$}", strDllPath.c_str());
  180. if (!LoadXiuYuanDLL(strDllPath))
  181. {
  182. FERROR("XiuYuanCtrl::Init LoadXiuYuanDLL failed");
  183. return false;
  184. }
  185. m_hXiuYuanScanEnd = CreateEvent(NULL, FALSE, FALSE, NULL);
  186. m_hWindowOffEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  187. m_hHWStatusThreadEndEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  188. m_hExitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  189. m_hArrayEvent[0] = m_hExitEvent;
  190. FINFO("XiuYuanCtrl::Init over");
  191. return true;
  192. }
  193. //初始化连接探测器
  194. bool XiuYuanCtrl::DetectorInitProcess(int nDetectorID, bool bFDAttach)
  195. {
  196. FINFO("--XiuYuanCtrl Func-- DetectorInitProcess");
  197. int nDetectorIndex = nDetectorID - 1;
  198. bool bPingSucces = false;
  199. int nPingTotalTime = 30; //ping不通,一次约2s,共30次,1分钟左右超时
  200. int nLocalPort;
  201. int nRemotePort;
  202. bool bSDKSaveLog;
  203. bool bSDKSaveRaw;
  204. string strWirdIP;
  205. string strLocalIP;
  206. string strSDKSaveLogPath;
  207. string strSDKSaveRawPath;
  208. strWirdIP = (string)m_ModeConfig["DetectorWiredIP"];
  209. for (int nPingTimes = 0; nPingTimes < nPingTotalTime; nPingTimes++)
  210. {
  211. bPingSucces = IsConnected(strWirdIP);
  212. if (bPingSucces)
  213. {
  214. FINFO("Ping Detector successfully");
  215. break;
  216. }
  217. Sleep(2000);
  218. }
  219. //ping不通就不用连接了
  220. if (!bPingSucces)
  221. {
  222. FERROR("Ping detector failed, timeout!!!");
  223. return false;
  224. }
  225. m_bTemperatureEnable = ((int)m_ModeConfig["TemperatureEnable"] != 0) ? true : false;
  226. m_bBatteryEnable = ((int)m_ModeConfig["BatteryEnable"] != 0) ? true : false;
  227. m_bWifiEnable = ((int)m_ModeConfig["WifiEnable"] != 0) ? true : false;
  228. m_nExpWindowMode = (int)m_ModeConfig["ExpWindowMode"];
  229. string strXWindowMode = "XWindow" + std::to_string(m_nExpWindowMode);
  230. m_nXWindow = (int)m_ModeConfig["ExpWindow"][strXWindowMode.c_str()];
  231. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_START, "");
  232. strLocalIP = (string)m_ModeConfig["LocalIP"];
  233. nLocalPort = 28000;
  234. nRemotePort = 27999;
  235. char szDetectorID[100] = { 0 };
  236. FINFO("LocalIP: {$}:28000, RemoteIP: {$}:27999", strLocalIP, strWirdIP);
  237. int nRet = API_YI_Initialize_FPD_V4(strWirdIP.c_str(), nRemotePort, szDetectorID);
  238. if (TestError(nDetectorID, nRet, "API_YI_Initialize_FPD_V4"))
  239. {
  240. FERROR("Connect Detector {$} Failed", nDetectorID);
  241. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END_ERROR, "");
  242. return false;
  243. }
  244. m_vecDetectorID.push_back(szDetectorID);
  245. FINFO("Connect Detector {$} Success", nDetectorID);
  246. m_bConnectStatus = true;
  247. StatusFeedback(EVT_STATUS_PANEL, PANEL_CONNECT);
  248. bSDKSaveLog = (bool)m_ModeConfig["SDKSaveLog"];
  249. strSDKSaveLogPath = (string)m_ModeConfig["SDKSaveLogPath"];
  250. nRet = API_YI_Set_Save_Log_Flag(bSDKSaveLog, strSDKSaveLogPath.c_str());
  251. if (TestError(nDetectorID, nRet, "SaveLog"))
  252. {
  253. FERROR("{$} SDK save log failed!!! path: {$} ", (bSDKSaveLog ? "Enable" : "Disable"),
  254. strSDKSaveLogPath);
  255. }
  256. else
  257. {
  258. FINFO("{$} SDK save log success, path: {$}", (bSDKSaveLog ? "Enable" : "Disable"),
  259. strSDKSaveLogPath);
  260. }
  261. bSDKSaveRaw = (bool)m_ModeConfig["SDKSaveRaw"];
  262. strSDKSaveRawPath = (string)m_ModeConfig["SDKSaveRawPath"];
  263. nRet = API_YI_Set_Image_Save_Path(szDetectorID, strSDKSaveRawPath.c_str());
  264. nRet |= API_YI_Set_Image_Save_State(szDetectorID, bSDKSaveRaw);
  265. if (TestError(nDetectorID, nRet, "SaveRaw"))
  266. {
  267. FERROR("{$} SDK save raw image failed!!! path: {$} ", (bSDKSaveRaw ? "Enable" : "Disable"),
  268. strSDKSaveRawPath);
  269. }
  270. else
  271. {
  272. FINFO("{$} SDK save raw image success, path: {$}", (bSDKSaveRaw ? "Enable" : "Disable"),
  273. strSDKSaveRawPath);
  274. }
  275. //获取尺寸
  276. int nWidth = 0;
  277. int nHeight = 0;
  278. int nBits = 0;
  279. nRet = API_YI_Get_Callback_Image_Size(szDetectorID, nWidth, nHeight, nBits);
  280. if (TestError(nDetectorID, nRet, "API_YI_Get_Callback_Image_Size"))
  281. {
  282. FERROR("Get detector({$}) image size failed", nDetectorID);
  283. }
  284. else
  285. {
  286. FINFO("Get detector image size: {$}x{$}x{$}", nWidth, nHeight, nBits);
  287. }
  288. //注册回调
  289. /*nRet = API_YI_ImageReady_Callback_Register(szDetectorID, nullptr);
  290. if (TestError(nDetectorID, nRet, "API_YI_ImageReady_Callback_Register"))
  291. {
  292. FERROR("Reset ImageReadyCallbackProcess failed!!!");
  293. }
  294. else
  295. {
  296. FINFO("Reset ImageReadyCallbackProcess success");
  297. }*/
  298. nRet = API_YI_SystemInfo_Callback_Register(szDetectorID, nullptr);
  299. if (TestError(nDetectorID, nRet, "API_YI_SystemInfo_Callback_Register"))
  300. {
  301. FERROR("Reset SystemInfoCallbackProcess failed!!!");
  302. }
  303. else
  304. {
  305. FINFO("Reset SystemInfoCallbackProcess success");
  306. }
  307. nRet = API_YI_ImageReady_Callback_Register(szDetectorID, ImageReadyCallbackProcess);
  308. if (TestError(nDetectorID, nRet, "API_YI_ImageReady_Callback_Register"))
  309. {
  310. FERROR("Register ImageReadyCallbackProcess failed!!!");
  311. }
  312. else
  313. {
  314. FINFO("Register ImageReadyCallbackProcess success");
  315. }
  316. nRet = API_YI_SystemInfo_Callback_Register(szDetectorID, SystemInfoCallbackProcess);
  317. if (TestError(nDetectorID, nRet, "API_YI_SystemInfo_Callback_Register"))
  318. {
  319. FERROR("Register SystemInfoCallbackProcess failed!!!");
  320. }
  321. else
  322. {
  323. FINFO("Register SystemInfoCallbackProcess success");
  324. }
  325. //读取或设置common参数
  326. YIConfigInfo_Common stConfigCommon = { 0 };
  327. nRet = API_YI_FPD_Get_Configure_Common(szDetectorID, &stConfigCommon);
  328. if (TestError(nDetectorID, nRet, "API_YI_FPD_Get_Configure_Common"))
  329. {
  330. FERROR("Get detector common config failed!!!");
  331. }
  332. else
  333. {
  334. FINFO("Get detector common config success");
  335. FINFO("DetectorSN: {$}; FPGA version: {$}; MCU version: {$}; NetWork: {$}:{$}",
  336. stConfigCommon.arrProductInitSN, stConfigCommon.arrFPGAVerMain, stConfigCommon.arrMCUVerMain, stConfigCommon.arrLocalIPAddress, stConfigCommon.usLocalUDPPort);
  337. }
  338. //读取syncout参数
  339. YIConfigInfo_SyncOut stConfigSyncOut = { 0 };
  340. nRet = API_YI_FPD_Get_Configure_SyncOut_Mode(szDetectorID, &stConfigSyncOut);
  341. if (TestError(nDetectorID, nRet, "API_YI_FPD_Get_Configure_SyncOut_Mode"))
  342. {
  343. FERROR("Get detector syncmode config failed!!!");
  344. }
  345. else
  346. {
  347. FINFO("Get detector syncmode config success");
  348. FINFO("ExpWindow: {$}; ExpTimeout: {$}; ", stConfigSyncOut.usExposureWindow, stConfigSyncOut.usExposureTimeOut);
  349. }
  350. m_nCalibrationMode = (CCOS_CALIBRATION_MODE)((int)m_ModeConfig["CalibMode"]);
  351. m_nImageHeight = (int)m_ModeConfig["ModeTable"][0]["ImageHeight"];
  352. m_nImageWidth = (int)m_ModeConfig["ModeTable"][0]["ImageWidth"];
  353. if (m_nCalibrationMode == CCOS_CALIBRATION_MODE::CCOS_CALIBRATION_MODE_ZSKK)
  354. {
  355. Info("Load ZSKK Reference file");
  356. m_pZSKKCalib->m_strRawImgPath = m_strWorkPath + "\\rawdata\\";
  357. m_pZSKKCalib->m_strRefFilePath = m_strWorkPath + "\\references\\";
  358. //读取配置文件中RAD模式的高和宽
  359. m_pZSKKCalib->m_nFullImgWidth = m_nImageWidth;
  360. m_pZSKKCalib->m_nFullImgHeight = m_nImageHeight;
  361. m_pZSKKCalib->m_nSaturationValue = 50000;
  362. if (!m_pZSKKCalib->LoadZSKKGainMap(true, m_strDetectorType))
  363. {
  364. Warn("Load ZSKK Gain calibration failed");
  365. }
  366. if (!m_pZSKKCalib->LoadZSKKPixelMap(true, m_strDetectorType))
  367. {
  368. Warn("Load ZSKK Defect calibration failed");
  369. }
  370. }
  371. else if (m_nCalibrationMode == CCOS_CALIBRATION_MODE::CCOS_CALIBRATION_MODE_OEM)
  372. {
  373. //加载模板
  374. FPDLoadCorrectFiles(nDetectorID, szDetectorID);
  375. }
  376. //设置工作模式
  377. FpdMode tempFpdMode;
  378. tempFpdMode.workMode = ModeType::Normal_Mode;
  379. tempFpdMode.trigType = TrigType::SENSOR_TRIG_MODE;
  380. SetDetectorWorkMode(nDetectorID, szDetectorID, &tempFpdMode);
  381. StatusFeedback(EVT_STATUS_INIT, PANEL_EVENT_END_OK, "");
  382. FINFO("DetectorInitProcess Over");
  383. return true;
  384. }
  385. //接口成功返回false,接口失败或有错返回true
  386. bool XiuYuanCtrl::TestError(int nDetectorID, int nErrorStatus, std::string strAPI)
  387. {
  388. switch (nErrorStatus)
  389. {
  390. case 0:
  391. {
  392. SystemErrorCode nErrorCode = SEC_Succeed;
  393. nErrorCode = (SystemErrorCode)API_YI_GetLastErrorCode();
  394. FWARN("{$} Failed!!! ErrorCode: {$}", strAPI.c_str(), (int)nErrorCode);
  395. return true;
  396. break;
  397. }
  398. case 1:
  399. {
  400. FDEBUG("{$} Success", strAPI);
  401. return false;
  402. break;
  403. }
  404. default:
  405. break;
  406. }
  407. return true;
  408. }
  409. bool XiuYuanCtrl::LoadXiuYuanDLL(string strWorkPath)
  410. {
  411. FINFO("--XiuYuanCtrl Func-- LoadXiuYuanDLL");
  412. string strDllDir = strWorkPath;
  413. if (SetDllDirectory(strDllDir.c_str()) == 0)
  414. {
  415. DWORD dw = GetLastError();
  416. FINFO("SetDllDirectory error,error code [{$}]", dw);
  417. return false;
  418. }
  419. string strDllPath = strWorkPath + "\\YuYingAPI.dll";
  420. FINFO("Load XiuYuan API, {$}", strDllPath);
  421. m_hXiuYuanModule = LoadLibrary(strDllPath.c_str());
  422. if (nullptr == m_hXiuYuanModule)
  423. {
  424. FWARN("Load XiuYuan API failed!");
  425. return false;
  426. }
  427. API_YI_Initialize_FPD_V4 = (Func_YI_Initialize_FPD_V4)GetProcAddress(m_hXiuYuanModule, "YI_Initialize_FPD_V4");
  428. if (nullptr == API_YI_Initialize_FPD_V4)
  429. {
  430. FWARN("Load YI_Initialize_FPD_V4 failed!");
  431. return false;
  432. }
  433. API_YI_FPD_Set_Work_Mode = (Func_YI_FPD_Set_Work_Mode)GetProcAddress(m_hXiuYuanModule, "YI_FPD_Set_Work_Mode");
  434. if (nullptr == API_YI_FPD_Set_Work_Mode)
  435. {
  436. FWARN("Load YI_FPD_Set_Work_Mode failed!");
  437. return false;
  438. }
  439. API_YI_FPD_Stop_Capture_Image = (Func_YI_FPD_Stop_Capture_Image)GetProcAddress(m_hXiuYuanModule, "YI_FPD_Stop_Capture_Image");
  440. if (nullptr == API_YI_FPD_Stop_Capture_Image)
  441. {
  442. FWARN("Load YI_FPD_Stop_Capture_Image failed!");
  443. return false;
  444. }
  445. API_YI_FPD_Get_Configure_Common = (Func_YI_FPD_Get_Configure_Common)GetProcAddress(m_hXiuYuanModule, "YI_FPD_Get_Configure_Common");
  446. if (nullptr == API_YI_FPD_Get_Configure_Common)
  447. {
  448. FWARN("Load YI_FPD_Get_Configure_Common failed!");
  449. return false;
  450. }
  451. API_YI_FPD_Set_Configure_Common = (Func_YI_FPD_Set_Configure_Common)GetProcAddress(m_hXiuYuanModule, "YI_FPD_Set_Configure_Common");
  452. if (nullptr == API_YI_FPD_Set_Configure_Common)
  453. {
  454. FWARN("Load YI_FPD_Set_Configure_Common failed!");
  455. return false;
  456. }
  457. API_YI_FPD_Get_Configure_SyncOut_Mode = (Func_YI_FPD_Get_Configure_SyncOut_Mode)GetProcAddress(m_hXiuYuanModule, "YI_FPD_Get_Configure_SyncOut_Mode");
  458. if (nullptr == API_YI_FPD_Get_Configure_SyncOut_Mode)
  459. {
  460. FWARN("Load YI_FPD_Get_Configure_SyncOut_Mode failed!");
  461. return false;
  462. }
  463. API_YI_FPD_Set_Configure_SyncOut_Mode = (Func_YI_FPD_Set_Configure_SyncOut_Mode)GetProcAddress(m_hXiuYuanModule, "YI_FPD_Set_Configure_SyncOut_Mode");
  464. if (nullptr == API_YI_FPD_Set_Configure_SyncOut_Mode)
  465. {
  466. FWARN("Load YI_FPD_Set_Configure_SyncOut_Mode failed!");
  467. return false;
  468. }
  469. API_YI_FPD_Restore_Factory_Settings = (Func_YI_FPD_Restore_Factory_Settings)GetProcAddress(m_hXiuYuanModule, "YI_FPD_Restore_Factory_Settings");
  470. if (nullptr == API_YI_FPD_Restore_Factory_Settings)
  471. {
  472. FWARN("Load YI_FPD_Restore_Factory_Settings failed!");
  473. return false;
  474. }
  475. API_YI_Subtract_Offset = (Func_YI_Subtract_Offset)GetProcAddress(m_hXiuYuanModule, "YI_Subtract_Offset");
  476. if (nullptr == API_YI_Subtract_Offset)
  477. {
  478. FWARN("Load YI_FPD_Subtract_Offset failed!");
  479. return false;
  480. }
  481. API_YI_ImageReady_Callback_Register = (Func_YI_ImageReady_Callback_Register)GetProcAddress(m_hXiuYuanModule, "YI_ImageReady_Callback_Register");
  482. if (nullptr == API_YI_ImageReady_Callback_Register)
  483. {
  484. FWARN("Load YI_ImageReady_Callback_Register failed!");
  485. return false;
  486. }
  487. API_YI_SystemInfo_Callback_Register = (Func_YI_SystemInfo_Callback_Register)GetProcAddress(m_hXiuYuanModule, "YI_SystemInfo_Callback_Register");
  488. if (nullptr == API_YI_SystemInfo_Callback_Register)
  489. {
  490. FWARN("Load YI_SystemInfo_Callback_Register failed!");
  491. return false;
  492. }
  493. API_YI_Get_Callback_Image_Size = (Func_YI_Get_Callback_Image_Size)GetProcAddress(m_hXiuYuanModule, "YI_Get_Callback_Image_Size");
  494. if (nullptr == API_YI_Get_Callback_Image_Size)
  495. {
  496. FWARN("Load YI_Get_Callback_Image_Size failed!");
  497. return false;
  498. }
  499. API_YI_GetLastErrorCode = (Func_YI_GetLastErrorCode)GetProcAddress(m_hXiuYuanModule, "YI_GetLastErrorCode");
  500. if (nullptr == API_YI_GetLastErrorCode)
  501. {
  502. FWARN("Load YI_GetLastErrorCode failed!");
  503. return false;
  504. }
  505. API_YI_Set_Save_Log_Flag = (Func_YI_Set_Save_Log_Flag)GetProcAddress(m_hXiuYuanModule, "YI_Set_Save_Log_Flag");
  506. if (nullptr == API_YI_Set_Save_Log_Flag)
  507. {
  508. FWARN("Load YI_Set_Save_Log_Flag failed!");
  509. return false;
  510. }
  511. API_YI_GetLoacalIPs_V4 = (Func_YI_GetLoacalIPs_V4)GetProcAddress(m_hXiuYuanModule, "YI_GetLoacalIPs_V4");
  512. if (nullptr == API_YI_GetLoacalIPs_V4)
  513. {
  514. FWARN("Load YI_GetLoacalIPs_V4 failed!");
  515. return false;
  516. }
  517. API_YI_Set_Image_Save_State = (Func_YI_Set_Image_Save_State)GetProcAddress(m_hXiuYuanModule, "YI_Set_Image_Save_State");
  518. if (nullptr == API_YI_Set_Image_Save_State)
  519. {
  520. FWARN("Load YI_Set_Image_Save_State failed!");
  521. return false;
  522. }
  523. API_YI_Set_Image_Save_Path = (Func_YI_Set_Image_Save_Path)GetProcAddress(m_hXiuYuanModule, "YI_Set_Image_Save_Path");
  524. if (nullptr == API_YI_Set_Image_Save_Path)
  525. {
  526. FWARN("Load YI_Set_Image_Save_Path failed!");
  527. return false;
  528. }
  529. API_YI_FPD_Get_FPD_TYPE = (Func_YI_FPD_Get_FPD_TYPE)GetProcAddress(m_hXiuYuanModule, "YI_FPD_Get_FPD_TYPE");
  530. if (nullptr == API_YI_FPD_Get_FPD_TYPE)
  531. {
  532. FWARN("Load YI_FPD_Get_FPD_TYPE failed!");
  533. return false;
  534. }
  535. API_YI_FPD_Get_Invalid_Region = (Func_YI_FPD_Get_Invalid_Region)GetProcAddress(m_hXiuYuanModule, "YI_FPD_Get_Invalid_Region");
  536. if (nullptr == API_YI_FPD_Get_Invalid_Region)
  537. {
  538. FWARN("Load YI_FPD_Get_Invalid_Region failed!");
  539. return false;
  540. }
  541. API_YI_FPD_Capture_Image = (Func_YI_FPD_Capture_Image)GetProcAddress(m_hXiuYuanModule, "YI_FPD_Capture_Image");
  542. if (nullptr == API_YI_FPD_Capture_Image)
  543. {
  544. FWARN("Load YI_FPD_Capture_Image failed!");
  545. return false;
  546. }
  547. /*API_YI_FPD_Capture_Prepare = (Func_YI_FPD_Capture_Prepare)GetProcAddress(m_hXiuYuanModule, "YI_FPD_Capture_Prepare");
  548. if (nullptr == API_YI_FPD_Capture_Prepare)
  549. {
  550. FWARN("Load YI_FPD_Capture_Prepare failed!");
  551. return false;
  552. }*/
  553. API_YI_Load_Gain_Tmp_File = (Func_YI_Load_Gain_Tmp_File)GetProcAddress(m_hXiuYuanModule, "YI_Load_Gain_Tmp_File");
  554. if (nullptr == API_YI_Load_Gain_Tmp_File)
  555. {
  556. FWARN("Load YI_Load_Gain_Tmp_File failed!");
  557. return false;
  558. }
  559. API_YI_Load_Defect_Tmp_File = (Func_YI_Load_Defect_Tmp_File)GetProcAddress(m_hXiuYuanModule, "YI_Load_Defect_Tmp_File");
  560. if (nullptr == API_YI_Load_Defect_Tmp_File)
  561. {
  562. FWARN("Load YI_Load_Defect_Tmp_File failed!");
  563. return false;
  564. }
  565. API_YI_Load_Offset_Tmp_File = (Func_YI_Load_Offset_Tmp_File)GetProcAddress(m_hXiuYuanModule, "YI_Load_Offset_Tmp_File");
  566. if (nullptr == API_YI_Load_Offset_Tmp_File)
  567. {
  568. FWARN("Load YI_Load_Offset_Tmp_File failed!");
  569. return false;
  570. }
  571. API_YI_Load_AED_Offset_Tmp_File = (Func_YI_Load_AED_Offset_Tmp_File)GetProcAddress(m_hXiuYuanModule, "YI_Load_AED_Offset_Tmp_File");
  572. if (nullptr == API_YI_Load_AED_Offset_Tmp_File)
  573. {
  574. FWARN("Load YI_Load_AED_Offset_Tmp_File failed!");
  575. return false;
  576. }
  577. API_YI_Set_Correct_Type = (Func_YI_Set_Correct_Type)GetProcAddress(m_hXiuYuanModule, "YI_Set_Correct_Type");
  578. if (nullptr == API_YI_Set_Correct_Type)
  579. {
  580. FWARN("Load YI_Set_Correct_Type failed!");
  581. return false;
  582. }
  583. API_YI_FPD_FreeBuffer = (Func_YI_FPD_FreeBuffer)GetProcAddress(m_hXiuYuanModule, "YI_FPD_FreeBuffer");
  584. if (nullptr == API_YI_FPD_FreeBuffer)
  585. {
  586. FWARN("Load YI_FPD_FreeBuffer failed!");
  587. return false;
  588. }
  589. FINFO("LoadXiuYuanDLL Over");
  590. return true;
  591. }
  592. void XiuYuanCtrl::FreeXiuYuanDLL()
  593. {
  594. FINFO("--XiuYuan Ctrl-- FreeXiuYuanDLL");
  595. if (m_hXiuYuanModule)
  596. {
  597. FreeLibrary(m_hXiuYuanModule);
  598. m_hXiuYuanModule = nullptr;
  599. FINFO(" Free XiuYuan DLL");
  600. }
  601. FINFO("FreeXiuYuanDLL Over");
  602. }
  603. bool XiuYuanCtrl::DriverEntry(FPDDeviceXiuYuan* pDrvDPC, ResDataObject& Configuration)
  604. {
  605. FINFO("--XiuYuanCtrl Func-- DriverEntry");
  606. map<FPDDeviceXiuYuan*, int>::iterator DPCsIter = m_pDPC2PanelID->find(pDrvDPC);
  607. if (DPCsIter != m_pDPC2PanelID->end())
  608. {
  609. FERROR("This DPC already exist");
  610. return false;
  611. }
  612. CPanelStatus* p = new CPanelStatus();
  613. m_pStPanelStatus[m_nPanelCount] = p;
  614. m_pDPC2PanelID->insert(pair<FPDDeviceXiuYuan*, int>(pDrvDPC, m_nPanelCount));
  615. m_pPanelID2DPC->insert(pair<int, FPDDeviceXiuYuan*>(m_nPanelCount, pDrvDPC));
  616. m_nPanelCount++;
  617. m_ModeConfig = Configuration; //记录配置 --目前只有一个平板,多板时应该分别存储
  618. FINFO("Config: {$}", m_ModeConfig.encode());
  619. FINFO("DriverEntry Over");
  620. return true;
  621. }
  622. bool XiuYuanCtrl::ActiveDetector(nsDPC::FPDDeviceXiuYuan* pDrvDPC, bool bActive)
  623. {
  624. FINFO("--XiuYuanCtrl Func-- ActiveDetector");
  625. FINFO("ActivePanel start: {$}, DetectorIndex {$}", pDrvDPC, m_nDetectorIndex);
  626. map<nsDPC::FPDDeviceXiuYuan*, int>::iterator DPCsIter = m_pDPC2PanelID->find(pDrvDPC);
  627. if (DPCsIter != m_pDPC2PanelID->end())
  628. {
  629. if (m_nDetectorIndex != DPCsIter->second)
  630. {
  631. FINFO("DetectorIndex {$} != DPCsIter->second {$}", m_nDetectorIndex, DPCsIter->second);
  632. m_nDetectorIndex = DPCsIter->second;
  633. FINFO("ActivePanel over: {$}, DetectorIndex {$}", pDrvDPC, m_nDetectorIndex);
  634. }
  635. else
  636. {
  637. FINFO("DetectorIndex {$} == DPCsIter->second {$}", m_nDetectorIndex, DPCsIter->second);
  638. }
  639. }
  640. else
  641. {
  642. FWARN("Not find DPC in group");
  643. return false;
  644. }
  645. FINFO("ActiveDetector Over");
  646. return true;
  647. }
  648. bool XiuYuanCtrl::EnterExam(APP_STATUS eStatus)
  649. {
  650. string strLog = "";
  651. switch (eStatus)
  652. {
  653. case APP_STATUS_IDLE:
  654. strLog = "APP_STATUS_IDLE";
  655. break;
  656. case APP_STATUS_WORK_BEGIN:
  657. strLog = "APP_STATUS_WORK_BEGIN";
  658. m_bInCalibrating = false;
  659. break;
  660. case APP_STATUS_WORK_END:
  661. strLog = "APP_STATUS_WORK_END";
  662. break;
  663. case APP_STATUS_DETSHARE_BEGIN:
  664. strLog = "APP_STATUS_DETSHARE_BEGIN";
  665. break;
  666. case APP_STATUS_DETSHAR_END:
  667. strLog = "APP_STATUS_DETSHAR_END";
  668. break;
  669. case APP_STATUS_CAL_BEGIN:
  670. strLog = "APP_STATUS_CAL_BEGIN";
  671. break;
  672. case APP_STATUS_CAL_END:
  673. strLog = "APP_STATUS_CAL_END";
  674. m_bInCalibrating = false;
  675. break;
  676. default:
  677. break;
  678. }
  679. FINFO("Enter exam: {$}", strLog.c_str());
  680. m_eAppStatus = eStatus;
  681. return true;
  682. }
  683. /***
  684. ** 说明:连接
  685. ** 加载SDK,初始化SDK,连接探测器等初始化操作
  686. ** 参数:strWorkPath,初始化SDK必须的conf路径
  687. ***/
  688. bool XiuYuanCtrl::Connect(FPDDeviceXiuYuan* pDrvDPC, string strWorkPath)
  689. {
  690. FINFO("--XiuYuanCtrl Func-- Connect");
  691. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  692. {
  693. FWARN("Not current DPC, return true");
  694. return true;
  695. }
  696. if (!m_pZSKKCalib)
  697. {
  698. m_pZSKKCalib = new CZSKKCalibrationCtrl();
  699. }
  700. m_strWorkPath = strWorkPath;
  701. if (!Init(strWorkPath))
  702. {
  703. FERROR("Load Dll Failed");
  704. }
  705. if (!DetectorInitProcess(1))
  706. {
  707. FERROR("Init Detector failed");
  708. }
  709. FINFO("=== Connect detector OK ===");
  710. FINFO("Connect Over");
  711. return true;
  712. }
  713. /***
  714. ** 说明:退出
  715. ** 释放SDK
  716. ***/
  717. bool XiuYuanCtrl::DisConnect(nsDPC::FPDDeviceXiuYuan* pDrvDPC)
  718. {
  719. FINFO("--XiuYuanCtrl Func-- DisConnect");
  720. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  721. {
  722. FWARN("Not current DPC, return");
  723. return true;
  724. }
  725. FINFO("DicConnect DoNothing");
  726. FINFO("DisConnect Over");
  727. return true;
  728. }
  729. /***
  730. ** 说明:设置当前的曝光模式
  731. ** 参数:nLogicMode,从配置文件读取,与SDK配置application mode对应
  732. ***/
  733. bool XiuYuanCtrl::SetAcqMode(string strLogicMode)
  734. {
  735. FINFO("--XiuYuanCtrl Func-- SetAcqMode");
  736. if (m_bConnectStatus == false)
  737. {
  738. FERROR("Current detector {$} is not connect, return", m_nDetectorIndex);
  739. return false;
  740. }
  741. if (m_strAcqMode == "RAD")
  742. {
  743. FINFO("Same Acq Mode");
  744. FINFO("SetAcqMode Over");
  745. return true;
  746. }
  747. m_bSaveRaw = (bool)m_ModeConfig["IsSaveRaw"];
  748. try
  749. {
  750. m_nRawImgHeight = (int)m_ModeConfig["ModeTable"][0]["RawImgHeight"];
  751. m_nRawImgWidth = (int)m_ModeConfig["ModeTable"][0]["RawImgWidth"];
  752. m_nImageHeight = (int)m_ModeConfig["ModeTable"][0]["ImageHeight"];
  753. m_nImageWidth = (int)m_ModeConfig["ModeTable"][0]["ImageWidth"];
  754. m_nWidthOffset = (int)m_ModeConfig["ModeTable"][0]["WidthOffset"];
  755. m_nHeightOffset = (int)m_ModeConfig["ModeTable"][0]["HeightOffset"];
  756. m_nImgBits = (int)m_ModeConfig["ModeTable"][0]["PhySizeInfoBit"];
  757. m_nPixelPitch = (int)m_ModeConfig["ModeTable"][0]["PixelPitch"];
  758. FINFO("Raw({$}*{$}), Effective({$}*{$}), Offset({$} {$}), Bits({$}), PixelPitch({$})",
  759. m_nRawImgWidth, m_nRawImgHeight, m_nImageWidth, m_nImageHeight, m_nHeightOffset, m_nWidthOffset,
  760. m_nImgBits, m_nPixelPitch);
  761. }
  762. catch (ResDataObjectExption& exp)
  763. {
  764. FERROR("Get config failed: {$}", exp.what());
  765. }
  766. if (m_pImgBuffer)
  767. {
  768. delete[] m_pImgBuffer;
  769. m_pImgBuffer = nullptr;
  770. }
  771. m_pImgBuffer = new WORD[m_nImageHeight * m_nImageWidth];
  772. FINFO("SetAcqMode Over");
  773. return true;
  774. }
  775. //设置同步模式
  776. bool XiuYuanCtrl::SetSyncMode(int nSyncMode)
  777. {
  778. FINFO("--XiuYuanCtrl Func-- SetSyncMode");
  779. FpdMode tempFpdMode;
  780. int tempSyncMode = 0;
  781. if (nSyncMode == 1)
  782. {
  783. tempSyncMode = TrigType::SOFT_TRIG_MODE;
  784. }
  785. else if (nSyncMode == 2)
  786. {
  787. tempSyncMode = TrigType::EXT_TRIG_MODE;
  788. }
  789. else if (nSyncMode == 3)
  790. {
  791. tempSyncMode = TrigType::SENSOR_TRIG_MODE;
  792. }
  793. FINFO("To SetDetectorWorkMode {$}", tempSyncMode);
  794. if (m_nSyncMode == tempSyncMode)
  795. {
  796. FINFO("Same sync mode, omit set sync mode");
  797. FINFO("SetSyncMode Over");
  798. return true;
  799. }
  800. tempFpdMode.workMode = ModeType::Normal_Mode;
  801. tempFpdMode.trigType = tempSyncMode;
  802. const char* szDetectorID = m_vecDetectorID[m_nDetectorIndex].c_str();
  803. if (SetDetectorWorkMode(m_nDetectorID, szDetectorID, &tempFpdMode))
  804. {
  805. m_nSyncMode = tempSyncMode;
  806. FINFO("Set detector sync mode into {$}", tempSyncMode);
  807. }
  808. else
  809. {
  810. FERROR("Set detector sync mode failed!");
  811. }
  812. FINFO("SetSyncMode Over");
  813. return true;
  814. }
  815. /***
  816. ** 说明:曝光前的准备流程
  817. ***/
  818. RET_STATUS XiuYuanCtrl::PrepareAcquisition(nsDPC::FPDDeviceXiuYuan* pDrvDPC)
  819. {
  820. FINFO("--XiuYuanCtrl Func-- PrepareAcquisition");
  821. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  822. {
  823. FWARN("Not current DPC, return");
  824. return RET_STATUS::RET_FAILED;
  825. }
  826. if (m_bConnectStatus == false)
  827. {
  828. FINFO("Current detector is not connect, return");
  829. return RET_STATUS::RET_FAILED;
  830. }
  831. int nRet = API_YI_FPD_Stop_Capture_Image(m_vecDetectorID[m_nDetectorIndex].c_str());
  832. if (TestError(m_nDetectorID, nRet, "Stop_Capture_Image"))
  833. {
  834. FERROR("Stop Capture image failed");
  835. }
  836. int nTempTriggerMode = m_nSyncMode;
  837. if (TrigType::SOFT_TRIG_MODE != nTempTriggerMode)
  838. {
  839. nRet = API_YI_FPD_Capture_Image(m_vecDetectorID[m_nDetectorIndex].c_str(), 1);
  840. if (TestError(m_nDetectorID, nRet, "Capture_Image"))
  841. {
  842. FERROR("Capture image failed");
  843. }
  844. }
  845. if (TrigType::SOFT_TRIG_MODE == nTempTriggerMode)
  846. {
  847. StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY);
  848. }
  849. m_bStandbyFlag = true;
  850. m_bAEDWorkFlag = false;
  851. FINFO("PrepareAcquisition Over");
  852. return RET_STATUS::RET_SUCCEED;
  853. }
  854. RET_STATUS XiuYuanCtrl::StartAcquisition(nsDPC::FPDDeviceXiuYuan* pDrvDPC)
  855. {
  856. FINFO("--XiuYuanCtrl Func-- StartAcquisition");
  857. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  858. {
  859. FWARN("Not current DPC, return");
  860. return RET_STATUS::RET_FAILED;
  861. }
  862. RET_STATUS Ret = RET_STATUS::RET_FAILED;
  863. if (!m_bConnectStatus)
  864. {
  865. FWARN("Detector not in connection when start acq, return failed");
  866. return RET_STATUS::RET_FAILED;
  867. }
  868. StatusFeedback(EVT_STATUS_ACQUISITION, PANEL_EVENT_START);
  869. m_bInExposure = true;
  870. int nTempTriggerMode = m_nSyncMode;
  871. if (TrigType::SOFT_TRIG_MODE == nTempTriggerMode) //软同步
  872. {
  873. FINFO("Softerware mode");
  874. int nRet = API_YI_FPD_Capture_Image(m_vecDetectorID[m_nDetectorIndex].c_str(), 1);
  875. if (TestError(m_nDetectorID, nRet, "Capture_Image"))
  876. {
  877. FERROR("Capture image failed");
  878. }
  879. }
  880. /*int nRet = API_YI_FPD_Capture_Image(m_vecDetectorID[m_nDetectorIndex].c_str(), 1);
  881. if (TestError(m_nDetectorID, nRet, "Capture_Image"))
  882. {
  883. FERROR("Capture image failed");
  884. }*/
  885. StatusFeedback(EVT_STATUS_ACQUISITION, PANEL_EVENT_END_OK);
  886. FINFO("PANEL_START_ACQ");
  887. StatusFeedback(EVT_STATUS_PANEL, PANEL_START_ACQ);
  888. if (TrigType::SOFT_TRIG_MODE == nTempTriggerMode)
  889. {
  890. StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON);
  891. }
  892. if (m_nSyncMode == TrigType::SENSOR_TRIG_MODE)
  893. {
  894. FINFO("AED Work Flag");
  895. m_bAEDWorkFlag = true;
  896. }
  897. FINFO("StartAcquisition Over");
  898. return RET_STATUS::RET_SUCCEED;
  899. }
  900. RET_STATUS XiuYuanCtrl::StopAcquisition(nsDPC::FPDDeviceXiuYuan* pDrvDPC)
  901. {
  902. FINFO("--XiuYuanCtrl Func-- StopAcquisition");
  903. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  904. {
  905. FWARN("Not current DPC, return");
  906. return RET_STATUS::RET_FAILED;
  907. }
  908. int nRet = API_YI_FPD_Stop_Capture_Image(m_vecDetectorID[m_nDetectorIndex].c_str());
  909. if (TestError(m_nDetectorID, nRet, "Stop_Capture_Image"))
  910. {
  911. FERROR("Stop Capture image failed");
  912. }
  913. FINFO("StopAcquisition Over");
  914. return RET_STATUS::RET_SUCCEED;
  915. }
  916. /********************************************************************/
  917. //功能:XiuYuan没有曝光窗口关闭的消息,启动线程,等待500ms曝光窗口过后,模拟发送曝光窗口关闭的消息给HW层
  918. /********************************************************************/
  919. bool XiuYuanCtrl::StartXWindowOffThread()
  920. {
  921. if (m_pXWindowoffThread == nullptr)
  922. {
  923. DWORD m_NotifyThreadID;
  924. m_pXWindowoffThread = CreateThread(0, 0, XWindowOffThread, this, 0, &m_NotifyThreadID);
  925. if (m_pXWindowoffThread == nullptr)
  926. {
  927. FWARN("Start Inner Exp Thread Failed");
  928. return false;
  929. }
  930. }
  931. return true;
  932. }
  933. /********************************************************************/
  934. //功能:XiuYuan没有曝光窗口关闭的消息,启动线程,等待500ms曝光窗口过后,模拟发送曝光窗口关闭的消息给HW层
  935. /********************************************************************/
  936. DWORD XiuYuanCtrl::XWindowOffThread(LPVOID pParam)
  937. {
  938. XiuYuanCtrl* pCurPanel = (XiuYuanCtrl*)pParam;
  939. if (pCurPanel == nullptr)
  940. {
  941. return false;
  942. }
  943. DWORD dwTimer = pCurPanel->m_nXWindow;
  944. DWORD dwResult = WaitForSingleObject(pCurPanel->m_hWindowOffEvent, dwTimer);
  945. Sleep(50);
  946. FINFO("Simulate XWINDOW_OFF");
  947. pCurPanel->StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_OFF);
  948. pCurPanel->m_pXWindowoffThread = nullptr;
  949. return true;
  950. }
  951. /***
  952. ** 说明:激活校正
  953. ** 增益校正(探测器采用post-offset,暗场校正基本没用了)时拿到dose回调,算作执行完毕
  954. ***/
  955. bool XiuYuanCtrl::ActiveCalibration(nsDPC::FPDDeviceXiuYuan* pDrvDPC, CCOS_CALIBRATION_TYPE Type)
  956. {
  957. FINFO("--XiuYuanCtrl Func-- ActiveCalibration");
  958. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  959. {
  960. FWARN("Not current DPC, return");
  961. return RET_STATUS::RET_FAILED;
  962. }
  963. StatusFeedback(EVT_STATUS_CALIBRATIOIN, PANEL_EVENT_START);
  964. m_eAppStatus = APP_STATUS_CAL_BEGIN; //激活校正,置为校正界面
  965. m_eCaliType = Type;
  966. if (CCOS_CALIBRATION_TYPE_DARK == m_eCaliType)
  967. {
  968. FINFO("Active Dark Calibration");
  969. }
  970. if (CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType)
  971. {
  972. FINFO("Active Xray Calibration");
  973. if (m_nCalibrationMode) //厂商校正ActiveCalibration
  974. {
  975. }
  976. else //ZSKK校正
  977. {
  978. if (!m_pZSKKCalib)
  979. {
  980. FERROR("ZSKK Calibration object is undefined");
  981. }
  982. else
  983. {
  984. //加载ZSKK的校正文件
  985. m_pZSKKCalib->m_strRawImgPath = m_strWorkPath + "\\rawdata\\";
  986. m_pZSKKCalib->m_strRefFilePath = m_strWorkPath + "\\references\\";
  987. m_pZSKKCalib->m_nFullImgWidth = m_nImageWidth;
  988. m_pZSKKCalib->m_nFullImgHeight = m_nImageHeight;
  989. m_pZSKKCalib->m_nReferenceNum = m_nCalibrationRounds;
  990. m_pZSKKCalib->m_nSaturationValue = 50000;
  991. //LoadZSKKGainMap 参数为false,意思是开始增益校正
  992. m_pZSKKCalib->LoadZSKKGainMap(false, m_strDetectorType);
  993. m_pZSKKCalib->LoadZSKKPixelMap(false, m_strDetectorType);
  994. FINFO("Load ecom gain and pixel map, references file path: {$}", m_pZSKKCalib->m_strRefFilePath);
  995. }
  996. }
  997. }
  998. FINFO("ActiveCalibration Over");
  999. return true;
  1000. }
  1001. /***
  1002. ** 说明:准备校正(状态机FramePrep)
  1003. ** 曝光使能过程,使探测器开窗
  1004. ***/
  1005. bool XiuYuanCtrl::PrepareCalibration(nsDPC::FPDDeviceXiuYuan* pDrvDPC)
  1006. {
  1007. FINFO("--XiuYuanCtrl Func-- PrepareCalibration");
  1008. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  1009. {
  1010. FWARN("Not current DPC, return");
  1011. return false;
  1012. }
  1013. if (CCOS_CALIBRATION_TYPE_DARK == m_eCaliType)
  1014. {
  1015. FINFO("PrepareCalibration CCOS_CALIBRATION_TYPE_DARK == m_eCaliType");
  1016. //由于前端没有测试过暗场校正上图的情况,故此处不进行暗场上图
  1017. }
  1018. else if (CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType)
  1019. {
  1020. FINFO("PrepareCalibration CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType");
  1021. m_bCancelFlag = false; //准备校正前恢复初值
  1022. bool ret = PrepareAcquisition(pDrvDPC);
  1023. if (ret)
  1024. {
  1025. FINFO("PrepareCalibration PrepareAcquisition success!");
  1026. }
  1027. else
  1028. {
  1029. FERROR("PrepareCalibration PrepareAcquisition fail!");
  1030. FERROR("PrepareCalibration Over");
  1031. return false;
  1032. }
  1033. }
  1034. FINFO("PrepareCalibration Over");
  1035. return true;
  1036. }
  1037. /***
  1038. ** 说明:开始校正(状态机FrameStart)
  1039. ***/
  1040. bool XiuYuanCtrl::StartCalibration(nsDPC::FPDDeviceXiuYuan* pDrvDPC)
  1041. {
  1042. FINFO("--XiuYuanCtrl Func-- StartCalibration");
  1043. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  1044. {
  1045. FWARN("Not current DPC, return");
  1046. return false;
  1047. }
  1048. if (CCOS_CALIBRATION_TYPE_DARK == m_eCaliType)
  1049. {
  1050. FINFO("StartCalibration DARK");
  1051. StatusFeedback(EVT_STATUS_CALIBRATIOIN, PANEL_EVENT_END_OK);
  1052. m_pStPanelStatus[m_nDetectorIndex]->eFPDStatus = eDetStatus::DetStatus_Offset;
  1053. }
  1054. else if (CCOS_CALIBRATION_TYPE_XRAY == m_eCaliType)
  1055. {
  1056. FINFO("StartCalibration XRAY");
  1057. bool ret = StartAcquisition(pDrvDPC);
  1058. if (!ret)
  1059. {
  1060. FERROR("StartCalibration Over");
  1061. return false;
  1062. }
  1063. m_pStPanelStatus[m_nDetectorIndex]->eFPDStatus = eDetStatus::DetStatus_XrayCalibration;
  1064. }
  1065. FINFO("StartCalibration Over");
  1066. return true;
  1067. }
  1068. bool XiuYuanCtrl::StopCalibration(FPDDeviceXiuYuan* pDrvDPC)
  1069. {
  1070. FINFO("--XiuYuanCtrl Func-- StopCalibration");
  1071. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  1072. {
  1073. FERROR("Not current DPC, return");
  1074. return false;
  1075. }
  1076. if (!m_bConnectStatus)
  1077. {
  1078. FERROR("bConnectState is false, Detector not connected, return");
  1079. return false;
  1080. }
  1081. m_bCancelFlag = true;//中止校正
  1082. m_eAppStatus = APP_STATUS_CAL_END;
  1083. FINFO("StopCalibration Over");
  1084. return true;
  1085. }
  1086. /***
  1087. ** 说明:终止校正
  1088. ***/
  1089. bool XiuYuanCtrl::AbortCalibration(nsDPC::FPDDeviceXiuYuan* pDrvDPC)
  1090. {
  1091. FINFO("--XiuYuanCtrl Func-- AbortCalibration");
  1092. m_eCaliType = CCOS_CALIBRATION_TYPE_NONE; //恢复初值
  1093. if (m_nCalibrationMode) //厂商校正AbortCalibration
  1094. {
  1095. }
  1096. else
  1097. {
  1098. FINFO("Reload Gain Map And Pixel Map");
  1099. //重新加载增益校正文件
  1100. if (!m_pZSKKCalib->LoadZSKKGainMap(true, m_strDetectorType))
  1101. {
  1102. Warn("Load ZSKK Gain calibration failed");
  1103. }
  1104. //放弃坏点校正并重新加载原来的坏点校正文件
  1105. m_pZSKKCalib->AbortZSKKPixMap(m_strDetectorType);
  1106. }
  1107. m_eAppStatus = APP_STATUS_CAL_END;
  1108. FINFO("AbortCalibration Over");
  1109. return true;
  1110. }
  1111. bool XiuYuanCtrl::AcceptCalibration()
  1112. {
  1113. FINFO("--XiuYuanCtrl Func-- AcceptCalibration");
  1114. if (m_nCalibrationMode)//厂商校正AcceptCalibration
  1115. {
  1116. //不做处理
  1117. }
  1118. else //ZSKK校正
  1119. {
  1120. WORD* pImageBuffer = nullptr;
  1121. //这里要注意使用的image buffer是哪个,裁剪和不裁剪是不一样的
  1122. if (m_nWidthOffset != 0 || m_nHeightOffset != 0)
  1123. {
  1124. pImageBuffer = m_pImgBuffer;
  1125. }
  1126. else
  1127. {
  1128. pImageBuffer = m_pRawImgBuffer;
  1129. }
  1130. if (m_nCalibCurrentExposureIndex == 1)
  1131. {
  1132. m_pZSKKCalib->AddImageToPixMap(pImageBuffer);
  1133. m_pZSKKCalib->AverageZSKKGainMap(pImageBuffer, m_nCalibCurrentCalibrationRound - 1, true);
  1134. }
  1135. else
  1136. {
  1137. m_pZSKKCalib->AverageZSKKGainMap(pImageBuffer, m_nCalibCurrentCalibrationRound - 1, false); //曝光第几轮
  1138. }
  1139. }
  1140. FINFO("AcceptCalibration Over");
  1141. return true;
  1142. }
  1143. bool XiuYuanCtrl::RejectCalibration()
  1144. {
  1145. FINFO("--XiuYuanCtrl Func-- RejectCalibration");
  1146. FINFO("Reject Calibration");
  1147. FINFO("RejectCalibration Over");
  1148. return true;
  1149. }
  1150. void XiuYuanCtrl::SetCalibRounds(int nCalibRounds)
  1151. {
  1152. FINFO("--XiuYuanCtrl Func-- SetCalibRounds");
  1153. m_nCalibrationRounds = nCalibRounds;
  1154. FINFO("Set CalibrationRounds: {$}", m_nCalibrationRounds);
  1155. FINFO("SetCalibRounds Over");
  1156. }
  1157. bool XiuYuanCtrl::GetCalibrationStep(int nCalibCurrentCalibrationRound, int nCalibrationRounds, int nCalibCurrentExposureIndex, int nExposureNumCurrentRound)
  1158. {
  1159. FINFO("--XiuYuanCtrl Func-- GetCalibrationStep");
  1160. m_nCalibCurrentCalibrationRound = nCalibCurrentCalibrationRound;
  1161. m_nCalibrationRounds = nCalibrationRounds;
  1162. m_nCalibCurrentExposureIndex = nCalibCurrentExposureIndex;
  1163. m_nExposureNumCurrentRound = nExposureNumCurrentRound;
  1164. FINFO("Calibration Step===Round: {$}/{$}, ExposureNum: {$}/{$}", nCalibCurrentCalibrationRound, nCalibrationRounds,
  1165. nCalibCurrentExposureIndex, nExposureNumCurrentRound);
  1166. FINFO("GetCalibrationStep Over");
  1167. return true;
  1168. }
  1169. /***
  1170. ** 说明:结束校正
  1171. ** DPC处理完校正报告后调用,此处上传map、报告等文件
  1172. ***/
  1173. bool XiuYuanCtrl::CompleteCalibration(nsDPC::FPDDeviceXiuYuan* pDrvDPC)
  1174. {
  1175. FINFO("--XiuYuanCrtl Func-- CompleteCalibration");
  1176. if ((*m_pDPC2PanelID)[pDrvDPC] != m_nDetectorIndex)
  1177. {
  1178. FWARN("Not current DPC, return");
  1179. return false;
  1180. }
  1181. FINFO("Calib type {$}", (int)m_eCaliType);
  1182. if (m_eCaliType == CCOS_CALIBRATION_TYPE_DARK)
  1183. {
  1184. FINFO("DARK Calib over");
  1185. }
  1186. else if (m_eCaliType == CCOS_CALIBRATION_TYPE_XRAY)
  1187. {
  1188. FINFO("XRAY Calib over");
  1189. m_eAppStatus = APP_STATUS_CAL_END;
  1190. }
  1191. FINFO("CompleteCalibration Over");
  1192. return true;
  1193. }
  1194. CCOS_CALIBRATION_TYPE XiuYuanCtrl::GetCalibType()
  1195. {
  1196. FINFO("--XiuYuanCtrl Func-- GetCalibType");
  1197. FINFO("CalibType: {$}", (int)m_eCaliType);
  1198. FINFO("GetCalibType Over");
  1199. return m_eCaliType;
  1200. }
  1201. bool XiuYuanCtrl::UpdateCalibMode(CCOS_CALIBRATION_MODE eCalibMode)
  1202. {
  1203. FINFO("--XiuYuanCtrl Func-- UpdateCalibMode");
  1204. FINFO("CalibMode: {$}", (int)eCalibMode);
  1205. m_nCalibrationMode = eCalibMode;
  1206. FINFO("UpdateCalibMode Over");
  1207. return true;
  1208. }
  1209. bool XiuYuanCtrl::SaveCalibrationFile()
  1210. {
  1211. FINFO("--XiuYuanCtrl Func-- SaveCalibrationFile");
  1212. if (m_nCalibrationMode)//厂商校正SaveCalibrationFile
  1213. {
  1214. //不做处理
  1215. }
  1216. else
  1217. {
  1218. FINFO("Save ZSKK Calibration File");
  1219. m_pZSKKCalib->StoreZSKKGainMap(m_strDetectorType);
  1220. m_pZSKKCalib->StoreZSKKPixMap(m_strDetectorType);
  1221. }
  1222. //更新配置文件中校正日期和时间
  1223. SYSTEMTIME stCurrentTime = { 0 };
  1224. GetLocalTime(&stCurrentTime);
  1225. FINFO("save calib file time: {$04d}/{$02d}/{$02d} {$02d}:{$02d}:{$02d}:{$03d}",
  1226. stCurrentTime.wYear, stCurrentTime.wMonth, stCurrentTime.wDay,
  1227. stCurrentTime.wHour, stCurrentTime.wMinute, stCurrentTime.wSecond, stCurrentTime.wMilliseconds);
  1228. FINFO("SaveCalibrationFile over");
  1229. return true;
  1230. }
  1231. //设置探测器的工作模式
  1232. bool XiuYuanCtrl::SetDetectorWorkMode(int nDetectorID, const char* szFPD, FpdMode* stWorkMode)
  1233. {
  1234. FINFO("--XiuYuanCtrl Func-- SetDetectorWorkMode");
  1235. FINFO("Set detector({$})({$}) work mode: {$}", nDetectorID, szFPD, stWorkMode->workMode);
  1236. int nRet = API_YI_FPD_Set_Work_Mode(szFPD, stWorkMode);
  1237. if (TestError(nDetectorID, nRet, "API_YI_FPD_Set_Work_Mode"))
  1238. {
  1239. FERROR("Set work mode failed!!!");
  1240. FERROR("SetDetectorWorkMode Over");
  1241. return false;
  1242. }
  1243. else
  1244. {
  1245. FINFO("Set work mode success");
  1246. }
  1247. FINFO("SetDetectorWorkMode Over");
  1248. return true;
  1249. }
  1250. //加载校正
  1251. bool XiuYuanCtrl::FPDLoadCorrectFiles(int nDetectorID, const char* szDetectorID)
  1252. {
  1253. FINFO("--XiuYuan Func-- FPDLoadCorrectFiles");
  1254. int nRet = 0;
  1255. std::string strGainPath = m_stDeviceIndex[m_nDetectorIndex].strGainPath;
  1256. std::string strDefectPath = m_stDeviceIndex[m_nDetectorIndex].strDefectPath;
  1257. if (m_stDeviceIndex[m_nDetectorIndex].bGainDefectEnable)
  1258. {
  1259. nRet = API_YI_Load_Gain_Tmp_File(szDetectorID, strGainPath.c_str()); //加载Gain模板
  1260. if (TestError(nDetectorID, nRet, "Load_Gain"))
  1261. {
  1262. FERROR("Load gain template failed!");
  1263. }
  1264. else
  1265. {
  1266. FINFO("Load gain tempplate success");
  1267. }
  1268. nRet = API_YI_Load_Defect_Tmp_File(szDetectorID, strDefectPath.c_str());
  1269. if (TestError(nDetectorID, nRet, "Load_Defect"))
  1270. {
  1271. FERROR("Load defect template failed!");
  1272. }
  1273. else
  1274. {
  1275. FINFO("Load defect template success");
  1276. }
  1277. int nCorrectType = Do_Gain | Do_Defect;
  1278. nRet = API_YI_Set_Correct_Type(szDetectorID, nCorrectType);
  1279. if (TestError(nDetectorID, nRet, "Set_Correction"))
  1280. {
  1281. FERROR("Set correction failed!");
  1282. }
  1283. else
  1284. {
  1285. FINFO("Set correction success");
  1286. }
  1287. }
  1288. //设置探测器做Offset校正
  1289. nRet = API_YI_Subtract_Offset(szDetectorID, true);
  1290. if (TestError(nDetectorID, nRet, "Set_Offset"))
  1291. {
  1292. FERROR("Set offset failed!");
  1293. }
  1294. else
  1295. {
  1296. FINFO("Set offset success");
  1297. }
  1298. FINFO("FPDLoadCorrectFiles Over");
  1299. return true;
  1300. }
  1301. bool XiuYuanCtrl::IsConnected(string strIP)
  1302. {
  1303. FINFO("Check ping {$}", strIP);
  1304. CMyPingip obPingIp;
  1305. StatusFeedback(EVT_STATUS_PING, 0, "true");
  1306. if (!obPingIp.PingFunction(strIP.c_str()))
  1307. {
  1308. FINFO("ping {$} Failed", strIP);
  1309. StatusFeedback(EVT_STATUS_PING, 0, "false");
  1310. return false;
  1311. }
  1312. return true;
  1313. }
  1314. void XiuYuanCtrl::OnProcessImg()
  1315. {
  1316. if (m_nWidthOffset != 0 || m_nHeightOffset != 0)
  1317. {
  1318. FDEBUG("Begin get effect image, m_nRawImgWidth {$}", m_nRawImgWidth);
  1319. if (!GetEffectiveImage(m_pImgBuffer, m_pRawImgBuffer, m_nRawImgWidth))
  1320. {
  1321. FERROR("Get effect image failed");
  1322. return;
  1323. }
  1324. FDEBUG("Get effect image over");
  1325. if (m_eAppStatus != APP_STATUS_CAL_BEGIN && m_nCalibrationMode == CCOS_CALIBRATION_MODE_ZSKK)
  1326. {
  1327. FINFO("Apply ZSKK Calibration File");
  1328. m_pZSKKCalib->m_nGridSuppressed = 6;
  1329. m_pZSKKCalib->ApplyZSKKReference(m_nImageHeight, m_nImageWidth, m_pImgBuffer);
  1330. }
  1331. if (m_bSaveRaw)
  1332. {
  1333. std::string strFileName = m_strWorkPath + "\\rawdata";
  1334. strFileName += "\\AfterCalImage.raw";
  1335. std::filesystem::path file_path{ strFileName.c_str() };
  1336. std::ofstream file_stream(file_path, std::ios::binary);
  1337. if (!file_stream.is_open())
  1338. {
  1339. FERROR("Open Save File Failed");
  1340. }
  1341. unsigned int nTempSize = m_nImageHeight * m_nImageWidth * 2;
  1342. file_stream.write(reinterpret_cast<const char*>(m_pImgBuffer), nTempSize);
  1343. file_stream.close();
  1344. }
  1345. DataFeedback(EVT_DATA_RAW_IMAGE, m_pImgBuffer);
  1346. }
  1347. else
  1348. {
  1349. //memcpy(m_pImgBuffer, m_pRawImgBuffer, m_nImageHeight * m_nImageWidth * sizeof(WORD));
  1350. if (m_eAppStatus != APP_STATUS_CAL_BEGIN && m_nCalibrationMode == CCOS_CALIBRATION_MODE_ZSKK)
  1351. {
  1352. FINFO("Apply ZSKK Calibration File");
  1353. m_pZSKKCalib->m_nGridSuppressed = 6;
  1354. m_pZSKKCalib->ApplyZSKKReference(m_nRawImgHeight, m_nRawImgWidth, m_pRawImgBuffer);
  1355. }
  1356. if (m_bSaveRaw)
  1357. {
  1358. std::string strFileName = m_strWorkPath + "\\rawdata";
  1359. strFileName += "\\AfterCalImage.raw";
  1360. std::filesystem::path file_path{ strFileName.c_str() };
  1361. std::ofstream file_stream(file_path, std::ios::binary);
  1362. if (!file_stream.is_open())
  1363. {
  1364. FERROR("Open Save File Failed");
  1365. }
  1366. unsigned int nTempSize = m_nRawImgHeight * m_nRawImgWidth * 2;
  1367. file_stream.write(reinterpret_cast<const char*>(m_pRawImgBuffer), nTempSize);
  1368. file_stream.close();
  1369. }
  1370. DataFeedback(EVT_DATA_RAW_IMAGE, m_pRawImgBuffer);
  1371. }
  1372. }
  1373. // pOutImg: 裁剪后图像; pInImg: 裁剪前图像; nInWidth: 裁剪前图像宽度
  1374. bool XiuYuanCtrl::GetEffectiveImage(WORD* pOutImg, WORD* pInImg, int nInWidth)
  1375. {
  1376. if (pOutImg == nullptr || pInImg == nullptr || nInWidth < 0)
  1377. {
  1378. FERROR("Illegal parameter, can not get effective image");
  1379. return false;
  1380. }
  1381. try
  1382. {
  1383. for (int i = 0; i < m_nImageHeight; i++)
  1384. {
  1385. memcpy(pOutImg + i * m_nImageWidth,
  1386. pInImg + (i + m_nHeightOffset) * nInWidth + m_nWidthOffset,
  1387. m_nImageWidth * sizeof(WORD));
  1388. }
  1389. }
  1390. catch (...)
  1391. {
  1392. FERROR("Get effective image crashed. m_nImageWidth {$},m_nImageHeight {$},m_nWidthOffset {$},m_nHeightOffset {$}",
  1393. m_nImageWidth, m_nImageHeight, m_nWidthOffset, m_nHeightOffset);
  1394. return false;
  1395. }
  1396. return true;
  1397. }
  1398. /***
  1399. * 保存RAW图像
  1400. ***/
  1401. bool XiuYuanCtrl::SaveRawImage(const char* pImgName, const WORD* pRawImg, int nWidth, int nHeight)
  1402. {
  1403. FINFO("Begin to Save {$} Image, width: {$}, height: {$}", pImgName, nWidth, nHeight);
  1404. if (pRawImg == nullptr || pImgName == nullptr)
  1405. {
  1406. return false;
  1407. }
  1408. string strImagePath = m_strAppPath + "\\rawdata\\" + pImgName;
  1409. std::filesystem::path file_path{ strImagePath.c_str() };
  1410. std::ofstream file_stream(file_path, std::ios::binary);
  1411. if (!file_stream.is_open())
  1412. {
  1413. FERROR("Open {$} Failed!", strImagePath);
  1414. }
  1415. unsigned int nSize = nWidth * nHeight * sizeof(WORD);
  1416. file_stream.write(reinterpret_cast<const char*>(pRawImg), nSize);
  1417. file_stream.close();
  1418. FINFO("End to Save Raw Image");
  1419. return true;
  1420. }
  1421. //图像回调
  1422. bool XiuYuanCtrl::ImageReadyCallbackProcess(const char* pImage, unsigned long iFlag)
  1423. {
  1424. return g_pXiuYuanCtrl->onImageReadyCallbackProcess(pImage, iFlag);
  1425. }
  1426. //系统回调
  1427. bool XiuYuanCtrl::SystemInfoCallbackProcess(SystemInfoCode iCodeIndex, const char* sContent)
  1428. {
  1429. return g_pXiuYuanCtrl->onSystemInfoCallbackProcess(iCodeIndex, sContent);
  1430. }
  1431. bool XiuYuanCtrl::onImageReadyCallbackProcess(const char* pImage, int iFlag)
  1432. {
  1433. FINFO("onImageReadyCallbackProcess");
  1434. if (nullptr == pImage)
  1435. {
  1436. FWARN("Image Data is null");
  1437. return false;
  1438. }
  1439. if (TrigType::SENSOR_TRIG_MODE == m_nSyncMode)
  1440. {
  1441. while (!m_bAEDWorkFlag)
  1442. {
  1443. Sleep(20);
  1444. }
  1445. StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON);
  1446. FINFO("StartXWindowOffThread");
  1447. StartXWindowOffThread();
  1448. }
  1449. else if (TrigType::EXT_TRIG_MODE == m_nSyncMode)
  1450. {
  1451. StatusFeedback(EVT_STATUS_PANEL, PANEL_XWINDOW_ON);
  1452. FINFO("StartXWindowOffThread");
  1453. StartXWindowOffThread();
  1454. }
  1455. else if (TrigType::SOFT_TRIG_MODE == m_nSyncMode)
  1456. {
  1457. FINFO("StartXWindowOffThread");
  1458. StartXWindowOffThread();
  1459. }
  1460. if (m_pRawImgBuffer)
  1461. {
  1462. delete[] m_pRawImgBuffer;
  1463. m_pRawImgBuffer = nullptr;
  1464. }
  1465. m_pRawImgBuffer = new WORD[m_nRawImgHeight * m_nRawImgWidth];
  1466. if (m_pRawImgBuffer == nullptr)
  1467. {
  1468. FWARN("Allocate Raw Image Failed");
  1469. return false;
  1470. }
  1471. memcpy(m_pRawImgBuffer, pImage, m_nRawImgHeight * m_nRawImgWidth * sizeof(WORD));
  1472. if (m_bSaveRaw)
  1473. {
  1474. std::string strFileName = m_strWorkPath + "\\rawdata";
  1475. strFileName += "\\Image.raw";
  1476. std::filesystem::path file_path{ strFileName.c_str() };
  1477. std::ofstream file_stream(file_path, std::ios::binary);
  1478. if (!file_stream.is_open())
  1479. {
  1480. FERROR("Open Save File Failed");
  1481. }
  1482. unsigned int nTempSize = m_nRawImgHeight * m_nRawImgWidth * 2;
  1483. file_stream.write(reinterpret_cast<const char*>(m_pRawImgBuffer), nTempSize);
  1484. file_stream.close();
  1485. }
  1486. OnProcessImg();
  1487. return true;
  1488. }
  1489. bool XiuYuanCtrl::onSystemInfoCallbackProcess(SystemInfoCode iCodeIndex, const char* sContent)
  1490. {
  1491. switch (iCodeIndex)
  1492. {
  1493. case SIC_WAIT_EXP:
  1494. FINFO("Send Standby---Ready");
  1495. if (m_bStandbyFlag)
  1496. {
  1497. StatusFeedback(EVT_STATUS_PANEL, PANEL_STANDBY);
  1498. m_bStandbyFlag = false;
  1499. }
  1500. break;
  1501. case SIC_IN_EXP:
  1502. StatusFeedback(EVT_STATUS_PANEL, PANEL_XRAY_ON);
  1503. break;
  1504. case SIC_TEMPERTURE:
  1505. {
  1506. FINFO("{$}", sContent);
  1507. float value;
  1508. if (sscanf(sContent, "temperature:%f", &value))
  1509. {
  1510. FINFO("Get Temperature Success");
  1511. }
  1512. StatusFeedback(EVT_STATUS_TEMPERATURE, 0, "", 0, value);
  1513. }
  1514. break;
  1515. case SIC_BATTERY:
  1516. {
  1517. FINFO("{$}", sContent);
  1518. float value;
  1519. if (sscanf(sContent, "battery:%f", &value))
  1520. {
  1521. FINFO("Get Battery Success");
  1522. }
  1523. StatusFeedback(EVT_STATUS_BATTERY_VALUE, value, "", 0);
  1524. StatusFeedback(EVT_STATUS_WIFI, 100, "", 0);
  1525. }
  1526. break;
  1527. case SIC_ROIC_BUSY:
  1528. if (!m_bFreeBuffer)
  1529. {
  1530. API_YI_FPD_FreeBuffer(m_vecDetectorID[m_nDetectorIndex].c_str());
  1531. }
  1532. break;
  1533. case SIC_ROIC_DONE:
  1534. if (!m_bFreeBuffer)
  1535. {
  1536. API_YI_FPD_FreeBuffer(m_vecDetectorID[m_nDetectorIndex].c_str());
  1537. }
  1538. break;
  1539. default:
  1540. break;
  1541. }
  1542. m_bFreeBuffer = true;
  1543. return true;
  1544. }
  1545. void XiuYuanCtrl::SetNotifyStatusTimePeriod(int nTime)
  1546. {
  1547. FINFO("--XiuYuanCtrl Func-- SetNotifyStatusTimePeriod");
  1548. FINFO("SetNotifyStatusTimePeriod Time:{$}", nTime);
  1549. m_nNotifyStatusTimePeriod = nTime;
  1550. FINFO("SetNotifyStatusTimePeriod Over");
  1551. }
  1552. void XiuYuanCtrl::SetReconnectTimePeriod(int nTime)
  1553. {
  1554. FINFO("--XiuYuanCtrl Func-- SetReconnectTimePeriod");
  1555. FINFO("SetReconnectTimePeriod nTime:{$}", nTime);
  1556. m_nReconnectTimePeriod = nTime;
  1557. FINFO("SetReconnectTimePeriod Over");
  1558. }
  1559. void XiuYuanCtrl::ConfFeedback(int nEventID, int nDetectorID, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1560. {
  1561. if (-1 == nDetectorID)
  1562. {
  1563. nDetectorID = m_nDetectorIndex;
  1564. }
  1565. ((*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
  1566. nEventID, EVT_LEVEL_CONFIGURATION, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1567. }
  1568. void XiuYuanCtrl::InfoFeedback(int nEventID, int nDetectorID, int nParam1, float fParam2, const char* pszMsg, int nPtrParamLen, void* pParam)
  1569. {
  1570. if (-1 == nDetectorID)
  1571. {
  1572. nDetectorID = m_nDetectorIndex;
  1573. }
  1574. ((*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
  1575. nEventID, EVT_LEVEL_INFORMATOION, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1576. }
  1577. void XiuYuanCtrl::StatusFeedback(int nEventID, int nParam1, const char* pszMsg, int nDetectorID, float fParam2, int nPtrParamLen, void* pParam)
  1578. {
  1579. if (-1 == nDetectorID)
  1580. {
  1581. nDetectorID = m_nDetectorIndex;
  1582. }
  1583. ((*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
  1584. nEventID, EVT_LEVEL_STATUS, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1585. }
  1586. void XiuYuanCtrl::DataFeedback(int nEventID, void* pParam, int nParam1, float fParam2, const char* pszMsg, int nPtrParamLen, int nDetectorID)
  1587. {
  1588. if (-1 == nDetectorID)
  1589. {
  1590. nDetectorID = m_nDetectorIndex;
  1591. }
  1592. ((*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
  1593. nEventID, EVT_LEVEL_DATA, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1594. }
  1595. void XiuYuanCtrl::WarnFeedback(int nEventID, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam, int nDetectorID)
  1596. {
  1597. if (-1 == nDetectorID)
  1598. {
  1599. nDetectorID = m_nDetectorIndex;
  1600. }
  1601. ((*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
  1602. nEventID, EVT_LEVEL_WARNING, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1603. }
  1604. void XiuYuanCtrl::ErrorFeedback(int nEventID, const char* pszMsg, int nDetectorID, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
  1605. {
  1606. if (-1 == nDetectorID)
  1607. {
  1608. nDetectorID = m_nDetectorIndex;
  1609. }
  1610. ((*m_pPanelID2DPC)[nDetectorID])->OnFPDCallback(nDetectorID,
  1611. nEventID, EVT_LEVEL_ERROR, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
  1612. }