123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505 |
- // CCOS.Dev.GEN.SINOmini.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include "stdafx.h"
- #include <assert.h>
- #include <functional>
- using namespace std::placeholders;
- //#include "logger.temp.h"
- #include "CCOS.Dev.Generator.SINOmini.h"
- #include "Helper.JSON.hpp"
- 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”混合不安全
- //设置对应通信接口库
- #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
- /*
- #数据命令格式
- 字节编号 数据 数据含义 备注
- 1 STX 帧头 WS(程序)的帧头为:0xA5,MU(设备)的帧头为:0xCF
- 2 TYPE 数据类型 0x00: 主动发出的数据,0x01: 反馈数据,表示收到命令并反馈数据
- 3 ID 命令ID(CMD)
- 4 LEN 数据总长度(LEN)
- 5~n DATA… 参数数据
- n+1 CRC 异或取反校验(CRC)
- n+2 ETX 帧尾 WS的帧尾为:0x5A,MU的帧尾为:0xFC
- #应答命令格式
- 字节编号 数据 数据含义 备注
- 1 STX 帧头 WS的帧头为:0xA5,MU的帧头为:0xCF
- 2 TYPE 数据类型 0x02: 应答命令
- 3 ID 命令ID(CMD)
- 4 LEN 数据总长度(LEN)
- 5 Stauts 状态 0x00: 数据成功接收并设置, 0x01: 数据不正确,未成功设置
- 6 CRC 异或取反校验(CRC)
- 7 ETX 帧尾 WS的帧尾为:0x5A, MU的帧尾为:0xFC
- */
- //设置相关常量
- static const int msTimeOut_Lock = 500;
- Log4CPP::Logger* gLogger = nullptr;
- //指令操作关联结构
- struct tFrameMapping
- {
- static const int MaxLen = 5; //前缀不能超超过5个字符
- using cbFun = std::function <void(char*, int)>;
- char strHead[MaxLen];
- int NbOfCharOfHead;
- cbFun fun;
- tFrameMapping(char* str, int len, cbFun f)
- {
- assert(len < MaxLen); //len最大只能是4
- for (int i = 0; i < len; i++) //给strHead赋值
- strHead[i] = str[i];
- NbOfCharOfHead = len + 1;
- fun = f;
- }
- tFrameMapping(char str, cbFun f)
- {
- strHead[0] = str;
- NbOfCharOfHead = 1;
- fun = f;
- }
- };
- //响应操作对照表
- static std::list <tFrameMapping> arFrame;
- //生成命令校验和:多项式POLY 0x31,初始值INIT 0x00,结果亦或值XOROU 0x00,输入数据反转REFIN YES,输出数据反转REFOUT YES
- char crc8_MAXIM(char* data, int len)
- {
- uint8_t crc, i;
- crc = 0x00;
- while (len--)
- {
- crc ^= *data++;
- for (i = 0; i < 8; i++)
- {
- if (crc & 0x01)
- {
- crc = (crc >> 1) ^ 0x8c;
- }
- else crc >>= 1;
- }
- }
- return crc;
- }
- //查找响应操作对照表执行对应操作
- static bool DecodeFrame(const char* strFrame, int length)
- {
- auto pr = [strFrame, length](const tFrameMapping& Item)
- {
- FDEBUG("DecodeFrame[{$}][{$}]", (UINT8)strFrame[2], (UINT8)Item.strHead[0]);
- for (int i = 0; i < Item.NbOfCharOfHead; i++)
- {
- if ((UINT8)strFrame[i+1] != (UINT8)Item.strHead[i])
- {
- return false;
- }
- }
- return true;
- };
- auto found = std::find_if(arFrame.begin(), arFrame.end(), pr);//此处pr用来在arFrame中找到对于的包头
- if (found == arFrame.end())
- {
- return false;
- }
- const auto& Item = *found;
- auto pc = strFrame;
- char data[SINOmini_Com_NormalLen] = { 0 };
- //memcpy(data, strFrame + Item.NbOfCharOfHead + 3, length - Item.NbOfCharOfHead - 3);
- memcpy(data, strFrame, length);
- Item.fun(data, length - Item.NbOfCharOfHead);//第二个参数 不重要
- return true;
- }
- //-----------------------------------------------------------------------------
- // SINOminiDevice
- //-----------------------------------------------------------------------------
- int nsGEN::SINOminiDevice::m_iLoopTime = 1000;
- nsGEN::SINOminiDevice::SINOminiDevice(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"];
- TransJsonText(m_GenConfig);
- m_pHardwareStatusThread = NULL;
- m_pAECProcessThread = NULL;
- m_AECFlag = false;
- m_bExpEnable = false;
- m_iHeartBeats = 0;
- m_bConnectFlag = true;
- m_pMechDev = nullptr;
- m_pCollDev = nullptr;
- string version;
- if(GetVersion(version,m_GenConfig))
- 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(0.0, 20.0, 36, 1.0));
- m_DoseUnit.m_MA.reset(new MAMould(0, 0.0, 200.0, 0.1));
- m_DoseUnit.m_MS.reset(new MSMould(0, 20.0, 12000.0, 0.01));
- m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.0, 630.0, 1.0));
- m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_AEC_2P, 1));
- m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
- m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_TYPE::FOCUS_SMALL, 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(7, -10, 10, 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_MAX, 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(AttrKey::EXPMODE_TYPE::Single));
- m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 16, 1));
- m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
- m_DoseUnit.m_BatteryChargeState.reset(new BATTERYCHARGSTATEMould(0, 0, 1, 1));
- //m_DoseUnit.m_EXAMMode.reset(new EXAMMODEMould(EXAMMODE_TYPE::MANUAL));
- //实际曝光参数值
- m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 0.0, 40.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, 20.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));
-
- //配置响应操作对照表 供发生器回传的数据触发相应的操作
- OnCallBack();
- //将发生器可以对外提供的指令注册集进行补充
- Register();
- //重置发生器
- Reset();
- Sleep(500);
- //以下进行默认设置,需要注意默认值是否正确
- //刷新数据
- RefreshData();
-
- //启动硬件转状态查询进程
- StartHardwareStatusThread();
- }
- nsGEN::SINOminiDevice::~SINOminiDevice()
- {
- FINFO("\n===============log end ===================\n");
- //ReleaseLogger();
- if (m_pHardwareStatusThread != NULL)
- {
- DWORD dwExitCode = 0;
- GetExitCodeThread(m_pHardwareStatusThread, &dwExitCode);
- if (STILL_ACTIVE != dwExitCode)
- {
- TerminateThread(m_pHardwareStatusThread, 0);
- }
- m_pHardwareStatusThread = NULL;
- }
- }
- std::string nsGEN::SINOminiDevice::GetGUID() const
- {
- FINFO("===============GetGUID : {$} ===================\n", GeneratorUnitType);
- return GeneratorUnitType;
- }
- void nsGEN::SINOminiDevice::Register()
- {
- auto Disp = &Dispatch;
- superGen::Register(Disp);
- superGen::RegisterRAD(Disp);
- superGen::RegisterAEC(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 a, auto&)
- {
- return Clear_DAP();
- };
- Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
- auto fun_GetValue_DAP = [this](auto a, auto& b)
- {
- float value = 0;
- RET_STATUS ret = GetValue_DAP(value);
- b = ToJSON(value);
- return ret;
- };
- Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
- #if 0
- auto fun_StartMove = [this](auto a,auto& b)
- {
- return StartMove();
- };
- Disp->Action.Push("StartMove", fun_StartMove);
- auto fun_EndMove = [this](auto a, auto& b)
- {
- return EndMove();
- };
- Disp->Action.Push("EndMove", fun_EndMove);
- #endif // 0
- }
- RET_STATUS nsGEN::SINOminiDevice::SetAPRMaMmo(int nKV, float fMAS, int nFO, int nET, int nDensity, int nThickness, int nPress, int nFilter, int nSensor, int nGrid)
- {
- FDEBUG("SetAPRMaMmo:nKV[{$}],MAS[{$}],FO[{$}],ET[{$}],Density[{$}],Thickness[{$}],Press[{$}],Filter[{$}],Sensor[{$}],Grid[{$}] ", nKV, fMAS, nFO, nET, nDensity, nThickness, nPress, nFilter, nSensor, nGrid);
- SINOminiCommand strCmd(SINOmini_Parameter, EM_Param000);
- strCmd.SetAt(4, fMAS);
- strCmd.SetAt(5, nKV);
- strCmd.SetAt(6, nDensity);
- if (-1 == nThickness) //压迫厚度
- {
- if (m_pMechDev)
- {
- nThickness = m_pMechDev->GetMammo_Thickness();
- }
- else
- nThickness = 0;
- }
- strCmd.SetAt(8, nThickness);
- if (-1 == nPress) //压力值
- {
- if (m_pMechDev)
- {
- nPress = m_pMechDev->GetMammo_PressureValue();
- }
- else
- nPress = 0;
- }
- strCmd.SetAt(9, nPress);
- char cData10 = 0;
- cData10 = ((nSensor / 0x11) & 0x0F) << 4;
- if (nET == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- nET == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P) //曝光模式
- {
- FERROR("SetAPRMaMmo:can not set TECHMODE[{$}] \n", nET);
- }
- else
- {
- if (nET == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P)
- {
- cData10 += (1) << 2;
- }
- else if (nET == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P)
- {
- cData10 += (0) << 2;
- }
- else if (nET == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- cData10 += (2) << 2;//应该是2,暂时改1
- }
- }
- if (-1 == nFilter) //滤线器
- {
- if (m_pMechDev)
- {
- nFilter = m_pMechDev->GetMammo_FT();
- }
- else
- nFilter = 0;
- }
- cData10 += (nFilter & 0x01) << 1;
- cData10 += nFO & 0x01;
- strCmd.SetAt(10, cData10);
-
- return HWSend(strCmd);
- }
- RET_STATUS nsGEN::SINOminiDevice::IncKV()
- {
- if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
-
- float oldKV= m_DoseUnit.m_KV->Get();
- oldKV++;
- FINFO("IncKV call SetAPRMaMmo \n");
- return SetAPRMaMmo(oldKV, m_DoseUnit.m_MAS->Get(), m_DoseUnit.m_Focus->Get(), m_DoseUnit.m_Techmode->Get(), m_DoseUnit.m_AECDensity->Get());
- }
- RET_STATUS nsGEN::SINOminiDevice::DecKV()
- {
- if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
-
- float oldKV = m_DoseUnit.m_KV->Get();
- oldKV--;
- FINFO("DecKV call SetAPRMaMmo \n");
- return SetAPRMaMmo(oldKV, m_DoseUnit.m_MAS->Get(), m_DoseUnit.m_Focus->Get(), m_DoseUnit.m_Techmode->Get(), m_DoseUnit.m_AECDensity->Get());
- }
- RET_STATUS nsGEN::SINOminiDevice::SetKV(float value)
- {
- if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("SetKV call SetAPRMaMmo \n");
- return SetAPRMaMmo(value, m_DoseUnit.m_MAS->Get(), m_DoseUnit.m_Focus->Get(), m_DoseUnit.m_Techmode->Get(), m_DoseUnit.m_AECDensity->Get());
- }
- RET_STATUS nsGEN::SINOminiDevice::IncMAS()
- {
- if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
- float oldMAS = m_DoseUnit.m_MAS->Get();
- oldMAS++;
- FINFO("IncMAS call SetAPRMaMmo \n");
- return SetAPRMaMmo(m_DoseUnit.m_KV->Get(), oldMAS, m_DoseUnit.m_Focus->Get(), m_DoseUnit.m_Techmode->Get(), m_DoseUnit.m_AECDensity->Get());
- }
- RET_STATUS nsGEN::SINOminiDevice::DecMAS()
- {
- if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
- float oldMAS = m_DoseUnit.m_MAS->Get();
- oldMAS--;
- FINFO("DecMAS call SetAPRMaMmo \n");
- return SetAPRMaMmo(m_DoseUnit.m_KV->Get(), oldMAS, m_DoseUnit.m_Focus->Get(), m_DoseUnit.m_Techmode->Get(), m_DoseUnit.m_AECDensity->Get());
- }
- RET_STATUS nsGEN::SINOminiDevice::SetMAS(float value)
- {
- if (!m_DoseUnit.m_MAS->Verify(value))
- {
- if (m_DoseUnit.m_GenState->Get() == nsGEN::AttrKey::GENERATOR_STATUS_EXP)
- {
- value = 11;
- FDEBUG("SetMAS in AEC MAS is too small, use 11 \n");
- }
- else
- {
- FDEBUG("SetMAS in AEC MAS is too small \n");
- return RET_STATUS::RET_SUCCEED;
- }
- }
- FINFO("SetMAS call SetAPRMaMmo \n");
- #if 0 //wxx test for SINO AEC
- return SetAPRMaMmo(m_DoseUnit.m_KV->Get(), value, m_DoseUnit.m_Focus->Get(), m_DoseUnit.m_Techmode->Get(), m_DoseUnit.m_AECDensity->Get());
- #else
- if (m_DoseUnit.m_GenState->Get() == nsGEN::AttrKey::GENERATOR_STATUS_EXP)
- {
- char tempCMD[12] = { 0xf0,0x07,0x00,0x00,0x00,0x00,0x01,0x28,0x00,0x00,0xC6 };
- SINOminiCommand strCmd(tempCMD, 11);
- HWSend(strCmd);
- }
- else
- {
- return SetAPRMaMmo(m_DoseUnit.m_KV->Get(), value, m_DoseUnit.m_Focus->Get(), m_DoseUnit.m_Techmode->Get(), m_DoseUnit.m_AECDensity->Get());
- }
- #endif // 0
- }
- RET_STATUS nsGEN::SINOminiDevice::SetTechmode(int value)
- {
- if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
-
- FINFO("SetTechmode [{$}] \n", value);
- if (value == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- value == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P ||
- value == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P)
- {
- FINFO("SetTechmode call SetAPRMaMmo \n");
- return SetAPRMaMmo(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MAS->Get(), m_DoseUnit.m_Focus->Get(), value, m_DoseUnit.m_AECDensity->Get());
- }
- else
- {
- FERROR("SetTechmode:unknown mode[{$}] \n", value);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetEXAMMode(std::string value)
- {
- //上层给我设置exam mode。(manual semi atuo)对应(NoAEC2Point AEC2Point AEC2Point)
- FINFO("Enter setexammode func value = {$}\n", value);
- if (value == AttrKey::EXAMMODE_TYPE::MANUAL)
- {
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P)
- {
- SetTechmode(1);
- }
- }
- else if (value == AttrKey::EXAMMODE_TYPE::SEMIAUTO)
- {
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- SetTechmode(3);
- }
- }
- else if (value == AttrKey::EXAMMODE_TYPE::AUTOMATIC)
- {
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- SetTechmode(3);
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetFocus(int value)
- {
- if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("SetFocus call SetAPRMaMmo \n");
- return SetAPRMaMmo(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MAS->Get(), value, m_DoseUnit.m_Techmode->Get(), m_DoseUnit.m_AECDensity->Get());
- }
- RET_STATUS nsGEN::SINOminiDevice::SetAECDensity(int value)
- {
- if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED;
- #if 0
- 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;
- }
- #endif // 0
- FINFO("SetAECDensity call SetAPRMaMmo \n");
- return SetAPRMaMmo(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MAS->Get(), m_DoseUnit.m_Focus->Get(), m_DoseUnit.m_Techmode->Get(), value);
- }
- RET_STATUS nsGEN::SINOminiDevice::SetAECField(int value) //发生器无此设置
- {
- if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
- #if 0
- 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;
- }
- #endif // 0
- m_DoseUnit.m_AECField->Update(value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetAECFilm(int value) //发生器无此设置
- {
- if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
- #if 0
- 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;
- }
- #endif // 0
- m_DoseUnit.m_AECFilm->Update(value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::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;
- }
- RET_STATUS nsGEN::SINOminiDevice::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);
- }
- 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_AEC_2P || m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P)//wxx test for SINO AEC
- {
- #if 1
- if (m_DoseUnit.m_GenState->Get() == nsGEN::AttrKey::GENERATOR_STATUS_EXP)
- {
- FDEBUG("SetAPR call AEC Mean [296] \n");
- char tempCMD1[12] = { 0xf0,0x07,0x00,0x00,0x00,0x00,0x01,0x28,0x00,0x00,0xC6 };
- SINOminiCommand strCmd1(tempCMD1, 11);
- HWSend(strCmd1);
- FDEBUG("SetAPR call SyncTimestamp \n");
- char tempCMD2[12] = { 0xf0,0x04,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x8b };
- SINOminiCommand strCmd2(tempCMD2, 11);
- HWSend(strCmd2);
- FDEBUG("SetAPR call PlateAutoRelease Enable \n");
- char tempCMD3[12] = { 0xf0,0x2a,0x2e,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x81 };
- SINOminiCommand strCmd3(tempCMD3, 11);
- HWSend(strCmd3);
- }
- else
- #endif // 0
- {
- FDEBUG("SetAPR call fixed SetAPRMaMmo \n");
- char tempCMD[12] = { 0xf0,0x01,0x00,0x00,0x1c,0x0a,0x00,0x27,0x00,0xf8,0x00 };
- SINOminiCommand strCmd(tempCMD, 11);
- HWSend(strCmd);
- }
- }
- else
- {
- FINFO("SetAPR call SetAPRMaMmo \n");
- int nBreastThickness = 0;
- if (m_pMechDev)
- nBreastThickness = m_pMechDev->GetMammo_Thickness();
- float fPressure = 0;
- if (m_pMechDev)
- fPressure = m_pMechDev->GetMammo_PressureValue();
- SetAPRMaMmo(t.fKV, t.fMAS, t.nFocus, m_DoseUnit.m_Techmode->Get(), t.nAECDensity, nBreastThickness, fPressure);
- }
- }
- m_DoseUnit.m_WS->Update(t.nWS);
- SetAECField(t.nAECField);
- SetAECFilm(t.nAECFilm);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::QueryHE(int& value) //实际为主动上报
- {
- //value = m_DoseUnit.m_HE->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::RefreshData()
- {
- FDEBUG("RefreshData: set System [init status] \n");
- SINOminiCommand strCmd(SINOmini_DevStatus, EM_DevStatus001);
- HWSend(strCmd);
- FDEBUG("RefreshData: set System [work mode] \n");
- SINOminiCommand strCmd2(SINOmini_WorkMode, 0x00);
- strCmd2.SetAt(3, 0x01);//PhotoMode
- strCmd2.SetAt(4, 0x01);//ImagingMode
- strCmd2.SetAt(5, 0x03);//AecMode
- strCmd2.SetAt(6, 0x01);//3dScanRange
- strCmd2.SetAt(7, 0x01);//3dSameAngle
- strCmd2.SetAt(8, 0x01);//FrameFrequency
- HWSend(strCmd2);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetExpEnable()
- {
- SINOminiCommand strCmd(SINOmini_DevStatus, EM_DevStatus003);
- HWSend(strCmd);
- SINOminiCommand strCmd2(SINOmini_RackAct, EM_RackACT055);
- strCmd.SetAt(10, 0x01);
- HWSend(strCmd2);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetExpDisable()
- {
- SINOminiCommand strCmd(SINOmini_DevStatus, EM_DevStatus004);
- HWSend(strCmd);
- SINOminiCommand strCmd2(SINOmini_RackAct, EM_RackACT055);
- strCmd.SetAt(10, 0x01);
- HWSend(strCmd2);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::QueryPostKV(float& value) //实际为主动上报
- {
- if (m_DoseUnit.m_PostKV->Get() > 0)
- {
- value = m_DoseUnit.m_PostKV->Get();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::QueryPostMA(float& value) //实际为主动上报
- {
- if (m_DoseUnit.m_PostMA->Get() > 0)
- {
- value = m_DoseUnit.m_PostMA->Get();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::QueryPostMS(float& value) //实际为主动上报
- {
- if (m_DoseUnit.m_PostMS->Get() > 0)
- {
- value = m_DoseUnit.m_PostMS->Get();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::QueryPostMAS(float& value) //实际为主动上报
- {
- if (m_DoseUnit.m_PostMAS->Get() > 0)
- {
- value = m_DoseUnit.m_PostMAS->Get();
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::IncMA()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::DecMA()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetMA(float value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::IncMS()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::DecMS()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetMS(float value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::Clear_DAP() //发生器无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::GetValue_DAP(float& value) //发生器无此设置
- {
- //value = m_DAP->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::StartMove() //发生器无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::EndMove() //发生器无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetGenSynState(int value) //在圣诺中用作AEC第二次曝光流程控制
- {
- FINFO("Enter SetGenSynState");
- if (m_AECFlag)
- {
- m_AECFlag = false;
- FINFO("SetGenSynState:Resolve AEC process too quickly");
- if (m_pAECProcessThread == NULL)
- {
- TerminateThread(m_pAECProcessThread, 0);
- m_pAECProcessThread = NULL;
- }
- DWORD m_HardwareStatusID;
- m_pAECProcessThread = CreateThread(0, 0, AECProcessThread, this, 0, &m_HardwareStatusID);
- if (m_pAECProcessThread == NULL)
- {
- FERROR("Start AECProcessThread Thread Failed");
- return RET_STATUS::RET_SUCCEED;;
- }
- }
- else
- {
- FINFO("SetGenSynState:RAD process do nothing");
- }
- return RET_STATUS::RET_SUCCEED;
- }
- DWORD nsGEN::SINOminiDevice::AECProcessThread(LPVOID pParam)
- {
- SINOminiDevice* pCurGen = (SINOminiDevice*)pParam;
- if (pCurGen == NULL)
- {
- return false;
- }
- FINFO("AECProcessThread start");
-
- FINFO("AECProcessThread send PR2");
- pCurGen->FireNotify(AttrKey::GENSYNSTATE, "2"); //PR2
- Sleep(2000);
- FINFO("AECProcessThread send XR1");
- pCurGen->FireNotify(AttrKey::GENSYNSTATE, "3"); //XR1Sleep(1000);
- Sleep(1000);
- FINFO("AECProcessThread send XR0");
- pCurGen->FireNotify(AttrKey::GENSYNSTATE, "4"); //XR0
- Sleep(1000);
- FINFO("AECProcessThread send PR0");
- pCurGen->FireNotify(AttrKey::GENSYNSTATE, "0"); //PR0
- FINFO("HardwareStatusThread stop");
- pCurGen->m_pAECProcessThread = NULL;
- return true;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetGenState(int value) //发生器无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetExpMode(std::string value) //发生器无此设置
- {
- FINFO("Enter SetExpMode...{$} \n",value);
- m_DoseUnit.m_ExpMode->Update(value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetFLFMode(std::string value) //发生器无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetFrameRate(FLOAT frameRate) //发生器无此设置
- {
- m_DoseUnit.m_FrameRate->Update(frameRate);
-
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetRPS(int rps) //发生器无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- //为了将gen和其他设备关联,能相互调用接口
- RET_STATUS nsGEN::SINOminiDevice::SetGrid(int nGridType)
- {
- FDEBUG("Enter SetGrid[{$}]", nGridType);
- if (m_pMechDev)
- m_pMechDev->UpdateGrid(nGridType);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetFilter(int nFilterType)
- {
- /*if (m_pMechDev)
- {
- m_pMechDev->UpdateMammo_FT(nFilterType);
- }
- if (m_pCollDev)
- {
- m_pCollDev->UpdateCollimatorFilter(nFilterType);
- }*/
- #if 0
- FINFO("SetFilter call SetAPRMaMmo \n");
- return SetAPRMaMmo(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MAS->Get(), m_DoseUnit.m_Focus->Get(), m_DoseUnit.m_Techmode->Get()
- , m_DoseUnit.m_AECDensity->Get(), -1, -1, nFilterType);
- #else
- SINOminiCommand strCmd(SINOmini_RackAct, EM_RackACT050);
- strCmd.SetAt(5, nFilterType);
- strCmd.SetAt(10, 0x01);
- return HWSend(strCmd);
- #endif
- }
- RET_STATUS nsGEN::SINOminiDevice::SetAutoTracking(int nAutoTracking)
- {
- FDEBUG("Enter SetAutoTracking[{$}]", nAutoTracking);
- /*if (m_pMechDev)
- m_pMechDev->UpdateMammo_Depress(nAutoTracking);*/
- SINOminiCommand strCmd(SINOmini_RackAct, EM_RackACT046);
- strCmd.SetAt(5, nAutoTracking);
- strCmd.SetAt(10, 0x01);
- return HWSend(strCmd);
- }
- RET_STATUS nsGEN::SINOminiDevice::GetTomoResults(ResDataObject& resultAngle, ResDataObject& resultHeight)
- {
- FDEBUG("Enter GetTomoResults");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetMechDev(OemMechanical* dev)
- {
- if (dev)
- m_pMechDev.reset(dev);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetCollimatorDev(OemCollimator* dev)
- {
- if (dev)
- m_pCollDev.reset(dev);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetCollimatorSize(int xsize, int ysize)
- {
- if (m_pCollDev)
- {
- m_pCollDev->UpdateCollimatorXSize(xsize);
- m_pCollDev->UpdateCollimatorYSize(ysize);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::SetCollimatorLight(WORD pParams)
- {
- //此处应该发送指令给GEN,并且该指令可以控制 coll 的LED
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::SINOminiDevice::Reset()
- {
- FDEBUG("clear all errors \n");
- int level = 0;
- m_MSGUnit->DelErrorMessage("0", level, "begin Rack homing");
-
- SINOminiCommand strCmd(SINOmini_RackAct, EM_RackACT045);
- strCmd.SetAt(5, 0x01);//AecMode
- strCmd.SetAt(10, 0x01);//3dScanRange
- HWSend(strCmd);
- SINOminiCommand strCmd2(SINOmini_DevStatus, EM_DevStatus003);
- return HWSend(strCmd2);
- }
- RET_STATUS nsGEN::SINOminiDevice::HWSend(SINOminiCommand& strCommand, int nTimeOut)
- {
- std::unique_lock<std::mutex> uqeConnectFlag(mtxConnectFlag);
- if (!m_bConnectFlag)
- {
- FERROR("==OUT==: not Connect,[{$}] send failed \n", strCommand.Get_Hex_Log());
- uqeConnectFlag.unlock();
- return RET_STATUS::RET_FAILED;
- }
- uqeConnectFlag.unlock();
- if (!m_SCF) return RET_STATUS::RET_FAILED;
- strCommand.SetCRC(crc8_MAXIM);
- FINFO("==OUT==: [{$}] \n", strCommand.Get_Hex_Log());
- int retLength;
- m_SCF.Lock(msTimeOut_Lock)
- .SendPacket(strCommand, SINOmini_Com_NormalLen-1, nTimeOut, retLength);
- Sleep(nTimeOut);
-
- return RET_STATUS::RET_SUCCEED;
- }
- //-----------------------------------------------------------------------------
- // ProcessCmd
- //-----------------------------------------------------------------------------
- void nsGEN::SINOminiDevice::FireNotify(std::string key, std::string content)
- {
- EventCenter->OnNotify(1, key, content);
- }
- void nsGEN::SINOminiDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
- {
- char ErrorCode[20] = {0};
- sprintf_s(ErrorCode, "SINOmini_ERR_%03d", Code);
- int level = SINOmini_REGULATION_LEVEL::REG_ERRO;
- if (Act)
- {
- FERROR("add {$}:{$}", ErrorCode, ResInfo);
- m_MSGUnit->AddErrorMessage(ErrorCode, level, ResInfo);
- }
- else
- {
- FERROR("del {$}:{$}", ErrorCode, ResInfo);
- m_MSGUnit->DelErrorMessage(ErrorCode, level, ResInfo);
- }
- }
- void nsGEN::SINOminiDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
- {
- char ErrorCode[20] = { 0 };
- sprintf_s(ErrorCode, "SINOmini_WAR_%03d", Code);
- int level = SINOmini_REGULATION_LEVEL::REG_WARN;
- if (Act)
- {
- FERROR("add {$}:{$}", ErrorCode, ResInfo);
- m_MSGUnit->AddWarnMessage(ErrorCode, level, ResInfo);
- }
- else
- {
- FERROR("del {$}:{$}", ErrorCode, ResInfo);
- m_MSGUnit->DelWarnMessage(ErrorCode, level, ResInfo);
- }
- }
- void nsGEN::SINOminiDevice::OnCallBack()
- {
- //无 操作
- auto HWNotProcess = [this](const char* value, int length) -> void
- {
- FINFO("\n This commands didn't need to process!");
- };
- //响应操作
- auto CallbackACK = [this](const char* value, int length) -> void
- {
- //根据现场圣诺系统日志,理应有个ACK
- };
- //命令模式:用于正常操作
- auto CallbackParameter = [this](const char* value, int length) -> void
- {
- if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_STANDBY)
- {
- FDEBUG("Request Status_1: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());
- }
- int type = value[2];
- switch ((UINT8)type)
- {
- case EM_Param000:
- {
- SINOminiCommand ExposureParam(value, SINOmini_Com_NormalLen-1);
- //KV
- int nKV = ExposureParam.GetAt(5);
- FDEBUG("get CurrtSetKV [{$}]", nKV);
- m_DoseUnit.m_KV->Update(nKV);
- FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
- //MAS
- float fMAS = ExposureParam.GetAt(4);
- FDEBUG("get CurrtSetMAS [{$}]", fMAS);
- m_DoseUnit.m_MAS->Update(fMAS);
- FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
- //Focus
- int nFO = (ExposureParam.GetAt(10) & 0x01);
- FDEBUG("get CurrtSetFocus [{$}]", nFO);
- if (m_DoseUnit.m_Focus->Update(nFO))
- FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
- //Techmode
- int nET = (ExposureParam.GetAt(10) & 0x0C) >> 2;
- switch (nET)
- {
- case 0:
- FDEBUG("get CurrtSetTechmode [TECHMODE_NOAEC_2P]");
- nET = AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P;
- if (m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P))
- FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
- break;
- case 1:
- FDEBUG("get CurrtSetTechmode [TECHMODE_AEC_1P]");
- nET = AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P;
- if (m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P))
- FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
- break;
- case 2:
- {
- FDEBUG("get CurrtSetTechmode [TECHMODE_AEC_2P]");
- nET = AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P;
- if (m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P))
- FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
- }
- break;
- default:
- FERROR("==CallbackParameter==: Get other Techmode value!");
- break;
- }
- //AECDensity
- int nDensity = ExposureParam.GetAt(6);
- FDEBUG("get CurrtSetDensity [{$}]", nDensity);
- if (m_DoseUnit.m_AECDensity->Update(nDensity))
- FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
- #if 0
- //BreastThickness
- int nBreastThickness = ExposureParam.GetAt(8);
- if (m_pMechDev)
- m_pMechDev->UpdateMammo_Thickness(nBreastThickness);
- //pressure
- float fPressure = ExposureParam.GetAt(9);
- if (m_pMechDev)
- m_pMechDev->UpdateMammo_PressureValue(fPressure);
- #else
- int nBreastThickness = 0;
- float fPressure = 0;
- #endif
- //Filter
- int nFilter = (ExposureParam.GetAt(10) & 0x0C) >> 1;
- if (m_pMechDev)
- m_pMechDev->UpdateMammo_FT(nFilter);
- //AGD
- #if 1
- float fAGD = 1;
- #else
- float fAGD = ExposureParam.GetAt();
- if (m_pMechDev)
- {
- m_pMechDev->UpdateMammo_AGD(fAGD);
- }
- #endif // 0
- FDEBUG("==CallbackParameter==: KV:[{$}],MAS:[{$}],FO:[{$}],Techmode:[{$}],AGD:[{$}],Filter:[{$}],Thickness:[{$}],Pressure:[{$}]",
- nKV, fMAS, nFO, nET, fAGD, nFilter, nBreastThickness, fPressure);
- break;
- }
- case EM_Param001:
- {
- FDEBUG("can not deal with Param001");
- break;
- }
- case EM_Param002:
- {
- FDEBUG("can not deal with Param002");
- break;
- }
- default:
- FERROR("==CallbackParameter==: unknown Param type value!");
- break;
- }
- };
- auto CallbackWarningInfo = [this](const char* value, int length) -> void
- {
- SINOminiCommand SystemWarn(value, SINOmini_Com_NormalLen - 1);
- UINT8 nCode = SystemWarn.GetAt(3);
- FDEBUG("==CallbackWarningInfo==: Gen system Wraning: [{$:x}]", nCode);
- switch ((UINT8)nCode)
- {
- case (UINT8)EM_Warn001: //开机高压错误
- {
- FireErrorMessage(true, nCode, "Power on high voltage error");
- break;
- }
- case (UINT8)EM_Warn002: //曝光控制板运行时高压错误
- {
- FireErrorMessage(true, nCode, "High voltage error during of exp_ctrl board");
- break;
- }
- case (UINT8)EM_Warn003: //开机时灯丝错误
- {
- FireErrorMessage(true, nCode, "Filament error during startup");
- break;
- }
- case (UINT8)EM_Warn004: //曝光时灯丝错误
- {
- FireErrorMessage(true, nCode, "Filament error during exposure");
- break;
- }
- case (UINT8)EM_Warn005: //曝光板读存储器错误
- {
- FireErrorMessage(true, nCode, "Exposure board read memory error");
- break;
- }
- case (UINT8)EM_Warn006: //球管过温保护错误
- {
- FireWarnMessage(true, nCode, "Ball tube over temperature protection error");
- break;
- }
- case (UINT8)EM_Warn007: //球管运行绕阻线断开错误
- {
- FireErrorMessage(true, nCode, "Error in the winding wire during tube operation");
- break;
- }
- case (UINT8)EM_Warn008: //阳极启动信号异常
- {
- FireErrorMessage(true, nCode, "Anode start signal abnormality");
- break;
- }
- case (UINT8)EM_Warn011: //曝光时高压电源未产生高压
- {
- FireWarnMessage(true, nCode, "The high-voltage power not supply during exp");
- break;
- }
- case (UINT8)EM_Warn228:
- {
- FireWarnMessage(false, EM_Warn011, "del EM_Warn011");
- break;
- }
- case (UINT8)EM_Warn013: //球管打火计数错误
- {
- FireErrorMessage(true, nCode, "Ball tube firing count error");
- break;
- }
- case (UINT8)EM_Warn014: //手闸激活没有及时释放
- {
- FireWarnMessage(true, nCode, "The handswitch was not released in a timely manner");
- break;
- }
- case (UINT8)EM_Warn233:
- {
- FireWarnMessage(false, EM_Warn014, "del EM_Warn014");
- break;
- }
- case (UINT8)EM_Warn015: //曝光时提前松开手闸错误
- {
- FireWarnMessage(true, nCode, "Error releasing handswitch during exposure");
- break;
- }
- case (UINT8)EM_Warn234:
- {
- FireWarnMessage(false, EM_Warn015, "del EM_Warn015");
- break;
- }
- case (UINT8)EM_Warn016: //自动测试模式时,没有插短接头错误
- {
- FireWarnMessage(true, nCode, "there is no short When in automatic testing mode");
- break;
- }
- case (UINT8)EM_Warn227:
- {
- FireWarnMessage(false, EM_Warn016, "del EM_Warn016");
- break;
- }
- case (UINT8)EM_Warn017: //曝光时管电流过高错误
- {
- FireErrorMessage(true, nCode, "Tube current too high during exposure error");
- break;
- }
- case (UINT8)EM_Warn018: //曝光时管电流过低错误
- {
- FireErrorMessage(true, nCode, "Low tube current error during exposure");
- break;
- }
- case (UINT8)EM_Warn019: //灯丝板输入功率不正常
- {
- FireErrorMessage(true, nCode, "Abnormal input power of filament board");
- break;
- }
- case (UINT8)EM_Warn020: //探测器反馈错误
- {
- FireErrorMessage(true, nCode, "Detector feedback error");
- break;
- }
- case (UINT8)EM_Warn021: //曝光时滤线栅抖动错误
- {
- FireErrorMessage(true, nCode, "Filter grid jitter error during exposure");
- break;
- }
- case (UINT8)EM_Warn025: //急停开关按下
- {
- FireWarnMessage(true, nCode, "Emergency stop switch pressed");
- break;
- }
- case (UINT8)EM_Warn024:
- {
- FireWarnMessage(false, EM_Warn025, "del EM_Warn025");
- break;
- }
- case (UINT8)EM_Warn027: //二次限位开关按下
- {
- FireWarnMessage(true, nCode, "Secondary limit switch pressed");
- break;
- }
- case (UINT8)EM_Warn026:
- {
- FireWarnMessage(false, EM_Warn027, "del EM_Warn027");
- break;
- }
- case (UINT8)EM_Warn029: //在AEC模式下,压迫器压力小于30N不可以曝光
- {
- FireWarnMessage(true, nCode, "In AEC mode, the comp_pressure is less than 30N");
- break;
- }
- case (UINT8)EM_Warn028:
- {
- FireWarnMessage(false, EM_Warn029, "del EM_Warn029");
- break;
- }
- case (UINT8)EM_Warn031: //系统在运动中
- {
- FireWarnMessage(true, nCode, "The system is in motion");
- FireWarnMessage(false, EM_Warn006, "del EM_Warn006");
- break;
- }
- case (UINT8)EM_Warn030:
- {
- FireWarnMessage(false, EM_Warn031, "del EM_Warn031");
- break;
- }
- case (UINT8)EM_Warn033: //屏蔽门打开
- {
- FireWarnMessage(true, nCode, "Platform screen door open");
- break;
- }
- case (UINT8)EM_Warn032:
- {
- FireWarnMessage(false, EM_Warn033, "del EM_Warn033");
- SINOminiCommand strCmd2(SINOmini_DevStatus, EM_DevStatus003);
- HWSend(strCmd2);
- break;
- }
- case (UINT8)EM_Warn035: //校准开关已打开
- {
- FireWarnMessage(true, nCode, "Calibration switch turned on");
- break;
- }
- case (UINT8)EM_Warn034:
- {
- FireWarnMessage(false, EM_Warn035, "del EM_Warn035");
- break;
- }
- case (UINT8)EM_Warn037: //压迫器释放按钮在开机时按下错误
- {
- FireWarnMessage(true, nCode, "Compressor release button during startup");
- break;
- }
- case (UINT8)EM_Warn036:
- {
- FireWarnMessage(false, EM_Warn037, "del EM_Warn037");
- break;
- }
- case (UINT8)EM_Warn048: //C臂旋转方向控制引脚失效
- {
- FireErrorMessage(true, nCode, "C-arm rotation direction control pin failure");
- break;
- }
- case (UINT8)EM_Warn049: //压迫器升降方向控制引脚失效
- {
- FireErrorMessage(true, nCode, "Compressor lifting direction control pin failure");
- break;
- }
- case (UINT8)EM_Warn050: //系统自检未完成时脚踏开关被踩下
- {
- FireWarnMessage(true, nCode, "The foot switch is down when system self-test");
- break;
- }
- case (UINT8)EM_Warn237:
- {
- FireWarnMessage(false, EM_Warn050, "del EM_Warn050");
- break;
- }
- case (UINT8)EM_Warn051: //系统自检未完成时C臂旋转或升降按键被按下
- {
- FireWarnMessage(true, nCode, "The C-arm rotation is pressed when system self-test");
- break;
- }
- case (UINT8)EM_Warn238:
- {
- FireWarnMessage(false, EM_Warn051, "del EM_Warn051");
- break;
- }
- case (UINT8)EM_Warn052: //运动控制板自检未通过错误
- {
- FireErrorMessage(true, nCode, "Motion control board self test failed error");
- break;
- }
- case (UINT8)EM_Warn053: //滤线栅控制电路错误
- {
- FireErrorMessage(true, nCode, "Filter grid control circuit error");
- break;
- }
- case (UINT8)EM_Warn054: //急停开关按下时运动控制键被按下
- {
- FireWarnMessage(true, nCode, "The move_Control pressed when emergency stop switch is pressed");
- break;
- }
- case (UINT8)EM_Warn241:
- {
- FireWarnMessage(false, EM_Warn054, "del EM_Warn054");
- break;
- }
- case (UINT8)EM_Warn055: //滤片切换超时错误
- {
- FireErrorMessage(true, nCode, "Filter switching timeout error");
- break;
- }
- case (UINT8)EM_Warn056: //运动板SysTick时钟初始化不通过错误
- {
- FireErrorMessage(true, nCode, "Sports board SysTick clock initialization failed error");
- break;
- }
- case (UINT8)EM_Warn057: //运动板存储器读取错误
- {
- FireErrorMessage(true, nCode, "Motion board memory read error");
- break;
- }
- case (UINT8)EM_Warn058: //运动板存储器写数据失败错误
- {
- FireErrorMessage(true, nCode, "Motion board memory write data failure error");
- break;
- }
- case (UINT8)EM_Warn059: //C臂电机驱动器错误
- {
- FireErrorMessage(true, nCode, "C-arm motor driver error");
- break;
- }
- case (UINT8)EM_Warn060: //压力传感器故障
- {
- FireErrorMessage(true, nCode, "PRESSURE SENSOR FAILURE");
- break;
- }
- case (UINT8)EM_Warn061: //压迫器电机位置超差错误
- {
- FireErrorMessage(true, nCode, "Compressor motor position out of tolerance error");
- break;
- }
- case (UINT8)EM_Warn062: //C臂电机位置超差错误
- {
- FireErrorMessage(true, nCode, "C-arm motor position out of tolerance error");
- break;
- }
- case (UINT8)EM_Warn063: //推杆电机位置超差错误
- {
- FireErrorMessage(true, nCode, "Pushrod motor position out of tolerance error");
- break;
- }
- case (UINT8)EM_Warn064: //压迫器高度过低时插入放大架错误
- {
- FireWarnMessage(true, nCode, "Inserting the amplifier frame when compressor height too low");
- break;
- }
- case (UINT8)EM_Warn246:
- {
- FireWarnMessage(false, EM_Warn064, "del EM_Warn064");
- break;
- }
- case (UINT8)EM_Warn065: //压迫器电机驱动器错误
- {
- FireErrorMessage(true, nCode, "Compressor motor driver error");
- break;
- }
- case (UINT8)EM_Warn066: //推杆电机驱动器错误
- {
- FireErrorMessage(true, nCode, "Pushrod motor driver error");
- break;
- }
- case (UINT8)EM_Warn067: //角度校准板失效错误
- {
- FireErrorMessage(true, nCode, "Angle calibration board failure error");
- break;
- }
- case (UINT8)EM_Warn069: //开机检测到压力报错
- {
- FireWarnMessage(true, nCode, "Pressure error detected during startup");
- break;
- }
- case (UINT8)EM_Warn249:
- {
- FireWarnMessage(false, EM_Warn069, "del EM_Warn069");
- break;
- }
- case (UINT8)EM_Warn070: //AEC主曝光MAS小于最小值
- {
- FireWarnMessage(true, nCode, "AEC main exposure MAS is less than the minimum value");
- break;
- }
- case (UINT8)EM_Warn071: //AEC主曝光MAS大于最大值
- {
- FireWarnMessage(true, nCode, "AEC main exposure MAS greater than maximum value");
- break;
- }
- case (UINT8)EM_Warn072:
- {
- FireWarnMessage(false, EM_Warn070, "del EM_Warn070");
- FireWarnMessage(false, EM_Warn071, "del EM_Warn071");
- break;
- }
- case (UINT8)EM_Warn073: //滤线栅自检不通过
- {
- FireWarnMessage(true, nCode, "Filter grid self check failed");
- break;
- }
- case (UINT8)EM_Warn080:
- {
- FireWarnMessage(false, EM_Warn073, "del EM_Warn073");
- break;
- }
- case (UINT8)EM_Warn081: //滤过挡片自检不通过
- {
- FireErrorMessage(true, nCode, "Filter filter self check failed");
- break;
- }
- case (UINT8)EM_Warn082: //热容量已满,停止曝光
- {
- FireWarnMessage(true, nCode, "Heat capacity is full, stop exposure");
- break;
- }
- case (UINT8)EM_Warn083:
- {
- FireWarnMessage(false, EM_Warn082, "del EM_Warn082");
- break;
- }
- case (UINT8)EM_Warn128: //运动板问询通信异常
- {
- FireErrorMessage(true, nCode, "Abnormal communication in sports board inquiry");
- break;
- }
- case (UINT8)EM_Warn129: //曝光板问询通信异常
- {
- FireErrorMessage(true, nCode, "Abnormal communication during exposure board inquiry");
- break;
- }
- case (UINT8)EM_Warn130: //压力采集板问询通信异常
- {
- FireErrorMessage(true, nCode, "Pressure collection board inquiry communication abnormality");
- break;
- }
- case (UINT8)EM_Warn131: //X光剂量检测板问询通信异常
- {
- FireErrorMessage(true, nCode, "Abnormal communication during X-ray dose detection board inquiry");
- break;
- }
- case (UINT8)EM_Warn132: //阳极控制板问询通信异常
- {
- FireErrorMessage(true, nCode, "Anode control board inquiry communication abnormality");
- break;
- }
- case (UINT8)EM_Warn133: //显示板通信异常
- {
- FireErrorMessage(true, nCode, "Abnormal communication on the display board");
- break;
- }
- default:
- FERROR("==CallbackSystemWarn==: unKnown Wraning: [{$}]", nCode);
- }
- };
- auto CallbackExpStatus = [this](const char* value, int length) -> void
- {
- SINOminiCommand SystemStatus(value, SINOmini_Com_NormalLen - 1);
- int nStatus = SystemStatus.GetAt(3);
- FDEBUG("==CallbackExpStatus==: Gen system Status: [{$:x}]", nStatus);
- switch ((UINT8)nStatus)
- {
- case (UINT8)EM_ExpStatus001: //进入曝光状态
- {
- FDEBUG("PR1 : Exposure handbrake pressed");
- 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());
- break;
- }
- case (UINT8)EM_ExpStatus002: //系统曝光预热状态
- {
- FDEBUG("PR2 : System exposure preheating status");
- 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());
- break;
- }
- case (UINT8)EM_ExpStatus003: //AEC模式开启高压预曝光
- {
- FDEBUG("Pre - XR1 : AEC mode high-pressure pre exposure begin");
- 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());
- FDEBUG("Request Status_1: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());
- break;
- }
- case (UINT8)EM_ExpStatus004: //AEC模式高压预曝光结束
- {
- FDEBUG("Pre - XR0 : AEC mode enables high-pressure pre exposure end");
- 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());
- FDEBUG("Request Status_1: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());
- Sleep(50);
- if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- //wxx test for SINO AEC
- m_DoseUnit.m_PostKV->Update(28);
- FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
- m_DoseUnit.m_PostMAS->Update(11);
- FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet());
- //m_AECFlag = true;
-
- #if 1 //wxx test for SINO AEC
- {
- FDEBUG("SetAPR call AEC Mean [296] \n");
- char tempCMD1[12] = { 0xf0,0x07,0x00,0x00,0x00,0x00,0x01,0x28,0x00,0x00,0xC6 };
- SINOminiCommand strCmd1(tempCMD1, 11);
- HWSend(strCmd1);
- FDEBUG("SetAPR call SyncTimestamp \n");
- char tempCMD2[12] = { 0xf0,0x04,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x8b };
- SINOminiCommand strCmd2(tempCMD2, 11);
- HWSend(strCmd2);
- FDEBUG("SetAPR call PlateAutoRelease Enable \n");
- char tempCMD3[12] = { 0xf0,0x2a,0x2e,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x81 };
- SINOminiCommand strCmd3(tempCMD3, 11);
- HWSend(strCmd3);
- }
- #endif // 0
- break;
- }
- case (UINT8)EM_ExpStatus005: //开启高压,系统开始正常曝光
- {
- FDEBUG("XR1 : the system starts normal exposure");
- 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());
- FDEBUG("Request Status_1: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());
- break;
- }
- case (UINT8)EM_ExpStatus006: //曝光结束
- {
- FDEBUG("XR0 : Exposure process over");
- 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());
- FDEBUG("Request Status_1: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());
- //wxx test for SINO AEC
- int tempKV = m_DoseUnit.m_KV->Get();
- float tempMAS = m_DoseUnit.m_MAS->Get();
- FDEBUG("get CurrtPOSTKV[{$}], CurrtPOSTMAS[{$}]", tempKV, tempMAS);
- m_DoseUnit.m_PostKV->Update(tempKV);
- FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
- if (m_DoseUnit.m_PostMAS->Update(tempMAS))
- FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet());
- break;
- }
- case (UINT8)EM_ExpStatus238: //曝光完成开始冷却
- {
- FDEBUG("PR0 : Start cooling after exposure is completed");
- FDEBUG("Request Status_4:GEN is not in 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());
- FDEBUG("Request Fault Status: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());
- break;
- }
- case (UINT8)EM_ExpStatus239: //系统冷却完成
- {
- FDEBUG("System cooling completed");
- FDEBUG("Request Status_1: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());
- FireWarnMessage(false, 101, "del warn 101");
- break;
- }
- case (UINT8)EM_ExpStatus254: //正在曝光或曝光条件不充足
- {
- FDEBUG("In Exposure or not OK to enter exposure");
- if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_OFF)
- {
- FireWarnMessage(true, 100, "Not OK to enter exposure,Please pressurize");
- FireWarnMessage(false, 101, "del warn 101");
- }
- break;
- }
- case (UINT8)EM_ExpStatus255: //系统曝光条件充足
- {
- FDEBUG("OK to enter exposure");
- FireWarnMessage(false, 100, "del warn 100");
- FireWarnMessage(true, 101, "OK to enter exposure");
- break;
- }
- default:
- FERROR("==CallbackExpStatus==: unKnown status: [{$}]", nStatus);
- }
- };
- auto CallbackDevStatus = [this](const char* value, int length) -> void
- {
- //未在现场圣诺系统日志中发现这个日志的响应
- };
- auto CallbackcArmAngle = [this](const char* value, int length) -> void
- {
- SINOminiCommand cArmAngle(value, SINOmini_Com_NormalLen - 1);
- //Angle
- float fAngle = cArmAngle.GetAt(4);
- if (m_pMechDev)
- m_pMechDev->UpdateMammo_MechAngle(fAngle);
- FDEBUG("==CallbackcArmAngle==: Angle:[{$}]", fAngle);
- };
- auto CallbackHu = [this](const char* value, int length) -> void
- {
- SINOminiCommand HU(value, SINOmini_Com_NormalLen - 1);
- //TubeHeat status
- int nHUStatus = HU.GetAt(3);
- m_DoseUnit.m_HE->Update(nHUStatus);
- FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
- FDEBUG("==CallbackHu==: HUStatus: SINOmini_HU: [{$}]", nHUStatus);
- };
- auto CallbackGenAGD = [this](const char* value, int length) -> void
- {
- #if 1
- SINOminiCommand GenAGD(value, SINOmini_Com_NormalLen - 1);
- //AGD
- float fAGD = GenAGD.GetAt(4);
- if (m_pMechDev)
- {
- m_pMechDev->UpdateMammo_AGD(fAGD);
- }
- #endif
- };
- auto CallbackWorkMode = [this](const char* value, int length) -> void
- {
- //未在现场圣诺系统日志中发现这个日志的响应
- };
- auto CallbackRackAct = [this](const char* value, int length) -> void
- {
- SINOminiCommand RackAct(value, SINOmini_Com_NormalLen - 1);
- UINT8 nCode = RackAct.GetAt(3);
- FDEBUG("==CallbackRackAct==: act code: [{$:x}]", nCode);
- switch ((UINT8)nCode)
- {
- case (UINT8)EM_RackACT045: //一键归零
- {
- FINFO("Rack homing finish");
- break;
- }
- case (UINT8)EM_RackACT046: //压迫板自动释放
- {
- int nAutoTracking = RackAct.GetAt(5);
- nAutoTracking--;
- FINFO("==CallbackRackAct==: AutoTracking[{$}]", nAutoTracking);
-
- if (m_pMechDev)
- m_pMechDev->UpdateMammo_Depress(nAutoTracking);
- break;
- }
- case (UINT8)EM_RackACT049: //在 Get generator warning info, type = 0x22 之后出现
- {
- FINFO("==CallbackRackAct==: receive after warning 0x22");
- break;
- }
- case (UINT8)EM_RackACT050: //Filter
- {
- int nFilterType = RackAct.GetAt(5);
- if (m_pMechDev)
- {
- m_pMechDev->UpdateMammo_FT(nFilterType);
- }
- if (m_pCollDev)
- {
- m_pCollDev->UpdateCollimatorFilter(nFilterType);
- }
- break;
- }
- case (UINT8)EM_RackACT053: //?
- {
- FINFO("==CallbackRackAct==: unknown 0x35");
- break;
- }
- case (UINT8)EM_RackACT054: //SendUnixTime
- {
- string tempUnixTime(value + 3, 4);
- UINT8 UnixTime = atoi(tempUnixTime.c_str());
- FINFO("==CallbackRackAct==: UnixTime[{$}]", UnixTime);
- break;
- }
- case (UINT8)EM_RackACT055: //ENTER_STUDY_QUERY
- {
- FINFO("==CallbackRackAct==: 0x37 should not get res");
- break;
- }
- default:
- FERROR("==CallbackRackAct==: unKnown RackAct: [{$}]", nCode);
- }
- };
- auto CheckHeartBeat = [this](const char* value, int length) -> void
- {
- std::unique_lock<std::mutex> uqeHeartBeat(mtxHeartBeats); //心跳包统计清空
- m_iHeartBeats = 0;
- uqeHeartBeat.unlock();
- FDEBUG("==CheckHeartBeat==: status[{$}]", 1);
- };
- //服务模式:用于修改并读取非通用值, 不是正常操作的一部分.仅用于系统测试和设备维修
- //暂不使用
-
- arFrame.clear();
- //命令模式:用于正常操作
- //arFrame.push_back(tFrameMapping("ACK",3, CallbackACK));
- arFrame.push_back(tFrameMapping(SINOmini_Parameter, CallbackParameter));
- arFrame.push_back(tFrameMapping(SINOmini_WarningInfo,CallbackWarningInfo));
- arFrame.push_back(tFrameMapping(SINOmini_ExpStatus, CallbackExpStatus));
- arFrame.push_back(tFrameMapping(SINOmini_DevStatus, CallbackDevStatus));
- arFrame.push_back(tFrameMapping(SINOmini_cArmAngle, CallbackcArmAngle));
- arFrame.push_back(tFrameMapping(SINOmini_GenAGD, CallbackGenAGD));
- arFrame.push_back(tFrameMapping(SINOmini_WorkMode, CallbackWorkMode));
- arFrame.push_back(tFrameMapping(SINOmini_TubeHeat, CallbackHu));
- arFrame.push_back(tFrameMapping(SINOmini_RackAct, CallbackRackAct));
- }
- void nsGEN::SINOminiDevice::ReConnect()
- {
- FINFO("enter reconnect");
- m_SCF.Disconnect();
- ResDataObject Connection = m_GenConfig["connections"][0];
- FINFO("Reconnections:{$} \n", Connection.encode());
- auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::SINOminiDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
- if (erCode == SCF_ERR::SCF_SUCCEED)
- {
- FireErrorMessage(false, 1, "lost Connect");
- std::unique_lock<std::mutex> uqeConnectFlag(mtxConnectFlag);
- m_bConnectFlag = true;
- uqeConnectFlag.unlock();
- FINFO("reconnect success");
- }
- else
- {
- FINFO("reconnect failed");
- }
- }
- bool nsGEN::SINOminiDevice::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::SINOminiDevice::HardwareStatusThread(LPVOID pParam)
- {
- SINOminiDevice* pCurGen = (SINOminiDevice*)pParam;
- if (pCurGen == NULL)
- {
- return false;
- }
- FINFO("HardwareStatusThread start");
- int iloopingFlag = 0;
- if ((int)pCurGen->m_GenConfig["loopEnable"] >= 1)
- {
- iloopingFlag = (int)pCurGen->m_GenConfig["loopEnable"];
- }
- if ((int)pCurGen->m_GenConfig["loopTime"] >= 100)
- {
- pCurGen->m_iLoopTime = (int)pCurGen->m_GenConfig["loopTime"];
- }
- FINFO("loopEnable = {$},loopTime = {$}", iloopingFlag, pCurGen->m_iLoopTime);
- int currtTime = pCurGen->m_iLoopTime;
- //暂无心跳查询指令
- /*SINOminiCommand strHBCmd();
- pCurGen->HWSend(strHBCmd);*/
- Sleep(currtTime);
- while (iloopingFlag == 1)
- {
- std::unique_lock<std::mutex> uqeConnectFlag(pCurGen->mtxConnectFlag); //判断是否断连
- if (!(pCurGen->m_bConnectFlag))
- {
- uqeConnectFlag.unlock();
- FINFO("SINOminiGEN: not Connect,try to reconnect \n");
- pCurGen->FireErrorMessage(true, 1, "lost Connect");
- pCurGen->ReConnect();
- Sleep(20000);
- continue;
- }
- uqeConnectFlag.unlock();
- std::unique_lock<std::mutex> uqeTime(pCurGen->mtxTime); //读取循环时间
- FDEBUG("currtloopTime = {$}", pCurGen->m_iLoopTime);
- currtTime = pCurGen->m_iLoopTime;
- uqeTime.unlock();
- Sleep(currtTime);
- //pCurGen->HWSend(strHBCmd); //轮询发生器相关数据信息
- std::unique_lock<std::mutex> uqeHeartBeat(pCurGen->mtxHeartBeats); //心跳包统计加1
- pCurGen->m_iHeartBeats++;
- int tempHeartBeat = pCurGen->m_iHeartBeats;
- uqeHeartBeat.unlock();
- if (tempHeartBeat > 10) //无返回信息认为连接断开
- {
- uqeHeartBeat.lock();
- pCurGen->m_iHeartBeats = 0;
- uqeHeartBeat.unlock();
- FINFO("SINOminiGEN: lost Connect \n");
- uqeConnectFlag.lock();
- pCurGen->m_bConnectFlag = false;
- uqeConnectFlag.unlock();
- }
- }
- FINFO("HardwareStatusThread stop");
- return true;
- }
- //-----------------------------------------------------------------------------
- // SINOminiDriver
- //-----------------------------------------------------------------------------
- nsGEN::SINOminiDriver::SINOminiDriver()
- {
- m_bDemoConnected = false;
- m_pAttribute.reset(new ResDataObject());
- m_pDescription.reset(new ResDataObject());
- m_pDriGenDev = nullptr;
- m_pDriMechDev = nullptr;
- m_pDriCollDev = nullptr;
- }
- nsGEN::SINOminiDriver::~SINOminiDriver()
- {
- Close();
- gLogger = nullptr;
- if (m_pDriGenDev)
- {
- delete m_pDriGenDev;
- m_pDriGenDev = nullptr;
- }
- if (m_pDriMechDev)
- {
- delete m_pDriMechDev;
- m_pDriMechDev = nullptr;
- }
- if (m_pDriCollDev)
- {
- delete m_pDriCollDev;
- m_pDriCollDev = nullptr;
- }
- }
- void nsGEN::SINOminiDriver::Prepare()
- {
- string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
- //Log4CPP::ThreadContext::Map::Set("LogFileName", "GEN.SINOmini");
- Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.SINOmini");
- auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
- gLogger = Log4CPP::LogManager::GetLogger("GEN.SINOmini");
- m_SCFDllName = GetConnectDLL(m_ConfigFileName);
- super::Prepare();
- }
- std::string nsGEN::SINOminiDriver::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", "SINOmini");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Drv");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- bool DATA_ACTION nsGEN::SINOminiDriver::Connect()
- {
- ResDataObject Connection = GetConnectParam(m_ConfigFileName);
- FINFO("connections:{$} \n", Connection.encode());
- auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::SINOminiDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
- if (erCode != SCF_ERR::SCF_SUCCEED)
- return false;
- auto rc = super::Connect();
- if (!rc)
- return false;
- //return (erCode == SCF_ERR::SCF_SUCCEED);
- return true;
- }
- auto nsGEN::SINOminiDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
- {
- FINFO("Enter CreateDevice, index={$}", index);
-
- if (!m_SCF.isConnected())
- {
- FWARN("CreateDevice:not Connected");
- return nullptr;
- }
- if (index == 0)
- {
- m_pDriGenDev = new SINOminiDevice(EventCenter, m_SCF, m_ConfigFileName);
- auto dev = std::unique_ptr<IODevice>(new IODevice(m_pDriGenDev));
- return dev;
- }
- else if (index == 1)
- {
- FINFO("Enter CreateDevice Mechanical");
- m_pDriMechDev = new OemMechanical(std::shared_ptr<IOEventCenter>(new IOEventCenter()), 0, 1, 2, 31, 32, 33, 0, 35, 36, 4, 1);
- auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriMechDev));
- m_pDriMechDev->SetCtrlDev(m_pDriGenDev);
- m_pDriGenDev->SetMechDev(m_pDriMechDev);
- FINFO("Leave CreateDevice Mechanical");
- return dev;
- }
- else if (index == 2)
- {
- FINFO("Enter CreateDevice Collimator");
- m_pDriCollDev = new OemCollimator(std::shared_ptr<IOEventCenter>(new IOEventCenter()), 40, 50, 6, 7, 8, 1);
- auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriCollDev));
- m_pDriCollDev->SetCtrlDev(m_pDriGenDev);
- m_pDriGenDev->SetCollimatorDev(m_pDriCollDev);
- FINFO("Leave CreateDevice Collimator");
- return dev;
- }
- }
- void nsGEN::SINOminiDriver::FireNotify(int code, std::string key, std::string content)
- {
- EventCenter->OnNotify(code, key, content);
- }
- bool nsGEN::SINOminiDriver::isConnected() const
- {
- return super::isConnected();
- }
- std::string nsGEN::SINOminiDriver::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());
- //printf("************* get resource over %s \n", DescriptionTempEx.encode());
- return res;
- }
- std::string nsGEN::SINOminiDriver::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", "SINOmini");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Dev");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- void nsGEN::SINOminiDriver::Disconnect()
- {
- super::Disconnect();
- m_SCF.Disconnect();
- m_bDemoConnected = false;
- Close();
- gLogger = nullptr;
- }
- void nsGEN::SINOminiDriver::Dequeue(const char* Packet, DWORD Length)
- {
- DecodeFrame(Packet, Length);
- }
- PACKET_RET nsGEN::SINOminiDriver::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++)
- {
- FDEBUG("receive data[{$}][{$:x2}]", i, RecData[i]);
- }
- }
- #endif
- bool bHasHead = false;
- if (nLength < SINOmini_Com_NormalLen - 1)
- {
- PacketLength = 0;
- //printf("nLength too small, nLength==%d \n", nLength);
- FERROR("nLength too small, nLength==[{$}],RecData[{$}]", nLength, RecData);
- return PACKET_NOPACKET;
- }
- for (DWORD i = 0; i < nLength; i++)
- {
- //寻找包头
- if ((UINT8)RecData[i]== SINOmini_STX)
- {
- if (i!=0) //包头之前的数据格式不对,全部扔掉
- {
- if (!bHasHead)
- {
- PacketLength = i;
- SINOminiCommand strtemp(RecData, PacketLength);
- FERROR("==IN unknown format data ==:[{$}],UselessDataLength={$},TotalLength={$} \n", strtemp.Get_Hex_Log(), PacketLength, nLength);
- return PACKET_USELESS;
- }
- }
- else
- {
- bHasHead = true;
- }
- }
- //寻找包尾
- if (i == SINOmini_Com_NormalLen - 2)
- {
- if(bHasHead)
- {
- PacketLength = i + 1; //+1 because ETX
- SINOminiCommand strtemp(RecData, PacketLength); //全部数据
- FINFO("==IN==:[{$}]", strtemp.Get_Hex_Log());
- return PACKET_ISPACKET;
- }
- }
- }
- if (bHasHead && nLength < SINOmini_Com_NormalLen - 1)
- {
- PacketLength = 0;
- }
- if (nLength > SINOmini_Com_NormalLen)
- {
- PacketLength = nLength;
- SINOminiCommand strtemp(RecData, PacketLength);
- FERROR("==IN unknown format data ==:[{$}],nLength{$} too big,", strtemp.Get_Hex_Log(), nLength);
- return PACKET_USELESS;
- }
- return PACKET_NOPACKET;
- }
- bool nsGEN::SINOminiDriver::GetDeviceConfig(std::string& Cfg)
- {
- Cfg = m_DeviceConfigSend.encode();
- printf("GetDeviceConfig over , %s", Cfg.c_str());
- return true;
- }
- bool nsGEN::SINOminiDriver::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::SINOminiDriver::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::SINOminiDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
- {
- strValue = "";
- //return true;//暂时不需要
- 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::SINOminiDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
- {
- //return true;//暂时不需要
- 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::SINOminiDriver gIODriver;
- extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
- {
- return new nsGEN::SINOminiDriver();
- }
|