DIOS.Dev.Generator.HaoWei.cpp 63 KB

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