DIOS.Dev.Generator.REMEDY.cpp 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430
  1. // CCOS.Dev.GEN.REMEDY.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. #include "stdafx.h"
  4. #include <assert.h>
  5. #include <functional>
  6. #include "LogicDevice.h"
  7. #include "CCOS.Dev.Generator.REMEDY.h"
  8. #include "Helper.JSON.hpp"
  9. #include <unordered_map>
  10. #include <fstream>
  11. #include <set>
  12. using namespace std::placeholders;
  13. using namespace CCOS::Dev::Detail::Generator;
  14. namespace nsGEN = CCOS::Dev::Detail::Generator;
  15. #pragma warning (disable:4244)
  16. #pragma warning (disable:4305)
  17. #pragma warning (disable:4267)
  18. static const int msTimeOut_Lock = 500;
  19. #ifdef _WIN64
  20. #ifdef _DEBUG
  21. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64D.dll";
  22. #else
  23. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64.dll";
  24. #endif
  25. #endif
  26. #ifdef _WIN64
  27. #ifdef _DEBUG
  28. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64D.dll";
  29. #else
  30. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64.dll";
  31. #endif
  32. #endif
  33. //-----------------------------------------------------------------------------
  34. // REMEDYDevice
  35. //-----------------------------------------------------------------------------
  36. 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 };
  37. 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 };
  38. 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 };
  39. atomic<int> nsGEN::REMEDYDevice::m_iLoopTime = REMEDY_LoopDefTime;
  40. string GetProcessDirectory()
  41. {
  42. string ret = "";
  43. char szFilename[MAX_PATH] = { 0 };
  44. DWORD res = GetModuleFileNameA(0, szFilename, MAX_PATH);
  45. if (res == 0)
  46. {
  47. return ret;
  48. }
  49. string fullpath = szFilename;
  50. string::size_type firstHit = fullpath.find_last_of('\\');
  51. if (firstHit == string::npos || firstHit == 0)
  52. {
  53. return ret;
  54. }
  55. ret = fullpath.substr(0, firstHit);//kick last \
  56. return ret;
  57. }
  58. nsGEN::REMEDYDevice::REMEDYDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF, string configfile) : super(center, SCF)
  59. {
  60. assert(EventCenter);
  61. string version;
  62. if (GetVersion(version, hMyModule))
  63. FINFO("\n===============log begin : version:{$} ===================\n", version.c_str());
  64. else
  65. FINFO("\n===============log begin : version:0.0.0.0 ===================\n");
  66. m_DoseUnit.m_KV.reset(new KVMould(0.0, 40.0, 120.0, 1.0));
  67. m_DoseUnit.m_MA.reset(new MAMould(0.0, 0.1, 1000.0, 0.1));
  68. m_DoseUnit.m_MS.reset(new MSMould(0.0, 0.1, 10000.0, 0.01));
  69. m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.1, 1000.0, 0.01));
  70. m_DoseUnit.m_Techmode.reset(new TECHMODEMould(0, 0, 2, 1));
  71. m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
  72. m_DoseUnit.m_Focus.reset(new FOCUSMould(1, 0, 1, 1));
  73. m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
  74. m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
  75. m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
  76. m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
  77. m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 40.0, 120.0, 1.0));
  78. m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 10.0, 1000.0, 0.1));
  79. m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 1.0, 10000.0, 0.01));
  80. m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.5, 1000.0, 0.01));
  81. m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(0, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
  82. m_DoseUnit.m_GenState.reset(new GENSTATEMould(0, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
  83. m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
  84. m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
  85. m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
  86. m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
  87. m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
  88. m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single));
  89. m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 16, 1));
  90. m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
  91. m_DAP.reset(new DevDAP::DOSEMould(0.0, 0.0, 1000.0, 0.01));
  92. m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
  93. m_DoseUnit.m_FLIntTime.reset(new FLUIntTimeMould(0.0, 0.0, 100.0, 0.1));
  94. m_DoseUnit.m_FLAccTime.reset(new FLAccTimeMould(0.0, 0.0, 999.0, 0.1));
  95. m_DoseUnit.m_FLKV.reset(new FLUKVMould(0, 40, 125, 1));
  96. m_DoseUnit.m_FLMS.reset(new FLUMSMould(10.0, 10.0, 999999.0, 0.01));
  97. m_DoseUnit.m_FLMA.reset(new FLUMAMould(0.5, 0.5, 99.0, 0.1));
  98. m_DoseUnit.m_ABSStatus.reset(new FLUABSStatusMould(0, 0, 2, 1));
  99. m_DoseUnit.m_PPS.reset(new PPSMould(0.5, 0.5, 30, 0.1));
  100. m_DoseUnit.m_DoseLevel.reset(new FLUDoseLevelMould(0, 0, 2, 1));
  101. m_DoseUnit.m_Curve.reset(new FLUCurveMould(0, 0, 3, 1));
  102. m_hGenPostEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  103. string strErrConfig = GetProcessDirectory() + R"(\OEMDrivers\Generator\REMEDY\REMEDY_RF\ErrorWarnInfo.json)";
  104. m_DeviceErrorHandler.reset(new DeviceErrorHandler(center, nsGEN::GeneratorUnitType, strErrConfig));
  105. m_pHardwareStatusThread = NULL;
  106. m_pTrueParameterThread = NULL;
  107. m_strConfigPath = configfile;
  108. m_DoseUnit.m_FLAccTimeUnit = "m";
  109. m_bisNotDirectConnection = false;
  110. m_nReturnTime = 0;
  111. m_bMasR20 = 1;
  112. m_bUseEAcmd = 0;
  113. m_bResetActive = false;
  114. m_bIsConfigLoaded = false;
  115. OnCallBack();
  116. Register();
  117. HWSend("RE");
  118. Sleep(30);
  119. HWSend("WS1");
  120. Sleep(30);
  121. HWSend("FLA0");
  122. StartHardwareStatusThread();
  123. }
  124. nsGEN::REMEDYDevice::~REMEDYDevice()
  125. {
  126. CloseHandle(m_hGenPostEvent);
  127. }
  128. std::string nsGEN::REMEDYDevice::GetGUID() const
  129. {
  130. FINFO("\n===============GetGUID : {$} ===================\n", GeneratorUnitType);
  131. return GeneratorUnitType;
  132. }
  133. void nsGEN::REMEDYDevice::Register()
  134. {
  135. auto Disp = &Dispatch;
  136. superGen::Register(Disp);
  137. superGen::RegisterRAD(Disp);
  138. superGen::RegisterAEC(Disp);
  139. superGen::RegisterExpEnable(Disp);
  140. superGen::RegisterGeneratortoSyncStatus(Disp);
  141. superGen::RegisterFluoro(Disp);
  142. Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  143. auto fun_Clear_DAP = [this](auto a, auto&)
  144. {
  145. return Clear_DAP();
  146. };
  147. Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
  148. auto fun_GetValue_DAP = [this](auto a, auto& b)
  149. {
  150. float value = 0;
  151. RET_STATUS ret = GetValue_DAP(value);
  152. b = ToJSON(value);
  153. return ret;
  154. };
  155. Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
  156. auto fun_StartMove = [this](auto a,auto& b)
  157. {
  158. return StartMove();
  159. };
  160. Disp->Action.Push("StartMove", fun_StartMove);
  161. auto fun_EndMove = [this](auto a, auto& b)
  162. {
  163. return EndMove();
  164. };
  165. Disp->Action.Push("EndMove", fun_EndMove);
  166. }
  167. RET_STATUS nsGEN::REMEDYDevice::IncKV()
  168. {
  169. FINFO("KV value before calling IncKV: {$}\n", m_DoseUnit.m_KV->JSGet().c_str());
  170. if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
  171. return HWSend("KV+");
  172. }
  173. RET_STATUS nsGEN::REMEDYDevice::DecKV()
  174. {
  175. FINFO("KV value before calling DecKV: {$}\n", m_DoseUnit.m_KV->JSGet().c_str());
  176. if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
  177. return HWSend("KV-");
  178. }
  179. RET_STATUS nsGEN::REMEDYDevice::SetKV(float value)
  180. {
  181. FINFO("KV value before calling SetKV: {$}\n", m_DoseUnit.m_KV->JSGet().c_str());
  182. if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
  183. char temp[50] = { 0 };
  184. sprintf_s(temp, "KV%03d", (int)value);
  185. return HWSend(temp);
  186. }
  187. RET_STATUS nsGEN::REMEDYDevice::IncMA()
  188. {
  189. FINFO("MA value before calling IncMA: {$}\n", m_DoseUnit.m_MA->JSGet().c_str());
  190. if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
  191. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  192. {
  193. FINFO("\n Techmode is MAS, can't inc MA");
  194. return RET_STATUS::RET_FAILED;
  195. }
  196. return HWSend("MA+");
  197. }
  198. RET_STATUS nsGEN::REMEDYDevice::DecMA()
  199. {
  200. FINFO("MA value before calling DecMA: {$}\n", m_DoseUnit.m_MA->JSGet().c_str());
  201. if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
  202. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  203. {
  204. FINFO("\n Techmode is MAS, can't dec MA");
  205. return RET_STATUS::RET_FAILED;
  206. }
  207. return HWSend("MA-");
  208. }
  209. RET_STATUS nsGEN::REMEDYDevice::SetMA(float value)
  210. {
  211. FINFO("MA value before calling SetMA: {$}\n", m_DoseUnit.m_MA->JSGet().c_str());
  212. if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  213. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  214. {
  215. FINFO("\n Techmode is MAS, can't set MA");
  216. return RET_STATUS::RET_FAILED;
  217. }
  218. char temp[50] = { 0 };
  219. sprintf_s(temp, "MA%05d", (int)(value * 10));
  220. return HWSend(temp);
  221. }
  222. RET_STATUS nsGEN::REMEDYDevice::IncMS()
  223. {
  224. FINFO("MS value before calling IncMS: {$}\n", m_DoseUnit.m_MS->JSGet().c_str());
  225. if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
  226. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  227. {
  228. FINFO("\n Techmode is MAS, can't inc MS");
  229. return RET_STATUS::RET_FAILED;
  230. }
  231. return HWSend("MS+");
  232. }
  233. RET_STATUS nsGEN::REMEDYDevice::DecMS()
  234. {
  235. FINFO("MS value before calling DecMS: {$}\n", m_DoseUnit.m_MS->JSGet().c_str());
  236. if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
  237. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  238. {
  239. FINFO("\n Techmode is MAS, can't dec MS");
  240. return RET_STATUS::RET_FAILED;
  241. }
  242. return HWSend("MS-");
  243. }
  244. RET_STATUS nsGEN::REMEDYDevice::SetMS(float value)
  245. {
  246. FINFO("MS value before calling SetMS: {$}\n", m_DoseUnit.m_MS->JSGet().c_str());
  247. if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  248. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  249. {
  250. FINFO("\n Techmode is MAS, can't set MS");
  251. return RET_STATUS::RET_FAILED;
  252. }
  253. char temp[50] { 0 };
  254. sprintf_s(temp, "MS%05d", (int)(value * 10));
  255. return HWSend(temp);
  256. }
  257. RET_STATUS nsGEN::REMEDYDevice::IncMAS()
  258. {
  259. FINFO("MAS value before calling IncMAS: {$}\n", m_DoseUnit.m_MAS->JSGet().c_str());
  260. if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
  261. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  262. {
  263. FINFO("\n Techmode is not MAS, can't inc MAS");
  264. return RET_STATUS::RET_FAILED;
  265. }
  266. return HWSend("MX+");
  267. }
  268. RET_STATUS nsGEN::REMEDYDevice::DecMAS()
  269. {
  270. FINFO("MAS value before calling DecMAS: {$}\n", m_DoseUnit.m_MAS->JSGet().c_str());
  271. if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
  272. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  273. {
  274. FINFO("\n Techmode is not MAS, can't dec MAS");
  275. return RET_STATUS::RET_FAILED;
  276. }
  277. return HWSend("MX-");
  278. }
  279. RET_STATUS nsGEN::REMEDYDevice::SetMAS(float value)
  280. {
  281. FINFO("MAS value before calling SetMAS: {$}\n", m_DoseUnit.m_MAS->JSGet().c_str());
  282. if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  283. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  284. {
  285. FINFO("\n Techmode is not MAS, can't set MAS");
  286. return RET_STATUS::RET_FAILED;
  287. }
  288. char temp[50] = { 0 };
  289. if (m_bMasR20)
  290. {
  291. sprintf_s(temp, "MX%06d", (int)(value * 100));
  292. }
  293. else
  294. {
  295. sprintf_s(temp, "MX%05d", (int)(value * 10));
  296. }
  297. return HWSend(temp);
  298. }
  299. RET_STATUS nsGEN::REMEDYDevice::SetTechmode(int value)
  300. {
  301. FINFO("Techmode value before calling SetTechmode: {$}\n", m_DoseUnit.m_Techmode->JSGet().c_str());
  302. if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
  303. //if (value == AttrKey::TECHMODE_V2TYPE::ET_AEC)//if AEC, translate to time. why? i need reason.
  304. // value = AttrKey::TECHMODE_V2TYPE::ET_TIME;
  305. char temp[50] = { 0 };
  306. sprintf_s(temp, "ET%01d", (int)value);
  307. return HWSend(temp);
  308. }
  309. RET_STATUS nsGEN::REMEDYDevice::SetFocus(int value)
  310. {
  311. FINFO("Focus value before calling SetFocus: {$}\n", m_DoseUnit.m_Focus->JSGet().c_str());
  312. if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
  313. char temp[50] = { 0 };
  314. sprintf_s(temp, "FO%01d", (int)value);
  315. return HWSend(temp);
  316. }
  317. RET_STATUS nsGEN::REMEDYDevice::SetAECDensity(int value)
  318. {
  319. if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED;
  320. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
  321. return RET_STATUS::RET_FAILED;
  322. char temp[50] = { 0 };
  323. if (value >= 0)
  324. {
  325. sprintf_s(temp, "FN+%01d", (int)value);
  326. }
  327. else
  328. {
  329. sprintf_s(temp, "FN-%01d", (int)value);
  330. }
  331. return HWSend(temp);
  332. }
  333. RET_STATUS nsGEN::REMEDYDevice::SetAECField(int value)
  334. {
  335. if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
  336. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
  337. return RET_STATUS::RET_FAILED;
  338. char temp[50] = { 0 };
  339. sprintf_s(temp, "FI%03d", (int)value);
  340. return HWSend(temp);
  341. }
  342. RET_STATUS nsGEN::REMEDYDevice::SetAECFilm(int value)
  343. {
  344. if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
  345. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
  346. return RET_STATUS::RET_FAILED;
  347. char temp[50] = { 0 };
  348. sprintf_s(temp, "FS%03d", (int)value);
  349. return HWSend(temp);
  350. }
  351. RET_STATUS nsGEN::REMEDYDevice::SetWS(const string value)
  352. {
  353. int tempws = 0;
  354. if (value == "Table") tempws = (int)m_GenConfig["WSTable"];
  355. else if (value == "Wall") tempws = (int)m_GenConfig["WSWall"];
  356. else if (value == "Direct") tempws = (int)m_GenConfig["WSConventional"];
  357. else if (value == "Free") tempws = (int)m_GenConfig["WSFree"];
  358. else if (value == "Tomo") tempws = (int)m_GenConfig["WSTomo"];
  359. char temp[50] = { 0 };
  360. sprintf_s(temp, "WS%01d", tempws);
  361. return HWSend(temp);
  362. }
  363. string nsGEN::REMEDYDevice::WSUI2Gen(int nUIWS)
  364. {
  365. string strWS = "";
  366. try
  367. {
  368. if (nUIWS == AttrKey::GENWS_TYPE::TABLE) //lying: cross mode
  369. {
  370. strWS = m_GenConfig["WSTable"].encode();
  371. }
  372. else if (nUIWS == AttrKey::GENWS_TYPE::WALL) //standing mode
  373. {
  374. strWS = m_GenConfig["WSWall"].encode();
  375. }
  376. else if (nUIWS == AttrKey::GENWS_TYPE::FREE_TABLE) //standing mode
  377. {
  378. strWS = m_GenConfig["WSFree"].encode();
  379. }
  380. else if (nUIWS == AttrKey::GENWS_TYPE::TOMO) //standing mode
  381. {
  382. strWS = m_GenConfig["WSTOMO"].encode();
  383. }
  384. else if (nUIWS == AttrKey::GENWS_TYPE::CONVENTIONAL) //standing mode
  385. {
  386. strWS = m_GenConfig["WSConventional"].encode();
  387. }
  388. }
  389. catch (ResDataObjectExption& exp)
  390. {
  391. FERROR("Get configuration failed, {$}\n", exp.what());
  392. }
  393. FINFO("Set WS: {$},Generator workstaion: {$}\n", nUIWS, strWS);
  394. if (strWS == "")
  395. {
  396. strWS = "Table";
  397. }
  398. return strWS;
  399. }
  400. RET_STATUS nsGEN::REMEDYDevice::SetAPR(const _tAPRArgs& t)
  401. {
  402. m_t = t;
  403. FINFO("*********************Enter SetAPR*********************");
  404. FINFO("t.ws={$},t.fKV={$},t.fMA={$},t.fMAS={$},t.nAECDensity={$},t.nAECField={$},t.nAECFilm={$},t.nFocus={$},t.nTechmode={$}", t.nWS,t.fKV, t.fMA, t.fMAS, t.nAECDensity, t.nAECField, t.nAECFilm, t.nFocus, t.nTechmode);
  405. //2
  406. SetKV(t.fKV);
  407. //3
  408. SetFocus(t.nFocus);
  409. //4
  410. if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_AEC)//aec
  411. {
  412. SetTechmode(t.nTechmode);
  413. SetAECField(t.nAECField);
  414. SetAECDensity(t.nAECDensity);
  415. SetMA(t.fMA);
  416. SetMS(t.fMS);
  417. }
  418. else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)//2p
  419. {
  420. SetTechmode(t.nTechmode);
  421. const float EPSINON = 0.000001;
  422. SetMAS(t.fMAS);
  423. }
  424. else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_TIME)//3p
  425. {
  426. SetTechmode(t.nTechmode);
  427. SetMA(t.fMA);
  428. SetMS(t.fMS);
  429. }
  430. HWSend("RR");
  431. FINFO("*********************Leave SetAPR*********************");
  432. return RET_STATUS::RET_SUCCEED;
  433. }
  434. RET_STATUS nsGEN::REMEDYDevice::QueryHE(int& value)
  435. {
  436. return HWSend("HE?");
  437. }
  438. RET_STATUS nsGEN::REMEDYDevice::QueryPostKV(float& value)
  439. {
  440. m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
  441. value = m_DoseUnit.m_PostKV->Get();
  442. return HWSend("AP?");
  443. return RET_STATUS::RET_SUCCEED;
  444. }
  445. RET_STATUS nsGEN::REMEDYDevice::QueryPostMA(float& value)
  446. {
  447. return HWSend("AP?");
  448. }
  449. RET_STATUS nsGEN::REMEDYDevice::QueryPostMS(float& value)
  450. {
  451. return HWSend("AT?");
  452. }
  453. RET_STATUS nsGEN::REMEDYDevice::QueryPostMAS(float& value)
  454. {
  455. value = m_DoseUnit.m_PostMAS->Get();
  456. return RET_STATUS::RET_SUCCEED;
  457. }
  458. RET_STATUS nsGEN::REMEDYDevice::Clear_DAP()
  459. {
  460. if (m_bDAPEnable)
  461. {
  462. return HWSend("DZ");
  463. }
  464. return RET_STATUS::RET_SUCCEED;
  465. }
  466. RET_STATUS nsGEN::REMEDYDevice::GetValue_DAP(float& value)
  467. {
  468. if (m_bDAPEnable)
  469. {
  470. HWSend("DA");
  471. Sleep(300); //wait 300ms to get real dap value.
  472. value = m_DAP->Get();
  473. }
  474. return RET_STATUS::RET_SUCCEED;
  475. }
  476. RET_STATUS nsGEN::REMEDYDevice::StartMove()
  477. {
  478. FINFO("Enter startMove");
  479. FINFO("end startmove");
  480. return RET_STATUS::RET_SUCCEED;
  481. }
  482. RET_STATUS nsGEN::REMEDYDevice::EndMove()
  483. {
  484. FINFO("Enter endmove");
  485. FINFO("end EndMove");
  486. return RET_STATUS::RET_SUCCEED;
  487. }
  488. RET_STATUS nsGEN::REMEDYDevice::SetGenSynState(int value)
  489. {
  490. FINFO("Enter SetGenSynState...{$} \n", value);
  491. //if (AttrKey::GENERATOR_RAD_XRAYON == value) //软同步,收到XR1时,子系统会变为XRAYON状态,并调用此处,然后我立刻回复XR1至发生器,然后才真正出线。
  492. //{
  493. // FINFO("SetGenSynState be call.this is soft syn mode.");
  494. // HWSend("XR1");
  495. // m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
  496. // FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  497. //}
  498. return RET_STATUS::RET_SUCCEED;
  499. }
  500. RET_STATUS nsGEN::REMEDYDevice::SetGenState(int value)
  501. {
  502. return RET_STATUS::RET_SUCCEED;
  503. }
  504. RET_STATUS nsGEN::REMEDYDevice::SetExpMode(std::string value)
  505. {
  506. //note: when time the func be called?
  507. FINFO("Enter SetExpMode...{$}",value);
  508. m_DoseUnit.m_ExpMode->Update(value);
  509. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  510. return RET_STATUS::RET_SUCCEED;
  511. }
  512. RET_STATUS nsGEN::REMEDYDevice::SetFLFMode(std::string value)
  513. {
  514. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  515. FINFO("Enter SetFLFMode...,FLFMode:{$} \n", value.c_str());
  516. if (value == "CF")
  517. {
  518. m_DoseUnit.m_FLMode->Update(1);
  519. HWSend("FLF1");
  520. }
  521. else if (value == "PF")
  522. {
  523. m_DoseUnit.m_FLMode->Update(2);
  524. HWSend("FLF2");
  525. }
  526. else if (value == "HLF")
  527. {
  528. m_DoseUnit.m_FLMode->Update(2);
  529. HWSend("FLF2");
  530. }
  531. else
  532. {
  533. FINFO("other FluMode : {$}", value.c_str());
  534. }
  535. return RET_STATUS::RET_SUCCEED;
  536. }
  537. RET_STATUS nsGEN::REMEDYDevice::SetAPF(const _tAPFArgs& t)
  538. {
  539. FINFO("APF:FLKV={$},FLMA={$},PPS={$},WS={$},FLuType={$},ABSMode={$},DoseLever={$}", t.nFLKV, t.fFLMA, t.nPPS, t.nWS, t.nFluMode, t.nABSMode, t.nDoseLever);
  540. //SetABSMode(t.nABSMode);
  541. //SetFLFMode(to_string(t.nFluMode));
  542. //SetFluDoseLever(t.nDoseLever);
  543. SetFluKV(t.nFLKV);
  544. SetFluMA(t.fFLMA);
  545. HWSend("RF");
  546. return RET_STATUS::RET_SUCCEED;
  547. }
  548. RET_STATUS nsGEN::REMEDYDevice::IncFluKV()
  549. {
  550. FINFO("FluKV value before calling IncFluKV: {$}\n", m_DoseUnit.m_FLKV->JSGet().c_str());
  551. if (!m_DoseUnit.m_FLKV->CanInc()) return RET_STATUS::RET_SUCCEED;
  552. return HWSend("FLK+");
  553. }
  554. RET_STATUS nsGEN::REMEDYDevice::DecFluKV()
  555. {
  556. FINFO("FluKV value before calling DecFluKV: {$}\n", m_DoseUnit.m_FLKV->JSGet().c_str());
  557. if (!m_DoseUnit.m_FLKV->CanDec()) return RET_STATUS::RET_SUCCEED;
  558. return HWSend("FLK-");
  559. }
  560. RET_STATUS nsGEN::REMEDYDevice::SetFluKV(float value)
  561. {
  562. FINFO("FluKV value before calling SetFluKV: {$}\n", m_DoseUnit.m_FLKV->JSGet().c_str());
  563. if (!m_DoseUnit.m_FLKV->Verify(value)) return RET_STATUS::RET_SUCCEED;
  564. char temp[50] = { 0 };
  565. sprintf_s(temp, "FLK%03d", (int)value);
  566. return HWSend(temp);
  567. }
  568. RET_STATUS nsGEN::REMEDYDevice::IncFluMA()
  569. {
  570. FINFO("FluMA value before calling IncFluMA: {$}\n", m_DoseUnit.m_FLMA->JSGet().c_str());
  571. if (!m_DoseUnit.m_FLMA->CanInc()) return RET_STATUS::RET_SUCCEED;
  572. return HWSend("FLM+");
  573. }
  574. RET_STATUS nsGEN::REMEDYDevice::DecFluMA()
  575. {
  576. FINFO("FluMA value before calling DecFluMA: {$}\n", m_DoseUnit.m_FLMA->JSGet().c_str());
  577. if (!m_DoseUnit.m_FLMA->CanDec()) return RET_STATUS::RET_SUCCEED;
  578. return HWSend("FLM-");
  579. }
  580. RET_STATUS nsGEN::REMEDYDevice::SetFluMA(float value)
  581. {
  582. FINFO("FluMA value before calling SetFluMA: {$}\n", m_DoseUnit.m_FLMA->JSGet().c_str());
  583. if (!m_DoseUnit.m_FLMA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  584. char temp[50] = { 0 };
  585. sprintf_s(temp, "FLM%03d", (int)(value * 10));
  586. return HWSend(temp);
  587. }
  588. RET_STATUS nsGEN::REMEDYDevice::INCPPS()
  589. {
  590. if (!m_DoseUnit.m_PPS->CanInc()) return RET_STATUS::RET_SUCCEED;
  591. return HWSend("FLS+");
  592. }
  593. RET_STATUS nsGEN::REMEDYDevice::DECPPS()
  594. {
  595. if (!m_DoseUnit.m_PPS->CanDec()) return RET_STATUS::RET_SUCCEED;
  596. return HWSend("FLS-");
  597. }
  598. RET_STATUS nsGEN::REMEDYDevice::SetPPS(float value)
  599. {
  600. if (!m_DoseUnit.m_PPS->Verify(value)) return RET_STATUS::RET_SUCCEED;
  601. char temp[50] = { 0 };
  602. sprintf_s(temp, "FLS%03d", (int)(value * 10));
  603. return HWSend(temp);
  604. }
  605. RET_STATUS nsGEN::REMEDYDevice::SetABSMode(int nMode)
  606. {
  607. if (!m_DoseUnit.m_ABSStatus->Verify(nMode)) return RET_STATUS::RET_SUCCEED;
  608. char temp[50] = { 0 };
  609. FINFO("SetABSMode[{$}] \n", nMode);
  610. sprintf_s(temp, "FLA%1d", (int)nMode);
  611. return HWSend(temp);
  612. }
  613. RET_STATUS nsGEN::REMEDYDevice::SetABSCurve(int curveNum)
  614. {
  615. return RET_STATUS::RET_SUCCEED;
  616. }
  617. RET_STATUS nsGEN::REMEDYDevice::IncABSCurve()
  618. {
  619. return RET_STATUS::RET_SUCCEED;
  620. }
  621. RET_STATUS nsGEN::REMEDYDevice::DecABSCurve()
  622. {
  623. return RET_STATUS::RET_SUCCEED;
  624. }
  625. RET_STATUS nsGEN::REMEDYDevice::GetABSCurve()
  626. {
  627. return HWSend("FLA?");
  628. }
  629. float nsGEN::REMEDYDevice::GetFluIntTimer()
  630. {
  631. return HWSend("FLI?");
  632. }
  633. float nsGEN::REMEDYDevice::GetFluAccTimer()
  634. {
  635. return HWSend("FLT?");
  636. }
  637. RET_STATUS nsGEN::REMEDYDevice::ResetFluTimer(int ntype)
  638. {
  639. char temp[50] = { 0 };
  640. sprintf_s(temp, "FLR%1d", (int)ntype);
  641. FINFO("ReSetFluAccTimer:[{$}] \n", ntype);
  642. return HWSend(temp);
  643. }
  644. RET_STATUS nsGEN::REMEDYDevice::SetFluPre(int value)
  645. {
  646. return RET_STATUS::RET_SUCCEED;
  647. }
  648. RET_STATUS nsGEN::REMEDYDevice::SetFluEXP(int value)
  649. {
  650. return RET_STATUS::RET_SUCCEED;
  651. }
  652. RET_STATUS nsGEN::REMEDYDevice::SetFluMode(std::string value)
  653. {
  654. FINFO("Enter SetFLFMode...{$} \n", value.c_str());
  655. if (value == "CF")
  656. {
  657. m_DoseUnit.m_FLMode->Update(1);
  658. return HWSend("FLF1");
  659. }
  660. else if (value == "PF")
  661. {
  662. m_DoseUnit.m_FLMode->Update(2);
  663. return HWSend("FLF2");
  664. }
  665. else
  666. {
  667. FINFO("other FluMode : {$}", value.c_str());
  668. return RET_STATUS::RET_SUCCEED;
  669. }
  670. }
  671. RET_STATUS nsGEN::REMEDYDevice::SetFluDoseLever(int value)
  672. {
  673. FINFO("Enter SetFluDoseLever...{$} \n", value);
  674. // 提取当前剂量级别
  675. int currentDoseLevel = m_DoseUnit.m_DoseLevel->Get();
  676. // 只有在剂量级别发生变化时才继续处理
  677. if (currentDoseLevel == value) {
  678. return RET_STATUS::RET_SUCCEED;
  679. }
  680. float fma;
  681. // 计算新的FLMA值
  682. if (value == 1) {
  683. fma = 2 * m_DoseUnit.m_FLMA->Get();
  684. }
  685. else if (value == 0) {
  686. fma = 0.5 * m_DoseUnit.m_FLMA->Get();
  687. }
  688. else {
  689. FINFO("Invalid value:{$} \n", value);
  690. return RET_STATUS::RET_FAILED; // 非法值处理
  691. }
  692. // 更新剂量级别
  693. m_DoseUnit.m_DoseLevel->Update(value);
  694. // 验证FLMA值
  695. if (!m_DoseUnit.m_FLMA->Verify(fma)) {
  696. return RET_STATUS::RET_SUCCEED;
  697. }
  698. // 发送命令到硬件
  699. char temp[50] = { 0 };
  700. sprintf_s(temp, "FLM%03d", (int)(fma * 10));
  701. return HWSend(temp, strlen(temp));
  702. }
  703. void CCOS::Dev::Detail::Generator::REMEDYDevice::UpdateLimits(const std::string& key, float& currentValue, float defaultValue)
  704. {
  705. if (m_GenConfig.GetKeyCount(key.c_str()) > 0)
  706. {
  707. currentValue = static_cast<float>(m_GenConfig[key.c_str()]);
  708. }
  709. else
  710. {
  711. currentValue = defaultValue;
  712. }
  713. }
  714. void nsGEN::REMEDYDevice::UpdateLimitsInt(const std::string& key, int& currentValue, int defaultValue)
  715. {
  716. if (m_GenConfig.GetKeyCount(key.c_str()) > 0)
  717. {
  718. currentValue = static_cast<int>(m_GenConfig[key.c_str()]);
  719. }
  720. else
  721. {
  722. currentValue = defaultValue;
  723. }
  724. }
  725. int nsGEN::REMEDYDevice::GetGenState()
  726. {
  727. if (m_DoseUnit.m_GenState != NULL)
  728. {
  729. return m_DoseUnit.m_GenState->Get();
  730. }
  731. else
  732. {
  733. return 0;
  734. }
  735. }
  736. int nsGEN::REMEDYDevice::LoadConfig(string configfile)
  737. {
  738. FINFO("=====================LoadConfig=========================");
  739. // 检查文件是否存在
  740. std::ifstream file(configfile);
  741. if (!file) {
  742. // 文件不存在,直接返回空的Connection对象
  743. FINFO("Config file does not exist: {$}", configfile.c_str());
  744. return -1;
  745. }
  746. if (m_bIsConfigLoaded)
  747. {
  748. FINFO("Configuration already loaded.");
  749. return 0;
  750. }
  751. ResDataObject temp;
  752. temp.loadFile(m_strConfigPath.c_str());
  753. m_GenConfig = temp["CONFIGURATION"];
  754. TransJsonText(m_GenConfig);
  755. if (m_GenConfig.GetKeyCount("ReturnTime") > 0)
  756. {
  757. m_nReturnTime = (int)m_GenConfig["ReturnTime"];
  758. }
  759. if (m_GenConfig.GetKeyCount("R20Enable") > 0)
  760. {
  761. m_bMasR20 = (bool)m_GenConfig["R20Enable"];
  762. }
  763. if (m_GenConfig.GetKeyCount("USEEACMD") > 0)
  764. {
  765. m_bUseEAcmd = (bool)m_GenConfig["USEEACMD"];
  766. }
  767. UpdateLimits("PFMALimitMax", m_fPFLimitMaxMA, 40.0f);
  768. UpdateLimits("PFKVLimitMax", m_fPFLimitMaxKV, 80.0f);
  769. UpdateLimits("PFMALimitMin", m_fPFLimitMinMA, 1.0f);
  770. UpdateLimits("PFKVLimitMin", m_fPFLimitMinKV, 39.0f);
  771. // Update HLF limits
  772. UpdateLimits("HLFMALimitMax", m_fHLFLimitMaxMA, 99.0f);
  773. UpdateLimits("HLFKVLimitMax", m_fHLFLimitMaxKV, 151.0f);
  774. UpdateLimits("HLFMALimitMin", m_fHLFLimitMinMA, 40.0f);
  775. UpdateLimits("HLFKVLimitMin", m_fHLFLimitMinKV, 80.0f);
  776. if (!InitDevice())
  777. {
  778. FINFO("InitDevice succeed\n");
  779. }
  780. m_bIsConfigLoaded = true;
  781. return 0;
  782. }
  783. int nsGEN::REMEDYDevice::InitDevice()
  784. {
  785. HWSend("RE");
  786. Sleep(30);
  787. HWSend("WS1");
  788. Sleep(30);
  789. HWSend("FLA0");
  790. return 0;
  791. }
  792. RET_STATUS nsGEN::REMEDYDevice::SetEXAMMode(std::string value)
  793. {
  794. //EXAMMODE_TYPE::MANUAL
  795. return RET_STATUS::RET_SUCCEED;
  796. }
  797. RET_STATUS REMEDYDevice::REMEDYDevice::ActiveSyncMode(_tSyncModeArgs value)
  798. {
  799. FINFO("value.strSyncMode: {$}, value.strSyncValue: {$}, value.strWS: {$} \n", value.strSyncMode, value.strSyncValue, value.strWS);
  800. int nSyncModeValue = atoi(value.strSyncValue.c_str());
  801. char temp[50] = { 0 };
  802. sprintf_s(temp, "WS%01d", nSyncModeValue);
  803. return HWSend(temp);
  804. }
  805. void nsGEN::REMEDYDevice::HandleError(const char* value, const char* prefix, const std::string& type)
  806. {
  807. assert(value);
  808. int nValue = atoi(value);
  809. char temp[50] = { 0 };
  810. sprintf_s(temp, "%s%03d", type.c_str(), nValue);
  811. HWSend(temp);
  812. std::string errorCode = "Remedy_ER" + std::string(value);
  813. if (m_DeviceErrorHandler->ParseAndReport(errorCode) == "error")
  814. {
  815. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR))
  816. {
  817. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  818. }
  819. }
  820. }
  821. RET_STATUS nsGEN::REMEDYDevice::SetFrameRate(FLOAT frameRate)
  822. {
  823. m_DoseUnit.m_FrameRate->Update(frameRate); //this variable should be set when in oncallback.
  824. char temp[50]{ 0 };
  825. sprintf_s(temp, "FLS%03d", int(frameRate*10));
  826. return HWSend(temp);
  827. }
  828. RET_STATUS nsGEN::REMEDYDevice::SetRPS(int rps)
  829. {
  830. return RET_STATUS::RET_SUCCEED;
  831. //char temp[50]{ 0 };
  832. //sprintf_s(temp, "RPS%03d", rps * 10);
  833. //return HWSend(temp);
  834. }
  835. RET_STATUS nsGEN::REMEDYDevice::RefreshData()
  836. {
  837. HWSend("RR");
  838. HWSend("RS");
  839. HWSend("RF");
  840. return RET_STATUS::RET_SUCCEED;
  841. }
  842. RET_STATUS nsGEN::REMEDYDevice::SetExpEnable()
  843. {
  844. FINFO("SetExpEnable in ...\n");
  845. if (m_bUseEAcmd)
  846. {
  847. HWSend("EA111");
  848. }
  849. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  850. return RET_STATUS::RET_SUCCEED;
  851. //return HWSend("EXB1");
  852. }
  853. RET_STATUS nsGEN::REMEDYDevice::SetExpDisable()
  854. {
  855. FINFO("SetExpDisable in...\n");
  856. if (m_bUseEAcmd)
  857. {
  858. HWSend("EA000");
  859. }
  860. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  861. FINFO("SetExpDisable... {$}\n", m_DoseUnit.m_GenState->JSGet().c_str());
  862. return RET_STATUS::RET_SUCCEED;
  863. //return HWSend("EXB0");
  864. }
  865. RET_STATUS nsGEN::REMEDYDevice::Reset()
  866. {
  867. m_bResetActive = true;
  868. FINFO("RESET in...\n");
  869. int level = 0;
  870. if (!m_localWarnlist.empty())
  871. {
  872. m_localWarnlist.clear();
  873. FINFO("Local warning list has been cleared.\n");
  874. m_MSGUnit->DelErrorMessage("0", level, "clear all errors");
  875. m_MSGUnit->DelWarnMessage("0", level, "clear all Warning");
  876. }
  877. return HWSend("RE");
  878. }
  879. RET_STATUS nsGEN::REMEDYDevice::HWSend(char* strCommand, int nTimeOut)
  880. {
  881. if (!m_SCF) return RET_STATUS::RET_FAILED;
  882. char strSendCommand[100] = { 0 };
  883. int len = strlen(strCommand);
  884. int tmpSum = 0;
  885. for (int i = 0; i < len; i++)
  886. {
  887. tmpSum += (int)strCommand[i];
  888. }
  889. char checkSum = char(tmpSum + 3); //3 is ETX
  890. memcpy(strSendCommand, strCommand, len);
  891. strSendCommand[len + 0] = 0x03;
  892. strSendCommand[len + 1] = checkSum;
  893. FINFO("==OUT==: {$} \n", strSendCommand);
  894. int retLength;
  895. m_SCF.Lock(msTimeOut_Lock)
  896. .SendPacket(strSendCommand, strlen(strSendCommand), nTimeOut, retLength);
  897. //Sleep(nTimeOut);
  898. return RET_STATUS::RET_SUCCEED;
  899. }
  900. //-----------------------------------------------------------------------------
  901. // ProcessCmd
  902. //-----------------------------------------------------------------------------
  903. void nsGEN::REMEDYDevice::FireNotify(std::string key, std::string content)
  904. {
  905. EventCenter->OnNotify(1, key, content);
  906. }
  907. struct tFrameMapping
  908. {
  909. static const int MaxLen = 5; // 前缀不能超超过 5 个字符 !
  910. using cbFun = std::function <void(const char*, int)>;
  911. char strHead[MaxLen];
  912. int NbOfCharOfHead;
  913. cbFun fun;
  914. tFrameMapping(char* str, int len, cbFun f)
  915. {
  916. assert(len < MaxLen); //len最大只能是4
  917. //strHead[0] = 0x02; //STX ----------->note : no package header
  918. for (int i = 0; i < len; i++) //给strHead赋值
  919. strHead[i] = str[i];
  920. NbOfCharOfHead = len;
  921. fun = f;
  922. }
  923. };
  924. static std::list <tFrameMapping> arFrame;
  925. static bool DecodeFrame(const char* strFrame, int length);
  926. void nsGEN::REMEDYDevice::OnCallBack()
  927. {
  928. auto HWNotProcess = [](const char* value, int length) -> void
  929. {
  930. printf("\n This commands didn't need to process!\n");
  931. FINFO("\n This commands didn't need to process!\n");
  932. };
  933. //==IN==:KV070 MA00320 MS00063 MX00036 sometimes : this long str appear. so must deal with it
  934. auto HWKV = [this](const char* value, int length) -> void
  935. {
  936. assert(value);
  937. FINFO("hwkv={$},len={$}",value, length);
  938. if (length > 20) //if length more than 20, it must be a long string like :070 MA00320 MS00063 MX00036
  939. {
  940. //loop the long string to find kv ma ms mas
  941. int tmpkv;
  942. float tmpma, tmpms, tmpmx;
  943. char tmpbuf[5]{ 0,0,0,0,0 };
  944. //kv
  945. tmpbuf[0] = value[0];
  946. tmpbuf[1] = value[1];
  947. tmpbuf[2] = value[2];
  948. tmpkv = atoi(tmpbuf);
  949. m_DoseUnit.m_KV->Update(tmpkv);
  950. FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
  951. //ma
  952. tmpbuf[0] = value[6];
  953. tmpbuf[1] = value[7];
  954. tmpbuf[2] = value[8];
  955. tmpbuf[3] = value[9];
  956. tmpbuf[4] = value[10];
  957. tmpma = atof(tmpbuf)/10;
  958. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  959. {
  960. m_DoseUnit.m_MA->Update(0);
  961. FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
  962. }
  963. else
  964. {
  965. m_DoseUnit.m_MA->Update(tmpma);
  966. FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
  967. }
  968. //ms
  969. tmpbuf[0] = value[14];
  970. tmpbuf[1] = value[15];
  971. tmpbuf[2] = value[16];
  972. tmpbuf[3] = value[17];
  973. tmpbuf[4] = value[18];
  974. tmpms = atof(tmpbuf) / 10;
  975. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  976. {
  977. m_DoseUnit.m_MS->Update(0);
  978. FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
  979. }
  980. else
  981. {
  982. m_DoseUnit.m_MS->Update(tmpms);
  983. FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
  984. }
  985. //mx
  986. tmpbuf[0] = value[22];
  987. tmpbuf[1] = value[23];
  988. tmpbuf[2] = value[24];
  989. tmpbuf[3] = value[25];
  990. tmpbuf[4] = value[26];
  991. tmpmx = atof(tmpbuf) / 10;
  992. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_TIME)
  993. {
  994. m_DoseUnit.m_MAS->Update(0);
  995. FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  996. }
  997. else
  998. {
  999. m_DoseUnit.m_MAS->Update(tmpmx);
  1000. FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  1001. }
  1002. FINFO("tmpkv={$} tmpma={$}, tmpms={$}, tmpmx={$};", tmpkv, tmpma, tmpms, tmpmx);
  1003. }
  1004. else
  1005. {
  1006. int tmpkv = atoi(value);
  1007. if (m_DoseUnit.m_KV->Get() != tmpkv && m_DoseUnit.m_KV->Update(tmpkv))
  1008. FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
  1009. }
  1010. };
  1011. //==IN==:TU0 WS1 FO0 ET0 FI010 FS001 FN 0 HE000
  1012. auto HWTU = [this](const char* value, int length) -> void
  1013. {
  1014. assert(value);
  1015. FINFO("recv TU={$},len={$}", value,length);
  1016. char tmpbuf[3] = { 0,0,0 };
  1017. int tmpWS, tmpFO, tmpET, tmpField, tmpFilm, tmpDensity, tmpHE;
  1018. //ws
  1019. tmpbuf[0] = value[4];
  1020. tmpWS = atoi(tmpbuf);
  1021. m_DoseUnit.m_WS->Update(tmpWS);
  1022. FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
  1023. //FO
  1024. tmpbuf[0] = value[8];
  1025. tmpFO = atoi(tmpbuf);
  1026. m_DoseUnit.m_Focus->Update(tmpFO);
  1027. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  1028. FINFO("Current focus:{$}, FO={$}", atoi(m_DoseUnit.m_Focus->JSGet().c_str()) ? "large focus" : "small focus", m_DoseUnit.m_Focus->JSGet().c_str());
  1029. //ET
  1030. tmpbuf[0] = value[12];
  1031. tmpET = atoi(tmpbuf);
  1032. m_DoseUnit.m_Techmode->Update(tmpET);
  1033. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  1034. switch (tmpET)
  1035. {
  1036. case 0:
  1037. FINFO("ET={$}", "mA/ms", m_DoseUnit.m_Techmode->JSGet().c_str());
  1038. break;
  1039. case 1:
  1040. FINFO("ET={$}", "mAs", m_DoseUnit.m_Techmode->JSGet().c_str());
  1041. break;
  1042. case 2:
  1043. FINFO("ET={$}", "AEC / mA", m_DoseUnit.m_Techmode->JSGet().c_str());
  1044. break;
  1045. case 3:
  1046. FINFO("ET={$}", "mAs / ms", m_DoseUnit.m_Techmode->JSGet().c_str());
  1047. break;
  1048. case 4:
  1049. FINFO("ET={$}", "AEC", m_DoseUnit.m_Techmode->JSGet().c_str());
  1050. break;
  1051. }
  1052. //FIELD
  1053. tmpbuf[0] = value[16];
  1054. tmpbuf[1] = value[17];
  1055. tmpbuf[2] = value[18];
  1056. tmpField = atoi(tmpbuf);
  1057. if (m_DoseUnit.m_AECField->Update(tmpField))
  1058. FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_AECField->JSGet());
  1059. //Film
  1060. tmpbuf[0] = value[22];
  1061. tmpbuf[1] = value[23];
  1062. tmpbuf[2] = value[24];
  1063. tmpFilm = atoi(tmpbuf);
  1064. if (m_DoseUnit.m_AECFilm->Update(tmpFilm))
  1065. FireNotify(AttrKey::AECFILM, m_DoseUnit.m_AECFilm->JSGet());
  1066. //Density
  1067. tmpbuf[0] = value[29];
  1068. tmpbuf[1] = 0;
  1069. tmpbuf[2] = 0;
  1070. tmpDensity = atoi(tmpbuf);
  1071. if (m_DoseUnit.m_AECDensity->Update(tmpDensity))
  1072. FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
  1073. //HE
  1074. tmpbuf[0] = value[33];
  1075. tmpbuf[1] = value[34];
  1076. tmpbuf[2] = value[35];
  1077. tmpHE = atoi(tmpbuf);
  1078. if (m_DoseUnit.m_HE->Update(tmpHE))
  1079. FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
  1080. FINFO("parse tmpWS={$}, tmpFO={$}, tmpET={$}, tmpField={$}, tmpFilm={$}, tmpDensity={$}, tmpHE={$}", tmpWS, tmpFO, tmpET, tmpField, tmpFilm, tmpDensity, tmpHE);
  1081. };
  1082. auto HWEC = [this](const char* value, int length) -> void
  1083. {
  1084. assert(value);
  1085. FINFO("recv EC{$}",value);
  1086. };
  1087. auto HWST = [this](const char* value, int length) -> void
  1088. {
  1089. assert(value);
  1090. int genStatus = atoi(value);
  1091. if (m_bResetActive)
  1092. {
  1093. m_bResetActive = false;
  1094. //clear all error list
  1095. int level = 1;
  1096. for (auto errorStr : m_localErrorlist)
  1097. {
  1098. m_MSGUnit->DelErrorMessage(errorStr.c_str(), level, "");
  1099. FINFO("clear error = {$}\n", errorStr);
  1100. }
  1101. m_localErrorlist.clear();
  1102. }
  1103. switch (genStatus)
  1104. {
  1105. case 1:
  1106. FDEBUG("Get Gen Status_1:GENSTATE {$}", m_DoseUnit.m_GenState->JSGet());
  1107. if (1 == m_bUseEAcmd)
  1108. {
  1109. static int nST001Count = 0;
  1110. if (0 == nST001Count)//只执行一次。
  1111. {
  1112. FINFO("recv st001,and feedback EA000,just once");
  1113. HWSend("EA000");
  1114. nST001Count = 1;
  1115. }
  1116. }
  1117. break;
  1118. case 2:
  1119. FDEBUG("Get Gen Status_2:GENSTATE {$} -> (Standby Phase)", m_DoseUnit.m_GenState->JSGet());
  1120. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY))
  1121. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1122. break;
  1123. case 10:
  1124. FDEBUG("Get Gen Status_10:GENSTATE {$} -> (GENERATOR_STATUS_EXP)", m_DoseUnit.m_GenSynState->JSGet());
  1125. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP))
  1126. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1127. break;
  1128. default:
  1129. FDEBUG("Get Gen Status:[{$}] unknown", genStatus);
  1130. break;
  1131. }
  1132. };
  1133. auto HWMAS = [this](const char* value, int length)
  1134. {
  1135. assert(value);
  1136. float fmas = 0.0f;
  1137. if (m_bMasR20)
  1138. {
  1139. fmas = atof(value) / 100.0;
  1140. }
  1141. else
  1142. {
  1143. fmas = atof(value) / 10.0;
  1144. }
  1145. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_TIME)
  1146. {
  1147. if (m_DoseUnit.m_MAS->Update(0))
  1148. FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  1149. }
  1150. else
  1151. {
  1152. if (m_DoseUnit.m_MAS->Update(fmas))
  1153. FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  1154. }
  1155. };
  1156. auto HWMA = [this](const char* value, int length)
  1157. {
  1158. assert(value);
  1159. float fma = atof(value) / 10.0;
  1160. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  1161. {
  1162. m_DoseUnit.m_MA->Update(0);
  1163. FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
  1164. }
  1165. else
  1166. {
  1167. m_DoseUnit.m_MA->Update(fma);
  1168. FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
  1169. }
  1170. };
  1171. auto HWMS = [this](const char* value, int length)
  1172. {
  1173. assert(value);
  1174. float fms = atof(value) / 10.0;
  1175. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  1176. {
  1177. m_DoseUnit.m_MS->Update(0);
  1178. FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
  1179. }
  1180. else
  1181. {
  1182. m_DoseUnit.m_MS->Update(fms);
  1183. FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
  1184. }
  1185. };
  1186. auto HWFocus = [this](const char* value, int length)
  1187. {
  1188. assert(value);
  1189. int nfous = atoi(value);
  1190. if (m_DoseUnit.m_Focus->Update(nfous))
  1191. {
  1192. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  1193. FINFO("Current focus:{$}, FO={$}", atoi(m_DoseUnit.m_Focus->JSGet().c_str()) ? "large focus" : "small focus", m_DoseUnit.m_Focus->JSGet().c_str());
  1194. }
  1195. };
  1196. auto HWTechmode = [this](const char* value, int length)
  1197. {
  1198. assert(value);
  1199. int ntechmode = atoi(value);
  1200. m_DoseUnit.m_Techmode->Update(ntechmode);
  1201. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  1202. switch (ntechmode)
  1203. {
  1204. case 0:
  1205. {
  1206. FINFO(" ET={$}", "mA/ms", m_DoseUnit.m_Techmode->JSGet().c_str());
  1207. m_DoseUnit.m_MA->Update(0);
  1208. FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
  1209. }
  1210. break;
  1211. case 1:
  1212. {
  1213. FINFO(" ET={$}", "mAs", m_DoseUnit.m_Techmode->JSGet().c_str());
  1214. m_DoseUnit.m_MS->Update(0);
  1215. FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
  1216. m_DoseUnit.m_MA->Update(0);
  1217. FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
  1218. }
  1219. break;
  1220. case 2:
  1221. FINFO(" ET={$}", "AEC / mA", m_DoseUnit.m_Techmode->JSGet().c_str());
  1222. break;
  1223. case 3:
  1224. FINFO(" ET={$}", "mAs / ms", m_DoseUnit.m_Techmode->JSGet().c_str());
  1225. break;
  1226. case 4:
  1227. FINFO(" ET={$}", "AEC", m_DoseUnit.m_Techmode->JSGet().c_str());
  1228. break;
  1229. }
  1230. };
  1231. auto HWAECField = [this](const char* value, int length)
  1232. {
  1233. assert(value);
  1234. int nvalue = atoi(value);
  1235. if (m_DoseUnit.m_AECField->Update(nvalue))
  1236. FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_AECField->JSGet());
  1237. };
  1238. auto HWAECFilm = [this](const char* value, int length)
  1239. {
  1240. assert(value);
  1241. int nvalue = atoi(value);
  1242. if (m_DoseUnit.m_AECFilm->Update(nvalue))
  1243. FireNotify(AttrKey::AECFILM, m_DoseUnit.m_AECFilm->JSGet());
  1244. };
  1245. auto HWAECDensity = [this](const char* value, int length)
  1246. {
  1247. assert(value);
  1248. int nvalue = atoi(value);
  1249. if (m_DoseUnit.m_AECDensity->Update(nvalue))
  1250. FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
  1251. };
  1252. auto HWWS = [this](const char* value, int length)
  1253. {
  1254. assert(value);
  1255. int nValue = atoi(value);
  1256. m_DoseUnit.m_WS->Update(nValue);
  1257. FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
  1258. };
  1259. auto HWPR = [this](const char* value, int length)
  1260. {
  1261. assert(value);
  1262. int nValue = atoi(value);
  1263. if (nValue == 2)
  1264. {
  1265. FINFO("The high voltage generator enters the exposure preparation stage。");
  1266. HWSend("PR2");
  1267. }
  1268. else if (nValue == 1)
  1269. {
  1270. HWSend("PR1");
  1271. m_iLoopTime = REMEDY_LoopExpTime;
  1272. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE))
  1273. {
  1274. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1275. FINFO("Generator exposure process status:{$};", "GENERATOR_RAD_PREPARE");
  1276. }
  1277. }
  1278. else if (nValue == 0)
  1279. {
  1280. HWSend("PR0");
  1281. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF));
  1282. {
  1283. Sleep(m_nReturnTime);
  1284. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1285. FINFO("Generator exposure process status:{$};", "GENERATOR_RAD_OFF");
  1286. FINFO("HWPR m_DoseUnit.m_GenSynState->JSGet()={$}", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1287. FINFO("m_nReturnTimee={$};", m_nReturnTime);
  1288. //RefreshData();
  1289. }
  1290. if (m_iLoopTime == REMEDY_LoopExpTime)
  1291. {
  1292. if ((int)m_GenConfig["loopTime"] >= 100)
  1293. {
  1294. m_iLoopTime = (int)m_GenConfig["loopTime"];
  1295. }
  1296. else
  1297. m_iLoopTime = REMEDY_LoopDefTime;
  1298. FDEBUG("reduction loopTime[{$}]->[{$}]", REMEDY_LoopExpTime, m_iLoopTime.load());
  1299. }
  1300. }
  1301. };
  1302. auto HWXR = [this](const char* value, int length)
  1303. {
  1304. assert(value);
  1305. int nValue = atoi(value);
  1306. if (nValue == 1)
  1307. {
  1308. HWSend("XR1");
  1309. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY))
  1310. {
  1311. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1312. FINFO("Generator exposure process status:{$};", "GENERATOR_RAD_READY");
  1313. ResetEvent(m_hGenPostEvent);
  1314. }
  1315. }
  1316. else if (nValue == 2)
  1317. {
  1318. HWSend("XR2");
  1319. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP))
  1320. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1321. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON))
  1322. {
  1323. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1324. FINFO("Generator exposure process status:{$};", "GENERATOR_RAD_XRAYON");
  1325. }
  1326. }
  1327. else if (nValue == 0)
  1328. {
  1329. HWSend("XR0");
  1330. if(m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF));
  1331. {
  1332. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1333. FINFO("Generator exposure process status:{$};", "GENERATOR_RAD_XRAYOFF");
  1334. FINFO("HWXR m_DoseUnit.m_GenSynState->JSGet()={$}", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1335. HWSend("AP?");
  1336. Sleep(30);
  1337. HWSend("AT?");
  1338. Sleep(30);
  1339. }
  1340. }
  1341. };
  1342. auto HWVPDOSE = [this](const char* value, int length)//mas
  1343. {
  1344. assert(value);
  1345. m_DoseUnit.m_PostKV->Update(atof(value));
  1346. FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
  1347. FINFO("Actual exposure parametersKV:{$}", m_DoseUnit.m_PostKV->JSGet().c_str());
  1348. };
  1349. auto HWAPDOSE = [this](const char* value, int length)//mas
  1350. {
  1351. assert(value);
  1352. m_DoseUnit.m_PostMAS->Update(atof(value) / 10.0);
  1353. FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
  1354. m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
  1355. FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
  1356. FINFO("Actual exposure parametersMAS:{$}", m_DoseUnit.m_PostMAS->JSGet().c_str());
  1357. };
  1358. auto HWATDOSE = [this](const char* value, int length)
  1359. {
  1360. assert(value);
  1361. m_DoseUnit.m_PostMS->Update(atof(value) / 10.0);
  1362. FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
  1363. m_DoseUnit.m_PostMA->Update(m_DoseUnit.m_PostMAS->Get() * 1000.0 / m_DoseUnit.m_PostMS->Get());
  1364. FireNotify(m_DoseUnit.m_PostMA->GetKey(), m_DoseUnit.m_PostMA->JSGet());
  1365. FINFO("Actual exposure parametersMS:{$}", m_DoseUnit.m_PostMS->JSGet().c_str());
  1366. };
  1367. auto HWDAPST = [this](const char* value, int length)
  1368. {
  1369. assert(value);
  1370. int dapStatus = atoi(value);
  1371. if (dapStatus == 1)
  1372. {
  1373. m_bDAPEnable = true;
  1374. m_bAKEnable = false;
  1375. }
  1376. else if (dapStatus == 2)
  1377. {
  1378. m_bDAPEnable = false;
  1379. m_bAKEnable = true;
  1380. }
  1381. else if (dapStatus == 3)
  1382. {
  1383. m_bDAPEnable = true;
  1384. m_bAKEnable = true;
  1385. }
  1386. else
  1387. {
  1388. m_bDAPEnable = false;
  1389. m_bAKEnable = false;
  1390. }
  1391. };
  1392. auto HWDT = [this](const char* value, int length)
  1393. {
  1394. assert(value);
  1395. int dapStatus = atoi(value);
  1396. if (dapStatus == 0)
  1397. {
  1398. m_bDAPEnable = false;
  1399. FINFO("DAP test failed");
  1400. }
  1401. else if (dapStatus == 1)
  1402. {
  1403. m_bDAPEnable = true;
  1404. FINFO("DAP test passed");
  1405. }
  1406. else if (dapStatus == 2)
  1407. {
  1408. m_bDAPEnable = true;
  1409. FINFO("DAP test in progress.");
  1410. }
  1411. };
  1412. auto HWDAP = [this](const char* value, int length)
  1413. {
  1414. assert(value);
  1415. //m_DoseUnit.->Update(atof(value));
  1416. //FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
  1417. //SetEvent(m_hGenPostEvent);
  1418. m_DAP->Update(atof(value)); //should push to subsystem.......
  1419. };
  1420. auto HWEL = [this](const char* value, int length)
  1421. {
  1422. HandleError(value, "REMEDY_EL_", "EL");
  1423. };
  1424. auto HWER = [this](const char* value, int length)
  1425. {
  1426. HandleError(value, "REMEDY_ER_", "ER");
  1427. };
  1428. auto HWWARN = [this](const char* value, int length)
  1429. {
  1430. HandleError(value, "REMEDY_WARN_", "EW");
  1431. };
  1432. auto HWEHE = [this](const char* value, int length)
  1433. {
  1434. assert(value);
  1435. int nhe = atoi(value);
  1436. FINFO("HE:{$}%", nhe);
  1437. if (m_DoseUnit.m_HE->Update(nhe))
  1438. FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
  1439. };
  1440. //075 FLM100 FLI000 FLT006 FLF2 FLA0 FLS060 FLZ0 FLD0
  1441. auto HWFLK = [this](const char* value, int length)
  1442. {
  1443. assert(value);
  1444. if (length > 20) // Check if length is more than 20
  1445. {
  1446. FINFO("HWFLK={$}", value);
  1447. int tmpflk, tmpflf, tmpfla, tmpfld, tmpflo;
  1448. float tmpflm, tmpfli, tmpflt, tmpfls, tmpflw;
  1449. char tmpbuf[3]{ 0, 0, 0 };
  1450. //flk
  1451. tmpbuf[0] = value[0];
  1452. tmpbuf[1] = value[1];
  1453. tmpbuf[2] = value[2];
  1454. tmpflk = atoi(tmpbuf);
  1455. m_DoseUnit.m_FLKV->Update(tmpflk);
  1456. FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
  1457. // flm
  1458. tmpbuf[0] = value[7];
  1459. tmpbuf[1] = value[8];
  1460. tmpbuf[2] = value[9];
  1461. tmpflm = atof(tmpbuf) / 10.0;
  1462. m_DoseUnit.m_FLMA->Update(tmpflm);
  1463. FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
  1464. // fli
  1465. tmpbuf[0] = value[14];
  1466. tmpbuf[1] = value[15];
  1467. tmpbuf[2] = value[16];
  1468. tmpfli = atof(tmpbuf) / 10.0;
  1469. m_DoseUnit.m_FLIntTime->Update(tmpfli);
  1470. FireNotify(AttrKey::FLUIntTime, m_DoseUnit.m_FLIntTime->JSGet());
  1471. // flt
  1472. tmpbuf[0] = value[21];
  1473. tmpbuf[1] = value[22];
  1474. tmpbuf[2] = value[23];
  1475. tmpflt = atof(tmpbuf) / 10.0;
  1476. m_DoseUnit.m_FLAccTime->Update(tmpflt);
  1477. FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
  1478. // flf
  1479. tmpbuf[0] = value[28];
  1480. tmpbuf[1] = 0;
  1481. tmpbuf[2] = 0;
  1482. tmpflf = atoi(tmpbuf);
  1483. m_DoseUnit.m_FLMode->Update(tmpflf);
  1484. FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
  1485. // fla
  1486. tmpbuf[0] = value[33];
  1487. tmpfla = atoi(tmpbuf);
  1488. m_DoseUnit.m_ABSStatus->Update(tmpfla);
  1489. FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
  1490. // fls
  1491. tmpbuf[0] = value[38];
  1492. tmpbuf[1] = value[39];
  1493. tmpbuf[2] = value[40];
  1494. tmpfls = atof(tmpbuf) / 10.0;
  1495. m_DoseUnit.m_PPS->Update(tmpfls);
  1496. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1497. //// fld
  1498. //tmpbuf[0] = value[50];
  1499. //tmpbuf[1] = 0;
  1500. //tmpbuf[2] = 0;
  1501. //tmpfld = atoi(tmpbuf);
  1502. //if (m_DoseUnit.m_DoseLevel->Get() != tmpfld && m_DoseUnit.m_DoseLevel->Update(tmpfld))
  1503. // FireNotify(AttrKey::FLUDoseLevel, m_DoseUnit.m_DoseLevel->JSGet());
  1504. FINFO("tmpflk={$}, tmpflf={$}, tmpfla={$}, tmpfld={$}, tmpflm={$}, tmpfli={$}, tmpflt={$}, tmpfls={$};", tmpflk, tmpflf, tmpfla, tmpfld, tmpflm, tmpfli, tmpflt, tmpfls);
  1505. }
  1506. else
  1507. {
  1508. m_DoseUnit.m_FLKV->Update(atof(value));
  1509. FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
  1510. }
  1511. };
  1512. auto HWFLM = [this](const char* value, int length)
  1513. {
  1514. assert(value);
  1515. float tmpflm = atof(value) / 10.0;
  1516. m_DoseUnit.m_FLMA->Update(tmpflm);
  1517. FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
  1518. };
  1519. auto HWFLS = [this](const char* value, int length)
  1520. {
  1521. assert(value);
  1522. FINFO("HWFLS={$}", value);
  1523. float tmppps = atof(value) / 10.0;
  1524. m_DoseUnit.m_PPS->Update(tmppps);
  1525. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1526. };
  1527. auto HWFLX = [this](const char* value, int length)
  1528. {
  1529. assert(value);
  1530. int nValue = atoi(value);
  1531. if (nValue == 0)
  1532. {
  1533. HWSend("FLX0");
  1534. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYOFF))
  1535. {
  1536. FINFO("Generator exposure process status{$};", "GENERATOR_FLU_XRAYOFF");
  1537. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1538. }
  1539. }
  1540. else if (nValue == 1)
  1541. {
  1542. HWSend("FLX1");
  1543. m_iLoopTime = REMEDY_LoopExpTime;
  1544. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_READY))
  1545. {
  1546. FINFO("Generator exposure process status{$};", "GENERATOR_FLU_READY");
  1547. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1548. }
  1549. }
  1550. else if (nValue == 2)
  1551. {
  1552. HWSend("FLX2");
  1553. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP))
  1554. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1555. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYON))
  1556. {
  1557. FINFO("Generator exposure process status{$};", "GENERATOR_FLU_XRAYON");
  1558. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1559. }
  1560. }
  1561. };
  1562. auto HWFLP = [this](const char* value, int length)
  1563. {
  1564. assert(value);
  1565. int nValue = atoi(value);
  1566. if (nValue == 0)
  1567. {
  1568. HWSend("FLP0");
  1569. if (m_iLoopTime == REMEDY_LoopExpTime)
  1570. {
  1571. if ((int)m_GenConfig["loopTime"] >= 100)
  1572. {
  1573. m_iLoopTime = (int)m_GenConfig["loopTime"];
  1574. }
  1575. else
  1576. m_iLoopTime = REMEDY_LoopDefTime;
  1577. FDEBUG("reduction loopTime[{$}]->[{$}]", REMEDY_LoopExpTime, m_iLoopTime.load());
  1578. }
  1579. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_OFF))
  1580. {
  1581. FINFO("Generator exposure process status{$};", "GENERATOR_FLU_OFF");
  1582. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1583. }
  1584. RefreshData();
  1585. }
  1586. else
  1587. {
  1588. HWSend("FLP1");
  1589. FINFO("FLP1 do nothing");
  1590. }
  1591. };
  1592. auto HWFLF = [this](const char* value, int length)
  1593. {
  1594. assert(value);
  1595. FINFO("HWFLF={$};", value);
  1596. int tmpflf = atoi(value);
  1597. m_DoseUnit.m_FLMode->Update(tmpflf);
  1598. FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
  1599. };
  1600. auto HWFLA = [this](const char* value, int length)
  1601. {
  1602. assert(value);
  1603. int tmpfla = atoi(value);
  1604. if (m_DoseUnit.m_ABSStatus->Update(tmpfla))
  1605. FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
  1606. };
  1607. auto HWFLD = [this](const char* value, int length)
  1608. {
  1609. assert(value);
  1610. };
  1611. auto HWFLC = [this](const char* value, int length)
  1612. {
  1613. assert(value);
  1614. };
  1615. auto HWFLO = [this](const char* value, int length)
  1616. {
  1617. assert(value);
  1618. int nValue = atoi(value);
  1619. if (m_DoseUnit.m_Curve->Update(nValue))
  1620. FireNotify(AttrKey::FLUCurve, m_DoseUnit.m_Curve->JSGet());
  1621. };
  1622. auto HWFLW = [this](const char* value, int length)
  1623. {
  1624. assert(value);;
  1625. float tmpflms = atof(value) / 100.0;
  1626. if (m_DoseUnit.m_FLMS->Update(tmpflms))
  1627. FireNotify(AttrKey::FLUMS, m_DoseUnit.m_FLMS->JSGet());
  1628. };
  1629. auto HWFLI = [this](const char* value, int length)
  1630. {
  1631. assert(value);
  1632. float tmpfli = atof(value) / 10.0;
  1633. if (m_DoseUnit.m_FLIntTime->Update(tmpfli))
  1634. FireNotify(AttrKey::FLUIntTime, m_DoseUnit.m_FLIntTime->JSGet());
  1635. };
  1636. auto HWFLT = [this](const char* value, int length)
  1637. {
  1638. assert(value);
  1639. float tmpflt = atof(value) / 10.0;
  1640. if (m_DoseUnit.m_FLAccTime->Update(tmpflt))
  1641. {
  1642. std::string strFlAccTime = m_DoseUnit.m_FLAccTime->JSGet() ;
  1643. FINFO("HWFLT:{$};", strFlAccTime.c_str());
  1644. FireNotify(AttrKey::FLUAccTime, strFlAccTime);
  1645. }
  1646. };
  1647. // 有部分前缀是包含关系, 长的包含短的, 例如 KVS 包含了 KV.
  1648. // 因此长的在前面, 短的在后面
  1649. // !!! Device 是个短寿命对象, 而 arFrame 是静态变量 !!!
  1650. // !!! 因此, 在添加到 arFrame 之前, 务必先清零 !!!
  1651. arFrame.clear();
  1652. arFrame.push_back(tFrameMapping("KV", 2, HWKV));
  1653. arFrame.push_back(tFrameMapping("TU", 2, HWTU));
  1654. arFrame.push_back(tFrameMapping("MX", 2, HWMAS));
  1655. arFrame.push_back(tFrameMapping("MA", 2, HWMA));
  1656. arFrame.push_back(tFrameMapping("MS", 2, HWMS));
  1657. arFrame.push_back(tFrameMapping("ET", 2, HWTechmode));
  1658. arFrame.push_back(tFrameMapping("FO", 2, HWFocus));
  1659. arFrame.push_back(tFrameMapping("FI", 2, HWAECField));
  1660. arFrame.push_back(tFrameMapping("FS", 2, HWAECFilm));
  1661. arFrame.push_back(tFrameMapping("FN", 2, HWAECDensity));
  1662. arFrame.push_back(tFrameMapping("WS", 2, HWWS));
  1663. arFrame.push_back(tFrameMapping("PR", 2, HWPR));
  1664. arFrame.push_back(tFrameMapping("XR", 2, HWXR));
  1665. arFrame.push_back(tFrameMapping("VP", 2, HWVPDOSE));
  1666. arFrame.push_back(tFrameMapping("AP", 2, HWAPDOSE));
  1667. arFrame.push_back(tFrameMapping("AT", 2, HWATDOSE));
  1668. arFrame.push_back(tFrameMapping("EL", 2, HWEL));
  1669. arFrame.push_back(tFrameMapping("ER", 2, HWER));
  1670. arFrame.push_back(tFrameMapping("EW", 2, HWWARN));
  1671. arFrame.push_back(tFrameMapping("HE", 2, HWEHE));
  1672. arFrame.push_back(tFrameMapping("FLK", 3, HWFLK));
  1673. arFrame.push_back(tFrameMapping("FLM", 3, HWFLM));
  1674. arFrame.push_back(tFrameMapping("FLS", 3, HWFLS));
  1675. arFrame.push_back(tFrameMapping("FLF", 3, HWFLF));
  1676. arFrame.push_back(tFrameMapping("FLP", 3, HWFLP));
  1677. arFrame.push_back(tFrameMapping("FLX", 3, HWFLX));
  1678. arFrame.push_back(tFrameMapping("FLW", 3, HWFLW));
  1679. arFrame.push_back(tFrameMapping("FLI", 3, HWFLI));
  1680. arFrame.push_back(tFrameMapping("FLT", 3, HWFLT));
  1681. arFrame.push_back(tFrameMapping("FLA", 3, HWFLA));
  1682. arFrame.push_back(tFrameMapping("FLD", 3, HWFLD));
  1683. arFrame.push_back(tFrameMapping("FLC", 3, HWFLD));
  1684. arFrame.push_back(tFrameMapping("FLO", 3, HWFLO));
  1685. arFrame.push_back(tFrameMapping("ST", 2, HWST));
  1686. arFrame.push_back(tFrameMapping("EC", 2, HWEC));
  1687. arFrame.push_back(tFrameMapping("DS", 2, HWDAPST)); //dap status
  1688. arFrame.push_back(tFrameMapping("DA", 2, HWDAP)); //dap value
  1689. arFrame.push_back(tFrameMapping("DT", 2, HWDT)); //test dap
  1690. arFrame.push_back(tFrameMapping("P", 1, HWPR));
  1691. }
  1692. bool nsGEN::REMEDYDevice::StartHardwareStatusThread()
  1693. {
  1694. FINFO("enter Start HardwareStatus Thread ");
  1695. if (m_pHardwareStatusThread == NULL)
  1696. {
  1697. DWORD m_HardwareStatusID;
  1698. m_pHardwareStatusThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
  1699. if (m_pHardwareStatusThread == NULL)
  1700. {
  1701. Fatal("Start HardwareStatus Thread Failed");
  1702. return false;
  1703. }
  1704. }
  1705. return true;
  1706. }
  1707. bool nsGEN::REMEDYDevice::StartTrueParameterThread()
  1708. {
  1709. FINFO("enter Start TrueParameterThread Thread ");
  1710. if (m_pTrueParameterThread == NULL)
  1711. {
  1712. DWORD m_pTrueParameterID;
  1713. m_pTrueParameterThread = CreateThread(0, 0, TrueParameterThread, this, 0, &m_pTrueParameterID);
  1714. if (m_pTrueParameterThread == NULL)
  1715. {
  1716. FERROR("Start TrueParameterThread Thread Failed");
  1717. return false;
  1718. }
  1719. }
  1720. return true;
  1721. }
  1722. DWORD nsGEN::REMEDYDevice::HardwareStatusThread(LPVOID pParam)
  1723. {
  1724. REMEDYDevice* pCurGen = (REMEDYDevice*)pParam;
  1725. if (pCurGen == NULL)
  1726. {
  1727. return false;
  1728. }
  1729. FDEBUG("loopTime = {$}", pCurGen->m_iLoopTime.load());
  1730. int currtTime = pCurGen->m_iLoopTime;
  1731. int messageIndex = 0;
  1732. FINFO("HardwareStatusThread start");
  1733. while (true)
  1734. {
  1735. currtTime = pCurGen->m_iLoopTime;
  1736. Sleep(currtTime);
  1737. // 发送不同的消息,根据messageIndex循环
  1738. switch (messageIndex)
  1739. {
  1740. case 0:
  1741. pCurGen->HWSend("HE?");
  1742. break;
  1743. case 1:
  1744. pCurGen->HWSend("ST");
  1745. break;
  1746. case 2:
  1747. pCurGen->HWSend("FLT?");
  1748. break;
  1749. }
  1750. // 更新messageIndex,以便下一轮发送不同的消息
  1751. messageIndex = (messageIndex + 1) % 3;
  1752. }
  1753. FINFO("HardwareStatusThread stop");
  1754. return true;
  1755. }
  1756. DWORD CCOS::Dev::Detail::Generator::REMEDYDevice::TrueParameterThread(LPVOID pParam)
  1757. {
  1758. REMEDYDevice* pCurGen = (REMEDYDevice*)pParam;
  1759. if (pCurGen == NULL)
  1760. {
  1761. return false;
  1762. };
  1763. while (false)
  1764. {
  1765. Sleep(100);// 可以考虑继续Sleep(100)或者增加逻辑等待条件满足后再执行
  1766. }
  1767. return true;
  1768. }
  1769. //-----------------------------------------------------------------------------
  1770. // REMEDYDriver
  1771. //-----------------------------------------------------------------------------
  1772. nsGEN::REMEDYDriver::REMEDYDriver()
  1773. {
  1774. }
  1775. nsGEN::REMEDYDriver::~REMEDYDriver()
  1776. {
  1777. }
  1778. auto nsGEN::REMEDYDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  1779. {
  1780. FINFO("CreateDevice in\n");
  1781. m_pDevice = new REMEDYDevice(EventCenter, m_SCF, m_ConfigFileName);
  1782. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDevice));
  1783. FINFO("CreateDevice out\n");
  1784. return dev;
  1785. }
  1786. void nsGEN::REMEDYDriver::FireNotify(int code, std::string key, std::string content)
  1787. {
  1788. EventCenter->OnNotify(code, key, content);
  1789. }
  1790. Log4CPP::Logger* gLogger = nullptr;
  1791. void nsGEN::REMEDYDriver::Prepare()
  1792. {
  1793. string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
  1794. Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.REMEDY");
  1795. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  1796. gLogger = Log4CPP::LogManager::GetLogger("GEN.REMEDY");
  1797. FINFO("Enter Prepare.");
  1798. m_SCFDllName = GetConnectDLL(m_ConfigFileName);
  1799. super::Prepare();
  1800. }
  1801. bool DATA_ACTION nsGEN::REMEDYDriver::Connect()
  1802. {
  1803. FINFO("Enter {$},configlef={$}\n", __FUNCTION__, m_ConfigFileName.c_str());
  1804. super::Disconnect();
  1805. m_SCF.Disconnect();
  1806. ResDataObject Connection = GetConnectParam(m_ConfigFileName);
  1807. FINFO("connections:{$} \n", Connection.encode());
  1808. auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::REMEDYDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  1809. if (erCode != SCF_ERR::SCF_SUCCEED)
  1810. {
  1811. FINFO("SCF connection failed: erCode != SCF_ERR::SCF_SUCCEED\n");
  1812. return false;
  1813. }
  1814. auto rc = super::Connect();
  1815. if (!rc)
  1816. {
  1817. FINFO("super::Connect() failed\n");
  1818. return false;
  1819. }
  1820. return true;
  1821. }
  1822. void nsGEN::REMEDYDriver::Disconnect()
  1823. {
  1824. super::Disconnect();
  1825. m_SCF.Disconnect();
  1826. }
  1827. bool nsGEN::REMEDYDriver::isConnected() const
  1828. {
  1829. if (!super::isConnected())
  1830. {
  1831. FINFO("No valid connection!!!\n");
  1832. return false;
  1833. }
  1834. if (m_pDevice == nullptr)
  1835. {
  1836. FINFO("m_pDevice == nullptr\n");
  1837. return false;
  1838. }
  1839. if (m_pDevice->LoadConfig(m_ConfigFileName) == -1)
  1840. {
  1841. return false;
  1842. }
  1843. int genState = m_pDevice->GetGenState();
  1844. FINFO("m_pDevice->GetGenState() == {$}\n", genState);
  1845. return genState > 0; // 只有返回值大于 0 时才返回 true
  1846. }
  1847. std::string nsGEN::REMEDYDriver::DriverProbe()
  1848. {
  1849. FINFO("DriverProbe in \n");
  1850. ResDataObject r_config, HardwareInfo;
  1851. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1852. {
  1853. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  1854. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  1855. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  1856. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  1857. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  1858. }
  1859. else
  1860. {
  1861. HardwareInfo.add("MajorID", "Generator");
  1862. HardwareInfo.add("MinorID", "Dr");
  1863. HardwareInfo.add("VendorID", "REMEDY");
  1864. HardwareInfo.add("ProductID", "HF");
  1865. HardwareInfo.add("SerialID", "Drv");
  1866. }
  1867. string ret = HardwareInfo.encode();
  1868. FINFO("DriverProbe out \n");
  1869. return ret;
  1870. }
  1871. std::string nsGEN::REMEDYDriver::GetResource()
  1872. {
  1873. ResDataObject temp;
  1874. if (!temp.loadFile(m_ConfigFileName.c_str()))
  1875. return std::string();
  1876. auto r_config = temp["CONFIGURATION"];
  1877. for (auto& Item : m_ConfigInfo)
  1878. {
  1879. string key = Item.GetKey();
  1880. if (key == ConfKey::CcosGeneratorType)
  1881. {
  1882. Item.SetCurrentValue(((string)r_config["VendorID"]).c_str());
  1883. }
  1884. else if (key == ConfKey::CcosGeneratorModel)
  1885. {
  1886. Item.SetCurrentValue(((string)r_config["ProductID"]).c_str());
  1887. }
  1888. else if (key == ConfKey::CcosWSTable || key == ConfKey::CcosWSWall || key == ConfKey::CcosWSFree
  1889. || key == ConfKey::CcosWSTomo || key == ConfKey::CcosWSConventional)
  1890. {
  1891. Item.SetCurrentValue(((string)r_config[key.c_str()]).c_str());
  1892. }
  1893. else if (key == ConfKey::CcosSynTable || key == ConfKey::CcosSynWall || key == ConfKey::CcosSynFree
  1894. || key == ConfKey::CcosSynTomo || key == ConfKey::CcosSynConventional)
  1895. {
  1896. Item.SetCurrentValue(((string)r_config[key.c_str()]).c_str());
  1897. }
  1898. else if (key == ConfKey::CcosSCFType)
  1899. {
  1900. Item.SetCurrentValue(((string)r_config["connections"][0]["type"]).c_str());
  1901. }
  1902. else if (key == ConfKey::CcosSCFPort || key == ConfKey::CcosSCFBaudrate || key == ConfKey::CcosSCFBytesize
  1903. || key == ConfKey::CcosSCFParity || key == ConfKey::CcosSCFStopbits || key == ConfKey::CcosSCFIP)
  1904. {
  1905. if (r_config["connections"][0].GetFirstOf(key.c_str()) >= 0)
  1906. {
  1907. Item.SetCurrentValue(((string)r_config["connections"][0][key.c_str()]).c_str());
  1908. }
  1909. }
  1910. }
  1911. ResDataObject resAttr, resDescription;
  1912. for (auto Item : m_ConfigInfo)
  1913. {
  1914. resAttr.add(Item.GetKey(), Item.GetCurrentValue());
  1915. resDescription.add(Item.GetKey(), Item.GetDescription());
  1916. }
  1917. ResDataObject resDeviceResource;
  1918. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, resAttr);
  1919. resDeviceResource.add(ConfKey::CcosGeneratorDescription, resDescription);
  1920. string res = resDeviceResource.encode();
  1921. //printf("resDeviceResource :%s \n", resDeviceResource.encode());
  1922. FINFO("resDeviceResource :{$} \n", resDeviceResource.encode());
  1923. ResDataObject DescriptionTempEx;
  1924. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  1925. m_DeviceConfig.clear();
  1926. m_DeviceConfig = DescriptionTempEx;
  1927. return res;
  1928. }
  1929. bool nsGEN::REMEDYDriver::GetDeviceConfig(std::string& Cfg)
  1930. {
  1931. //Cfg = m_DeviceConfigSend.encode();
  1932. Cfg = m_DeviceConfig.encode();
  1933. //printf("GetDeviceConfig over");
  1934. printf("GetDeviceConfig over , %s", Cfg.c_str());
  1935. return true;
  1936. }
  1937. bool nsGEN::REMEDYDriver::SetDeviceConfig(std::string Cfg)
  1938. {
  1939. FINFO("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  1940. return true;
  1941. #if 0
  1942. ResDataObject DeviceConfig;
  1943. DeviceConfig.decode(Cfg.c_str());
  1944. ResDataObject DescriptionTempEx;
  1945. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  1946. FDEBUG("Attribute:{$}", DescriptionTempEx.encode());
  1947. bool bSaveFile = false; //true:重新保存配置文件
  1948. string strAccess = "";
  1949. for (int i = 0; i < DescriptionTempEx.size(); i++)
  1950. {
  1951. string strKey = DescriptionTempEx.GetKey(i);
  1952. FINFO("{$}", strKey.c_str());
  1953. try
  1954. {
  1955. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  1956. {
  1957. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  1958. if ("RW" == strAccess)
  1959. {
  1960. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  1961. //1. 修改内存中的值,用于给上层发消息
  1962. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  1963. //2. 拿到Innerkey
  1964. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1965. FINFO("nConfigInfoCount {$}", nConfigInfoCount);
  1966. string strTemp = ""; //存储AttributeKey
  1967. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1968. {
  1969. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1970. if (strTemp == strKey)
  1971. {
  1972. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1973. break;
  1974. }
  1975. }
  1976. //3. 修改配置文件中的值
  1977. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  1978. {
  1979. FDEBUG("SetDeviceConfigValue over");
  1980. bSaveFile = true;
  1981. }
  1982. }
  1983. else
  1984. {
  1985. FINFO("{$} is not a RW configuration item", strKey.c_str());
  1986. }
  1987. }
  1988. else
  1989. {
  1990. FINFO("without this attribute {$}", strKey.c_str());
  1991. }
  1992. }
  1993. catch (ResDataObjectExption& e)
  1994. {
  1995. FERROR("SetDriverConfig crashed: {$}", e.what());
  1996. return false;
  1997. }
  1998. }
  1999. if (bSaveFile)
  2000. {
  2001. //3. 重新保存配置文件
  2002. SaveConfigFile(true);
  2003. }
  2004. #endif // 0
  2005. return true;
  2006. }
  2007. bool nsGEN::REMEDYDriver::SaveConfigFile(bool bSendNotify)
  2008. {
  2009. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  2010. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  2011. FINFO("SaveConfigFile over {$}", bRt);
  2012. return true;
  2013. }
  2014. std::string nsGEN::REMEDYDriver::DeviceProbe()
  2015. {
  2016. FINFO("std::string nsGEN::PSGRFDriver::DeviceProbe() in\n");
  2017. ResDataObject r_config, HardwareInfo;
  2018. if (r_config.loadFile(m_ConfigFileName.c_str()))
  2019. {
  2020. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  2021. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  2022. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  2023. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  2024. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  2025. }
  2026. else
  2027. {
  2028. HardwareInfo.add("MajorID", "Generator");
  2029. HardwareInfo.add("MinorID", "Dr");
  2030. HardwareInfo.add("VendorID", "REMEDY");
  2031. HardwareInfo.add("ProductID", "HF");
  2032. HardwareInfo.add("SerialID", "1234");
  2033. }
  2034. string ret = HardwareInfo.encode();
  2035. FINFO("std::string nsGEN::PSGRFDriver::DeviceProbe() out\n");
  2036. return ret;
  2037. }
  2038. void nsGEN::REMEDYDriver::Dequeue(const char* Packet, DWORD Length)
  2039. {
  2040. DecodeFrame(Packet, Length);
  2041. }
  2042. /*
  2043. ==IN==:KV070 MA00320 MS00063 MX00036
  2044. ==IN==:TU0 WS1 FO0 ET0 FI010 FS001 FN 0 HE000
  2045. how to split the str like up.
  2046. //command+03+sum
  2047. */
  2048. PACKET_RET nsGEN::REMEDYDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
  2049. {
  2050. if (nLength < 1)
  2051. {
  2052. printf("nLength < 1, nLength==%d \n", nLength);
  2053. return PACKET_USELESS;
  2054. }
  2055. for (DWORD i = 0; i < nLength - 1; i++)
  2056. {
  2057. if (RecData[i] == 0x03)
  2058. {
  2059. PacketLength = i + 2; //应该+2.才会把最后的checmsum也包含进来。FO1+03+sum.
  2060. char strtemp[100] = { 0 };
  2061. memcpy(strtemp, RecData, i);
  2062. strtemp[i + 1] = 0;
  2063. FINFO("==IN==:{$}\n", strtemp);
  2064. return PACKET_ISPACKET;
  2065. }
  2066. }
  2067. return PACKET_NOPACKET;
  2068. }
  2069. //-----------------------------------------------------------------------------
  2070. // DecodeFrame
  2071. //-----------------------------------------------------------------------------
  2072. static bool DecodeFrame(const char* strFrame, int length)
  2073. {
  2074. auto pr = [strFrame, length](const tFrameMapping& Item)
  2075. {
  2076. for (int i = 0; i < Item.NbOfCharOfHead; i++)
  2077. {
  2078. if (strFrame[i] != Item.strHead[i])
  2079. {
  2080. return false;
  2081. }
  2082. }
  2083. return true;
  2084. };
  2085. auto found = std::find_if(arFrame.begin(), arFrame.end(), pr);
  2086. if (found == arFrame.end())
  2087. {
  2088. return false;
  2089. }
  2090. const auto& Item = *found;
  2091. auto pc = strFrame;
  2092. pc += Item.NbOfCharOfHead;
  2093. Item.fun(pc, length - Item.NbOfCharOfHead);
  2094. return true;
  2095. }
  2096. //-----------------------------------------------------------------------------
  2097. // GetIODriver & CreateIODriver
  2098. //-----------------------------------------------------------------------------
  2099. static nsGEN::REMEDYDriver gIODriver;
  2100. extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  2101. {
  2102. return &gIODriver;
  2103. }
  2104. extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  2105. {
  2106. return new nsGEN::REMEDYDriver();
  2107. }