CCOS.Dev.Generator.PSG_HR.cpp 96 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017
  1. // CCOS.Dev.GEN.PSGHR.cpp
  2. #include <assert.h>
  3. #include <functional>
  4. #include <unordered_map>
  5. #include <fstream>
  6. #include "LogicDevice.h"
  7. using namespace std::placeholders;
  8. #include "Helper.JSON.hpp"
  9. #include "CCOS.Dev.Generator.PSG_HR.h"
  10. #include "LogLocalHelper.h"
  11. #include "Log4CPP.h"
  12. using namespace CCOS::Dev::Detail::Generator;
  13. namespace nsGEN = CCOS::Dev::Detail::Generator;
  14. static nsGEN::PSGHRDriver* pIODriver = nullptr;
  15. #define PSGHR_LARGE_POWER 5
  16. #define PSGHR_SMALL_POWER 1.1
  17. #define PSGHR_MAX_HEAT 225
  18. #define PSGHR_MIN_MA 1.0
  19. #define PSGHR_MAX_MA 1000.0
  20. #define PSGHR_MIN_MS 1.0
  21. #define PSGHR_MAX_MS 10001.0
  22. #define PSGHR_LoopDefHBTime 1000
  23. #define PSGHR_LoopExpHBTime 500
  24. static const int msTimeOut_Lock = 500;
  25. #define PSGHR_Com_NormalLen 150
  26. #define PSGHR_ETX 0x03
  27. #define PSGHR_RESOK "$"
  28. #define Sleep(ms) std::this_thread::sleep_for(std::chrono::milliseconds(ms))
  29. static const auto COM_SCFDllName = "libSerialSCF.so";
  30. static const auto TCP_SCFDllName = "libTcpipSCF.so";
  31. //Log4CPP::Logger* gLogger = nullptr;
  32. struct tFrameMapping
  33. {
  34. static const int MaxLen = 5;
  35. using cbFun = std::function <void(const char*, int)>;
  36. char strHead[MaxLen];
  37. int NbOfCharOfHead;
  38. cbFun fun;
  39. tFrameMapping(const char* str, int len, cbFun f)
  40. {
  41. assert(len < MaxLen);
  42. for (int i = 0; i < len; i++)
  43. strHead[i] = str[i];
  44. NbOfCharOfHead = len;
  45. fun = f;
  46. }
  47. };
  48. static std::list <tFrameMapping> arFrame;
  49. static bool DecodeFrame(const char* strFrame, int length)
  50. {
  51. auto pr = [strFrame, length](const tFrameMapping& Item)
  52. {
  53. for (int i = 0; i < Item.NbOfCharOfHead; i++)
  54. {
  55. if (strFrame[i] != Item.strHead[i])
  56. {
  57. return false;
  58. }
  59. }
  60. return true;
  61. };
  62. auto found = std::find_if(arFrame.begin(), arFrame.end(), pr);
  63. if (found == arFrame.end())
  64. {
  65. return false;
  66. }
  67. const auto& Item = *found;
  68. auto pc = strFrame;
  69. char data[100] = { 0 };
  70. // 找到ETX位置(0x03)
  71. int etxPos = -1;
  72. for (int i = Item.NbOfCharOfHead; i < length - 1; i++) // length-1是因为最后一个字节是校验和
  73. {
  74. if (strFrame[i] == 0x03)
  75. {
  76. etxPos = i;
  77. break;
  78. }
  79. }
  80. // 计算Data部分的长度
  81. int dataLength = 0;
  82. if (etxPos != -1)
  83. {
  84. // Data长度 = ETX位置 - Command长度
  85. dataLength = etxPos - Item.NbOfCharOfHead;
  86. }
  87. else
  88. {
  89. // 如果没找到ETX,假设Data部分到倒数第二个字节(排除校验和)
  90. dataLength = length - Item.NbOfCharOfHead - 1;
  91. }
  92. // 只复制Data部分
  93. if (dataLength > 0 && dataLength < 100)
  94. {
  95. memcpy(data, strFrame + Item.NbOfCharOfHead, dataLength);
  96. }
  97. Item.fun(data, dataLength);
  98. return true;
  99. }
  100. //-----------------------------------------------------------------------------
  101. // PSGHRDevice
  102. //-----------------------------------------------------------------------------
  103. atomic<int> nsGEN::PSGHRDevice::m_iLoopTime = PSGHR_LoopDefHBTime;
  104. atomic<bool> nsGEN::PSGHRDevice::m_bExtraFlag = false;
  105. static atomic<bool>HeartBeatFlag = false;
  106. nsGEN::PSGHRDevice::PSGHRDevice(std::shared_ptr <IOEventCenter> center, std::shared_ptr<SCFWrapper> SCF, string configfile)
  107. : super(center)
  108. , superGen()
  109. , m_SCF(SCF)
  110. , m_bConnectFlag(false)
  111. , HeartBeatFlag(false)
  112. {
  113. assert(EventCenter);
  114. m_bExtraFlag = true;
  115. //��ʼ��
  116. m_bExpEnable = false;
  117. m_bConnectFlag = true;
  118. m_iLoopTime.store(PSGHR_LoopDefHBTime);
  119. for (int i = 0; i < 18; i++)
  120. {
  121. m_bFaultList[i] = false;
  122. }
  123. m_iMaxPower = PSGHR_LARGE_POWER; //KW
  124. MaxHeatContent = PSGHR_MAX_HEAT; //KJ
  125. string version;
  126. //if(GetVersion(version, hMyModule))
  127. FINFO("\n===============log begin : version:{$} ===================\n", version.c_str());
  128. //else
  129. FINFO("\n===============log begin : version:0.0.0.0 ===================\n");
  130. //���÷��������Լ��ϸ���ֵ�ķ�Χ������
  131. m_DoseUnit.m_KV.reset(new KVMould(0.0, 39.0, 151.0, 1.0));
  132. m_DoseUnit.m_MA.reset(new MAMould(0.0, PSGHR_MIN_MA, PSGHR_MAX_MA, 0.1));
  133. m_DoseUnit.m_MS.reset(new MSMould(0.0, PSGHR_MIN_MS, PSGHR_MAX_MS, 0.01));
  134. m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.1, 1000.0, 0.01));
  135. m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_AEC_MAS_MA, 1));
  136. m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
  137. m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_TYPE::FOCUS_LARGE, AttrKey::FOCUS_SMALL, AttrKey::FOCUS_LARGE, 1));
  138. m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
  139. m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
  140. m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -3, 3, 1));
  141. m_DoseUnit.m_GenHE.reset(new GENHEATMould(0, 0, 100, 1));
  142. m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
  143. m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
  144. m_DoseUnit.m_GenState.reset(new GENSTATEMould(0, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
  145. m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
  146. m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
  147. m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
  148. m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
  149. m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
  150. m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single));
  151. m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 16, 1));
  152. m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
  153. m_DoseUnit.m_BatteryChargeState.reset(new BATTERYCHARGSTATEMould(0, 0, 1, 1));
  154. m_DoseUnit.m_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(AttrKey::TUBETARGETMATERIAL_TYPE::MO));
  155. m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0, -45, 45, 1));
  156. m_DoseUnit.m_FLIntTime.reset(new FLUIntTimeMould(0.0, 0.0, 100.0, 0.1));
  157. m_DoseUnit.m_FLAccTime.reset(new FLAccTimeMould(0.0, 0.0, 999.0, 0.1));
  158. m_DoseUnit.m_FLKV.reset(new FLUKVMould(0, 40, 125, 1));
  159. m_DoseUnit.m_FLMS.reset(new FLUMSMould(10.0, 10.0, 999999.0, 0.01));
  160. m_DoseUnit.m_FLMA.reset(new FLUMAMould(0.5, 0.5, 99.0, 0.1));
  161. m_DoseUnit.m_ABSStatus.reset(new FLUABSStatusMould(0, 0, 2, 1));
  162. m_DoseUnit.m_PPS.reset(new PPSMould(0.5,0.5, 30, 0.1));
  163. m_DoseUnit.m_DoseLevel.reset(new FLUDoseLevelMould(0, 0, 2, 1));
  164. m_DoseUnit.m_FLMode.reset(new FLUModeMould(0, 0, 4, 1));
  165. m_DoseUnit.m_Curve.reset(new FLUCurveMould(0, 0, 3, 1));
  166. //Actual exposure parameters ֵ
  167. m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 40.0, 120.0, 1.0));
  168. m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 1.0, 1000.0, 0.1));
  169. m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 1.0, 10000.0, 0.01));
  170. m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.5, 1000.0, 0.01));
  171. //�������澯��������Ϣ
  172. m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
  173. m_hGenPostEvent = LinuxEvent::CreateEvent(LinuxEvent::MANUAL_RESET, false);
  174. //������Ӧ�������ձ� ���������ش������ݴ�����Ӧ�IJ���
  175. OnCallBack();
  176. //�����������Զ����ṩ��ָ��ע�Ἧ���в���
  177. Register();
  178. LoadConfig(configfile);
  179. //����Ӳ��״̬��ѯ����
  180. StartHardwareStatusThread();
  181. }
  182. nsGEN::PSGHRDevice::~PSGHRDevice()
  183. {
  184. m_bExtraFlag = false;
  185. if (m_pHardwareStatusThread.joinable()) {
  186. m_pHardwareStatusThread.join();
  187. }
  188. FINFO("\n===============log end ===================\n");
  189. arFrame.clear();
  190. }
  191. std::string nsGEN::PSGHRDevice::GetGUID() const
  192. {
  193. FINFO("===============GetGUID : {$} ===================\n", GeneratorUnitType);
  194. return GeneratorUnitType;
  195. }
  196. void nsGEN::PSGHRDevice::Register()
  197. {
  198. auto Disp = m_Dispatch.Lock().As();
  199. superGen::Register(Disp);
  200. superGen::RegisterRAD(Disp);
  201. superGen::RegisterAEC(Disp);
  202. superGen::RegisterExpEnable(Disp);
  203. superGen::RegisterGeneratortoSyncStatus(Disp);
  204. superGen::RegisterFluoro(Disp);
  205. Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  206. Disp->Get.Push(AttrKey::DENHEAT, [this](std::string& out) { out = m_DoseUnit.m_GenHE->JSGet(); return RET_STATUS::RET_SUCCEED; });
  207. auto fun_Clear_DAP = [this](auto in, auto& out)
  208. {
  209. return Clear_DAP();
  210. };
  211. Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
  212. auto fun_GetValue_DAP = [this](auto in, auto& out)
  213. {
  214. float value = 0;
  215. RET_STATUS ret = GetValue_DAP(value);
  216. out = ToJSON(value);
  217. return ret;
  218. };
  219. Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
  220. }
  221. RET_STATUS nsGEN::PSGHRDevice::IncKV()
  222. {
  223. FINFO("Enter PSGHRDevice::IncKV()\n");
  224. if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
  225. return HWSend("KV+", 3);
  226. }
  227. RET_STATUS nsGEN::PSGHRDevice::DecKV()
  228. {
  229. if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
  230. return HWSend("KV-", 3);
  231. }
  232. RET_STATUS nsGEN::PSGHRDevice::SetKV(float value)
  233. {
  234. if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
  235. char temp[50] = { 0 };
  236. snprintf(temp, sizeof(temp), "KV%03d", (int)value);
  237. return HWSend(temp, strlen(temp));
  238. }
  239. RET_STATUS nsGEN::PSGHRDevice::IncMA()
  240. {
  241. if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
  242. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  243. {
  244. FINFO("\n Techmode is MAS, can't inc MA");
  245. return RET_STATUS::RET_FAILED;
  246. }
  247. return HWSend("MA+",3);
  248. }
  249. RET_STATUS nsGEN::PSGHRDevice::DecMA()
  250. {
  251. if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
  252. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  253. {
  254. FINFO("\n Techmode is MAS, can't dec MA");
  255. return RET_STATUS::RET_FAILED;
  256. }
  257. return HWSend("MA-", 3);
  258. }
  259. RET_STATUS nsGEN::PSGHRDevice::SetMA(float value)
  260. {
  261. if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  262. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  263. {
  264. FINFO("\n Techmode is MAS, can't set MA");
  265. return RET_STATUS::RET_FAILED;
  266. }
  267. char temp[50] = { 0 };
  268. snprintf(temp, sizeof(temp), "MA%05d", (int)(value * 10));
  269. return HWSend(temp, strlen(temp));
  270. }
  271. RET_STATUS nsGEN::PSGHRDevice::IncMS()
  272. {
  273. FINFO("nsGEN::PSGHRDevice::IncMS()\n");
  274. if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
  275. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  276. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  277. {
  278. FINFO("Techmode is 2Point, Cannot inc MS \n");
  279. return RET_STATUS::RET_FAILED;
  280. }
  281. return HWSend("MS+",3);
  282. }
  283. RET_STATUS nsGEN::PSGHRDevice::DecMS()
  284. {
  285. if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
  286. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  287. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  288. {
  289. FINFO("Techmode is 2Point, Cannot dec MS \n");
  290. return RET_STATUS::RET_FAILED;
  291. }
  292. return HWSend("MS-", 3);;
  293. }
  294. RET_STATUS nsGEN::PSGHRDevice::SetMS(float value)
  295. {
  296. if (!m_DoseUnit.m_MS->Verify(value)) return RET_STATUS::RET_SUCCEED;
  297. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  298. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  299. {
  300. FINFO("Techmode is 2Point, Cannot set MS \n");
  301. return RET_STATUS::RET_FAILED;
  302. }
  303. char temp[50] = { 0 };
  304. snprintf(temp, sizeof(temp), "MS%07d", (int)(value * 100));
  305. return HWSend(temp,strlen(temp));
  306. }
  307. RET_STATUS nsGEN::PSGHRDevice::IncMAS()
  308. {
  309. FINFO("nsGEN::PSGHRDevice::IncMAS()\n");
  310. if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
  311. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  312. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  313. {
  314. FINFO("Techmode is 3Point, Cannot inc MAS \n");
  315. return RET_STATUS::RET_FAILED;
  316. }
  317. return HWSend("MX+" , 3);
  318. }
  319. RET_STATUS nsGEN::PSGHRDevice::DecMAS()
  320. {
  321. if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
  322. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  323. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  324. {
  325. FINFO("Techmode is 3Point, Cannot dec MAS \n");
  326. return RET_STATUS::RET_FAILED;
  327. }
  328. return HWSend("MX-", 3);
  329. }
  330. RET_STATUS nsGEN::PSGHRDevice::SetMAS(float value)
  331. {
  332. if (!m_DoseUnit.m_MAS->Verify(value)) return RET_STATUS::RET_SUCCEED;
  333. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  334. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  335. {
  336. FINFO("Techmode is 3Point, Cannot set MAS \n");
  337. return RET_STATUS::RET_FAILED;
  338. }
  339. char temp[50] = { 0 };
  340. snprintf(temp, sizeof(temp), "MX%06d", (int)(value * 100));
  341. return HWSend(temp, strlen(temp));
  342. }
  343. RET_STATUS nsGEN::PSGHRDevice::SetTechmode(int value)
  344. {
  345. if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
  346. char temp[50] = { 0 };
  347. snprintf(temp, sizeof(temp), "ET%1d", (int)value);
  348. return HWSend(temp, strlen(temp));
  349. }
  350. RET_STATUS nsGEN::PSGHRDevice::SetEXAMMode(std::string value)
  351. {
  352. //�ϲ��������exam mode��manual semiauto automatic����Ӧ��NoAEC2Point AEC2Point AEC2Point��
  353. FINFO("Enter setexammode func value = {$}\n", value);
  354. if (value == AttrKey::EXAMMODE_TYPE::MANUAL)
  355. {
  356. SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P);
  357. }
  358. else if (value == AttrKey::EXAMMODE_TYPE::SEMIAUTO)
  359. {
  360. SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  361. }
  362. else if (value == AttrKey::EXAMMODE_TYPE::AUTOMATIC)
  363. {
  364. SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  365. }
  366. return RET_STATUS::RET_SUCCEED;
  367. }
  368. RET_STATUS nsGEN::PSGHRDevice::SetAPR(const _tAPRArgs& t)
  369. {
  370. m_bGenBusy = true;
  371. FINFO("APR:KV={$},MA={$},MS={$},MAS={$},Focus={$},Techmode={$},WS={$},AECDensity={$},AECField={$},AECFilm={$}", t.fKV, t.fMA, t.fMS, t.fMAS, t.nFocus, t.nTechmode, t.nWS, t.nAECDensity, t.nAECField, t.nAECFilm);
  372. if (t.nFocus < 0)
  373. {
  374. FINFO("SetAPR: the focus value is amall than 0, set focus to small focus\n");
  375. SetFocus(0);
  376. }
  377. int nTempAECFilm = 1;
  378. switch (t.nAECFilm)
  379. {
  380. case 0:
  381. nTempAECFilm = 1;
  382. break;
  383. case 1:
  384. nTempAECFilm = 10;
  385. break;
  386. case 2:
  387. nTempAECFilm = 100;
  388. break;
  389. default:
  390. break;
  391. }
  392. SetKV(t.fKV);
  393. SetFocus(t.nFocus);
  394. if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_AEC)
  395. {
  396. // aec
  397. SetTechmode(t.nTechmode);
  398. Sleep(50);
  399. SetAECField(t.nAECField);
  400. Sleep(80);
  401. SetAECDensity(t.nAECDensity);
  402. Sleep(50);
  403. SetAECFilm(nTempAECFilm);
  404. Sleep(50);
  405. SetMA(t.fMA);
  406. Sleep(50);
  407. SetMS(t.fMS);
  408. }
  409. else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  410. {
  411. // mas
  412. SetTechmode(t.nTechmode);
  413. Sleep(50);
  414. const float EPSINON = 0.000001;
  415. if ((t.fMAS >= -EPSINON) && (t.fMAS <= EPSINON))
  416. {
  417. SetMAS(t.fMA * t.fMS / 1000);
  418. }
  419. else
  420. {
  421. SetMAS(t.fMAS);
  422. }
  423. }
  424. else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_TIME)
  425. {
  426. // time
  427. SetTechmode(t.nTechmode);
  428. Sleep(50);
  429. SetMA(t.fMA);
  430. Sleep(80);
  431. SetMS(t.fMS);
  432. }
  433. m_bGenBusy = false;
  434. HWSend("RR", 2);
  435. ///////////////////////end
  436. return RET_STATUS::RET_SUCCEED;
  437. }
  438. RET_STATUS nsGEN::PSGHRDevice::RefreshData()
  439. {
  440. if (!m_bGenBusy)
  441. {
  442. HWSend("RR", 2);
  443. Sleep(50);
  444. HWSend("RS", 2);
  445. }
  446. return RET_STATUS::RET_SUCCEED;
  447. }
  448. RET_STATUS nsGEN::PSGHRDevice::SetFocus(int value)
  449. {
  450. if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
  451. char temp[50] = { 0 };
  452. snprintf(temp, sizeof(temp), "FO%01d", (int)value);
  453. return HWSend(temp,strlen(temp));
  454. }
  455. RET_STATUS nsGEN::PSGHRDevice::Reset()
  456. {
  457. FDEBUG("clear all errors \n");
  458. int level = 0;
  459. m_MSGUnit->DelErrorMessage("0", level, "clear all errors");
  460. m_MSGUnit->DelWarnMessage("0", level, "clear all Warning");
  461. HWSend("RE",2);//�����ô���״̬
  462. return RET_STATUS::RET_SUCCEED;
  463. }
  464. RET_STATUS nsGEN::PSGHRDevice::ActiveSyncMode(_tSyncModeArgs value)
  465. {
  466. FINFO("value.strSyncMode: {$}, value.strSyncValue: {$}, value.strWS: {$} \n", value.strSyncMode, value.strSyncValue, value.strWS);
  467. int nSyncModeValue = atoi(value.strSyncValue.c_str());
  468. char temp[50] = { 0 };
  469. snprintf(temp, sizeof(temp), "WS%01d", nSyncModeValue);
  470. return HWSend(temp, strlen(temp));
  471. }
  472. RET_STATUS nsGEN::PSGHRDevice::QueryHE(int& value)
  473. {
  474. if (!m_bGenBusy)
  475. return HWSend("HE?", 3);
  476. return RET_STATUS::RET_SUCCEED;
  477. }
  478. void nsGEN::PSGHRDevice::SubscribeSelf(ccos_mqtt_connection* conn)
  479. {
  480. //����GEN����Action
  481. //SubscribeTopic(conn, "CCOS/DEVICE/Generator/Action/#"); Moduld��Ĭ�϶��������Action��������Ҳ���ĵĻ��ͻ�ִ������Action�����ܻ������
  482. }
  483. RET_STATUS nsGEN::PSGHRDevice::SetVibrationGrid(int value)
  484. {
  485. FINFO("Enter StartVibrationGrid:[{$}]", value);
  486. return RET_STATUS::RET_SUCCEED;
  487. }
  488. RET_STATUS nsGEN::PSGHRDevice::GetVibrationGridMS(int& value)
  489. {
  490. return RET_STATUS::RET_SUCCEED;
  491. }
  492. RET_STATUS nsGEN::PSGHRDevice::SetAECDensity(int value)
  493. {
  494. if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED;
  495. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC) return RET_STATUS::RET_FAILED;
  496. int nAECDensity = m_DoseUnit.m_AECDensity->Get();
  497. if (value < m_DoseUnit.m_AECDensity->Get())
  498. {
  499. if (value < m_DoseUnit.m_AECDensity->Get() - 1)
  500. {
  501. nAECDensity = (int)value;
  502. }
  503. else
  504. {
  505. nAECDensity = nAECDensity - 1;
  506. }
  507. }
  508. else if (value > m_DoseUnit.m_AECDensity->Get())
  509. {
  510. if (value > m_DoseUnit.m_AECDensity->Get() + 1)
  511. {
  512. nAECDensity = (int)value;
  513. }
  514. else
  515. {
  516. nAECDensity = nAECDensity + 1;
  517. }
  518. }
  519. m_DoseUnit.m_AECDensity->Update(value);
  520. char temp[50] = { 0 };
  521. if (nAECDensity >= 0)
  522. {
  523. snprintf(temp, sizeof(temp), "FN+%01d", (int)nAECDensity);
  524. }
  525. else
  526. {
  527. snprintf(temp, sizeof(temp), "FN-%01d", (int)nAECDensity);
  528. }
  529. return HWSend(temp, strlen(temp));
  530. }
  531. RET_STATUS nsGEN::PSGHRDevice::SetAECField(int value)
  532. {
  533. if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
  534. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) return RET_STATUS::RET_FAILED;
  535. m_DoseUnit.m_AECField->Update(value);
  536. char temp[50] = { 0 };
  537. snprintf(temp, sizeof(temp), "FI%03d", (int)value);
  538. return HWSend(temp, strlen(temp));
  539. }
  540. RET_STATUS nsGEN::PSGHRDevice::SetAECFilm(int value)
  541. {
  542. if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
  543. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) return RET_STATUS::RET_FAILED;
  544. m_DoseUnit.m_AECFilm->Update(value);
  545. char temp[50] = { 0 };
  546. snprintf(temp, sizeof(temp), "FS%03d", (int)value);
  547. return HWSend(temp, strlen(temp));
  548. }
  549. RET_STATUS nsGEN::PSGHRDevice::SetWS(const string value)
  550. {
  551. FINFO("Enter SetWS {$}", value);
  552. int tempws = 0;
  553. if (value == "Table") tempws = (int)m_GenConfig["WSTable"];
  554. else if (value == "Wall") tempws = (int)m_GenConfig["WSWall"];
  555. else if (value == "Direct") tempws = (int)m_GenConfig["WSConventional"];
  556. else if (value == "Free") tempws = (int)m_GenConfig["WSFree"];
  557. else if (value == "Tomo") tempws = (int)m_GenConfig["WSTomo"];
  558. m_DoseUnit.m_WS->Update(tempws);
  559. char temp[50] = { 0 };
  560. snprintf(temp, sizeof(temp), "WS%01d", tempws);
  561. return HWSend(temp, strlen(temp));
  562. }
  563. RET_STATUS nsGEN::PSGHRDevice::QueryPostKV(float& value)
  564. {
  565. m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
  566. value = m_DoseUnit.m_PostKV->Get();
  567. return HWSend("VP?",3);
  568. }
  569. RET_STATUS nsGEN::PSGHRDevice::QueryPostMA(float& value)
  570. {
  571. return HWSend("PA?", 3);
  572. }
  573. RET_STATUS nsGEN::PSGHRDevice::QueryPostMS(float& value)
  574. {
  575. return HWSend("AT?",3);
  576. }
  577. RET_STATUS nsGEN::PSGHRDevice::QueryPostMAS(float& value)
  578. {
  579. return HWSend("AP?", 3);
  580. }
  581. RET_STATUS nsGEN::PSGHRDevice::Clear_DAP()
  582. {
  583. return RET_STATUS::RET_SUCCEED;
  584. }
  585. RET_STATUS nsGEN::PSGHRDevice::GetValue_DAP(float& value)
  586. {
  587. return RET_STATUS::RET_SUCCEED;
  588. }
  589. RET_STATUS nsGEN::PSGHRDevice::StartMove() //�������޴�����
  590. {
  591. return RET_STATUS::RET_SUCCEED;
  592. }
  593. RET_STATUS nsGEN::PSGHRDevice::EndMove() //�������޴�����
  594. {
  595. return RET_STATUS::RET_SUCCEED;
  596. }
  597. RET_STATUS nsGEN::PSGHRDevice::SetGenSynState(int value)
  598. {
  599. FINFO("Enter SetGenSynState...{$} \n", value);
  600. //if (AttrKey::GENERATOR_RAD_XRAYON == value)
  601. //{
  602. // FINFO("SetGenSynState be call.this is soft syn mode.");
  603. // HWSend("XR2",3);
  604. // m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
  605. // FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  606. //}
  607. //else if(AttrKey::GENERATOR_FLU_XRAYON == value)
  608. //{
  609. // FINFO("SetGenSynState be call.this is soft syn mode.");
  610. // //HWSend("FLX2", 4);
  611. // //m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYON);
  612. // //FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  613. //}
  614. return RET_STATUS::RET_SUCCEED;
  615. }
  616. RET_STATUS nsGEN::PSGHRDevice::SetGenState(int value)
  617. {
  618. return RET_STATUS::RET_SUCCEED;
  619. }
  620. RET_STATUS nsGEN::PSGHRDevice::SetExpMode(std::string value)
  621. {
  622. FINFO("Enter SetExpMode...{$} \n",value.c_str());
  623. m_DoseUnit.m_ExpMode->Update(value);
  624. //add for dcm iRF hard
  625. FINFO("SetExpMode:add for dcm iRF hard");
  626. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  627. FireNotify(m_DoseUnit.m_TubeTargetMaterial->GetKey(), m_DoseUnit.m_TubeTargetMaterial->JSGet());
  628. FireNotify(m_DoseUnit.m_TubeAngle->GetKey(), m_DoseUnit.m_TubeAngle->JSGet());
  629. return RET_STATUS::RET_SUCCEED;
  630. }
  631. RET_STATUS nsGEN::PSGHRDevice::SetFLFMode(std::string value)
  632. {
  633. FINFO("Enter SetFLFMode...{$} \n", value.c_str());
  634. if (value == "CF")
  635. {
  636. m_DoseUnit.m_FLMode->Update(1);
  637. HWSend("FLF1", 4);
  638. SetPPS(15);
  639. SetPluseWidth(15);
  640. }
  641. else if (value == "PF")
  642. {
  643. m_DoseUnit.m_FLMode->Update(2);
  644. HWSend("FLF2", 4);
  645. SetPPS(5);
  646. SetPluseWidth(5);
  647. }
  648. else
  649. {
  650. FINFO("other FluMode : {$}", value.c_str());
  651. return RET_STATUS::RET_SUCCEED;
  652. }
  653. return RET_STATUS::RET_SUCCEED;
  654. }
  655. RET_STATUS nsGEN::PSGHRDevice::SetFLLever(float value)
  656. {
  657. FINFO("Enter SetFLLever...{$} \n", value);
  658. m_DoseUnit.m_DoseLevel->Update(value);
  659. char temp[50]{ 0 };
  660. snprintf(temp, sizeof(temp), "FLD%f", value);
  661. return HWSend(temp, strlen(temp));
  662. }
  663. RET_STATUS nsGEN::PSGHRDevice::SetFrameRate(float frameRate)
  664. {
  665. FINFO("SetFrameRate in\n");
  666. /*m_DoseUnit.m_FrameRate->Update(frameRate);
  667. char temp[50]{ 0 };
  668. snprintf(temp, sizeof(temp), "FLS%03d", int(frameRate * 10));
  669. return HWSend(temp, strlen(temp));*/
  670. return RET_STATUS::RET_SUCCEED;
  671. }
  672. RET_STATUS nsGEN::PSGHRDevice::SetRPS(int rps) //�������޴˶�̬����
  673. {
  674. return RET_STATUS::RET_SUCCEED;
  675. }
  676. RET_STATUS nsGEN::PSGHRDevice::SetAPF(const _tAPFArgs& t)
  677. {
  678. m_bGenBusy = true;
  679. FINFO("APF:FLKV={$},FLMA={$},PPS={$},WS={$},FLuType={$},ABSMode={$},DoseLever={$}", t.nFLKV, t.fFLMA, t.nPPS, t.nWS, t.nFluMode, t.nABSMode, t.nDoseLever);
  680. SetABSMode(t.nABSMode);
  681. Sleep(50);
  682. SetFLFMode(to_string(t.nFluMode));
  683. Sleep(50);
  684. SetFluDoseLever(t.nDoseLever);
  685. Sleep(50);
  686. SetFluKV(t.nFLKV);
  687. Sleep(50);
  688. SetFluMA(t.fFLMA);
  689. m_bGenBusy = false;
  690. return RET_STATUS::RET_SUCCEED;
  691. }
  692. RET_STATUS nsGEN::PSGHRDevice::IncFluKV()
  693. {
  694. FINFO("nsGEN::PSGHRDevice::IncFLKV()\n");
  695. if (!m_DoseUnit.m_FLKV->CanInc()) return RET_STATUS::RET_SUCCEED;
  696. return HWSend("FLK+", 4);
  697. }
  698. RET_STATUS nsGEN::PSGHRDevice::DecFluKV()
  699. {
  700. if (!m_DoseUnit.m_FLKV->CanDec()) return RET_STATUS::RET_SUCCEED;
  701. return HWSend("FLK-", 4);
  702. }
  703. RET_STATUS nsGEN::PSGHRDevice::SetFluKV(float value)
  704. {
  705. if (!m_DoseUnit.m_FLKV->Verify(value)) return RET_STATUS::RET_SUCCEED;
  706. char temp[50] = { 0 };
  707. snprintf(temp, sizeof(temp), "FLK%03d", (int)value);
  708. return HWSend(temp, strlen(temp));
  709. }
  710. RET_STATUS nsGEN::PSGHRDevice::IncFluMA()
  711. {
  712. if (!m_DoseUnit.m_FLMA->CanInc()) return RET_STATUS::RET_SUCCEED;
  713. return HWSend("FLM+", 4);
  714. }
  715. RET_STATUS nsGEN::PSGHRDevice::DecFluMA()
  716. {
  717. if (!m_DoseUnit.m_FLMA->CanDec()) return RET_STATUS::RET_SUCCEED;
  718. return HWSend("FLM-", 4);
  719. }
  720. RET_STATUS nsGEN::PSGHRDevice::SetFluMA(float value)
  721. {
  722. if (!m_DoseUnit.m_FLMA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  723. char temp[50] = { 0 };
  724. snprintf(temp, sizeof(temp), "FLM%03d", (int)(value * 10));
  725. return HWSend(temp, strlen(temp));
  726. }
  727. RET_STATUS nsGEN::PSGHRDevice::INCPPS()
  728. {
  729. if (!m_DoseUnit.m_PPS->CanInc()) return RET_STATUS::RET_SUCCEED;
  730. return HWSend("FLS+", 4);
  731. }
  732. RET_STATUS nsGEN::PSGHRDevice::DECPPS()
  733. {
  734. if (!m_DoseUnit.m_PPS->CanDec()) return RET_STATUS::RET_SUCCEED;
  735. return HWSend("FLS-", 4);
  736. }
  737. RET_STATUS nsGEN::PSGHRDevice::SetPPS(float value)
  738. {
  739. if (!m_DoseUnit.m_PPS->Verify(value)) return RET_STATUS::RET_SUCCEED;
  740. char temp[50] = { 0 };
  741. snprintf(temp, sizeof(temp), "FLS%03d", (int)(value * 10));
  742. return HWSend(temp, strlen(temp));
  743. }
  744. RET_STATUS nsGEN::PSGHRDevice::SetABSMode(int nMode)
  745. {
  746. if (!m_DoseUnit.m_ABSStatus->Verify(nMode)) return RET_STATUS::RET_SUCCEED;
  747. char temp[50] = { 0 };
  748. FINFO("SetABSMode[{$}] \n", nMode);
  749. snprintf(temp, sizeof(temp), "FLA%d", (int)nMode);
  750. return HWSend(temp, strlen(temp));
  751. }
  752. RET_STATUS nsGEN::PSGHRDevice::SetABSCurve(int curveNum)
  753. {
  754. return RET_STATUS::RET_SUCCEED;
  755. }
  756. RET_STATUS nsGEN::PSGHRDevice::IncABSCurve()
  757. {
  758. return RET_STATUS::RET_SUCCEED;
  759. }
  760. RET_STATUS nsGEN::PSGHRDevice::DecABSCurve()
  761. {
  762. return RET_STATUS::RET_SUCCEED;
  763. }
  764. RET_STATUS nsGEN::PSGHRDevice::GetABSCurve()
  765. {
  766. return HWSend("FLA?", 4);
  767. }
  768. float nsGEN::PSGHRDevice::GetFluIntTimer()
  769. {
  770. return HWSend("FLI?", 4);
  771. }
  772. float nsGEN::PSGHRDevice::GetFluAccTimer()
  773. {
  774. return HWSend("FLT?", 4);
  775. }
  776. RET_STATUS nsGEN::PSGHRDevice::ResetFluTimer(int value)
  777. {
  778. char temp[50] = { 0 };
  779. snprintf(temp, sizeof(temp), "FLR%d", (int)value);
  780. FINFO("ReSetFluAccTimer[{$}] \n", value);
  781. return HWSend(temp, strlen(temp));
  782. }
  783. RET_STATUS nsGEN::PSGHRDevice::SetFluPre(int value)
  784. {
  785. return RET_STATUS::RET_SUCCEED;
  786. }
  787. RET_STATUS nsGEN::PSGHRDevice::SetFluEXP(int value)
  788. {
  789. return RET_STATUS::RET_SUCCEED;
  790. }
  791. RET_STATUS nsGEN::PSGHRDevice::SetFluMode(std::string value)
  792. {
  793. FINFO("Enter SetFLFMode...{$} \n", value.c_str());
  794. if (value == "CF")
  795. {
  796. m_DoseUnit.m_FLMode->Update(1);
  797. return HWSend("FLF1", 4);
  798. }
  799. else if (value == "PF")
  800. {
  801. m_DoseUnit.m_FLMode->Update(2);
  802. return HWSend("FLF2", 4);
  803. }
  804. else
  805. {
  806. FINFO("other FluMode : {$}",value.c_str());
  807. return RET_STATUS::RET_SUCCEED;
  808. }
  809. }
  810. RET_STATUS nsGEN::PSGHRDevice::SetFluDoseLever(int value)
  811. {
  812. FINFO("Enter SetFluDoseLever...{$} \n", value);
  813. m_DoseUnit.m_DoseLevel->Update(value);
  814. char temp[50]{ 0 };
  815. snprintf(temp, sizeof(temp), "FLD%d", value);
  816. return HWSend(temp, strlen(temp));
  817. }
  818. RET_STATUS nsGEN::PSGHRDevice::SetPluseWidth(float fplusewidth)
  819. {
  820. if (!m_DoseUnit.m_PPS->Verify(fplusewidth)) return RET_STATUS::RET_SUCCEED;
  821. char temp[50] = { 0 };
  822. snprintf(temp, sizeof(temp), "FLW%05d", (int)(fplusewidth * 100));
  823. return HWSend(temp, strlen(temp));
  824. }
  825. RET_STATUS nsGEN::PSGHRDevice::SetExpEnable()
  826. {
  827. if (1 == m_bUseCECmd)
  828. {
  829. HWSend("CE1", 3);
  830. }
  831. HWSend("ST?", 3);
  832. FINFO("SetExpEnable in\n");
  833. m_bExpEnable = true;
  834. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  835. return RET_STATUS::RET_SUCCEED;
  836. }
  837. RET_STATUS nsGEN::PSGHRDevice::SetExpDisable()
  838. {
  839. if (1 == m_bUseCECmd)
  840. {
  841. HWSend("CE0", 3);
  842. }
  843. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  844. FINFO("SetExpDisable in\n");
  845. m_bExpEnable = false;
  846. return RET_STATUS::RET_SUCCEED;
  847. }
  848. RET_STATUS nsGEN::PSGHRDevice::PrepareAcquisition()
  849. {
  850. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  851. return RET_STATUS::RET_SUCCEED;
  852. }
  853. void nsGEN::PSGHRDevice::SetSmartAEC(int value)
  854. {
  855. }
  856. //-----------------------------------------------------------------------------
  857. // ProcessCmd
  858. //-----------------------------------------------------------------------------
  859. void nsGEN::PSGHRDevice::ProcessClientData(const char* pData, unsigned long nDataLength, void* lparam)
  860. {
  861. PSGHRDevice* pCurGen = (PSGHRDevice*)lparam;
  862. pCurGen->HWSend(pData, nDataLength);
  863. }
  864. RET_STATUS nsGEN::PSGHRDevice::HWSend(const char* strCommand,int lengh, bool reSend, int nTimeOut)
  865. {
  866. if (!m_bConnectFlag)
  867. {
  868. FERROR("==OUT==: not Connect,[{$}] send failed \n", strCommand);
  869. return RET_STATUS::RET_FAILED;
  870. }
  871. if (!m_SCF) return RET_STATUS::RET_FAILED;
  872. char strSendCommand[100] = { 0 };
  873. int len = strlen(strCommand);
  874. int tmpSum = 0;
  875. for (int i = 0; i < len; i++)
  876. {
  877. tmpSum += (int)strCommand[i];
  878. }
  879. char checkSum = char(tmpSum + 3);
  880. memcpy(strSendCommand, strCommand, len);
  881. strSendCommand[len + 0] = 0x03;
  882. strSendCommand[len + 1] = checkSum;
  883. FINFO("==OUT==: [{$}] \n", strSendCommand);
  884. unsigned int retLength;
  885. if (m_SCF->Lock(1000) == WAIT_OBJECT_0) {
  886. int result = m_SCF->SendPacket(strSendCommand, strlen(strSendCommand), nTimeOut, retLength);
  887. m_SCF->Unlock();
  888. if (result != SCF_SUCCEED) {
  889. return RET_STATUS::RET_FAILED;
  890. }
  891. }
  892. else {
  893. return RET_STATUS::RET_FAILED;
  894. }
  895. return RET_STATUS::RET_SUCCEED;
  896. }
  897. void nsGEN::PSGHRDevice::FireNotify(string key, int context)
  898. {
  899. char szInfo[64] = { 0 };
  900. snprintf(szInfo, sizeof(szInfo), "%d", context); // Linux ��׼����
  901. std::string str = szInfo;
  902. EventCenter->OnNotify(1, key, str);
  903. }
  904. void nsGEN::PSGHRDevice::FireNotify(std::string key, float context)
  905. {
  906. char szInfo[16] = { 0 };
  907. snprintf(szInfo, sizeof(szInfo), "%.2f", context); // Linux ��׼����
  908. std::string str = szInfo;
  909. EventCenter->OnNotify(1, key, str);
  910. }
  911. void nsGEN::PSGHRDevice::FireNotify(std::string key, std::string context)
  912. {
  913. EventCenter->OnNotify(1, key, context);
  914. }
  915. void nsGEN::PSGHRDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
  916. {
  917. string ErrorCode("PSGHR_ERR_");
  918. ErrorCode += std::to_string(Code);
  919. int level = PSG_HR_REGULATION_LEVEL::REG_ERRO;
  920. if (Act)
  921. {
  922. FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
  923. m_MSGUnit->AddErrorMessage(ErrorCode.c_str(), level, ResInfo);
  924. }
  925. else
  926. {
  927. FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
  928. m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo);
  929. }
  930. }
  931. void nsGEN::PSGHRDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
  932. {
  933. string ErrorCode("PSGHR_WAR_");
  934. ErrorCode += std::to_string(Code);
  935. int level = PSG_HR_REGULATION_LEVEL::REG_WARN;
  936. if (Act)
  937. {
  938. FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
  939. m_MSGUnit->AddWarnMessage(ErrorCode.c_str(), level, ResInfo);
  940. }
  941. else
  942. {
  943. FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
  944. m_MSGUnit->DelWarnMessage(ErrorCode.c_str(), level, ResInfo);
  945. }
  946. }
  947. void nsGEN::PSGHRDevice::OnCallBack()
  948. {
  949. auto HWNotProcess = [](const char* value, int length) -> void
  950. {
  951. FINFO("This commands[{$}] didn't need to process", value);
  952. };
  953. auto extractValue = [](const char* src, int start, int len, bool isInt = false) -> double {
  954. char buf[7] = { 0 };
  955. memcpy(buf + (7 - len), src + start, len);
  956. return isInt ? atoi(buf) : atof(buf);
  957. };
  958. auto HWKV = [this, extractValue](const char* value, int length) {
  959. assert(value);
  960. if (length > 20) {
  961. FINFO("value:{$}", value);
  962. int tmpkv = static_cast<int>(extractValue(value, 0, 3, true));
  963. float tmpma = static_cast<float>(extractValue(value, 6, 5)) / 10.0f;
  964. float tmpms = static_cast<float>(extractValue(value, 14, 7)) / 100.0f;
  965. float tmpmx = static_cast<float>(extractValue(value, 24, 6)) / 100.0f;
  966. m_DoseUnit.m_KV->Update(tmpkv);
  967. FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
  968. m_DoseUnit.m_MA->Update(tmpma);
  969. FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
  970. m_DoseUnit.m_MS->Update(tmpms);
  971. FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
  972. m_DoseUnit.m_MAS->Update(tmpmx);
  973. FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  974. FINFO("tmpkv={$}, tmpma={$}, tmpms={$}, tmpmx={$};", tmpkv, tmpma, tmpms, tmpmx);
  975. }
  976. else {
  977. if (m_DoseUnit.m_KV->Update(atof(value))) {
  978. FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
  979. }
  980. }
  981. };
  982. auto HWMAS = [this](const char* value, int length)
  983. {
  984. assert(value);
  985. float fmas = atof(value) / 100.0;
  986. m_DoseUnit.m_MAS->Update(fmas);
  987. FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  988. };
  989. auto HWMA = [this](const char* value, int length)
  990. {
  991. assert(value);
  992. float fma = atof(value) / 10.0;
  993. m_DoseUnit.m_MA->Update(fma);
  994. FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
  995. };
  996. auto HWMS = [this](const char* value, int length)
  997. {
  998. assert(value);
  999. float fms = atof(value) / 100.0;
  1000. m_DoseUnit.m_MS->Update(fms);
  1001. FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
  1002. };
  1003. auto HWVP = [this](const char* value, int length)
  1004. {
  1005. assert(value);
  1006. m_DoseUnit.m_PostKV->Update(atof(value));
  1007. FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
  1008. FINFO("Actual exposure parameters KV:{$}", m_DoseUnit.m_PostKV->JSGet().c_str());
  1009. };
  1010. auto HWPA = [this](const char* value, int length)
  1011. {
  1012. assert(value);
  1013. float fma = atof(value) / 10.0;
  1014. m_DoseUnit.m_PostMA->Update(fma);
  1015. FireNotify(AttrKey::POSTMA, m_DoseUnit.m_PostMA->JSGet());
  1016. FINFO("Actual exposure parameters MA:{$}", m_DoseUnit.m_PostMA->JSGet().c_str());
  1017. };
  1018. auto HWAP = [this](const char* value, int length)
  1019. {
  1020. assert(value);
  1021. float fmas = atof(value) / 100.0;
  1022. m_DoseUnit.m_PostMAS->Update(fmas);
  1023. FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet());
  1024. FINFO("Actual exposure parameters MAS:{$}", m_DoseUnit.m_PostMAS->JSGet().c_str());
  1025. };
  1026. auto HWFocus = [this](const char* value, int length)
  1027. {
  1028. assert(value);
  1029. int nfous = atoi(value);
  1030. if (m_DoseUnit.m_Focus->Update(nfous))
  1031. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  1032. FINFO("Current focus:{$}, FO={$}", atoi(m_DoseUnit.m_Focus->JSGet().c_str()) ? "large focus" : "small focus", m_DoseUnit.m_Focus->JSGet().c_str());
  1033. };
  1034. auto HWTechmode = [this](const char* value, int length)
  1035. {
  1036. assert(value);
  1037. int ntechmode = atoi(value);
  1038. m_DoseUnit.m_Techmode->Update(ntechmode);
  1039. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  1040. switch (ntechmode)
  1041. {
  1042. case 0:
  1043. FINFO("ET={$}", "mA/ms",m_DoseUnit.m_Techmode->JSGet().c_str());
  1044. break;
  1045. case 1:
  1046. FINFO("ET={$}", "mAs", m_DoseUnit.m_Techmode->JSGet().c_str());
  1047. break;
  1048. case 2:
  1049. FINFO("ET={$}", "AEC / mA", m_DoseUnit.m_Techmode->JSGet().c_str());
  1050. break;
  1051. case 3:
  1052. FINFO("ET={$}", "mAs / ms", m_DoseUnit.m_Techmode->JSGet().c_str());
  1053. break;
  1054. case 4:
  1055. FINFO("ET={$}", "AEC", m_DoseUnit.m_Techmode->JSGet().c_str());
  1056. break;
  1057. }
  1058. };
  1059. auto HWAECField = [this](const char* value, int length)
  1060. {
  1061. assert(value);
  1062. int nvalue = atoi(value);
  1063. if (m_DoseUnit.m_AECField->Update(nvalue))
  1064. FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_AECField->JSGet());
  1065. };
  1066. auto HWAECFilm = [this](const char* value, int length)
  1067. {
  1068. assert(value);
  1069. if (m_DoseUnit.m_AECFilm->Update(atoi(value)))
  1070. FireNotify(AttrKey::AECFILM, m_DoseUnit.m_AECFilm->JSGet());
  1071. };
  1072. auto HWAECDensity = [this](const char* value, int length)
  1073. {
  1074. assert(value);
  1075. if (m_DoseUnit.m_AECDensity->Update(atoi(value)))
  1076. FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
  1077. };
  1078. auto HWWS = [this](const char* value, int length)
  1079. {
  1080. assert(value);
  1081. int nValue = atoi(value);
  1082. m_DoseUnit.m_WS->Update(nValue);
  1083. {
  1084. FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
  1085. }
  1086. };
  1087. auto HWPR = [this](const char* value, int length)
  1088. {
  1089. assert(value);
  1090. int nValue = atoi(value);
  1091. if (nValue == 2)
  1092. {
  1093. }
  1094. else if (nValue == 1)
  1095. {
  1096. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE);
  1097. FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1098. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1099. }
  1100. else if (nValue == 0)
  1101. {
  1102. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
  1103. FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1104. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1105. m_bGenBusy = false;
  1106. RefreshData();
  1107. }
  1108. };
  1109. auto HWXR = [this](const char* value, int length)
  1110. {
  1111. assert(value);
  1112. int nValue = atoi(value);
  1113. if (nValue == 2)
  1114. {
  1115. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
  1116. FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1117. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1118. }
  1119. else if (nValue == 1)
  1120. {
  1121. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
  1122. m_hGenPostEvent->ResetEvent();
  1123. FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1124. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1125. }
  1126. else if (nValue == 0)
  1127. {
  1128. m_bGenBusy = false;
  1129. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF);
  1130. FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1131. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1132. }
  1133. };
  1134. auto HWAPDOSE = [this](const char* value, int length)//post mas
  1135. {
  1136. assert(value);
  1137. m_DoseUnit.m_PostMAS->Update(atof(value) / 100.0);
  1138. FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
  1139. FINFO("Actual exposure parameters MAS:{$}", m_DoseUnit.m_PostMAS->JSGet().c_str());
  1140. };
  1141. auto HWATDOSE = [this](const char* value, int length)
  1142. {
  1143. assert(value);
  1144. m_DoseUnit.m_PostMS->Update(atof(value) / 100.0);
  1145. FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
  1146. FINFO("Actual exposure parameters MS:{$}", m_DoseUnit.m_PostMS->JSGet().c_str());
  1147. };
  1148. auto HWDAP = [this](const char* value, int length)
  1149. {
  1150. assert(value);
  1151. FINFO("Recv DAP ={$}", atof(value) / 100.0);
  1152. };
  1153. auto HWEHE = [this](const char* value, int length)
  1154. {
  1155. m_iHeartBeats = 0;
  1156. assert(value);
  1157. int nhe = atoi(value);
  1158. if (m_DoseUnit.m_HE->Update(nhe))
  1159. FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
  1160. };
  1161. auto HWHH = [this](const char* value, int length)
  1162. {
  1163. m_iHeartBeats = 0;
  1164. assert(value);
  1165. int nhe = atoi(value);
  1166. if (m_DoseUnit.m_GenHE->Update(nhe))
  1167. FireNotify(m_DoseUnit.m_GenHE->GetKey(), m_DoseUnit.m_GenHE->JSGet());
  1168. };
  1169. auto HWFLK = [this](const char* value, int length) {
  1170. assert(value);
  1171. if (length > 20) { // ��������ʽ�ַ���: "040 FLM00010 FLI000 FLT000 FLF1 FLA0 FLS060 FLD0 FLO0 FLC1 FLW00400"
  1172. FINFO("value:{$}", value);
  1173. int tmpflk, tmpflf, tmpfla, tmpfld, tmpflo;
  1174. float tmpflm, tmpfli, tmpflt, tmpfls, tmpflw;
  1175. // ����ʽֱ����ȡ�����ֶΣ�%n��ȡ�Ѷ��ֽ���������У���ʽ��
  1176. int bytesRead;
  1177. const char* fmt = "%3d FLM%5f FLI%3f FLT%3f FLF%d FLA%d FLS%3f FLD%d FLO%d FLC%d FLW%5f%n";
  1178. int ret = sscanf(value, fmt,
  1179. &tmpflk, &tmpflm, &tmpfli, &tmpflt, &tmpflf, &tmpfla, &tmpfls, &tmpfld, &tmpflo, /*FLCδʹ��*/nullptr, & tmpflw, & bytesRead);
  1180. // У������Ƿ�ɹ�����ƥ��11���ֶ��Ҷ��������ַ�����
  1181. if (ret == 11 && bytesRead == length) {
  1182. // ͳһ������ֵת����ԭ�߼��еij�����
  1183. tmpflm /= 10.0f;
  1184. tmpfli /= 10.0f;
  1185. tmpflt /= 10.0f;
  1186. tmpfls /= 10.0f;
  1187. tmpflw /= 100.0f;
  1188. // ���²�֪ͨ������������
  1189. if (m_DoseUnit.m_FLKV->Update(tmpflk))
  1190. FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
  1191. if (m_DoseUnit.m_FLMA->Update(tmpflm))
  1192. FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
  1193. if (m_DoseUnit.m_FLIntTime->Update(tmpfli))
  1194. FireNotify(AttrKey::FLUIntTime, m_DoseUnit.m_FLIntTime->JSGet());
  1195. if (m_DoseUnit.m_FLAccTime->Update(tmpflt))
  1196. FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
  1197. if (m_DoseUnit.m_FLMode->Update(tmpflf))
  1198. FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
  1199. if (m_DoseUnit.m_ABSStatus->Update(tmpfla))
  1200. FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
  1201. if (m_DoseUnit.m_PPS->Update(tmpfls))
  1202. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1203. if (m_DoseUnit.m_DoseLevel->Update(tmpfld))
  1204. FireNotify(AttrKey::FLUDoseLevel, m_DoseUnit.m_DoseLevel->JSGet());
  1205. if (m_DoseUnit.m_Curve->Update(tmpflo))
  1206. FireNotify(AttrKey::FLUCurve, m_DoseUnit.m_Curve->JSGet());
  1207. if (m_DoseUnit.m_FLMS->Update(tmpflw))
  1208. FireNotify(AttrKey::FLUMS, m_DoseUnit.m_FLMS->JSGet());
  1209. FINFO("tmpflk={$}, tmpflf={$}, tmpfla={$}, tmpfld={$}, tmpflo={$}, tmpflm={$}, tmpfli={$}, tmpflt={$}, tmpfls={$}, tmpflw={$};",
  1210. tmpflk, tmpflf, tmpfla, tmpfld, tmpflo, tmpflm, tmpfli, tmpflt, tmpfls, tmpflw);
  1211. }
  1212. else {
  1213. FINFO("FLK format parse failed");
  1214. }
  1215. }
  1216. else {
  1217. // �̸�ʽ����
  1218. int tmpflkv = atoi(value);
  1219. m_DoseUnit.m_FLKV->Update(tmpflkv);
  1220. FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
  1221. }
  1222. };
  1223. auto HWFLM = [this](const char* value, int length)
  1224. {
  1225. assert(value);
  1226. float tmpflm = atof(value) / 10.0;
  1227. m_DoseUnit.m_FLMA->Update(tmpflm);
  1228. FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
  1229. };
  1230. auto HWFLW = [this](const char* value, int length)
  1231. {
  1232. assert(value);
  1233. float tmpflms = atof(value) / 100.0;
  1234. m_DoseUnit.m_FLMS->Update(tmpflms);
  1235. FireNotify(AttrKey::FLUMS, m_DoseUnit.m_FLMS->JSGet());
  1236. };
  1237. auto HWFLI = [this](const char* value, int length)
  1238. {
  1239. assert(value);
  1240. float tmpfli = atof(value) / 10.0;
  1241. if (m_DoseUnit.m_FLIntTime->Update(tmpfli))
  1242. FireNotify(AttrKey::FLUIntTime, m_DoseUnit.m_FLIntTime->JSGet());
  1243. };
  1244. auto HWFLT = [this](const char* value, int length)
  1245. {
  1246. assert(value);
  1247. float tmpflt = atof(value) / 10.0;
  1248. if (m_DoseUnit.m_FLAccTime->Update(tmpflt))
  1249. FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
  1250. };
  1251. auto HWFLS = [this](const char* value, int length)
  1252. {
  1253. assert(value);
  1254. float tmppps = atof(value) / 10.0;
  1255. if (m_DoseUnit.m_PPS->Update(tmppps))
  1256. FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
  1257. };
  1258. auto HWFLF = [this](const char* value, int length)
  1259. {
  1260. assert(value);
  1261. FINFO("m_FLMode={$};", value);
  1262. int tmpflf = atoi(value);
  1263. if (m_DoseUnit.m_FLMode->Update(tmpflf))
  1264. FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
  1265. };
  1266. auto HWFLX = [this](const char* value, int length)
  1267. {
  1268. assert(value);
  1269. int nValue = atoi(value);
  1270. if (nValue == 2)
  1271. {
  1272. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYON);
  1273. FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1274. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1275. }
  1276. else if (nValue == 1)
  1277. {
  1278. FINFO("Recv FLX1, do nothing");
  1279. }
  1280. else if (nValue == 0)
  1281. {
  1282. m_bGenBusy = false;
  1283. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYOFF);
  1284. FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1285. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1286. }
  1287. };
  1288. auto HWFLP = [this](const char* value, int length)
  1289. {
  1290. assert(value);
  1291. int nValue = atoi(value);
  1292. if (nValue == 2)
  1293. {
  1294. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_READY);
  1295. FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1296. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1297. }
  1298. else if (nValue == 1)
  1299. {
  1300. FINFO("Recv FLP1, do nothing\n");
  1301. }
  1302. else if (nValue == 0)
  1303. {
  1304. int nFlFMode = atoi(m_DoseUnit.m_FLMode->JSGet().c_str());
  1305. FINFO("m_DoseUnit.m_FLMode={$}- number ={$};", m_DoseUnit.m_FLMode->JSGet().c_str(), nFlFMode);
  1306. if (nFlFMode == 2)
  1307. {
  1308. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYOFF);
  1309. FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1310. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1311. }
  1312. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_OFF);
  1313. FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
  1314. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1315. m_bGenBusy = false;
  1316. RefreshData();
  1317. }
  1318. };
  1319. auto HWDS = [this](const char* value, int length)
  1320. {
  1321. assert(value);
  1322. };
  1323. auto HWFLA = [this](const char* value, int length)
  1324. {
  1325. assert(value);
  1326. int tmpfla = atoi(value);
  1327. if ( m_DoseUnit.m_ABSStatus->Update(tmpfla))
  1328. FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
  1329. };
  1330. auto HWFLD = [this](const char* value, int length)
  1331. {
  1332. assert(value);
  1333. };
  1334. auto HWFLC= [this](const char* value, int length)
  1335. {
  1336. assert(value);
  1337. };
  1338. auto HWFLO = [this](const char* value, int length)
  1339. {
  1340. assert(value);
  1341. int nValue = atoi(value);
  1342. if (m_DoseUnit.m_Curve->Update(nValue))
  1343. FireNotify(AttrKey::FLUCurve, m_DoseUnit.m_Curve->JSGet());
  1344. };
  1345. auto HWER = [this](const char* value, int length)
  1346. {
  1347. assert(value);
  1348. int nValue = atoi(value);
  1349. char tmpbuf[4] = { 0,0,0,0 };
  1350. tmpbuf[0] = value[0];
  1351. tmpbuf[1] = value[1];
  1352. tmpbuf[2] = value[2];
  1353. if (nValue != 0)
  1354. {
  1355. std::unordered_map<std::string, std::string> errorMessages = {
  1356. {"100", "AEC Back-up Timer - Exposure Terminated"},
  1357. {"101", "AEC mAs Exceeded - Exposure Terminated"},
  1358. {"102", "Door Interlock FERROR"},
  1359. {"103", "Calibration Data Corrupt FERROR"},
  1360. {"104", "AEC Data Corrupt FERROR"},
  1361. {"105", "Receptor Data Corrupt FERROR"},
  1362. {"106", "Tube Data Corrupt FERROR"},
  1363. {"107", "Generator Limit Data Corrupt FERROR"},
  1364. {"108", "mA Correction Data Corrupt FERROR"},
  1365. {"109", "Not Enabled FERROR"},
  1366. {"110", "AEC Feedback FERROR - No Feedback Signal Detected"},
  1367. {"111", "EXP_SW Signal Active in Standby State"},
  1368. {"112", "Calibration FERROR - No mA"},
  1369. {"113", "Calibration FERROR - Maximum Filament Current Exceeded"},
  1370. {"114", "MA During Exposure too High"},
  1371. {"115", "MA During Exposure too Low"},
  1372. {"116", "Generator KW Limit"},
  1373. {"117", "Generator KV Limit"},
  1374. {"118", "Generator MA Limit"},
  1375. {"119", "Generator MS Limit"},
  1376. {"120", "Generator MAS Limit"},
  1377. {"121", "Tube KW Limit"},
  1378. {"122", "Tube KV Limit"},
  1379. {"123", "Tube MA Limit"},
  1380. {"124", "Tube MAS Limit"},
  1381. {"125", "Parameter Limit"},
  1382. {"126", "Manually Terminated Exposure"},
  1383. {"127", "Preparation Time-out FERROR prep time is over 30s or 60s"},
  1384. {"128", "Prep Input Active During Initialization Phase"},
  1385. {"129", "X-ray Input Active During Initialization Phase"},
  1386. {"130", "No Fields Selected in AEC mode"},
  1387. {"131", "Generator AEC Density Limit"},
  1388. {"132", "Calibration FERROR - Manually Terminated"},
  1389. {"133", "EEPROM Communication FERROR"},
  1390. {"134", "RTC Communication FERROR"},
  1391. {"135", "AEC Channel FERROR"},
  1392. {"136", "Anode Communication FERROR"},
  1393. {"137", "EXP_OK TimeOut"},
  1394. {"138", "KV TimeOut"},
  1395. {"139", "Mosfet Temperature Limit Exceeded"},
  1396. {"140", "HU Power Limit"},
  1397. {"141", "HU Power Warning"},
  1398. {"142", "Small Focus Disable"},
  1399. {"143", "Large Focus Disable"},
  1400. {"144", "Low Speed Disable"},
  1401. {"145", "High Speed Disable"},
  1402. {"146", "Anode Heat Warning Exceeded"},
  1403. {"147", "Anode Heat Limit Exceeded"},
  1404. {"148", "KV Unbalance"},
  1405. {"149", "Thermal Switch Interlock FERROR"},
  1406. {"150", "Emergency FERROR"},
  1407. {"151", "KV Correction Data Corrupt FERROR"},
  1408. {"152", "Generator Tank Power Limit"},
  1409. {"153", "AEC Standby Signal FERROR"},
  1410. {"154", "DCBUS Calibration Data Corrupt FERROR"},
  1411. {"155", "Fluoro Timer Terminated "},
  1412. {"156", "Fluoro Timer Terminated "},
  1413. {"157", "Power Off In X - Ray State"},
  1414. {"158", "DAP Data Corrupt "},
  1415. {"159", "Auto APR TimeOut "},
  1416. {"160", "ERR_FLUORO_ABSFDBNONE"},
  1417. {"200", "FLASH LOCK"},
  1418. {"201", "FLASH REVID_INVALID"},
  1419. {"202", "FLASH ADDR_INVALID"},
  1420. {"203", "FLASH INCORRECT_PARTID"},
  1421. {"204", "FLASH API_SILICON_MISMATCH"},
  1422. {"205", "FLASH ERASE ERROR"},
  1423. {"206", "FLASH FAIL_PROGRAM"},
  1424. {"207", "FLASH FAIL_ZERO_BIT_ERROR"},
  1425. {"208", "FLASH FAIL_VERIFY"},
  1426. {"209", "FLASH BUSY"},
  1427. {"210", "FLASH_PROGRM_ADDR_ERROR"},
  1428. {"211", "UPDATA_VERSION_ERROR"},
  1429. {"212", "UPDATA SN_ERROR"},
  1430. {"213", "UPDATA_BYTE_COUNT_ERROR"},
  1431. {"214", "UPDATA_CHECKSUM_ERROR"}
  1432. };
  1433. char ErrorCode[20];
  1434. snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_ER_%d", nValue);
  1435. char temp[50] = { 0 };
  1436. snprintf(temp, sizeof(temp), "ER%03d", nValue);
  1437. HWSend(temp, strlen(temp));
  1438. int level = 1;
  1439. auto it = errorMessages.find(tmpbuf);
  1440. if (it != errorMessages.end())
  1441. {
  1442. m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
  1443. }
  1444. }
  1445. else
  1446. {
  1447. int level = 1;
  1448. char ErrorCode[20];
  1449. m_MSGUnit->DelWarnMessage(ErrorCode, level, "");
  1450. }
  1451. };
  1452. auto HWEL = [this](const char* value, int length)
  1453. {
  1454. assert(value);
  1455. int nValue = atoi(value);
  1456. char tmpbuf[3] = { 0,0,0 };
  1457. tmpbuf[0] = value[0];
  1458. tmpbuf[1] = value[1];
  1459. tmpbuf[2] = value[2];
  1460. if (nValue != 0)
  1461. {
  1462. std::unordered_map<std::string, std::string> errorMessages = {
  1463. {"001", "Generator CPU Real Time Clock FERROR"},
  1464. {"002", "Main Contactor FERROR"},
  1465. {"003", "Rotor Fault"},
  1466. {"004", "DC Bus Voltage too Low"},
  1467. {"005", "DC Bus Voltage too High"},
  1468. {"006", "Filament Adjust FERROR"},
  1469. {"007", "Filament PowerBoard Not Connected"},
  1470. {"008", "Filament Short Circuit"},
  1471. {"019", "Filament Overcurrent"},
  1472. {"010", "Anode Overcurrent"},
  1473. {"011", "Cathode Overcurrent"},
  1474. {"012", "Anode Overvoltage"},
  1475. {"013", "Cathode Overvoltage"},
  1476. {"014", "ARC"},
  1477. {"015", "Short Current 1"},
  1478. {"016", "Short Current 2"},
  1479. {"017", "Short Current A"},
  1480. {"018", "Short Current B"}
  1481. };
  1482. char ErrorCode[20];
  1483. snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_EL_%d", nValue);
  1484. char temp[50] = { 0 };
  1485. snprintf(temp, sizeof(temp), "EL%03d", nValue);
  1486. HWSend(temp, strlen(temp));
  1487. int level = 1;
  1488. auto it = errorMessages.find(tmpbuf);
  1489. if (it != errorMessages.end())
  1490. {
  1491. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
  1492. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1493. m_MSGUnit->AddErrorMessage(ErrorCode, level, it->second.c_str());
  1494. }
  1495. }
  1496. else
  1497. {
  1498. int level = 1;
  1499. char ErrorCode[20];
  1500. m_MSGUnit->DelErrorMessage(ErrorCode, level, "");
  1501. }
  1502. };
  1503. auto HWEI = [this](const char* value, int length)
  1504. {
  1505. assert(value);
  1506. int nValue = atoi(value);
  1507. char tmpbuf[3] = { 0,0,0 };
  1508. tmpbuf[0] = value[0];
  1509. tmpbuf[1] = value[1];
  1510. tmpbuf[2] = value[2];
  1511. if (nValue != 0)
  1512. {
  1513. std::unordered_map<std::string, std::string> errorMessages = {
  1514. {"400", "Enter the service mode"},
  1515. {"401", "Exit the service mode"},
  1516. {"402", "Resonance Overcurrent1"},
  1517. {"403", "Resonance Overcurrent2"},
  1518. {"404", "Resonance Overcurrent3"},
  1519. {"405", "Charging, Please Wait "},
  1520. {"406", "DAC Reset "},
  1521. {"407", "X-Rays State PowerOff "},
  1522. {"408", "Fluoro Disable "},
  1523. {"409", "Fluoro Timer Warning Level Exceeded"},
  1524. {"410", "Anode Heat Warning Exceeded "},
  1525. {"411", "MA Too Low "}
  1526. };
  1527. char ErrorCode[20];
  1528. snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_EI_%d", nValue);
  1529. char temp[50] = { 0 };
  1530. snprintf(temp, sizeof(temp), "EI%03d", nValue);
  1531. HWSend(temp, strlen(temp));
  1532. int level = 1;
  1533. auto it = errorMessages.find(tmpbuf);
  1534. if (it != errorMessages.end())
  1535. {
  1536. //m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
  1537. //FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1538. m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
  1539. }
  1540. }
  1541. else
  1542. {
  1543. int level = 1;
  1544. char ErrorCode[20];
  1545. m_MSGUnit->DelWarnMessage(ErrorCode, level, "");
  1546. }
  1547. };
  1548. auto HWMSG = [this](const char* value, int length)
  1549. {
  1550. assert(value);
  1551. int nValue = atoi(value);
  1552. char tmpbuf[3] = { 0,0,0 };
  1553. tmpbuf[0] = value[0];
  1554. tmpbuf[1] = value[1];
  1555. tmpbuf[2] = value[2];
  1556. if (nValue != 0)
  1557. {
  1558. std::unordered_map<std::string, std::string> errorMessages = {
  1559. {"001", "Rotating anode protection parameters are incorrectly configured"},
  1560. {"002", "Press emergency stop of high voltage generator"},
  1561. {"003", "The first level hand brake is not triggered, and the second level hand brake is triggered"},
  1562. {"004", "The first level hand brake is pressed during the wake - up or startup process of the high - voltage generator."},
  1563. {"005", "The second level hand brake is pressed during the wake - up or startup process of the high - voltage generator."},
  1564. {"006", "Low battery power of the high - voltage generator, please recharge."},
  1565. {"007", "Anode thermal capacity exceeds the warning value."},
  1566. {"008", "Exposure time interval is too short, please wait for exposure."},
  1567. {"009", "Parameter adjustment is prohibited during exposure."},
  1568. {"010", "High - voltage generator is not ready, please confirm the status."},
  1569. {"011", "The oil tank temperature of the high - voltage generator exceeds the warning value."},
  1570. {"012", "Training cannot be conducted in this state."},
  1571. {"013", "The tube current of the high voltage generator is low."},
  1572. {"014", "The PFC module of the high voltage generator works abnormally."},
  1573. {"015", "Battery output power limits for high voltage generators."},
  1574. {"016", "The battery of the high voltage generator is charging."},
  1575. {"017", "The mA parameter of the high voltage generator exceeds the maximum tube value."},
  1576. {"018", "The kV parameter of the high voltage generator exceeds the limit value."},
  1577. {"019", "The mA parameter of the high voltage generator exceeds the limit value."},
  1578. {"020", "The ms parameter of the high voltage generator exceeds the limit value."},
  1579. {"021", "The mAs parameter of the high voltage generator exceeds the limit value."},
  1580. {"022", "Filament selection parameter exceeds the limit."},
  1581. {"023", "Anode rotation speed selection parameter exceeds the limit."},
  1582. {"024", "The exposure technical parameters of the high voltage generator exceed the limits."},
  1583. {"025", "AEC density parameter exceeds the limit."},
  1584. {"026", "AEC field selection parameter exceeds the limit."},
  1585. {"027", "AEC channel parameter exceeds the limit."},
  1586. {"028", "AEC sensitivity parameter exceeds the limit."},
  1587. {"029", "High - voltage generator power exceeds the limit."},
  1588. {"030", "Tube power exceeds the limit."},
  1589. {"031", "The frame rate parameter of the high voltage generator exceeds the limit value."},
  1590. {"032", "Exposure parameter exceeds the high - voltage generator energy storage limit."},
  1591. {"033", "High voltage generator battery pack alarm."},
  1592. {"035", "Foot brake signal is pressed during the wake - up or startup process of the high - voltage generator."},
  1593. {"036", "Cumulative fluoroscopy time alarm."},
  1594. {"037", "The console of the high voltage generator is not connected, please open the console."},
  1595. {"038", "Tube sleeve thermal capacity exceeds the warning value."},
  1596. {"049", "Bus voltage of the high - voltage generator exceeds the limit."},
  1597. {"050", "High - voltage generator does not support this exposure mode."},
  1598. {"051", "The rotation speed of the rotating anode does not meet the exposure requirements."},
  1599. {"052", "The second level hand brake is not pressed within the specified time."},
  1600. {"053", "Interlock 1 is effective during the exposure process of the high - voltage generator."},
  1601. {"054", "Timeout for feedback signal in flat panel mode."},
  1602. {"055", "The kV establishment timeout of the high voltage generator."},
  1603. {"056", "Anode thermal capacity exceeds the limit."},
  1604. {"057", "Filament calibration data abnormality."},
  1605. {"058", "Tube current is too low during training."},
  1606. {"059", "Release hand brake prematurely during exposure."},
  1607. {"060", "AEC feedback abnormality."},
  1608. {"061", "Inverter temperature of the high - voltage generator exceeds the limit."},
  1609. {"062", "kV is too low during exposure, exposure abnormality aborted."},
  1610. {"063", "kV is too high during exposure, exposure abnormality aborted."},
  1611. {"064", "Oil temperature of the high - voltage generator exceeds the limit."},
  1612. {"065", "Tube sleeve thermal capacity exceeds the limit."},
  1613. {"066", "The current exposure parameters of the high voltage generator exceed the heat capacity limit."},
  1614. {"068", "mA is too high during exposure, exposure abnormality aborted."},
  1615. {"069", "The DRVEN enable of the high voltage generator to establish a timeout."},
  1616. {"070", "Interruption in communication with the rotating anode."},
  1617. {"071", "Emergency stop is pressed during exposure."},
  1618. {"072", "The battery pack of the high voltage generator is faulty."},
  1619. {"073", "Resonant current exceeds the limit, exposure abnormality aborted(software)."},
  1620. {"074", "Anode kV exceeds the limit, exposure abnormality aborted(software)."},
  1621. {"075", "Cathode kV exceeds the limit, exposure abnormality aborted(software)."},
  1622. {"076", "Filament current exceeds the limit(software)."},
  1623. {"078", "Oil tank power limit of the high - voltage generator."},
  1624. {"080", "Deviation of anode kV and cathode kV exceeds the limit, exposure abnormality aborted."},
  1625. {"081", "Power exceeds the limit during exposure, exposure abnormality aborted."},
  1626. {"082", "The external synchronization signal of the high voltage generator has timed out."},
  1627. {"083", "Fan fault in high voltage generator."},
  1628. {"084", "High voltage generator InterLock1 effective."},
  1629. {"085", "High voltage generator InterLock2 effective."},
  1630. {"087", "Release foot brake prematurely during exposure."},
  1631. {"088", "Foot brake signal abnormality."},
  1632. {"089", "The DA chip of the high voltage generator is abnormal."},
  1633. {"090", "Timeout for cumulative fluoroscopy time."},
  1634. {"091", "The external discharge line of the high voltage generator enables the signal to timeout."},
  1635. {"092", "XRAYReady invalid."},
  1636. {"093", "High voltage generator during exposure interlock 2 effective."}
  1637. };
  1638. char ErrorCode[20];
  1639. snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_MSG_%d", nValue);
  1640. int level = 1;
  1641. /*char temp[50] = { 0 };
  1642. snprintf(temp, sizeof(temp), "MSG%03d", nValue);
  1643. HWSend(temp, strlen(temp));*/
  1644. auto it = errorMessages.find(tmpbuf);
  1645. if (it != errorMessages.end())
  1646. {
  1647. FINFO("WarnCode: {$}, Level: {$}, ResInfo: {$}\n", ErrorCode, level, it->second.c_str());
  1648. m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
  1649. }
  1650. }
  1651. else
  1652. {
  1653. int level = 1;
  1654. char WarnCode[20]{ "" };
  1655. m_MSGUnit->DelWarnMessage(WarnCode, level, "");
  1656. }
  1657. };
  1658. //==IN==:TU0 WS1 FO0 ET0 FI010 FS001 FN0 HE000
  1659. auto HWTU = [this](const char* value, int length) -> void
  1660. {
  1661. assert(value);
  1662. FINFO("recv TU={$},len={$}", value, length);
  1663. char tmpbuf[3] = { 0,0,0 };
  1664. int tmpWS, tmpFO, tmpET, tmpField, tmpFilm, tmpDensity, tmpHE;
  1665. //ws
  1666. tmpbuf[0] = value[4];
  1667. tmpWS = atoi(tmpbuf);
  1668. m_DoseUnit.m_WS->Update(tmpWS);
  1669. {
  1670. FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
  1671. }
  1672. //FO
  1673. tmpbuf[0] = value[8];
  1674. tmpFO = atoi(tmpbuf);
  1675. m_DoseUnit.m_Focus->Update(tmpFO);
  1676. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  1677. FINFO("Current focus:{$}, FO={$}", atoi(m_DoseUnit.m_Focus->JSGet().c_str()) ? "large focus" : "small focus", m_DoseUnit.m_Focus->JSGet().c_str());
  1678. //ET
  1679. tmpbuf[0] = value[12];
  1680. tmpET = atoi(tmpbuf);
  1681. m_DoseUnit.m_Techmode->Update(tmpET);
  1682. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  1683. //FIELD
  1684. tmpbuf[0] = value[16];
  1685. tmpbuf[1] = value[17];
  1686. tmpbuf[2] = value[18];
  1687. tmpField = atoi(tmpbuf);
  1688. if (m_DoseUnit.m_AECField->Update(tmpField))
  1689. FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_AECField->JSGet());
  1690. //Film
  1691. tmpbuf[0] = value[22];
  1692. tmpbuf[1] = value[23];
  1693. tmpbuf[2] = value[24];
  1694. tmpFilm = atoi(tmpbuf);
  1695. if (m_DoseUnit.m_AECFilm->Update(tmpFilm))
  1696. FireNotify(AttrKey::AECFILM, m_DoseUnit.m_AECFilm->JSGet());
  1697. //Density
  1698. tmpbuf[0] = value[29];
  1699. tmpbuf[1] = 0;
  1700. tmpbuf[2] = 0;
  1701. tmpDensity = atoi(tmpbuf);
  1702. if (m_DoseUnit.m_AECDensity->Update(tmpDensity))
  1703. FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
  1704. //HE
  1705. tmpbuf[0] = value[33];
  1706. tmpbuf[1] = value[34];
  1707. tmpbuf[2] = value[35];
  1708. tmpHE = atoi(tmpbuf);
  1709. m_DoseUnit.m_HE->Update(tmpHE);
  1710. FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
  1711. FINFO("parse tmpWS={$}, tmpFO={$}, tmpET={$}, tmpField={$}, tmpFilm={$}, tmpDensity={$}, tmpHE={$}", tmpWS, tmpFO, tmpET, tmpField, tmpFilm, tmpDensity, tmpHE);
  1712. };
  1713. auto HWST = [this](const char* value, int length)
  1714. {
  1715. assert(value);
  1716. int genStatus = atoi(value);
  1717. FINFO("genStatus={$}", genStatus);
  1718. switch (genStatus)
  1719. {
  1720. case 1:
  1721. FDEBUG("get Gen Status_1:GENSTATE {$} -> STATUS_INIT", m_DoseUnit.m_GenState->JSGet());
  1722. ///*if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_INIT))
  1723. // FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());*/
  1724. break;
  1725. case 2:
  1726. FDEBUG("get Gen Status_2:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
  1727. if (m_isFirstHWPhase) {
  1728. HWSend("RE", 2);
  1729. // HWSend("RR", 2);
  1730. HWSend("RS", 2);
  1731. HWSend("ET?", 3);
  1732. HWSend("ST?", 3);
  1733. m_isFirstHWPhase = false;
  1734. }
  1735. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY))
  1736. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1737. break;
  1738. case 3: // Rad Preparation Phase
  1739. /*FDEBUG("get Gen Status_3:RAD_OFF(PR0) -> RAD_PREPARE(PR1)");
  1740. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE))
  1741. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());*/
  1742. if (m_iLoopTime != PSGHR_LoopExpHBTime)
  1743. {
  1744. FDEBUG("get Gen Status_3:quicken loopTime[{$}]->[{$}]", m_iLoopTime.load(), PSGHR_LoopExpHBTime);
  1745. m_iLoopTime = PSGHR_LoopExpHBTime;
  1746. }
  1747. break;
  1748. case 4:
  1749. FDEBUG("get Gen Status_4:PREPARE(PR1) -> RAD_READY(PR2)");
  1750. /*if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
  1751. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());*/
  1752. break;
  1753. case 5:
  1754. FDEBUG("get Gen Status_5:RAD_READY(PR2) -> X-Ray On(XR2)");
  1755. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP))
  1756. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1757. /*if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYON))
  1758. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());*/
  1759. break;
  1760. case 6:
  1761. FDEBUG("get Gen Status_6:X-Ray On(XR2) -> X-Ray Off(XR0)");
  1762. /*if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF))
  1763. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());*/
  1764. break;
  1765. case 7:
  1766. FDEBUG("get Gen Status_7:GENSTATE {$} -> STATUS_ERROR", m_DoseUnit.m_GenState->JSGet());
  1767. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR))
  1768. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1769. break;
  1770. case 8:
  1771. FDEBUG("get Gen Status_8:in Calibration");
  1772. break;
  1773. default:
  1774. FDEBUG("get Gen Status:[{$}] unknown", genStatus);
  1775. break;
  1776. }
  1777. };
  1778. auto HWSR = [this](const char* value, int length)
  1779. {
  1780. assert(value);
  1781. int stopReason = atoi(value);
  1782. FINFO("stopReason={$}", stopReason);
  1783. switch (stopReason)
  1784. {
  1785. case 0:
  1786. FDEBUG("Exposure stop reason:AEC feedback voltage is too low");
  1787. break;
  1788. case 5:
  1789. FDEBUG("Exposure stop reason: Stop exposure manually");
  1790. break;
  1791. case 6:
  1792. FDEBUG("Exposure stop reason: door lock open");
  1793. break;
  1794. case 7:
  1795. FDEBUG("Exposure stop reason:Bulb tube anode ignition");
  1796. break;
  1797. case 8:
  1798. FDEBUG("Exposure stop reason:Bulb cathode ignition");
  1799. break;
  1800. case 9:
  1801. FDEBUG("Exposure stop reason:The pipe is lit");
  1802. break;
  1803. case 10:
  1804. FDEBUG("Exposure stop reason:KV is too low or too high");
  1805. break;
  1806. case 11:
  1807. FDEBUG("Exposure stop reason:Ma too low");
  1808. break;
  1809. case 12:
  1810. FDEBUG("Exposure stop reason:Set ms reached");
  1811. break;
  1812. case 13:
  1813. FDEBUG("Exposure stop reason:Set mAs reached");
  1814. break;
  1815. case 14:
  1816. FDEBUG("Exposure stop reason:AEC dose reached");
  1817. break;
  1818. default:
  1819. FDEBUG("Exposure stop reason:default");
  1820. break;
  1821. }
  1822. };
  1823. arFrame.clear();
  1824. arFrame.push_back(tFrameMapping("EL", 2, HWEL));
  1825. arFrame.push_back(tFrameMapping("EI", 2, HWEI));
  1826. arFrame.push_back(tFrameMapping("ER", 2, HWER));
  1827. arFrame.push_back(tFrameMapping("MSG", 3, HWMSG));
  1828. arFrame.push_back(tFrameMapping("TU", 2, HWTU));
  1829. arFrame.push_back(tFrameMapping("EC", 2, HWNotProcess));
  1830. arFrame.push_back(tFrameMapping("PW", 2, HWNotProcess));
  1831. arFrame.push_back(tFrameMapping("KV", 2, HWKV));
  1832. arFrame.push_back(tFrameMapping("MX", 2, HWMAS));
  1833. arFrame.push_back(tFrameMapping("MA", 2, HWMA));
  1834. arFrame.push_back(tFrameMapping("MS", 2, HWMS));
  1835. arFrame.push_back(tFrameMapping("VP", 2, HWVP));
  1836. arFrame.push_back(tFrameMapping("PA", 2, HWPA));
  1837. arFrame.push_back(tFrameMapping("AP", 2, HWAPDOSE));
  1838. arFrame.push_back(tFrameMapping("ET", 2, HWTechmode));
  1839. arFrame.push_back(tFrameMapping("FO", 2, HWFocus));
  1840. arFrame.push_back(tFrameMapping("FI", 2, HWAECField));
  1841. arFrame.push_back(tFrameMapping("FS", 2, HWAECFilm));
  1842. arFrame.push_back(tFrameMapping("FN", 2, HWAECDensity));
  1843. arFrame.push_back(tFrameMapping("WS", 2, HWWS));
  1844. arFrame.push_back(tFrameMapping("PR", 2, HWPR));
  1845. arFrame.push_back(tFrameMapping("XR", 2, HWXR));
  1846. arFrame.push_back(tFrameMapping("AT", 2, HWATDOSE));
  1847. arFrame.push_back(tFrameMapping("FLK", 3, HWFLK));
  1848. arFrame.push_back(tFrameMapping("FLM", 3, HWFLM));
  1849. arFrame.push_back(tFrameMapping("FLW", 3, HWFLW));
  1850. arFrame.push_back(tFrameMapping("FLI", 3, HWFLI));
  1851. arFrame.push_back(tFrameMapping("FLT", 3, HWFLT));
  1852. arFrame.push_back(tFrameMapping("FLS", 3, HWFLS));
  1853. arFrame.push_back(tFrameMapping("FLF", 3, HWFLF));
  1854. arFrame.push_back(tFrameMapping("FLP", 3, HWFLP));
  1855. arFrame.push_back(tFrameMapping("FLX", 3, HWFLX));
  1856. arFrame.push_back(tFrameMapping("FLA", 3, HWFLA));
  1857. arFrame.push_back(tFrameMapping("FLD", 3, HWFLD));
  1858. arFrame.push_back(tFrameMapping("FLC", 3, HWFLD));
  1859. arFrame.push_back(tFrameMapping("FLO", 3, HWFLO));
  1860. arFrame.push_back(tFrameMapping("HE", 2, HWEHE));
  1861. arFrame.push_back(tFrameMapping("HH", 2, HWHH));
  1862. arFrame.push_back(tFrameMapping("DA", 2, HWDAP));
  1863. arFrame.push_back(tFrameMapping("DV", 2, HWDAP));
  1864. arFrame.push_back(tFrameMapping("DS", 2, HWDS));
  1865. arFrame.push_back(tFrameMapping("ST", 2, HWST));
  1866. arFrame.push_back(tFrameMapping("SR", 2, HWSR));
  1867. arFrame.push_back(tFrameMapping("P", 1, HWPR));
  1868. }
  1869. bool nsGEN::PSGHRDevice::ReConnect()
  1870. {
  1871. FINFO("Enter PSG_reConnect");
  1872. m_SCF->Disconnect();
  1873. if (!pIODriver)
  1874. {
  1875. FINFO("PSG_reConnect:Driver null");
  1876. }
  1877. else
  1878. {
  1879. // ��Ҫ�� pIODriver ת��Ϊ PSGHRDriver*
  1880. PSGHRDriver* driver = dynamic_cast<PSGHRDriver*>(pIODriver.get());
  1881. if (driver && driver->ReConnection())
  1882. {
  1883. FireErrorMessage(false, 1, "lost Connect");
  1884. m_bConnectFlag = true;
  1885. FINFO("PSG_reConnect success");
  1886. return true;
  1887. }
  1888. else
  1889. {
  1890. FINFO("PSG_reConnect failed");
  1891. }
  1892. }
  1893. return false;
  1894. }
  1895. int nsGEN::PSGHRDevice::GridMSMargin()
  1896. {
  1897. return 0;
  1898. }
  1899. bool nsGEN::PSGHRDevice::CalculateAppropriateMA(float& inoutMAS, float& inoutMA, float& inoutMS)
  1900. {
  1901. FINFO("Enter CalculateAppropriateMA:MAS[{$}],MA[{$}],MS[{$}]", inoutMAS, inoutMA, inoutMS);
  1902. if (m_DoseUnit.m_Focus->Get() == AttrKey::FOCUS_TYPE::FOCUS_LARGE)
  1903. {
  1904. m_iMaxPower = PSGHR_LARGE_POWER;
  1905. }
  1906. else
  1907. {
  1908. m_iMaxPower = PSGHR_SMALL_POWER;
  1909. }
  1910. int currKV = 0 , tempMA = 0, tempMS = 0;
  1911. currKV = m_DoseUnit.m_KV->Get();
  1912. tempMA = m_iMaxPower * 1000 / currKV;
  1913. FDEBUG("power[{$}]*1000 / KV[{$}] = MAX_MA[{$}]", m_iMaxPower, currKV, tempMA);
  1914. if (tempMA > PSGHR_MAX_MA)
  1915. {
  1916. tempMA = PSGHR_MAX_MA;
  1917. FDEBUG(" MAX_MA too big,be close to range_right[{$}]", tempMA);
  1918. }
  1919. else if (tempMA < PSGHR_MIN_MA)
  1920. {
  1921. FWARN(" MAX_MA too small,compute failed");
  1922. return false;
  1923. }
  1924. for (int i = tempMA;i >= PSGHR_MIN_MA; i--)
  1925. {
  1926. tempMS = inoutMAS * 1000.0 / i;
  1927. FDEBUG("MAS[{$}]*1000 / temp_MA[{$}] = temp_MS[{$}]", inoutMAS, i, tempMS);
  1928. }
  1929. FDEBUG("can not use MAS[{$}]compute Appropriate MA MS", inoutMAS);
  1930. return false;
  1931. }
  1932. void nsGEN::PSGHRDevice::ReSendFailedAction(string& cmdNum)
  1933. {
  1934. }
  1935. int nsGEN::PSGHRDevice::GetGenState()
  1936. {
  1937. if (m_DoseUnit.m_GenState != NULL)
  1938. {
  1939. return m_DoseUnit.m_GenState->Get();
  1940. }
  1941. else
  1942. {
  1943. return 0;
  1944. }
  1945. }
  1946. int nsGEN::PSGHRDevice::LoadConfig(string configfile)
  1947. {
  1948. FINFO("=====================LoadConfig=========================");
  1949. // ����ļ��Ƿ����
  1950. std::ifstream file(configfile);
  1951. if (!file) {
  1952. // �ļ������ڣ�ֱ�ӷ��ؿյ�Connection����
  1953. FINFO("Config file does not exist: {$}", configfile.c_str());
  1954. return -1;
  1955. }
  1956. if (m_bIsConfigLoaded)
  1957. {
  1958. FINFO("Configuration already loaded.");
  1959. return 0;
  1960. }
  1961. ResDataObject temp;
  1962. temp.loadFile(configfile.c_str());
  1963. m_GenConfig = temp["CONFIGURATION"];
  1964. TransJsonText(m_GenConfig);
  1965. if (m_GenConfig.GetKeyCount("loopEnable") > 0)
  1966. {
  1967. m_bExtraFlag = (int)m_GenConfig["loopEnable"];
  1968. }
  1969. if (m_GenConfig.GetKeyCount(ConfKey::CcosTubeInfo) > 0)
  1970. {
  1971. string tempValue = (string)m_GenConfig[ConfKey::CcosTubeInfo];
  1972. m_DoseUnit.m_TubeInfo.reset(new TUBEINFOMould(tempValue));
  1973. FireNotify(AttrKey::TUBEINFO, m_DoseUnit.m_TubeInfo->JSGet());
  1974. }
  1975. if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusSmall) > 0)
  1976. {
  1977. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusSmall];
  1978. m_DoseUnit.m_FocusSmall = tempValue;
  1979. }
  1980. if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusLarge) > 0)
  1981. {
  1982. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
  1983. m_DoseUnit.m_FocusLarge = tempValue;
  1984. }
  1985. if (m_GenConfig.GetKeyCount("GenCtrlMode") > 0)
  1986. {
  1987. m_nCtlMode = (float)m_GenConfig["GenCtrlMode"];//default 2
  1988. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
  1989. }
  1990. if (m_GenConfig.GetKeyCount("USECECMD") > 0)
  1991. {
  1992. m_bUseCECmd = (bool)m_GenConfig["USECECMD"];
  1993. }
  1994. m_bIsConfigLoaded = true;
  1995. return 0;
  1996. }
  1997. bool nsGEN::PSGHRDevice::EnableBucky(int nbucky)
  1998. {
  1999. char temp[50]{ 0 };
  2000. snprintf(temp, sizeof(temp), "BU%1d", nbucky);
  2001. return HWSend(temp, strlen(temp));
  2002. }
  2003. bool nsGEN::PSGHRDevice::ECHO(void)
  2004. {
  2005. return HWSend("EC", 2);
  2006. }
  2007. bool nsGEN::PSGHRDevice::SetABSModeNative(int nMode)
  2008. {
  2009. char temp[50]{ 0 };
  2010. snprintf(temp, sizeof(temp), "FLA%1d", nMode);
  2011. return HWSend(temp, strlen(temp));
  2012. }
  2013. bool nsGEN::PSGHRDevice::StartHardwareStatusThread()
  2014. {
  2015. if (!m_pHardwareStatusThread.joinable())
  2016. {
  2017. m_pHardwareStatusThread = std::thread(HardwareStatusThread, this);
  2018. return true;
  2019. }
  2020. return false;
  2021. }
  2022. void PSGHRDevice::HardwareStatusThread(PSGHRDevice* pParam)
  2023. {
  2024. PSGHRDevice* pCurGen = pParam;
  2025. if (pCurGen == NULL)
  2026. {
  2027. return;
  2028. }
  2029. pCurGen->HeartBeatFlag = true;
  2030. int messageIndex = 0;
  2031. int currtTime = pCurGen->m_iLoopTime;
  2032. while (pCurGen->m_bExtraFlag)
  2033. {
  2034. currtTime = pCurGen->m_iLoopTime;
  2035. Sleep(currtTime);
  2036. if (messageIndex % 5 == 0)
  2037. {
  2038. pCurGen->HWSend("HE?", 3);
  2039. Sleep(100);
  2040. pCurGen->HWSend("ST?", 3);
  2041. }
  2042. messageIndex++;
  2043. }
  2044. }
  2045. //-----------------------------------------------------------------------------
  2046. // PSGHRDriver
  2047. //-----------------------------------------------------------------------------
  2048. nsGEN::PSGHRDriver::PSGHRDriver()
  2049. : m_scfWrapper(std::make_shared<SCFWrapper>())
  2050. {
  2051. m_pAttribute.reset(new ResDataObject());
  2052. m_pDescription.reset(new ResDataObject());
  2053. }
  2054. nsGEN::PSGHRDriver::~PSGHRDriver()
  2055. {
  2056. Disconnect();
  2057. }
  2058. void nsGEN::PSGHRDriver::Prepare()
  2059. {
  2060. // ��ʼ����־ϵͳ
  2061. std::string strLogPath = GetProcessDirectory() + R"(/Conf/log_config.xml)";
  2062. std::string LogHost = "DevPSGHR";
  2063. std::string moduleName = "DevPSGHR";
  2064. bool ret = initLogModule(
  2065. LogHost, // ��������������־·���е�{host}ռλ����
  2066. moduleName, // Ψһģ����
  2067. strLogPath, // ��������
  2068. true // �Ƿ����������̨����ѡ��
  2069. );
  2070. if (!ret) {
  2071. std::cerr << "Log init failed!" << std::endl;
  2072. return;
  2073. }
  2074. PSGHR_SetLocalModuleName(moduleName);
  2075. m_SCFDllName = GetConnectDLL(m_ConfigFileName);
  2076. FINFO("OK.");
  2077. }
  2078. std::string nsGEN::PSGHRDriver::DriverProbe()
  2079. {
  2080. FINFO("DriverProbe in \n");
  2081. ResDataObject r_config, HardwareInfo;
  2082. if (r_config.loadFile(m_ConfigFileName.c_str()))
  2083. {
  2084. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  2085. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  2086. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  2087. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  2088. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  2089. }
  2090. else
  2091. {
  2092. HardwareInfo.add("MajorID", "Generator");
  2093. HardwareInfo.add("MinorID", "Dr");
  2094. HardwareInfo.add("VendorID", "PSGHR");
  2095. HardwareInfo.add("ProductID", "HF");
  2096. HardwareInfo.add("SerialID", "Drv");
  2097. }
  2098. string ret = HardwareInfo.encode();
  2099. return ret;
  2100. }
  2101. bool nsGEN::PSGHRDriver::ReConnection()
  2102. {
  2103. Disconnect();
  2104. FINFO("ReConnection:SCF Disconnect");
  2105. ResDataObject Connection = GetConnectParam(m_ConfigFileName);
  2106. FINFO("ReConnection:{$} \n", Connection.encode());
  2107. auto erCode = m_scfWrapper->Connect(Connection, &PSGHRDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  2108. if (erCode == SCF_SUCCEED)
  2109. {
  2110. Sleep(1000);
  2111. // �����������ݽ��ջص�
  2112. m_scfWrapper->SetDataReceivedCallback([this](const char* data, uint32_t length) {
  2113. this->Dequeue(data, length);
  2114. });
  2115. // �����Զ�����
  2116. m_scfWrapper->StartAutoReceive();
  2117. return true;
  2118. }
  2119. else
  2120. {
  2121. FINFO("ReConnection failed");
  2122. }
  2123. return false;
  2124. }
  2125. bool nsGEN::PSGHRDriver::Connect()
  2126. {
  2127. std::lock_guard<std::mutex> lock(m_connectionMutex);
  2128. const auto currentState = m_connectionState.load();
  2129. auto now = std::chrono::steady_clock::now();
  2130. // 1. 处理可重试的失败状态
  2131. if (currentState == ConnectionState::Failed) {
  2132. if ((now - m_lastConnectionAttempt) >= RETRY_INTERVAL && m_connectionRetryCount < MAX_RETRY_COUNT) {
  2133. m_connectionState = ConnectionState::Disconnected;
  2134. }
  2135. else {
  2136. return false; // 不满足重试条件,直接返回
  2137. }
  2138. }
  2139. // 2. 检查无效状态(正在连接/已连接但实际有效)
  2140. if (currentState == ConnectionState::Connecting) {
  2141. FINFO("Already connecting (type: {$})",
  2142. m_currentConnType == ConnectionType::Serial ? "Serial" : "Ethernet");
  2143. return true;
  2144. }
  2145. if (currentState == ConnectionState::Connected && m_scfWrapper && m_scfWrapper->IsConnected()) {
  2146. FINFO("Already connected (type: {$})",
  2147. m_currentConnType == ConnectionType::Serial ? "Serial" : "Ethernet");
  2148. return true;
  2149. }
  2150. // 3. 检查重试间隔
  2151. if (m_connectionRetryCount > 0 && (now - m_lastConnectionAttempt) < RETRY_INTERVAL) {
  2152. FINFO("Retry in {$}s (type: {$})",
  2153. std::chrono::duration_cast<std::chrono::seconds>(RETRY_INTERVAL - (now - m_lastConnectionAttempt)).count(),
  2154. m_currentConnType == ConnectionType::Serial ? "Serial" : "Ethernet");
  2155. return false;
  2156. }
  2157. ResDataObject connParam = GetConnectParam(m_ConfigFileName);
  2158. std::string connPortStr = "";
  2159. std::string connTypeStr = (std::string)connParam["type"]; // 从配置读取type字段
  2160. m_currentConnType = (connTypeStr == "COM") ? ConnectionType::Serial : ConnectionType::Ethernet;
  2161. if (m_currentConnType == ConnectionType::Serial)
  2162. {
  2163. connPortStr = (std::string)connParam["port"];// 从配置读取port字段
  2164. // 查找配置端口在现有端口列表中的位置
  2165. auto it = std::find(m_serialPorts.begin(), m_serialPorts.end(), connPortStr);
  2166. if (it == m_serialPorts.end()) {
  2167. // 配置的端口不在列表中,添加到首位
  2168. FINFO("Configured serial port {$} not found, adding to front of port list", connPortStr);
  2169. m_serialPorts.insert(m_serialPorts.begin(), connPortStr);
  2170. }
  2171. else if (it != m_serialPorts.begin()) {
  2172. // 配置的端口存在但不在首位,移动到首位
  2173. FINFO("Moving configured serial port {$} to front of port list", connPortStr);
  2174. m_serialPorts.erase(it);
  2175. m_serialPorts.insert(m_serialPorts.begin(), connPortStr);
  2176. }
  2177. }
  2178. // 4. 执行连接流程
  2179. m_connectionState = ConnectionState::Connecting;
  2180. m_lastConnectionAttempt = now;
  2181. std::string connInfo;
  2182. try {
  2183. if (m_currentConnType == ConnectionType::Serial) {
  2184. // 串口连接:使用当前索引的端口
  2185. std::string currentPort = m_serialPorts[m_currentSerialPortIndex];
  2186. connParam.update("port", currentPort.c_str()); // 将当前尝试的端口写入参数
  2187. connInfo = "Serial (port: " + currentPort + ")";
  2188. }
  2189. else {
  2190. // 网口连接:直接使用配置参数
  2191. connInfo = "Ethernet (ip: " + std::string(connParam["ip"]) + ")";
  2192. }
  2193. FINFO("Enter Connect ({$}), config: {$}", connInfo, connParam.encode());
  2194. if (!m_scfWrapper->Initialize(m_SCFDllName)) {
  2195. FINFO("Init failed: {$}", m_scfWrapper->GetLastError());
  2196. m_connectionState = ConnectionState::Failed;
  2197. return false;
  2198. }
  2199. m_scfWrapper->SetDataReceivedCallback([this](const char* data, uint32_t length) {
  2200. this->Dequeue(data, length);
  2201. });
  2202. auto erCode = m_scfWrapper->Connect(connParam, &PSGHRDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  2203. if (erCode != SCF_SUCCEED || !m_scfWrapper->StartAutoReceive()) {
  2204. FINFO("Connect failed (code: {$}) for {$}", erCode, connInfo);
  2205. m_scfWrapper->Disconnect();
  2206. m_connectionState = ConnectionState::Failed;
  2207. // 串口连接:未遍历完所有端口时,优先切换端口重试(不计入总重试次数)
  2208. if (m_currentConnType == ConnectionType::Serial) {
  2209. int nextIndex = (m_currentSerialPortIndex + 1) % m_serialPorts.size();
  2210. // 判断是否已遍历所有端口(当前索引是最后一个时,nextIndex会回到0)
  2211. bool allPortsTried = (nextIndex == 0);
  2212. if (!allPortsTried) {
  2213. // 未遍历完所有端口:切换到下一端口,不增加重试计数
  2214. m_currentSerialPortIndex = nextIndex;
  2215. m_connectionRetryCount = 0;
  2216. FINFO("Trying next serial port: {$}", m_serialPorts[nextIndex]);
  2217. return false; // 触发外部线程立即尝试下一端口
  2218. }
  2219. else {
  2220. // 已遍历所有端口:重置到第一个端口,增加重试计数(进入间隔等待)
  2221. m_currentSerialPortIndex = 0;
  2222. m_connectionRetryCount++;
  2223. FINFO("All serial ports tried, retry count: {$}/{$}", m_connectionRetryCount, MAX_RETRY_COUNT);
  2224. return false;
  2225. }
  2226. }
  2227. // 所有端口失败(串口)或网口失败,才增加总重试计数
  2228. m_connectionRetryCount++;
  2229. return false;
  2230. }
  2231. // 连接成功:重置状态
  2232. m_connectionState = ConnectionState::Connected;
  2233. m_connectionRetryCount = 0;
  2234. m_currentSerialPortIndex = 0; // 重置串口端口索引
  2235. FINFO("Connected successfully ({$})", connInfo);
  2236. return true;
  2237. }
  2238. catch (const std::exception& e) {
  2239. FINFO("Exception for {$}: {$}", connInfo, e.what());
  2240. m_connectionState = ConnectionState::Failed;
  2241. m_connectionRetryCount++;
  2242. return false;
  2243. }
  2244. }
  2245. auto nsGEN::PSGHRDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  2246. {
  2247. FINFO("CreateDevice in\n");
  2248. m_pDevice = new PSGHRDevice(EventCenter, m_scfWrapper, m_ConfigFileName);
  2249. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDevice));
  2250. FINFO("CreateDevice out\n");
  2251. return dev;
  2252. }
  2253. void nsGEN::PSGHRDriver::FireNotify(int code, std::string key, std::string content)
  2254. {
  2255. EventCenter->OnNotify(code, key, content);
  2256. }
  2257. bool nsGEN::PSGHRDriver::isConnected() const
  2258. {
  2259. const auto state = m_connectionState.load();
  2260. // 1. 连接中/实际已连接:返回true(无需重连)
  2261. if (state == ConnectionState::Connecting || (m_scfWrapper && m_scfWrapper->IsConnected())) {
  2262. FINFO(state == ConnectionState::Connecting ? "Connecting in progress" : "Already connected");
  2263. return true;
  2264. }
  2265. // 2. 失败状态处理:判断是否允许重试
  2266. if (state == ConnectionState::Failed) {
  2267. auto now = std::chrono::steady_clock::now();
  2268. const auto timeSinceLast = now - m_lastConnectionAttempt;
  2269. // 2.1 达到最大重试次数,但超过重置间隔:重置计数,允许重新重试
  2270. if (m_connectionRetryCount >= MAX_RETRY_COUNT && timeSinceLast >= RESET_RETRY_AFTER) {
  2271. FINFO("Max retries reached, resetting count after {$}s",
  2272. std::chrono::duration_cast<std::chrono::seconds>(timeSinceLast).count());
  2273. m_connectionRetryCount = 0; // 重置计数(因mutable修饰,const函数可修改)
  2274. }
  2275. // 2.2 不适合重连(时间未到 或 次数仍超限):返回true阻止重连
  2276. if (timeSinceLast < RETRY_INTERVAL || m_connectionRetryCount >= MAX_RETRY_COUNT) {
  2277. FINFO(timeSinceLast < RETRY_INTERVAL ?
  2278. "Retry later ({$}s)" : "Max retries, waiting {$}s to reset",
  2279. std::chrono::duration_cast<std::chrono::seconds>(
  2280. timeSinceLast < RETRY_INTERVAL ? RETRY_INTERVAL - timeSinceLast : RESET_RETRY_AFTER - timeSinceLast
  2281. ).count()
  2282. );
  2283. return true;
  2284. }
  2285. }
  2286. // 3. 其他情况(适合重连):返回false触发Connect()
  2287. return false;
  2288. }
  2289. std::string nsGEN::PSGHRDriver::GetResource()
  2290. {
  2291. FDEBUG("GetResource");
  2292. ResDataObject r_config, temp;
  2293. if (!temp.loadFile(m_ConfigFileName.c_str()))
  2294. {
  2295. return "";
  2296. }
  2297. m_ConfigAll = temp;
  2298. r_config = temp["CONFIGURATION"];
  2299. m_Configurations = r_config;
  2300. ResDataObject DescriptionTemp;
  2301. ResDataObject DescriptionSend;
  2302. ResDataObject m_DescriptionSend;
  2303. ResDataObject ListTemp;
  2304. string strTemp = "";
  2305. string strIndex = "";
  2306. int nTemp = -1;
  2307. char sstream[10] = { 0 };
  2308. string strValue = "";
  2309. string strType = "";
  2310. /***
  2311. * 1. ͨ��ѭ����������������д��pDeviceConfig
  2312. * 2. ��¼��������ڲ�key�Լ��������ͣ����Ͷ�Ӧ�˲�ͬ�����ļ�·�������ڶ�д��ʵֵ
  2313. ***/
  2314. try
  2315. {
  2316. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  2317. m_pAttribute->clear();
  2318. m_pDescription->clear();
  2319. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  2320. {
  2321. DescriptionTemp.clear();
  2322. DescriptionSend.clear();
  2323. ListTemp.clear();
  2324. //AttributeType
  2325. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  2326. DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  2327. DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  2328. strType = strTemp;
  2329. //AttributeKey
  2330. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  2331. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  2332. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue);
  2333. //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  2334. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2335. if ("int" == strType)
  2336. {
  2337. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  2338. }
  2339. else if ("float" == strType)
  2340. {
  2341. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  2342. }
  2343. else
  2344. {
  2345. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  2346. }
  2347. //printf("********************************outkey =%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  2348. //AttributeAccess
  2349. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  2350. DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
  2351. DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
  2352. /*
  2353. //AttributeRangeMin
  2354. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  2355. if (strTemp != "") //����Ҫ��������Ϊ��
  2356. {
  2357. DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
  2358. }
  2359. //AttributeRangeMax
  2360. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  2361. if (strTemp != "") //����Ҫ��������Ϊ��
  2362. {
  2363. DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
  2364. }
  2365. */
  2366. //AttributeList
  2367. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  2368. if (nTemp > 0)
  2369. {
  2370. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  2371. {
  2372. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  2373. auto temKey = std::to_string(nListIndex);
  2374. ListTemp.add(temKey.c_str(), strTemp.c_str());
  2375. }
  2376. DescriptionTemp.add(ConfKey::CcosList, ListTemp);
  2377. DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
  2378. }
  2379. //AttributeRequired
  2380. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  2381. DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
  2382. DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
  2383. //AttributeDefaultValue
  2384. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  2385. if (strTemp != "")
  2386. {
  2387. DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  2388. DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  2389. }
  2390. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2391. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  2392. m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
  2393. }
  2394. }
  2395. catch (ResDataObjectExption& e)
  2396. {
  2397. FERROR("Get config error: {$}", e.what());
  2398. return "";
  2399. }
  2400. ResDataObject resDeviceResource;
  2401. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  2402. resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
  2403. ResDataObject DescriptionTempEx;
  2404. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  2405. m_DeviceConfig.clear();
  2406. m_DeviceConfig = DescriptionTempEx;
  2407. //FDEBUG("local ************* get resource over {$}", DescriptionTempEx.encode());
  2408. //printf("local ************* get resource over %s \n", DescriptionTempEx.encode());
  2409. resDeviceResource.clear();
  2410. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  2411. resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
  2412. DescriptionTempEx.clear();
  2413. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  2414. m_DeviceConfigSend.clear();
  2415. m_DeviceConfigSend = DescriptionTempEx;
  2416. string res = m_DeviceConfigSend.encode();
  2417. //printf("%s", res.c_str());
  2418. //FDEBUG("get resource over {$}", DescriptionTempEx.encode());
  2419. //("************* get resource over %s \n", DescriptionTempEx.encode());
  2420. return res;
  2421. }
  2422. std::string nsGEN::PSGHRDriver::DeviceProbe()
  2423. {
  2424. FINFO("std::string nsGEN::PSGHRDriver::DeviceProbe() in\n");
  2425. ResDataObject r_config, HardwareInfo;
  2426. if (r_config.loadFile(m_ConfigFileName.c_str()))
  2427. {
  2428. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  2429. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  2430. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  2431. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  2432. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  2433. }
  2434. else
  2435. {
  2436. HardwareInfo.add("MajorID", "Generator");
  2437. HardwareInfo.add("MinorID", "Dr");
  2438. HardwareInfo.add("VendorID", "PSGHR");
  2439. HardwareInfo.add("ProductID", "HF");
  2440. HardwareInfo.add("SerialID", "Dev");
  2441. }
  2442. string ret = HardwareInfo.encode();
  2443. FINFO("std::string nsGEN::PSGHRDriver::DeviceProbe() out\n");
  2444. return ret;
  2445. }
  2446. void nsGEN::PSGHRDriver::Disconnect()
  2447. {
  2448. if (m_scfWrapper) {
  2449. m_scfWrapper->StopAutoReceive();
  2450. m_scfWrapper->Disconnect();
  2451. }
  2452. }
  2453. void nsGEN::PSGHRDriver::Dequeue(const char* Packet, DWORD Length)
  2454. {
  2455. DecodeFrame(Packet, Length);
  2456. }
  2457. PACKET_RET nsGEN::PSGHRDriver::callbackPackageProcess(const char* RecData, uint32_t nLength, uint32_t& PacketLength)
  2458. {
  2459. if (nLength < 1)
  2460. {
  2461. FINFO("nLength < 1, nLength=={$} \n", nLength);
  2462. return PACKET_USELESS;
  2463. }
  2464. for (DWORD i = 0; i < nLength - 1; i++)
  2465. {
  2466. if (RecData[i] == 0x02)
  2467. {
  2468. if (i != 0)
  2469. {
  2470. PacketLength = i;
  2471. char strtemp[100] = { 0 };
  2472. memcpy(strtemp, RecData, i);
  2473. strtemp[PacketLength + 1] = 0;
  2474. return PACKET_USELESS;
  2475. }
  2476. }
  2477. if (RecData[i] == 0x03)
  2478. {
  2479. PacketLength = i + 2;
  2480. char strtemp[100] = { 0 };
  2481. memcpy(strtemp, RecData, i);
  2482. strtemp[PacketLength + 1] = 0;
  2483. FINFO("==IN==:{$}\n", strtemp);
  2484. return PACKET_ISPACKET;
  2485. }
  2486. }
  2487. return PACKET_NOPACKET;
  2488. }
  2489. bool nsGEN::PSGHRDriver::GetDeviceConfig(std::string& Cfg)
  2490. {
  2491. Cfg = m_DeviceConfigSend.encode();
  2492. printf("GetDeviceConfig over , %s", Cfg.c_str());
  2493. return true;
  2494. }
  2495. bool nsGEN::PSGHRDriver::SetDeviceConfig(std::string Cfg)
  2496. {
  2497. FINFO("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  2498. printf("\n--Func-- SetDeviceConfig %s\n", Cfg.c_str());
  2499. ResDataObject DeviceConfig;
  2500. DeviceConfig.decode(Cfg.c_str());
  2501. ResDataObject DescriptionTempEx;
  2502. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  2503. FDEBUG("Attribute:{$}", DescriptionTempEx.encode());
  2504. bool bSaveFile = false; //true:���±��������ļ�
  2505. string strAccess = "";
  2506. for (int i = 0; i < DescriptionTempEx.size(); i++)
  2507. {
  2508. string strKey = DescriptionTempEx.GetKey(i);
  2509. FINFO("{$}", strKey.c_str());
  2510. printf("%s\n", strKey.c_str());
  2511. try
  2512. {
  2513. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  2514. {
  2515. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  2516. if ("RW" == strAccess)
  2517. {
  2518. //�޸Ķ�Ӧ���ã���������Ԫ��������Ҫͬʱ�������޸ĺ����޸���ʵֵ
  2519. //1. �޸��ڴ��е�ֵ�����ڸ��ϲ㷢��Ϣ
  2520. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  2521. //2. �õ�Innerkey
  2522. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  2523. FINFO("nConfigInfoCount {$}", nConfigInfoCount);
  2524. string strTemp = ""; //�洢AttributeKey
  2525. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  2526. {
  2527. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2528. if (strTemp == strKey)
  2529. {
  2530. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  2531. break;
  2532. }
  2533. }
  2534. //3. �޸������ļ��е�ֵ
  2535. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  2536. {
  2537. FDEBUG("SetDeviceConfigValue over");
  2538. bSaveFile = true;
  2539. }
  2540. }
  2541. else
  2542. {
  2543. FINFO("{$} is not a RW configuration item", strKey.c_str());
  2544. }
  2545. }
  2546. else
  2547. {
  2548. FINFO("without this attribute {$}", strKey.c_str());
  2549. }
  2550. }
  2551. catch (ResDataObjectExption& e)
  2552. {
  2553. printf("\nSetDriverConfig crashed: %s\n", e.what());
  2554. FERROR("SetDriverConfig crashed: {$}", e.what());
  2555. return false;
  2556. }
  2557. }
  2558. if (bSaveFile)
  2559. {
  2560. //3. ���±��������ļ�
  2561. SaveConfigFile(true);
  2562. }
  2563. return true;
  2564. }
  2565. bool nsGEN::PSGHRDriver::SaveConfigFile(bool bSendNotify)
  2566. {
  2567. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  2568. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  2569. FINFO("SaveConfigFile over {$}", bRt);
  2570. return true;
  2571. }
  2572. bool nsGEN::PSGHRDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  2573. {
  2574. strValue = "";
  2575. string strTemp = pInnerKey;
  2576. if (1 == nPathID) //��DriverConfig·����ÿ��DPC�Լ��������ļ���ȡ
  2577. {
  2578. int pos = 0;
  2579. ResDataObject resTemp = config;
  2580. while ((pos = strTemp.find_first_of(',')) != string::npos)
  2581. {
  2582. string Key = strTemp.substr(0, pos);
  2583. string TempValue = resTemp[Key.c_str()].encode();
  2584. // printf("-TempValue=== %s", TempValue.c_str());
  2585. resTemp.clear();
  2586. resTemp.decode(TempValue.c_str());
  2587. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  2588. //printf("-************--%s", strTemp.c_str());
  2589. }
  2590. if (strTemp != "")
  2591. {
  2592. strValue = (string)resTemp[strTemp.c_str()];
  2593. }
  2594. else
  2595. {
  2596. strValue = (string)resTemp;
  2597. }
  2598. }
  2599. //printf("------------%s", strValue.c_str());
  2600. return true;
  2601. }
  2602. bool nsGEN::PSGHRDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  2603. {
  2604. string strTemp = pInnerKey;
  2605. FDEBUG("Begin to change {$} item value to {$}", pInnerKey, szValue);
  2606. if (1 == nPathID) //��DriverConfig·����ÿ��DPC�Լ��������ļ���ȡ
  2607. {
  2608. try {
  2609. int pos = 0;
  2610. ResDataObject* resTemp = &config;
  2611. while ((pos = strTemp.find_first_of(',')) != string::npos)
  2612. {
  2613. string Key = strTemp.substr(0, pos);
  2614. resTemp = &(*resTemp)[Key.c_str()];
  2615. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  2616. }
  2617. if (strTemp != "")
  2618. {
  2619. (*resTemp)[strTemp.c_str()] = szValue;
  2620. }
  2621. else
  2622. {
  2623. *resTemp = szValue;
  2624. }
  2625. }
  2626. catch (ResDataObjectExption& e)
  2627. {
  2628. FERROR("SetDriverConfigvalue crashed: {$}", e.what());
  2629. return false;
  2630. }
  2631. }
  2632. return true;
  2633. }
  2634. //-----------------------------------------------------------------------------
  2635. // GetIODriver & CreateIODriver
  2636. //-----------------------------------------------------------------------------
  2637. static nsGEN::PSGHRDriver gIODriver;
  2638. extern "C" CCOS::Dev::IODriver * GetIODriver()
  2639. {
  2640. return &gIODriver;
  2641. }
  2642. extern "C" CCOS::Dev::IODriver * CreateIODriver()
  2643. {
  2644. pIODriver = new nsGEN::PSGHRDriver();
  2645. return pIODriver;
  2646. }