1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076 |
- // CCOS.Dev.GEN.PSGHR.cpp
- #include <assert.h>
- #include <functional>
- #include <unordered_map>
- #include <fstream>
- #include "LogicDevice.h"
- using namespace std::placeholders;
- #include "Helper.JSON.hpp"
- #include "CCOS.Dev.Generator.PSG_HR.h"
- #include "LogLocalHelper.h"
- #include "Log4CPP.h"
- using namespace CCOS::Dev::Detail::Generator;
- namespace nsGEN = CCOS::Dev::Detail::Generator;
- static nsGEN::PSGHRDriver* pIODriver = nullptr;
- #define PSGHR_LARGE_POWER 5
- #define PSGHR_SMALL_POWER 1.1
- #define PSGHR_MAX_HEAT 225
- #define PSGHR_MIN_MA 1.0
- #define PSGHR_MAX_MA 1000.0
- #define PSGHR_MIN_MS 1.0
- #define PSGHR_MAX_MS 10001.0
- #define PSGHR_LoopDefHBTime 1000
- #define PSGHR_LoopExpHBTime 500
- static const int msTimeOut_Lock = 500;
- #define PSGHR_Com_NormalLen 150
- #define PSGHR_ETX 0x03
- #define PSGHR_RESOK "$"
- #define Sleep(ms) std::this_thread::sleep_for(std::chrono::milliseconds(ms))
- static const auto COM_SCFDllName = "libSerialSCF.so";
- static const auto TCP_SCFDllName = "libTcpipSCF.so";
- //Log4CPP::Logger* gLogger = nullptr;
- struct tFrameMapping
- {
- static const int MaxLen = 5;
- using cbFun = std::function <void(const char*, int)>;
- char strHead[MaxLen];
- int NbOfCharOfHead;
- cbFun fun;
- tFrameMapping(const char* str, int len, cbFun f)
- {
- assert(len < MaxLen);
- for (int i = 0; i < len; i++)
- strHead[i] = str[i];
- NbOfCharOfHead = len;
- fun = f;
- }
- };
- static std::list <tFrameMapping> arFrame;
- static bool DecodeFrame(const char* strFrame, int length)
- {
- auto pr = [strFrame, length](const tFrameMapping& Item)
- {
- for (int i = 0; i < Item.NbOfCharOfHead; i++)
- {
- if (strFrame[i] != Item.strHead[i])
- {
- return false;
- }
- }
- return true;
- };
- auto found = std::find_if(arFrame.begin(), arFrame.end(), pr);
- if (found == arFrame.end())
- {
- return false;
- }
- const auto& Item = *found;
- auto pc = strFrame;
- char data[100] = { 0 };
- // 找到ETX位置(0x03)
- int etxPos = -1;
- for (int i = Item.NbOfCharOfHead; i < length - 1; i++) // length-1是因为最后一个字节是校验和
- {
- if (strFrame[i] == 0x03)
- {
- etxPos = i;
- break;
- }
- }
- // 计算Data部分的长度
- int dataLength = 0;
- if (etxPos != -1)
- {
- // Data长度 = ETX位置 - Command长度
- dataLength = etxPos - Item.NbOfCharOfHead;
- }
- else
- {
- // 如果没找到ETX,假设Data部分到倒数第二个字节(排除校验和)
- dataLength = length - Item.NbOfCharOfHead - 1;
- }
- // 只复制Data部分
- if (dataLength > 0 && dataLength < 100)
- {
- memcpy(data, strFrame + Item.NbOfCharOfHead, dataLength);
- }
- Item.fun(data, dataLength);
- return true;
- }
- //-----------------------------------------------------------------------------
- // PSGHRDevice
- //-----------------------------------------------------------------------------
- atomic<int> nsGEN::PSGHRDevice::m_iLoopTime = PSGHR_LoopDefHBTime;
- atomic<bool> nsGEN::PSGHRDevice::m_bExtraFlag = false;
- static atomic<bool>HeartBeatFlag = false;
- nsGEN::PSGHRDevice::PSGHRDevice(std::shared_ptr <IOEventCenter> center, std::shared_ptr<SCFWrapper> SCF, string configfile)
- : super(center)
- , superGen()
- , m_SCF(SCF)
- , m_bConnectFlag(false)
- , HeartBeatFlag(false)
- {
- assert(EventCenter);
- m_bExtraFlag = true;
- //��ʼ��
- m_bExpEnable = false;
- m_bConnectFlag = true;
- m_iLoopTime.store(PSGHR_LoopDefHBTime);
- for (int i = 0; i < 18; i++)
- {
- m_bFaultList[i] = false;
- }
- m_iMaxPower = PSGHR_LARGE_POWER; //KW
- MaxHeatContent = PSGHR_MAX_HEAT; //KJ
- 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(0.0, 39.0, 151.0, 1.0));
- m_DoseUnit.m_MA.reset(new MAMould(0.0, PSGHR_MIN_MA, PSGHR_MAX_MA, 0.1));
- m_DoseUnit.m_MS.reset(new MSMould(0.0, PSGHR_MIN_MS, PSGHR_MAX_MS, 0.01));
- m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.1, 1000.0, 0.01));
- 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, -3, 3, 1));
- m_DoseUnit.m_GenHE.reset(new GENHEATMould(0, 0, 100, 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_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(AttrKey::TUBETARGETMATERIAL_TYPE::MO));
- m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0, -45, 45, 1));
- m_DoseUnit.m_FLIntTime.reset(new FLUIntTimeMould(0.0, 0.0, 100.0, 0.1));
- m_DoseUnit.m_FLAccTime.reset(new FLAccTimeMould(0.0, 0.0, 999.0, 0.1));
- m_DoseUnit.m_FLKV.reset(new FLUKVMould(0, 40, 125, 1));
- m_DoseUnit.m_FLMS.reset(new FLUMSMould(10.0, 10.0, 999999.0, 0.01));
- m_DoseUnit.m_FLMA.reset(new FLUMAMould(0.5, 0.5, 99.0, 0.1));
- m_DoseUnit.m_ABSStatus.reset(new FLUABSStatusMould(0, 0, 2, 1));
- m_DoseUnit.m_PPS.reset(new PPSMould(0.5,0.5, 30, 0.1));
- m_DoseUnit.m_DoseLevel.reset(new FLUDoseLevelMould(0, 0, 2, 1));
- m_DoseUnit.m_FLMode.reset(new FLUModeMould(0, 0, 4, 1));
- m_DoseUnit.m_Curve.reset(new FLUCurveMould(0, 0, 3, 1));
-
- //Actual exposure parameters ֵ
- m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 40.0, 120.0, 1.0));
- m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 1.0, 1000.0, 0.1));
- m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 1.0, 10000.0, 0.01));
- m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.5, 1000.0, 0.01));
- //�������澯��������Ϣ
- m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
-
- m_hGenPostEvent = LinuxEvent::CreateEvent(LinuxEvent::MANUAL_RESET, false);
- //������Ӧ�������ձ� ���������ش������ݴ�����Ӧ�IJ���
- OnCallBack();
- //�����������Զ����ṩ��ָ��ע�Ἧ���в���
- Register();
- LoadConfig(configfile);
-
- //����Ӳ��״̬��ѯ����
- StartHardwareStatusThread();
- }
- nsGEN::PSGHRDevice::~PSGHRDevice()
- {
- m_bExtraFlag = false;
- if (m_pHardwareStatusThread.joinable()) {
- m_pHardwareStatusThread.join();
- }
- FINFO("\n===============log end ===================\n");
- arFrame.clear();
- }
- std::string nsGEN::PSGHRDevice::GetGUID() const
- {
- FINFO("===============GetGUID : {$} ===================\n", GeneratorUnitType);
- return GeneratorUnitType;
- }
- void nsGEN::PSGHRDevice::Register()
- {
- auto Disp = m_Dispatch.Lock().As();
- superGen::Register(Disp);
- superGen::RegisterRAD(Disp);
- superGen::RegisterAEC(Disp);
- superGen::RegisterExpEnable(Disp);
- superGen::RegisterGeneratortoSyncStatus(Disp);
- superGen::RegisterFluoro(Disp);
- Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
- Disp->Get.Push(AttrKey::DENHEAT, [this](std::string& out) { out = m_DoseUnit.m_GenHE->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);
- }
- RET_STATUS nsGEN::PSGHRDevice::IncKV()
- {
- FINFO("Enter PSGHRDevice::IncKV()\n");
- if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("KV+", 3);
- }
- RET_STATUS nsGEN::PSGHRDevice::DecKV()
- {
- if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("KV-", 3);
- }
- RET_STATUS nsGEN::PSGHRDevice::SetKV(float value)
- {
- if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "KV%03d", (int)value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::IncMA()
- {
- if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't inc MA");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MA+",3);
- }
- RET_STATUS nsGEN::PSGHRDevice::DecMA()
- {
- if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't dec MA");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MA-", 3);
- }
- RET_STATUS nsGEN::PSGHRDevice::SetMA(float value)
- {
- if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't set MA");
- return RET_STATUS::RET_FAILED;
- }
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "MA%05d", (int)(value * 10));
- return HWSend(temp, strlen(temp));
-
- }
- RET_STATUS nsGEN::PSGHRDevice::IncMS()
- {
- FINFO("nsGEN::PSGHRDevice::IncMS()\n");
- 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;
- }
- return HWSend("MS+",3);
- }
- RET_STATUS nsGEN::PSGHRDevice::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;
- }
- return HWSend("MS-", 3);;
- }
- RET_STATUS nsGEN::PSGHRDevice::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 };
- snprintf(temp, sizeof(temp), "MS%07d", (int)(value * 100));
- return HWSend(temp,strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::IncMAS()
- {
- FINFO("nsGEN::PSGHRDevice::IncMAS()\n");
- 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;
- }
- return HWSend("MX+" , 3);
- }
- RET_STATUS nsGEN::PSGHRDevice::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;
- }
- return HWSend("MX-", 3);
- }
- RET_STATUS nsGEN::PSGHRDevice::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;
- }
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "MX%06d", (int)(value * 100));
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetTechmode(int value)
- {
- if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "ET%1d", (int)value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetEXAMMode(std::string value)
- {
- //�ϲ��������exam mode��manual semiauto automatic����Ӧ��NoAEC2Point AEC2Point AEC2Point��
- FINFO("Enter setexammode func value = {$}\n", value);
- if (value == AttrKey::EXAMMODE_TYPE::MANUAL)
- {
- SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P);
- }
- else if (value == AttrKey::EXAMMODE_TYPE::SEMIAUTO)
- {
- SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
- }
- else if (value == AttrKey::EXAMMODE_TYPE::AUTOMATIC)
- {
- SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetAPR(const _tAPRArgs& t)
- {
- m_bGenBusy = true;
- 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 (t.nFocus < 0)
- {
- FINFO("SetAPR: the focus value is amall than 0, set focus to small focus\n");
- SetFocus(0);
- }
- int nTempAECFilm = 1;
- switch (t.nAECFilm)
- {
- case 0:
- nTempAECFilm = 1;
- break;
- case 1:
- nTempAECFilm = 10;
- break;
- case 2:
- nTempAECFilm = 100;
- break;
- default:
- break;
- }
- SetKV(t.fKV);
- SetFocus(t.nFocus);
- if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_AEC)
- {
- // aec
- SetTechmode(t.nTechmode);
- Sleep(50);
- SetAECField(t.nAECField);
- Sleep(80);
- SetAECDensity(t.nAECDensity);
- Sleep(50);
- SetAECFilm(nTempAECFilm);
- Sleep(50);
- SetMA(t.fMA);
- Sleep(50);
- SetMS(t.fMS);
- }
- else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- // mas
- SetTechmode(t.nTechmode);
- Sleep(50);
- const float EPSINON = 0.000001;
- if ((t.fMAS >= -EPSINON) && (t.fMAS <= EPSINON))
- {
- SetMAS(t.fMA * t.fMS / 1000);
- }
- else
- {
- SetMAS(t.fMAS);
- }
- }
- else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_TIME)
- {
- // time
- SetTechmode(t.nTechmode);
- Sleep(50);
- SetMA(t.fMA);
- Sleep(80);
- SetMS(t.fMS);
- }
- m_bGenBusy = false;
- HWSend("RR", 2);
- ///////////////////////end
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::RefreshData()
- {
- if (!m_bGenBusy)
- {
- HWSend("RR", 2);
- Sleep(50);
- HWSend("RS", 2);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFocus(int value)
- {
- if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FO%01d", (int)value);
- return HWSend(temp,strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::Reset()
- {
- FDEBUG("clear all errors \n");
- int level = 0;
- m_MSGUnit->DelErrorMessage("0", level, "clear all errors");
- m_MSGUnit->DelWarnMessage("0", level, "clear all Warning");
- HWSend("RE",2);//�����ô���״̬
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::ActiveSyncMode(_tSyncModeArgs value)
- {
- FINFO("value.strSyncMode: {$}, value.strSyncValue: {$}, value.strWS: {$} \n", value.strSyncMode, value.strSyncValue, value.strWS);
- int nSyncModeValue = atoi(value.strSyncValue.c_str());
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "WS%01d", nSyncModeValue);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::QueryHE(int& value)
- {
- if (!m_bGenBusy)
- return HWSend("HE?", 3);
- return RET_STATUS::RET_SUCCEED;
- }
- void nsGEN::PSGHRDevice::SubscribeSelf(ccos_mqtt_connection* conn)
- {
- //����GEN����Action
- //SubscribeTopic(conn, "CCOS/DEVICE/Generator/Action/#"); Moduld��Ĭ�϶��������Action��������Ҳ���ĵĻ��ͻ�ִ������Action�����ܻ������
- }
- RET_STATUS nsGEN::PSGHRDevice::SetVibrationGrid(int value)
- {
- FINFO("Enter StartVibrationGrid:[{$}]", value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::GetVibrationGridMS(int& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetAECDensity(int value)
- {
- if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC) return RET_STATUS::RET_FAILED;
- int nAECDensity = m_DoseUnit.m_AECDensity->Get();
- if (value < m_DoseUnit.m_AECDensity->Get())
- {
- if (value < m_DoseUnit.m_AECDensity->Get() - 1)
- {
- nAECDensity = (int)value;
- }
- else
- {
- nAECDensity = nAECDensity - 1;
- }
- }
- else if (value > m_DoseUnit.m_AECDensity->Get())
- {
- if (value > m_DoseUnit.m_AECDensity->Get() + 1)
- {
- nAECDensity = (int)value;
- }
- else
- {
- nAECDensity = nAECDensity + 1;
- }
- }
- m_DoseUnit.m_AECDensity->Update(value);
- char temp[50] = { 0 };
- if (nAECDensity >= 0)
- {
- snprintf(temp, sizeof(temp), "FN+%01d", (int)nAECDensity);
- }
- else
- {
- snprintf(temp, sizeof(temp), "FN-%01d", (int)nAECDensity);
- }
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetAECField(int value)
- {
- if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) return RET_STATUS::RET_FAILED;
- m_DoseUnit.m_AECField->Update(value);
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FI%03d", (int)value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetAECFilm(int value)
- {
- if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS) return RET_STATUS::RET_FAILED;
- m_DoseUnit.m_AECFilm->Update(value);
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FS%03d", (int)value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::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);
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "WS%01d", tempws);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::QueryPostKV(float& value)
- {
- m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
- value = m_DoseUnit.m_PostKV->Get();
- return HWSend("VP?",3);
- }
- RET_STATUS nsGEN::PSGHRDevice::QueryPostMA(float& value)
- {
- return HWSend("PA?", 3);
- }
- RET_STATUS nsGEN::PSGHRDevice::QueryPostMS(float& value)
- {
- return HWSend("AT?",3);
- }
- RET_STATUS nsGEN::PSGHRDevice::QueryPostMAS(float& value)
- {
- return HWSend("AP?", 3);
- }
- RET_STATUS nsGEN::PSGHRDevice::Clear_DAP()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::GetValue_DAP(float& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::StartMove() //������������
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::EndMove() //������������
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetGenSynState(int value)
- {
- FINFO("Enter SetGenSynState...{$} \n", value);
- //if (AttrKey::GENERATOR_RAD_XRAYON == value)
- //{
- // FINFO("SetGenSynState be call.this is soft syn mode.");
- // HWSend("XR2",3);
- // m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
- // FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- //}
- //else if(AttrKey::GENERATOR_FLU_XRAYON == value)
- //{
- // FINFO("SetGenSynState be call.this is soft syn mode.");
- // //HWSend("FLX2", 4);
- // //m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYON);
- // //FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- //}
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetGenState(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetExpMode(std::string value)
- {
- FINFO("Enter SetExpMode...{$} \n",value.c_str());
- m_DoseUnit.m_ExpMode->Update(value);
- //add for dcm iRF hard
- FINFO("SetExpMode:add for dcm iRF hard");
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- 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::PSGHRDevice::SetFLFMode(std::string value)
- {
- FINFO("Enter SetFLFMode...{$} \n", value.c_str());
- if (value == "CF")
- {
- m_DoseUnit.m_FLMode->Update(1);
- HWSend("FLF1", 4);
- SetPPS(15);
- SetPluseWidth(15);
- }
- else if (value == "PF")
- {
- m_DoseUnit.m_FLMode->Update(2);
- HWSend("FLF2", 4);
- SetPPS(5);
- SetPluseWidth(5);
- }
- else
- {
- FINFO("other FluMode : {$}", value.c_str());
- return RET_STATUS::RET_SUCCEED;
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFLLever(float value)
- {
- FINFO("Enter SetFLLever...{$} \n", value);
- m_DoseUnit.m_DoseLevel->Update(value);
- char temp[50]{ 0 };
- snprintf(temp, sizeof(temp), "FLD%f", value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFrameRate(float frameRate)
- {
- FINFO("SetFrameRate in\n");
- /*m_DoseUnit.m_FrameRate->Update(frameRate);
-
- char temp[50]{ 0 };
- snprintf(temp, sizeof(temp), "FLS%03d", int(frameRate * 10));
- return HWSend(temp, strlen(temp));*/
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetRPS(int rps) //�������˶�̬����
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetAPF(const _tAPFArgs& t)
- {
- m_bGenBusy = true;
- FINFO("APF:FLKV={$},FLMA={$},PPS={$},WS={$},FLuType={$},ABSMode={$},DoseLever={$}", t.nFLKV, t.fFLMA, t.nPPS, t.nWS, t.nFluMode, t.nABSMode, t.nDoseLever);
- SetABSMode(t.nABSMode);
- Sleep(50);
- SetFLFMode(to_string(t.nFluMode));
- Sleep(50);
- SetFluDoseLever(t.nDoseLever);
- Sleep(50);
- SetFluKV(t.nFLKV);
- Sleep(50);
- SetFluMA(t.fFLMA);
- m_bGenBusy = false;
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::IncFluKV()
- {
- FINFO("nsGEN::PSGHRDevice::IncFLKV()\n");
- if (!m_DoseUnit.m_FLKV->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLK+", 4);
- }
- RET_STATUS nsGEN::PSGHRDevice::DecFluKV()
- {
- if (!m_DoseUnit.m_FLKV->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLK-", 4);
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFluKV(float value)
- {
- if (!m_DoseUnit.m_FLKV->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FLK%03d", (int)value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::IncFluMA()
- {
- if (!m_DoseUnit.m_FLMA->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLM+", 4);
- }
- RET_STATUS nsGEN::PSGHRDevice::DecFluMA()
- {
- if (!m_DoseUnit.m_FLMA->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLM-", 4);
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFluMA(float value)
- {
- if (!m_DoseUnit.m_FLMA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FLM%03d", (int)(value * 10));
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::INCPPS()
- {
- if (!m_DoseUnit.m_PPS->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLS+", 4);
- }
- RET_STATUS nsGEN::PSGHRDevice::DECPPS()
- {
- if (!m_DoseUnit.m_PPS->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLS-", 4);
- }
- RET_STATUS nsGEN::PSGHRDevice::SetPPS(float value)
- {
- if (!m_DoseUnit.m_PPS->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FLS%03d", (int)(value * 10));
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetABSMode(int nMode)
- {
- if (!m_DoseUnit.m_ABSStatus->Verify(nMode)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- FINFO("SetABSMode[{$}] \n", nMode);
- snprintf(temp, sizeof(temp), "FLA%d", (int)nMode);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetABSCurve(int curveNum)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::IncABSCurve()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::DecABSCurve()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::GetABSCurve()
- {
- return HWSend("FLA?", 4);
- }
- float nsGEN::PSGHRDevice::GetFluIntTimer()
- {
- return HWSend("FLI?", 4);
- }
- float nsGEN::PSGHRDevice::GetFluAccTimer()
- {
- return HWSend("FLT?", 4);
- }
- RET_STATUS nsGEN::PSGHRDevice::ResetFluTimer(int value)
- {
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FLR%d", (int)value);
- FINFO("ReSetFluAccTimer[{$}] \n", value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFluPre(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFluEXP(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFluMode(std::string value)
- {
- FINFO("Enter SetFLFMode...{$} \n", value.c_str());
- if (value == "CF")
- {
- m_DoseUnit.m_FLMode->Update(1);
- return HWSend("FLF1", 4);
- }
- else if (value == "PF")
- {
- m_DoseUnit.m_FLMode->Update(2);
- return HWSend("FLF2", 4);
- }
- else
- {
- FINFO("other FluMode : {$}",value.c_str());
- return RET_STATUS::RET_SUCCEED;
- }
- }
- RET_STATUS nsGEN::PSGHRDevice::SetFluDoseLever(int value)
- {
- FINFO("Enter SetFluDoseLever...{$} \n", value);
- m_DoseUnit.m_DoseLevel->Update(value);
- char temp[50]{ 0 };
- snprintf(temp, sizeof(temp), "FLD%d", value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetPluseWidth(float fplusewidth)
- {
- if (!m_DoseUnit.m_PPS->Verify(fplusewidth)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FLW%05d", (int)(fplusewidth * 100));
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::PSGHRDevice::SetExpEnable()
- {
- if (1 == m_bUseCECmd)
- {
- HWSend("CE1", 3);
- }
- HWSend("ST?", 3);
- FINFO("SetExpEnable in\n");
- m_bExpEnable = true;
-
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
-
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::SetExpDisable()
- {
- if (1 == m_bUseCECmd)
- {
- HWSend("CE0", 3);
- }
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- FINFO("SetExpDisable in\n");
- m_bExpEnable = false;
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::PSGHRDevice::PrepareAcquisition()
- {
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- return RET_STATUS::RET_SUCCEED;
- }
- void nsGEN::PSGHRDevice::SetSmartAEC(int value)
- {
- }
- //-----------------------------------------------------------------------------
- // ProcessCmd
- //-----------------------------------------------------------------------------
- void nsGEN::PSGHRDevice::ProcessClientData(const char* pData, unsigned long nDataLength, void* lparam)
- {
- PSGHRDevice* pCurGen = (PSGHRDevice*)lparam;
- pCurGen->HWSend(pData, nDataLength);
- }
- RET_STATUS nsGEN::PSGHRDevice::HWSend(const char* strCommand,int lengh, bool reSend, int nTimeOut)
- {
- if (!m_bConnectFlag)
- {
- FERROR("==OUT==: not Connect, send failed \n");
- return RET_STATUS::RET_FAILED;
- }
- if (!m_SCF) return RET_STATUS::RET_FAILED;
- // 使用传入的lengh参数,如果为0则用strlen计算
- int cmdLen = (lengh > 0) ? lengh : strlen(strCommand);
- // 检查缓冲区大小,数据包 = 命令 + ETX(1字节) + CheckSum(1字节)
- const int maxCmdLen = 256; // 增大缓冲区以支持更长的命令
- if (cmdLen > maxCmdLen - 2)
- {
- FERROR("Command too long: {$} bytes, max allowed: {$} bytes\n", cmdLen, maxCmdLen - 2);
- return RET_STATUS::RET_FAILED;
- }
- char strSendCommand[maxCmdLen] = { 0 };
- // 计算校验和
- int tmpSum = 0;
- for (int i = 0; i < cmdLen; i++)
- {
- tmpSum += (unsigned char)strCommand[i];
- }
- char checkSum = char(tmpSum + 3);
- // 构建数据包:命令 + ETX + CheckSum
- memcpy(strSendCommand, strCommand, cmdLen);
- strSendCommand[cmdLen] = 0x03;
- strSendCommand[cmdLen + 1] = checkSum;
- int totalLen = cmdLen + 2; // 实际发送的总长度
- // 打印完整数据包的十六进制(含ETX和CheckSum)便于调试
- std::string hexStr;
- hexStr.reserve(totalLen * 3);
- int printLen = std::min(totalLen, 32); // 最多打印前32字节
- for (int i = 0; i < printLen; i++) {
- char buf[4];
- snprintf(buf, sizeof(buf), "%02X ", (unsigned char)strSendCommand[i]);
- hexStr += buf;
- }
- if (totalLen > 32) hexStr += "...";
- FINFO("==OUT== Packet[{$}]: {$}\n", totalLen, hexStr.c_str());
- // 发送数据包,支持重发机制
- int maxRetry = reSend ? 2 : 1; // 如果reSend为true,最多重试2次
- unsigned int retLength = 0;
- for (int retry = 0; retry < maxRetry; retry++)
- {
- if (retry > 0)
- {
- FWARN("Retry sending packet, attempt {$}/{$}\n", retry + 1, maxRetry);
- Sleep(100); // 重试前短暂延时
- }
- if (m_SCF->Lock(1000) == WAIT_OBJECT_0)
- {
- // 使用实际长度totalLen,而不是strlen
- int result = m_SCF->SendPacket(strSendCommand, totalLen, nTimeOut, retLength);
- m_SCF->Unlock();
- if (result == SCF_SUCCEED)
- {
- if (retry > 0)
- {
- FINFO("Send succeeded after {$} retries\n", retry);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- else
- {
- FERROR("SendPacket failed, result={$}, retry={$}/{$}\n", result, retry + 1, maxRetry);
- }
- }
- else
- {
- FERROR("Lock failed, retry={$}/{$}\n", retry + 1, maxRetry);
- }
- }
- FERROR("Send failed after {$} attempts\n", maxRetry);
- return RET_STATUS::RET_FAILED;
- }
- void nsGEN::PSGHRDevice::FireNotify(string key, int context)
- {
- char szInfo[64] = { 0 };
- snprintf(szInfo, sizeof(szInfo), "%d", context); // Linux ������
- std::string str = szInfo;
- EventCenter->OnNotify(1, key, str);
- }
- void nsGEN::PSGHRDevice::FireNotify(std::string key, float context)
- {
- char szInfo[16] = { 0 };
- snprintf(szInfo, sizeof(szInfo), "%.2f", context); // Linux ������
- std::string str = szInfo;
- EventCenter->OnNotify(1, key, str);
- }
- void nsGEN::PSGHRDevice::FireNotify(std::string key, std::string context)
- {
- EventCenter->OnNotify(1, key, context);
- }
- void nsGEN::PSGHRDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
- {
- string ErrorCode("PSGHR_ERR_");
- ErrorCode += std::to_string(Code);
- int level = PSG_HR_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::PSGHRDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
- {
- string ErrorCode("PSGHR_WAR_");
- ErrorCode += std::to_string(Code);
- int level = PSG_HR_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::PSGHRDevice::OnCallBack()
- {
- auto HWNotProcess = [](const char* value, int length) -> void
- {
- FINFO("This commands[{$}] didn't need to process", value);
- };
- auto extractValue = [](const char* src, int start, int len, bool isInt = false) -> double {
- char buf[7] = { 0 };
- memcpy(buf + (7 - len), src + start, len);
- return isInt ? atoi(buf) : atof(buf);
- };
- auto HWKV = [this, extractValue](const char* value, int length) {
- assert(value);
- if (length > 20) {
- FINFO("value:{$}", value);
- int tmpkv = static_cast<int>(extractValue(value, 0, 3, true));
- float tmpma = static_cast<float>(extractValue(value, 6, 5)) / 10.0f;
- float tmpms = static_cast<float>(extractValue(value, 14, 7)) / 100.0f;
- float tmpmx = static_cast<float>(extractValue(value, 24, 6)) / 100.0f;
- m_DoseUnit.m_KV->Update(tmpkv);
- FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
- m_DoseUnit.m_MA->Update(tmpma);
- FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
- m_DoseUnit.m_MS->Update(tmpms);
- FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
- m_DoseUnit.m_MAS->Update(tmpmx);
- FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
- FINFO("tmpkv={$}, tmpma={$}, tmpms={$}, tmpmx={$};", tmpkv, tmpma, tmpms, tmpmx);
- }
- else {
- if (m_DoseUnit.m_KV->Update(atof(value))) {
- FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
- }
- }
- };
- auto HWMAS = [this](const char* value, int length)
- {
- assert(value);
- float fmas = atof(value) / 100.0;
- m_DoseUnit.m_MAS->Update(fmas);
- FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
- };
- auto HWMA = [this](const char* value, int length)
- {
- assert(value);
- float fma = atof(value) / 10.0;
- m_DoseUnit.m_MA->Update(fma);
- FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
- };
- auto HWMS = [this](const char* value, int length)
- {
- assert(value);
- float fms = atof(value) / 100.0;
- m_DoseUnit.m_MS->Update(fms);
- FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
- };
- auto HWVP = [this](const char* value, int length)
- {
- assert(value);
- m_DoseUnit.m_PostKV->Update(atof(value));
- FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
- FINFO("Actual exposure parameters KV:{$}", m_DoseUnit.m_PostKV->JSGet().c_str());
- };
- auto HWPA = [this](const char* value, int length)
- {
- assert(value);
- float fma = atof(value) / 10.0;
- m_DoseUnit.m_PostMA->Update(fma);
- FireNotify(AttrKey::POSTMA, m_DoseUnit.m_PostMA->JSGet());
- FINFO("Actual exposure parameters MA:{$}", m_DoseUnit.m_PostMA->JSGet().c_str());
- };
- auto HWAP = [this](const char* value, int length)
- {
- assert(value);
- float fmas = atof(value) / 100.0;
- m_DoseUnit.m_PostMAS->Update(fmas);
- FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet());
- FINFO("Actual exposure parameters MAS:{$}", m_DoseUnit.m_PostMAS->JSGet().c_str());
- };
- auto HWFocus = [this](const char* value, int length)
- {
- assert(value);
- int nfous = atoi(value);
- if (m_DoseUnit.m_Focus->Update(nfous))
- FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
- FINFO("Current focus:{$}, FO={$}", atoi(m_DoseUnit.m_Focus->JSGet().c_str()) ? "large focus" : "small focus", m_DoseUnit.m_Focus->JSGet().c_str());
- };
- auto HWTechmode = [this](const char* value, int length)
- {
- assert(value);
- int ntechmode = atoi(value);
- m_DoseUnit.m_Techmode->Update(ntechmode);
- FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
- switch (ntechmode)
- {
- case 0:
- FINFO("ET={$}", "mA/ms",m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- case 1:
- FINFO("ET={$}", "mAs", m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- case 2:
- FINFO("ET={$}", "AEC / mA", m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- case 3:
- FINFO("ET={$}", "mAs / ms", m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- case 4:
- FINFO("ET={$}", "AEC", m_DoseUnit.m_Techmode->JSGet().c_str());
- break;
- }
- };
- auto HWAECField = [this](const char* value, int length)
- {
- assert(value);
- int nvalue = atoi(value);
- if (m_DoseUnit.m_AECField->Update(nvalue))
- FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_AECField->JSGet());
- };
- auto HWAECFilm = [this](const char* value, int length)
- {
- assert(value);
- if (m_DoseUnit.m_AECFilm->Update(atoi(value)))
- FireNotify(AttrKey::AECFILM, m_DoseUnit.m_AECFilm->JSGet());
- };
- auto HWAECDensity = [this](const char* value, int length)
- {
- assert(value);
- if (m_DoseUnit.m_AECDensity->Update(atoi(value)))
- FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
- };
- auto HWWS = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- m_DoseUnit.m_WS->Update(nValue);
- {
- FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
- }
- };
- auto HWPR = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 2)
- {
-
- }
- else if (nValue == 1)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE);
- FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else if (nValue == 0)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
- FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- m_bGenBusy = false;
- RefreshData();
- }
- };
- auto HWXR = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 2)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
- FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else if (nValue == 1)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
- m_hGenPostEvent->ResetEvent();
- FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else if (nValue == 0)
- {
- m_bGenBusy = false;
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF);
- FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- };
- auto HWAPDOSE = [this](const char* value, int length)//post mas
- {
- assert(value);
- m_DoseUnit.m_PostMAS->Update(atof(value) / 100.0);
- FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
- FINFO("Actual exposure parameters MAS:{$}", m_DoseUnit.m_PostMAS->JSGet().c_str());
- };
- auto HWATDOSE = [this](const char* value, int length)
- {
- assert(value);
- m_DoseUnit.m_PostMS->Update(atof(value) / 100.0);
- FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
- FINFO("Actual exposure parameters MS:{$}", m_DoseUnit.m_PostMS->JSGet().c_str());
- };
- auto HWDAP = [this](const char* value, int length)
- {
- assert(value);
- FINFO("Recv DAP ={$}", atof(value) / 100.0);
- };
- auto HWEHE = [this](const char* value, int length)
- {
- m_iHeartBeats = 0;
- assert(value);
- int nhe = atoi(value);
- if (m_DoseUnit.m_HE->Update(nhe))
- FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
- };
- auto HWHH = [this](const char* value, int length)
- {
- m_iHeartBeats = 0;
- assert(value);
- int nhe = atoi(value);
- if (m_DoseUnit.m_GenHE->Update(nhe))
- FireNotify(m_DoseUnit.m_GenHE->GetKey(), m_DoseUnit.m_GenHE->JSGet());
- };
-
- auto HWFLK = [this](const char* value, int length) {
- assert(value);
- if (length > 20) { // ��������ʽ�ַ���: "040 FLM00010 FLI000 FLT000 FLF1 FLA0 FLS060 FLD0 FLO0 FLC1 FLW00400"
- FINFO("value:{$}", value);
- int tmpflk, tmpflf, tmpfla, tmpfld, tmpflo;
- float tmpflm, tmpfli, tmpflt, tmpfls, tmpflw;
- // ����ʽֱ����ȡ�����ֶΣ�%n��ȡ�Ѷ��ֽ���������У���ʽ��
- int bytesRead;
- const char* fmt = "%3d FLM%5f FLI%3f FLT%3f FLF%d FLA%d FLS%3f FLD%d FLO%d FLC%d FLW%5f%n";
- int ret = sscanf(value, fmt,
- &tmpflk, &tmpflm, &tmpfli, &tmpflt, &tmpflf, &tmpfla, &tmpfls, &tmpfld, &tmpflo, /*FLCδʹ��*/nullptr, & tmpflw, & bytesRead);
- // У������Ƿ�ɹ�����ƥ��11���ֶ��Ҷ��������ַ�����
- if (ret == 11 && bytesRead == length) {
- // ͳһ������ֵת����ԭ���еij�����
- tmpflm /= 10.0f;
- tmpfli /= 10.0f;
- tmpflt /= 10.0f;
- tmpfls /= 10.0f;
- tmpflw /= 100.0f;
- // ���²�֪ͨ������������
- if (m_DoseUnit.m_FLKV->Update(tmpflk))
- FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
- if (m_DoseUnit.m_FLMA->Update(tmpflm))
- FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
- if (m_DoseUnit.m_FLIntTime->Update(tmpfli))
- FireNotify(AttrKey::FLUIntTime, m_DoseUnit.m_FLIntTime->JSGet());
- if (m_DoseUnit.m_FLAccTime->Update(tmpflt))
- FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
- if (m_DoseUnit.m_FLMode->Update(tmpflf))
- FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
- if (m_DoseUnit.m_ABSStatus->Update(tmpfla))
- FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
- if (m_DoseUnit.m_PPS->Update(tmpfls))
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- if (m_DoseUnit.m_DoseLevel->Update(tmpfld))
- FireNotify(AttrKey::FLUDoseLevel, m_DoseUnit.m_DoseLevel->JSGet());
- if (m_DoseUnit.m_Curve->Update(tmpflo))
- FireNotify(AttrKey::FLUCurve, m_DoseUnit.m_Curve->JSGet());
- if (m_DoseUnit.m_FLMS->Update(tmpflw))
- FireNotify(AttrKey::FLUMS, m_DoseUnit.m_FLMS->JSGet());
- FINFO("tmpflk={$}, tmpflf={$}, tmpfla={$}, tmpfld={$}, tmpflo={$}, tmpflm={$}, tmpfli={$}, tmpflt={$}, tmpfls={$}, tmpflw={$};",
- tmpflk, tmpflf, tmpfla, tmpfld, tmpflo, tmpflm, tmpfli, tmpflt, tmpfls, tmpflw);
- }
- else {
- FINFO("FLK format parse failed");
- }
- }
- else {
- // �̸�ʽ����
- int tmpflkv = atoi(value);
- m_DoseUnit.m_FLKV->Update(tmpflkv);
- FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
- }
- };
- auto HWFLM = [this](const char* value, int length)
- {
- assert(value);
- float tmpflm = atof(value) / 10.0;
- m_DoseUnit.m_FLMA->Update(tmpflm);
- FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
- };
- auto HWFLW = [this](const char* value, int length)
- {
- assert(value);
- float tmpflms = atof(value) / 100.0;
- m_DoseUnit.m_FLMS->Update(tmpflms);
- FireNotify(AttrKey::FLUMS, m_DoseUnit.m_FLMS->JSGet());
- };
- auto HWFLI = [this](const char* value, int length)
- {
- assert(value);
- float tmpfli = atof(value) / 10.0;
- if (m_DoseUnit.m_FLIntTime->Update(tmpfli))
- FireNotify(AttrKey::FLUIntTime, m_DoseUnit.m_FLIntTime->JSGet());
- };
- auto HWFLT = [this](const char* value, int length)
- {
- assert(value);
- float tmpflt = atof(value) / 10.0;
- if (m_DoseUnit.m_FLAccTime->Update(tmpflt))
- FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
- };
- auto HWFLS = [this](const char* value, int length)
- {
- assert(value);
- float tmppps = atof(value) / 10.0;
- if (m_DoseUnit.m_PPS->Update(tmppps))
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- };
- auto HWFLF = [this](const char* value, int length)
- {
- assert(value);
- FINFO("m_FLMode={$};", value);
- int tmpflf = atoi(value);
- if (m_DoseUnit.m_FLMode->Update(tmpflf))
- FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
- };
- auto HWFLX = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 2)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYON);
- FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else if (nValue == 1)
- {
- FINFO("Recv FLX1, do nothing");
- }
- else if (nValue == 0)
- {
- m_bGenBusy = false;
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYOFF);
- FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- };
- auto HWFLP = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 2)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_READY);
- FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- else if (nValue == 1)
- {
- FINFO("Recv FLP1, do nothing\n");
- }
- else if (nValue == 0)
- {
- int nFlFMode = atoi(m_DoseUnit.m_FLMode->JSGet().c_str());
- FINFO("m_DoseUnit.m_FLMode={$}- number ={$};", m_DoseUnit.m_FLMode->JSGet().c_str(), nFlFMode);
- if (nFlFMode == 2)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYOFF);
- FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_OFF);
- FINFO("m_DoseUnit.m_GenSynState={$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- m_bGenBusy = false;
- RefreshData();
- }
- };
- auto HWDS = [this](const char* value, int length)
- {
- assert(value);
- };
- auto HWFLA = [this](const char* value, int length)
- {
- assert(value);
- int tmpfla = atoi(value);
- if ( m_DoseUnit.m_ABSStatus->Update(tmpfla))
- FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
- };
- auto HWFLD = [this](const char* value, int length)
- {
- assert(value);
- };
- auto HWFLC= [this](const char* value, int length)
- {
- assert(value);
- };
- auto HWFLO = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (m_DoseUnit.m_Curve->Update(nValue))
- FireNotify(AttrKey::FLUCurve, m_DoseUnit.m_Curve->JSGet());
- };
- auto HWER = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- char tmpbuf[4] = { 0,0,0,0 };
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- if (nValue != 0)
- {
- std::unordered_map<std::string, std::string> errorMessages = {
- {"100", "AEC Back-up Timer - Exposure Terminated"},
- {"101", "AEC mAs Exceeded - Exposure Terminated"},
- {"102", "Door Interlock FERROR"},
- {"103", "Calibration Data Corrupt FERROR"},
- {"104", "AEC Data Corrupt FERROR"},
- {"105", "Receptor Data Corrupt FERROR"},
- {"106", "Tube Data Corrupt FERROR"},
- {"107", "Generator Limit Data Corrupt FERROR"},
- {"108", "mA Correction Data Corrupt FERROR"},
- {"109", "Not Enabled FERROR"},
- {"110", "AEC Feedback FERROR - No Feedback Signal Detected"},
- {"111", "EXP_SW Signal Active in Standby State"},
- {"112", "Calibration FERROR - No mA"},
- {"113", "Calibration FERROR - Maximum Filament Current Exceeded"},
- {"114", "MA During Exposure too High"},
- {"115", "MA During Exposure too Low"},
- {"116", "Generator KW Limit"},
- {"117", "Generator KV Limit"},
- {"118", "Generator MA Limit"},
- {"119", "Generator MS Limit"},
- {"120", "Generator MAS Limit"},
- {"121", "Tube KW Limit"},
- {"122", "Tube KV Limit"},
- {"123", "Tube MA Limit"},
- {"124", "Tube MAS Limit"},
- {"125", "Parameter Limit"},
- {"126", "Manually Terminated Exposure"},
- {"127", "Preparation Time-out FERROR prep time is over 30s or 60s"},
- {"128", "Prep Input Active During Initialization Phase"},
- {"129", "X-ray Input Active During Initialization Phase"},
- {"130", "No Fields Selected in AEC mode"},
- {"131", "Generator AEC Density Limit"},
- {"132", "Calibration FERROR - Manually Terminated"},
- {"133", "EEPROM Communication FERROR"},
- {"134", "RTC Communication FERROR"},
- {"135", "AEC Channel FERROR"},
- {"136", "Anode Communication FERROR"},
- {"137", "EXP_OK TimeOut"},
- {"138", "KV TimeOut"},
- {"139", "Mosfet Temperature Limit Exceeded"},
- {"140", "HU Power Limit"},
- {"141", "HU Power Warning"},
- {"142", "Small Focus Disable"},
- {"143", "Large Focus Disable"},
- {"144", "Low Speed Disable"},
- {"145", "High Speed Disable"},
- {"146", "Anode Heat Warning Exceeded"},
- {"147", "Anode Heat Limit Exceeded"},
- {"148", "KV Unbalance"},
- {"149", "Thermal Switch Interlock FERROR"},
- {"150", "Emergency FERROR"},
- {"151", "KV Correction Data Corrupt FERROR"},
- {"152", "Generator Tank Power Limit"},
- {"153", "AEC Standby Signal FERROR"},
- {"154", "DCBUS Calibration Data Corrupt FERROR"},
- {"155", "Fluoro Timer Terminated "},
- {"156", "Fluoro Timer Terminated "},
- {"157", "Power Off In X - Ray State"},
- {"158", "DAP Data Corrupt "},
- {"159", "Auto APR TimeOut "},
- {"160", "ERR_FLUORO_ABSFDBNONE"},
- {"200", "FLASH LOCK"},
- {"201", "FLASH REVID_INVALID"},
- {"202", "FLASH ADDR_INVALID"},
- {"203", "FLASH INCORRECT_PARTID"},
- {"204", "FLASH API_SILICON_MISMATCH"},
- {"205", "FLASH ERASE ERROR"},
- {"206", "FLASH FAIL_PROGRAM"},
- {"207", "FLASH FAIL_ZERO_BIT_ERROR"},
- {"208", "FLASH FAIL_VERIFY"},
- {"209", "FLASH BUSY"},
- {"210", "FLASH_PROGRM_ADDR_ERROR"},
- {"211", "UPDATA_VERSION_ERROR"},
- {"212", "UPDATA SN_ERROR"},
- {"213", "UPDATA_BYTE_COUNT_ERROR"},
- {"214", "UPDATA_CHECKSUM_ERROR"}
- };
- char ErrorCode[20];
- snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_ER_%d", nValue);
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "ER%03d", nValue);
- HWSend(temp, strlen(temp));
- int level = 1;
- auto it = errorMessages.find(tmpbuf);
- if (it != errorMessages.end())
- {
- m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
- }
- }
- else
- {
- int level = 1;
- char ErrorCode[20];
- m_MSGUnit->DelWarnMessage(ErrorCode, level, "");
- }
- };
- auto HWEL = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- char tmpbuf[3] = { 0,0,0 };
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- if (nValue != 0)
- {
- std::unordered_map<std::string, std::string> errorMessages = {
- {"001", "Generator CPU Real Time Clock FERROR"},
- {"002", "Main Contactor FERROR"},
- {"003", "Rotor Fault"},
- {"004", "DC Bus Voltage too Low"},
- {"005", "DC Bus Voltage too High"},
- {"006", "Filament Adjust FERROR"},
- {"007", "Filament PowerBoard Not Connected"},
- {"008", "Filament Short Circuit"},
- {"019", "Filament Overcurrent"},
- {"010", "Anode Overcurrent"},
- {"011", "Cathode Overcurrent"},
- {"012", "Anode Overvoltage"},
- {"013", "Cathode Overvoltage"},
- {"014", "ARC"},
- {"015", "Short Current 1"},
- {"016", "Short Current 2"},
- {"017", "Short Current A"},
- {"018", "Short Current B"}
- };
- char ErrorCode[20];
- snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_EL_%d", nValue);
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "EL%03d", nValue);
- HWSend(temp, strlen(temp));
- int level = 1;
- auto it = errorMessages.find(tmpbuf);
- if (it != errorMessages.end())
- {
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- m_MSGUnit->AddErrorMessage(ErrorCode, level, it->second.c_str());
- }
- }
- else
- {
- int level = 1;
- char ErrorCode[20];
- m_MSGUnit->DelErrorMessage(ErrorCode, level, "");
- }
- };
- auto HWEI = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- char tmpbuf[3] = { 0,0,0 };
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- if (nValue != 0)
- {
- std::unordered_map<std::string, std::string> errorMessages = {
- {"400", "Enter the service mode"},
- {"401", "Exit the service mode"},
- {"402", "Resonance Overcurrent1"},
- {"403", "Resonance Overcurrent2"},
- {"404", "Resonance Overcurrent3"},
- {"405", "Charging, Please Wait "},
- {"406", "DAC Reset "},
- {"407", "X-Rays State PowerOff "},
- {"408", "Fluoro Disable "},
- {"409", "Fluoro Timer Warning Level Exceeded"},
- {"410", "Anode Heat Warning Exceeded "},
- {"411", "MA Too Low "}
- };
- char ErrorCode[20];
- snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_EI_%d", nValue);
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "EI%03d", nValue);
- HWSend(temp, strlen(temp));
- int level = 1;
- auto it = errorMessages.find(tmpbuf);
- if (it != errorMessages.end())
- {
- //m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
- //FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
- }
- }
- else
- {
- int level = 1;
- char ErrorCode[20];
- m_MSGUnit->DelWarnMessage(ErrorCode, level, "");
- }
- };
- auto HWMSG = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- char tmpbuf[3] = { 0,0,0 };
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- if (nValue != 0)
- {
- std::unordered_map<std::string, std::string> errorMessages = {
- {"001", "Rotating anode protection parameters are incorrectly configured"},
- {"002", "Press emergency stop of high voltage generator"},
- {"003", "The first level hand brake is not triggered, and the second level hand brake is triggered"},
- {"004", "The first level hand brake is pressed during the wake - up or startup process of the high - voltage generator."},
- {"005", "The second level hand brake is pressed during the wake - up or startup process of the high - voltage generator."},
- {"006", "Low battery power of the high - voltage generator, please recharge."},
- {"007", "Anode thermal capacity exceeds the warning value."},
- {"008", "Exposure time interval is too short, please wait for exposure."},
- {"009", "Parameter adjustment is prohibited during exposure."},
- {"010", "High - voltage generator is not ready, please confirm the status."},
- {"011", "The oil tank temperature of the high - voltage generator exceeds the warning value."},
- {"012", "Training cannot be conducted in this state."},
- {"013", "The tube current of the high voltage generator is low."},
- {"014", "The PFC module of the high voltage generator works abnormally."},
- {"015", "Battery output power limits for high voltage generators."},
- {"016", "The battery of the high voltage generator is charging."},
- {"017", "The mA parameter of the high voltage generator exceeds the maximum tube value."},
- {"018", "The kV parameter of the high voltage generator exceeds the limit value."},
- {"019", "The mA parameter of the high voltage generator exceeds the limit value."},
- {"020", "The ms parameter of the high voltage generator exceeds the limit value."},
- {"021", "The mAs parameter of the high voltage generator exceeds the limit value."},
- {"022", "Filament selection parameter exceeds the limit."},
- {"023", "Anode rotation speed selection parameter exceeds the limit."},
- {"024", "The exposure technical parameters of the high voltage generator exceed the limits."},
- {"025", "AEC density parameter exceeds the limit."},
- {"026", "AEC field selection parameter exceeds the limit."},
- {"027", "AEC channel parameter exceeds the limit."},
- {"028", "AEC sensitivity parameter exceeds the limit."},
- {"029", "High - voltage generator power exceeds the limit."},
- {"030", "Tube power exceeds the limit."},
- {"031", "The frame rate parameter of the high voltage generator exceeds the limit value."},
- {"032", "Exposure parameter exceeds the high - voltage generator energy storage limit."},
- {"033", "High voltage generator battery pack alarm."},
- {"035", "Foot brake signal is pressed during the wake - up or startup process of the high - voltage generator."},
- {"036", "Cumulative fluoroscopy time alarm."},
- {"037", "The console of the high voltage generator is not connected, please open the console."},
- {"038", "Tube sleeve thermal capacity exceeds the warning value."},
- {"049", "Bus voltage of the high - voltage generator exceeds the limit."},
- {"050", "High - voltage generator does not support this exposure mode."},
- {"051", "The rotation speed of the rotating anode does not meet the exposure requirements."},
- {"052", "The second level hand brake is not pressed within the specified time."},
- {"053", "Interlock 1 is effective during the exposure process of the high - voltage generator."},
- {"054", "Timeout for feedback signal in flat panel mode."},
- {"055", "The kV establishment timeout of the high voltage generator."},
- {"056", "Anode thermal capacity exceeds the limit."},
- {"057", "Filament calibration data abnormality."},
- {"058", "Tube current is too low during training."},
- {"059", "Release hand brake prematurely during exposure."},
- {"060", "AEC feedback abnormality."},
- {"061", "Inverter temperature of the high - voltage generator exceeds the limit."},
- {"062", "kV is too low during exposure, exposure abnormality aborted."},
- {"063", "kV is too high during exposure, exposure abnormality aborted."},
- {"064", "Oil temperature of the high - voltage generator exceeds the limit."},
- {"065", "Tube sleeve thermal capacity exceeds the limit."},
- {"066", "The current exposure parameters of the high voltage generator exceed the heat capacity limit."},
- {"068", "mA is too high during exposure, exposure abnormality aborted."},
- {"069", "The DRVEN enable of the high voltage generator to establish a timeout."},
- {"070", "Interruption in communication with the rotating anode."},
- {"071", "Emergency stop is pressed during exposure."},
- {"072", "The battery pack of the high voltage generator is faulty."},
- {"073", "Resonant current exceeds the limit, exposure abnormality aborted(software)."},
- {"074", "Anode kV exceeds the limit, exposure abnormality aborted(software)."},
- {"075", "Cathode kV exceeds the limit, exposure abnormality aborted(software)."},
- {"076", "Filament current exceeds the limit(software)."},
- {"078", "Oil tank power limit of the high - voltage generator."},
- {"080", "Deviation of anode kV and cathode kV exceeds the limit, exposure abnormality aborted."},
- {"081", "Power exceeds the limit during exposure, exposure abnormality aborted."},
- {"082", "The external synchronization signal of the high voltage generator has timed out."},
- {"083", "Fan fault in high voltage generator."},
- {"084", "High voltage generator InterLock1 effective."},
- {"085", "High voltage generator InterLock2 effective."},
- {"087", "Release foot brake prematurely during exposure."},
- {"088", "Foot brake signal abnormality."},
- {"089", "The DA chip of the high voltage generator is abnormal."},
- {"090", "Timeout for cumulative fluoroscopy time."},
- {"091", "The external discharge line of the high voltage generator enables the signal to timeout."},
- {"092", "XRAYReady invalid."},
- {"093", "High voltage generator during exposure interlock 2 effective."}
- };
- char ErrorCode[20];
- snprintf(ErrorCode, sizeof(ErrorCode), "PSGHR_MSG_%d", nValue);
- int level = 1;
- /*char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "MSG%03d", nValue);
- HWSend(temp, strlen(temp));*/
- auto it = errorMessages.find(tmpbuf);
- if (it != errorMessages.end())
- {
- FINFO("WarnCode: {$}, Level: {$}, ResInfo: {$}\n", ErrorCode, level, it->second.c_str());
- m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
- }
- }
- else
- {
- int level = 1;
- char WarnCode[20]{ "" };
- m_MSGUnit->DelWarnMessage(WarnCode, level, "");
- }
- };
- //==IN==:TU0 WS1 FO0 ET0 FI010 FS001 FN0 HE000
- auto HWTU = [this](const char* value, int length) -> void
- {
- assert(value);
- FINFO("recv TU={$},len={$}", value, length);
- char tmpbuf[3] = { 0,0,0 };
- int tmpWS, tmpFO, tmpET, tmpField, tmpFilm, tmpDensity, tmpHE;
- //ws
- tmpbuf[0] = value[4];
- tmpWS = atoi(tmpbuf);
- m_DoseUnit.m_WS->Update(tmpWS);
- {
- FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
- }
- //FO
- tmpbuf[0] = value[8];
- tmpFO = atoi(tmpbuf);
- m_DoseUnit.m_Focus->Update(tmpFO);
- FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
- FINFO("Current focus:{$}, FO={$}", atoi(m_DoseUnit.m_Focus->JSGet().c_str()) ? "large focus" : "small focus", m_DoseUnit.m_Focus->JSGet().c_str());
- //ET
- tmpbuf[0] = value[12];
- tmpET = atoi(tmpbuf);
- m_DoseUnit.m_Techmode->Update(tmpET);
- FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
- //FIELD
- tmpbuf[0] = value[16];
- tmpbuf[1] = value[17];
- tmpbuf[2] = value[18];
- tmpField = atoi(tmpbuf);
- if (m_DoseUnit.m_AECField->Update(tmpField))
- FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_AECField->JSGet());
- //Film
- tmpbuf[0] = value[22];
- tmpbuf[1] = value[23];
- tmpbuf[2] = value[24];
- tmpFilm = atoi(tmpbuf);
- if (m_DoseUnit.m_AECFilm->Update(tmpFilm))
- FireNotify(AttrKey::AECFILM, m_DoseUnit.m_AECFilm->JSGet());
- //Density
- tmpbuf[0] = value[29];
- tmpbuf[1] = 0;
- tmpbuf[2] = 0;
- tmpDensity = atoi(tmpbuf);
- if (m_DoseUnit.m_AECDensity->Update(tmpDensity))
- FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
- //HE
- tmpbuf[0] = value[33];
- tmpbuf[1] = value[34];
- tmpbuf[2] = value[35];
- tmpHE = atoi(tmpbuf);
- m_DoseUnit.m_HE->Update(tmpHE);
- FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
- FINFO("parse tmpWS={$}, tmpFO={$}, tmpET={$}, tmpField={$}, tmpFilm={$}, tmpDensity={$}, tmpHE={$}", tmpWS, tmpFO, tmpET, tmpField, tmpFilm, tmpDensity, tmpHE);
- };
- auto HWST = [this](const char* value, int length)
- {
- assert(value);
- int genStatus = atoi(value);
- FINFO("genStatus={$}", genStatus);
- switch (genStatus)
- {
- case 1:
- FDEBUG("get Gen Status_1:GENSTATE {$} -> STATUS_INIT", m_DoseUnit.m_GenState->JSGet());
- if (m_isFirstHWPhase) {
- HWSend("RE", 2);
- // HWSend("RR", 2);
- HWSend("RS", 2);
- HWSend("ET?", 3);
- HWSend("ST?", 3);
- m_isFirstHWPhase = false;
- }
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_INIT))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- break;
- case 2:
- FDEBUG("get Gen Status_2:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- break;
- case 3: // Rad Preparation Phase
- /*FDEBUG("get Gen Status_3: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 4:
- FDEBUG("get Gen Status_4:PREPARE(PR1) -> 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 5:
- FDEBUG("get Gen Status_5:RAD_READY(PR2) -> X-Ray On(XR2)");
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- /*if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYON))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());*/
- break;
- case 6:
- FDEBUG("get Gen Status_6:X-Ray On(XR2) -> X-Ray Off(XR0)");
- /*if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF))
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());*/
- break;
- case 7:
- FDEBUG("get Gen Status_7:GENSTATE {$} -> STATUS_ERROR", m_DoseUnit.m_GenState->JSGet());
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- break;
- case 8:
- FDEBUG("get Gen Status_8:in Calibration");
- break;
- default:
- FDEBUG("get Gen Status:[{$}] unknown", genStatus);
- break;
- }
- };
- auto HWSR = [this](const char* value, int length)
- {
- assert(value);
- int stopReason = atoi(value);
- FINFO("stopReason={$}", stopReason);
- switch (stopReason)
- {
- case 0:
- FDEBUG("Exposure stop reason:AEC feedback voltage is too low");
- break;
- case 5:
- FDEBUG("Exposure stop reason: Stop exposure manually");
- break;
- case 6:
- FDEBUG("Exposure stop reason: door lock open");
- break;
- case 7:
- FDEBUG("Exposure stop reason:Bulb tube anode ignition");
- break;
- case 8:
- FDEBUG("Exposure stop reason:Bulb cathode ignition");
- break;
- case 9:
- FDEBUG("Exposure stop reason:The pipe is lit");
- break;
- case 10:
- FDEBUG("Exposure stop reason:KV is too low or too high");
- break;
- case 11:
- FDEBUG("Exposure stop reason:Ma too low");
- break;
- case 12:
- FDEBUG("Exposure stop reason:Set ms reached");
- break;
- case 13:
- FDEBUG("Exposure stop reason:Set mAs reached");
- break;
- case 14:
- FDEBUG("Exposure stop reason:AEC dose reached");
- break;
- default:
- FDEBUG("Exposure stop reason:default");
- break;
- }
- };
- arFrame.clear();
- arFrame.push_back(tFrameMapping("EL", 2, HWEL));
- arFrame.push_back(tFrameMapping("EI", 2, HWEI));
- arFrame.push_back(tFrameMapping("ER", 2, HWER));
- arFrame.push_back(tFrameMapping("MSG", 3, HWMSG));
- arFrame.push_back(tFrameMapping("TU", 2, HWTU));
- arFrame.push_back(tFrameMapping("EC", 2, HWNotProcess));
- arFrame.push_back(tFrameMapping("PW", 2, HWNotProcess));
-
- arFrame.push_back(tFrameMapping("KV", 2, HWKV));
- arFrame.push_back(tFrameMapping("MX", 2, HWMAS));
- arFrame.push_back(tFrameMapping("MA", 2, HWMA));
- arFrame.push_back(tFrameMapping("MS", 2, HWMS));
- arFrame.push_back(tFrameMapping("VP", 2, HWVP));
- arFrame.push_back(tFrameMapping("PA", 2, HWPA));
- arFrame.push_back(tFrameMapping("AP", 2, HWAPDOSE));
- arFrame.push_back(tFrameMapping("ET", 2, HWTechmode));
- arFrame.push_back(tFrameMapping("FO", 2, HWFocus));
- arFrame.push_back(tFrameMapping("FI", 2, HWAECField));
- arFrame.push_back(tFrameMapping("FS", 2, HWAECFilm));
- arFrame.push_back(tFrameMapping("FN", 2, HWAECDensity));
- arFrame.push_back(tFrameMapping("WS", 2, HWWS));
- arFrame.push_back(tFrameMapping("PR", 2, HWPR));
- arFrame.push_back(tFrameMapping("XR", 2, HWXR));
- arFrame.push_back(tFrameMapping("AT", 2, HWATDOSE));
- arFrame.push_back(tFrameMapping("FLK", 3, HWFLK));
- arFrame.push_back(tFrameMapping("FLM", 3, HWFLM));
- arFrame.push_back(tFrameMapping("FLW", 3, HWFLW));
- arFrame.push_back(tFrameMapping("FLI", 3, HWFLI));
- arFrame.push_back(tFrameMapping("FLT", 3, HWFLT));
- arFrame.push_back(tFrameMapping("FLS", 3, HWFLS));
- arFrame.push_back(tFrameMapping("FLF", 3, HWFLF));
- arFrame.push_back(tFrameMapping("FLP", 3, HWFLP));
- arFrame.push_back(tFrameMapping("FLX", 3, HWFLX));
- arFrame.push_back(tFrameMapping("FLA", 3, HWFLA));
- arFrame.push_back(tFrameMapping("FLD", 3, HWFLD));
- arFrame.push_back(tFrameMapping("FLC", 3, HWFLD));
- arFrame.push_back(tFrameMapping("FLO", 3, HWFLO));
- arFrame.push_back(tFrameMapping("HE", 2, HWEHE));
- arFrame.push_back(tFrameMapping("HH", 2, HWHH));
- arFrame.push_back(tFrameMapping("DA", 2, HWDAP));
- arFrame.push_back(tFrameMapping("DV", 2, HWDAP));
- arFrame.push_back(tFrameMapping("DS", 2, HWDS));
- arFrame.push_back(tFrameMapping("ST", 2, HWST));
- arFrame.push_back(tFrameMapping("SR", 2, HWSR));
- arFrame.push_back(tFrameMapping("P", 1, HWPR));
- }
- bool nsGEN::PSGHRDevice::ReConnect()
- {
- FINFO("Enter PSG_reConnect");
- m_SCF->Disconnect();
- if (!pIODriver)
- {
- FINFO("PSG_reConnect:Driver null");
- }
- else
- {
- // ��Ҫ�� pIODriver ת��Ϊ PSGHRDriver*
- PSGHRDriver* driver = dynamic_cast<PSGHRDriver*>(pIODriver.get());
- if (driver && driver->ReConnection())
- {
- FireErrorMessage(false, 1, "lost Connect");
- m_bConnectFlag = true;
- FINFO("PSG_reConnect success");
- return true;
- }
- else
- {
- FINFO("PSG_reConnect failed");
- }
- }
- return false;
- }
- int nsGEN::PSGHRDevice::GridMSMargin()
- {
- return 0;
- }
- bool nsGEN::PSGHRDevice::CalculateAppropriateMA(float& inoutMAS, float& inoutMA, float& inoutMS)
- {
- FINFO("Enter CalculateAppropriateMA:MAS[{$}],MA[{$}],MS[{$}]", inoutMAS, inoutMA, inoutMS);
- if (m_DoseUnit.m_Focus->Get() == AttrKey::FOCUS_TYPE::FOCUS_LARGE)
- {
- m_iMaxPower = PSGHR_LARGE_POWER;
- }
- else
- {
- m_iMaxPower = PSGHR_SMALL_POWER;
- }
- int currKV = 0 , tempMA = 0, tempMS = 0;
- currKV = m_DoseUnit.m_KV->Get();
- tempMA = m_iMaxPower * 1000 / currKV;
- FDEBUG("power[{$}]*1000 / KV[{$}] = MAX_MA[{$}]", m_iMaxPower, currKV, tempMA);
- if (tempMA > PSGHR_MAX_MA)
- {
- tempMA = PSGHR_MAX_MA;
- FDEBUG(" MAX_MA too big,be close to range_right[{$}]", tempMA);
- }
- else if (tempMA < PSGHR_MIN_MA)
- {
- FWARN(" MAX_MA too small,compute failed");
- return false;
- }
- for (int i = tempMA;i >= PSGHR_MIN_MA; i--)
- {
- tempMS = inoutMAS * 1000.0 / i;
- FDEBUG("MAS[{$}]*1000 / temp_MA[{$}] = temp_MS[{$}]", inoutMAS, i, tempMS);
- }
-
- FDEBUG("can not use MAS[{$}]compute Appropriate MA MS", inoutMAS);
- return false;
- }
- void nsGEN::PSGHRDevice::ReSendFailedAction(string& cmdNum)
- {
- }
- int nsGEN::PSGHRDevice::GetGenState()
- {
- if (m_DoseUnit.m_GenState != NULL)
- {
- return m_DoseUnit.m_GenState->Get();
- }
- else
- {
- return 0;
- }
- }
- int nsGEN::PSGHRDevice::LoadConfig(string configfile)
- {
- FINFO("=====================LoadConfig=========================");
- // ����ļ��Ƿ����
- std::ifstream file(configfile);
- if (!file) {
- // �ļ������ڣ�ֱ�ӷ��ؿյ�Connection����
- FINFO("Config file does not exist: {$}", configfile.c_str());
- return -1;
- }
- if (m_bIsConfigLoaded)
- {
- FINFO("Configuration already loaded.");
- return 0;
- }
- ResDataObject temp;
- temp.loadFile(configfile.c_str());
- m_GenConfig = temp["CONFIGURATION"];
- TransJsonText(m_GenConfig);
- if (m_GenConfig.GetKeyCount("loopEnable") > 0)
- {
- m_bExtraFlag = (int)m_GenConfig["loopEnable"];
- }
- if (m_GenConfig.GetKeyCount(ConfKey::CcosTubeInfo) > 0)
- {
- string tempValue = (string)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;
- }
- if (m_GenConfig.GetKeyCount("GenCtrlMode") > 0)
- {
- m_nCtlMode = (float)m_GenConfig["GenCtrlMode"];//default 2
- float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
- }
- if (m_GenConfig.GetKeyCount("USECECMD") > 0)
- {
- m_bUseCECmd = (bool)m_GenConfig["USECECMD"];
- }
- m_bIsConfigLoaded = true;
- return 0;
- }
- bool nsGEN::PSGHRDevice::EnableBucky(int nbucky)
- {
- char temp[50]{ 0 };
- snprintf(temp, sizeof(temp), "BU%1d", nbucky);
- return HWSend(temp, strlen(temp));
- }
- bool nsGEN::PSGHRDevice::ECHO(void)
- {
- return HWSend("EC", 2);
- }
- bool nsGEN::PSGHRDevice::SetABSModeNative(int nMode)
- {
- char temp[50]{ 0 };
- snprintf(temp, sizeof(temp), "FLA%1d", nMode);
- return HWSend(temp, strlen(temp));
- }
- bool nsGEN::PSGHRDevice::StartHardwareStatusThread()
- {
- if (!m_pHardwareStatusThread.joinable())
- {
- m_pHardwareStatusThread = std::thread(HardwareStatusThread, this);
- return true;
- }
- return false;
- }
- void PSGHRDevice::HardwareStatusThread(PSGHRDevice* pParam)
- {
- PSGHRDevice* pCurGen = pParam;
- if (pCurGen == NULL)
- {
- return;
- }
- pCurGen->HeartBeatFlag = true;
- int messageIndex = 0;
- int currtTime = pCurGen->m_iLoopTime;
- while (pCurGen->m_bExtraFlag)
- {
- currtTime = pCurGen->m_iLoopTime;
- Sleep(currtTime);
- if (messageIndex % 5 == 0)
- {
- pCurGen->HWSend("HE?", 3);
- Sleep(100);
- pCurGen->HWSend("ST?", 3);
- }
- messageIndex++;
- }
- }
- //-----------------------------------------------------------------------------
- // PSGHRDriver
- //-----------------------------------------------------------------------------
- nsGEN::PSGHRDriver::PSGHRDriver()
- : m_scfWrapper(std::make_shared<SCFWrapper>())
- {
- m_pAttribute.reset(new ResDataObject());
- m_pDescription.reset(new ResDataObject());
- }
- nsGEN::PSGHRDriver::~PSGHRDriver()
- {
- Disconnect();
- }
- void nsGEN::PSGHRDriver::Prepare()
- {
- // ��ʼ����־ϵͳ
- std::string strLogPath = GetProcessDirectory() + R"(/Conf/log_config.xml)";
- std::string LogHost = "DevPSGHR";
- std::string moduleName = "DevPSGHR";
- bool ret = initLogModule(
- LogHost, // ��������������־·���е�{host}ռλ����
- moduleName, // Ψһģ����
- strLogPath, // ��������
- true // �Ƿ����������̨����ѡ��
- );
- if (!ret) {
- std::cerr << "Log init failed!" << std::endl;
- return;
- }
- PSGHR_SetLocalModuleName(moduleName);
- m_SCFDllName = GetConnectDLL(m_ConfigFileName);
- FINFO("OK.");
- }
- std::string nsGEN::PSGHRDriver::DriverProbe()
- {
- FINFO("DriverProbe in \n");
- 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", "PSGHR");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Drv");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- bool nsGEN::PSGHRDriver::ReConnection()
- {
- Disconnect();
- FINFO("ReConnection:SCF Disconnect");
- ResDataObject Connection = GetConnectParam(m_ConfigFileName);
- FINFO("ReConnection:{$} \n", Connection.encode());
- auto erCode = m_scfWrapper->Connect(Connection, &PSGHRDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
- if (erCode == SCF_SUCCEED)
- {
- Sleep(1000);
- // �����������ݽ��ջص�
- m_scfWrapper->SetDataReceivedCallback([this](const char* data, uint32_t length) {
- this->Dequeue(data, length);
- });
- // �����Զ�����
- m_scfWrapper->StartAutoReceive();
- return true;
- }
- else
- {
- FINFO("ReConnection failed");
- }
- return false;
- }
- bool nsGEN::PSGHRDriver::Connect()
- {
- std::lock_guard<std::mutex> lock(m_connectionMutex);
- const auto currentState = m_connectionState.load();
- auto now = std::chrono::steady_clock::now();
- // 1. 处理可重试的失败状态
- if (currentState == ConnectionState::Failed) {
- if ((now - m_lastConnectionAttempt) >= RETRY_INTERVAL && m_connectionRetryCount < MAX_RETRY_COUNT) {
- m_connectionState = ConnectionState::Disconnected;
- }
- else {
- return false; // 不满足重试条件,直接返回
- }
- }
- // 2. 检查无效状态(正在连接/已连接但实际有效)
- if (currentState == ConnectionState::Connecting) {
- FINFO("Already connecting (type: {$})",
- m_currentConnType == ConnectionType::Serial ? "Serial" : "Ethernet");
- return true;
- }
- if (currentState == ConnectionState::Connected && m_scfWrapper && m_scfWrapper->IsConnected()) {
- FINFO("Already connected (type: {$})",
- m_currentConnType == ConnectionType::Serial ? "Serial" : "Ethernet");
- return true;
- }
- // 3. 检查重试间隔
- if (m_connectionRetryCount > 0 && (now - m_lastConnectionAttempt) < RETRY_INTERVAL) {
- FINFO("Retry in {$}s (type: {$})",
- std::chrono::duration_cast<std::chrono::seconds>(RETRY_INTERVAL - (now - m_lastConnectionAttempt)).count(),
- m_currentConnType == ConnectionType::Serial ? "Serial" : "Ethernet");
- return false;
- }
- ResDataObject connParam = GetConnectParam(m_ConfigFileName);
- std::string connPortStr = "";
- std::string connTypeStr = (std::string)connParam["type"]; // 从配置读取type字段
- m_currentConnType = (connTypeStr == "COM") ? ConnectionType::Serial : ConnectionType::Ethernet;
- if (m_currentConnType == ConnectionType::Serial)
- {
- connPortStr = (std::string)connParam["port"];// 从配置读取port字段
- // 查找配置端口在现有端口列表中的位置
- auto it = std::find(m_serialPorts.begin(), m_serialPorts.end(), connPortStr);
- if (it == m_serialPorts.end()) {
- // 配置的端口不在列表中,添加到首位
- FINFO("Configured serial port {$} not found, adding to front of port list", connPortStr);
- m_serialPorts.insert(m_serialPorts.begin(), connPortStr);
- }
- else if (it != m_serialPorts.begin()) {
- // 配置的端口存在但不在首位,移动到首位
- FINFO("Moving configured serial port {$} to front of port list", connPortStr);
- m_serialPorts.erase(it);
- m_serialPorts.insert(m_serialPorts.begin(), connPortStr);
- }
- }
- // 4. 执行连接流程
- m_connectionState = ConnectionState::Connecting;
- m_lastConnectionAttempt = now;
- std::string connInfo;
- try {
- if (m_currentConnType == ConnectionType::Serial) {
- // 串口连接:使用当前索引的端口
- std::string currentPort = m_serialPorts[m_currentSerialPortIndex];
- connParam.update("port", currentPort.c_str()); // 将当前尝试的端口写入参数
- connInfo = "Serial (port: " + currentPort + ")";
- }
- else {
- // 网口连接:直接使用配置参数
- connInfo = "Ethernet (ip: " + std::string(connParam["ip"]) + ")";
- }
- FINFO("Enter Connect ({$}), config: {$}", connInfo, connParam.encode());
- if (!m_scfWrapper->Initialize(m_SCFDllName)) {
- FINFO("Init failed: {$}", m_scfWrapper->GetLastError());
- m_connectionState = ConnectionState::Failed;
- return false;
- }
- m_scfWrapper->SetDataReceivedCallback([this](const char* data, uint32_t length) {
- this->Dequeue(data, length);
- });
- auto erCode = m_scfWrapper->Connect(connParam, &PSGHRDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
- if (erCode != SCF_SUCCEED || !m_scfWrapper->StartAutoReceive()) {
- FINFO("Connect failed (code: {$}) for {$}", erCode, connInfo);
- m_scfWrapper->Disconnect();
- m_connectionState = ConnectionState::Failed;
- // 串口连接:未遍历完所有端口时,优先切换端口重试(不计入总重试次数)
- if (m_currentConnType == ConnectionType::Serial) {
- int nextIndex = (m_currentSerialPortIndex + 1) % m_serialPorts.size();
- // 判断是否已遍历所有端口(当前索引是最后一个时,nextIndex会回到0)
- bool allPortsTried = (nextIndex == 0);
- if (!allPortsTried) {
- // 未遍历完所有端口:切换到下一端口,不增加重试计数
- m_currentSerialPortIndex = nextIndex;
- m_connectionRetryCount = 0;
- FINFO("Trying next serial port: {$}", m_serialPorts[nextIndex]);
- return false; // 触发外部线程立即尝试下一端口
- }
- else {
- // 已遍历所有端口:重置到第一个端口,增加重试计数(进入间隔等待)
- m_currentSerialPortIndex = 0;
- m_connectionRetryCount++;
- FINFO("All serial ports tried, retry count: {$}/{$}", m_connectionRetryCount, MAX_RETRY_COUNT);
- return false;
- }
- }
- // 所有端口失败(串口)或网口失败,才增加总重试计数
- m_connectionRetryCount++;
- return false;
- }
- // 连接成功:重置状态
- m_connectionState = ConnectionState::Connected;
- m_connectionRetryCount = 0;
- m_currentSerialPortIndex = 0; // 重置串口端口索引
- FINFO("Connected successfully ({$})", connInfo);
- return true;
- }
- catch (const std::exception& e) {
- FINFO("Exception for {$}: {$}", connInfo, e.what());
- m_connectionState = ConnectionState::Failed;
- m_connectionRetryCount++;
- return false;
- }
- }
- auto nsGEN::PSGHRDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
- {
- FINFO("CreateDevice in\n");
- m_pDevice = new PSGHRDevice(EventCenter, m_scfWrapper, m_ConfigFileName);
- auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDevice));
- FINFO("CreateDevice out\n");
- return dev;
- }
- void nsGEN::PSGHRDriver::FireNotify(int code, std::string key, std::string content)
- {
- EventCenter->OnNotify(code, key, content);
- }
- bool nsGEN::PSGHRDriver::isConnected() const
- {
- const auto state = m_connectionState.load();
- // 1. 连接中/实际已连接:返回true(无需重连)
- if (state == ConnectionState::Connecting || (m_scfWrapper && m_scfWrapper->IsConnected())) {
- FINFO(state == ConnectionState::Connecting ? "Connecting in progress" : "Already connected");
- return true;
- }
- // 2. 失败状态处理:判断是否允许重试
- if (state == ConnectionState::Failed) {
- auto now = std::chrono::steady_clock::now();
- const auto timeSinceLast = now - m_lastConnectionAttempt;
- // 2.1 达到最大重试次数,但超过重置间隔:重置计数,允许重新重试
- if (m_connectionRetryCount >= MAX_RETRY_COUNT && timeSinceLast >= RESET_RETRY_AFTER) {
- FINFO("Max retries reached, resetting count after {$}s",
- std::chrono::duration_cast<std::chrono::seconds>(timeSinceLast).count());
- m_connectionRetryCount = 0; // 重置计数(因mutable修饰,const函数可修改)
- }
- // 2.2 不适合重连(时间未到 或 次数仍超限):返回true阻止重连
- if (timeSinceLast < RETRY_INTERVAL || m_connectionRetryCount >= MAX_RETRY_COUNT) {
- FINFO(timeSinceLast < RETRY_INTERVAL ?
- "Retry later ({$}s)" : "Max retries, waiting {$}s to reset",
- std::chrono::duration_cast<std::chrono::seconds>(
- timeSinceLast < RETRY_INTERVAL ? RETRY_INTERVAL - timeSinceLast : RESET_RETRY_AFTER - timeSinceLast
- ).count()
- );
- return true;
- }
- }
- // 3. 其他情况(适合重连):返回false触发Connect()
- return false;
- }
- std::string nsGEN::PSGHRDriver::GetResource()
- {
- FDEBUG("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 = "";
- int nTemp = -1;
- char sstream[10] = { 0 };
- string strValue = "";
- string strType = "";
- /***
- * 1. ͨ��ѭ����������������д��pDeviceConfig
- * 2. ��¼��������ڲ�key�Լ��������ͣ����Ͷ�Ӧ�˲�ͬ�����ļ�·�������ڶ�д��ʵֵ
- ***/
- try
- {
- 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
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
- nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
- GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue);
- //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
- 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
- {
- (*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)
- {
- 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::PSGHRDriver::DeviceProbe()
- {
- FINFO("std::string nsGEN::PSGHRDriver::DeviceProbe() in\n");
- 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", "PSGHR");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Dev");
- }
- string ret = HardwareInfo.encode();
- FINFO("std::string nsGEN::PSGHRDriver::DeviceProbe() out\n");
- return ret;
- }
- void nsGEN::PSGHRDriver::Disconnect()
- {
- if (m_scfWrapper) {
- m_scfWrapper->StopAutoReceive();
- m_scfWrapper->Disconnect();
- }
- }
- void nsGEN::PSGHRDriver::Dequeue(const char* Packet, DWORD Length)
- {
- DecodeFrame(Packet, Length);
- }
- PACKET_RET nsGEN::PSGHRDriver::callbackPackageProcess(const char* RecData, uint32_t nLength, uint32_t& PacketLength)
- {
- // 输出RecData的十六进制日志
- /*if (nLength > 0)
- {
- std::string hexStr;
- hexStr.reserve(nLength * 3);
- char hexBuf[4] = { 0 };
- for (uint32_t i = 0; i < nLength; i++)
- {
- sprintf(hexBuf, "%02X ", (unsigned char)RecData[i]);
- hexStr += hexBuf;
- }
- FINFO("RecData[{$}]: {$}\n", nLength, hexStr.c_str());
- }*/
- if (nLength < 1)
- {
- FINFO("nLength < 1, nLength=={$} \n", nLength);
- return PACKET_USELESS;
- }
- for (DWORD i = 0; i < nLength - 1; i++)
- {
- if (RecData[i] == 0x02)
- {
- if (i != 0)
- {
- PacketLength = i;
- char strtemp[100] = { 0 };
- memcpy(strtemp, RecData, i);
- strtemp[PacketLength + 1] = 0;
- return PACKET_USELESS;
- }
- }
- if (RecData[i] == 0x03)
- {
- PacketLength = i + 2;
- char strtemp[100] = { 0 };
- memcpy(strtemp, RecData, i);
- strtemp[PacketLength + 1] = 0;
- FINFO("==IN==:{$}\n", strtemp);
- return PACKET_ISPACKET;
- }
- }
- return PACKET_NOPACKET;
- }
- bool nsGEN::PSGHRDriver::GetDeviceConfig(std::string& Cfg)
- {
- Cfg = m_DeviceConfigSend.encode();
- printf("GetDeviceConfig over , %s", Cfg.c_str());
- return true;
- }
- bool nsGEN::PSGHRDriver::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::PSGHRDriver::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::PSGHRDriver::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::PSGHRDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
- {
- string strTemp = pInnerKey;
- FDEBUG("Begin to change {$} item value to {$}", 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 != "")
- {
- (*resTemp)[strTemp.c_str()] = szValue;
- }
- else
- {
- *resTemp = szValue;
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("SetDriverConfigvalue crashed: {$}", e.what());
- return false;
- }
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- // GetIODriver & CreateIODriver
- //-----------------------------------------------------------------------------
- static nsGEN::PSGHRDriver gIODriver;
- extern "C" CCOS::Dev::IODriver * GetIODriver()
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * CreateIODriver()
- {
- pIODriver = new nsGEN::PSGHRDriver();
- return pIODriver;
- }
|