CCOS.Dev.Generator.PSG_HR.cpp 98 KB

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