V2COMBoxDevice.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. #include "stdafx.h"
  2. #include "CommonFun.h"
  3. #include "V2COMBoxDevice.hpp"
  4. #include "DIOS.Dev.SyncBox.V2COM.h"
  5. #include "Helper.JSON.hpp"
  6. using namespace DIOS::Dev::Detail::SYNBOX;
  7. namespace nsSYN = DIOS::Dev::Detail::SYNBOX;
  8. static string tempErrorList = "";
  9. const char cCmd_heartbeat[5] = {'E','C',0x0d ,0x0a ,0x00};// "EC 回车 换行";
  10. //static string tempErrorlist;
  11. //-----------------------------------------------------------------------------
  12. // V2COMBoxDevice
  13. //-----------------------------------------------------------------------------
  14. nsSYN::V2COMBoxDevice::V2COMBoxDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF, string configfile)
  15. {
  16. m_SCF = SCF;
  17. EventCenter = center;
  18. ResDataObject temp;
  19. temp.loadFile(configfile.c_str());
  20. m_SYNConfig = temp["CONFIGURATION"];
  21. m_SynBoxUnit.m_WS.reset(new WORKSTATIONMould(""));
  22. m_SynBoxUnit.m_CurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 10000, 1));
  23. m_SynBoxUnit.m_HandSwitchState.reset(new HANDSWITCHMould(0, 0, 10000, 1));
  24. m_SynBoxUnit.m_GenSynState.reset(new GENSYNSTATEMould(0, 0, 10000, 1));
  25. m_SynBoxUnit.m_GenExpectSynState.reset(new GENEXPECTSYNSTATEMould(0, 0, 10000, 1));
  26. m_SynBoxUnit.m_TotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 10000, 1));
  27. m_SynBoxUnit.m_DetectorState.reset(new DETECTORSTATUSMould(0, 0, 10000, 1));
  28. m_SynBoxUnit.m_DetectorWindowState.reset(new XWINDOWSTATUSMould(AttrKey::XWINDOW_OFF, AttrKey::XWINDOW_OFF, AttrKey::XWINDOW_ON, 1));
  29. m_SynBoxUnit.m_ExpMode.reset(new EXPMODEMould(""));
  30. //同步盒错误、告警信息
  31. m_MSGUnit.reset(new nsDetail::MSGUnit(center, SyncConsoleUnitType));
  32. m_DYNMap.m_MapChannelState["TB"] = 0;
  33. m_DYNMap.m_MapChannelState["WB"] = 0;
  34. m_DYNMap.m_MapChannelState["GT"] = 0;
  35. m_DYNMap.m_MapChannelState["GW"] = 0;
  36. m_DYNMap.m_MapChannelState["PT"] = 0;
  37. m_DYNMap.m_MapChannelState["PW"] = 0;
  38. m_DYNMap.m_MapChannelState["ER"] = 0;
  39. m_DYNMap.m_MapChannelState["RT"] = 0;
  40. m_DYNMap.m_MapChannelState["RW"] = 0;
  41. m_DYNMap.m_MapChannelState["OT"] = 0;
  42. m_DYNMap.m_MapChannelState["OW"] = 0;
  43. m_DYNMap.m_MapChannelState["PR"] = 0;
  44. m_DYNMap.m_MapChannelState["FT"] = 0;
  45. m_DYNMap.m_MapChannelState["FW"] = 0;
  46. m_DYNMap.m_MapChannelState["TT"] = 0;
  47. m_DYNMap.m_MapChannelState["TW"] = 0;
  48. m_pHardwareThread = nullptr;
  49. m_iHeartBeats = 0;
  50. m_bConnectFlag = true;
  51. m_bSetBaudOK = false;
  52. #if 1 //暂不启用断线检测
  53. StartHardwareThread();
  54. #endif
  55. }
  56. nsSYN::V2COMBoxDevice::~V2COMBoxDevice()
  57. {
  58. if (m_pHardwareThread != NULL)
  59. {
  60. TerminateThread(m_pHardwareThread, 0);
  61. m_pHardwareThread = NULL;
  62. }
  63. }
  64. void nsSYN::V2COMBoxDevice::ReConnect(string &errorList)
  65. {
  66. mLog::Info("Enter V2COMBox_reConnect");
  67. m_SCF.Disconnect();
  68. ResDataObject Connection = m_SYNConfig["connections"][0];
  69. mLog::Info("Reconnections:{$} \n", Connection.encode());
  70. auto erCode = m_SCF.Connect(Connection.encode(), &nsSYN::DynBoxDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  71. if (erCode == SCF_ERR::SCF_SUCCEED)
  72. {
  73. FireErrorMessage(false, 1, "lost Connect");
  74. m_bConnectFlag = true;
  75. mLog::Info("reconnect success");
  76. mLog::Info("old errorlist:{$}", errorList.c_str());
  77. errorList = "";
  78. }
  79. else
  80. {
  81. mLog::Info("reconnect failed");
  82. }
  83. }
  84. bool nsSYN::V2COMBoxDevice::StartHardwareThread()
  85. {
  86. mLog::Info("enter Start HardwareStatus Thread ");
  87. if (m_pHardwareThread == NULL)
  88. {
  89. DWORD m_HardwareStatusID;
  90. m_pHardwareThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
  91. if (m_pHardwareThread == NULL)
  92. {
  93. mLog::Error("Start HardwareStatus Thread Failed");
  94. return false;
  95. }
  96. }
  97. return true;
  98. }
  99. #if 1
  100. DWORD nsSYN::V2COMBoxDevice::HardwareStatusThread(LPVOID pParam)
  101. {
  102. V2COMBoxDevice* pCurSyn = (V2COMBoxDevice*)pParam;
  103. if (pCurSyn == NULL)
  104. {
  105. return false;
  106. }
  107. mLog::Info("HardwareStatusThread start");
  108. bool HeartBeatFlag = false;
  109. if(pCurSyn->m_SYNConfig.GetKeyCount("HeartBeatEnable")>0)
  110. HeartBeatFlag = (int)pCurSyn->m_SYNConfig["HeartBeatEnable"];
  111. //pCurSyn->FireErrorMessage(false, 1, "lost Connect");
  112. //pCurSyn->StopWindowRequest();
  113. //pCurSyn->SetGenAECSignal(3);
  114. int iloopingFlag = 0;
  115. while (true)
  116. {
  117. if (HeartBeatFlag) //心跳检测
  118. {
  119. //判断是否断连
  120. if (!(pCurSyn->m_bConnectFlag))
  121. {
  122. mLog::Info("V2COM: not Connect,try to reconnect \n");
  123. pCurSyn->ReConnect(tempErrorList);
  124. Sleep(20000);
  125. continue;
  126. }
  127. Sleep(2000);
  128. pCurSyn->SendHeartBeat();
  129. pCurSyn->m_iHeartBeats++;
  130. int tempHeartBeat = pCurSyn->m_iHeartBeats;
  131. if (tempHeartBeat > 10) //无返回信息认为连接断开
  132. {
  133. pCurSyn->m_iHeartBeats = 0;
  134. pCurSyn->m_bConnectFlag = false;
  135. pCurSyn->FireErrorMessage(true, 1, "lost Connect");
  136. tempErrorList = pCurSyn->m_MSGUnit->JSGet();
  137. }
  138. }
  139. //定时查询CAN信息
  140. Sleep(5000);
  141. pCurSyn->QueryInfo();
  142. }
  143. mLog::Info("HardwareStatusThread stop");
  144. return true;
  145. }
  146. #endif // 0
  147. void nsSYN::V2COMBoxDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
  148. {
  149. string ErrorCode("SYNBOX_ERR_");
  150. ErrorCode += std::to_string(Code);
  151. int level = 0;
  152. if (Act)
  153. {
  154. mLog::Error("add {$}:{$}", ErrorCode.c_str(), ResInfo);
  155. m_MSGUnit->AddErrorMessage(ErrorCode.c_str(), level, ResInfo);
  156. }
  157. else
  158. {
  159. mLog::Error("del {$}:{$}", ErrorCode.c_str(), ResInfo);
  160. m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo);
  161. }
  162. }
  163. void nsSYN::V2COMBoxDevice::Register(Dispatch* Dispatch)
  164. {
  165. superGen::Register(Dispatch);
  166. Dispatch->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  167. }
  168. nDev::RET_STATUS nsSYN::V2COMBoxDevice::SetWS(std::string value)
  169. {
  170. if (ResDYNConfig.GetFirstOf(value.c_str()) >= 0)
  171. {
  172. m_SynBoxUnit.m_WS->Update(value);
  173. m_strSYNMode = (string)ResDYNConfig[value.c_str()];
  174. }
  175. else
  176. {
  177. m_strSYNMode = "SYN0";
  178. }
  179. return RET_STATUS::RET_SUCCEED;
  180. }
  181. nDev::RET_STATUS nsSYN::V2COMBoxDevice::SetExpMode(std::string value)
  182. {
  183. m_SynBoxUnit.m_ExpMode->Update(value);
  184. mLog::Info("SetExpMode {$}", value.c_str());
  185. return RET_STATUS::RET_SUCCEED;
  186. }
  187. nDev::RET_STATUS nsSYN::V2COMBoxDevice::SetGeneratortoSyncStatus(int state)
  188. {
  189. string strStateName = "";
  190. int nstate = -1;
  191. mLog::Info(" SetGeneratortoSyncStatus :{$}", state);
  192. if (state == AttrKey::GENERATOR_FLU_OFF || state == AttrKey::GENERATOR_RAD_OFF)//如果是采集结束的消息,直接恢复同步盒状态
  193. {
  194. ClearSignal();
  195. }
  196. if (m_SynBoxUnit.m_GenSynState->Get() != state || state == AttrKey::GENERATOR_RAD_XRAYON || state == AttrKey::GENERATOR_RAD_XRAYOFF)
  197. {
  198. mLog::Info("switch :{$}", state);
  199. switch (state)
  200. {
  201. case AttrKey::GENERATOR_RAD_PREPARE:
  202. m_nCurrentExpTimes = 0;
  203. strStateName = "HANDSWITCHPREPREQUEST";
  204. nstate = 1;
  205. m_nInExpState = true;
  206. m_wStartEXPTime = GetTickCount();
  207. break;
  208. case AttrKey::GENERATOR_RAD_READY:
  209. m_nCurrentExpTimes = 0;
  210. strStateName = "HANDSWITCHREADYREQUEST";
  211. nstate = 1;
  212. break;
  213. case AttrKey::GENERATOR_RAD_OFF:
  214. m_nCurrentExpTimes = 0;
  215. m_nExpTimes = -1;
  216. m_nInExpState = false;
  217. /*strStateName = "HANDSWITCHREADYREQUEST";
  218. nstate = 0;
  219. ((DYNSyncBox*)GetDrvDPC())->SetSignal(strStateName.c_str(), state);
  220. Sleep(30);
  221. strStateName = "GENEXPREQUEST";
  222. nstate = 0;
  223. ((DYNSyncBox*)GetDrvDPC())->SetSignal(strStateName.c_str(), state);
  224. Sleep(30);
  225. strStateName = "HANDSWITCHPREPREQUEST";
  226. nstate = 0;*/
  227. break;
  228. case AttrKey::GENERATOR_FLU_READY:
  229. m_nCurrentExpTimes = 0;
  230. strStateName = "HANDSWITCHPREPREQUEST";
  231. nstate = 1;
  232. SetSignal(strStateName.c_str(), nstate);
  233. Sleep(30);
  234. strStateName = "HANDSWITCHREADYREQUEST";
  235. nstate = 1;
  236. break;
  237. case AttrKey::GENERATOR_FLU_OFF:
  238. m_nCurrentExpTimes = 0;
  239. m_nExpTimes = -1;
  240. /*strStateName = "HANDSWITCHREADYREQUEST";
  241. nstate = 0;
  242. ((DYNSyncBox*)GetDrvDPC())->SetSignal(strStateName.c_str(), nstate);
  243. Sleep(30);
  244. strStateName = "HANDSWITCHPREPREQUEST";*/
  245. break;
  246. case AttrKey::GENERATOR_RAD_XRAYON:
  247. m_bINEEnable = true;
  248. strStateName = "GENEXPREQUEST";
  249. nstate = 1;
  250. break;
  251. case AttrKey::GENERATOR_RAD_XRAYOFF:
  252. if (m_SynBoxUnit.m_ExpMode->JSGet() != "ContinueSerial")
  253. {
  254. strStateName = "GENEXPREQUEST";
  255. nstate = 0;
  256. }
  257. break;
  258. default:
  259. strStateName = "";
  260. nstate = -1;
  261. break;
  262. }
  263. if (state == AttrKey::GENERATOR_FLU_OFF || state == AttrKey::GENERATOR_RAD_OFF)//如果是采集结束的消息,直接恢复同步盒状态
  264. {
  265. if (!m_bClear)
  266. {
  267. ClearSignal();
  268. m_bClear = true;
  269. }
  270. m_SynBoxUnit.m_GenExpectSynState->Update(state);
  271. }
  272. else if (strStateName != "" && nstate >= 0)
  273. {
  274. m_bClear = false;
  275. SetSignal(strStateName.c_str(), nstate);
  276. m_SynBoxUnit.m_GenExpectSynState->Update(state);
  277. }
  278. }
  279. else
  280. {
  281. mLog::Error("switch :{$}, PreSetGeneratortoSyncStatus=false", state);
  282. }
  283. return RET_STATUS::RET_SUCCEED;
  284. }
  285. nDev::RET_STATUS nsSYN::V2COMBoxDevice::HWSend(char* strCommand, int nTimeOut)
  286. {
  287. if (!m_SCF) return RET_STATUS::RET_FAILED;
  288. mLog::Info("==OUT==: {$} ,len={$}\n", strCommand, strlen((char*)strCommand));
  289. int retLength;
  290. m_SCF.Lock(msTimeOut_Lock)
  291. .SendPacket((char*)strCommand, strlen((char*)strCommand), nTimeOut, retLength);
  292. Sleep(nTimeOut);
  293. return RET_STATUS::RET_SUCCEED;
  294. }
  295. nDev::RET_STATUS nsSYN::V2COMBoxDevice::SetFilter(int filter)
  296. {
  297. BYTE data[16];
  298. data[0] = 0x43; //C
  299. data[1] = 0x53; //S
  300. data[2] = 0x94; //ID:0x4A1
  301. data[3] = 0x28;
  302. data[4] = 0x01;
  303. data[5] = 0x07;
  304. data[6] = filter;
  305. data[7] = 0x00;
  306. data[8] = 0x00;
  307. data[9] = 0x00;
  308. data[10] = 0x00;
  309. data[11] = 0x00;
  310. data[12] = 0x0D;
  311. data[13] = 0x0A;
  312. data[14] = 0x0;
  313. //不确定是否需要转0--->0x30
  314. for (int i = 0; i <= 13; i++)
  315. {
  316. if (data[i] == 0)
  317. data[i] = 0x30;
  318. }
  319. HWSend((char*)data);
  320. }
  321. void nsSYN::V2COMBoxDevice::QueryInfo()
  322. {
  323. char data[20] = { 0 };
  324. int nCmdSize;
  325. data[0] = 0x43; //C
  326. data[1] = 0x53; //S
  327. data[2] = 0x94; //ID:0x4A1
  328. data[3] = 0x28;
  329. data[4] = 0x01;
  330. data[5] = 0x08;
  331. data[6] = 0x3F;
  332. data[7] = 0x3F;
  333. data[8] = 0x00;
  334. data[9] = 0x00;
  335. data[10] = 0x00;
  336. data[11] = 0x00;
  337. data[12] = 0x0D;
  338. data[13] = 0x0A;
  339. for (int i = 0; i <= 11; i++)
  340. {
  341. if (data[i] == 0)
  342. data[i] = 0x30;
  343. }
  344. data[14] = 0x0;
  345. HWSend((char*)data);
  346. }
  347. nDev::RET_STATUS nsSYN::V2COMBoxDevice::SetGrid(unsigned int GridType)
  348. {
  349. BYTE data[16];
  350. data[0] = 0x43; //C
  351. data[1] = 0x53; //S
  352. data[2] = 0x94; //ID:0x4A1
  353. data[3] = 0x28;
  354. data[4] = 0x01;
  355. data[5] = 0x04;
  356. data[6] = GridType;
  357. data[7] = 0x01; //振栅状态:1.图像IN;2.图像OUT;3.运动中.不知道如何处理
  358. data[8] = 0x00;
  359. data[9] = 0x00;
  360. data[10] = 0x00;
  361. data[11] = 0x00;
  362. data[12] = 0x0D;
  363. data[13] = 0x0A;
  364. //不确定是否需要转0--->0x30
  365. for (int i = 0; i <= 13; i++)
  366. {
  367. if (data[i] == 0)
  368. data[i] = 0x30;
  369. }
  370. data[14] = 0x0;
  371. HWSend((char*)data);
  372. }
  373. nDev::RET_STATUS nsSYN::V2COMBoxDevice::SetExpEnable()
  374. {
  375. return RET_STATUS::RET_SUCCEED;
  376. }
  377. nDev::RET_STATUS nsSYN::V2COMBoxDevice::SetExpDisable()
  378. {
  379. return RET_STATUS::RET_SUCCEED;
  380. }
  381. nDev::RET_STATUS nsSYN::V2COMBoxDevice::PrepareAcquisition()
  382. {
  383. return RET_STATUS::RET_SUCCEED;
  384. }
  385. nDev::RET_STATUS nsSYN::V2COMBoxDevice::StartWindowRequest()
  386. {
  387. if (m_nGenSynStateSignal == AttrKey::GENERATOR_RAD_READY) //add by wxx:解决OT1信号在 配置 及 工作流中重复发送的问题
  388. {
  389. mLog::Info("send OT1 by workflows");
  390. m_bINEEnable = true;
  391. string strStateName = "DETREACQREQUEST";
  392. int state = 1;
  393. Sleep(1000);
  394. SetSignal(strStateName.c_str(), state);
  395. }
  396. else
  397. {
  398. mLog::Info("there is already send OT1 in this Exposure or not start Exposure yet");
  399. }
  400. return RET_STATUS::RET_SUCCEED;
  401. }
  402. nDev::RET_STATUS nsSYN::V2COMBoxDevice::StopWindowRequest()
  403. {
  404. mLog::Info("send OT0 by workflows");
  405. m_bINEEnable = false;
  406. string strStateName = "DETREACQREQUEST";
  407. int state = 0;
  408. SetSignal(strStateName.c_str(), state);
  409. return RET_STATUS::RET_SUCCEED;
  410. }
  411. nDev::RET_STATUS nsSYN::V2COMBoxDevice::SetExposureTimes(int nNum)
  412. {
  413. m_nExpTimes = nNum;
  414. return RET_STATUS::RET_SUCCEED;
  415. }
  416. nDev::RET_STATUS nsSYN::V2COMBoxDevice::SetFrameRate(FLOAT frameRate)
  417. {
  418. SetPWM(frameRate);
  419. return RET_STATUS::RET_SUCCEED;
  420. }
  421. nDev::RET_STATUS nsSYN::V2COMBoxDevice::SetGenAECSignal(int signal)
  422. {
  423. mLog::Info("GENAECCONTROL:{$},AECMode:{$}", signal, m_bGenAECModeFlag);
  424. if (signal == 0)
  425. {
  426. m_bGenAECModeFlag = true;
  427. SetSignal("GENAECCONTROL", 0); //Preview模式控制AEC信号高
  428. }
  429. else if(signal == 1)
  430. {
  431. if (m_bGenAECModeFlag)
  432. {
  433. m_bINEEnable = true;
  434. SetSignal("GENAECCONTROL", 1); //Preview模式控制AEC信号低
  435. mLog::Info("send RT0 by Preview.workflows");
  436. if (m_nGenSynStateSignal != AttrKey::GENERATOR_RAD_OFF)
  437. {
  438. m_nGenSynStateSignal = AttrKey::GENERATOR_RAD_READY;
  439. }
  440. mLog::Info("send RT0 by RAD.workflows GenSynState = {$}", m_nGenSynStateSignal);
  441. SetSignal("GENEXPREQUEST", 0);
  442. m_bINEEnable = false;
  443. }
  444. }
  445. else if (signal == 2)
  446. {
  447. if (m_bGenAECModeFlag)
  448. SetSignal("GENAECCONTROL", 0); //控制AEC信号高
  449. }
  450. else if (signal == 3)
  451. {
  452. if (m_bGenAECModeFlag)
  453. {
  454. m_bGenAECModeFlag = false;
  455. SetSignal("GENAECCONTROL", 1); //控制AEC信号低
  456. }
  457. m_bINEEnable = true;
  458. mLog::Info("send RT0 by RAD.workflows");
  459. SetSignal("GENEXPREQUEST", 0);
  460. m_bINEEnable = false;
  461. }
  462. return RET_STATUS::RET_SUCCEED;
  463. }
  464. //-----------------------------------------------------------------------------
  465. // ProcessCmd
  466. //-----------------------------------------------------------------------------
  467. void nsSYN::V2COMBoxDevice::FireNotify(std::string key, std::string content)
  468. {
  469. EventCenter->OnNotify(1, key, content);
  470. }
  471. nDev::RET_STATUS nsSYN::V2COMBoxDevice::SetCollimatorDev(OemCollimator* dev)
  472. {
  473. if (dev)
  474. m_pCollDev.reset(dev);
  475. return RET_STATUS::RET_SUCCEED;
  476. }
  477. nDev::RET_STATUS nsSYN::V2COMBoxDevice::SetMechDev(OemMechanical* dev)
  478. {
  479. if (dev)
  480. m_pMechDev.reset(dev);
  481. return RET_STATUS::RET_SUCCEED;
  482. }
  483. //static bool DecodeFrame(const char* strFrame, int length);
  484. // 收到硬件的通知, 有包到达
  485. // 按照设计, 仅当数据有变化时, 才发通知到上层, 因此里面有大量的 if (..) FireNotify (..)
  486. void nsSYN::V2COMBoxDevice::OnCallBack()
  487. {
  488. auto HWNotProcess = [](const char* value, int length) -> void
  489. {
  490. mLog::Info(" This commands didn't need to process!");
  491. };
  492. auto HWSignal = [this](const char* value, int length) -> void
  493. {
  494. assert(value && length>=3);
  495. char cChannelValue;
  496. cChannelValue = value[2]; //status : on /off
  497. string strChannel = ((string)value).substr(0, 2);
  498. bool bStatus = ChartoInt(cChannelValue);
  499. DealtheSignal(strChannel.c_str(), bStatus);
  500. };
  501. auto HWCAN = [this](const char* value, int length)
  502. {
  503. char data_can[MAX_COMMAND_LEN] = { 0 };
  504. for (int i = 0; i < length; i++)
  505. {
  506. if (value[i] == 0x30)
  507. data_can[i] = 0x0;
  508. else if (value[i] == 0x61)
  509. data_can[i] = 0x0a;
  510. else if (value[i] == 0x64)
  511. data_can[i] = 0x0d;
  512. else
  513. data_can[i] = value[i];
  514. }
  515. string strcmd = data_can;
  516. string sCmdID = strcmd.substr(2, 2);
  517. DealReceiveData(data_can, length);
  518. };
  519. arFrame.clear();
  520. arFrame.push_back(tFrameMapping("EC", 2, HWNotProcess));
  521. arFrame.push_back(tFrameMapping("CO", 2, HWNotProcess));
  522. arFrame.push_back(tFrameMapping("GR", 2, HWCAN));
  523. arFrame.push_back(tFrameMapping("CR", 2, HWCAN));
  524. arFrame.push_back(tFrameMapping("TB", 2, HWSignal));
  525. arFrame.push_back(tFrameMapping("WB", 2, HWSignal));
  526. arFrame.push_back(tFrameMapping("GT", 2, HWSignal));
  527. arFrame.push_back(tFrameMapping("GW", 2, HWSignal));
  528. arFrame.push_back(tFrameMapping("PT", 2, HWSignal));
  529. arFrame.push_back(tFrameMapping("PW", 2, HWSignal));
  530. arFrame.push_back(tFrameMapping("ER", 2, HWSignal));
  531. arFrame.push_back(tFrameMapping("RT", 2, HWSignal));
  532. arFrame.push_back(tFrameMapping("RW", 2, HWSignal));
  533. arFrame.push_back(tFrameMapping("OT", 2, HWSignal));
  534. arFrame.push_back(tFrameMapping("OW", 2, HWSignal));
  535. arFrame.push_back(tFrameMapping("PR", 2, HWSignal));
  536. arFrame.push_back(tFrameMapping("FT", 2, HWSignal));
  537. arFrame.push_back(tFrameMapping("FW", 2, HWSignal));
  538. arFrame.push_back(tFrameMapping("TT", 2, HWSignal));
  539. arFrame.push_back(tFrameMapping("TW", 2, HWSignal));
  540. }
  541. void nsSYN::V2COMBoxDevice::DealReceiveData(char* data_can, int length_can_data)
  542. {
  543. char logbuf[200] = { 0 };
  544. if(length_can_data>=14)
  545. {
  546. sprintf(logbuf, "%2X,%2X,%2X,%2X,%2X,%2X,%2X,%2X,%2X,%2X,%2X,%2X,%2X,%2X,length_can_data=%d",
  547. (BYTE)data_can[0], (BYTE)data_can[1], (BYTE)data_can[2], (BYTE)data_can[3], (BYTE)data_can[4], (BYTE)data_can[5],
  548. (BYTE)data_can[6], (BYTE)data_can[7], (BYTE)data_can[8], (BYTE)data_can[9], (BYTE)data_can[10], (BYTE)data_can[11],
  549. (BYTE)data_can[12], (BYTE)data_can[13], length_can_data);
  550. }
  551. if (length_can_data==5)//CO4
  552. {
  553. //set baud ok.
  554. if (data_can[2]==0)
  555. {
  556. m_bSetBaudOK = true;
  557. }
  558. else
  559. {
  560. m_bSetBaudOK = false;
  561. }
  562. }
  563. if (length_can_data==4)//EC
  564. {
  565. //echo ok
  566. }
  567. mLog::Info("recv {$}.",logbuf);
  568. int idHigh = (unsigned char)(data_can[2]);
  569. int idLow = (unsigned char)(data_can[3]);
  570. if (idHigh == 0x80 && idLow == 0xA8)//0x405
  571. {
  572. if (data_can[4] == 0 && data_can[5] == 1)
  573. {
  574. mLog::Info("recv 405 heart beat.");
  575. }
  576. if (data_can[4] == 1 && data_can[5] == 2)
  577. {
  578. //平板选择
  579. int nPanelType = (BYTE)data_can[6];
  580. //C arm ML0位,角度
  581. int nML0Angle = (BYTE)data_can[7];
  582. if (m_pMechDev)
  583. {
  584. m_pMechDev->UpdateMammo_MechAngle(100);
  585. }
  586. mLog::Info("recv 405 panelType and MLOangle ={$},{$}",nPanelType,nML0Angle);
  587. }
  588. if (data_can[4] == 1 && data_can[5] == 3)
  589. {
  590. //曝光模式:1-4(1-3为自动,4手动);6(48KV);8(校准)
  591. mLog::Info("recv 405 曝光模式");
  592. }
  593. if (data_can[4] == 1 && data_can[5] == 4)
  594. {
  595. //1:ANRAN平板未准备好
  596. //2:ANRAN平板准备好
  597. int nPanelStatus = (BYTE)data_can[7];
  598. mLog::Info("recv 405 ANRAN panel ready or not");
  599. }
  600. }
  601. if (idHigh == 0x84 && idLow == 0xA8)//0x425
  602. {
  603. if (data_can[4] == 1 && data_can[5] == 1)
  604. {
  605. //recv 425 heart
  606. mLog::Info("recv 425 heart beat.");
  607. }
  608. if (data_can[4] == 1 && data_can[5] == 3)
  609. {
  610. //recv 425 heart
  611. //压迫模式:普通压迫(01); 预压迫(10); 全压迫(11) 压迫器:自动释放(01); 手动释放(10)
  612. int nCompPressureMode = (BYTE)data_can[6];
  613. if (m_pMechDev)
  614. {
  615. m_pMechDev->UpdateMammo_PressureState(nCompPressureMode);
  616. }
  617. //自动释放设定
  618. int nCompPressureDEC = (BYTE)data_can[7];
  619. if (m_pMechDev)
  620. {
  621. m_pMechDev->UpdateMammo_CompPressureDEC(nCompPressureDEC);
  622. }
  623. if (m_pMechDev)
  624. {
  625. m_pMechDev->UpdateMammo_Depress(nCompPressureDEC);//vmi doc文档中,DF0 DF1 也表示自动释放
  626. }
  627. mLog::Info("recv 425 压迫模式{$},自动释放模式{$}",nCompPressureMode,nCompPressureDEC);
  628. }
  629. //filter
  630. if (data_can[4] == 1 && data_can[5] == 7)
  631. {
  632. //col滤过类型:1Mo,2Rh
  633. int nFilter = (BYTE)data_can[6];
  634. if (m_pCollDev)
  635. {
  636. m_pCollDev->UpdateCollimatorFilter(nFilter);
  637. }
  638. if (m_pMechDev)
  639. {
  640. m_pMechDev->UpdateMammo_FT(nFilter);
  641. }
  642. mLog::Info("recv 425 fileter {$}",nFilter);
  643. }
  644. //angle
  645. if ((data_can[4] == 0 && data_can[5] == 6) || (data_can[4] == 0x30 && data_can[5] == 6))
  646. {
  647. //C arm angle
  648. int angle = 0;
  649. int nSign = (BYTE)data_can[6];
  650. if (nSign == 2)
  651. {
  652. angle = (BYTE)data_can[7] * -1;
  653. }
  654. else
  655. {
  656. angle = (BYTE)data_can[7];
  657. }
  658. if (m_pCollDev)
  659. {
  660. m_pCollDev->UpdateCollimatorAngle(99);
  661. }
  662. mLog::Info("recv 425 CARM angle{$}",angle);
  663. }
  664. //grid mode
  665. if (data_can[4] == 1 && data_can[5] == 4)
  666. {
  667. int nGridMode = (BYTE)data_can[6];
  668. if (nGridMode == 1) //此处更像是mag
  669. {
  670. //正常模式
  671. }
  672. if (nGridMode == 0x10)
  673. {
  674. //放大模式
  675. }
  676. if (m_pMechDev)
  677. {
  678. m_pMechDev->UpdateMammo_MAG(nGridMode);
  679. }
  680. int nGridStatus = (BYTE)data_can[7];
  681. if (nGridStatus == 1)
  682. {
  683. //IN
  684. }
  685. if (nGridStatus == 2)
  686. {
  687. //OUT
  688. }
  689. if (nGridStatus == 3)
  690. {
  691. //RUNNING
  692. }
  693. if (m_pMechDev)
  694. {
  695. m_pMechDev->UpdateGrid(nGridStatus);
  696. }
  697. mLog::Info("recv 425 grid mode {$},gird status {$}",nGridMode,nGridStatus);
  698. }
  699. if (data_can[4] == 1 && data_can[5] == 5)
  700. {
  701. int nThickness = (BYTE)data_can[6];
  702. int nPressValue = (BYTE)data_can[7];
  703. //int nCompPressureMode = data_can[6];
  704. if (m_pMechDev)
  705. {
  706. m_pMechDev->UpdateMammo_PressureState(nThickness);//note :thickness
  707. }
  708. if (m_pMechDev)
  709. {
  710. m_pMechDev->UpdateMammo_PressureValue(nPressValue);
  711. }
  712. mLog::Info("recv 425 thickness {$}, pressvalue {$}", nThickness, nPressValue);
  713. }
  714. if (data_can[4] == 1 && data_can[5] == 6)
  715. {
  716. int colHeight = (BYTE)data_can[6] * 256 + (BYTE)data_can[7];
  717. int colWidth = (BYTE)data_can[8] * 256 + (BYTE)data_can[9];
  718. if (m_pCollDev)
  719. {
  720. m_pCollDev->UpdateCollimatorXSize(colWidth);
  721. m_pCollDev->UpdateCollimatorYSize(colHeight);
  722. }
  723. mLog::Info("recv 425 : coll: x={$},y={$}",colWidth,colHeight);
  724. }
  725. if (data_can[4] == 1 && data_can[5] == 0x19)
  726. {
  727. //压迫板类型:1.大压迫板。2.小压迫板。3.放大摄影压迫板
  728. int nPlateID = (BYTE)data_can[6];
  729. std::string strPlateID = "";
  730. if (m_pMechDev)
  731. {
  732. if (1 == nPlateID)
  733. {
  734. strPlateID = "1";
  735. }
  736. else if (2 == nPlateID)
  737. {
  738. strPlateID = "2";
  739. }
  740. else if (3 == nPlateID)
  741. {
  742. strPlateID = "3";
  743. }
  744. m_pMechDev->UpdateMammo_CompressPaddle(strPlateID);
  745. }
  746. mLog::Info("recv 425 : 压迫板类型 {$}--[1.大压迫板。2.小压迫板。3.放大摄影压迫板]",nPlateID);
  747. }
  748. }
  749. }
  750. //不用了
  751. int nsSYN::V2COMBoxDevice::DealReceiveData(string sCmdID, const char* pData, int Datalen)
  752. {
  753. if (strtol(("0x" + sCmdID).c_str(), NULL, 16) == 0x626)
  754. {
  755. string strCmd = pData;
  756. if (strtol(("0x" + strCmd.substr(0, 2)).c_str(), NULL, 16) == 0x14)
  757. {
  758. /*bool bUpdateSize = false, bUpdateFilter = false;
  759. if (strtol(("0x" + strCmd.substr(3, 1)).c_str(), NULL, 16) & 0x01)
  760. {
  761. m_nXSize = strtol(("0x" + strCmd.substr(4, 2)).c_str(), NULL, 16) + strtol(("0x" + strCmd.substr(6, 2)).c_str(), NULL, 16) * 256;
  762. bUpdateSize = true;
  763. m_nXSize = m_nXSize / 100;
  764. printf("m_nXSize = {$}", m_nXSize);
  765. }
  766. if (strtol(("0x" + strCmd.substr(3, 1)).c_str(), NULL, 16) & 0x02)
  767. {
  768. m_nYSize = strtol(("0x" + strCmd.substr(8, 2)).c_str(), NULL, 16) + strtol(("0x" + strCmd.substr(10, 2)).c_str(), NULL, 16) * 256;
  769. m_nYSize = m_nYSize / 100;
  770. bUpdateSize = true;
  771. printf("m_nYSize = {$}", m_nYSize);
  772. }
  773. if (strtol(("0x" + strCmd.substr(2, 1)).c_str(), NULL, 16) & 0x04)
  774. {
  775. m_nFilter = strtol(("0x" + strCmd.substr(12, 2)).c_str(), NULL, 16) + strtol(("0x" + strCmd.substr(14, 2)).c_str(), NULL, 16) * 256;
  776. bUpdateFilter = true;
  777. printf("m_nFilter = {$}", m_nFilter);
  778. }
  779. if (bUpdateSize)
  780. {
  781. CollimatorLogic::SetCollimatorSize(m_nXSize, m_nYSize);
  782. }
  783. if (bUpdateFilter)
  784. {
  785. CollimatorLogic::SetCollimatorFilter(m_nFilter);
  786. }*/
  787. }
  788. }
  789. return 1;
  790. }
  791. int nsSYN::V2COMBoxDevice::DealtheSignal(const char* channel, int state)
  792. {
  793. string strchannel = channel;
  794. m_DYNMap.m_MapChannelState[strchannel] = state;
  795. if (ResDYNConfig.GetFirstOf(m_strSYNMode.c_str()) < 0)
  796. {
  797. mLog::Error("Didn't find SynMode : {$}", m_strSYNMode.c_str());
  798. return -1;
  799. }
  800. if (ResDYNConfig[m_strSYNMode.c_str()].GetFirstOf(m_SynBoxUnit.m_ExpMode->JSGet().c_str()) < 0)
  801. {
  802. mLog::Error("Didn't find CurrentExamMode : {$}", m_SynBoxUnit.m_ExpMode->JSGet().c_str());
  803. return -1;
  804. }
  805. int count = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["INPUT"].size();
  806. string strSignalName = "";
  807. int nState = -1;
  808. mLog::Info("CurrentExamMode = {$}, strchannel = {$}", m_SynBoxUnit.m_ExpMode->JSGet().c_str(), strchannel.c_str());
  809. for (int i = 0; i < count; i++)
  810. {
  811. string strKey = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["INPUT"].GetKey(i);
  812. string confchannel = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["INPUT"][strKey.c_str()]["CHANNEL"];
  813. mLog::Info("strKey = {$}, confchannel = {$}", strKey.c_str(), confchannel.c_str());
  814. if (confchannel == strchannel)
  815. {
  816. strSignalName = strKey;
  817. nState = state;
  818. if (strSignalName == "GENPREP") //add by wxx:解决OT1信号在 配置 及 工作流中重复发送的问题
  819. {
  820. if (state == 1) //ER1
  821. {
  822. m_nGenSynStateSignal = AttrKey::GENERATOR_RAD_PREPARE;
  823. }
  824. else
  825. {
  826. m_nGenSynStateSignal = AttrKey::GENERATOR_RAD_OFF;
  827. SetGenAECSignal(3);
  828. }
  829. }
  830. else if (strSignalName == "GENREADY")
  831. {
  832. if (state == 1) //TB1
  833. {
  834. m_nGenSynStateSignal = AttrKey::GENERATOR_RAD_READY;
  835. }
  836. else
  837. {
  838. if (m_nGenSynStateSignal != AttrKey::GENERATOR_RAD_OFF)
  839. {
  840. m_nGenSynStateSignal = AttrKey::GENERATOR_RAD_PREPARE;
  841. }
  842. }
  843. }
  844. else if (strSignalName == "XWINDOWSTATUS")
  845. {
  846. if (state == 1)
  847. {
  848. if (m_nGenSynStateSignal == AttrKey::GENERATOR_RAD_READY) //发送OT1收到PT1
  849. m_bINEEnable = true;
  850. }
  851. else //PT0
  852. {
  853. if (m_nGenSynStateSignal != AttrKey::GENERATOR_RAD_OFF)
  854. {
  855. m_nGenSynStateSignal = AttrKey::GENERATOR_RAD_XRAYOFF;
  856. }
  857. }
  858. }
  859. mLog::Info("Signal Name = {$}, state = {$},GenSynState = {$}", strSignalName.c_str(), nState, m_nGenSynStateSignal);
  860. break;
  861. }
  862. }
  863. if (strSignalName != "" && nState >= 0)
  864. {
  865. NotifySignal(strSignalName.c_str(), nState);
  866. string strSetEnableSignal = (string)ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["INPUT"][strSignalName.c_str()]["SETENABLE"];
  867. string strSetDisableSignal = (string)ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["INPUT"][strSignalName.c_str()]["SETDISABLE"];
  868. if (nState == 1 && strSetEnableSignal != "")
  869. {
  870. if (strSetEnableSignal == "GENEXPREQUEST") //RT1
  871. {
  872. m_nGenSynStateSignal = AttrKey::GENERATOR_RAD_XRAYON;
  873. }
  874. string strRelaySignal = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["INPUT"][strSignalName.c_str()]["RELAY"];
  875. if (strRelaySignal != "")
  876. {
  877. //strRelaySignal = strRelaySignal + "," + strSetEnableSignal;
  878. mLog::Info("Set Enable Relay_Signal = {$},GenSynState = {$}", strSetEnableSignal.c_str(), m_nGenSynStateSignal);
  879. SetSignal(strRelaySignal.c_str(), nState);
  880. }
  881. else
  882. {
  883. mLog::Info("Set Enable Signal = {$},GenSynState = {$}", strSetEnableSignal.c_str(), m_nGenSynStateSignal);
  884. SetSignal(strSetEnableSignal.c_str(), nState);
  885. }
  886. }
  887. else if (state == 0 && strSetDisableSignal != "")
  888. {
  889. if (strSetEnableSignal == "GENEXPREQUEST") //RT0
  890. {
  891. if (m_nGenSynStateSignal != AttrKey::GENERATOR_RAD_OFF)
  892. {
  893. m_nGenSynStateSignal = AttrKey::GENERATOR_RAD_READY;
  894. }
  895. }
  896. string strRelaySignal = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["INPUT"][strSignalName.c_str()]["RELAY"];
  897. if (strRelaySignal != "")
  898. {
  899. //strRelaySignal = strRelaySignal + "," + strSetDisableSignal;
  900. mLog::Info("Set Disable Relay_Signal = {$},GenSynState = {$}", strSetDisableSignal.c_str(), m_nGenSynStateSignal);
  901. SetSignal(strRelaySignal.c_str(), state);
  902. }
  903. else
  904. {
  905. mLog::Info("Set Disable Signal = {$},GenSynState = {$}", strSetDisableSignal.c_str(), m_nGenSynStateSignal);
  906. SetSignal(strSetDisableSignal.c_str(), state);
  907. }
  908. if (strSignalName == "GENEXPREQUEST") //RT0,add by wxx:解决OT1信号在 配置 及 工作流中重复发送的问题
  909. {
  910. m_bINEEnable = false;
  911. }
  912. }
  913. }
  914. return 2;
  915. }
  916. int nsSYN::V2COMBoxDevice::NotifySignal(const char* name, int state)
  917. {
  918. string strname = name;
  919. mLog::Info("Send Notify : Name = {$}, State = {$}", name, state);
  920. if (strname == "HANDSWITCHPREP")
  921. {
  922. if (state)
  923. {
  924. m_SynBoxUnit.m_HandSwitchState->Update(1);
  925. FireNotify(m_SynBoxUnit.m_HandSwitchState->GetKey(), m_SynBoxUnit.m_HandSwitchState->JSGet());
  926. }
  927. else
  928. {
  929. m_SynBoxUnit.m_HandSwitchState->Update(0);
  930. FireNotify(m_SynBoxUnit.m_HandSwitchState->GetKey(), m_SynBoxUnit.m_HandSwitchState->JSGet());
  931. }
  932. }
  933. else if (strname == "HANDSWITCHREADY")
  934. {
  935. if (state)
  936. {
  937. m_SynBoxUnit.m_HandSwitchState->Update(2);
  938. FireNotify(m_SynBoxUnit.m_HandSwitchState->GetKey(), m_SynBoxUnit.m_HandSwitchState->JSGet());
  939. }
  940. else
  941. {
  942. m_SynBoxUnit.m_HandSwitchState->Update(0);
  943. FireNotify(m_SynBoxUnit.m_HandSwitchState->GetKey(), m_SynBoxUnit.m_HandSwitchState->JSGet());
  944. }
  945. }
  946. #if 0//change by wxx:for 迈科龙乳腺机项目 探测器状态应由发生器自行更新
  947. else if (strname == "XWINDOWSTATUS")
  948. {
  949. if (state)
  950. {
  951. m_SynBoxUnit.m_DetectorWindowState->Update(AttrKey::XWINDOW_ON);
  952. FireNotify(m_SynBoxUnit.m_DetectorWindowState->GetKey(), m_SynBoxUnit.m_DetectorWindowState->JSGet());
  953. }
  954. else
  955. {
  956. m_SynBoxUnit.m_DetectorWindowState->Update(AttrKey::XWINDOW_OFF);
  957. FireNotify(m_SynBoxUnit.m_DetectorWindowState->GetKey(), m_SynBoxUnit.m_DetectorWindowState->JSGet());
  958. }
  959. }
  960. #endif
  961. //change by wxx:for 迈科龙乳腺机项目 发生器状态应由发生器自行更新
  962. #if 0
  963. else if (strname == "GENPREP")
  964. {
  965. if (state)
  966. {
  967. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE);
  968. FireNotify(m_SynBoxUnit.m_GenSynState->GetKey(), m_SynBoxUnit.m_GenSynState->JSGet());
  969. }
  970. else
  971. {
  972. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
  973. FireNotify(m_SynBoxUnit.m_GenExpectSynState->GetKey(), m_SynBoxUnit.m_GenExpectSynState->JSGet());
  974. }
  975. }
  976. else if (strname == "GENREADY")
  977. {
  978. if (state)
  979. {
  980. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
  981. FireNotify(m_SynBoxUnit.m_GenSynState->GetKey(), m_SynBoxUnit.m_GenSynState->JSGet());
  982. }
  983. else
  984. {
  985. //m_pSynGen->ExpectToSyncStatus(GENERATOR_RAD_EXPECT_OFF);
  986. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
  987. FireNotify(m_SynBoxUnit.m_GenSynState->GetKey(), m_SynBoxUnit.m_GenSynState->JSGet());
  988. }
  989. }
  990. else if (strname == "GENEXPSTATUS")
  991. {
  992. if (state)
  993. {
  994. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
  995. FireNotify(m_SynBoxUnit.m_GenSynState->GetKey(), m_SynBoxUnit.m_GenSynState->JSGet());
  996. m_nCurrentExpTimes++;
  997. }
  998. else
  999. {
  1000. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF);
  1001. FireNotify(m_SynBoxUnit.m_GenSynState->GetKey(), m_SynBoxUnit.m_GenSynState->JSGet());
  1002. }
  1003. }
  1004. #endif
  1005. return 2;
  1006. }
  1007. int nsSYN::V2COMBoxDevice::SetSignal(const char* name, int state)
  1008. {
  1009. string strtemp = name;
  1010. string strName = strtemp;
  1011. std::size_t oldPos = 0;
  1012. std::size_t findPos = strtemp.find(",");
  1013. while (findPos != string::npos) //change by wxx:原截取字符串操作有问题
  1014. {
  1015. strName = strtemp.substr(oldPos, findPos - oldPos);
  1016. if (ResDYNConfig.GetFirstOf(m_strSYNMode.c_str()) < 0)
  1017. {
  1018. mLog::Error("Didn't find SynMode : {$}", m_strSYNMode.c_str());
  1019. return -1;
  1020. }
  1021. if (ResDYNConfig[m_strSYNMode.c_str()].GetFirstOf(m_SynBoxUnit.m_ExpMode->JSGet().c_str()) < 0)
  1022. {
  1023. mLog::Error("Set Signal {$}, state {$} ", name, state);
  1024. mLog::Error("Didn't find m_SynBoxUnit.m_ExpMode->JSGet() : {$}", m_SynBoxUnit.m_ExpMode->JSGet().c_str());
  1025. return -1;
  1026. }
  1027. string strChannel = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["OUTPUT"][strName.c_str()]["CHANNEL"];
  1028. if (strChannel != "")
  1029. {
  1030. if (strName == "GENEXPREQUEST")
  1031. {
  1032. if (m_bINEEnable)
  1033. {
  1034. //m_nCurrentExpTimes++;
  1035. if (m_nExpTimes > 0 && m_nCurrentExpTimes > m_nExpTimes)
  1036. {
  1037. mLog::Warn("m_nExpTimes has been enough in this sequence! m_nExpTimes={$},m_nCurrentExpTimes={$}", m_nExpTimes, m_nCurrentExpTimes);
  1038. return true;
  1039. }
  1040. }
  1041. else
  1042. {
  1043. mLog::Warn("Generator didn't ready or detector didn't startAcq, So can't send INE to generator!");
  1044. return true;
  1045. }
  1046. }
  1047. mLog::Info("Set Signal {$}, state {$} ", strName, state);
  1048. SendBySCF(strChannel.c_str(), state);
  1049. //Sleep(10);
  1050. }
  1051. if (findPos != strtemp.length())
  1052. {
  1053. oldPos = findPos + 1;
  1054. findPos = strtemp.find(",", oldPos);
  1055. if (findPos == string::npos)
  1056. {
  1057. strName = strtemp.substr(oldPos, strtemp.length() - oldPos);
  1058. break;
  1059. }
  1060. }
  1061. else
  1062. {
  1063. break;
  1064. }
  1065. }
  1066. //strName = strtemp;
  1067. if (ResDYNConfig.GetFirstOf(m_strSYNMode.c_str()) < 0)
  1068. {
  1069. mLog::Error("Didn't find SynMode : {$}", m_strSYNMode.c_str());
  1070. return -1;
  1071. }
  1072. if (ResDYNConfig[m_strSYNMode.c_str()].GetFirstOf(m_SynBoxUnit.m_ExpMode->JSGet().c_str()) < 0)
  1073. {
  1074. mLog::Error("Set Signal {$}, state {$} ", name, state);
  1075. mLog::Error("Didn't find CurrentExamMode : {$}", m_SynBoxUnit.m_ExpMode->JSGet().c_str());
  1076. return -1;
  1077. }
  1078. string strChannel = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["OUTPUT"][strName.c_str()]["CHANNEL"];
  1079. if (strChannel != "")
  1080. {
  1081. if (strName == "GENEXPREQUEST")
  1082. {
  1083. if (m_bINEEnable)
  1084. {
  1085. //m_nCurrentExpTimes++;
  1086. if (m_nExpTimes > 0 && m_nCurrentExpTimes > m_nExpTimes)
  1087. {
  1088. mLog::Warn("m_nExpTimes has been enough in this sequence! m_nExpTimes={$},m_nCurrentExpTimes={$}", m_nExpTimes, m_nCurrentExpTimes);
  1089. return true;
  1090. }
  1091. }
  1092. else
  1093. {
  1094. mLog::Warn("Generator didn't ready or detector didn't startAcq, So can't send INE to generator!");
  1095. return true;
  1096. }
  1097. }
  1098. mLog::Info("Set Signal {$}, state {$} ", name, state);
  1099. SendBySCF(strChannel.c_str(), state);
  1100. return 1;
  1101. }
  1102. return -1;
  1103. }
  1104. void nsSYN::V2COMBoxDevice::ClearSignal()
  1105. {
  1106. if (ResDYNConfig.GetFirstOf(m_strSYNMode.c_str()) < 0)
  1107. {
  1108. mLog::Error("Didn't find SynMode : {$}", m_strSYNMode.c_str());
  1109. return;
  1110. }
  1111. if (ResDYNConfig[m_strSYNMode.c_str()].GetFirstOf(m_SynBoxUnit.m_ExpMode->JSGet().c_str()) < 0)
  1112. {
  1113. mLog::Error("Didn't find CurrentExamMode : {$}", m_SynBoxUnit.m_ExpMode->JSGet().c_str());
  1114. return;
  1115. }
  1116. int nsize = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["OUTPUT"].size();
  1117. for (int i = 0; i < nsize; i++)
  1118. {
  1119. string strChannel = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["OUTPUT"][i]["CHANNEL"];
  1120. string name = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["OUTPUT"].GetKey(i);
  1121. mLog::Info("Clear Name :{$},CurrentExamMode ={$}", name.c_str(), m_SynBoxUnit.m_ExpMode->JSGet().c_str());
  1122. if (strChannel != "" && "FRAMERATE" != name)
  1123. {
  1124. mLog::Info("Clear Signal {$} ", strChannel);
  1125. SendBySCF(strChannel.c_str(), false);
  1126. Sleep(10);
  1127. }
  1128. }
  1129. return;
  1130. }
  1131. int nsSYN::V2COMBoxDevice::SetPWM(float fpps)
  1132. {
  1133. return -1;
  1134. }
  1135. nDev::RET_STATUS nsSYN::V2COMBoxDevice::SendBySCF(const char* chChannelID, bool bStatus)
  1136. {
  1137. int nTimeout = 100;
  1138. char cCmd[MAX_COMMAND_LEN] = { 0 };
  1139. cCmd[0] = chChannelID[0];
  1140. cCmd[1] = chChannelID[1];
  1141. if (bStatus)
  1142. cCmd[2] = '1';
  1143. else
  1144. cCmd[2] = '0';
  1145. int nSize = 3;
  1146. FormatCmd(cCmd, nSize);
  1147. string strLog;
  1148. CmdtoString(cCmd, nSize, strLog);
  1149. mLog::Info("[Send:{$}]", cCmd);
  1150. if (!m_SCF)
  1151. {
  1152. mLog::Error("SCF is NULL");
  1153. return RET_STATUS::RET_FAILED;
  1154. }
  1155. mLog::Info("==OUT==: {$} ", cCmd);
  1156. int ret = 0;
  1157. m_SCF.Lock(msTimeOut_Lock)
  1158. .SendPacket(cCmd, nSize, nTimeout, ret);
  1159. Sleep(nTimeout);
  1160. return RET_STATUS::RET_SUCCEED;
  1161. }
  1162. void nsSYN::V2COMBoxDevice::SendHeartBeat()
  1163. {
  1164. int nTimeout = 100;
  1165. int ret = 0;
  1166. mLog::Info("==OUT==: heartbeat{$} ", cCmd_heartbeat);
  1167. m_SCF.Lock(msTimeOut_Lock)
  1168. .SendPacket(cCmd_heartbeat, 4, nTimeout, ret);
  1169. Sleep(nTimeout);
  1170. }
  1171. void nsSYN::V2COMBoxDevice::DealtheHB(const char* channel, int state)
  1172. {
  1173. m_iHeartBeats = 0;
  1174. }