123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316 |
- // CCOS.Dev.GEN.Almax.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include "stdafx.h"
- #include <assert.h>
- #include <functional>
- #include <LogicDevice.h>
- using namespace std::placeholders;
- #include "Helper.JSON.hpp"
- #include "CCOS.Dev.Generator.ContainerExample.h"
- using namespace CCOS::Dev::Detail::Generator;
- namespace nsGEN = CCOS::Dev::Detail::Generator;
- //关闭无关警告
- #pragma warning (disable:4244) // warning C4244: “初始化”: 从“double”转换到“float”,可能丢失数据
- #pragma warning (disable:4305) // warning C4305: “参数”: 从“double”到“float”截断
- #pragma warning (disable:4267) // warning C4267 : “初始化”: 从“size_t”转换到“int”,可能丢失数据
- #pragma warning (disable:4805) // warning C4805: “!=”: 在操作中将类型“bool”与类型“int”混合不安全
- //全局定义
- static nsGEN::AlmaxDriver* pIODriver = nullptr;
- //指令头
- #define Almax_CMD_GetGenVer "C0" //5.1.1.MESSAGE TYPE C0H <REQ SW VER>
- #define Almax_CMD_SetLanguage "82" //5.1.2.MESSAGE TYPE 82H <LANGUAGE USED>
- #define Almax_CMD_SetAPRAPF "38" //5.1.3.MESSAGE TYPE 38H <EXAM SELECTION>
- #define Almax_CMD_SetAnatomic "39" //5.1.4.MESSAGE TYPE 39H <ANATOMIC>解剖
- #define Almax_CMD_SetProject "3A" //5.1.5.MESSAGE TYPE 3AH <PROJECTION>
- #define Almax_CMD_SetFluPPS "3C" //5.1.6.MESSAGE TYPE 3CH <PULSED RATE>
- #define Almax_CMD_SetRadPPS "3D" //5.1.7.MESSAGE TYPE 3DH <RAD RATE>
- #define Almax_CMD_SetRadDose "49" //5.1.8.MESSAGE TYPE 49H <RAD DOSE CONTROL>
- #define Almax_CMD_SetAcqData "4A" //5.1.9.MESSAGE TYPE 4AH <ACQUISITION FLUORO DATA>采集透视数据
- #define Almax_CMD_SetABSKV "4B" //5.1.10. MESSAGE TYPE 4BH <ABC SET KV>
- #define Almax_CMD_GetABSKV "4C" //5.1.11. MESSAGE TYPE 4CH <ABC GET KV>
- #define Almax_CMD_SetABSGrey "4E" //5.1.12. MESSAGE TYPE 4EH <ABC SET CURRENT GREY LEVEL>
- #define Almax_CMD_GetStatus "50" //5.1.13. MESSAGE TYPE 50H <GET STATUS C-ARM>
- #define Almax_CMD_GetRPData "51" //5.1.14. MESSAGE TYPE 51H <GET RP DATA>
- #define Almax_CMD_GetFluDose "52" //5.1.15. MESSAGE TYPE 52H <GET DOSE FLUO>
- #define Almax_CMD_GetRadDose "53" //5.1.16. MESSAGE TYPE 53H <GET DOSE RAD>
- #define Almax_CMD_SetFPDTemp "54" //5.1.17. MESSAGE TYPE 54H <SET TEMP FPD>
- #define Almax_CMD_SetNewExam "55" //5.1.18. MESSAGE TYPE 55H <SET NEW STUDY>
- #define Almax_CMD_SetlowDose "56" //5.1.19. MESSAGE TYPE 56H <SET LOW DOSE>
- #define Almax_CMD_SetPatient "58" //5.1.21. MESSAGE TYPE 58H <PATIENT DATA>
- #define Almax_CMD_SetPhysique "59" //5.1.22. MESSAGE TYPE 59H <PATIENT SIZE>
- #define Almax_CMD_ResKeyEvent "00" //6.1.1.MESSAGE TYPE 00H <KEY EVENT>
- #define Almax_CMD_ResGenVer "81" //6.1.2.MESSAGE TYPE 81H <SW VER> (作为消息 83H 的替代方案)
- #define Almax_CMD_ResArchVer "83" //6.1.3.MESSAGE TYPE 83H <SW VER> (作为消息 81H 的替代方案)
- #define Almax_CMD_ResExam "3E" //6.1.4.MESSAGE TYPE 3EH <REMOTE EXAM SELECT>
- #define Almax_CMD_ResPhysique "3F" //6.1.5.MESSAGE TYPE 3FH <REMOTE PATIENT SIZE SELECTION>
- #define Almax_CMD_ResABSKV "4D" //6.1.6.MESSAGE TYPE 4DH <ABC STATUS KV>
- #define Almax_CMD_ReslowDose "57" //6.1.7.MESSAGE TYPE 57H <STATUS LOW DOSE>
- #define Almax_CMD_ResFluPost "72" //6.1.8.MESSAGE TYPE 72H <DOSE FLUO + COLLIMATOR>
- #define Almax_CMD_ResFLUPost "73" //6.1.9.MESSAGE TYPE 73H <DOSE FLUO X10 + COLLIMATOR >
- #define Almax_CMD_ResRadPost "7B" //6.1.10. MESSAGE TYPE 7BH <DOSE RAD>
- #define Almax_CMD_ResRADPost "74" //6.1.11. MESSAGE TYPE 74H <DOSE RAD X10>
- #define Almax_CMD_ResRPData "91" //6.1.12. MESSAGE TYPE 91H <RP DATA>
- #define Almax_CMD_ResStatus "76" //6.1.13. MESSAGE TYPE 76H <STATUS C-ARM>
- #define Almax_CMD_ResSID "77" //6.1.14. Message Type 77H <STATUS C-ARM SID>
- #define Almax_CMD_ResCollData "7E" //6.1.15. MESSAGE TYPE 7EH <STATUS_COL>
- #define Almax_CMD_ResRotating "7F" //6.1.16. MESSAGE TYPE 7FH <STATUS_ROTATING_COL>
- #define Almax_CMD_ResErrWarn "80" //6.1.17. MESSAGE TYPE 80H <ERROR / WARNING>
- //设置相关常量
- static const int msTimeOut_Lock = 500; //通讯接口锁定时间
- #define Almax_Com_NormalLen 300
- #define Almax_LoopDefHBTime 1000
- #define Almax_LoopExpHBTime 500
- #define Almax_STX 0x02
- #define Almax_ETX 0x03
- #define Almax_ACK 0x06
- #define Almax_NAK 0x15
- /*
- *串口/以太网通信帧格式:
- <STX><code[30H-39H,41H-46H]><CSUM[所有code的异或值]><ETX>
- 解释:
- <STX> = 1 ASCII 0x02 帧头
- <code> = 1 ASCII指令头+不定长属性项、属性值
- <CSUM> = 校验和
- <ETX> = 1 ASCII 0x03 帧尾
- 串口通信设置:
- . 19200 波特率
- . No Parity
- . 8 Data Bits
- . 2 Stop Bit
- . 无握手过程
- */
- //设置对应通信接口库
- #ifdef _WIN64
- #ifdef _DEBUG
- static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64D.dll";
- #else
- static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64.dll";
- #endif
- #endif
- #ifdef _WIN64
- #ifdef _DEBUG
- static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64D.dll";
- #else
- static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64.dll";
- #endif
- #endif
- Log4CPP::Logger* gLogger = nullptr;
- //指令操作关联结构
- nsGEN::tFrameMapItem::tFrameMapItem()
- {
- m_fFun = NULL;
- }
- nsGEN::tFrameMapItem::tFrameMapItem(cbFun f)
- {
- m_fFun = f;
- }
- nsGEN::tFrameMapItem& nsGEN::tFrameMapItem::operator =(const tFrameMapItem& value)
- {
- m_fFun = value.m_fFun;
- return *this;
- }
- //响应操作对照表
- static std::map <string,tFrameMapItem> arFrame;
- //生成命令校验和:cmdData 为 <CMD>; size:指令长度+1 BYTE CheckSum
- char ComputeCheckSum(const char* cmdData, int& size)
- {
- try
- {
- char AsciiSum = 0x00;
- if (size < 2) //1 BYTE CMD_ID + 1 BYTE Reserved
- {
- FDEBUG("ComputeCheckSum:failed[0x00]");
- return AsciiSum;
- }
- for (int i = 0; i < size; i++) //每字节相加
- {
- AsciiSum ^= cmdData[i];
- }
- FDEBUG("ComputeCheckSum:[0x{$:x}]", AsciiSum);
- return (char)AsciiSum;
- }
- catch (...)
- {
- FDEBUG("ComputeCheckSum:Error[0x00]");
- return 0x00;
- }
- }
- //查找响应操作对照表执行对应操作
- static bool DecodeFrame(const char* strFrame, int length)
- {
- char data[Almax_Com_NormalLen] = { 0 };
- strncpy_s(data, strFrame+1, 2);
- auto found = arFrame.find(data);//此处pr用来在arFrame中找到对于的包头
- if (found == arFrame.end())
- {
- return false;
- }
- //found->second.tChangeWaitState(0, data);
- int cmdHead = found->first.length();
- memcpy(data, strFrame + cmdHead + 1, length - cmdHead - 1);
- found->second.m_fFun(data, length - cmdHead);//第二个参数 不重要
- return true;
- }
- //取值集合
- 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 };
- 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 };
- //-----------------------------------------------------------------------------
- // AlmaxDevice
- //-----------------------------------------------------------------------------
- atomic<bool> nsGEN::AlmaxDevice::m_bExtraFlag = false;
- atomic<int> nsGEN::AlmaxDevice::m_iLoopTime = Almax_LoopDefHBTime;
- nsSerialGPM::CDeliverModule nsGEN::AlmaxDevice::m_tDelivermodule;
- static atomic<bool>HeartBeatFlag = false;
- nsGEN::AlmaxDevice::AlmaxDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF, string configfile) : super(center, SCF)
- {
- assert(EventCenter);
- //其余属性初始化
- ResDataObject temp;
- temp.loadFile(configfile.c_str());
- m_GenConfig = temp["CONFIGURATION"];
- m_pHardwareStatusThread = NULL;
- m_bExpEnable = false;
- m_iHeartBeats = 0;
- m_bConnectFlag = true;
- m_iLoopTime.store(Almax_LoopDefHBTime);
- //两种日志方式自行选择
- string version;
- if(GetVersion(version, hMyModule))
- FINFO("\n===============log begin : version:{$} ===================\n", version.c_str());
- else
- FINFO("\n===============log begin : version:0.0.0.0 ===================\n");
- //点片参数
- m_DoseUnit.m_KV.reset(new KVMould(40.0, 40.0, 150.0, 1.0)); //接口协议范围:40-150
- m_DoseUnit.m_MA.reset(new MAMould(10.0, 0, 1000, 0.1)); //接口协议范围:10-1000
- m_DoseUnit.m_MS.reset(new MSMould(500.0, 0, 65535, 0.01));//接口协议范围:0-65535
- m_DoseUnit.m_MAS.reset(new MASMould(0.5, 0, 1000.0, 0.01)); //接口协议范围:0.5-1000
- m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_AEC_MAS_MA, 1));
- m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
- m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_TYPE::FOCUS_LARGE, AttrKey::FOCUS_SMALL, AttrKey::FOCUS_LARGE, 1));
- m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
- m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
- m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
- m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
- m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
- m_DoseUnit.m_GenState.reset(new GENSTATEMould(0, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_NOWORK, 1));
- m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(EXPMODE_TYPE::Single));
- m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 16, 1));
- m_DoseUnit.m_FLFMode.reset(new FLFMODEMould(FLFMODE_TYPE::FLF_DISB));
- m_DoseUnit.m_BatteryChargeState.reset(new BATTERYCHARGSTATEMould(0, 0, 1, 1));
- m_DoseUnit.m_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(TUBETARGETMATERIAL_TYPE::MO));
- m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0, -45, 45, 1));
- //动态参数
- std::unique_ptr<FLUKVMould> m_FLKV;
- std::unique_ptr<FLUMAMould> m_FLMA;
- std::unique_ptr<FLUMSMould> m_FLMS;
- std::unique_ptr<FLAccTimeMould> m_FLAccTime;//透视累计时间
- std::unique_ptr<FLUIntTimeMould> m_FLIntTime;//脉冲周期时间
- std::unique_ptr<PPSMould> m_PPS;//帧率
- std::unique_ptr<FLUModeMould> m_FLMode;//透视模式: 0-非透视, 1-连续,2-脉冲,3-高剂量连续,4-高剂量脉冲
- std::unique_ptr<FLUABSStatusMould> m_ABSStatus;//ABS状态: 0-ABS关闭, 1-ABS启用(KV only), 2 - ABS启用(KV/mA)
- std::unique_ptr<FLUMagMould> m_MagSize;//fluoro mag 0 to 3 - sets Mag size, ASCII character for 255 - Mag selection disabled
- 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 使用。
- std::unique_ptr<FLUCurveMould> m_Curve;//ABS曲线 0 = OFF, 1-3 = curve enabled
- //cine
- std::unique_ptr<FLUCineKVMould> m_CineFLKV;//
- std::unique_ptr<FLUCineMAMould> m_CineFLMA;//
- std::unique_ptr<FLUCineMSMould> m_CineFLMS;//
-
- //实际曝光参数值
- m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 0.0, 50.0, 1.0));
- m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 0.0, 200.0, 0.1));
- m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 0.0, 12000.0, 0.01));
- m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.0, 600.0, 0.01));
- //发生器告警及错误消息
- m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
-
- if (m_GenConfig.GetKeyCount("loopEnable") > 0)
- {
- m_bExtraFlag = (int)m_GenConfig["loopEnable"];
- }
- if (m_GenConfig.GetKeyCount(ConfKey::CcosTubeInfo) > 0)
- {
- string tempValue = m_GenConfig[ConfKey::CcosTubeInfo];
- m_DoseUnit.m_TubeInfo.reset(new TUBEINFOMould(tempValue));
- FireNotify(AttrKey::TUBEINFO, m_DoseUnit.m_TubeInfo->JSGet());
- }
- if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusSmall) > 0)
- {
- float tempValue = (float)m_GenConfig[ConfKey::CcosFocusSmall];
- m_DoseUnit.m_FocusSmall = tempValue;
- }
- if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusLarge) > 0)
- {
- float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
- m_DoseUnit.m_FocusLarge = tempValue;
- }
- m_tDelivermodule.InitSendModle(this, &ProcessClientData, WriteLog);
- m_nCMDType_WaitTime = m_tDelivermodule.SetPriority(true, false, false, true, 100);
- m_nCMDType_HB = m_tDelivermodule.SetPriority(false, true, false, true, 100);
- m_nCMDType_WaitACK = m_tDelivermodule.SetPriority(true, false, 3, false, 0,true,1000);
- FINFO("m_nCMDType_WaitTime[{$}]m_nCMDType_HB[{$}] m_nCMDType_WaitACK[{$}]", m_nCMDType_WaitTime, m_nCMDType_HB, m_nCMDType_WaitACK);
- //配置响应操作对照表 供发生器回传的数据触发相应的操作
- OnCallBack();
- //将发生器可以对外提供的指令注册集进行补充
- Register();
- //重置发生器
- Reset();
- Sleep(500);
- //以下进行默认设置,需要注意默认值是否正确
- RefreshData(); //刷新初始数值
-
- //启动硬件状态轮询进程
- StartHardwareStatusThread();
- }
- nsGEN::AlmaxDevice::~AlmaxDevice()
- {
- m_bExtraFlag = false;
- FINFO("\n===============log end ===================\n");
- if (m_pHardwareStatusThread != NULL)
- {
- TerminateThread(m_pHardwareStatusThread, 0);
- m_pHardwareStatusThread = NULL;
- }
- arFrame.clear();
- }
- std::string nsGEN::AlmaxDevice::GetGUID() const
- {
- FINFO("===============GetGUID : {$} ===================\n", GeneratorUnitType);
- return GeneratorUnitType;
- }
- void nsGEN::AlmaxDevice::Register()
- {
- auto Disp = Dispatch.Lock().As();
- superGen::Register(Disp);
- superGen::RegisterKV(Disp);
- superGen::RegisterMA(Disp);
- superGen::RegisterMS(Disp);
- superGen::RegisterMAS(Disp);
- superGen::RegisterAEC(Disp);
- superGen::RegisterFOCUS(Disp);
- superGen::RegisterTECHMODE(Disp);
- superGen::RegisterExpEnable(Disp);
- superGen::RegisterGeneratortoSyncStatus(Disp);
- Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
- auto fun_Clear_DAP = [this](auto in, auto& out)
- {
- return Clear_DAP();
- };
- Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
- auto fun_GetValue_DAP = [this](auto in, auto& out)
- {
- float value = 0;
- RET_STATUS ret = GetValue_DAP(value);
- out = ToJSON(value);
- return ret;
- };
- Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
- auto fun_StartMove = [this](auto in, auto& out)
- {
- return StartMove();
- };
- Disp->Action.Push("StartMove", fun_StartMove);
- auto fun_EndMove = [this](auto in, auto& out)
- {
- return EndMove();
- };
- Disp->Action.Push("EndMove", fun_EndMove);
- }
- RET_STATUS nsGEN::AlmaxDevice::IncKV()
- {
- if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
-
- float oldKV= m_DoseUnit.m_KV->Get();
- oldKV++;
- oldKV *= 1000;
- char temp[50] = { 0 };
- sprintf_s(temp, "10,%d,", (int)round(oldKV / 12.21));
- return HWSendWaittimeCMD(temp,strlen(temp));
- }
- RET_STATUS nsGEN::AlmaxDevice::DecKV()
- {
- if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
-
- float oldKV = m_DoseUnit.m_KV->Get();
- oldKV--;
- oldKV *= 1000;
- char temp[50] = { 0 };
- sprintf_s(temp, "10,%d,", (int)round(oldKV / 12.21));
- return HWSendWaittimeCMD(temp,strlen(temp));
- }
- RET_STATUS nsGEN::AlmaxDevice::SetKV(float value)
- {
- if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- sprintf_s(temp, "10,%d,", (int)round(value * 1000 / 12.21));
- return HWSendWaittimeCMD(temp,strlen(temp));
- }
- RET_STATUS nsGEN::AlmaxDevice::IncMA()
- {
- if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- FINFO("Techmode is 2Point, Cannot inc MA \n");
- return RET_STATUS::RET_FAILED;
- }
- float oldMA = m_DoseUnit.m_MA->Get();
- oldMA++;
- char temp[50] = { 0 };
- sprintf_s(temp, "11,%d,", (int)round(oldMA / 0.04884));
- return HWSendWaittimeCMD(temp,strlen(temp));
- }
- RET_STATUS nsGEN::AlmaxDevice::DecMA()
- {
- if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- FINFO("Techmode is 2Point, Cannot dec MA \n");
- return RET_STATUS::RET_FAILED;
- }
- float oldMA = m_DoseUnit.m_MA->Get();
- oldMA--;
- char temp[50] = { 0 };
- sprintf_s(temp, "11,%d,", (int)round(oldMA / 0.04884));
- return HWSendWaittimeCMD(temp,strlen(temp));
- }
- RET_STATUS nsGEN::AlmaxDevice::SetMA(float value)
- {
- if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- FINFO("Techmode is 2Point, Cannot set MA \n");
- return RET_STATUS::RET_FAILED;
- }
- char temp[50] = { 0 };
- sprintf_s(temp, "11,%d,", (int)round(value / 0.04884));
- return HWSendWaittimeCMD(temp,strlen(temp));
- }
- RET_STATUS nsGEN::AlmaxDevice::IncMS()
- {
- if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- FINFO("Techmode is 2Point, Cannot inc MS \n");
- return RET_STATUS::RET_FAILED;
- }
- float oldMS = m_DoseUnit.m_MS->Get();
- oldMS++;
- char temp[50] = { 0 };
- sprintf_s(temp, "72,%d,", (int)(oldMS));
- return HWSendWaittimeCMD(temp,strlen(temp));
- }
- RET_STATUS nsGEN::AlmaxDevice::DecMS()
- {
- if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- FINFO("Techmode is 2Point, Cannot dec MS \n");
- return RET_STATUS::RET_FAILED;
- }
- float oldMS = m_DoseUnit.m_MS->Get();
- oldMS--;
- char temp[50] = { 0 };
- sprintf_s(temp, "72,%d,", (int)(oldMS));
- return HWSendWaittimeCMD(temp,strlen(temp));
- }
- RET_STATUS nsGEN::AlmaxDevice::SetMS(float value)
- {
- if (!m_DoseUnit.m_MS->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- FINFO("Techmode is 2Point, Cannot set MS \n");
- return RET_STATUS::RET_FAILED;
- }
-
- char temp[50] = { 0 };
- sprintf_s(temp, "72,%d,", (int)(value));
- return HWSendWaittimeCMD(temp,strlen(temp));
- }
- RET_STATUS nsGEN::AlmaxDevice::IncMAS()
- {
- if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- FINFO("Techmode is 3Point, Cannot inc MAS \n");
- return RET_STATUS::RET_FAILED;
- }
- float oldMAS = m_DoseUnit.m_MAS->Get();
- if (m_DoseUnit.m_MAS->CanToNext(oldMAS, g_MAS_List))
- {
- FDEBUG("IncMAS:inc MAS[{$}]->[{$}]", m_DoseUnit.m_MAS->Get(), oldMAS);
- char temp[50] = { 0 };
- sprintf_s(temp, "74,%d,", (int)round(oldMAS / 0.1));
- return HWSendWaittimeCMD(temp, strlen(temp));
- }
- else
- {
- FERROR("IncMAS:Cannot inc MAS[{$}]", m_DoseUnit.m_MAS->Get());
- return RET_STATUS::RET_FAILED;
- }
- return RET_STATUS::RET_FAILED;
- }
- RET_STATUS nsGEN::AlmaxDevice::DecMAS()
- {
- if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- FINFO("Techmode is 3Point, Cannot dec MAS \n");
- return RET_STATUS::RET_FAILED;
- }
- float oldMAS = m_DoseUnit.m_MAS->Get();
- if (m_DoseUnit.m_MAS->CanToPrev(oldMAS, g_MAS_List))
- {
- FDEBUG("DecMAS:dec MAS[{$}]->[{$}]", m_DoseUnit.m_MAS->Get(), oldMAS);
- char temp[50] = { 0 };
- sprintf_s(temp, "74,%d,", (int)round(oldMAS / 0.1));
- return HWSendWaittimeCMD(temp, strlen(temp));
- }
- else
- {
- FERROR("DecMAS:Cannot dec MAS[{$}]", m_DoseUnit.m_MAS->Get());
- return RET_STATUS::RET_FAILED;
- }
- return RET_STATUS::RET_FAILED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetMAS(float value)
- {
- if (!m_DoseUnit.m_MAS->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- FINFO("Techmode is 3Point, Cannot set MAS \n");
- return RET_STATUS::RET_FAILED;
- }
-
- float tempValue = value;
- if (m_DoseUnit.m_MAS->CanToUpdate(tempValue, g_MAS_List))
- {
- FDEBUG("UpdateMAS:update MAS[{$}]->[{$}]->[{$}]", m_DoseUnit.m_MAS->Get(), value, tempValue);
- char temp[50] = { 0 };
- sprintf_s(temp, "74,%d,", (int)round(tempValue / 0.1));
- return HWSendWaittimeCMD(temp, strlen(temp));
- }
- else
- {
- FERROR("UpdateMAS:Cannot set MAS[{$}]->[{$}]", value, tempValue);
- return RET_STATUS::RET_FAILED;
- }
-
- return RET_STATUS::RET_FAILED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetTechmode(int value)
- {
- if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("SetTechmode:[{$}] \n", value);
- switch (value)
- {
- case AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P:
- {
- HWSendWaitACKCMD("55,0,", 5, 3);
- HWSendWaitACKCMD("57,0,", 5, 3);
- }
- break;
- case AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P:
- {
- HWSendWaitACKCMD("55,1,", 5, 3);
- HWSendWaitACKCMD("57,0,", 5, 3);
- }
- break;
- case AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P:
- {
- HWSendWaitACKCMD("55,0,", 5, 3);
- HWSendWaitACKCMD("57,1,", 5, 3);
- }
- break;
- case AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P:
- {
- HWSendWaitACKCMD("55,1,", 5, 3);
- HWSendWaitACKCMD("57,1,", 5, 3);
- }
- break;
- default:
- break;
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetEXAMMode(std::string value) //DMOC实际是通过此接口设置是否启用AEC
- {
- //上层给我设置exam mode(manual semiauto automatic)对应(NoAEC2Point AEC2Point AEC2Point)
- FINFO("Enter setexammode func value = {$}\n", value);
- if (value == EXAMMODE_TYPE::MANUAL)
- {
- //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P)
- {
- SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P);
- }
- }
- else if (value == EXAMMODE_TYPE::SEMIAUTO)
- {
- //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
- }
- }
- else if (value == EXAMMODE_TYPE::AUTOMATIC)
- {
- //if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetAPR(const _tAPRArgs& t)
- {
- 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);
- if (!m_DoseUnit.m_KV->Verify(t.fKV))
- {
- FERROR("SetAPR:KV Out of bounds[{$}] \n", t.fKV);
- }
- else if (!m_DoseUnit.m_MA->Verify(t.fMA) && (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P))
- {
- FERROR("SetAPR:MA Out of bounds[{$}] \n", t.fMA);
- }
- else if (!m_DoseUnit.m_MS->Verify(t.fMS) && (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P))
- {
- FERROR("SetAPR:MS Out of bounds[{$}] \n", t.fMS);
- }
- else if (!m_DoseUnit.m_MAS->Verify(t.fMAS) && (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P))
- {
- FERROR("SetAPR:MAS Out of bounds[{$}] \n", t.fMAS);
- //add by wxx for test
- float oldKV = m_DoseUnit.m_KV->Get();
- float oldMAS = m_DoseUnit.m_MAS->Get();
- float oldMA = m_DoseUnit.m_MA->Get();
- float oldMS = m_DoseUnit.m_MS->Get();
- int oldFocus = m_DoseUnit.m_Focus->Get();
- FERROR("SetAPR:old KV[{$}],MAS[{$}],MA[{$}],Focus[{$}]", oldKV, oldMAS, oldMA, oldFocus);
- char temp[50] = { 0 };
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- char temp[50] = { 0 };
- sprintf_s(temp, "50,%d,%d,%d,%d,", (int)(oldMS), (int)round(oldKV * 1000 / 12.21), (int)round(oldMA / 0.04884), (int)(oldFocus));
- return HWSendWaittimeCMD(temp, strlen(temp));
- }
- else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- char temp[50] = { 0 };
- sprintf_s(temp, "10,%d,", (int)round(oldKV * 1000 / 12.21));
- HWSendWaittimeCMD(temp, strlen(temp));
- float tempValue = oldMAS;
- if (m_DoseUnit.m_MAS->CanToUpdate(tempValue, g_MAS_List))
- {
- FDEBUG("SetAPR:update MAS[{$}]->[{$}]->[{$}]", m_DoseUnit.m_MAS->Get(), oldFocus, tempValue);
- char temp[50] = { 0 };
- sprintf_s(temp, "74,%d,", (int)round(tempValue / 0.1));
- HWSendWaittimeCMD(temp, strlen(temp));
- }
- }
- }
- else if (!m_DoseUnit.m_Focus->Verify(t.nFocus))
- {
- FERROR("SetAPR:Focus Out of bounds[{$}] \n", t.nFocus);
- }
- else
- {
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- char temp[50] = { 0 };
- 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));
- return HWSendWaittimeCMD(temp, strlen(temp));
- }
- else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- char temp[50] = { 0 };
- sprintf_s(temp, "10,%d,", (int)round(t.fKV * 1000 / 12.21));
- HWSendWaittimeCMD(temp, strlen(temp));
- float tempValue = t.fMAS;
- if (m_DoseUnit.m_MAS->CanToUpdate(tempValue, g_MAS_List))
- {
- FDEBUG("SetAPR:update MAS[{$}]->[{$}]->[{$}]", m_DoseUnit.m_MAS->Get(), t.fMAS, tempValue);
- char temp[50] = { 0 };
- sprintf_s(temp, "74,%d,", (int)round(tempValue / 0.1));
- HWSendWaittimeCMD(temp, strlen(temp));
- }
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::RefreshData()
- {
- FDEBUG("RefreshData:processing begin \n");
- //HWSendWaittimeCMD("51,",3);
- //HWSendWaittimeCMD("54,",3);
- HWSendWaittimeCMD("22,", 3);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetFocus(int value)
- {
- if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- sprintf_s(temp, "73,%01d,", (int)value);
- return HWSendWaittimeCMD(temp,strlen(temp));
- }
- RET_STATUS nsGEN::AlmaxDevice::Reset()
- {
- FDEBUG("clear all errors \n");
- int level = 0;
- m_MSGUnit->DelErrorMessage("0", level, "clear all errors");
- HWSendWaittimeCMD("31,",3);//仅重置错误状态
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::QueryHE(int& value) //实际为主动上报
- {
- //value = m_DoseUnit.m_HE->Get();
- HWSendWaittimeCMD("77,",3);
- return RET_STATUS::RET_SUCCEED;
- }
- //Almax发生器不支持的通用操作
- RET_STATUS nsGEN::AlmaxDevice::SetAECDensity(int value) //发生器无此设置
- {
- if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P)
- {
- FINFO("Techmode is not AEC, Cannot set Density \n");
- return RET_STATUS::RET_FAILED;
- }
- m_DoseUnit.m_AECDensity->Update(value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetAECField(int value) //发生器无此设置
- {
- if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
-
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P)
- {
- FINFO("Techmode is not AEC, Cannot set Field \n");
- return RET_STATUS::RET_FAILED;
- }
- m_DoseUnit.m_AECField->Update(value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetAECFilm(int value) //发生器无此设置
- {
- if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P)
- {
- FINFO("Techmode is not AEC, Cannot set Film \n");
- return RET_STATUS::RET_FAILED;
- }
- m_DoseUnit.m_AECFilm->Update(value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetWS(const string value) //发生器无此设置
- {
- FINFO("Enter SetWS {$}", value);
- int tempws = 0;
- if (value == "Table") tempws = (int)m_GenConfig["WSTable"];
- else if (value == "Wall") tempws = (int)m_GenConfig["WSWall"];
- else if (value == "Direct") tempws = (int)m_GenConfig["WSConventional"];
- else if (value == "Free") tempws = (int)m_GenConfig["WSFree"];
- else if (value == "Tomo") tempws = (int)m_GenConfig["WSTomo"];
- m_DoseUnit.m_WS->Update(tempws);
- return RET_STATUS::RET_SUCCEED;
- }
- int nsGEN::AlmaxDevice::GetGeneratorBatteryChargState() //实际为主动上报
- {
- return m_DoseUnit.m_BatteryChargeState->Get();
- }
- RET_STATUS nsGEN::AlmaxDevice::QueryPostKV(float& value) //实际为主动上报
- {
- if (m_DoseUnit.m_PostKV->Get() > 0)
- {
- value = m_DoseUnit.m_PostKV->Get();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::QueryPostMA(float& value) //实际为主动上报
- {
- if (m_DoseUnit.m_PostMA->Get() > 0)
- {
- value = m_DoseUnit.m_PostMA->Get();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::QueryPostMS(float& value) //实际为主动上报
- {
- if (m_DoseUnit.m_PostMS->Get() > 0)
- {
- value = m_DoseUnit.m_PostMS->Get();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::QueryPostMAS(float& value) //实际为主动上报
- {
- if (m_DoseUnit.m_PostMAS->Get() > 0)
- {
- value = m_DoseUnit.m_PostMAS->Get();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::Clear_DAP() //发生器无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::GetValue_DAP(float& value) //发生器无此设置
- {
- //value = m_DAP->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::StartMove() //发生器无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::EndMove() //发生器无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetGenSynState(int value) //发生器无此设置:AEC二阶段曝光使用
- {
- FDEBUG("Enter SetGenSynState[{$}]->[{$}]", m_DoseUnit.m_GenSynState->Get(), value);
-
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_MAS_MA)
- {
- if (value == nsGEN::AttrKey::GENERATOR_RAD_XRAYON)
- {
- FDEBUG("SetGenSynState:get Gen Status_5:RAD_READY(PR2) -> X-Ray On(XR1)");
- if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYON))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else if (value == nsGEN::AttrKey::GENERATOR_RAD_OFF)
- {
- float CurrtLastKV = m_DoseUnit.m_PostKV->Get();
- FDEBUG("SetGenSynState:get CurrtLastKV [{$}]", CurrtLastKV);
- FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
- float CurrtLastMA = m_DoseUnit.m_PostMA->Get();
- float CurrtLastMS = m_DoseUnit.m_PostMS->Get();
- float CurrtLastMAS = CurrtLastMS * CurrtLastMA / 1000;
- FDEBUG("SetGenSynState:CurrtLastMS[{$}] and CurrtLastMA[{$}] compute CurrtLastMAS[{$}]", CurrtLastMS, CurrtLastMA, CurrtLastMAS);
- m_DoseUnit.m_PostMAS->Update(CurrtLastMAS);
- FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet());
- FDEBUG("SetGenSynState:get Gen Status_5:X-Ray On(XR1) -> RAD_OFF(PR0)");
- if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_OFF))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetGenState(int value) //发生器无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetExpMode(std::string value) //发生器无此设置
- {
- FINFO("Enter SetExpMode...{$} \n",value);
- m_DoseUnit.m_ExpMode->Update(value);
- //add for dcm img hard
- FINFO("SetExpMode:add for dcm img hard");
- FireNotify(m_DoseUnit.m_TubeTargetMaterial->GetKey(), m_DoseUnit.m_TubeTargetMaterial->JSGet());
- FireNotify(m_DoseUnit.m_TubeAngle->GetKey(), m_DoseUnit.m_TubeAngle->JSGet());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetFLFMode(std::string value) //发生器无此动态设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetFrameRate(FLOAT frameRate) //发生器无此动态设置
- {
- m_DoseUnit.m_FrameRate->Update(frameRate);
-
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetRPS(int rps) //发生器无此动态设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetExpEnable() //发生器无此设置
- {
- //HWSendWaittimeCMD("31,",3); //清空错误
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::AlmaxDevice::SetExpDisable() //发生器无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- //Almax发生器特有功能
- //-----------------------------------------------------------------------------
- // ProcessCmd
- //-----------------------------------------------------------------------------
- void nsGEN::AlmaxDevice::ProcessClientData(const char* pData, unsigned long nDataLength, void* lparam)
- {
- AlmaxDevice* pCurGen = (AlmaxDevice*)lparam;
- pCurGen->HWSend(pData, nDataLength);
- }
- void nsGEN::AlmaxDevice::WriteLog(const char* pData, nsSerialGPM::LOG_V2_LEVEL level)
- {
- switch (level)
- {
- case nsSerialGPM::LOG_V2_FATAL:
- case nsSerialGPM::LOG_V2_ERROR:
- FERROR(pData);
- break;
- case nsSerialGPM::LOG_V2_WARNING:
- FWARN(pData);
- break;
- case nsSerialGPM::LOG_V2_DEBUG:
- FDEBUG(pData);
- break;
- case nsSerialGPM::LOG_V2_INFO:
- FINFO(pData);
- break;
- default:
- break;
- }
- }
- RET_STATUS nsGEN::AlmaxDevice::HWSendWaittimeCMD(char* strCommand, int lengh, int headLengh)
- {
- return m_tDelivermodule.ProcessCommand(strCommand, lengh, m_nCMDType_WaitTime, headLengh);
- }
- RET_STATUS nsGEN::AlmaxDevice::HWSendHBCMD(char* strCommand, int lengh, int headLengh)
- {
- return m_tDelivermodule.ProcessCommand(strCommand, lengh, m_nCMDType_HB, headLengh);
- }
- RET_STATUS nsGEN::AlmaxDevice::HWSendWaitACKCMD(char* strCommand, int lengh, int headLengh)
- {
- return m_tDelivermodule.ProcessCommand(strCommand, lengh, m_nCMDType_WaitACK, headLengh);
- }
- RET_STATUS nsGEN::AlmaxDevice::HWSend(const char* strCommand,int lengh, bool reSend, int nTimeOut)
- {
- if (!m_bConnectFlag)
- {
- FERROR("==OUT==: not Connect,[{$:x2}] send failed \n", strCommand[0]);
- return RET_STATUS::RET_FAILED;
- }
- if (!m_SCF) return RET_STATUS::RET_FAILED;
- char checkSum = ComputeCheckSum(strCommand, lengh);
- if (checkSum == 0x00)
- {
- FERROR("HWSend: cmd[{$:x2}] Check Sum failed \n", strCommand[0]);
- return RET_STATUS::RET_FAILED;
- }
- string cmdText{ "" };
- string tempTransmit;
- cmdText += Almax_STX;
- for (int i = 0; i < lengh; i++)
- {
- tempTransmit = std::format("{:02X}", strCommand[i]);
- cmdText += tempTransmit;
- }
- tempTransmit = std::format("{:02X}", checkSum);
- cmdText += tempTransmit;
- cmdText += Almax_ETX;
- if (cmdText.compare(0,2,Almax_CMD_GetStatus,0,2) != 0)
- {
- if (reSend)
- {
- FINFO("==OUT==: [{$}:{$}] reSend \n", cmdText.c_str(), cmdText.length());
- }
- else
- {
- FINFO("==OUT==: [{$}:{$}] \n", cmdText.c_str(), cmdText.length());
- }
- }
- int retLength;
- m_SCF.Lock(msTimeOut_Lock)
- .SendPacket(cmdText.c_str(), cmdText.length(), nTimeOut, retLength);
- //Sleep(nTimeOut);
-
- return RET_STATUS::RET_SUCCEED;
- }
- void nsGEN::AlmaxDevice::FireNotify(string key, int context)
- {
- char szInfo[64] = { 0 };
- sprintf_s(szInfo, "%d", context);
- std::string str = szInfo;
- EventCenter->OnNotify(1, key, str);
- }
- void nsGEN::AlmaxDevice::FireNotify(std::string key, float context)
- {
- char szInfo[16] = { 0 };
- sprintf_s(szInfo,15, "%.2f", context);
- std::string str = szInfo;
- FINFO("FireNotify(float):[{$}][{$}]", szInfo, str.c_str());
- EventCenter->OnNotify(1, key, str);
- }
- void nsGEN::AlmaxDevice::FireNotify(std::string key, std::string context)
- {
- EventCenter->OnNotify(1, key, context);
- }
- void nsGEN::AlmaxDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
- {
- string ErrorCode("Almax_ERR_");
- ErrorCode += std::to_string(Code);
- int level = ContainerExample_REGULATION_LEVEL::REG_ERRO;
- if (Act)
- {
- FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->AddErrorMessage(ErrorCode.c_str(), level, ResInfo);
- }
- else
- {
- FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo);
- }
- }
- void nsGEN::AlmaxDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
- {
- string ErrorCode("Almax_WAR_");
- ErrorCode += std::to_string(Code);
- int level = ContainerExample_REGULATION_LEVEL::REG_WARN;
- if (Act)
- {
- FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->AddWarnMessage(ErrorCode.c_str(), level, ResInfo);
- }
- else
- {
- FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->DelWarnMessage(ErrorCode.c_str(), level, ResInfo);
- }
- }
- void nsGEN::AlmaxDevice::OnCallBack()
- {
- //无 操作
- auto HWNotProcess = [](const char* value, int length) -> void
- {
- //printf("This commands didn't need to process!");
- FINFO("This commands[{$}] didn't need to process", value);
- };
- //校验和错误
- auto HWERROR_1 = [this](char* value, int length) -> void
- {
- char* nextTokenPtr = NULL;
- char* tokenPtr = strtok_s(value, ",", &nextTokenPtr);
- if(tokenPtr != NULL)
- {
- FERROR("== HWERROR_1 == : error CheckSum:[{$}]", tokenPtr);
- }
- else
- {
- FERROR("== HWERROR_1 == : error CheckSum:no csum");
- }
- };
- //命令模式:用于正常操作
- //主机请求固件传输模拟监视器读回当前值
- //主机请求固件发送电源状态
- auto HW22 = [this](char* value, int length) -> void
- {
- m_iHeartBeats = 0;
- int FaultFlag = false;
- int AECReady = false;
- char* nextTokenPtr = NULL;
- char* tokenPtr = strtok_s(value, ",", &nextTokenPtr);
- if (tokenPtr != NULL) //ARG1:XR1 / XR0状态
- {
- int iARG = atoi(tokenPtr);
- #if Almax_22CMDCtrlGenSynState_Flag
- if (iARG)
- {
- if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYON)
- {
- FDEBUG("Request Status_1:already X-Ray On(XR1)");
- }
- else if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_READY)
- {
- FDEBUG("Request Status_1:RAD_READY(PR2) -> X-Ray On(XR1)");
- if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYON))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else
- {
- FWARN("Request Status_1:Wrong state change:{$} -try to> X-Ray On(XR1)", m_DoseUnit.m_GenSynState->Get());
- if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYON))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- }
- else
- {
- if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYON)
- {
- FDEBUG("Request Status_1:get post KV MA MS MAS");
- //HWSendWaittimeCMD("54,3");
- m_iCompPostMAS = 10;
- HWSendWaittimeCMD("60,",3);
- HWSendWaittimeCMD("61,",3);
- HWSendWaittimeCMD("65,",3);
-
- FDEBUG("Request Status_1:X-Ray On(XR1) -> Off(XR0)");
- if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF)
- {
- FDEBUG("Request Status_1:X-Ray Off(XR0) -> Off(PR2)");
- if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else
- FDEBUG("Request Status_1:already X-Ray Off(XR0)");
- }
- #else
- FDEBUG("Request Status_1:Unit High Voltage output Status[{$}]", iARG);
- #endif // Almax_22CMDCtrlGenSynState_Flag
- }
- else return;
- tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
- if (tokenPtr != NULL) //ARG2:安全开关状态
- {
- int iARG = atoi(tokenPtr);
- if (iARG == 0)
- {
- FDEBUG("Request Status_2:Safety interlock is Open; not ok to make high voltage");
- FaultFlag = true;
- }
- else
- {
- FDEBUG("Request Status_2:Safety interlock is closed; ok to make high voltage");
- }
- }
- else return;
- tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
- if (tokenPtr != NULL) //ARG3:故障状况
- {
- int iARG = atoi(tokenPtr);
- if (iARG == 1)
- {
- FDEBUG("Request Status_3:There are 1 or more active faults,not make high voltage");
- FaultFlag = true;
- }
- else
- {
- FDEBUG("Request Status_3:no active faults");
- }
- }
- else return;
- tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
- if (tokenPtr != NULL) //ARG4:PR1 / PR0状态
- {
- int iARG = atoi(tokenPtr);
- #if Almax_22CMDCtrlGenSynState_Flag
- if (iARG == 1)
- {
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- FDEBUG("Request Status_4:AEC mod ignore ARG13");
- AECReady = true;
- }
- //加快查询时间
- if (m_iLoopTime != Almax_LoopExpHBTime)
- {
- FDEBUG("quicken loopTime[{$}]->[{$}]", m_iLoopTime.load(), Almax_LoopExpHBTime);
- m_iLoopTime = Almax_LoopExpHBTime;
- }
- if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_PREPARE ||
- m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_READY ||
- m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYON ||
- m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF)
- {
- FDEBUG("Request Status_4:GEN is already in Prep state(PR1)");
- }
- else if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_OFF)
- {
- FDEBUG("Request Status_4:RAD_OFF(PR0) -> RAD_PREPARE(PR1)");
- if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else
- {
- FWARN("Request Status_4:Wrong state change:{$} -> RAD_PREPARE(PR1)", m_DoseUnit.m_GenSynState->Get());
- if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_EXP &&
- m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_ERROR)
- {
- //更新发生器状态并上报,否则会影响工作流 FrameEnable -> FrameReady 的转变
- FDEBUG("Request Status_4:GENSTATE {$} -> STATUS_EXP", m_DoseUnit.m_GenState->JSGet());
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- }
- else
- {
- AECReady = false;
-
- //回复查询时间
- if (m_iLoopTime == Almax_LoopExpHBTime)
- {
- if ((int)m_GenConfig["loopTime"] >= 100)
- {
- m_iLoopTime = (int)m_GenConfig["loopTime"];
- }
- else
- m_iLoopTime = Almax_LoopDefHBTime;
- FDEBUG("reduction loopTime[{$}]->[{$}]", Almax_LoopExpHBTime,m_iLoopTime.load());
- }
- FDEBUG("Request Status_4:GEN is not in Prep state(PR0)");
- if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_PREPARE)
- {
- if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_OFF))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_STANDBY &&
- m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_ERROR)
- {
- if (m_bExpEnable)
- {
- FDEBUG("Request Status_4:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- else if(m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_SLEEP)
- {
- FDEBUG("Request Status_4:GENSTATE {$} -> STATUS_SLEEP", m_DoseUnit.m_GenState->JSGet());
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SLEEP);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- }
- }
- #else
- FDEBUG("Request Status_4:Unit Prep state[{$}]", iARG);
- if (iARG == 1)
- {
- //加快查询时间
- if (m_iLoopTime != Almax_LoopExpHBTime)
- {
- FDEBUG("quicken loopTime[{$}]->[{$}]", m_iLoopTime.load(), Almax_LoopExpHBTime);
- m_iLoopTime = Almax_LoopExpHBTime;
- }
- if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_EXP &&
- m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_ERROR)
- {
- //更新发生器状态并上报,否则会影响工作流 FrameEnable -> FrameReady 的转变
- FDEBUG("Request Status_4:GENSTATE {$} -> STATUS_EXP", m_DoseUnit.m_GenState->JSGet());
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- }
- else
- {
- //回复查询时间
- if (m_iLoopTime == Almax_LoopExpHBTime)
- {
- if ((int)m_GenConfig["loopTime"] >= 100)
- {
- m_iLoopTime = (int)m_GenConfig["loopTime"];
- }
- else
- m_iLoopTime = Almax_LoopDefHBTime;
- FDEBUG("reduction loopTime[{$}]->[{$}]", Almax_LoopExpHBTime, m_iLoopTime.load());
- }
- FDEBUG("Request Status_4:GEN turn to Prep state(PR0)");
- if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_OFF))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_STANDBY &&
- m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_ERROR)
- {
- if (m_bExpEnable)
- {
- FDEBUG("Request Status_4:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- else if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_SLEEP)
- {
- FDEBUG("Request Status_4:GENSTATE {$} -> STATUS_SLEEP", m_DoseUnit.m_GenState->JSGet());
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SLEEP);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- }
- }
- #endif // Almax_22CMDCtrlGenSynState_Flag
- }
- else return;
- tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
- if (tokenPtr != NULL) //ARG5:Xray Condition
- {
- int iflag = atoi(tokenPtr);
- if(iflag)
- FDEBUG("Request Status_5:Unit is in Xray state (Ready to make X-Ray shot)");
- else
- FDEBUG("Request Status_5:Unit is not in Xray state");
- }
- else return;
- tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG6
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG7
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG8
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG9
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG10
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG11
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG12
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
- if (tokenPtr != NULL) //ARG13:准备状态(PR2)
- {
- int iARG = atoi(tokenPtr);
- #if Almax_22CMDCtrlGenSynState_Flag
- if (iARG == 1)
- {
- if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_READY ||
- m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYON ||
- m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF)
- {
- FDEBUG("Request Status_13:GEN is already to make X-Rays(PR2)");
- }
- else if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_PREPARE)
- {
- FDEBUG("Request Status_13:PREPARE or XRAYOFF(PR1 or XR0) -> RAD_READY(PR2)");
- if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else
- {
- FWARN("Request Status_13:Wrong state change:{$} -> RAD_READY(PR2)", m_DoseUnit.m_GenSynState->Get());
- if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- }
- else
- {
- if (AECReady)
- {
- FDEBUG("Request Status_13:GEN is in AEC_ready(temp PR0)");
- }
- else
- {
- FDEBUG("Request Status_13:GEN is not finish ready(PR0)");
- }
- if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_READY && !AECReady)
- {
- if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
-
- }
- #else
- FDEBUG("Request Status_13:Unit Ready Status[{$}]", iARG);
- #endif // Almax_22CMDCtrlGenSynState_Flag
- }
- else return;
- tokenPtr = strtok_s(NULL, ",",&nextTokenPtr); //ARG14
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
- if (tokenPtr != NULL) //ARG15:校准模式
- {
- int iARG = atoi(tokenPtr);
- if (iARG == 1) //该装置处于校准模式
- {
- FDEBUG("Request Status_15:GEN is in calibration mode");
- }
- else
- {
- FDEBUG("Request Status_15:GEN is not in calibration mode");
- }
- }
- else return;
- tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG16
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG17
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG18
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG19
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG20
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG21
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG22
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",", &nextTokenPtr); //ARG23
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
- if (tokenPtr != NULL) //ARG24:负载持续率可限制
- {
- int iARG = atoi(tokenPtr);
- if (iARG == 1) //此位表示设备如果过载保护也允许新的曝光周期开始
- {
- FDEBUG("Request Status_24:Ok to enter Prep");
- if (!m_bExpEnable)
- {
- m_bExpEnable = true;
- if (m_DoseUnit.m_GenState->Get() == nsGEN::AttrKey::GENERATOR_STATUS_SLEEP)
- {
- FireWarnMessage(false, 2, "Almax generator need some time to rest(about 20 Sec)");
- if (FaultFlag)
- {
- FDEBUG("Request Status_24 STATUS_SLEEP -> STATUS_ERROR");
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- else
- {
- FDEBUG("Request Status_24 STATUS_SLEEP -> STATUS_STANDBY");
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- }
- }
- }
- else
- {
- FDEBUG("Request Status_24:Not ready to enter prep");
- if (m_bExpEnable)
- {
- FireWarnMessage(true, 2, "Almax generator need some time to rest(about 20 Sec)");
- m_bExpEnable = false;
- if (m_DoseUnit.m_GenSynState->Get() < nsGEN::AttrKey::GENERATOR_RAD_PREPARE && !FaultFlag)
- {
- FDEBUG("Request Status_24:GENSTATE {$} -> STATUS_SLEEP", m_DoseUnit.m_GenState->JSGet());
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SLEEP);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- }
- }
- }
- else return;
- tokenPtr = strtok_s(NULL, ",",&nextTokenPtr); //ARG25
- if (tokenPtr == NULL) return;
- tokenPtr = strtok_s(NULL, ",",&nextTokenPtr);
- if (tokenPtr != NULL) //ARG26:HSS速度
- {
- int iARG = atoi(tokenPtr);
- if (iARG == 1) //X射线管转子转速设定
- {
- FDEBUG("Request Status_26:High Speed");
- }
- else
- {
- FDEBUG("Request Status_26:Low Speed");
- }
- }
- else return;
- };
-
- arFrame.clear();
- //命令模式:用于正常操作
- arFrame["22"] = tFrameMapItem(HW22);
- arFrame["1"] = tFrameMapItem(HWERROR_1);//命令格式:校验和错误
- }
- bool nsGEN::AlmaxDevice::ReConnect()
- {
- FINFO("Enter PSG_reConnect");
- m_SCF.Disconnect();
- if (!pIODriver)
- {
- FINFO("PSG_reConnect:Driver null");
- }
- else if (pIODriver->ReConnection(m_SCF))
- {
- FireErrorMessage(false, 1, "lost Connect");
- m_bConnectFlag = true;
- FINFO("PSG_reConnect success");
- return true;
- }
- else
- {
- FINFO("PSG_reConnect failed");
- }
- return false;
- }
- bool nsGEN::AlmaxDevice::StartHardwareStatusThread()
- {
- FINFO("enter Start HardwareStatus Thread ");
- if (m_pHardwareStatusThread == NULL)
- {
- DWORD m_HardwareStatusID;
- m_pHardwareStatusThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
- if (m_pHardwareStatusThread == NULL)
- {
- FERROR("Start HardwareStatus Thread Failed");
- return false;
- }
- }
- return true;
- }
- DWORD nsGEN::AlmaxDevice::HardwareStatusThread(LPVOID pParam)
- {
- AlmaxDevice* pCurGen = (AlmaxDevice*)pParam;
- if (pCurGen == NULL)
- {
- return false;
- }
- HeartBeatFlag = true;
- FINFO("HardwareStatusThread start");
- if ((int)pCurGen->m_GenConfig["loopTime"] >= 100)
- {
- pCurGen->m_iLoopTime = (int)pCurGen->m_GenConfig["loopTime"];
- }
- FINFO("loopTime = {$}", pCurGen->m_iLoopTime.load());
- int currtTime = pCurGen->m_iLoopTime;
- while (m_bExtraFlag)
- {
- if (!(pCurGen->m_bConnectFlag))
- {
- FINFO("AlmaxGEN: not Connect,try to reconnect \n");
- pCurGen->FireErrorMessage(true, 1, "lost Connect");
- pCurGen->ReConnect();
- Sleep(20000);
- continue;
- }
- FDEBUG("currtloopTime = {$}", pCurGen->m_iLoopTime.load());
- currtTime = pCurGen->m_iLoopTime;
- Sleep(currtTime);
- //心跳包统计加1
- pCurGen->m_iHeartBeats++;
- int tempHeartBeat = pCurGen->m_iHeartBeats;
- if (tempHeartBeat > 10) //无返回信息认为连接断开
- {
- pCurGen->m_iHeartBeats = 0;
- FINFO("AlmaxGEN: lost Connect \n");
- pCurGen->m_bConnectFlag = false;
- continue;
- }
- //发送心跳
- if (currtTime == Almax_LoopExpHBTime)
- {
- pCurGen->HWSendHBCMD("22,", 3);
- }
- else
- {
- if(!(pCurGen->m_bExpEnable))
- pCurGen->HWSendHBCMD("22,", 3);
- else
- pCurGen->HWSendHBCMD("99,", 3);
- }
- pCurGen->HWSendHBCMD("77,",3); //轮询发生器温度信息
- }
- FINFO("HardwareStatusThread stop");
- return true;
- }
- //-----------------------------------------------------------------------------
- // AlmaxDriver
- //-----------------------------------------------------------------------------
- nsGEN::AlmaxDriver::AlmaxDriver()
- {
- m_bDemoMode = false;
- m_bDemoConnected = false;
- m_pAttribute.reset(new ResDataObject());
- m_pDescription.reset(new ResDataObject());
- }
- nsGEN::AlmaxDriver::~AlmaxDriver()
- {
- Close();
- gLogger = nullptr;
- }
- void nsGEN::AlmaxDriver::Prepare()
- {
- ResDataObject r_config;
- if (r_config.loadFile(m_ConfigFileName.c_str()))
- {
- if ((int)r_config["CONFIGURATION"]["logEnable"] == 1)
- {
- string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
- //Log4CPP::ThreadContext::Map::Set("LogFileName", "GEN.ContainerExample");
- Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.ContainerExample");
- auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
- gLogger = Log4CPP::LogManager::GetLogger("GEN.ContainerExample");
- }
- m_bDemoMode = (atoi)(((string)r_config["CONFIGURATION"]["IsDemo"]).c_str());
- ResDataObject Connection = r_config["CONFIGURATION"]["connections"][0];
- if ((string)Connection["type"] == "COM")
- {
- m_SCFDllName = COM_SCFDllName;
- }
- else
- {
- m_SCFDllName = TCP_SCFDllName;
- }
- }
- super::Prepare();
- }
- std::string nsGEN::AlmaxDriver::DriverProbe()
- {
- ResDataObject r_config, HardwareInfo;
- if (r_config.loadFile(m_ConfigFileName.c_str()))
- {
- HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
- HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
- HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
- HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
- HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
- }
- else
- {
- HardwareInfo.add("MajorID", "Generator");
- HardwareInfo.add("MinorID", "Dr");
- HardwareInfo.add("VendorID", "Almax");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Drv");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- bool nsGEN::AlmaxDriver::ReConnection(nsSCF::SCF& DevSCF)
- {
- super::Disconnect();
- FINFO("ReConnection:SCF Disconnect");
- ResDataObject r_config;
- if (!r_config.loadFile(m_ConfigFileName.c_str()))
- {
- FINFO("ReConnection:open configFile failed");
- return SCF_ERR::SCF_OPEN_FAILED;
- }
- ResDataObject Connection = r_config["CONFIGURATION"]["connections"][0];
- FINFO("ReConnection:{$} \n", Connection.encode());
- auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::AlmaxDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
- if (erCode == SCF_ERR::SCF_SUCCEED)
- {
- Sleep(1000);
- auto rc = super::Connect();
- if (!rc)
- {
- FINFO("ReConnection:super Connect failed");
- }
- else
- {
- DevSCF = m_SCF;
- return true;
- }
- }
- else
- {
- FINFO("ReConnection failed");
- }
- return false;
- }
- bool nsGEN::AlmaxDriver::Connect()
- {
- if (m_bDemoMode)
- {
- FINFO("connections:DEMO \n");
- m_bDemoConnected = true;
- return true; //return SCF_ERR::SCF_SUCCEED;
- }
- ResDataObject r_config;
- if (!r_config.loadFile(m_ConfigFileName.c_str()))
- return false; //return SCF_ERR::SCF_OPEN_FAILED;
- ResDataObject Connection = r_config["CONFIGURATION"]["connections"][0];
- //printf("connections:%s \n", Connection.encode());
- FINFO("connections:{$} \n", Connection.encode());
- auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::AlmaxDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
- if (erCode != SCF_ERR::SCF_SUCCEED)
- return false; //return erCode;
- auto rc = super::Connect();
- if (!rc)
- return false; //return 0;
- //return (erCode == SCF_ERR::SCF_SUCCEED);
- return true; //return SCF_ERR::SCF_SUCCEED;
- }
- auto nsGEN::AlmaxDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
- {
- if (m_bDemoMode)
- {
- if (!m_bDemoConnected)
- {
- FERROR("CreateDevice:m_bDemoConnected is false \n");
- return nullptr;
- }
- auto dev = std::unique_ptr <IODevice>(new IODevice(new DemoDevice(EventCenter)));
- return dev;
- }
- if (!m_SCF.isConnected())
- {
- FERROR("CreateDevice:m_SCF is not Connected \n");
- return nullptr;
- }
- auto dev = std::unique_ptr <IODevice>(new IODevice(new AlmaxDevice(EventCenter, m_SCF, m_ConfigFileName)));
- return dev;
- }
- void nsGEN::AlmaxDriver::FireNotify(int code, std::string key, std::string content)
- {
- EventCenter->OnNotify(code, key, content);
- }
- bool nsGEN::AlmaxDriver::isConnected() const
- {
- if (m_bDemoMode)
- return m_bDemoConnected;
- else
- {
- if (super::isConnected())
- {
- return true;
- }
- else
- {
- if(HeartBeatFlag) //避过平台层的断连检测
- return true;
- else
- return false;
- }
- }
- }
- std::string nsGEN::AlmaxDriver::GetResource()
- {
- ResDataObject r_config, temp;
- if (!temp.loadFile(m_ConfigFileName.c_str()))
- {
- return "";
- }
- m_ConfigAll = temp;
- r_config = temp["CONFIGURATION"];
- m_Configurations = r_config;
- ResDataObject DescriptionTemp;
- ResDataObject DescriptionSend;
- ResDataObject m_DescriptionSend;
- ResDataObject ListTemp;
- string strTemp = ""; //用于读取字符串配置信息
- string strIndex = ""; //用于读取配置信息中的List项
- int nTemp = -1; //用于读取整型配置信息
- char sstream[10] = { 0 }; //用于转换值
- string strValue = ""; //用于存储配置的值
- string strType = ""; //用于存储配置的类型 int/float/string...
- /***
- * 1. 通过循环,将所有配置项写到pDeviceConfig
- * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
- ***/
- try
- {
- //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
- int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
- m_pAttribute->clear();
- m_pDescription->clear();
- for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
- {
- DescriptionTemp.clear();
- DescriptionSend.clear();
- ListTemp.clear();
- //AttributeType
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
- DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
- DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
- strType = strTemp; //记录配置项的类型
- //AttributeKey
- //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
- nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
- GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
- //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
- //2. 赋值
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- if ("int" == strType)
- {
- (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
- }
- else if ("float" == strType)
- {
- (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
- }
- else //其它先按string类型处理
- {
- (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
- }
- //printf("********************************outkey =%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
- //AttributeAccess
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
- DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
- /*
- //AttributeRangeMin
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
- }
- //AttributeRangeMax
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
- }
- */
- //AttributeList
- nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
- if (nTemp > 0) //ListNum不大于0时说明不需要list配置
- {
- for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
- auto temKey = std::to_string(nListIndex);
- ListTemp.add(temKey.c_str(), strTemp.c_str());
- }
- DescriptionTemp.add(ConfKey::CcosList, ListTemp);
- DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
- }
- //AttributeRequired
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
- DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
- //AttributeDefaultValue
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
- }
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
- m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("Get config error: {$}", e.what());
- return "";
- }
- ResDataObject resDeviceResource;
- resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
- resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
- ResDataObject DescriptionTempEx;
- DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
- m_DeviceConfig.clear();
- m_DeviceConfig = DescriptionTempEx;
- FDEBUG("local ************* get resource over {$}", DescriptionTempEx.encode());
- //printf("local ************* get resource over %s \n", DescriptionTempEx.encode());
- resDeviceResource.clear();
- resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
- resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
- DescriptionTempEx.clear();
- DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
- m_DeviceConfigSend.clear();
- m_DeviceConfigSend = DescriptionTempEx;
- string res = m_DeviceConfigSend.encode();
- //printf("%s", res.c_str());
- FDEBUG("get resource over {$}", DescriptionTempEx.encode());
- //("************* get resource over %s \n", DescriptionTempEx.encode());
- return res;
- }
- std::string nsGEN::AlmaxDriver::DeviceProbe()
- {
- ResDataObject r_config, HardwareInfo;
- if (r_config.loadFile(m_ConfigFileName.c_str()))
- {
- HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
- HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
- HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
- HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
- HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
- }
- else
- {
- HardwareInfo.add("MajorID", "Generator");
- HardwareInfo.add("MinorID", "Dr");
- HardwareInfo.add("VendorID", "Almax");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Dev");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- void nsGEN::AlmaxDriver::Disconnect()
- {
- super::Disconnect();
- m_SCF.Disconnect();
- m_bDemoConnected = false;
- Close();
- gLogger = nullptr;
- }
- void nsGEN::AlmaxDriver::Dequeue(const char* Packet, DWORD Length)
- {
- DecodeFrame(Packet, Length);
- }
- PACKET_RET nsGEN::AlmaxDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
- {
- #if 0
- if (nLength > 1)
- {
- FERROR("receive data_len[{$}]", nLength);
- for (int i = 0; i < nLength; i++)
- {
- if (i != nLength - 1)
- {
- FERROR("receive data[{$}][{$}]", i, RecData[i]);
- }
- else
- {
- FERROR("receive data[{$}][{$}]", i, RecData[i]);
- }
- }
- }
- #endif
- bool bHasHead = false;
- if (nLength < 1)
- {
- PacketLength = 0;
- FERROR("nLength too small, nLength=={$}", nLength);
- return PACKET_USELESS;
- }
- else if(nLength > Almax_Com_NormalLen)
- {
- PacketLength = nLength;
- FERROR("nLength too big, nLength=={$}", nLength);
- return PACKET_USELESS;
- }
- for (DWORD i = 0; i < nLength; i++)
- {
- //寻找包头
- if (RecData[i]== Almax_STX)
- {
- if (i!=0) //包头之前的数据格式不对,全部扔掉
- {
- PacketLength = i;
- char strtemp[Almax_Com_NormalLen] = { 0 };
- memcpy(strtemp, RecData, PacketLength);
- FERROR("==IN unknown format data ==:[{$}],UselessDataLength={$},TotalLength={$} \n", strtemp, PacketLength, nLength);
- return PACKET_USELESS;
- }
- else
- {
- bHasHead = true;
- }
- }
- //寻找包尾
- if (RecData[i] == Almax_ETX)
- {
- if(bHasHead)
- {
- if (i >= 4) //正常指令
- {
- PacketLength = i + 1; //+1 because ETX
- char strtemp[Almax_Com_NormalLen] = { 0 };
- memcpy(strtemp, RecData + 1, i - 1); //只有数据+CSUM,+1 排除 STX ,-1 排除 ETX。
- if (!((strtemp[0] == '9' && strtemp[1] == '9') || (strtemp[0] == '7' && strtemp[1] == '7')))
- {
- FINFO("==IN==:[{$}]", strtemp);
- AlmaxDevice::m_tDelivermodule.CheckReceive(strtemp,2);
- }
- return PACKET_ISPACKET;
- }
- else //空指令
- {
- PacketLength = i + 1;
- char strtemp[Almax_Com_NormalLen] = { 0 };
- memcpy(strtemp, RecData, PacketLength); //空数据,格式正确但无有效命令。
- FERROR("==IN uselss data==:[{$}] \n", strtemp);
- return PACKET_USELESS;
- }
- }
- else //有包尾但无包头
- {
- PacketLength = i + 1;
- char strtemp[Almax_Com_NormalLen] = { 0 };
- memcpy(strtemp, RecData, PacketLength);
- FERROR("==IN no head data ==:[{$}],NoHeadDataLength={$},TotalLength={$} \n", strtemp, PacketLength, nLength);
- return PACKET_USELESS;
- }
- }
- }
- if (bHasHead)
- {
- PacketLength = 0;
- }
- return PACKET_NOPACKET;
- }
- bool nsGEN::AlmaxDriver::GetDeviceConfig(std::string& Cfg)
- {
- Cfg = m_DeviceConfigSend.encode();
- printf("GetDeviceConfig over , %s", Cfg.c_str());
- return true;
- }
- bool nsGEN::AlmaxDriver::SetDeviceConfig(std::string Cfg)
- {
- FINFO("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
- printf("\n--Func-- SetDeviceConfig %s\n", Cfg.c_str());
- ResDataObject DeviceConfig;
- DeviceConfig.decode(Cfg.c_str());
- ResDataObject DescriptionTempEx;
- DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
- FDEBUG("Attribute:{$}", DescriptionTempEx.encode());
- bool bSaveFile = false; //true:重新保存配置文件
- string strAccess = "";
- for (int i = 0; i < DescriptionTempEx.size(); i++)
- {
- string strKey = DescriptionTempEx.GetKey(i);
- FINFO("{$}", strKey.c_str());
- printf("%s\n", strKey.c_str());
- try
- {
- if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
- {
- strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
- if ("RW" == strAccess)
- {
- //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
- //1. 修改内存中的值,用于给上层发消息
- (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
- //2. 拿到Innerkey
- int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
- FINFO("nConfigInfoCount {$}", nConfigInfoCount);
- string strTemp = ""; //存储AttributeKey
- for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- if (strTemp == strKey)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
- break;
- }
- }
- //3. 修改配置文件中的值
- if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
- {
- FDEBUG("SetDeviceConfigValue over");
- bSaveFile = true;
- }
- }
- else
- {
- FINFO("{$} is not a RW configuration item", strKey.c_str());
- }
- }
- else
- {
- FINFO("without this attribute {$}", strKey.c_str());
- }
- }
- catch (ResDataObjectExption& e)
- {
- printf("\nSetDriverConfig crashed: %s\n", e.what());
- FERROR("SetDriverConfig crashed: {$}", e.what());
- return false;
- }
- }
- if (bSaveFile)
- {
- //3. 重新保存配置文件
- SaveConfigFile(true);
- }
- return true;
- }
- bool nsGEN::AlmaxDriver::SaveConfigFile(bool bSendNotify)
- {
- m_ConfigAll["CONFIGURATION"] = m_Configurations;
- bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
- FINFO("SaveConfigFile over {$}", bRt);
- return true;
- }
- bool nsGEN::AlmaxDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
- {
- strValue = "";
- string strTemp = pInnerKey;
- if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
- {
- int pos = 0;
- ResDataObject resTemp = config;
- while ((pos = strTemp.find_first_of(',')) != string::npos)
- {
- string Key = strTemp.substr(0, pos);
- string TempValue = resTemp[Key.c_str()].encode();
- // printf("-TempValue=== %s", TempValue.c_str());
- resTemp.clear();
- resTemp.decode(TempValue.c_str());
- strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
- //printf("-************--%s", strTemp.c_str());
- }
- if (strTemp != "")
- {
- strValue = (string)resTemp[strTemp.c_str()];
- }
- else
- {
- strValue = (string)resTemp;
- }
- }
- //printf("------------%s", strValue.c_str());
- return true;
- }
- bool nsGEN::AlmaxDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
- {
- string strTemp = pInnerKey;
- FDEBUG("Begin to change {$} item value to {$}", pInnerKey, szValue);
- printf("\nbbbbbbbbbbbbbbBegin to change {%s} item value to {%s}\n", pInnerKey, szValue);
- if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
- {
- try {
- int pos = 0;
- ResDataObject* resTemp = &config;
- while ((pos = strTemp.find_first_of(',')) != string::npos)
- {
- string Key = strTemp.substr(0, pos);
- resTemp = &(*resTemp)[Key.c_str()];
- strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
- }
- if (strTemp != "")
- {
- //if ((strTemp.compare("WSTable") == 0) ||
- // (strTemp.compare("WSWall") == 0) ||
- // (strTemp.compare("WSFree") == 0) ||
- // (strTemp.compare("WSTomo") == 0) ||
- // (strTemp.compare("WSConventional") == 0)
- // )
- //{
- // int sum = (*szValue) + 1;
- // (*resTemp)[strTemp.c_str()] = (char*)(&sum);
- //}
- //else
- // (*resTemp)[strTemp.c_str()] = szValue;
- (*resTemp)[strTemp.c_str()] = szValue;
- }
- else
- {
- *resTemp = szValue;
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("SetDriverConfigvalue crashed: {$}", e.what());
- return false;
- }
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- // GetIODriver & CreateIODriver
- //-----------------------------------------------------------------------------
- static nsGEN::AlmaxDriver gIODriver;
- extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
- {
- pIODriver = new nsGEN::AlmaxDriver();
- return pIODriver;
- }
|