DIOS.Dev.Generator.PSG_HR.cpp 95 KB

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