DIOS.Dev.Generator.ContainerExample.cpp 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316
  1. // CCOS.Dev.GEN.Almax.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. #include "stdafx.h"
  4. #include <assert.h>
  5. #include <functional>
  6. #include <LogicDevice.h>
  7. using namespace std::placeholders;
  8. #include "Helper.JSON.hpp"
  9. #include "CCOS.Dev.Generator.ContainerExample.h"
  10. using namespace CCOS::Dev::Detail::Generator;
  11. namespace nsGEN = CCOS::Dev::Detail::Generator;
  12. //关闭无关警告
  13. #pragma warning (disable:4244) // warning C4244: “初始化”: 从“double”转换到“float”,可能丢失数据
  14. #pragma warning (disable:4305) // warning C4305: “参数”: 从“double”到“float”截断
  15. #pragma warning (disable:4267) // warning C4267 : “初始化”: 从“size_t”转换到“int”,可能丢失数据
  16. #pragma warning (disable:4805) // warning C4805: “!=”: 在操作中将类型“bool”与类型“int”混合不安全
  17. //全局定义
  18. static nsGEN::AlmaxDriver* pIODriver = nullptr;
  19. //指令头
  20. #define Almax_CMD_GetGenVer "C0" //5.1.1.MESSAGE TYPE C0H <REQ SW VER>
  21. #define Almax_CMD_SetLanguage "82" //5.1.2.MESSAGE TYPE 82H <LANGUAGE USED>
  22. #define Almax_CMD_SetAPRAPF "38" //5.1.3.MESSAGE TYPE 38H <EXAM SELECTION>
  23. #define Almax_CMD_SetAnatomic "39" //5.1.4.MESSAGE TYPE 39H <ANATOMIC>解剖
  24. #define Almax_CMD_SetProject "3A" //5.1.5.MESSAGE TYPE 3AH <PROJECTION>
  25. #define Almax_CMD_SetFluPPS "3C" //5.1.6.MESSAGE TYPE 3CH <PULSED RATE>
  26. #define Almax_CMD_SetRadPPS "3D" //5.1.7.MESSAGE TYPE 3DH <RAD RATE>
  27. #define Almax_CMD_SetRadDose "49" //5.1.8.MESSAGE TYPE 49H <RAD DOSE CONTROL>
  28. #define Almax_CMD_SetAcqData "4A" //5.1.9.MESSAGE TYPE 4AH <ACQUISITION FLUORO DATA>采集透视数据
  29. #define Almax_CMD_SetABSKV "4B" //5.1.10. MESSAGE TYPE 4BH <ABC SET KV>
  30. #define Almax_CMD_GetABSKV "4C" //5.1.11. MESSAGE TYPE 4CH <ABC GET KV>
  31. #define Almax_CMD_SetABSGrey "4E" //5.1.12. MESSAGE TYPE 4EH <ABC SET CURRENT GREY LEVEL>
  32. #define Almax_CMD_GetStatus "50" //5.1.13. MESSAGE TYPE 50H <GET STATUS C-ARM>
  33. #define Almax_CMD_GetRPData "51" //5.1.14. MESSAGE TYPE 51H <GET RP DATA>
  34. #define Almax_CMD_GetFluDose "52" //5.1.15. MESSAGE TYPE 52H <GET DOSE FLUO>
  35. #define Almax_CMD_GetRadDose "53" //5.1.16. MESSAGE TYPE 53H <GET DOSE RAD>
  36. #define Almax_CMD_SetFPDTemp "54" //5.1.17. MESSAGE TYPE 54H <SET TEMP FPD>
  37. #define Almax_CMD_SetNewExam "55" //5.1.18. MESSAGE TYPE 55H <SET NEW STUDY>
  38. #define Almax_CMD_SetlowDose "56" //5.1.19. MESSAGE TYPE 56H <SET LOW DOSE>
  39. #define Almax_CMD_SetPatient "58" //5.1.21. MESSAGE TYPE 58H <PATIENT DATA>
  40. #define Almax_CMD_SetPhysique "59" //5.1.22. MESSAGE TYPE 59H <PATIENT SIZE>
  41. #define Almax_CMD_ResKeyEvent "00" //6.1.1.MESSAGE TYPE 00H <KEY EVENT>
  42. #define Almax_CMD_ResGenVer "81" //6.1.2.MESSAGE TYPE 81H <SW VER> (作为消息 83H 的替代方案)
  43. #define Almax_CMD_ResArchVer "83" //6.1.3.MESSAGE TYPE 83H <SW VER> (作为消息 81H 的替代方案)
  44. #define Almax_CMD_ResExam "3E" //6.1.4.MESSAGE TYPE 3EH <REMOTE EXAM SELECT>
  45. #define Almax_CMD_ResPhysique "3F" //6.1.5.MESSAGE TYPE 3FH <REMOTE PATIENT SIZE SELECTION>
  46. #define Almax_CMD_ResABSKV "4D" //6.1.6.MESSAGE TYPE 4DH <ABC STATUS KV>
  47. #define Almax_CMD_ReslowDose "57" //6.1.7.MESSAGE TYPE 57H <STATUS LOW DOSE>
  48. #define Almax_CMD_ResFluPost "72" //6.1.8.MESSAGE TYPE 72H <DOSE FLUO + COLLIMATOR>
  49. #define Almax_CMD_ResFLUPost "73" //6.1.9.MESSAGE TYPE 73H <DOSE FLUO X10 + COLLIMATOR >
  50. #define Almax_CMD_ResRadPost "7B" //6.1.10. MESSAGE TYPE 7BH <DOSE RAD>
  51. #define Almax_CMD_ResRADPost "74" //6.1.11. MESSAGE TYPE 74H <DOSE RAD X10>
  52. #define Almax_CMD_ResRPData "91" //6.1.12. MESSAGE TYPE 91H <RP DATA>
  53. #define Almax_CMD_ResStatus "76" //6.1.13. MESSAGE TYPE 76H <STATUS C-ARM>
  54. #define Almax_CMD_ResSID "77" //6.1.14. Message Type 77H <STATUS C-ARM SID>
  55. #define Almax_CMD_ResCollData "7E" //6.1.15. MESSAGE TYPE 7EH <STATUS_COL>
  56. #define Almax_CMD_ResRotating "7F" //6.1.16. MESSAGE TYPE 7FH <STATUS_ROTATING_COL>
  57. #define Almax_CMD_ResErrWarn "80" //6.1.17. MESSAGE TYPE 80H <ERROR / WARNING>
  58. //设置相关常量
  59. static const int msTimeOut_Lock = 500; //通讯接口锁定时间
  60. #define Almax_Com_NormalLen 300
  61. #define Almax_LoopDefHBTime 1000
  62. #define Almax_LoopExpHBTime 500
  63. #define Almax_STX 0x02
  64. #define Almax_ETX 0x03
  65. #define Almax_ACK 0x06
  66. #define Almax_NAK 0x15
  67. /*
  68. *串口/以太网通信帧格式:
  69. <STX><code[30H-39H,41H-46H]><CSUM[所有code的异或值]><ETX>
  70. 解释:
  71. <STX> = 1 ASCII 0x02 帧头
  72. <code> = 1 ASCII指令头+不定长属性项、属性值
  73. <CSUM> = 校验和
  74. <ETX> = 1 ASCII 0x03 帧尾
  75. 串口通信设置:
  76. . 19200 波特率
  77. . No Parity
  78. . 8 Data Bits
  79. . 2 Stop Bit
  80. . 无握手过程
  81. */
  82. //设置对应通信接口库
  83. #ifdef _WIN64
  84. #ifdef _DEBUG
  85. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64D.dll";
  86. #else
  87. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64.dll";
  88. #endif
  89. #endif
  90. #ifdef _WIN64
  91. #ifdef _DEBUG
  92. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64D.dll";
  93. #else
  94. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64.dll";
  95. #endif
  96. #endif
  97. Log4CPP::Logger* gLogger = nullptr;
  98. //指令操作关联结构
  99. nsGEN::tFrameMapItem::tFrameMapItem()
  100. {
  101. m_fFun = NULL;
  102. }
  103. nsGEN::tFrameMapItem::tFrameMapItem(cbFun f)
  104. {
  105. m_fFun = f;
  106. }
  107. nsGEN::tFrameMapItem& nsGEN::tFrameMapItem::operator =(const tFrameMapItem& value)
  108. {
  109. m_fFun = value.m_fFun;
  110. return *this;
  111. }
  112. //响应操作对照表
  113. static std::map <string,tFrameMapItem> arFrame;
  114. //生成命令校验和:cmdData 为 <CMD>; size:指令长度+1 BYTE CheckSum
  115. char ComputeCheckSum(const char* cmdData, int& size)
  116. {
  117. try
  118. {
  119. char AsciiSum = 0x00;
  120. if (size < 2) //1 BYTE CMD_ID + 1 BYTE Reserved
  121. {
  122. FDEBUG("ComputeCheckSum:failed[0x00]");
  123. return AsciiSum;
  124. }
  125. for (int i = 0; i < size; i++) //每字节相加
  126. {
  127. AsciiSum ^= cmdData[i];
  128. }
  129. FDEBUG("ComputeCheckSum:[0x{$:x}]", AsciiSum);
  130. return (char)AsciiSum;
  131. }
  132. catch (...)
  133. {
  134. FDEBUG("ComputeCheckSum:Error[0x00]");
  135. return 0x00;
  136. }
  137. }
  138. //查找响应操作对照表执行对应操作
  139. static bool DecodeFrame(const char* strFrame, int length)
  140. {
  141. char data[Almax_Com_NormalLen] = { 0 };
  142. strncpy_s(data, strFrame+1, 2);
  143. auto found = arFrame.find(data);//此处pr用来在arFrame中找到对于的包头
  144. if (found == arFrame.end())
  145. {
  146. return false;
  147. }
  148. //found->second.tChangeWaitState(0, data);
  149. int cmdHead = found->first.length();
  150. memcpy(data, strFrame + cmdHead + 1, length - cmdHead - 1);
  151. found->second.m_fFun(data, length - cmdHead);//第二个参数 不重要
  152. return true;
  153. }
  154. //取值集合
  155. std::vector <float> g_MAS_List = { 0.5,0.6,0.8,1,1.6,2,2.5,3.2,4,5,6.3,8,10,12.5,16,20,25,32,40,50,63,71,80,100,125,160,200,250,320,400,500,630 };
  156. std::vector <float> g_MS_List = { 5,6,8,10,12,16,20,25,32,40,50,63,80,100,125,160,200,250,320,400,500,630,800,1000,1250,1600,2000,2500,3200,4000,5000,6300,8000,10000 };
  157. //-----------------------------------------------------------------------------
  158. // AlmaxDevice
  159. //-----------------------------------------------------------------------------
  160. atomic<bool> nsGEN::AlmaxDevice::m_bExtraFlag = false;
  161. atomic<int> nsGEN::AlmaxDevice::m_iLoopTime = Almax_LoopDefHBTime;
  162. nsSerialGPM::CDeliverModule nsGEN::AlmaxDevice::m_tDelivermodule;
  163. static atomic<bool>HeartBeatFlag = false;
  164. nsGEN::AlmaxDevice::AlmaxDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF, string configfile) : super(center, SCF)
  165. {
  166. assert(EventCenter);
  167. //其余属性初始化
  168. ResDataObject temp;
  169. temp.loadFile(configfile.c_str());
  170. m_GenConfig = temp["CONFIGURATION"];
  171. m_pHardwareStatusThread = NULL;
  172. m_bExpEnable = false;
  173. m_iHeartBeats = 0;
  174. m_bConnectFlag = true;
  175. m_iLoopTime.store(Almax_LoopDefHBTime);
  176. //两种日志方式自行选择
  177. string version;
  178. if(GetVersion(version, hMyModule))
  179. FINFO("\n===============log begin : version:{$} ===================\n", version.c_str());
  180. else
  181. FINFO("\n===============log begin : version:0.0.0.0 ===================\n");
  182. //点片参数
  183. m_DoseUnit.m_KV.reset(new KVMould(40.0, 40.0, 150.0, 1.0)); //接口协议范围:40-150
  184. m_DoseUnit.m_MA.reset(new MAMould(10.0, 0, 1000, 0.1)); //接口协议范围:10-1000
  185. m_DoseUnit.m_MS.reset(new MSMould(500.0, 0, 65535, 0.01));//接口协议范围:0-65535
  186. m_DoseUnit.m_MAS.reset(new MASMould(0.5, 0, 1000.0, 0.01)); //接口协议范围:0.5-1000
  187. m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_AEC_MAS_MA, 1));
  188. m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
  189. m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_TYPE::FOCUS_LARGE, AttrKey::FOCUS_SMALL, AttrKey::FOCUS_LARGE, 1));
  190. m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
  191. m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
  192. m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
  193. m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
  194. m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
  195. m_DoseUnit.m_GenState.reset(new GENSTATEMould(0, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_NOWORK, 1));
  196. m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
  197. m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
  198. m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
  199. m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
  200. m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
  201. m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(EXPMODE_TYPE::Single));
  202. m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 16, 1));
  203. m_DoseUnit.m_FLFMode.reset(new FLFMODEMould(FLFMODE_TYPE::FLF_DISB));
  204. m_DoseUnit.m_BatteryChargeState.reset(new BATTERYCHARGSTATEMould(0, 0, 1, 1));
  205. m_DoseUnit.m_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(TUBETARGETMATERIAL_TYPE::MO));
  206. m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0, -45, 45, 1));
  207. //动态参数
  208. std::unique_ptr<FLUKVMould> m_FLKV;
  209. std::unique_ptr<FLUMAMould> m_FLMA;
  210. std::unique_ptr<FLUMSMould> m_FLMS;
  211. std::unique_ptr<FLAccTimeMould> m_FLAccTime;//透视累计时间
  212. std::unique_ptr<FLUIntTimeMould> m_FLIntTime;//脉冲周期时间
  213. std::unique_ptr<PPSMould> m_PPS;//帧率
  214. std::unique_ptr<FLUModeMould> m_FLMode;//透视模式: 0-非透视, 1-连续,2-脉冲,3-高剂量连续,4-高剂量脉冲
  215. std::unique_ptr<FLUABSStatusMould> m_ABSStatus;//ABS状态: 0-ABS关闭, 1-ABS启用(KV only), 2 - ABS启用(KV/mA)
  216. std::unique_ptr<FLUMagMould> m_MagSize;//fluoro mag 0 to 3 - sets Mag size, ASCII character for 255 - Mag selection disabled
  217. std::unique_ptr<FLUDoseLevelMould> m_DoseLevel;//剂量模式,DOSE_LEVEL_LOW = 0, DOSE_LEVEL_NORMAL = 1, DOSE_LEVEL_HIGH = 2 ,后来由于需要分开cine的dose level和 透视的dose level 互不影响,所以约定 10以后的值 给cine 使用。
  218. std::unique_ptr<FLUCurveMould> m_Curve;//ABS曲线 0 = OFF, 1-3 = curve enabled
  219. //cine
  220. std::unique_ptr<FLUCineKVMould> m_CineFLKV;//
  221. std::unique_ptr<FLUCineMAMould> m_CineFLMA;//
  222. std::unique_ptr<FLUCineMSMould> m_CineFLMS;//
  223. //实际曝光参数值
  224. m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 0.0, 50.0, 1.0));
  225. m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 0.0, 200.0, 0.1));
  226. m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 0.0, 12000.0, 0.01));
  227. m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.0, 600.0, 0.01));
  228. //发生器告警及错误消息
  229. m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
  230. if (m_GenConfig.GetKeyCount("loopEnable") > 0)
  231. {
  232. m_bExtraFlag = (int)m_GenConfig["loopEnable"];
  233. }
  234. if (m_GenConfig.GetKeyCount(ConfKey::CcosTubeInfo) > 0)
  235. {
  236. string tempValue = m_GenConfig[ConfKey::CcosTubeInfo];
  237. m_DoseUnit.m_TubeInfo.reset(new TUBEINFOMould(tempValue));
  238. FireNotify(AttrKey::TUBEINFO, m_DoseUnit.m_TubeInfo->JSGet());
  239. }
  240. if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusSmall) > 0)
  241. {
  242. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusSmall];
  243. m_DoseUnit.m_FocusSmall = tempValue;
  244. }
  245. if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusLarge) > 0)
  246. {
  247. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
  248. m_DoseUnit.m_FocusLarge = tempValue;
  249. }
  250. m_tDelivermodule.InitSendModle(this, &ProcessClientData, WriteLog);
  251. m_nCMDType_WaitTime = m_tDelivermodule.SetPriority(true, false, false, true, 100);
  252. m_nCMDType_HB = m_tDelivermodule.SetPriority(false, true, false, true, 100);
  253. m_nCMDType_WaitACK = m_tDelivermodule.SetPriority(true, false, 3, false, 0,true,1000);
  254. FINFO("m_nCMDType_WaitTime[{$}]m_nCMDType_HB[{$}] m_nCMDType_WaitACK[{$}]", m_nCMDType_WaitTime, m_nCMDType_HB, m_nCMDType_WaitACK);
  255. //配置响应操作对照表 供发生器回传的数据触发相应的操作
  256. OnCallBack();
  257. //将发生器可以对外提供的指令注册集进行补充
  258. Register();
  259. //重置发生器
  260. Reset();
  261. Sleep(500);
  262. //以下进行默认设置,需要注意默认值是否正确
  263. RefreshData(); //刷新初始数值
  264. //启动硬件状态轮询进程
  265. StartHardwareStatusThread();
  266. }
  267. nsGEN::AlmaxDevice::~AlmaxDevice()
  268. {
  269. m_bExtraFlag = false;
  270. FINFO("\n===============log end ===================\n");
  271. if (m_pHardwareStatusThread != NULL)
  272. {
  273. TerminateThread(m_pHardwareStatusThread, 0);
  274. m_pHardwareStatusThread = NULL;
  275. }
  276. arFrame.clear();
  277. }
  278. std::string nsGEN::AlmaxDevice::GetGUID() const
  279. {
  280. FINFO("===============GetGUID : {$} ===================\n", GeneratorUnitType);
  281. return GeneratorUnitType;
  282. }
  283. void nsGEN::AlmaxDevice::Register()
  284. {
  285. auto Disp = Dispatch.Lock().As();
  286. superGen::Register(Disp);
  287. superGen::RegisterKV(Disp);
  288. superGen::RegisterMA(Disp);
  289. superGen::RegisterMS(Disp);
  290. superGen::RegisterMAS(Disp);
  291. superGen::RegisterAEC(Disp);
  292. superGen::RegisterFOCUS(Disp);
  293. superGen::RegisterTECHMODE(Disp);
  294. superGen::RegisterExpEnable(Disp);
  295. superGen::RegisterGeneratortoSyncStatus(Disp);
  296. Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  297. auto fun_Clear_DAP = [this](auto in, auto& out)
  298. {
  299. return Clear_DAP();
  300. };
  301. Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
  302. auto fun_GetValue_DAP = [this](auto in, auto& out)
  303. {
  304. float value = 0;
  305. RET_STATUS ret = GetValue_DAP(value);
  306. out = ToJSON(value);
  307. return ret;
  308. };
  309. Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
  310. auto fun_StartMove = [this](auto in, auto& out)
  311. {
  312. return StartMove();
  313. };
  314. Disp->Action.Push("StartMove", fun_StartMove);
  315. auto fun_EndMove = [this](auto in, auto& out)
  316. {
  317. return EndMove();
  318. };
  319. Disp->Action.Push("EndMove", fun_EndMove);
  320. }
  321. RET_STATUS nsGEN::AlmaxDevice::IncKV()
  322. {
  323. if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
  324. float oldKV= m_DoseUnit.m_KV->Get();
  325. oldKV++;
  326. oldKV *= 1000;
  327. char temp[50] = { 0 };
  328. sprintf_s(temp, "10,%d,", (int)round(oldKV / 12.21));
  329. return HWSendWaittimeCMD(temp,strlen(temp));
  330. }
  331. RET_STATUS nsGEN::AlmaxDevice::DecKV()
  332. {
  333. if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
  334. float oldKV = m_DoseUnit.m_KV->Get();
  335. oldKV--;
  336. oldKV *= 1000;
  337. char temp[50] = { 0 };
  338. sprintf_s(temp, "10,%d,", (int)round(oldKV / 12.21));
  339. return HWSendWaittimeCMD(temp,strlen(temp));
  340. }
  341. RET_STATUS nsGEN::AlmaxDevice::SetKV(float value)
  342. {
  343. if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
  344. char temp[50] = { 0 };
  345. sprintf_s(temp, "10,%d,", (int)round(value * 1000 / 12.21));
  346. return HWSendWaittimeCMD(temp,strlen(temp));
  347. }
  348. RET_STATUS nsGEN::AlmaxDevice::IncMA()
  349. {
  350. if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
  351. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  352. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  353. {
  354. FINFO("Techmode is 2Point, Cannot inc MA \n");
  355. return RET_STATUS::RET_FAILED;
  356. }
  357. float oldMA = m_DoseUnit.m_MA->Get();
  358. oldMA++;
  359. char temp[50] = { 0 };
  360. sprintf_s(temp, "11,%d,", (int)round(oldMA / 0.04884));
  361. return HWSendWaittimeCMD(temp,strlen(temp));
  362. }
  363. RET_STATUS nsGEN::AlmaxDevice::DecMA()
  364. {
  365. if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
  366. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  367. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  368. {
  369. FINFO("Techmode is 2Point, Cannot dec MA \n");
  370. return RET_STATUS::RET_FAILED;
  371. }
  372. float oldMA = m_DoseUnit.m_MA->Get();
  373. oldMA--;
  374. char temp[50] = { 0 };
  375. sprintf_s(temp, "11,%d,", (int)round(oldMA / 0.04884));
  376. return HWSendWaittimeCMD(temp,strlen(temp));
  377. }
  378. RET_STATUS nsGEN::AlmaxDevice::SetMA(float value)
  379. {
  380. if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
  381. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  382. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  383. {
  384. FINFO("Techmode is 2Point, Cannot set MA \n");
  385. return RET_STATUS::RET_FAILED;
  386. }
  387. char temp[50] = { 0 };
  388. sprintf_s(temp, "11,%d,", (int)round(value / 0.04884));
  389. return HWSendWaittimeCMD(temp,strlen(temp));
  390. }
  391. RET_STATUS nsGEN::AlmaxDevice::IncMS()
  392. {
  393. if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
  394. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  395. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  396. {
  397. FINFO("Techmode is 2Point, Cannot inc MS \n");
  398. return RET_STATUS::RET_FAILED;
  399. }
  400. float oldMS = m_DoseUnit.m_MS->Get();
  401. oldMS++;
  402. char temp[50] = { 0 };
  403. sprintf_s(temp, "72,%d,", (int)(oldMS));
  404. return HWSendWaittimeCMD(temp,strlen(temp));
  405. }
  406. RET_STATUS nsGEN::AlmaxDevice::DecMS()
  407. {
  408. if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
  409. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  410. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  411. {
  412. FINFO("Techmode is 2Point, Cannot dec MS \n");
  413. return RET_STATUS::RET_FAILED;
  414. }
  415. float oldMS = m_DoseUnit.m_MS->Get();
  416. oldMS--;
  417. char temp[50] = { 0 };
  418. sprintf_s(temp, "72,%d,", (int)(oldMS));
  419. return HWSendWaittimeCMD(temp,strlen(temp));
  420. }
  421. RET_STATUS nsGEN::AlmaxDevice::SetMS(float value)
  422. {
  423. if (!m_DoseUnit.m_MS->Verify(value)) return RET_STATUS::RET_SUCCEED;
  424. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  425. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  426. {
  427. FINFO("Techmode is 2Point, Cannot set MS \n");
  428. return RET_STATUS::RET_FAILED;
  429. }
  430. char temp[50] = { 0 };
  431. sprintf_s(temp, "72,%d,", (int)(value));
  432. return HWSendWaittimeCMD(temp,strlen(temp));
  433. }
  434. RET_STATUS nsGEN::AlmaxDevice::IncMAS()
  435. {
  436. if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
  437. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  438. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  439. {
  440. FINFO("Techmode is 3Point, Cannot inc MAS \n");
  441. return RET_STATUS::RET_FAILED;
  442. }
  443. float oldMAS = m_DoseUnit.m_MAS->Get();
  444. if (m_DoseUnit.m_MAS->CanToNext(oldMAS, g_MAS_List))
  445. {
  446. FDEBUG("IncMAS:inc MAS[{$}]->[{$}]", m_DoseUnit.m_MAS->Get(), oldMAS);
  447. char temp[50] = { 0 };
  448. sprintf_s(temp, "74,%d,", (int)round(oldMAS / 0.1));
  449. return HWSendWaittimeCMD(temp, strlen(temp));
  450. }
  451. else
  452. {
  453. FERROR("IncMAS:Cannot inc MAS[{$}]", m_DoseUnit.m_MAS->Get());
  454. return RET_STATUS::RET_FAILED;
  455. }
  456. return RET_STATUS::RET_FAILED;
  457. }
  458. RET_STATUS nsGEN::AlmaxDevice::DecMAS()
  459. {
  460. if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
  461. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  462. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  463. {
  464. FINFO("Techmode is 3Point, Cannot dec MAS \n");
  465. return RET_STATUS::RET_FAILED;
  466. }
  467. float oldMAS = m_DoseUnit.m_MAS->Get();
  468. if (m_DoseUnit.m_MAS->CanToPrev(oldMAS, g_MAS_List))
  469. {
  470. FDEBUG("DecMAS:dec MAS[{$}]->[{$}]", m_DoseUnit.m_MAS->Get(), oldMAS);
  471. char temp[50] = { 0 };
  472. sprintf_s(temp, "74,%d,", (int)round(oldMAS / 0.1));
  473. return HWSendWaittimeCMD(temp, strlen(temp));
  474. }
  475. else
  476. {
  477. FERROR("DecMAS:Cannot dec MAS[{$}]", m_DoseUnit.m_MAS->Get());
  478. return RET_STATUS::RET_FAILED;
  479. }
  480. return RET_STATUS::RET_FAILED;
  481. }
  482. RET_STATUS nsGEN::AlmaxDevice::SetMAS(float value)
  483. {
  484. if (!m_DoseUnit.m_MAS->Verify(value)) return RET_STATUS::RET_SUCCEED;
  485. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  486. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  487. {
  488. FINFO("Techmode is 3Point, Cannot set MAS \n");
  489. return RET_STATUS::RET_FAILED;
  490. }
  491. float tempValue = value;
  492. if (m_DoseUnit.m_MAS->CanToUpdate(tempValue, g_MAS_List))
  493. {
  494. FDEBUG("UpdateMAS:update MAS[{$}]->[{$}]->[{$}]", m_DoseUnit.m_MAS->Get(), value, tempValue);
  495. char temp[50] = { 0 };
  496. sprintf_s(temp, "74,%d,", (int)round(tempValue / 0.1));
  497. return HWSendWaittimeCMD(temp, strlen(temp));
  498. }
  499. else
  500. {
  501. FERROR("UpdateMAS:Cannot set MAS[{$}]->[{$}]", value, tempValue);
  502. return RET_STATUS::RET_FAILED;
  503. }
  504. return RET_STATUS::RET_FAILED;
  505. }
  506. RET_STATUS nsGEN::AlmaxDevice::SetTechmode(int value)
  507. {
  508. if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
  509. FINFO("SetTechmode:[{$}] \n", value);
  510. switch (value)
  511. {
  512. case AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P:
  513. {
  514. HWSendWaitACKCMD("55,0,", 5, 3);
  515. HWSendWaitACKCMD("57,0,", 5, 3);
  516. }
  517. break;
  518. case AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P:
  519. {
  520. HWSendWaitACKCMD("55,1,", 5, 3);
  521. HWSendWaitACKCMD("57,0,", 5, 3);
  522. }
  523. break;
  524. case AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P:
  525. {
  526. HWSendWaitACKCMD("55,0,", 5, 3);
  527. HWSendWaitACKCMD("57,1,", 5, 3);
  528. }
  529. break;
  530. case AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P:
  531. {
  532. HWSendWaitACKCMD("55,1,", 5, 3);
  533. HWSendWaitACKCMD("57,1,", 5, 3);
  534. }
  535. break;
  536. default:
  537. break;
  538. }
  539. return RET_STATUS::RET_SUCCEED;
  540. }
  541. RET_STATUS nsGEN::AlmaxDevice::SetEXAMMode(std::string value) //DMOC实际是通过此接口设置是否启用AEC
  542. {
  543. //上层给我设置exam mode(manual semiauto automatic)对应(NoAEC2Point AEC2Point AEC2Point)
  544. FINFO("Enter setexammode func value = {$}\n", value);
  545. if (value == EXAMMODE_TYPE::MANUAL)
  546. {
  547. //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P)
  548. {
  549. SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P);
  550. }
  551. }
  552. else if (value == EXAMMODE_TYPE::SEMIAUTO)
  553. {
  554. //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  555. {
  556. SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  557. }
  558. }
  559. else if (value == EXAMMODE_TYPE::AUTOMATIC)
  560. {
  561. //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  562. {
  563. SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  564. }
  565. }
  566. return RET_STATUS::RET_SUCCEED;
  567. }
  568. RET_STATUS nsGEN::AlmaxDevice::SetAPR(const _tAPRArgs& t)
  569. {
  570. 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);
  571. if (!m_DoseUnit.m_KV->Verify(t.fKV))
  572. {
  573. FERROR("SetAPR:KV Out of bounds[{$}] \n", t.fKV);
  574. }
  575. else if (!m_DoseUnit.m_MA->Verify(t.fMA) && (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  576. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P))
  577. {
  578. FERROR("SetAPR:MA Out of bounds[{$}] \n", t.fMA);
  579. }
  580. else if (!m_DoseUnit.m_MS->Verify(t.fMS) && (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  581. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P))
  582. {
  583. FERROR("SetAPR:MS Out of bounds[{$}] \n", t.fMS);
  584. }
  585. else if (!m_DoseUnit.m_MAS->Verify(t.fMAS) && (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  586. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P))
  587. {
  588. FERROR("SetAPR:MAS Out of bounds[{$}] \n", t.fMAS);
  589. //add by wxx for test
  590. float oldKV = m_DoseUnit.m_KV->Get();
  591. float oldMAS = m_DoseUnit.m_MAS->Get();
  592. float oldMA = m_DoseUnit.m_MA->Get();
  593. float oldMS = m_DoseUnit.m_MS->Get();
  594. int oldFocus = m_DoseUnit.m_Focus->Get();
  595. FERROR("SetAPR:old KV[{$}],MAS[{$}],MA[{$}],Focus[{$}]", oldKV, oldMAS, oldMA, oldFocus);
  596. char temp[50] = { 0 };
  597. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  598. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  599. {
  600. char temp[50] = { 0 };
  601. sprintf_s(temp, "50,%d,%d,%d,%d,", (int)(oldMS), (int)round(oldKV * 1000 / 12.21), (int)round(oldMA / 0.04884), (int)(oldFocus));
  602. return HWSendWaittimeCMD(temp, strlen(temp));
  603. }
  604. else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  605. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  606. {
  607. char temp[50] = { 0 };
  608. sprintf_s(temp, "10,%d,", (int)round(oldKV * 1000 / 12.21));
  609. HWSendWaittimeCMD(temp, strlen(temp));
  610. float tempValue = oldMAS;
  611. if (m_DoseUnit.m_MAS->CanToUpdate(tempValue, g_MAS_List))
  612. {
  613. FDEBUG("SetAPR:update MAS[{$}]->[{$}]->[{$}]", m_DoseUnit.m_MAS->Get(), oldFocus, tempValue);
  614. char temp[50] = { 0 };
  615. sprintf_s(temp, "74,%d,", (int)round(tempValue / 0.1));
  616. HWSendWaittimeCMD(temp, strlen(temp));
  617. }
  618. }
  619. }
  620. else if (!m_DoseUnit.m_Focus->Verify(t.nFocus))
  621. {
  622. FERROR("SetAPR:Focus Out of bounds[{$}] \n", t.nFocus);
  623. }
  624. else
  625. {
  626. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  627. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  628. {
  629. char temp[50] = { 0 };
  630. sprintf_s(temp, "50,%d,%d,%d,%d,", (int)(t.fMS), (int)round(t.fKV * 1000 / 12.21), (int)round(t.fMA / 0.04884), (int)(t.nFocus));
  631. return HWSendWaittimeCMD(temp, strlen(temp));
  632. }
  633. else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  634. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  635. {
  636. char temp[50] = { 0 };
  637. sprintf_s(temp, "10,%d,", (int)round(t.fKV * 1000 / 12.21));
  638. HWSendWaittimeCMD(temp, strlen(temp));
  639. float tempValue = t.fMAS;
  640. if (m_DoseUnit.m_MAS->CanToUpdate(tempValue, g_MAS_List))
  641. {
  642. FDEBUG("SetAPR:update MAS[{$}]->[{$}]->[{$}]", m_DoseUnit.m_MAS->Get(), t.fMAS, tempValue);
  643. char temp[50] = { 0 };
  644. sprintf_s(temp, "74,%d,", (int)round(tempValue / 0.1));
  645. HWSendWaittimeCMD(temp, strlen(temp));
  646. }
  647. }
  648. }
  649. return RET_STATUS::RET_SUCCEED;
  650. }
  651. RET_STATUS nsGEN::AlmaxDevice::RefreshData()
  652. {
  653. FDEBUG("RefreshData:processing begin \n");
  654. //HWSendWaittimeCMD("51,",3);
  655. //HWSendWaittimeCMD("54,",3);
  656. HWSendWaittimeCMD("22,", 3);
  657. return RET_STATUS::RET_SUCCEED;
  658. }
  659. RET_STATUS nsGEN::AlmaxDevice::SetFocus(int value)
  660. {
  661. if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
  662. char temp[50] = { 0 };
  663. sprintf_s(temp, "73,%01d,", (int)value);
  664. return HWSendWaittimeCMD(temp,strlen(temp));
  665. }
  666. RET_STATUS nsGEN::AlmaxDevice::Reset()
  667. {
  668. FDEBUG("clear all errors \n");
  669. int level = 0;
  670. m_MSGUnit->DelErrorMessage("0", level, "clear all errors");
  671. HWSendWaittimeCMD("31,",3);//仅重置错误状态
  672. return RET_STATUS::RET_SUCCEED;
  673. }
  674. RET_STATUS nsGEN::AlmaxDevice::QueryHE(int& value) //实际为主动上报
  675. {
  676. //value = m_DoseUnit.m_HE->Get();
  677. HWSendWaittimeCMD("77,",3);
  678. return RET_STATUS::RET_SUCCEED;
  679. }
  680. //Almax发生器不支持的通用操作
  681. RET_STATUS nsGEN::AlmaxDevice::SetAECDensity(int value) //发生器无此设置
  682. {
  683. if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED;
  684. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  685. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P)
  686. {
  687. FINFO("Techmode is not AEC, Cannot set Density \n");
  688. return RET_STATUS::RET_FAILED;
  689. }
  690. m_DoseUnit.m_AECDensity->Update(value);
  691. return RET_STATUS::RET_SUCCEED;
  692. }
  693. RET_STATUS nsGEN::AlmaxDevice::SetAECField(int value) //发生器无此设置
  694. {
  695. if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
  696. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  697. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P)
  698. {
  699. FINFO("Techmode is not AEC, Cannot set Field \n");
  700. return RET_STATUS::RET_FAILED;
  701. }
  702. m_DoseUnit.m_AECField->Update(value);
  703. return RET_STATUS::RET_SUCCEED;
  704. }
  705. RET_STATUS nsGEN::AlmaxDevice::SetAECFilm(int value) //发生器无此设置
  706. {
  707. if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
  708. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  709. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P)
  710. {
  711. FINFO("Techmode is not AEC, Cannot set Film \n");
  712. return RET_STATUS::RET_FAILED;
  713. }
  714. m_DoseUnit.m_AECFilm->Update(value);
  715. return RET_STATUS::RET_SUCCEED;
  716. }
  717. RET_STATUS nsGEN::AlmaxDevice::SetWS(const string value) //发生器无此设置
  718. {
  719. FINFO("Enter SetWS {$}", value);
  720. int tempws = 0;
  721. if (value == "Table") tempws = (int)m_GenConfig["WSTable"];
  722. else if (value == "Wall") tempws = (int)m_GenConfig["WSWall"];
  723. else if (value == "Direct") tempws = (int)m_GenConfig["WSConventional"];
  724. else if (value == "Free") tempws = (int)m_GenConfig["WSFree"];
  725. else if (value == "Tomo") tempws = (int)m_GenConfig["WSTomo"];
  726. m_DoseUnit.m_WS->Update(tempws);
  727. return RET_STATUS::RET_SUCCEED;
  728. }
  729. int nsGEN::AlmaxDevice::GetGeneratorBatteryChargState() //实际为主动上报
  730. {
  731. return m_DoseUnit.m_BatteryChargeState->Get();
  732. }
  733. RET_STATUS nsGEN::AlmaxDevice::QueryPostKV(float& value) //实际为主动上报
  734. {
  735. if (m_DoseUnit.m_PostKV->Get() > 0)
  736. {
  737. value = m_DoseUnit.m_PostKV->Get();
  738. }
  739. return RET_STATUS::RET_SUCCEED;
  740. }
  741. RET_STATUS nsGEN::AlmaxDevice::QueryPostMA(float& value) //实际为主动上报
  742. {
  743. if (m_DoseUnit.m_PostMA->Get() > 0)
  744. {
  745. value = m_DoseUnit.m_PostMA->Get();
  746. }
  747. return RET_STATUS::RET_SUCCEED;
  748. }
  749. RET_STATUS nsGEN::AlmaxDevice::QueryPostMS(float& value) //实际为主动上报
  750. {
  751. if (m_DoseUnit.m_PostMS->Get() > 0)
  752. {
  753. value = m_DoseUnit.m_PostMS->Get();
  754. }
  755. return RET_STATUS::RET_SUCCEED;
  756. }
  757. RET_STATUS nsGEN::AlmaxDevice::QueryPostMAS(float& value) //实际为主动上报
  758. {
  759. if (m_DoseUnit.m_PostMAS->Get() > 0)
  760. {
  761. value = m_DoseUnit.m_PostMAS->Get();
  762. }
  763. return RET_STATUS::RET_SUCCEED;
  764. }
  765. RET_STATUS nsGEN::AlmaxDevice::Clear_DAP() //发生器无此设置
  766. {
  767. return RET_STATUS::RET_SUCCEED;
  768. }
  769. RET_STATUS nsGEN::AlmaxDevice::GetValue_DAP(float& value) //发生器无此设置
  770. {
  771. //value = m_DAP->Get();
  772. return RET_STATUS::RET_SUCCEED;
  773. }
  774. RET_STATUS nsGEN::AlmaxDevice::StartMove() //发生器无此设置
  775. {
  776. return RET_STATUS::RET_SUCCEED;
  777. }
  778. RET_STATUS nsGEN::AlmaxDevice::EndMove() //发生器无此设置
  779. {
  780. return RET_STATUS::RET_SUCCEED;
  781. }
  782. RET_STATUS nsGEN::AlmaxDevice::SetGenSynState(int value) //发生器无此设置:AEC二阶段曝光使用
  783. {
  784. FDEBUG("Enter SetGenSynState[{$}]->[{$}]", m_DoseUnit.m_GenSynState->Get(), value);
  785. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P ||
  786. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P ||
  787. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_MAS_MA)
  788. {
  789. if (value == nsGEN::AttrKey::GENERATOR_RAD_XRAYON)
  790. {
  791. FDEBUG("SetGenSynState:get Gen Status_5:RAD_READY(PR2) -> X-Ray On(XR1)");
  792. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYON))
  793. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  794. }
  795. else if (value == nsGEN::AttrKey::GENERATOR_RAD_OFF)
  796. {
  797. float CurrtLastKV = m_DoseUnit.m_PostKV->Get();
  798. FDEBUG("SetGenSynState:get CurrtLastKV [{$}]", CurrtLastKV);
  799. FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
  800. float CurrtLastMA = m_DoseUnit.m_PostMA->Get();
  801. float CurrtLastMS = m_DoseUnit.m_PostMS->Get();
  802. float CurrtLastMAS = CurrtLastMS * CurrtLastMA / 1000;
  803. FDEBUG("SetGenSynState:CurrtLastMS[{$}] and CurrtLastMA[{$}] compute CurrtLastMAS[{$}]", CurrtLastMS, CurrtLastMA, CurrtLastMAS);
  804. m_DoseUnit.m_PostMAS->Update(CurrtLastMAS);
  805. FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet());
  806. FDEBUG("SetGenSynState:get Gen Status_5:X-Ray On(XR1) -> RAD_OFF(PR0)");
  807. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_OFF))
  808. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  809. }
  810. }
  811. return RET_STATUS::RET_SUCCEED;
  812. }
  813. RET_STATUS nsGEN::AlmaxDevice::SetGenState(int value) //发生器无此设置
  814. {
  815. return RET_STATUS::RET_SUCCEED;
  816. }
  817. RET_STATUS nsGEN::AlmaxDevice::SetExpMode(std::string value) //发生器无此设置
  818. {
  819. FINFO("Enter SetExpMode...{$} \n",value);
  820. m_DoseUnit.m_ExpMode->Update(value);
  821. //add for dcm img hard
  822. FINFO("SetExpMode:add for dcm img hard");
  823. FireNotify(m_DoseUnit.m_TubeTargetMaterial->GetKey(), m_DoseUnit.m_TubeTargetMaterial->JSGet());
  824. FireNotify(m_DoseUnit.m_TubeAngle->GetKey(), m_DoseUnit.m_TubeAngle->JSGet());
  825. return RET_STATUS::RET_SUCCEED;
  826. }
  827. RET_STATUS nsGEN::AlmaxDevice::SetFLFMode(std::string value) //发生器无此动态设置
  828. {
  829. return RET_STATUS::RET_SUCCEED;
  830. }
  831. RET_STATUS nsGEN::AlmaxDevice::SetFrameRate(FLOAT frameRate) //发生器无此动态设置
  832. {
  833. m_DoseUnit.m_FrameRate->Update(frameRate);
  834. return RET_STATUS::RET_SUCCEED;
  835. }
  836. RET_STATUS nsGEN::AlmaxDevice::SetRPS(int rps) //发生器无此动态设置
  837. {
  838. return RET_STATUS::RET_SUCCEED;
  839. }
  840. RET_STATUS nsGEN::AlmaxDevice::SetExpEnable() //发生器无此设置
  841. {
  842. //HWSendWaittimeCMD("31,",3); //清空错误
  843. return RET_STATUS::RET_SUCCEED;
  844. }
  845. RET_STATUS nsGEN::AlmaxDevice::SetExpDisable() //发生器无此设置
  846. {
  847. return RET_STATUS::RET_SUCCEED;
  848. }
  849. //Almax发生器特有功能
  850. //-----------------------------------------------------------------------------
  851. // ProcessCmd
  852. //-----------------------------------------------------------------------------
  853. void nsGEN::AlmaxDevice::ProcessClientData(const char* pData, unsigned long nDataLength, void* lparam)
  854. {
  855. AlmaxDevice* pCurGen = (AlmaxDevice*)lparam;
  856. pCurGen->HWSend(pData, nDataLength);
  857. }
  858. void nsGEN::AlmaxDevice::WriteLog(const char* pData, nsSerialGPM::LOG_V2_LEVEL level)
  859. {
  860. switch (level)
  861. {
  862. case nsSerialGPM::LOG_V2_FATAL:
  863. case nsSerialGPM::LOG_V2_ERROR:
  864. FERROR(pData);
  865. break;
  866. case nsSerialGPM::LOG_V2_WARNING:
  867. FWARN(pData);
  868. break;
  869. case nsSerialGPM::LOG_V2_DEBUG:
  870. FDEBUG(pData);
  871. break;
  872. case nsSerialGPM::LOG_V2_INFO:
  873. FINFO(pData);
  874. break;
  875. default:
  876. break;
  877. }
  878. }
  879. RET_STATUS nsGEN::AlmaxDevice::HWSendWaittimeCMD(char* strCommand, int lengh, int headLengh)
  880. {
  881. return m_tDelivermodule.ProcessCommand(strCommand, lengh, m_nCMDType_WaitTime, headLengh);
  882. }
  883. RET_STATUS nsGEN::AlmaxDevice::HWSendHBCMD(char* strCommand, int lengh, int headLengh)
  884. {
  885. return m_tDelivermodule.ProcessCommand(strCommand, lengh, m_nCMDType_HB, headLengh);
  886. }
  887. RET_STATUS nsGEN::AlmaxDevice::HWSendWaitACKCMD(char* strCommand, int lengh, int headLengh)
  888. {
  889. return m_tDelivermodule.ProcessCommand(strCommand, lengh, m_nCMDType_WaitACK, headLengh);
  890. }
  891. RET_STATUS nsGEN::AlmaxDevice::HWSend(const char* strCommand,int lengh, bool reSend, int nTimeOut)
  892. {
  893. if (!m_bConnectFlag)
  894. {
  895. FERROR("==OUT==: not Connect,[{$:x2}] send failed \n", strCommand[0]);
  896. return RET_STATUS::RET_FAILED;
  897. }
  898. if (!m_SCF) return RET_STATUS::RET_FAILED;
  899. char checkSum = ComputeCheckSum(strCommand, lengh);
  900. if (checkSum == 0x00)
  901. {
  902. FERROR("HWSend: cmd[{$:x2}] Check Sum failed \n", strCommand[0]);
  903. return RET_STATUS::RET_FAILED;
  904. }
  905. string cmdText{ "" };
  906. string tempTransmit;
  907. cmdText += Almax_STX;
  908. for (int i = 0; i < lengh; i++)
  909. {
  910. tempTransmit = std::format("{:02X}", strCommand[i]);
  911. cmdText += tempTransmit;
  912. }
  913. tempTransmit = std::format("{:02X}", checkSum);
  914. cmdText += tempTransmit;
  915. cmdText += Almax_ETX;
  916. if (cmdText.compare(0,2,Almax_CMD_GetStatus,0,2) != 0)
  917. {
  918. if (reSend)
  919. {
  920. FINFO("==OUT==: [{$}:{$}] reSend \n", cmdText.c_str(), cmdText.length());
  921. }
  922. else
  923. {
  924. FINFO("==OUT==: [{$}:{$}] \n", cmdText.c_str(), cmdText.length());
  925. }
  926. }
  927. int retLength;
  928. m_SCF.Lock(msTimeOut_Lock)
  929. .SendPacket(cmdText.c_str(), cmdText.length(), nTimeOut, retLength);
  930. //Sleep(nTimeOut);
  931. return RET_STATUS::RET_SUCCEED;
  932. }
  933. void nsGEN::AlmaxDevice::FireNotify(string key, int context)
  934. {
  935. char szInfo[64] = { 0 };
  936. sprintf_s(szInfo, "%d", context);
  937. std::string str = szInfo;
  938. EventCenter->OnNotify(1, key, str);
  939. }
  940. void nsGEN::AlmaxDevice::FireNotify(std::string key, float context)
  941. {
  942. char szInfo[16] = { 0 };
  943. sprintf_s(szInfo,15, "%.2f", context);
  944. std::string str = szInfo;
  945. FINFO("FireNotify(float):[{$}][{$}]", szInfo, str.c_str());
  946. EventCenter->OnNotify(1, key, str);
  947. }
  948. void nsGEN::AlmaxDevice::FireNotify(std::string key, std::string context)
  949. {
  950. EventCenter->OnNotify(1, key, context);
  951. }
  952. void nsGEN::AlmaxDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
  953. {
  954. string ErrorCode("Almax_ERR_");
  955. ErrorCode += std::to_string(Code);
  956. int level = ContainerExample_REGULATION_LEVEL::REG_ERRO;
  957. if (Act)
  958. {
  959. FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
  960. m_MSGUnit->AddErrorMessage(ErrorCode.c_str(), level, ResInfo);
  961. }
  962. else
  963. {
  964. FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
  965. m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo);
  966. }
  967. }
  968. void nsGEN::AlmaxDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
  969. {
  970. string ErrorCode("Almax_WAR_");
  971. ErrorCode += std::to_string(Code);
  972. int level = ContainerExample_REGULATION_LEVEL::REG_WARN;
  973. if (Act)
  974. {
  975. FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
  976. m_MSGUnit->AddWarnMessage(ErrorCode.c_str(), level, ResInfo);
  977. }
  978. else
  979. {
  980. FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
  981. m_MSGUnit->DelWarnMessage(ErrorCode.c_str(), level, ResInfo);
  982. }
  983. }
  984. void nsGEN::AlmaxDevice::OnCallBack()
  985. {
  986. //无 操作
  987. auto HWNotProcess = [](const char* value, int length) -> void
  988. {
  989. //printf("This commands didn't need to process!");
  990. FINFO("This commands[{$}] didn't need to process", value);
  991. };
  992. //校验和错误
  993. auto HWERROR_1 = [this](char* value, int length) -> void
  994. {
  995. char* nextTokenPtr = NULL;
  996. char* tokenPtr = strtok_s(value, ",", &nextTokenPtr);
  997. if(tokenPtr != NULL)
  998. {
  999. FERROR("== HWERROR_1 == : error CheckSum:[{$}]", tokenPtr);
  1000. }
  1001. else
  1002. {
  1003. FERROR("== HWERROR_1 == : error CheckSum:no csum");
  1004. }
  1005. };
  1006. //命令模式:用于正常操作
  1007. //主机请求固件传输模拟监视器读回当前值
  1008. //主机请求固件发送电源状态
  1009. auto HW22 = [this](char* value, int length) -> void
  1010. {
  1011. m_iHeartBeats = 0;
  1012. int FaultFlag = false;
  1013. int AECReady = false;
  1014. char* nextTokenPtr = NULL;
  1015. char* tokenPtr = strtok_s(value, ",", &nextTokenPtr);
  1016. if (tokenPtr != NULL) //ARG1:XR1 / XR0状态
  1017. {
  1018. int iARG = atoi(tokenPtr);
  1019. #if Almax_22CMDCtrlGenSynState_Flag
  1020. if (iARG)
  1021. {
  1022. if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYON)
  1023. {
  1024. FDEBUG("Request Status_1:already X-Ray On(XR1)");
  1025. }
  1026. else if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_READY)
  1027. {
  1028. FDEBUG("Request Status_1:RAD_READY(PR2) -> X-Ray On(XR1)");
  1029. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYON))
  1030. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1031. }
  1032. else
  1033. {
  1034. FWARN("Request Status_1:Wrong state change:{$} -try to> X-Ray On(XR1)", m_DoseUnit.m_GenSynState->Get());
  1035. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYON))
  1036. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1037. }
  1038. }
  1039. else
  1040. {
  1041. if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYON)
  1042. {
  1043. FDEBUG("Request Status_1:get post KV MA MS MAS");
  1044. //HWSendWaittimeCMD("54,3");
  1045. m_iCompPostMAS = 10;
  1046. HWSendWaittimeCMD("60,",3);
  1047. HWSendWaittimeCMD("61,",3);
  1048. HWSendWaittimeCMD("65,",3);
  1049. FDEBUG("Request Status_1:X-Ray On(XR1) -> Off(XR0)");
  1050. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF))
  1051. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1052. }
  1053. else if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF)
  1054. {
  1055. FDEBUG("Request Status_1:X-Ray Off(XR0) -> Off(PR2)");
  1056. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
  1057. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1058. }
  1059. else
  1060. FDEBUG("Request Status_1:already X-Ray Off(XR0)");
  1061. }
  1062. #else
  1063. FDEBUG("Request Status_1:Unit High Voltage output Status[{$}]", iARG);
  1064. #endif // Almax_22CMDCtrlGenSynState_Flag
  1065. }
  1066. else return;
  1067. tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
  1068. if (tokenPtr != NULL) //ARG2:安全开关状态
  1069. {
  1070. int iARG = atoi(tokenPtr);
  1071. if (iARG == 0)
  1072. {
  1073. FDEBUG("Request Status_2:Safety interlock is Open; not ok to make high voltage");
  1074. FaultFlag = true;
  1075. }
  1076. else
  1077. {
  1078. FDEBUG("Request Status_2:Safety interlock is closed; ok to make high voltage");
  1079. }
  1080. }
  1081. else return;
  1082. tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
  1083. if (tokenPtr != NULL) //ARG3:故障状况
  1084. {
  1085. int iARG = atoi(tokenPtr);
  1086. if (iARG == 1)
  1087. {
  1088. FDEBUG("Request Status_3:There are 1 or more active faults,not make high voltage");
  1089. FaultFlag = true;
  1090. }
  1091. else
  1092. {
  1093. FDEBUG("Request Status_3:no active faults");
  1094. }
  1095. }
  1096. else return;
  1097. tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
  1098. if (tokenPtr != NULL) //ARG4:PR1 / PR0状态
  1099. {
  1100. int iARG = atoi(tokenPtr);
  1101. #if Almax_22CMDCtrlGenSynState_Flag
  1102. if (iARG == 1)
  1103. {
  1104. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P ||
  1105. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  1106. {
  1107. FDEBUG("Request Status_4:AEC mod ignore ARG13");
  1108. AECReady = true;
  1109. }
  1110. //加快查询时间
  1111. if (m_iLoopTime != Almax_LoopExpHBTime)
  1112. {
  1113. FDEBUG("quicken loopTime[{$}]->[{$}]", m_iLoopTime.load(), Almax_LoopExpHBTime);
  1114. m_iLoopTime = Almax_LoopExpHBTime;
  1115. }
  1116. if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_PREPARE ||
  1117. m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_READY ||
  1118. m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYON ||
  1119. m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF)
  1120. {
  1121. FDEBUG("Request Status_4:GEN is already in Prep state(PR1)");
  1122. }
  1123. else if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_OFF)
  1124. {
  1125. FDEBUG("Request Status_4:RAD_OFF(PR0) -> RAD_PREPARE(PR1)");
  1126. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE))
  1127. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1128. }
  1129. else
  1130. {
  1131. FWARN("Request Status_4:Wrong state change:{$} -> RAD_PREPARE(PR1)", m_DoseUnit.m_GenSynState->Get());
  1132. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE))
  1133. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1134. }
  1135. if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_EXP &&
  1136. m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_ERROR)
  1137. {
  1138. //更新发生器状态并上报,否则会影响工作流 FrameEnable -> FrameReady 的转变
  1139. FDEBUG("Request Status_4:GENSTATE {$} -> STATUS_EXP", m_DoseUnit.m_GenState->JSGet());
  1140. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP);
  1141. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1142. }
  1143. }
  1144. else
  1145. {
  1146. AECReady = false;
  1147. //回复查询时间
  1148. if (m_iLoopTime == Almax_LoopExpHBTime)
  1149. {
  1150. if ((int)m_GenConfig["loopTime"] >= 100)
  1151. {
  1152. m_iLoopTime = (int)m_GenConfig["loopTime"];
  1153. }
  1154. else
  1155. m_iLoopTime = Almax_LoopDefHBTime;
  1156. FDEBUG("reduction loopTime[{$}]->[{$}]", Almax_LoopExpHBTime,m_iLoopTime.load());
  1157. }
  1158. FDEBUG("Request Status_4:GEN is not in Prep state(PR0)");
  1159. if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_PREPARE)
  1160. {
  1161. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_OFF))
  1162. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1163. }
  1164. if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_STANDBY &&
  1165. m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_ERROR)
  1166. {
  1167. if (m_bExpEnable)
  1168. {
  1169. FDEBUG("Request Status_4:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
  1170. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1171. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1172. }
  1173. else if(m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_SLEEP)
  1174. {
  1175. FDEBUG("Request Status_4:GENSTATE {$} -> STATUS_SLEEP", m_DoseUnit.m_GenState->JSGet());
  1176. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SLEEP);
  1177. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1178. }
  1179. }
  1180. }
  1181. #else
  1182. FDEBUG("Request Status_4:Unit Prep state[{$}]", iARG);
  1183. if (iARG == 1)
  1184. {
  1185. //加快查询时间
  1186. if (m_iLoopTime != Almax_LoopExpHBTime)
  1187. {
  1188. FDEBUG("quicken loopTime[{$}]->[{$}]", m_iLoopTime.load(), Almax_LoopExpHBTime);
  1189. m_iLoopTime = Almax_LoopExpHBTime;
  1190. }
  1191. if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_EXP &&
  1192. m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_ERROR)
  1193. {
  1194. //更新发生器状态并上报,否则会影响工作流 FrameEnable -> FrameReady 的转变
  1195. FDEBUG("Request Status_4:GENSTATE {$} -> STATUS_EXP", m_DoseUnit.m_GenState->JSGet());
  1196. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP);
  1197. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1198. }
  1199. }
  1200. else
  1201. {
  1202. //回复查询时间
  1203. if (m_iLoopTime == Almax_LoopExpHBTime)
  1204. {
  1205. if ((int)m_GenConfig["loopTime"] >= 100)
  1206. {
  1207. m_iLoopTime = (int)m_GenConfig["loopTime"];
  1208. }
  1209. else
  1210. m_iLoopTime = Almax_LoopDefHBTime;
  1211. FDEBUG("reduction loopTime[{$}]->[{$}]", Almax_LoopExpHBTime, m_iLoopTime.load());
  1212. }
  1213. FDEBUG("Request Status_4:GEN turn to Prep state(PR0)");
  1214. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_OFF))
  1215. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1216. if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_STANDBY &&
  1217. m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_ERROR)
  1218. {
  1219. if (m_bExpEnable)
  1220. {
  1221. FDEBUG("Request Status_4:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
  1222. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1223. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1224. }
  1225. else if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_SLEEP)
  1226. {
  1227. FDEBUG("Request Status_4:GENSTATE {$} -> STATUS_SLEEP", m_DoseUnit.m_GenState->JSGet());
  1228. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SLEEP);
  1229. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1230. }
  1231. }
  1232. }
  1233. #endif // Almax_22CMDCtrlGenSynState_Flag
  1234. }
  1235. else return;
  1236. tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
  1237. if (tokenPtr != NULL) //ARG5:Xray Condition
  1238. {
  1239. int iflag = atoi(tokenPtr);
  1240. if(iflag)
  1241. FDEBUG("Request Status_5:Unit is in Xray state (Ready to make X-Ray shot)");
  1242. else
  1243. FDEBUG("Request Status_5:Unit is not in Xray state");
  1244. }
  1245. else return;
  1246. tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG6
  1247. if (tokenPtr == NULL) return;
  1248. tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG7
  1249. if (tokenPtr == NULL) return;
  1250. tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG8
  1251. if (tokenPtr == NULL) return;
  1252. tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG9
  1253. if (tokenPtr == NULL) return;
  1254. tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG10
  1255. if (tokenPtr == NULL) return;
  1256. tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG11
  1257. if (tokenPtr == NULL) return;
  1258. tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG12
  1259. if (tokenPtr == NULL) return;
  1260. tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
  1261. if (tokenPtr != NULL) //ARG13:准备状态(PR2)
  1262. {
  1263. int iARG = atoi(tokenPtr);
  1264. #if Almax_22CMDCtrlGenSynState_Flag
  1265. if (iARG == 1)
  1266. {
  1267. if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_READY ||
  1268. m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYON ||
  1269. m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF)
  1270. {
  1271. FDEBUG("Request Status_13:GEN is already to make X-Rays(PR2)");
  1272. }
  1273. else if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_PREPARE)
  1274. {
  1275. FDEBUG("Request Status_13:PREPARE or XRAYOFF(PR1 or XR0) -> RAD_READY(PR2)");
  1276. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
  1277. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1278. }
  1279. else
  1280. {
  1281. FWARN("Request Status_13:Wrong state change:{$} -> RAD_READY(PR2)", m_DoseUnit.m_GenSynState->Get());
  1282. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
  1283. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1284. }
  1285. }
  1286. else
  1287. {
  1288. if (AECReady)
  1289. {
  1290. FDEBUG("Request Status_13:GEN is in AEC_ready(temp PR0)");
  1291. }
  1292. else
  1293. {
  1294. FDEBUG("Request Status_13:GEN is not finish ready(PR0)");
  1295. }
  1296. if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_READY && !AECReady)
  1297. {
  1298. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE))
  1299. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1300. }
  1301. }
  1302. #else
  1303. FDEBUG("Request Status_13:Unit Ready Status[{$}]", iARG);
  1304. #endif // Almax_22CMDCtrlGenSynState_Flag
  1305. }
  1306. else return;
  1307. tokenPtr = strtok_s(NULL, ",",&nextTokenPtr); //ARG14
  1308. if (tokenPtr == NULL) return;
  1309. tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
  1310. if (tokenPtr != NULL) //ARG15:校准模式
  1311. {
  1312. int iARG = atoi(tokenPtr);
  1313. if (iARG == 1) //该装置处于校准模式
  1314. {
  1315. FDEBUG("Request Status_15:GEN is in calibration mode");
  1316. }
  1317. else
  1318. {
  1319. FDEBUG("Request Status_15:GEN is not in calibration mode");
  1320. }
  1321. }
  1322. else return;
  1323. tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG16
  1324. if (tokenPtr == NULL) return;
  1325. tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG17
  1326. if (tokenPtr == NULL) return;
  1327. tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG18
  1328. if (tokenPtr == NULL) return;
  1329. tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG19
  1330. if (tokenPtr == NULL) return;
  1331. tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG20
  1332. if (tokenPtr == NULL) return;
  1333. tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG21
  1334. if (tokenPtr == NULL) return;
  1335. tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG22
  1336. if (tokenPtr == NULL) return;
  1337. tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG23
  1338. if (tokenPtr == NULL) return;
  1339. tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
  1340. if (tokenPtr != NULL) //ARG24:负载持续率可限制
  1341. {
  1342. int iARG = atoi(tokenPtr);
  1343. if (iARG == 1) //此位表示设备如果过载保护也允许新的曝光周期开始
  1344. {
  1345. FDEBUG("Request Status_24:Ok to enter Prep");
  1346. if (!m_bExpEnable)
  1347. {
  1348. m_bExpEnable = true;
  1349. if (m_DoseUnit.m_GenState->Get() == nsGEN::AttrKey::GENERATOR_STATUS_SLEEP)
  1350. {
  1351. FireWarnMessage(false, 2, "Almax generator need some time to rest(about 20 Sec)");
  1352. if (FaultFlag)
  1353. {
  1354. FDEBUG("Request Status_24 STATUS_SLEEP -> STATUS_ERROR");
  1355. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
  1356. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1357. }
  1358. else
  1359. {
  1360. FDEBUG("Request Status_24 STATUS_SLEEP -> STATUS_STANDBY");
  1361. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1362. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1363. }
  1364. }
  1365. }
  1366. }
  1367. else
  1368. {
  1369. FDEBUG("Request Status_24:Not ready to enter prep");
  1370. if (m_bExpEnable)
  1371. {
  1372. FireWarnMessage(true, 2, "Almax generator need some time to rest(about 20 Sec)");
  1373. m_bExpEnable = false;
  1374. if (m_DoseUnit.m_GenSynState->Get() < nsGEN::AttrKey::GENERATOR_RAD_PREPARE && !FaultFlag)
  1375. {
  1376. FDEBUG("Request Status_24:GENSTATE {$} -> STATUS_SLEEP", m_DoseUnit.m_GenState->JSGet());
  1377. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SLEEP);
  1378. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1379. }
  1380. }
  1381. }
  1382. }
  1383. else return;
  1384. tokenPtr = strtok_s(NULL, ",",&nextTokenPtr); //ARG25
  1385. if (tokenPtr == NULL) return;
  1386. tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
  1387. if (tokenPtr != NULL) //ARG26:HSS速度
  1388. {
  1389. int iARG = atoi(tokenPtr);
  1390. if (iARG == 1) //X射线管转子转速设定
  1391. {
  1392. FDEBUG("Request Status_26:High Speed");
  1393. }
  1394. else
  1395. {
  1396. FDEBUG("Request Status_26:Low Speed");
  1397. }
  1398. }
  1399. else return;
  1400. };
  1401. arFrame.clear();
  1402. //命令模式:用于正常操作
  1403. arFrame["22"] = tFrameMapItem(HW22);
  1404. arFrame["1"] = tFrameMapItem(HWERROR_1);//命令格式:校验和错误
  1405. }
  1406. bool nsGEN::AlmaxDevice::ReConnect()
  1407. {
  1408. FINFO("Enter PSG_reConnect");
  1409. m_SCF.Disconnect();
  1410. if (!pIODriver)
  1411. {
  1412. FINFO("PSG_reConnect:Driver null");
  1413. }
  1414. else if (pIODriver->ReConnection(m_SCF))
  1415. {
  1416. FireErrorMessage(false, 1, "lost Connect");
  1417. m_bConnectFlag = true;
  1418. FINFO("PSG_reConnect success");
  1419. return true;
  1420. }
  1421. else
  1422. {
  1423. FINFO("PSG_reConnect failed");
  1424. }
  1425. return false;
  1426. }
  1427. bool nsGEN::AlmaxDevice::StartHardwareStatusThread()
  1428. {
  1429. FINFO("enter Start HardwareStatus Thread ");
  1430. if (m_pHardwareStatusThread == NULL)
  1431. {
  1432. DWORD m_HardwareStatusID;
  1433. m_pHardwareStatusThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
  1434. if (m_pHardwareStatusThread == NULL)
  1435. {
  1436. FERROR("Start HardwareStatus Thread Failed");
  1437. return false;
  1438. }
  1439. }
  1440. return true;
  1441. }
  1442. DWORD nsGEN::AlmaxDevice::HardwareStatusThread(LPVOID pParam)
  1443. {
  1444. AlmaxDevice* pCurGen = (AlmaxDevice*)pParam;
  1445. if (pCurGen == NULL)
  1446. {
  1447. return false;
  1448. }
  1449. HeartBeatFlag = true;
  1450. FINFO("HardwareStatusThread start");
  1451. if ((int)pCurGen->m_GenConfig["loopTime"] >= 100)
  1452. {
  1453. pCurGen->m_iLoopTime = (int)pCurGen->m_GenConfig["loopTime"];
  1454. }
  1455. FINFO("loopTime = {$}", pCurGen->m_iLoopTime.load());
  1456. int currtTime = pCurGen->m_iLoopTime;
  1457. while (m_bExtraFlag)
  1458. {
  1459. if (!(pCurGen->m_bConnectFlag))
  1460. {
  1461. FINFO("AlmaxGEN: not Connect,try to reconnect \n");
  1462. pCurGen->FireErrorMessage(true, 1, "lost Connect");
  1463. pCurGen->ReConnect();
  1464. Sleep(20000);
  1465. continue;
  1466. }
  1467. FDEBUG("currtloopTime = {$}", pCurGen->m_iLoopTime.load());
  1468. currtTime = pCurGen->m_iLoopTime;
  1469. Sleep(currtTime);
  1470. //心跳包统计加1
  1471. pCurGen->m_iHeartBeats++;
  1472. int tempHeartBeat = pCurGen->m_iHeartBeats;
  1473. if (tempHeartBeat > 10) //无返回信息认为连接断开
  1474. {
  1475. pCurGen->m_iHeartBeats = 0;
  1476. FINFO("AlmaxGEN: lost Connect \n");
  1477. pCurGen->m_bConnectFlag = false;
  1478. continue;
  1479. }
  1480. //发送心跳
  1481. if (currtTime == Almax_LoopExpHBTime)
  1482. {
  1483. pCurGen->HWSendHBCMD("22,", 3);
  1484. }
  1485. else
  1486. {
  1487. if(!(pCurGen->m_bExpEnable))
  1488. pCurGen->HWSendHBCMD("22,", 3);
  1489. else
  1490. pCurGen->HWSendHBCMD("99,", 3);
  1491. }
  1492. pCurGen->HWSendHBCMD("77,",3); //轮询发生器温度信息
  1493. }
  1494. FINFO("HardwareStatusThread stop");
  1495. return true;
  1496. }
  1497. //-----------------------------------------------------------------------------
  1498. // AlmaxDriver
  1499. //-----------------------------------------------------------------------------
  1500. nsGEN::AlmaxDriver::AlmaxDriver()
  1501. {
  1502. m_bDemoMode = false;
  1503. m_bDemoConnected = false;
  1504. m_pAttribute.reset(new ResDataObject());
  1505. m_pDescription.reset(new ResDataObject());
  1506. }
  1507. nsGEN::AlmaxDriver::~AlmaxDriver()
  1508. {
  1509. Close();
  1510. gLogger = nullptr;
  1511. }
  1512. void nsGEN::AlmaxDriver::Prepare()
  1513. {
  1514. ResDataObject r_config;
  1515. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1516. {
  1517. if ((int)r_config["CONFIGURATION"]["logEnable"] == 1)
  1518. {
  1519. string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
  1520. //Log4CPP::ThreadContext::Map::Set("LogFileName", "GEN.ContainerExample");
  1521. Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.ContainerExample");
  1522. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  1523. gLogger = Log4CPP::LogManager::GetLogger("GEN.ContainerExample");
  1524. }
  1525. m_bDemoMode = (atoi)(((string)r_config["CONFIGURATION"]["IsDemo"]).c_str());
  1526. ResDataObject Connection = r_config["CONFIGURATION"]["connections"][0];
  1527. if ((string)Connection["type"] == "COM")
  1528. {
  1529. m_SCFDllName = COM_SCFDllName;
  1530. }
  1531. else
  1532. {
  1533. m_SCFDllName = TCP_SCFDllName;
  1534. }
  1535. }
  1536. super::Prepare();
  1537. }
  1538. std::string nsGEN::AlmaxDriver::DriverProbe()
  1539. {
  1540. ResDataObject r_config, HardwareInfo;
  1541. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1542. {
  1543. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  1544. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  1545. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  1546. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  1547. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  1548. }
  1549. else
  1550. {
  1551. HardwareInfo.add("MajorID", "Generator");
  1552. HardwareInfo.add("MinorID", "Dr");
  1553. HardwareInfo.add("VendorID", "Almax");
  1554. HardwareInfo.add("ProductID", "HF");
  1555. HardwareInfo.add("SerialID", "Drv");
  1556. }
  1557. string ret = HardwareInfo.encode();
  1558. return ret;
  1559. }
  1560. bool nsGEN::AlmaxDriver::ReConnection(nsSCF::SCF& DevSCF)
  1561. {
  1562. super::Disconnect();
  1563. FINFO("ReConnection:SCF Disconnect");
  1564. ResDataObject r_config;
  1565. if (!r_config.loadFile(m_ConfigFileName.c_str()))
  1566. {
  1567. FINFO("ReConnection:open configFile failed");
  1568. return SCF_ERR::SCF_OPEN_FAILED;
  1569. }
  1570. ResDataObject Connection = r_config["CONFIGURATION"]["connections"][0];
  1571. FINFO("ReConnection:{$} \n", Connection.encode());
  1572. auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::AlmaxDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  1573. if (erCode == SCF_ERR::SCF_SUCCEED)
  1574. {
  1575. Sleep(1000);
  1576. auto rc = super::Connect();
  1577. if (!rc)
  1578. {
  1579. FINFO("ReConnection:super Connect failed");
  1580. }
  1581. else
  1582. {
  1583. DevSCF = m_SCF;
  1584. return true;
  1585. }
  1586. }
  1587. else
  1588. {
  1589. FINFO("ReConnection failed");
  1590. }
  1591. return false;
  1592. }
  1593. bool nsGEN::AlmaxDriver::Connect()
  1594. {
  1595. if (m_bDemoMode)
  1596. {
  1597. FINFO("connections:DEMO \n");
  1598. m_bDemoConnected = true;
  1599. return true; //return SCF_ERR::SCF_SUCCEED;
  1600. }
  1601. ResDataObject r_config;
  1602. if (!r_config.loadFile(m_ConfigFileName.c_str()))
  1603. return false; //return SCF_ERR::SCF_OPEN_FAILED;
  1604. ResDataObject Connection = r_config["CONFIGURATION"]["connections"][0];
  1605. //printf("connections:%s \n", Connection.encode());
  1606. FINFO("connections:{$} \n", Connection.encode());
  1607. auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::AlmaxDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  1608. if (erCode != SCF_ERR::SCF_SUCCEED)
  1609. return false; //return erCode;
  1610. auto rc = super::Connect();
  1611. if (!rc)
  1612. return false; //return 0;
  1613. //return (erCode == SCF_ERR::SCF_SUCCEED);
  1614. return true; //return SCF_ERR::SCF_SUCCEED;
  1615. }
  1616. auto nsGEN::AlmaxDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  1617. {
  1618. if (m_bDemoMode)
  1619. {
  1620. if (!m_bDemoConnected)
  1621. {
  1622. FERROR("CreateDevice:m_bDemoConnected is false \n");
  1623. return nullptr;
  1624. }
  1625. auto dev = std::unique_ptr <IODevice>(new IODevice(new DemoDevice(EventCenter)));
  1626. return dev;
  1627. }
  1628. if (!m_SCF.isConnected())
  1629. {
  1630. FERROR("CreateDevice:m_SCF is not Connected \n");
  1631. return nullptr;
  1632. }
  1633. auto dev = std::unique_ptr <IODevice>(new IODevice(new AlmaxDevice(EventCenter, m_SCF, m_ConfigFileName)));
  1634. return dev;
  1635. }
  1636. void nsGEN::AlmaxDriver::FireNotify(int code, std::string key, std::string content)
  1637. {
  1638. EventCenter->OnNotify(code, key, content);
  1639. }
  1640. bool nsGEN::AlmaxDriver::isConnected() const
  1641. {
  1642. if (m_bDemoMode)
  1643. return m_bDemoConnected;
  1644. else
  1645. {
  1646. if (super::isConnected())
  1647. {
  1648. return true;
  1649. }
  1650. else
  1651. {
  1652. if(HeartBeatFlag) //避过平台层的断连检测
  1653. return true;
  1654. else
  1655. return false;
  1656. }
  1657. }
  1658. }
  1659. std::string nsGEN::AlmaxDriver::GetResource()
  1660. {
  1661. ResDataObject r_config, temp;
  1662. if (!temp.loadFile(m_ConfigFileName.c_str()))
  1663. {
  1664. return "";
  1665. }
  1666. m_ConfigAll = temp;
  1667. r_config = temp["CONFIGURATION"];
  1668. m_Configurations = r_config;
  1669. ResDataObject DescriptionTemp;
  1670. ResDataObject DescriptionSend;
  1671. ResDataObject m_DescriptionSend;
  1672. ResDataObject ListTemp;
  1673. string strTemp = ""; //用于读取字符串配置信息
  1674. string strIndex = ""; //用于读取配置信息中的List项
  1675. int nTemp = -1; //用于读取整型配置信息
  1676. char sstream[10] = { 0 }; //用于转换值
  1677. string strValue = ""; //用于存储配置的值
  1678. string strType = ""; //用于存储配置的类型 int/float/string...
  1679. /***
  1680. * 1. 通过循环,将所有配置项写到pDeviceConfig
  1681. * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
  1682. ***/
  1683. try
  1684. {
  1685. //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
  1686. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1687. m_pAttribute->clear();
  1688. m_pDescription->clear();
  1689. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1690. {
  1691. DescriptionTemp.clear();
  1692. DescriptionSend.clear();
  1693. ListTemp.clear();
  1694. //AttributeType
  1695. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  1696. DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  1697. DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  1698. strType = strTemp; //记录配置项的类型
  1699. //AttributeKey
  1700. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  1701. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1702. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  1703. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
  1704. //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  1705. //2. 赋值
  1706. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1707. if ("int" == strType)
  1708. {
  1709. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1710. }
  1711. else if ("float" == strType)
  1712. {
  1713. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1714. }
  1715. else //其它先按string类型处理
  1716. {
  1717. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  1718. }
  1719. //printf("********************************outkey =%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  1720. //AttributeAccess
  1721. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  1722. DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
  1723. DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
  1724. /*
  1725. //AttributeRangeMin
  1726. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  1727. if (strTemp != "") //不需要的配置项为空
  1728. {
  1729. DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
  1730. }
  1731. //AttributeRangeMax
  1732. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  1733. if (strTemp != "") //不需要的配置项为空
  1734. {
  1735. DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
  1736. }
  1737. */
  1738. //AttributeList
  1739. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  1740. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  1741. {
  1742. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  1743. {
  1744. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  1745. auto temKey = std::to_string(nListIndex);
  1746. ListTemp.add(temKey.c_str(), strTemp.c_str());
  1747. }
  1748. DescriptionTemp.add(ConfKey::CcosList, ListTemp);
  1749. DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
  1750. }
  1751. //AttributeRequired
  1752. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  1753. DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
  1754. DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
  1755. //AttributeDefaultValue
  1756. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  1757. if (strTemp != "") //不需要的配置项为空
  1758. {
  1759. DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  1760. DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  1761. }
  1762. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1763. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  1764. m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
  1765. }
  1766. }
  1767. catch (ResDataObjectExption& e)
  1768. {
  1769. FERROR("Get config error: {$}", e.what());
  1770. return "";
  1771. }
  1772. ResDataObject resDeviceResource;
  1773. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  1774. resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
  1775. ResDataObject DescriptionTempEx;
  1776. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  1777. m_DeviceConfig.clear();
  1778. m_DeviceConfig = DescriptionTempEx;
  1779. FDEBUG("local ************* get resource over {$}", DescriptionTempEx.encode());
  1780. //printf("local ************* get resource over %s \n", DescriptionTempEx.encode());
  1781. resDeviceResource.clear();
  1782. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  1783. resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
  1784. DescriptionTempEx.clear();
  1785. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  1786. m_DeviceConfigSend.clear();
  1787. m_DeviceConfigSend = DescriptionTempEx;
  1788. string res = m_DeviceConfigSend.encode();
  1789. //printf("%s", res.c_str());
  1790. FDEBUG("get resource over {$}", DescriptionTempEx.encode());
  1791. //("************* get resource over %s \n", DescriptionTempEx.encode());
  1792. return res;
  1793. }
  1794. std::string nsGEN::AlmaxDriver::DeviceProbe()
  1795. {
  1796. ResDataObject r_config, HardwareInfo;
  1797. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1798. {
  1799. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  1800. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  1801. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  1802. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  1803. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  1804. }
  1805. else
  1806. {
  1807. HardwareInfo.add("MajorID", "Generator");
  1808. HardwareInfo.add("MinorID", "Dr");
  1809. HardwareInfo.add("VendorID", "Almax");
  1810. HardwareInfo.add("ProductID", "HF");
  1811. HardwareInfo.add("SerialID", "Dev");
  1812. }
  1813. string ret = HardwareInfo.encode();
  1814. return ret;
  1815. }
  1816. void nsGEN::AlmaxDriver::Disconnect()
  1817. {
  1818. super::Disconnect();
  1819. m_SCF.Disconnect();
  1820. m_bDemoConnected = false;
  1821. Close();
  1822. gLogger = nullptr;
  1823. }
  1824. void nsGEN::AlmaxDriver::Dequeue(const char* Packet, DWORD Length)
  1825. {
  1826. DecodeFrame(Packet, Length);
  1827. }
  1828. PACKET_RET nsGEN::AlmaxDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
  1829. {
  1830. #if 0
  1831. if (nLength > 1)
  1832. {
  1833. FERROR("receive data_len[{$}]", nLength);
  1834. for (int i = 0; i < nLength; i++)
  1835. {
  1836. if (i != nLength - 1)
  1837. {
  1838. FERROR("receive data[{$}][{$}]", i, RecData[i]);
  1839. }
  1840. else
  1841. {
  1842. FERROR("receive data[{$}][{$}]", i, RecData[i]);
  1843. }
  1844. }
  1845. }
  1846. #endif
  1847. bool bHasHead = false;
  1848. if (nLength < 1)
  1849. {
  1850. PacketLength = 0;
  1851. FERROR("nLength too small, nLength=={$}", nLength);
  1852. return PACKET_USELESS;
  1853. }
  1854. else if(nLength > Almax_Com_NormalLen)
  1855. {
  1856. PacketLength = nLength;
  1857. FERROR("nLength too big, nLength=={$}", nLength);
  1858. return PACKET_USELESS;
  1859. }
  1860. for (DWORD i = 0; i < nLength; i++)
  1861. {
  1862. //寻找包头
  1863. if (RecData[i]== Almax_STX)
  1864. {
  1865. if (i!=0) //包头之前的数据格式不对,全部扔掉
  1866. {
  1867. PacketLength = i;
  1868. char strtemp[Almax_Com_NormalLen] = { 0 };
  1869. memcpy(strtemp, RecData, PacketLength);
  1870. FERROR("==IN unknown format data ==:[{$}],UselessDataLength={$},TotalLength={$} \n", strtemp, PacketLength, nLength);
  1871. return PACKET_USELESS;
  1872. }
  1873. else
  1874. {
  1875. bHasHead = true;
  1876. }
  1877. }
  1878. //寻找包尾
  1879. if (RecData[i] == Almax_ETX)
  1880. {
  1881. if(bHasHead)
  1882. {
  1883. if (i >= 4) //正常指令
  1884. {
  1885. PacketLength = i + 1; //+1 because ETX
  1886. char strtemp[Almax_Com_NormalLen] = { 0 };
  1887. memcpy(strtemp, RecData + 1, i - 1); //只有数据+CSUM,+1 排除 STX ,-1 排除 ETX。
  1888. if (!((strtemp[0] == '9' && strtemp[1] == '9') || (strtemp[0] == '7' && strtemp[1] == '7')))
  1889. {
  1890. FINFO("==IN==:[{$}]", strtemp);
  1891. AlmaxDevice::m_tDelivermodule.CheckReceive(strtemp,2);
  1892. }
  1893. return PACKET_ISPACKET;
  1894. }
  1895. else //空指令
  1896. {
  1897. PacketLength = i + 1;
  1898. char strtemp[Almax_Com_NormalLen] = { 0 };
  1899. memcpy(strtemp, RecData, PacketLength); //空数据,格式正确但无有效命令。
  1900. FERROR("==IN uselss data==:[{$}] \n", strtemp);
  1901. return PACKET_USELESS;
  1902. }
  1903. }
  1904. else //有包尾但无包头
  1905. {
  1906. PacketLength = i + 1;
  1907. char strtemp[Almax_Com_NormalLen] = { 0 };
  1908. memcpy(strtemp, RecData, PacketLength);
  1909. FERROR("==IN no head data ==:[{$}],NoHeadDataLength={$},TotalLength={$} \n", strtemp, PacketLength, nLength);
  1910. return PACKET_USELESS;
  1911. }
  1912. }
  1913. }
  1914. if (bHasHead)
  1915. {
  1916. PacketLength = 0;
  1917. }
  1918. return PACKET_NOPACKET;
  1919. }
  1920. bool nsGEN::AlmaxDriver::GetDeviceConfig(std::string& Cfg)
  1921. {
  1922. Cfg = m_DeviceConfigSend.encode();
  1923. printf("GetDeviceConfig over , %s", Cfg.c_str());
  1924. return true;
  1925. }
  1926. bool nsGEN::AlmaxDriver::SetDeviceConfig(std::string Cfg)
  1927. {
  1928. FINFO("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  1929. printf("\n--Func-- SetDeviceConfig %s\n", Cfg.c_str());
  1930. ResDataObject DeviceConfig;
  1931. DeviceConfig.decode(Cfg.c_str());
  1932. ResDataObject DescriptionTempEx;
  1933. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  1934. FDEBUG("Attribute:{$}", DescriptionTempEx.encode());
  1935. bool bSaveFile = false; //true:重新保存配置文件
  1936. string strAccess = "";
  1937. for (int i = 0; i < DescriptionTempEx.size(); i++)
  1938. {
  1939. string strKey = DescriptionTempEx.GetKey(i);
  1940. FINFO("{$}", strKey.c_str());
  1941. printf("%s\n", strKey.c_str());
  1942. try
  1943. {
  1944. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  1945. {
  1946. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  1947. if ("RW" == strAccess)
  1948. {
  1949. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  1950. //1. 修改内存中的值,用于给上层发消息
  1951. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  1952. //2. 拿到Innerkey
  1953. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1954. FINFO("nConfigInfoCount {$}", nConfigInfoCount);
  1955. string strTemp = ""; //存储AttributeKey
  1956. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1957. {
  1958. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1959. if (strTemp == strKey)
  1960. {
  1961. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1962. break;
  1963. }
  1964. }
  1965. //3. 修改配置文件中的值
  1966. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  1967. {
  1968. FDEBUG("SetDeviceConfigValue over");
  1969. bSaveFile = true;
  1970. }
  1971. }
  1972. else
  1973. {
  1974. FINFO("{$} is not a RW configuration item", strKey.c_str());
  1975. }
  1976. }
  1977. else
  1978. {
  1979. FINFO("without this attribute {$}", strKey.c_str());
  1980. }
  1981. }
  1982. catch (ResDataObjectExption& e)
  1983. {
  1984. printf("\nSetDriverConfig crashed: %s\n", e.what());
  1985. FERROR("SetDriverConfig crashed: {$}", e.what());
  1986. return false;
  1987. }
  1988. }
  1989. if (bSaveFile)
  1990. {
  1991. //3. 重新保存配置文件
  1992. SaveConfigFile(true);
  1993. }
  1994. return true;
  1995. }
  1996. bool nsGEN::AlmaxDriver::SaveConfigFile(bool bSendNotify)
  1997. {
  1998. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  1999. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  2000. FINFO("SaveConfigFile over {$}", bRt);
  2001. return true;
  2002. }
  2003. bool nsGEN::AlmaxDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  2004. {
  2005. strValue = "";
  2006. string strTemp = pInnerKey;
  2007. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  2008. {
  2009. int pos = 0;
  2010. ResDataObject resTemp = config;
  2011. while ((pos = strTemp.find_first_of(',')) != string::npos)
  2012. {
  2013. string Key = strTemp.substr(0, pos);
  2014. string TempValue = resTemp[Key.c_str()].encode();
  2015. // printf("-TempValue=== %s", TempValue.c_str());
  2016. resTemp.clear();
  2017. resTemp.decode(TempValue.c_str());
  2018. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  2019. //printf("-************--%s", strTemp.c_str());
  2020. }
  2021. if (strTemp != "")
  2022. {
  2023. strValue = (string)resTemp[strTemp.c_str()];
  2024. }
  2025. else
  2026. {
  2027. strValue = (string)resTemp;
  2028. }
  2029. }
  2030. //printf("------------%s", strValue.c_str());
  2031. return true;
  2032. }
  2033. bool nsGEN::AlmaxDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  2034. {
  2035. string strTemp = pInnerKey;
  2036. FDEBUG("Begin to change {$} item value to {$}", pInnerKey, szValue);
  2037. printf("\nbbbbbbbbbbbbbbBegin to change {%s} item value to {%s}\n", pInnerKey, szValue);
  2038. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  2039. {
  2040. try {
  2041. int pos = 0;
  2042. ResDataObject* resTemp = &config;
  2043. while ((pos = strTemp.find_first_of(',')) != string::npos)
  2044. {
  2045. string Key = strTemp.substr(0, pos);
  2046. resTemp = &(*resTemp)[Key.c_str()];
  2047. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  2048. }
  2049. if (strTemp != "")
  2050. {
  2051. //if ((strTemp.compare("WSTable") == 0) ||
  2052. // (strTemp.compare("WSWall") == 0) ||
  2053. // (strTemp.compare("WSFree") == 0) ||
  2054. // (strTemp.compare("WSTomo") == 0) ||
  2055. // (strTemp.compare("WSConventional") == 0)
  2056. // )
  2057. //{
  2058. // int sum = (*szValue) + 1;
  2059. // (*resTemp)[strTemp.c_str()] = (char*)(&sum);
  2060. //}
  2061. //else
  2062. // (*resTemp)[strTemp.c_str()] = szValue;
  2063. (*resTemp)[strTemp.c_str()] = szValue;
  2064. }
  2065. else
  2066. {
  2067. *resTemp = szValue;
  2068. }
  2069. }
  2070. catch (ResDataObjectExption& e)
  2071. {
  2072. FERROR("SetDriverConfigvalue crashed: {$}", e.what());
  2073. return false;
  2074. }
  2075. }
  2076. return true;
  2077. }
  2078. //-----------------------------------------------------------------------------
  2079. // GetIODriver & CreateIODriver
  2080. //-----------------------------------------------------------------------------
  2081. static nsGEN::AlmaxDriver gIODriver;
  2082. extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  2083. {
  2084. return &gIODriver;
  2085. }
  2086. extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  2087. {
  2088. pIODriver = new nsGEN::AlmaxDriver();
  2089. return pIODriver;
  2090. }