CCOS.Dev.Generator.PSG_HR.cpp 97 KB

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