CCOS.Dev.Generator.PSG_HR.cpp 99 KB

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