DIOS.Dev.Generator.CPI.cpp 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124
  1. // CCOS.Dev.GEN.CPI.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. #include "stdafx.h"
  4. #include <assert.h>
  5. #include <functional>
  6. using namespace std::placeholders;
  7. //#include "logger.temp.h"
  8. #include "CCOS.Dev.Generator.CPI.h"
  9. #include "Helper.JSON.hpp"
  10. using namespace CCOS::Dev::Detail::Generator;
  11. namespace nsGEN = CCOS::Dev::Detail::Generator;
  12. #pragma warning (disable:4244 4305 4267 4838 4309 4715 26495 26812)
  13. static const int msTimeOut_Lock = 500;
  14. #ifdef _WIN64
  15. #ifdef _DEBUG
  16. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64D.dll";
  17. #else
  18. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64.dll";
  19. #endif
  20. #endif
  21. #ifdef _WIN64
  22. #ifdef _DEBUG
  23. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64D.dll";
  24. #else
  25. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64.dll";
  26. #endif
  27. #endif
  28. //-----------------------------------------------------------------------------
  29. // CPIDevice
  30. //-----------------------------------------------------------------------------
  31. float g_MA_List[] = { 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640 };
  32. float g_MAS_List[] = { 1, 1.25, 1.6, 2, 2.5, 3.2, 4, 5, 6.4, 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000 };
  33. float g_MS_List[] = { 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6400, 8000, 10000 };
  34. int g_AECFIELD_List[] = { 1, 10, 100, 11, 101, 111 };
  35. std::vector <float> gf_MA_List = { 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640 };
  36. string GetProcessDirectory()
  37. {
  38. string ret = "";
  39. char szFilename[MAX_PATH] = { 0 };
  40. DWORD res = GetModuleFileNameA(0, szFilename, MAX_PATH);
  41. if (res == 0)
  42. {
  43. return ret;
  44. }
  45. string fullpath = szFilename;
  46. string::size_type firstHit = fullpath.find_last_of('\\');
  47. if (firstHit == string::npos || firstHit == 0)
  48. {
  49. return ret;
  50. }
  51. ret = fullpath.substr(0, firstHit);//kick last \
  52. return ret;
  53. }
  54. nsGEN::CPIDevice::CPIDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF, string configfile) : super(center, SCF)
  55. {
  56. assert(EventCenter);
  57. mLog::Info("version:3.0.0.5");
  58. m_DoseUnit.m_KV.reset(new KVMould(0.0, 40.0, 120.0, 1.0));
  59. m_DoseUnit.m_MA.reset(new MAMould(0.0, 1.0, 1000.0, 0.1));
  60. m_DoseUnit.m_MS.reset(new MSMould(0.0, 1.0, 10000.0, 0.01));
  61. m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.5, 1000.0, 0.01));
  62. m_DoseUnit.m_Techmode.reset(new TECHMODEMould(0, 0, 2, 1));
  63. m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
  64. m_DoseUnit.m_Focus.reset(new FOCUSMould(1, 0, 1, 1));
  65. m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
  66. m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
  67. m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
  68. m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
  69. m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 40.0, 120.0, 1.0));
  70. m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 1.0, 1000.0, 0.1));
  71. m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 1.0, 10000.0, 0.01));
  72. m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.5, 1000.0, 0.01));
  73. m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(0, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
  74. m_DoseUnit.m_GenState.reset(new GENSTATEMould(0, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
  75. m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
  76. m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
  77. m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
  78. m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
  79. m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
  80. m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single));
  81. m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 16, 1));
  82. m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
  83. m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
  84. m_DAP.reset(new DevDAP::DOSEMould(0.0, 0.0, 1000.0, 0.01));
  85. m_hGenPostEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  86. m_pHardwareStatusThread = NULL;
  87. m_bWithCollimator = false;
  88. m_nDeviceType = 0;
  89. m_fMsLimit = 500;
  90. m_strConfigPath = configfile;
  91. ResDataObject temp;
  92. temp.loadFile(m_strConfigPath.c_str());
  93. m_GenConfig = temp["CONFIGURATION"];
  94. TransJsonText(m_GenConfig);
  95. m_nDeviceType = (int)(m_GenConfig["GenType"]);//默认设置为2. 带有coll的。
  96. if (m_nDeviceType == 2)
  97. {
  98. m_bWithCollimator = true;
  99. }
  100. m_nAECMode = (int)m_GenConfig["AECMODE"];
  101. m_fMsLimit = (float)m_GenConfig["LIMITMS"];//default 500
  102. m_nCtlMode = (int)m_GenConfig["GenCtrlMode"];//default 2
  103. char strStart1[6] = { 0x01,0x35,0x00,0x01,0x01,0x38 };
  104. char strStart2[7] = { 0x01,0x01,0x00,0x02,0x00,0x64,0x73 };
  105. char strStart0a[7] = { 0x01,0x06,0x00,0x02,0x01,0x00,0x0a };
  106. char strStart1b[7] = { 0x01,0x06,0x00,0x02,0x01,0x01,0x0b };
  107. char strStart2c[7] = { 0x01,0x06,0x00,0x02,0x01,0x02,0x0c };
  108. char strStart3d[7] = { 0x01,0x06,0x00,0x02,0x01,0x03,0x0d };
  109. char strStart4e[7] = { 0x01,0x06,0x00,0x02,0x01,0x04,0x0e };
  110. char strStart5f[7] = { 0x01,0x06,0x00,0x02,0x01,0x05,0x0f };
  111. char strStart00c[8] = { 0x01,0x07,0x00,0x03,0x01,0x00,0x00,0x0c };
  112. char strStart01d[8] = { 0x01,0x07,0x00,0x03,0x01,0x00,0x01,0x0d };
  113. char strStart02e[8] = { 0x01,0x07,0x00,0x03,0x01,0x00,0x02,0x0e };
  114. char strStart03f[8] = { 0x01,0x07,0x00,0x03,0x01,0x00,0x03,0x0f };
  115. char strStart040[8] = { 0x01,0x07,0x00,0x03,0x01,0x00,0x04,0x10 };
  116. char strEnd1[8] = { 0x43,0x41,0x30,0x03,0xb7,0x50,0x52,0x30 };
  117. char strEnd2[8] = { 0x03,0xd5,0x01,0x35,0x00,0x01,0x00,0x37 };
  118. if (m_nCtlMode == 2)
  119. {
  120. //SendCommands(strStart1, 6);
  121. HWSend(strStart1);
  122. //::Sleep(50);
  123. HWSend(strStart2);
  124. //::Sleep(50);
  125. HWSend(strStart0a);
  126. //::Sleep(50);
  127. HWSend(strStart1b);
  128. //::Sleep(50);
  129. HWSend(strStart2c);
  130. //::Sleep(50);
  131. HWSend(strStart3d);
  132. //::Sleep(50);
  133. HWSend(strStart4e);
  134. //::Sleep(50);
  135. HWSend(strStart5f);
  136. //::Sleep(50);
  137. HWSend(strStart0a);
  138. //::Sleep(50);
  139. HWSend(strStart00c);
  140. //::Sleep(50);
  141. HWSend(strStart01d);
  142. //::Sleep(50);
  143. HWSend(strStart02e);
  144. //::Sleep(50);
  145. HWSend(strStart03f);
  146. //::Sleep(50);
  147. HWSend(strStart040);
  148. //::Sleep(50);
  149. HWSend(strStart00c);
  150. //::Sleep(50);
  151. HWSend(strStart01d);
  152. //::Sleep(50);
  153. HWSend(strStart02e);
  154. //::Sleep(50);
  155. HWSend(strStart03f);
  156. //::Sleep(50);
  157. HWSend(strStart040);
  158. SetExpEnable();
  159. }
  160. m_bDAPEnable = false;
  161. m_bSaveMSMA = true;
  162. //SynMode default is what?
  163. OnCallBack();
  164. Register();
  165. Reset();
  166. Sleep(500);
  167. HWSend("DS");
  168. HWSend("ET?");
  169. HWSend("ST");
  170. RefreshData();
  171. HWSend("ATU?");//直到收到ATU1为止。
  172. m_bCheckATUStatus = true;
  173. StartHardwareStatusThread();
  174. }
  175. nsGEN::CPIDevice::~CPIDevice()
  176. {
  177. CloseHandle(m_hGenPostEvent);
  178. }
  179. std::string nsGEN::CPIDevice::GetGUID() const
  180. {
  181. mLog::Info("\n===============GetGUID : {$} ===================\n", GeneratorUnitType);
  182. return GeneratorUnitType;
  183. }
  184. void nsGEN::CPIDevice::Register()
  185. {
  186. auto Disp = &Dispatch;
  187. superGen::Register(Disp);
  188. superGen::RegisterRAD(Disp);
  189. superGen::RegisterAEC(Disp);
  190. superGen::RegisterExpEnable(Disp);
  191. Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  192. auto fun_Clear_DAP = [this](auto a, auto&)
  193. {
  194. return Clear_DAP();
  195. };
  196. Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
  197. auto fun_GetValue_DAP = [this](auto a, auto& b)
  198. {
  199. float value = 0;
  200. RET_STATUS ret = GetValue_DAP(value);
  201. b = ToJSON(value);
  202. return ret;
  203. };
  204. Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
  205. auto fun_StartMove = [this](auto a,auto& b)
  206. {
  207. return StartMove();
  208. };
  209. Disp->Action.Push("StartMove", fun_StartMove);
  210. auto fun_EndMove = [this](auto a, auto& b)
  211. {
  212. return EndMove();
  213. };
  214. Disp->Action.Push("EndMove", fun_EndMove);
  215. }
  216. RET_STATUS nsGEN::CPIDevice::IncKV()
  217. {
  218. if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
  219. return HWSend("KV+");
  220. }
  221. RET_STATUS nsGEN::CPIDevice::DecKV()
  222. {
  223. if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
  224. return HWSend("KV-");
  225. }
  226. RET_STATUS nsGEN::CPIDevice::SetKV(float value)
  227. {
  228. if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
  229. char temp[50] = { 0 };
  230. sprintf_s(temp, "KV%03d", (int)value);
  231. return HWSend(temp);
  232. }
  233. RET_STATUS nsGEN::CPIDevice::IncMA()
  234. {
  235. if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
  236. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode == 1)
  237. {
  238. mLog::Info("\n In AEC mode, do not allowed INCMA");
  239. return RET_STATUS::RET_FAILED;
  240. }
  241. return HWSend("MA+");
  242. }
  243. RET_STATUS nsGEN::CPIDevice::DecMA()
  244. {
  245. if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
  246. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode == 1)
  247. {
  248. mLog::Info("\n In AEC mode, do not allowed DECMA");
  249. return RET_STATUS::RET_FAILED;
  250. }
  251. return HWSend("MA-");
  252. }
  253. RET_STATUS nsGEN::CPIDevice::SetMA(float value)
  254. {
  255. if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  256. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode == 1)
  257. {
  258. //logfile->WriteLog("In AEC mode, do not allowed SetMA", LOG_INFORMATION, LOG_DEBUG, true);
  259. mLog::Info("\n In AEC mode, do not allowed SetMA");
  260. return RET_STATUS::RET_FAILED;
  261. }
  262. char temp[50] = { 0 };
  263. sprintf_s(temp, "MA%05d", (int)(value * 10));
  264. return HWSend(temp);
  265. }
  266. RET_STATUS nsGEN::CPIDevice::IncMS()
  267. {
  268. if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
  269. /*
  270. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  271. {
  272. PRINTA_INFO("\n Techmode is MAS, can't inc MS");
  273. return RET_STATUS::RET_FAILED;
  274. }
  275. */
  276. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode != 2)
  277. {
  278. //logfile->WriteLog("In AEC mode, do not allowed SetMA", LOG_INFORMATION, LOG_DEBUG, true);
  279. mLog::Info("\n In AEC mode, do not allowed INCMS");
  280. return RET_STATUS::RET_FAILED;
  281. }
  282. return HWSend("MS+");
  283. }
  284. RET_STATUS nsGEN::CPIDevice::DecMS()
  285. {
  286. if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
  287. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode != 2)
  288. {
  289. mLog::Info("\n Techmode is MAS, can't dec MS");
  290. return RET_STATUS::RET_FAILED;
  291. }
  292. return HWSend("MS-");
  293. }
  294. RET_STATUS nsGEN::CPIDevice::SetMS(float value)
  295. {
  296. if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  297. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode != 2)
  298. {
  299. mLog::Info("\n In AEC mode, do not allowed SetMS");
  300. return RET_STATUS::RET_FAILED;
  301. }
  302. char temp[50] { 0 };
  303. sprintf_s(temp, "MS%05d", (int)(value * 10));
  304. return HWSend(temp);
  305. }
  306. RET_STATUS nsGEN::CPIDevice::IncMAS()
  307. {
  308. if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
  309. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode != 1)
  310. {
  311. mLog::Info("\n Techmode is not MAS, can't inc MAS");
  312. return RET_STATUS::RET_FAILED;
  313. }
  314. return HWSend("MX+");
  315. }
  316. RET_STATUS nsGEN::CPIDevice::DecMAS()
  317. {
  318. if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
  319. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode != 1)
  320. {
  321. mLog::Info("\n Techmode is not MAS, can't dec MAS");
  322. return RET_STATUS::RET_FAILED;
  323. }
  324. return HWSend("MX-");
  325. }
  326. RET_STATUS nsGEN::CPIDevice::SetMAS(float value)
  327. {
  328. if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  329. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC && m_nAECMode != 1)
  330. {
  331. mLog::Info("\n Techmode is not MAS, can't set MAS");
  332. return RET_STATUS::RET_FAILED;
  333. }
  334. char temp[50] = { 0 };
  335. sprintf_s(temp, "MX%05d", (int)(value * 10));
  336. return HWSend(temp);
  337. }
  338. RET_STATUS nsGEN::CPIDevice::SetTechmode(int value)
  339. {
  340. if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
  341. //char temp[50] = { 0 };
  342. //sprintf_s(temp, "ET%01d", (int)value);
  343. //return HWSend(temp);
  344. //CPI设置ET mode有点特殊
  345. float fms, fma;
  346. m_nPreET = m_DoseUnit.m_Techmode->Get();
  347. char temp[50] = { 0 };
  348. sprintf_s(temp, "ET%01d", (int)value);
  349. HWSend(temp);
  350. if (!m_bSaveMSMA)
  351. return RET_STATUS::RET_FAILED;
  352. if (value == AttrKey::TECHMODE_V2TYPE::ET_TIME)
  353. {
  354. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)//NOTE: use m_DoseUnit.m_Techmode->Get() not accurate. m_nPreET more better.!!!!
  355. {
  356. // mas - time
  357. if ((m_fPreMA > 0.1))
  358. {
  359. Sleep(50);
  360. SetMA(m_fPreMA);
  361. }
  362. Sleep(50);
  363. SetMS(m_PrefMS);
  364. }
  365. else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC)
  366. {
  367. // aec - time
  368. if (m_bSaveMSMA)
  369. {
  370. fms = m_PrefMS;
  371. fma = m_fPreMA;
  372. Sleep(50);
  373. SetMS(fms);
  374. Sleep(50);
  375. SetMA(fma);
  376. }
  377. }
  378. }
  379. else if (value == AttrKey::TECHMODE_V2TYPE::ET_MAS) //mas
  380. {
  381. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_TIME)
  382. {
  383. // time - mas save
  384. if (m_bSaveMSMA)
  385. {
  386. m_PrefMS = m_DoseUnit.m_MS->Get();
  387. m_fPreMA = m_DoseUnit.m_MA->Get();
  388. }
  389. }
  390. else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC)
  391. {
  392. // aec - mas
  393. if (m_bSaveMSMA)
  394. {
  395. fms = m_PrefMS;
  396. fma = m_fPreMA;
  397. }
  398. SetMAS(m_PrefMS * m_fPreMA / 1000); //mas mode : set dose to ma * ms
  399. }
  400. }
  401. else if (value == AttrKey::TECHMODE_V2TYPE::ET_AEC) //aec
  402. {
  403. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_TIME)
  404. {
  405. // time - aec save
  406. if (m_bSaveMSMA)
  407. {
  408. m_PrefMS = m_DoseUnit.m_MS->Get();
  409. m_fPreMA = m_DoseUnit.m_MA->Get();
  410. }
  411. }
  412. else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  413. {
  414. // mas - aec
  415. if ((m_fPreMA > 0.1))
  416. {
  417. Sleep(50);
  418. if (m_nAECMode != 1)
  419. SetMA(m_fPreMA);
  420. }
  421. }
  422. Sleep(50);
  423. if (m_nAECMode == 2)
  424. SetMS(m_fMsLimit);
  425. //ysj++:不知道为什么要这么干,不过此处需要一个设置MS的语句
  426. //if (m_nWS == GEN_WS_TOMO)
  427. //{
  428. // if (m_nAECMode == 2)
  429. // SetMS(m_PrefMS);
  430. //}
  431. //else
  432. //{
  433. // if (m_nAECMode == 2)
  434. // SetMS(m_fMsLimit);
  435. //}
  436. }
  437. }
  438. RET_STATUS nsGEN::CPIDevice::SetFocus(int value)
  439. {
  440. if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
  441. char temp[50] = { 0 };
  442. sprintf_s(temp, "FO%01d", (int)value);
  443. return HWSend(temp);
  444. }
  445. RET_STATUS nsGEN::CPIDevice::SetAECDensity(int value)
  446. {
  447. mLog::Info("Enter SetAECDensity {$}", value);
  448. if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED;
  449. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC) return RET_STATUS::RET_FAILED;
  450. int nAECDensity = m_DoseUnit.m_AECDensity->Get();
  451. if (value < m_DoseUnit.m_AECDensity->Get())
  452. {
  453. if (value < m_DoseUnit.m_AECDensity->Get() - 1)
  454. {
  455. nAECDensity = (int)value;
  456. }
  457. else
  458. {
  459. nAECDensity = nAECDensity - 1;
  460. }
  461. }
  462. else if (value > m_DoseUnit.m_AECDensity->Get())
  463. {
  464. if (value > m_DoseUnit.m_AECDensity->Get() + 1)
  465. {
  466. nAECDensity = (int)value;
  467. }
  468. else
  469. {
  470. nAECDensity = nAECDensity + 1;
  471. }
  472. }
  473. char temp[50] = { 0 };
  474. if (nAECDensity >= 0)
  475. {
  476. sprintf_s(temp, "FN+%01d", (int)nAECDensity);
  477. }
  478. else
  479. {
  480. sprintf_s(temp, "FN-%01d", (int)nAECDensity);
  481. }
  482. return HWSend(temp);
  483. }
  484. RET_STATUS nsGEN::CPIDevice::SetAECField(int value)
  485. {
  486. if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
  487. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) return RET_STATUS::RET_FAILED;
  488. char temp[50] = { 0 };
  489. sprintf_s(temp, "FI%03d", (int)value);
  490. return HWSend(temp);
  491. }
  492. RET_STATUS nsGEN::CPIDevice::SetAECFilm(int value)
  493. {
  494. if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
  495. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) return RET_STATUS::RET_FAILED;
  496. char temp[50] = { 0 };
  497. sprintf_s(temp, "FS%03d", (int)value);
  498. return HWSend(temp);
  499. }
  500. RET_STATUS nsGEN::CPIDevice::SetWS(const string value)
  501. {
  502. mLog::Info("Enter SetWS {$}", value);
  503. int tempws = 0;
  504. if (value == "Table") tempws = (int)m_GenConfig["WSTable"];
  505. else if (value == "Wall") tempws = (int)m_GenConfig["WSWall"];
  506. else if (value == "Direct") tempws = (int)m_GenConfig["WSConventional"];
  507. else if (value == "Free") tempws = (int)m_GenConfig["WSFree"];
  508. else if (value == "Tomo") tempws = (int)m_GenConfig["WSTomo"];
  509. char temp[50] = { 0 };
  510. sprintf_s(temp, "WS%01d", tempws);
  511. return HWSend(temp);
  512. }
  513. RET_STATUS nsGEN::CPIDevice::SetAPR(const _tAPRArgs& t)
  514. {
  515. m_t = t;
  516. mLog::Info("*********************Enter SetAPR**********************");
  517. mLog::Info("APR:t.fKV={$}, t.fMA={$}, t.fMAS={$}, t.fMS={$}, t.nAECDensity={$}, t.nAECField={$}, t.nAECFilm={$}, t.nFocus={$}, t.nTechmode={$}", t.fKV, t.fMA, t.fMAS, t.fMS, t.nAECDensity, t.nAECField, t.nAECFilm, t.nFocus, t.nTechmode);
  518. /// //////////////////////////////////////////////begin
  519. //SetWS(); //ysj++:缺少传递ws的apr结构体
  520. //GetTechMode(); //ysj++:理论上,init时,RR指令已经获取ET了。
  521. HWSend("ET?");
  522. if (m_DoseUnit.m_Focus->Get() == 0)
  523. {
  524. SetFocus(t.nFocus);
  525. }
  526. /*
  527. * //not add this logic: because struct _tAPRArgs ,not include WS item.
  528. if ((nWS != GEN_WS_TABLE) && (nWS != GEN_WS_WALL) && (nET == GEN_ET_AEC))
  529. {
  530. if (m_nET != GEN_ET_AEC)
  531. {
  532. nET = m_nET;
  533. }
  534. else
  535. {
  536. nET = GEN_ET_MATIME;
  537. }
  538. }
  539. */
  540. m_PrefMS = t.fMS;
  541. m_fPreMA = t.fMA;
  542. m_bSaveMSMA = false;
  543. if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_AEC)
  544. {
  545. // aec
  546. SetTechmode(t.nTechmode);
  547. SetAECField(t.nAECField);
  548. SetAECDensity(t.nAECDensity);
  549. if (t.nAECFilm == 0)
  550. {
  551. SetAECFilm(10);
  552. }
  553. else
  554. {
  555. SetAECFilm(t.nAECFilm);
  556. }
  557. if (m_nAECMode == 2)
  558. {
  559. if (t.fKV > m_DoseUnit.m_KV->Get())
  560. {
  561. SetMA(t.fMA);
  562. SetKV(t.fKV);
  563. }
  564. else
  565. {
  566. if (t.fMA < m_DoseUnit.m_MA->Get())
  567. {
  568. SetMA(t.fMA);
  569. SetKV(t.fKV);
  570. }
  571. else
  572. {
  573. SetKV(t.fKV);
  574. SetMA(t.fMA);
  575. }
  576. }
  577. Sleep(50);
  578. SetMS(m_fMsLimit);//int V2 mode.m_fMsLimit is set by UI.but in CCOS2.0 it set by config file.
  579. }
  580. else if (m_nAECMode == 1)
  581. {
  582. if (t.fKV > m_DoseUnit.m_KV->Get())
  583. {
  584. SetMA(t.fMA);
  585. Sleep(50);
  586. SetKV(t.fKV);
  587. }
  588. else
  589. {
  590. if (t.fMA < m_DoseUnit.m_MA->Get())
  591. {
  592. SetMA(t.fMA);
  593. Sleep(50);
  594. SetKV(t.fKV);
  595. }
  596. else
  597. {
  598. SetKV(t.fKV);
  599. Sleep(50);
  600. SetMA(t.fMA);
  601. }
  602. }
  603. Sleep(50);
  604. SetMAS(t.fMAS);
  605. }
  606. else
  607. {
  608. if (t.fMA < m_DoseUnit.m_MA->Get())
  609. {
  610. SetMA(t.fMA);
  611. Sleep(50);
  612. SetKV(t.fKV);
  613. }
  614. else
  615. {
  616. SetKV(t.fKV);
  617. Sleep(50);
  618. SetMA(t.fMA);
  619. }
  620. }
  621. }
  622. else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  623. {
  624. // mas
  625. SetTechmode(t.nTechmode);
  626. SetKV(t.fKV);
  627. const float EPSINON = 0.000001;
  628. if ((t.fMAS >= -EPSINON) && (t.fMAS <= EPSINON))
  629. {
  630. SetMAS(t.fMA * t.fMS / 1000);
  631. }
  632. else
  633. {
  634. SetMAS(t.fMAS);
  635. }
  636. }
  637. else if(t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_TIME)
  638. {
  639. // time
  640. SetTechmode(t.nTechmode);
  641. Sleep(50);
  642. if (t.fKV > m_DoseUnit.m_KV->Get())
  643. {
  644. SetMA(t.fMA);
  645. Sleep(50);
  646. SetKV(t.fKV);
  647. }
  648. else
  649. {
  650. if (t.fMA < m_DoseUnit.m_MA->Get())
  651. {
  652. SetMA(t.fMA);
  653. Sleep(50);
  654. SetKV(t.fKV);
  655. }
  656. else
  657. {
  658. SetKV(t.fKV);
  659. Sleep(50);
  660. SetMA(t.fMA);
  661. }
  662. }
  663. Sleep(80);
  664. SetMS(t.fMS);
  665. }
  666. if (m_DoseUnit.m_Focus->Get() == 1)
  667. {
  668. SetFocus(t.nFocus);
  669. }
  670. m_bSaveMSMA = true;
  671. ///////////////////////end
  672. return RET_STATUS::RET_SUCCEED;
  673. }
  674. RET_STATUS nsGEN::CPIDevice::QueryDAP()
  675. {
  676. if (m_bDAPEnable)
  677. {
  678. return HWSend("DA");
  679. }
  680. return RET_STATUS::RET_SUCCEED;
  681. }
  682. RET_STATUS nsGEN::CPIDevice::QueryHE(int& value)
  683. {
  684. value = m_DoseUnit.m_HE->Get();
  685. return RET_STATUS::RET_SUCCEED;
  686. }
  687. RET_STATUS nsGEN::CPIDevice::QueryPostKV(float& value)
  688. {
  689. value = m_DoseUnit.m_PostKV->Get();
  690. return RET_STATUS::RET_SUCCEED;
  691. }
  692. RET_STATUS nsGEN::CPIDevice::QueryPostMA(float& value)
  693. {
  694. value = m_DoseUnit.m_PostMA->Get();
  695. return RET_STATUS::RET_SUCCEED;
  696. }
  697. RET_STATUS nsGEN::CPIDevice::QueryPostMS(float& value)
  698. {
  699. value = m_DoseUnit.m_PostMS->Get();
  700. return RET_STATUS::RET_SUCCEED;
  701. }
  702. RET_STATUS nsGEN::CPIDevice::QueryPostMAS(float& value)
  703. {
  704. value = m_DoseUnit.m_PostMAS->Get();
  705. return RET_STATUS::RET_SUCCEED;
  706. }
  707. RET_STATUS nsGEN::CPIDevice::Clear_DAP()
  708. {
  709. if (m_bDAPEnable)
  710. {
  711. return HWSend("DZ");
  712. }
  713. else
  714. return RET_STATUS::RET_SUCCEED;
  715. }
  716. RET_STATUS nsGEN::CPIDevice::GetValue_DAP(float& value)
  717. {
  718. value = m_DAP->Get();
  719. return RET_STATUS::RET_SUCCEED;
  720. }
  721. RET_STATUS nsGEN::CPIDevice::StartMove()
  722. {
  723. mLog::Info("Enter startMove");
  724. mLog::Info("end startmove");
  725. return RET_STATUS::RET_SUCCEED;
  726. }
  727. RET_STATUS nsGEN::CPIDevice::EndMove()
  728. {
  729. mLog::Info("Enter endmove");
  730. mLog::Info("end EndMove");
  731. return RET_STATUS::RET_SUCCEED;
  732. }
  733. RET_STATUS nsGEN::CPIDevice::SetCollimatorSize(int height, int width)
  734. {
  735. if (!m_bWithCollimator)
  736. {
  737. return RET_STATUS::RET_SUCCEED;
  738. }
  739. char temp[50] = { 0 };
  740. sprintf_s(temp, "ACH%05d", (int)(height * 100));
  741. HWSend(temp);
  742. sprintf_s(temp, "ACW%05d", (int)(width * 100));
  743. HWSend(temp);
  744. return RET_STATUS::RET_SUCCEED;
  745. }
  746. RET_STATUS nsGEN::CPIDevice::SetFilter(int filterType)
  747. {
  748. if (!m_bWithCollimator)
  749. {
  750. return RET_STATUS::RET_SUCCEED;
  751. }
  752. if (filterType > 3)
  753. {
  754. filterType -= 3;
  755. }
  756. char temp[50] = { 0 };
  757. sprintf_s(temp, "FIL%02d", (int)(filterType));
  758. return HWSend(temp);
  759. }
  760. RET_STATUS nsGEN::CPIDevice::SetGenSynState(int value)
  761. {
  762. if (AttrKey::GENERATOR_RAD_XRAYON == value) //软同步,收到XR1时,子系统会变为XRAYON状态,并调用此处,然后我立刻回复XR1至发生器,然后才真正出线。
  763. {
  764. mLog::Info("SetGenSynState be call.this is soft syn mode.");
  765. HWSend("XR1");
  766. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
  767. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  768. }
  769. return RET_STATUS::RET_SUCCEED;
  770. }
  771. RET_STATUS nsGEN::CPIDevice::SetGenState(int value)
  772. {
  773. return RET_STATUS::RET_SUCCEED;
  774. }
  775. RET_STATUS nsGEN::CPIDevice::SetExpMode(std::string value)
  776. {
  777. mLog::Info("Enter SetExpMode...{$}",value);
  778. m_DoseUnit.m_ExpMode->Update(value);
  779. return RET_STATUS::RET_SUCCEED;
  780. }
  781. RET_STATUS nsGEN::CPIDevice::SetFLFMode(std::string value)
  782. {
  783. return RET_STATUS::RET_SUCCEED;
  784. //char temp[50]{ 0 };
  785. //sprintf_s(temp, "RTS%s",value.c_str());
  786. //return HWSend(temp);
  787. }
  788. RET_STATUS nsGEN::CPIDevice::SetEXAMMode(std::string value)
  789. {
  790. return RET_STATUS::RET_SUCCEED;
  791. }
  792. RET_STATUS nsGEN::CPIDevice::SetFrameRate(FLOAT frameRate)
  793. {
  794. m_DoseUnit.m_FrameRate->Update(frameRate);
  795. return RET_STATUS::RET_SUCCEED;
  796. }
  797. RET_STATUS nsGEN::CPIDevice::SetRPS(int rps)
  798. {
  799. return RET_STATUS::RET_SUCCEED;
  800. }
  801. RET_STATUS nsGEN::CPIDevice::RefreshData()
  802. {
  803. if (m_nDeviceType == 1)
  804. {
  805. HWSend("RRX");
  806. }
  807. else
  808. {
  809. //HWSend("RR");
  810. HWSend("KV?");
  811. HWSend("MA?");
  812. HWSend("MS?");
  813. HWSend("MX?");
  814. }
  815. return RET_STATUS::RET_SUCCEED;
  816. }
  817. RET_STATUS nsGEN::CPIDevice::SetExpEnable()
  818. {
  819. m_bExpEnable = true;
  820. return RET_STATUS::RET_SUCCEED;
  821. }
  822. RET_STATUS nsGEN::CPIDevice::SetExpDisable()
  823. {
  824. m_bExpEnable = false;
  825. return RET_STATUS::RET_SUCCEED;
  826. }
  827. RET_STATUS nsGEN::CPIDevice::Reset()
  828. {
  829. return HWSend("RE");
  830. }
  831. RET_STATUS nsGEN::CPIDevice::SetCollimatorDev(OemCollimator* dev)
  832. {
  833. if (dev)
  834. m_pCollDev.reset(dev);
  835. return RET_STATUS::RET_SUCCEED;
  836. }
  837. RET_STATUS nsGEN::CPIDevice::SetMechDev(OemMechanical* dev)
  838. {
  839. //if (dev)
  840. //m_pMechDev.reset(dev);
  841. return RET_STATUS::RET_SUCCEED;
  842. }
  843. RET_STATUS nsGEN::CPIDevice::SetDapDev(OemDap* dev)
  844. {
  845. if (dev)
  846. m_pDapDev.reset(dev);
  847. return RET_STATUS::RET_SUCCEED;
  848. }
  849. RET_STATUS nsGEN::CPIDevice::HWSend(char* strCommand, int nTimeOut)
  850. {
  851. if (!m_SCF) return RET_STATUS::RET_FAILED;
  852. char strSendCommand[100] = { 0 };
  853. int len = strlen(strCommand);
  854. int tmpSum = 0;
  855. for (int i = 0; i < len; i++)
  856. {
  857. tmpSum += (int)strCommand[i];
  858. }
  859. char checkSum = char(tmpSum + 3);
  860. //strSendCommand[0] = 0x02;
  861. memcpy(strSendCommand , strCommand, len);
  862. strSendCommand[len + 0] = 0x03;
  863. strSendCommand[len + 1] = checkSum;
  864. printf("==OUT==: %s \n", strSendCommand);
  865. mLog::Info("==OUT==: {$} \n", strSendCommand);
  866. int retLength;
  867. m_SCF.Lock(msTimeOut_Lock)
  868. .SendPacket(strSendCommand, strlen(strSendCommand), nTimeOut, retLength);
  869. Sleep(nTimeOut);
  870. return RET_STATUS::RET_SUCCEED;
  871. }
  872. //-----------------------------------------------------------------------------
  873. // ProcessCmd
  874. //-----------------------------------------------------------------------------
  875. void nsGEN::CPIDevice::FireNotify(std::string key, std::string content)
  876. {
  877. EventCenter->OnNotify(1, key, content);
  878. }
  879. struct tFrameMapping
  880. {
  881. static const int MaxLen = 5; // 前缀不能超超过 5 个字符 !
  882. using cbFun = std::function <void(const char*, int)>;
  883. char strHead[MaxLen];
  884. int NbOfCharOfHead;
  885. cbFun fun;
  886. tFrameMapping(char* str, int len, cbFun f)
  887. {
  888. assert(len < MaxLen); //len最大只能是4
  889. //strHead[0] = 0x02; //STX
  890. //for (int i = 0; i < len; i++) //给strHead赋值
  891. // strHead[i + 1] = str[i];
  892. //NbOfCharOfHead = len + 1;
  893. //fun = f;
  894. //assert(len < MaxLen);
  895. for (int i = 0; i < len; i++)
  896. strHead[i] = str[i];
  897. NbOfCharOfHead = len;
  898. fun = f;
  899. }
  900. };
  901. static std::list <tFrameMapping> arFrame;
  902. static bool DecodeFrame(const char* strFrame, int length);
  903. //KV075 MA05000 MS00800 MX00400
  904. // ==IN==:KV075 MA05000 MS00800 MX00400
  905. void nsGEN::CPIDevice::OnCallBack()
  906. {
  907. auto HWNotProcess = [](const char* value, int length) -> void
  908. {
  909. mLog::Info("\n This commands didn't need to process!\n");
  910. };
  911. auto HWKV = [this](const char* value, int length) -> void
  912. {
  913. assert(value);
  914. if (m_DoseUnit.m_KV->Update(atof(value)))
  915. FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
  916. };
  917. auto HWMAS = [this](const char* value, int length)
  918. {
  919. assert(value);
  920. float fmas = atof(value) / 10.0;
  921. //if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_TIME)
  922. //{
  923. // //if (m_DoseUnit.m_MAS->Update(0))
  924. // // FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  925. //}
  926. //else
  927. //{
  928. // if (m_DoseUnit.m_MAS->Update(fmas))
  929. // FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  930. //}
  931. if (m_DoseUnit.m_MAS->Update(fmas))
  932. FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  933. };
  934. auto HWMA = [this](const char* value, int length)
  935. {
  936. assert(value);
  937. float fma = atof(value) / 10.0;
  938. if (m_DoseUnit.m_MA->Update(fma))
  939. FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
  940. };
  941. auto HWMS = [this](const char* value, int length)
  942. {
  943. assert(value);
  944. if (m_DoseUnit.m_MS->Update(atof(value) / 10.0))
  945. FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
  946. };
  947. auto HWFocus = [this](const char* value, int length)
  948. {
  949. assert(value);
  950. if (m_DoseUnit.m_Focus->Update(atoi(value)))
  951. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  952. };
  953. auto HWTechmode = [this](const char* value, int length)
  954. {
  955. assert(value);
  956. if (m_DoseUnit.m_Techmode->Update(atoi(value)))
  957. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  958. };
  959. auto HWAECField = [this](const char* value, int length)
  960. {
  961. assert(value);
  962. int nvalue = atoi(value);
  963. if (m_DoseUnit.m_AECField->Update(nvalue))
  964. FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_AECField->JSGet());
  965. };
  966. auto HWAECFilm = [this](const char* value, int length)
  967. {
  968. assert(value);
  969. if (m_DoseUnit.m_AECFilm->Update(atoi(value)))
  970. FireNotify(AttrKey::AECFILM, m_DoseUnit.m_AECFilm->JSGet());
  971. };
  972. auto HWAECDensity = [this](const char* value, int length)
  973. {
  974. assert(value);
  975. if (m_DoseUnit.m_AECDensity->Update(atoi(value)))
  976. FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
  977. };
  978. auto HWWS = [this](const char* value, int length)
  979. {
  980. assert(value);
  981. //ysj++:理论上 此处得到WS的值,需要转为对应的数字,转换后的数字,能给UI一致,从而得出正确的ws并显示出来。
  982. int nValue = atoi(value);
  983. if (m_DoseUnit.m_WS->Update(nValue))
  984. {
  985. FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
  986. }
  987. };
  988. auto HWPR = [this](const char* value, int length)
  989. {
  990. assert(value);
  991. int nValue = atoi(value);
  992. if (nValue == 2)
  993. {
  994. m_bInExpState = true;
  995. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
  996. ResetEvent(m_hGenPostEvent);
  997. HWSend("PR2");
  998. }
  999. else if (nValue == 1)
  1000. {
  1001. m_bInExpState = true;
  1002. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE);
  1003. HWSend("PR1");
  1004. }
  1005. else if (nValue == 0)
  1006. {
  1007. m_bInExpState = false;;
  1008. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
  1009. HWSend("PR0");
  1010. }
  1011. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1012. };
  1013. auto HWXR = [this](const char* value, int length)
  1014. {
  1015. assert(value);
  1016. int nValue = atoi(value);
  1017. if (nValue == 1)
  1018. {
  1019. if ((this->m_nCtlMode == 2) && m_bExpEnable)
  1020. {
  1021. if (EXPOSURE_SOFTWARE_NOSYNBOX == (int)m_GenConfig["SynMode"] || EXPOSURE_NOSYNBOX_DIRCETCONNECT_DETECTOR_GEN == (int)m_nCtlMode["SynMode"])
  1022. {
  1023. mLog::Info("recv XR1 ,in nosynbox or in derect mode ,do nothing,and wait invoke be call,then send XR1,and send XRAYON msg.");
  1024. //m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);// ysj++ 我们认为此处不应该发这个消息,准确的时机 应该是invoke被调用的时候,
  1025. }
  1026. if (EXPOSURE_SOFTWARE_NOSYNBOX != (int)m_GenConfig["SynMode"])
  1027. {
  1028. mLog::Info("recv XR1 ,in hardware or in derect mode ,so response XR1.");
  1029. HWSend("XR1");
  1030. }
  1031. }
  1032. else
  1033. {
  1034. if (2 != this->m_nCtlMode)
  1035. {
  1036. if (EXPOSURE_SOFTWARE_NOSYNBOX == (int)m_GenConfig["SynMode"] || EXPOSURE_NOSYNBOX_DIRCETCONNECT_DETECTOR_GEN == (int)m_nCtlMode["SynMode"])
  1037. {
  1038. //::SendMessage(this->m_hWnd, MSG_SYN_STATUS, SYN_GEN_EIPON, 1); //------------------------------------------------貌似没有软同步的消息
  1039. mLog::Info("recv XR1 : ctrlmode !=2, in No SYNbox or in directly mode, Send Msg SYN_GEN_EIPON");
  1040. }
  1041. }
  1042. }
  1043. }
  1044. else if (nValue == 0)
  1045. {
  1046. if (m_nCtlMode == 2)
  1047. {
  1048. HWSend("XR0");
  1049. }
  1050. HWSend("DA");
  1051. HWSend("AP?");
  1052. HWSend("AT?");
  1053. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
  1054. }
  1055. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1056. };
  1057. auto HWAPDOSE = [this](const char* value, int length)//post mas
  1058. {
  1059. assert(value);
  1060. if(m_DoseUnit.m_PostMAS->Update(atof(value) / 10.0))
  1061. FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
  1062. //SetEvent(m_hGenPostEvent);
  1063. };
  1064. auto HWKW = [this](const char* value, int length)
  1065. {
  1066. assert(value);
  1067. mLog::Info("Recv KW={$}", atoi(value));
  1068. };
  1069. auto HWATDOSE = [this](const char* value, int length)
  1070. {
  1071. assert(value);
  1072. if(m_DoseUnit.m_PostMS->Update(atof(value)/10.0))
  1073. FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
  1074. //SetEvent(m_hGenPostEvent);
  1075. };
  1076. auto HWDAP = [this](const char* value, int length)
  1077. {
  1078. assert(value);
  1079. mLog::Info("Recv DAP ={$}", atof(value) / 100.0);
  1080. //ysj++:理论上此处应该调用DAP设备。
  1081. if (m_pDapDev)
  1082. {
  1083. m_pDapDev->UpdateMammo_DAP(atof(value) / 100.0);
  1084. }
  1085. };
  1086. auto HWERROR = [this](const char* value, int length)
  1087. {
  1088. assert(value);
  1089. int nValue = atoi(value);
  1090. if (nValue != 0)
  1091. {
  1092. char ErrorCode[10]{ "" };
  1093. sprintf_s(ErrorCode, "CPI_ERR_%d", nValue);
  1094. int level = 1;
  1095. m_MSGUnit->AddErrorMessage(ErrorCode, level, "");
  1096. //去配置文件中找error对应的信息
  1097. }
  1098. else
  1099. {
  1100. int level = 1;
  1101. char ErrorCode[10]{ "" };
  1102. m_MSGUnit->DelErrorMessage(ErrorCode, level, "");
  1103. }
  1104. };
  1105. auto HWWARN = [this](const char* value, int length)
  1106. {
  1107. assert(value);
  1108. int nValue = atoi(value);
  1109. if (nValue != 0)
  1110. {
  1111. char WarnCode[10]{ "" };
  1112. sprintf_s(WarnCode, "CPI_WARN_%d", nValue);
  1113. int level = 1;
  1114. m_MSGUnit->AddWarnMessage(WarnCode, level, "");
  1115. }
  1116. else
  1117. {
  1118. int level = 1;
  1119. char WarnCode[10]{ "" };
  1120. m_MSGUnit->AddWarnMessage(WarnCode, level, "");
  1121. }
  1122. };
  1123. auto HWEHE = [this](const char* value, int length)
  1124. {
  1125. assert(value);
  1126. if(m_DoseUnit.m_HE->Update(atoi(value)))
  1127. FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
  1128. };
  1129. auto HWFLK = [this](const char* value, int length)
  1130. {
  1131. assert(value);
  1132. if (m_DoseUnit.m_KV->Update(atof(value)))
  1133. FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
  1134. };
  1135. auto HWFLM = [this](const char* value, int length)
  1136. {
  1137. assert(value);
  1138. if (m_DoseUnit.m_MA->Update(atof(value)/10.0))
  1139. FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
  1140. };
  1141. auto HWFLS = [this](const char* value, int length)
  1142. {
  1143. assert(value);
  1144. if (m_DoseUnit.m_FrameRate->Update(atof(value)/10.0))
  1145. FireNotify(AttrKey::FRAMERATE, m_DoseUnit.m_FrameRate->JSGet());
  1146. };
  1147. auto HWFLX = [this](const char* value, int length)
  1148. {
  1149. assert(value);
  1150. int nValue = atoi(value);
  1151. if (nValue == 1)
  1152. {
  1153. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYON);
  1154. }
  1155. else if (nValue == 0)
  1156. {
  1157. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYOFF);
  1158. }
  1159. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1160. };
  1161. auto HWFLP = [this](const char* value, int length)
  1162. {
  1163. assert(value);
  1164. int nValue = atoi(value);
  1165. if (nValue == 1)
  1166. {
  1167. //PRINTA_INFO("\n recv FLP1\n"); //FLP1尚未真正的ready.
  1168. }
  1169. else if (nValue == 4)
  1170. {
  1171. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_READY); //根据全新定义 FLP4 才表示 ready。
  1172. }
  1173. else if (nValue == 0)
  1174. {
  1175. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_OFF);
  1176. }
  1177. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1178. };
  1179. auto HWACH = [this](const char* value, int length)
  1180. {
  1181. assert(value);
  1182. if (m_pCollDev)
  1183. {
  1184. m_pCollDev->UpdateCollimatorXSize(atoi(value) / 100.0);
  1185. }
  1186. };
  1187. auto HWACW = [this](const char* value, int length)
  1188. {
  1189. assert(value);
  1190. if (m_pCollDev)
  1191. {
  1192. m_pCollDev->UpdateCollimatorYSize(atoi(value) / 100.0);
  1193. }
  1194. };
  1195. auto HWFIL = [this](const char* value, int length)
  1196. {
  1197. assert(value);
  1198. if (m_pCollDev)
  1199. {
  1200. m_pCollDev->SetCollimatorFilter(atoi(value));
  1201. }
  1202. };
  1203. auto HWATU = [this](const char* value, int length)
  1204. {
  1205. assert(value);
  1206. if (1 == atoi(value))
  1207. {
  1208. m_bCheckATUStatus = false;//not need continue check status
  1209. }
  1210. else if (0 == atoi(value))
  1211. {
  1212. m_bCheckATUStatus = true;
  1213. }
  1214. };
  1215. auto HWDS = [this](const char* value, int length)
  1216. {
  1217. assert(value);
  1218. m_bDAPEnable = (bool)atoi(value);
  1219. };
  1220. arFrame.clear();
  1221. arFrame.push_back(tFrameMapping("KV", 2, HWKV));
  1222. arFrame.push_back(tFrameMapping("MX", 2, HWMAS));
  1223. arFrame.push_back(tFrameMapping("MA", 2, HWMA));
  1224. arFrame.push_back(tFrameMapping("MS", 2, HWMS));
  1225. arFrame.push_back(tFrameMapping("ET", 2, HWTechmode));
  1226. arFrame.push_back(tFrameMapping("FO", 2, HWFocus));
  1227. arFrame.push_back(tFrameMapping("FI", 2, HWAECField));
  1228. arFrame.push_back(tFrameMapping("FS", 2, HWAECFilm));
  1229. arFrame.push_back(tFrameMapping("FN", 2, HWAECDensity));
  1230. arFrame.push_back(tFrameMapping("WS", 2, HWWS));
  1231. arFrame.push_back(tFrameMapping("PR", 2, HWPR));
  1232. arFrame.push_back(tFrameMapping("XR", 2, HWXR));
  1233. arFrame.push_back(tFrameMapping("AP", 2, HWAPDOSE));
  1234. arFrame.push_back(tFrameMapping("AT", 2, HWATDOSE));
  1235. arFrame.push_back(tFrameMapping("EL", 2, HWERROR));
  1236. arFrame.push_back(tFrameMapping("ER", 2, HWWARN));
  1237. arFrame.push_back(tFrameMapping("HE", 2, HWEHE));
  1238. arFrame.push_back(tFrameMapping("DA", 2, HWDAP));
  1239. arFrame.push_back(tFrameMapping("DV", 2, HWDAP));
  1240. arFrame.push_back(tFrameMapping("DS", 2, HWDS));
  1241. arFrame.push_back(tFrameMapping("ACH", 3, HWACH));
  1242. arFrame.push_back(tFrameMapping("ACW", 3, HWACW));
  1243. arFrame.push_back(tFrameMapping("FIL", 3, HWFIL));
  1244. arFrame.push_back(tFrameMapping("ATU", 3, HWATU));
  1245. }
  1246. bool nsGEN::CPIDevice::StartHardwareStatusThread()
  1247. {
  1248. mLog::Info("enter Start HardwareStatus Thread ");
  1249. if (m_pHardwareStatusThread == NULL)
  1250. {
  1251. DWORD m_HardwareStatusID;
  1252. m_pHardwareStatusThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
  1253. if (m_pHardwareStatusThread == NULL)
  1254. {
  1255. mLog::Fatal("Start HardwareStatus Thread Failed");
  1256. return false;
  1257. }
  1258. }
  1259. return true;
  1260. }
  1261. DWORD nsGEN::CPIDevice::HardwareStatusThread(LPVOID pParam)
  1262. {
  1263. CPIDevice* pCurGen = (CPIDevice*)pParam;
  1264. if (pCurGen == NULL)
  1265. {
  1266. return false;
  1267. }
  1268. mLog::Info("HardwareStatusThread start");
  1269. while (true)
  1270. {
  1271. Sleep(2000);
  1272. pCurGen->HWSend("HE?");
  1273. static int cnt = 0;
  1274. if (pCurGen->m_bCheckATUStatus)
  1275. {
  1276. cnt++;
  1277. if (cnt == 10)
  1278. {
  1279. pCurGen->HWSend("ATU?");
  1280. cnt = 0;
  1281. }
  1282. }
  1283. else
  1284. {
  1285. cnt = 0;
  1286. }
  1287. }
  1288. mLog::Info("HardwareStatusThread stop");
  1289. return true;
  1290. }
  1291. //-----------------------------------------------------------------------------
  1292. // CPIDriver
  1293. //-----------------------------------------------------------------------------
  1294. nsGEN::CPIDriver::CPIDriver()
  1295. {
  1296. m_bDemoConnected = false;
  1297. m_pDriGenDev = nullptr;
  1298. m_pDriCollDev = nullptr;
  1299. m_pDriDapDev = nullptr;
  1300. m_pAttribute.reset(new ResDataObject());
  1301. m_pDescription.reset(new ResDataObject());
  1302. }
  1303. nsGEN::CPIDriver::~CPIDriver()
  1304. {
  1305. }
  1306. auto nsGEN::CPIDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  1307. {
  1308. if (!m_SCF.isConnected())
  1309. return nullptr;
  1310. // auto dev = std::unique_ptr <IODevice>(new IODevice(new CPIDevice(EventCenter, m_SCF, m_ConfigFileName)));
  1311. if (index == 0)
  1312. {
  1313. m_pDriGenDev = new CPIDevice(EventCenter, m_SCF, m_ConfigFileName);
  1314. auto dev = std::unique_ptr<IODevice>(new IODevice(m_pDriGenDev));
  1315. return dev;
  1316. }
  1317. else if (index == 1)
  1318. {
  1319. mLog::Info("Enter CreateDevice COLL");
  1320. m_pDriCollDev = new OemCollimator(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
  1321. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriCollDev));
  1322. m_pDriCollDev->SetCtrlDev(m_pDriGenDev);
  1323. m_pDriGenDev->SetCollimatorDev(m_pDriCollDev);
  1324. mLog::Info("Leave CreateDevice COLL");
  1325. return dev;
  1326. }
  1327. //else if (index == 2) //------------------------------因为改发生器没有关于机架的信息,所以此处不必创建机架设备的对象
  1328. //{
  1329. // mLog::Info("Enter CreateDevice Mech");
  1330. // m_pDriMechDev = new OemMechanical(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
  1331. // auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriMechDev));
  1332. // m_pDriMechDev->SetCtrlDev(m_pDriGenDev);
  1333. // m_pDriGenDev->SetMechDev(m_pDriMechDev);
  1334. // mLog::Info("Leave CreateDevice Mech");
  1335. // return dev;
  1336. //}
  1337. else if (index == 2)//----------------------------------maybe DAP设备也不是必须的
  1338. {
  1339. mLog::Info("Enter CreateDevice DAP");
  1340. m_pDriDapDev = new OemDap(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
  1341. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriDapDev));
  1342. m_pDriDapDev->SetCtrlDev(m_pDriGenDev);
  1343. m_pDriGenDev->SetDapDev(m_pDriDapDev);
  1344. mLog::Info("Leave CreateDevice DAP");
  1345. return dev;
  1346. }
  1347. }
  1348. void nsGEN::CPIDriver::FireNotify(int code, std::string key, std::string content)
  1349. {
  1350. EventCenter->OnNotify(code, key, content);
  1351. }
  1352. Log4CPP::Logger* mLog::gLogger = nullptr;
  1353. void nsGEN::CPIDriver::Prepare()
  1354. {
  1355. string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
  1356. //Log4CPP::ThreadContext::Map::Set("LogFileName", "GEN.CPI");
  1357. Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.CPI");
  1358. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  1359. mLog::gLogger = Log4CPP::LogManager::GetLogger("GEN.CPI");
  1360. m_SCFDllName = GetConnectDLL(m_ConfigFileName);
  1361. super::Prepare();
  1362. }
  1363. bool DATA_ACTION nsGEN::CPIDriver::Connect()
  1364. {
  1365. ResDataObject Connection = GetConnectParam(m_ConfigFileName);
  1366. mLog::Info("connections:{$} \n", Connection.encode());
  1367. auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::CPIDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  1368. if (erCode != SCF_ERR::SCF_SUCCEED)
  1369. return false;
  1370. auto rc = super::Connect();
  1371. if (!rc)
  1372. return false;
  1373. //return (erCode == SCF_ERR::SCF_SUCCEED);
  1374. return true;
  1375. }
  1376. void nsGEN::CPIDriver::Disconnect()
  1377. {
  1378. super::Disconnect();
  1379. m_SCF.Disconnect();
  1380. m_bDemoConnected = false;
  1381. }
  1382. bool nsGEN::CPIDriver::isConnected() const
  1383. {
  1384. return super::isConnected();
  1385. }
  1386. std::string nsGEN::CPIDriver::DriverProbe()
  1387. {
  1388. ResDataObject r_config, HardwareInfo;
  1389. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1390. {
  1391. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  1392. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  1393. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  1394. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  1395. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  1396. }
  1397. else
  1398. {
  1399. HardwareInfo.add("MajorID", "Generator");
  1400. HardwareInfo.add("MinorID", "Dr");
  1401. HardwareInfo.add("VendorID", "CPI");
  1402. HardwareInfo.add("ProductID", "HF");
  1403. HardwareInfo.add("SerialID", "Drv");
  1404. }
  1405. string ret = HardwareInfo.encode();
  1406. return ret;
  1407. }
  1408. std::string nsGEN::CPIDriver::DeviceProbe()
  1409. {
  1410. ResDataObject r_config, HardwareInfo;
  1411. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1412. {
  1413. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  1414. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  1415. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  1416. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  1417. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  1418. }
  1419. else
  1420. {
  1421. HardwareInfo.add("MajorID", "Generator");
  1422. HardwareInfo.add("MinorID", "Dr");
  1423. HardwareInfo.add("VendorID", "CPI");
  1424. HardwareInfo.add("ProductID", "HF");
  1425. HardwareInfo.add("SerialID", "Drv");
  1426. }
  1427. string ret = HardwareInfo.encode();
  1428. return ret;
  1429. }
  1430. bool nsGEN::CPIDriver::GetDeviceConfig(std::string& Cfg)
  1431. {
  1432. Cfg = m_DeviceConfigSend.encode();
  1433. //printf("GetDeviceConfig over");
  1434. printf("GetDeviceConfig over , %s", Cfg.c_str());
  1435. return true;
  1436. }
  1437. bool nsGEN::CPIDriver::SetDeviceConfig(std::string Cfg)
  1438. {
  1439. mLog::Info("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  1440. ResDataObject DeviceConfig;
  1441. DeviceConfig.decode(Cfg.c_str());
  1442. ResDataObject DescriptionTempEx;
  1443. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  1444. mLog::Debug("Attribute:{$}", DescriptionTempEx.encode());
  1445. bool bSaveFile = false; //true:重新保存配置文件
  1446. string strAccess = "";
  1447. for (int i = 0; i < DescriptionTempEx.size(); i++)
  1448. {
  1449. string strKey = DescriptionTempEx.GetKey(i);
  1450. mLog::Info("{$}", strKey.c_str());
  1451. try
  1452. {
  1453. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  1454. {
  1455. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  1456. if ("RW" == strAccess)
  1457. {
  1458. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  1459. //1. 修改内存中的值,用于给上层发消息
  1460. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  1461. //2. 拿到Innerkey
  1462. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1463. mLog::Info("nConfigInfoCount {$}", nConfigInfoCount);
  1464. string strTemp = ""; //存储AttributeKey
  1465. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1466. {
  1467. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1468. if (strTemp == strKey)
  1469. {
  1470. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1471. break;
  1472. }
  1473. }
  1474. //3. 修改配置文件中的值
  1475. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  1476. {
  1477. mLog::Debug("SetDeviceConfigValue over");
  1478. bSaveFile = true;
  1479. }
  1480. }
  1481. else
  1482. {
  1483. mLog::Info("{$} is not a RW configuration item", strKey.c_str());
  1484. }
  1485. }
  1486. else
  1487. {
  1488. mLog::Info("without this attribute {$}", strKey.c_str());
  1489. }
  1490. }
  1491. catch (ResDataObjectExption& e)
  1492. {
  1493. mLog::Error("SetDriverConfig crashed: {$}", e.what());
  1494. return false;
  1495. }
  1496. }
  1497. if (bSaveFile)
  1498. {
  1499. //3. 重新保存配置文件
  1500. SaveConfigFile(true);
  1501. }
  1502. return true;
  1503. }
  1504. bool nsGEN::CPIDriver::SaveConfigFile(bool bSendNotify)
  1505. {
  1506. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  1507. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  1508. mLog::Info("SaveConfigFile over {$}", bRt);
  1509. return true;
  1510. }
  1511. bool nsGEN::CPIDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  1512. {
  1513. strValue = "";
  1514. string strTemp = pInnerKey;
  1515. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  1516. {
  1517. int pos = 0;
  1518. ResDataObject resTemp = config;
  1519. while ((pos = strTemp.find_first_of(',')) != string::npos)
  1520. {
  1521. string Key = strTemp.substr(0, pos);
  1522. string TempValue = resTemp[Key.c_str()].encode();
  1523. // printf("-TempValue=== %s", TempValue.c_str());
  1524. resTemp.clear();
  1525. resTemp.decode(TempValue.c_str());
  1526. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  1527. //printf("-************--%s", strTemp.c_str());
  1528. }
  1529. if (strTemp != "")
  1530. {
  1531. strValue = (string)resTemp[strTemp.c_str()];
  1532. }
  1533. else
  1534. {
  1535. strValue = (string)resTemp;
  1536. }
  1537. }
  1538. //printf("------------%s", strValue.c_str());
  1539. return true;
  1540. }
  1541. bool nsGEN::CPIDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  1542. {
  1543. string strTemp = pInnerKey;
  1544. mLog::Debug("Begin to change {$} item value to {$}", pInnerKey, szValue);
  1545. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  1546. {
  1547. try {
  1548. int pos = 0;
  1549. ResDataObject* resTemp = &config;
  1550. while ((pos = strTemp.find_first_of(',')) != string::npos)
  1551. {
  1552. string Key = strTemp.substr(0, pos);
  1553. resTemp = &(*resTemp)[Key.c_str()];
  1554. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  1555. }
  1556. if (strTemp != "")
  1557. {
  1558. (*resTemp)[strTemp.c_str()] = szValue;
  1559. //if ((strTemp.compare("WSTable") == 0) ||
  1560. // (strTemp.compare("WSWall") == 0) ||
  1561. // (strTemp.compare("WSFree") == 0) ||
  1562. // (strTemp.compare("WSTomo") == 0) ||
  1563. // (strTemp.compare("WSConventional") == 0)
  1564. // )
  1565. //{
  1566. // int sum = (*szValue) + 1;
  1567. // (*resTemp)[strTemp.c_str()] = (char*)(&sum);
  1568. //}
  1569. //else
  1570. // (*resTemp)[strTemp.c_str()] = szValue;
  1571. }
  1572. else
  1573. {
  1574. *resTemp = szValue;
  1575. }
  1576. }
  1577. catch (ResDataObjectExption& e)
  1578. {
  1579. mLog::Error("SetDriverConfigvalue crashed: {$}", e.what());
  1580. return false;
  1581. }
  1582. }
  1583. return true;
  1584. }
  1585. std::string nsGEN::CPIDriver::GetResource()
  1586. {
  1587. ResDataObject r_config, temp;
  1588. if (!temp.loadFile(m_ConfigFileName.c_str()))
  1589. {
  1590. return "";
  1591. }
  1592. m_ConfigAll = temp;
  1593. r_config = temp["CONFIGURATION"];
  1594. m_Configurations = r_config;
  1595. ResDataObject DescriptionTemp;
  1596. ResDataObject DescriptionSend;
  1597. ResDataObject m_DescriptionSend;
  1598. ResDataObject ListTemp;
  1599. string strTemp = ""; //用于读取字符串配置信息
  1600. string strIndex = ""; //用于读取配置信息中的List项
  1601. int nTemp = -1; //用于读取整型配置信息
  1602. char sstream[10] = { 0 }; //用于转换值
  1603. string strValue = ""; //用于存储配置的值
  1604. string strType = ""; //用于存储配置的类型 int/float/string...
  1605. /***
  1606. * 1. 通过循环,将所有配置项写到pDeviceConfig
  1607. * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
  1608. ***/
  1609. try
  1610. {
  1611. //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
  1612. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1613. m_pAttribute->clear();
  1614. m_pDescription->clear();
  1615. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1616. {
  1617. DescriptionTemp.clear();
  1618. DescriptionSend.clear();
  1619. ListTemp.clear();
  1620. //AttributeType
  1621. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  1622. DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  1623. DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  1624. strType = strTemp; //记录配置项的类型
  1625. //AttributeKey
  1626. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  1627. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1628. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  1629. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
  1630. //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  1631. //2. 赋值
  1632. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1633. if ("int" == strType)
  1634. {
  1635. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1636. }
  1637. else if ("float" == strType)
  1638. {
  1639. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1640. }
  1641. else //其它先按string类型处理
  1642. {
  1643. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  1644. }
  1645. //printf("********************************outkey =%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  1646. //AttributeAccess
  1647. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  1648. DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
  1649. DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
  1650. /*
  1651. //AttributeRangeMin
  1652. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  1653. if (strTemp != "") //不需要的配置项为空
  1654. {
  1655. DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
  1656. }
  1657. //AttributeRangeMax
  1658. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  1659. if (strTemp != "") //不需要的配置项为空
  1660. {
  1661. DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
  1662. }
  1663. */
  1664. //AttributeList
  1665. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  1666. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  1667. {
  1668. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  1669. {
  1670. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  1671. auto temKey = std::to_string(nListIndex);
  1672. ListTemp.add(temKey.c_str(), strTemp.c_str());
  1673. }
  1674. DescriptionTemp.add(ConfKey::CcosList, ListTemp);
  1675. DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
  1676. }
  1677. //AttributeRequired
  1678. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  1679. DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
  1680. DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
  1681. //AttributeDefaultValue
  1682. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  1683. if (strTemp != "") //不需要的配置项为空
  1684. {
  1685. DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  1686. DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  1687. }
  1688. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1689. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  1690. m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
  1691. }
  1692. }
  1693. catch (ResDataObjectExption& e)
  1694. {
  1695. mLog::Error("Get config error: {$}", e.what());
  1696. return "";
  1697. }
  1698. ResDataObject resDeviceResource;
  1699. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  1700. resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
  1701. ResDataObject DescriptionTempEx;
  1702. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  1703. m_DeviceConfig.clear();
  1704. m_DeviceConfig = DescriptionTempEx;
  1705. mLog::Error("local ************* get resource over {$}", DescriptionTempEx.encode());
  1706. printf("local ************* get resource over %s \n", DescriptionTempEx.encode());
  1707. resDeviceResource.clear();
  1708. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  1709. resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
  1710. DescriptionTempEx.clear();
  1711. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  1712. m_DeviceConfigSend.clear();
  1713. m_DeviceConfigSend = DescriptionTempEx;
  1714. string res = m_DeviceConfigSend.encode();
  1715. //printf("%s", res.c_str());
  1716. mLog::Debug("get resource over {$}", DescriptionTempEx.encode());
  1717. printf("************* get resource over %s \n", DescriptionTempEx.encode());
  1718. return res;
  1719. }
  1720. void nsGEN::CPIDriver::Dequeue(const char* Packet, DWORD Length)
  1721. {
  1722. DecodeFrame(Packet, Length);
  1723. }
  1724. PACKET_RET nsGEN::CPIDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
  1725. {
  1726. if (nLength < 1)
  1727. {
  1728. printf("nLength < 1, nLength==%d \n", nLength);
  1729. mLog::Info("nLength < 1, nLength=={$} \n", nLength);
  1730. return PACKET_USELESS;
  1731. }
  1732. for (DWORD i = 0; i < nLength - 1; i++)
  1733. {
  1734. //1 首先寻找包头
  1735. if (RecData[i]==0x02)
  1736. {
  1737. if (i!=0)
  1738. {
  1739. PacketLength = i; //i之前的数据,全部扔掉
  1740. char strtemp[100] = { 0 };
  1741. memcpy(strtemp, RecData, i);
  1742. strtemp[PacketLength + 1] = 0;
  1743. printf("==IN error data ==:%s,PacketLength=%d,nLength=%d\n", strtemp, PacketLength, nLength);
  1744. //for test
  1745. //for (int j = 0; j < nLength; j++)
  1746. //{
  1747. // printf("%2X,", RecData[j]);
  1748. //}
  1749. //printf("\n");
  1750. return PACKET_USELESS;
  1751. }
  1752. }
  1753. if (RecData[i] == 0x03)
  1754. {
  1755. PacketLength = i + 2; //+2 because index + ETX + sum.
  1756. char strtemp[100] = { 0 };
  1757. memcpy(strtemp, RecData, i); //RKC005(not include 03 + sum); //only 复制 0x03之前的数据,这样解析时,后面的03 ,sum 都不要了。
  1758. strtemp[PacketLength + 1] = 0;
  1759. printf("==IN==:%s\n", strtemp);
  1760. mLog::Info("==IN==:{$}\n", strtemp);
  1761. return PACKET_ISPACKET;
  1762. }
  1763. }
  1764. return PACKET_NOPACKET;
  1765. }
  1766. //-----------------------------------------------------------------------------
  1767. // DecodeFrame
  1768. //-----------------------------------------------------------------------------
  1769. static bool DecodeFrame(const char* strFrame, int length)
  1770. {
  1771. auto pr = [strFrame, length](const tFrameMapping& Item)
  1772. {
  1773. for (int i = 0; i < Item.NbOfCharOfHead; i++)
  1774. {
  1775. if (strFrame[i] != Item.strHead[i])
  1776. {
  1777. return false;
  1778. }
  1779. }
  1780. return true;
  1781. };
  1782. auto found = std::find_if(arFrame.begin(), arFrame.end(), pr);//此处pr,是上面定义的 lambda表达式,用来在list中找到对于的包头。
  1783. if (found == arFrame.end())
  1784. {
  1785. return false;
  1786. }
  1787. const auto& Item = *found;
  1788. auto pc = strFrame;
  1789. char data[100] = { 0 };
  1790. memcpy(data, strFrame + Item.NbOfCharOfHead, length - Item.NbOfCharOfHead);
  1791. Item.fun(data, length - Item.NbOfCharOfHead);//第二个参数 不重要
  1792. return true;
  1793. }
  1794. //-----------------------------------------------------------------------------
  1795. // GetIODriver & CreateIODriver
  1796. //-----------------------------------------------------------------------------
  1797. static nsGEN::CPIDriver gIODriver;
  1798. extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  1799. {
  1800. return &gIODriver;
  1801. }
  1802. extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  1803. {
  1804. return new nsGEN::CPIDriver();
  1805. }