1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803 |
- // CCOS.Dev.GEN.REMEDYST.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include <assert.h>
- #include <functional>
- #include <unordered_map>
- #include <fstream>
- #include <set>
- #include "LogicDevice.h"
- #include "CCOS.Dev.Generator.REMEDYST.h"
- #include "Helper.JSON.hpp"
- #include "LogLocalHelper.h"
- #include "Log4CPP.h"
- using namespace std::placeholders;
- using namespace CCOS::Dev::Detail::Generator;
- namespace nsGEN = CCOS::Dev::Detail::Generator;
- static const int msTimeOut_Lock = 500;
- // Linux 环境下的 SCF 库文件名
- static const auto COM_SCFDllName = "libSerialSCF.so";
- static const auto TCP_SCFDllName = "libTcpipSCF.so";
- // 定义 Sleep 宏(如果头文件中没有定义)
- #ifndef Sleep
- #define Sleep(ms) std::this_thread::sleep_for(std::chrono::milliseconds(ms))
- #endif
- //-----------------------------------------------------------------------------
- // REMEDYSTDevice
- //-----------------------------------------------------------------------------
- float g_MA_List[] = { 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640 };
- float g_MAS_List[] = { 1, 1.25, 1.6, 2, 2.5, 3.2, 4, 5, 6.4, 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000 };
- float g_MS_List[] = { 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6400, 8000, 10000 };
- std::unordered_map<int, std::string> errorMessages = {
- {3, "Generator CPU EEPROM Data Checksum Error"},
- {4, "Generator CPU Real Time Clock error"},
- {5, "Main Contactor error"},
- {6, "Rotor Fault"},
- {7, "Filament Fault"},
- {9, "Beam_Cathode Fault"},
- {10, "Beam_Anode Fault"},
- {11, "Beam_INVA Fault"},
- {12, "Beam_INVB Fault"},
- {13, "Beam_KV Fault"},
- {14, "Beam_IR Fault"},
- {15, "Beam KV too low."},
- {16, "Beam kv unbalance"},
- {17, "Inverter is too hot"},
- {18, "Preparation Time-out Error"},
- {19, "Handle release time timed out"},
- {20, "No KV during exposure"},
- {21, "mA during exposure too high"},
- {22, "mA during exposure too low"},
- {23, "Manually Terminated Exposure"},
- {24, "AEC Back-up Timer - Exposure Terminated"},
- {25, "AEC MAS Exceeded - Exposure Terminated"},
- {27, "Anode Heat Limit"},
- {28, "Thermal Switch Interlock Error"},
- {29, "Door Interlock Error"},
- {31, "Bucky 1 Not Contact Error"},
- {33, "Bucky 2 Not Contact Error"},
- {34, "Prep Input active during Initialization Phase"},
- {35, "X-ray Input active during Initialization Phase"},
- {36, "Communication Error Console"},
- {37, "+12VDC Error"},
- {38, "-12VDC Error"},
- {43, "High Voltage Error - KV detected in non x-ray state"},
- {44, "Invalid Communication Message"},
- {45, "Communication Message Not Supported"},
- {46, "Communication Message Not Allowed"},
- {48, "Current reception is not enabled"},
- {49, "AEC channel is not enable in current reception"},
- {51, "AEC Feedback Error (No Feedback Signal Detected)"},
- {52, "High Small Focus Filament Current Error in Standby"},
- {53, "High Large Focus Filament Current Error in Standby"},
- {54, "AEC Reference out of range"},
- {55, "No Fields Selected in AEC mode"},
- {56, "No Tube Programmed"},
- {57, "AEC Stop signal in wrong state"},
- {60, "High KV Error"},
- {61, "Low KV Error"},
- {71, "Boost filament current error"},
- {72, "Preheat filament current error"},
- {73, "Film screen is invalid"},
- {74, "DC BUS voltage is too higher or too low"},
- {75, "Tube count data corrupt"},
- {82, "INV1 Error"},
- {83, "INV2 Error"},
- {84, "INV3 Error"},
- {100, "Calibration Error - Maximum mA Exceeded"},
- {101, "Calibration Error - Calibration Data Table Exceeded"},
- {102, "Calibration Error - Maximum Filament Current Exceeded"},
- {103, "Calibration Error - Manually Terminated"},
- {104, "Calibration Error - No mA"},
- {105, "Calibration Error - Minimum mA not calibrated"},
- {106, "Generator Limit, Selected Parameter Not calibrated"},
- {107, "pre-charge relay fault"},
- {108, "large filament set parameter is more than max. filament current"},
- {109, "small filament set parameter is more than max. filament current."},
- {200, "Anode Warning Level Exceeded"},
- {202, "Generator KW Limit"},
- {203, "Generator KV Limit"},
- {204, "Generator MA Limit"},
- {205, "Generator MS Limit"},
- {206, "Generator MAS Limit"},
- {207, "Tube KW Limit"},
- {208, "Tube KV Limit"},
- {209, "Tube MA Limit"},
- {210, "Tube MAS Limit"},
- {212, "Generator AEC Density Limit"},
- {213, "Invalid Communication Parameter"},
- {214, "Housing Heat Warning2 "}
- };
- static const std::set<int> specialErrorValues = { 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 20, 28, 29, 34, 35, 37, 38 };
- int g_AECFIELD_List[] = { 1, 10, 100, 11, 101, 111 };
- std::vector <float> gf_MA_List = { 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640 };
- atomic<int> nsGEN::REMEDYSTDevice::m_iLoopTime = REMEDYST_LoopDefTime;
- atomic<bool> nsGEN::REMEDYSTDevice::m_bExtraFlag = false;
- nsGEN::REMEDYSTDevice::REMEDYSTDevice(std::shared_ptr <IOEventCenter> center, std::shared_ptr<SCFWrapper> SCF, string configfile)
- : super(center)
- , superGen()
- , m_SCF(SCF)
- {
- FINFO("========================================");
- FINFO("REMEDYSTDevice Constructor Starting...");
- FINFO("Version: 0.0.1");
- FINFO("Config file: {$}", configfile.c_str());
- FINFO("========================================");
- assert(EventCenter);
- FINFO("Initializing dose unit moulds...");
- m_DoseUnit.m_KV.reset(new KVMould(0.0, 40.0, 120.0, 1.0));
- m_DoseUnit.m_MA.reset(new MAMould(0.0, 10.0, 1000.0, 0.1));
- m_DoseUnit.m_MS.reset(new MSMould(0.0, 1.0, 6300.0, 0.01));
- m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.1, 1000.0, 0.01));
- m_DoseUnit.m_Techmode.reset(new TECHMODEMould(0, 0, 2, 1));
- m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
- m_DoseUnit.m_Focus.reset(new FOCUSMould(1, 0, 1, 1));
- m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
- m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
- m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
- m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
- m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 40.0, 120.0, 1.0));
- m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 10.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_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(0, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
- m_DoseUnit.m_GenState.reset(new GENSTATEMould(4, 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_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
- m_DAP.reset(new DevDAP::DOSEMould(0.0, 0.0, 1000.0, 0.01));
- m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
- 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_Curve.reset(new FLUCurveMould(0, 0, 3, 1));
- FINFO("Dose unit moulds initialized successfully");
- m_hGenPostEvent = nullptr;
- m_bExtraFlag = true; // 启用硬件状态查询线程
- m_bIsConfigLoaded = false;
- m_strConfigPath = configfile;
- m_bMasR20 = 0;
- m_bUseEAcmd = 0;
- m_bResetActive = false;
- FINFO("Loading configuration from file: {$}", configfile.c_str());
- int loadResult = LoadConfig(configfile);
- if (loadResult != 0) {
- FERROR("Failed to load configuration file, result: {$}", loadResult);
- } else {
- FINFO("Configuration loaded successfully");
- }
- FINFO("Executing callback initialization...");
- OnCallBack();
- FINFO("Registering device interfaces...");
- Register();
- FINFO("Device interfaces registered");
- FINFO("Sending initial RE command...");
- HWSend("RE");
- FINFO("Sending initial RS command...");
- HWSend("RS");
- FINFO("Starting hardware status monitoring thread...");
- if (StartHardwareStatusThread()) {
- FINFO("Hardware status thread started successfully");
- } else {
- FERROR("Failed to start hardware status thread");
- }
- FINFO("========================================");
- FINFO("REMEDYSTDevice Constructor Completed");
- FINFO("========================================");
- }
- nsGEN::REMEDYSTDevice::~REMEDYSTDevice()
- {
- FINFO("========================================");
- FINFO("REMEDYSTDevice Destructor Starting...");
- FINFO("========================================");
- FINFO("Stopping hardware status thread...");
- m_bExtraFlag = false;
- if (m_pHardwareStatusThread.joinable()) {
- FINFO("Waiting for hardware status thread to join...");
- m_pHardwareStatusThread.join();
- FINFO("Hardware status thread joined successfully");
- } else {
- FINFO("Hardware status thread not joinable, skipping join");
- }
- FINFO("========================================");
- FINFO("REMEDYSTDevice Destructor Completed");
- FINFO("========================================");
- }
- std::string nsGEN::REMEDYSTDevice::GetGUID() const
- {
- FINFO("\n===============GetGUID : {$} ===================\n", GeneratorUnitType);
- return GeneratorUnitType;
- }
- void nsGEN::REMEDYSTDevice::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; });
- auto fun_Clear_DAP = [this](auto a, auto&)
- {
- return Clear_DAP();
- };
- Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
- auto fun_GetValue_DAP = [this](auto a, auto& b)
- {
- float value = 0;
- RET_STATUS ret = GetValue_DAP(value);
- b = ToJSON(value);
- return ret;
- };
- Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
- auto fun_StartMove = [this](auto a,auto& b)
- {
- return StartMove();
- };
- Disp->Action.Push("StartMove", fun_StartMove);
- auto fun_EndMove = [this](auto a, auto& b)
- {
- return EndMove();
- };
- Disp->Action.Push("EndMove", fun_EndMove);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::IncKV()
- {
- FINFO("KV value before calling IncKV: {$}\n", m_DoseUnit.m_KV->JSGet().c_str());
- if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("KV+");
- }
- RET_STATUS nsGEN::REMEDYSTDevice::DecKV()
- {
- FINFO("KV value before calling DecKV: {$}\n", m_DoseUnit.m_KV->JSGet().c_str());
- if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("KV-");
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetKV(float value)
- {
- FINFO("KV value before calling SetKV: {$}\n", m_DoseUnit.m_KV->JSGet().c_str());
- 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);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::IncMA()
- {
- FINFO("MA value before calling IncMA: {$}\n", m_DoseUnit.m_MA->JSGet().c_str());
- 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+");
- }
- RET_STATUS nsGEN::REMEDYSTDevice::DecMA()
- {
- FINFO("MA value before calling DecMA: {$}\n", m_DoseUnit.m_MA->JSGet().c_str());
- 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-");
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetMA(float value)
- {
- FINFO("MA value before calling SetMA: {$}\n", m_DoseUnit.m_MA->JSGet().c_str());
- 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);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::IncMS()
- {
- FINFO("MS value before calling IncMS: {$}\n", m_DoseUnit.m_MS->JSGet().c_str());
- if (!m_DoseUnit.m_MS->CanInc())
- {
- int Level = 1;
- m_MSGUnit->AddWarnMessage("REMEDYST_WARN", Level, "Generator MS Limit");
- return RET_STATUS::RET_SUCCEED;
- }
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is MAS, can't inc MS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MS+");
- }
- RET_STATUS nsGEN::REMEDYSTDevice::DecMS()
- {
- FINFO("MS value before calling DecMS: {$}\n", m_DoseUnit.m_MS->JSGet().c_str());
- if (!m_DoseUnit.m_MS->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 MS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MS-");
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetMS(float value)
- {
- FINFO("MS value before calling SetMS: {$}\n", m_DoseUnit.m_MS->JSGet().c_str());
- 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 MS");
- return RET_STATUS::RET_FAILED;
- }
- char temp[50] { 0 };
- snprintf(temp, sizeof(temp), "MS%05d", (int)(value * 10));
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::IncMAS()
- {
- FINFO("MAS value before calling IncMAS: {$}\n", m_DoseUnit.m_MAS->JSGet().c_str());
- if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (!m_DoseUnit.m_MS->CanInc())
- {
- int Level = 1;
- m_MSGUnit->AddWarnMessage("REMEDYST_WARN", Level, "Generator MS Limit");
- return RET_STATUS::RET_SUCCEED;
- }
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is not MAS, can't inc MAS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MX+");
- }
- RET_STATUS nsGEN::REMEDYSTDevice::DecMAS()
- {
- FINFO("MAS value before calling DecMAS: {$}\n", m_DoseUnit.m_MAS->JSGet().c_str());
- if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is not MAS, can't dec MAS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MX-");
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetMAS(float value)
- {
- FINFO("MAS value before calling SetMAS: {$}\n", m_DoseUnit.m_MAS->JSGet().c_str());
- if (!m_DoseUnit.m_MAS->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("\n Techmode is not MAS, can't set MAS");
- return RET_STATUS::RET_FAILED;
- }
- char temp[50] = { 0 };
- if (m_bMasR20)
- {
- snprintf(temp, sizeof(temp), "MX%06d", (int)(value * 100));
- }
- else
- {
- snprintf(temp, sizeof(temp), "MX%05d", (int)(value * 10));
- }
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetTechmode(int value)
- {
- FINFO("Techmode value before calling SetTechmode: {$}\n", m_DoseUnit.m_Techmode->JSGet().c_str());
- if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "ET%01d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetFocus(int value)
- {
- FINFO("Focus value before calling SetFocus: {$}\n", m_DoseUnit.m_Focus->JSGet().c_str());
- 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);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::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;
- char temp[50] = { 0 };
- if (value >= 0)
- {
- snprintf(temp, sizeof(temp), "FN+%01d", (int)value);
- }
- else
- {
- snprintf(temp, sizeof(temp), "FN-%01d", (int)value);
- }
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::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_AEC)
- return RET_STATUS::RET_FAILED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FI%03d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::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_AEC)
- return RET_STATUS::RET_FAILED;
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FS%03d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetWS(const string 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"];
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "WS%01d", tempws);
- return HWSend(temp);
- }
- string nsGEN::REMEDYSTDevice::WSUI2Gen(int nUIWS)
- {
- string strWS = "";
- try
- {
- if (nUIWS == AttrKey::GENWS_TYPE::TABLE) //lying: cross mode
- {
- strWS = m_GenConfig["WSTable"].encode();
- }
- else if (nUIWS == AttrKey::GENWS_TYPE::WALL) //standing mode
- {
- strWS = m_GenConfig["WSWall"].encode();
- }
- else if (nUIWS == AttrKey::GENWS_TYPE::FREE_TABLE) //standing mode
- {
- strWS = m_GenConfig["WSFree"].encode();
- }
- else if (nUIWS == AttrKey::GENWS_TYPE::TOMO) //standing mode
- {
- strWS = m_GenConfig["WSTOMO"].encode();
- }
- else if (nUIWS == AttrKey::GENWS_TYPE::CONVENTIONAL) //standing mode
- {
- strWS = m_GenConfig["WSConventional"].encode();
- }
- }
- catch (ResDataObjectExption& exp)
- {
- FERROR("Get configuration failed, {$}\n", exp.what());
- }
- FINFO("Set WS: {$},Generator workstaion: {$}\n", nUIWS, strWS);
- if (strWS == "")
- {
- strWS = "Table";
- }
- return strWS;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetAPR(const _tAPRArgs& t)
- {
- m_t = t;
- FINFO("*********************Enter SetAPR*********************");
- FINFO("t.ws={$},t.fKV={$},t.fMA={$},t.fMAS={$},t.nAECDensity={$},t.nAECField={$},t.nAECFilm={$},t.nFocus={$},t.nTechmode={$}", t.nWS,t.fKV, t.fMA, t.fMAS, t.nAECDensity, t.nAECField, t.nAECFilm, t.nFocus, t.nTechmode);
- //2
- SetKV(t.fKV);
- //3
- SetFocus(t.nFocus);
- //4
- if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_AEC)//aec
- {
- SetTechmode(t.nTechmode);
- SetAECField(t.nAECField);
- SetAECDensity(t.nAECDensity);
- SetMA(t.fMA);
- SetMS(t.fMS);
- }
- else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)//2p
- {
- SetTechmode(t.nTechmode);
- const float EPSINON = 0.000001;
- SetMAS(t.fMAS);
- }
- else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_TIME)//3p
- {
- SetTechmode(t.nTechmode);
- SetMA(t.fMA);
- SetMS(t.fMS);
- }
- HWSend("RR");
- FINFO("*********************Leave SetAPR*********************");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::QueryHE(int& value)
- {
- return HWSend("HE?");
- }
- RET_STATUS nsGEN::REMEDYSTDevice::QueryPostKV(float& value)
- {
- m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
- value = m_DoseUnit.m_PostKV->Get();
- return HWSend("AP?");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::QueryPostMA(float& value)
- {
- return HWSend("AP?");
- }
- RET_STATUS nsGEN::REMEDYSTDevice::QueryPostMS(float& value)
- {
- return HWSend("AT?");
- }
- RET_STATUS nsGEN::REMEDYSTDevice::QueryPostMAS(float& value)
- {
- value = m_DoseUnit.m_PostMAS->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::Clear_DAP()
- {
- if (m_bDAPEnable)
- {
- return HWSend("DZ");
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::GetValue_DAP(float& value)
- {
- if (m_bDAPEnable)
- {
- HWSend("DA");
- Sleep(300); //wait 300ms to get real dap value.
- value = m_DAP->Get();
- }
-
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::StartMove()
- {
- FINFO("Enter startMove");
- FINFO("end startmove");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::EndMove()
- {
- FINFO("Enter endmove");
- FINFO("end EndMove");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetGenSynState(int value)
- {
- FINFO("Enter SetGenSynState...{$} \n", value);
- //if (AttrKey::GENERATOR_RAD_XRAYON == value) //软同步,收到XR1时,子系统会变为XRAYON状态,并调用此处,然后我立刻回复XR1至发生器,然后才真正出线。
- //{
- // FINFO("SetGenSynState be call.this is soft syn mode.");
- // HWSend("XR1");
- // m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
- // FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- //}
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetGenState(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetExpMode(std::string value)
- {
- //note: when time the func be called?
- FINFO("Enter SetExpMode...{$}",value);
- m_DoseUnit.m_ExpMode->Update(value);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- //
- ////退出CBCT,更改exp mode时候强制退出cbct,因为在内endmove中,偶尔会执行不成功,很诡异。
- //SetFLFMode("0");
- //HWSend("TIC0");
- //
- //if (m_DoseUnit.m_ExpMode->JSGet() == EXPMODE_TYPE::Single)
- //{
- // FINFO("Enter SetAPR Single kv={$} ma={$}",m_t.fKV,m_t.fMA);
- // SetWS(m_DoseUnit.m_WS->JSGet());
- //
- // if (abs(m_t.fKV) == 0) //如果上层传下来为0,那么查询
- // {
- // HWSend("RKV?");
- // }
- // else
- // {
- // SetKV(m_t.fKV);
- // }
- // SetFocus(m_t.nFocus);
- // SetTechmode(m_t.nTechmode);
- // if (m_t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)//mas
- // {
- // SetMAS(m_t.fMAS);
- // }
- // else if (m_t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_AEC)//aec
- // {
- // SetAECField(m_t.nAECField);
- // SetAECFilm(m_t.nAECFilm);
- // SetAECDensity(m_t.nAECDensity);
- // SetMA(m_t.fMA);
- // SetMS(m_t.fMS);
- // }
- // else//time
- // {
- // if (abs(m_t.fMA) == 0)
- // {
- // HWSend("RMA?");
- // }
- // else
- // {
- // SetMA(m_t.fMA);
- // }
- // SetMS(m_t.fMS);
- // }
- //}
- //else if (m_DoseUnit.m_ExpMode->JSGet() == EXPMODE_TYPE::TOMO)
- //{
- // char temp[50] = { 0 };
- // sprintf_s(temp, "FLK%03d", (int)(m_DoseUnit.m_KV->Get()));
- // HWSend(temp);
- // sprintf_s(temp, "FLM%03d", (int)(10*(m_DoseUnit.m_MA->Get())));
- // HWSend(temp);
- // sprintf_s(temp, "FLS%03d", (int)(10*(m_DoseUnit.m_FrameRate->Get())));
- // FINFO("Enter SetAPR TOMO kv={$} ma={$}", m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get());
- // HWSend(temp);
- //}
- //
- ////这是老机器模式,其中是FLF2= PF. 新机器上,建议新式版本中删除.
- //char temp[50] = { 0 };
- //sprintf_s(temp, "FLF%01d", (int)(2));
- //HWSend(temp);
- ////这里有问题,如果是expmode单时,照射片的RPS必须设置为0.
- //if (EXPMODE_TYPE::Single == value)
- //{
- // FINFO("now is Single mode, send RPS0");
- // SetRPS(0);
- //}
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetFLFMode(std::string value)
- {
- FINFO("Enter SetFLFMode...,FLFMode:{$} \n", value.c_str());
- if (value == "CF")
- {
- m_DoseUnit.m_FLMode->Update(1);
- HWSend("FLF1", 4);
- SetPPS(15);
- SetPluseWidth(15);
- }
- else if (value == "PF")
- {
- if (m_DoseUnit.m_FLKV->Get() > m_fPFLimitMaxKV)
- {
- HWSend("FLK040", 6);
- }
- if (m_DoseUnit.m_FLMA->Get() > m_fPFLimitMaxMA)
- {
- HWSend("FLM100", 6);
- }
- m_DoseUnit.m_FLMode->Update(2);
- HWSend("FLF2", 4);
- SetPPS(5);
- SetPluseWidth(5);
- }
- else if (value == "HLF")
- {
-
- if (m_DoseUnit.m_FLKV->Get() < m_fHLFLimitMinKV)
- {
- HWSend("FLK080", 6);
- }
- if (m_DoseUnit.m_FLMA->Get() < m_fHLFLimitMinMA)
- {
- HWSend("FLM4000", 7);
- }
- 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;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetAPF(const _tAPFArgs& t)
- {
- FINFO("APF:FLKV={$},FLMA={$},PPS={$},WS={$},FLuType={$},ABSMode={$},DoseLever={$}", t.nFLKV, t.fFLMA, t.nPPS, t.nWS, t.nFluMode, t.nABSMode, t.nDoseLever);
- SetFluKV(t.nFLKV);
- SetFluMA(t.fFLMA);
- HWSend("RF");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::IncFluKV()
- {
- FINFO("FluKV value before calling IncFluKV: {$}\n", m_DoseUnit.m_FLKV->JSGet().c_str());
- if (!m_DoseUnit.m_FLKV->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLK+", 4);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::DecFluKV()
- {
- FINFO("FluKV value before calling DecFluKV: {$}\n", m_DoseUnit.m_FLKV->JSGet().c_str());
- if (!m_DoseUnit.m_FLKV->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLK-", 4);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetFluKV(float value)
- {
- FINFO("FluKV value before calling SetFluKV: {$}\n", m_DoseUnit.m_FLKV->JSGet().c_str());
- 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::REMEDYSTDevice::IncFluMA()
- {
- FINFO("FluMA value before calling IncFluMA: {$}\n", m_DoseUnit.m_FLMA->JSGet().c_str());
- if (!m_DoseUnit.m_FLMA->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLM+", 4);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::DecFluMA()
- {
- FINFO("FluMA value before calling DecFluMA: {$}\n", m_DoseUnit.m_FLMA->JSGet().c_str());
- if (!m_DoseUnit.m_FLMA->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLM-", 4);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetFluMA(float value)
- {
- FINFO("FluMA value before calling SetFluMA: {$}\n", m_DoseUnit.m_FLMA->JSGet().c_str());
- 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::REMEDYSTDevice::INCPPS()
- {
- if (!m_DoseUnit.m_PPS->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLS+", 4);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::DECPPS()
- {
- if (!m_DoseUnit.m_PPS->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FLS-", 4);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::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::REMEDYSTDevice::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%1d", (int)nMode);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetABSCurve(int curveNum)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::IncABSCurve()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::DecABSCurve()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::GetABSCurve()
- {
- return HWSend("FLA?", 4);
- }
- float nsGEN::REMEDYSTDevice::GetFluIntTimer()
- {
- return HWSend("FLI?", 4);
- }
- float nsGEN::REMEDYSTDevice::GetFluAccTimer()
- {
- return HWSend("FLT?", 4);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::ResetFluTimer(int ntype)
- {
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "FLR%1d", (int)ntype);
- FINFO("ReSetFluAccTimer[{$}] \n", ntype);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetFluPre(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetFluEXP(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::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::REMEDYSTDevice::SetFluDoseLever(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- void CCOS::Dev::Detail::Generator::REMEDYSTDevice::UpdateLimits(const std::string& key, float& currentValue, float defaultValue)
- {
- if (m_GenConfig.GetKeyCount(key.c_str()) > 0)
- {
- currentValue = static_cast<float>(m_GenConfig[key.c_str()]);
- }
- else
- {
- currentValue = defaultValue;
- }
- }
- void CCOS::Dev::Detail::Generator::REMEDYSTDevice::UpdateLimitsInt(const std::string& key, int& currentValue, int defaultValue)
- {
- if (m_GenConfig.GetKeyCount(key.c_str()) > 0)
- {
- currentValue = static_cast<int>(m_GenConfig[key.c_str()]);
- }
- else
- {
- currentValue = defaultValue;
- }
- }
- int CCOS::Dev::Detail::Generator::REMEDYSTDevice::GetGenState()
- {
- if (m_DoseUnit.m_GenState != NULL)
- {
- return m_DoseUnit.m_GenState->Get();
- }
- else
- {
- return 0;
- }
- }
- int CCOS::Dev::Detail::Generator::REMEDYSTDevice::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(m_strConfigPath.c_str());
- m_GenConfig = temp["CONFIGURATION"];
- TransJsonText(m_GenConfig);
- if (m_GenConfig.GetKeyCount("R20Enable") > 0)
- {
- m_bMasR20 = (bool)m_GenConfig["R20Enable"];
- }
- if (m_GenConfig.GetKeyCount("USEEACMD") > 0)
- {
- m_bUseEAcmd = (bool)m_GenConfig["USEEACMD"];
- }
- m_bIsConfigLoaded = true;
- return 0;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetEXAMMode(std::string value)
- {
- //EXAMMODE_TYPE::MANUAL
- return RET_STATUS::RET_SUCCEED;
- }
- void nsGEN::REMEDYSTDevice::HandleError(const char* value, const char* prefix, const std::string& type)
- {
- FINFO("========================================");
- FINFO("HandleError Entry");
- FINFO("Input value: {$}", value ? value : "NULL");
- FINFO("Prefix: {$}", prefix ? prefix : "NULL");
- FINFO("Type: {$}", type.c_str());
- assert(value);
- int nValue = atoi(value);
- FINFO("Parsed error value: {$}", nValue);
- if (nValue != 0)
- {
- char ErrorCode[20];
- snprintf(ErrorCode, sizeof(ErrorCode), "%s%d", prefix, nValue);
- FERROR("Error detected - Code: {$}", ErrorCode);
- int level = 1;
- auto it = errorMessages.find(nValue);
- FINFO("Looking up error message for code {$}", nValue);
- if (it != errorMessages.end())
- {
- FINFO("Error message found: {$}", it->second.c_str());
- char temp[50] = { 0 };
- snprintf(temp, sizeof(temp), "%s%03d", type.c_str(), nValue);
- FINFO("Sending acknowledgement command: {$}", temp);
- HWSend(temp);
- if (std::find(m_localWarnlist.begin(), m_localWarnlist.end(), ErrorCode) == m_localWarnlist.end())
- {
- FINFO("Error code not in local warning list, adding...");
- if (specialErrorValues.find(nValue) != specialErrorValues.end())
- {
- FERROR("Special error detected - Adding as ERROR: {$}", ErrorCode);
- m_MSGUnit->AddErrorMessage(ErrorCode, level, it->second.c_str());
- }
- else
- {
- FWARN("Adding as WARNING: {$}", ErrorCode);
- m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
- }
- m_localWarnlist.push_back(ErrorCode);
- FINFO("Error code added to local warning list (list size: {$})", m_localWarnlist.size());
- }
- else
- {
- FINFO("ErrorCode {$} is already in the local warning list, skipping", ErrorCode);
- }
- }
- else
- {
- // 处理未知错误码
- FWARN("Unknown error code: {$}", nValue);
- if (std::find(m_localWarnlist.begin(), m_localWarnlist.end(), ErrorCode) == m_localWarnlist.end())
- {
- FINFO("Adding unknown error code to warning list");
- m_localWarnlist.push_back(ErrorCode);
- m_MSGUnit->AddWarnMessage(ErrorCode, level, "Unknown error");
- }
- }
- FINFO("========================================");
- }
- else
- {
- FINFO("Error value is 0, clearing all errors and warnings");
- int level = 1;
- char EmptyCode[10] = { "" };
- m_MSGUnit->DelWarnMessage(EmptyCode, level, "");
- m_MSGUnit->DelErrorMessage(EmptyCode, level, "");
- FINFO("All errors and warnings cleared");
- FINFO("========================================");
- }
- }
- RET_STATUS nsGEN::REMEDYSTDevice::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);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetFrameRate(float frameRate)
- {
- m_DoseUnit.m_FrameRate->Update(frameRate); //this variable should be set when in oncallback.
-
- char temp[50]{ 0 };
- snprintf(temp, sizeof(temp), "FLS%03d", int(frameRate*10));
- return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetRPS(int rps)
- {
- return RET_STATUS::RET_SUCCEED;
- //char temp[50]{ 0 };
- //sprintf_s(temp, "RPS%03d", rps * 10);
- //return HWSend(temp);
- }
- RET_STATUS nsGEN::REMEDYSTDevice::RefreshData()
- {
- HWSend("RR");
- HWSend("RS");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetExpEnable()
- {
- FINFO("========================================");
- FINFO("SetExpEnable Entry");
- FINFO("UseEAcmd flag: {$}", m_bUseEAcmd);
- if (m_bUseEAcmd)
- {
- FINFO("Sending EA111 command (Exposure Enable)");
- RET_STATUS ret = HWSend("EA111");
- FINFO("EA111 command result: {$}", ret == RET_STATUS::RET_SUCCEED ? "SUCCESS" : "FAILED");
- FINFO("========================================");
- return ret;
- }
- FINFO("EA command disabled, skipping");
- FINFO("========================================");
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- return RET_STATUS::RET_SUCCEED;
- //return HWSend("EXB1");
- }
- RET_STATUS nsGEN::REMEDYSTDevice::SetExpDisable()
- {
- FINFO("========================================");
- FINFO("SetExpDisable Entry");
- FINFO("UseEAcmd flag: {$}", m_bUseEAcmd);
- if (m_bUseEAcmd)
- {
- FINFO("Sending EA000 command (Exposure Disable)");
- RET_STATUS ret = HWSend("EA000");
- FINFO("EA000 command result: {$}", ret == RET_STATUS::RET_SUCCEED ? "SUCCESS" : "FAILED");
- } else {
- FINFO("EA command disabled, skipping");
- }
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- FINFO("Generator state: {$}", m_DoseUnit.m_GenState->JSGet().c_str());
- FINFO("========================================");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::REMEDYSTDevice::Reset()
- {
- FINFO("========================================");
- FINFO("Reset Entry");
- m_bResetActive = true;
- FINFO("Reset active flag set to true");
- int level = 0;
- if (!m_localWarnlist.empty())
- {
- FINFO("Clearing local warning list (size: {$})", m_localWarnlist.size());
- m_localWarnlist.clear();
- FINFO("Local warning list cleared successfully");
- m_MSGUnit->DelErrorMessage("0", level, "clear all errors");
- m_MSGUnit->DelWarnMessage("0", level, "clear all Warning");
- FINFO("Sending RE command (Reset)");
- RET_STATUS ret = HWSend("RE");
- FINFO("Reset command result: {$}", ret == RET_STATUS::RET_SUCCEED ? "SUCCESS" : "FAILED");
- FINFO("========================================");
- return ret;
- }
- else
- {
- FINFO("Local warning list is empty, nothing to clear");
- FINFO("========================================");
- return RET_STATUS::RET_SUCCEED;
- }
- }
- RET_STATUS nsGEN::REMEDYSTDevice::HWSend(const char* strCommand, int length, bool reSend, int nTimeOut)
- {
- if (!m_SCF) {
- FINFO("Failed - Serial communication interface not initialized");
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN))
- {
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- FINFO("Generator status updated to {$}", static_cast<int>(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN));
- }
- return RET_STATUS::RET_FAILED;
- }
- if (!m_SCF->IsConnected())
- {
- FERROR("Failed - Device not connected");
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN))
- {
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- FINFO("Generator status updated to {$}", static_cast<int>(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN));
- }
- return RET_STATUS::RET_FAILED;
- }
- // 使用传入的length参数,如果为0则用strlen计算
- int cmdLen = (length > 0) ? length : 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; // 实际发送的总长度
- // 打印完整数据包的十六进制和ASCII(含ETX和CheckSum)便于调试
- std::string hexStr;
- std::string asciiStr;
- hexStr.reserve(totalLen * 3);
- asciiStr.reserve(cmdLen + 10);
- 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 += "...";
- // 提取可打印的ASCII字符串(命令部分,不包括ETX和CheckSum)
- for (int i = 0; i < cmdLen; i++) {
- char ch = strCommand[i];
- if (ch >= 32 && ch <= 126) { // 可打印字符
- asciiStr += ch;
- } else {
- asciiStr += '.'; // 不可打印字符用'.'表示
- }
- }
- asciiStr += " + ETX + CKS"; // 标注后面的控制字符
- FINFO("==OUT== Packet[{$}]: HEX=[{$}] ASCII=[{$}]\n", totalLen, hexStr.c_str(), asciiStr.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;
- }
- //-----------------------------------------------------------------------------
- // ProcessCmd
- //-----------------------------------------------------------------------------
- void nsGEN::REMEDYSTDevice::FireNotify(std::string key, std::string content)
- {
- EventCenter->OnNotify(1, key, content);
- }
- 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);
- //strHead[0] = 0x02;
- 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);
- void nsGEN::REMEDYSTDevice::OnCallBack()
- {
- auto HWNotProcess = [](const char* value, int length) -> void
- {
- printf("\n This commands didn't need to process!\n");
- FINFO("\n This commands didn't need to process!\n");
- };
- //==IN==:KV070 MA00320 MS00063 MX00036 sometimes : this long str appear. so must deal with it
- auto HWKV = [this](const char* value, int length) -> void
- {
- assert(value);
- FINFO("hwkv={$},len={$}",value, length);
- if (length > 20) //if length more than 20, it must be a long string like :070 MA00320 MS00063 MX00036
- {
- //loop the long string to find kv ma ms mas
- int tmpkv;
- float tmpma, tmpms, tmpmx;
- char tmpbuf[6]{ 0,0,0,0,0,0 };
- //kv
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- tmpkv = atoi(tmpbuf);
- if (m_DoseUnit.m_KV->Update(tmpkv))
- FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
- //ma
- tmpbuf[0] = value[6];
- tmpbuf[1] = value[7];
- tmpbuf[2] = value[8];
- tmpbuf[3] = value[9];
- tmpbuf[4] = value[10];
- tmpma = atof(tmpbuf)/10.0;
- /*if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_TIME)
- {
- FireNotify(AttrKey::MA, to_string(0));
- }
- else
- {*/
- m_DoseUnit.m_MA->Update(tmpma);
- FireNotify(AttrKey::MA, m_DoseUnit.m_MA->JSGet());
- /*}*/
- //ms
- tmpbuf[0] = value[14];
- tmpbuf[1] = value[15];
- tmpbuf[2] = value[16];
- tmpbuf[3] = value[17];
- tmpbuf[4] = value[18];
- tmpms = atof(tmpbuf) / 10.0;
- /*if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_TIME)
- {
- FireNotify(AttrKey::MS, to_string(0));
- }
- else
- {*/
- m_DoseUnit.m_MS->Update(tmpms);
- FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
- /*}*/
- //mx
- tmpbuf[0] = value[22];
- tmpbuf[1] = value[23];
- tmpbuf[2] = value[24];
- tmpbuf[3] = value[25];
- tmpbuf[4] = value[26];
- tmpbuf[5] = value[27];
- if (m_bMasR20)
- {
- tmpmx = atof(tmpbuf) / 100.0;
- }
- else
- {
- tmpmx = atof(tmpbuf) / 10.0;
- }
- /*
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_TIME)
- {
- FireNotify(AttrKey::MAS, to_string(0));
- }
- else
- {*/
- m_DoseUnit.m_MAS->Update(tmpmx);
- FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
- /*}*/
- FINFO("tmpkv={$} tmpma={$}, tmpms={$}, tmpmx={$};", tmpkv, tmpma, tmpms, tmpmx);
- }
- else
- {
- int tmpkv = atoi(value);
- if (m_DoseUnit.m_KV->Update(tmpkv))
- FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
- }
- };
- //==IN==:TU0 WS1 FO0 ET0 FI010 FS001 FN 0 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());
- switch (tmpET)
- {
- 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;
- }
- //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);
- if (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 HWEC = [this](const char* value, int length) -> void
- {
- assert(value);
- FINFO("recv EC{$}",value);
- };
- auto HWST = [this](const char* value, int length) -> void
- {
- assert(value);
- int genStatus = atoi(value);
- if (m_bResetActive)
- {
- m_bResetActive = false;
- //clear all error list
- int level = 1;
- for (auto errorStr : m_localErrorlist)
- {
- m_MSGUnit->DelErrorMessage(errorStr.c_str(), level, "");
- FINFO("clear error = {$}\n", errorStr);
- }
- m_localErrorlist.clear();
- }
- switch (genStatus)
- {
- case 0:
- FDEBUG("Get Gen Status_1:GENSTATE {$}", m_DoseUnit.m_GenState->JSGet());
- FINFO("Initialization Phase\n");
- if (1 == m_bUseEAcmd)
- {
- static int nST001Count = 0;
- if (0 == nST001Count)//ִֻ
- {
- FINFO("recv st001,and feedback EA000,just once");
- HWSend("EA000");
- nST001Count = 1;
- }
- }
- break;
- case 1:
- FDEBUG("Get Gen Status_2:GENSTATE {$} -> Standby Phase", 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 2:
- FINFO("Rad Preparation Phase\n");
- break;
- case 3:
- FINFO("Rad Ready Phase\n");
- break;
- case 4:
- FDEBUG("Get Gen Status_10:GENSTATE {$} -> GENERATOR_STATUS_EXP", m_DoseUnit.m_GenSynState->JSGet());
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- break;
- case 7:
- FDEBUG("Get Gen Status_7:GENSTATE {$} -> Error Phase", 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;
- default:
- FDEBUG("Get Gen Status:[{$}] unknown", genStatus);
- break;
- }
- };
- auto HWMAS = [this](const char* value, int length)
- {
- assert(value);
- float fmas = 0.0f;
- if (m_bMasR20)
- {
- fmas = atof(value) / 100.0;
- }
- else
- {
- fmas = atof(value) / 10.0;
- }
- /*if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_TIME)
- {
- FireNotify(AttrKey::MAS, to_string(0));
- }
- else
- {*/
- 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;
- /*if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_TIME)
- {
- FireNotify(AttrKey::MA, to_string(0));
- }
- else
- {*/
- 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) / 10.0;
- /*if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_TIME)
- {
- FireNotify(AttrKey::MS, to_string(0));
- }
- else
- {*/
- m_DoseUnit.m_MS->Update(fms);
- FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
- /*}*/
- };
- auto HWFocus = [this](const char* value, int length)
- {
- assert(value);
- int nfous = atoi(value);
- 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);
- int nvalue = atoi(value);
- if (m_DoseUnit.m_AECFilm->Update(nvalue))
- FireNotify(AttrKey::AECFILM, m_DoseUnit.m_AECFilm->JSGet());
- };
- auto HWAECDensity = [this](const char* value, int length)
- {
- assert(value);
- int nvalue = atoi(value);
- if (m_DoseUnit.m_AECDensity->Update(nvalue))
- FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
- };
- auto HWWS = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (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)
- {
- FINFO("The high voltage generator enters the exposure preparation stage");
- HWSend("PR2");
- }
- else if (nValue == 1)
- {
- HWSend("PR1");
- m_iLoopTime = REMEDYST_LoopExpTime;
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE))
- {
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Generator exposure process status:{$};", "GENERATOR_RAD_PREPARE");
- }
- }
- else if (nValue == 0)
- {
- HWSend("PR0");
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF));
- {
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Generator exposure process status:{$};", "GENERATOR_RAD_OFF");
- FINFO("HWPR m_DoseUnit.m_GenSynState->JSGet()={$}", m_DoseUnit.m_GenSynState->JSGet().c_str());
- RefreshData();
- }
- }
- };
- auto HWXR = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 1)
- {
- HWSend("XR1");
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY))
- {
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Generator exposure process status:{$};", "GENERATOR_RAD_READY");
- }
- }
- else if (nValue == 2)
- {
- HWSend("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(AttrKey::GENERATOR_RAD_XRAYON))
- {
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Generator exposure process status:{$};", "GENERATOR_RAD_XRAYON");
- }
- }
- else if (nValue == 0)
- {
- HWSend("XR0");
- if(m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF));
- {
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Generator exposure process status:{$};", "GENERATOR_RAD_XRAYOFF");
- FINFO("HWXR m_DoseUnit.m_GenSynState->JSGet()={$}", m_DoseUnit.m_GenSynState->JSGet().c_str());
- HWSend("AP?");
- Sleep(30);
- HWSend("AT?");
- Sleep(30);
- }
- }
- };
- auto HWVPDOSE = [this](const char* value, int length)//mas
- {
- 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 HWAPDOSE = [this](const char* value, int length)//mas
- {
- assert(value);
- m_DoseUnit.m_PostMAS->Update(atof(value) / 10.0);
- FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
- m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
- FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
- FINFO("Actual exposure parametersMAS:{$}", m_DoseUnit.m_PostMAS->JSGet().c_str());
- };
- auto HWATDOSE = [this](const char* value, int length)
- {
- assert(value);
- m_DoseUnit.m_PostMS->Update(atof(value) / 10.0);
- FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
- m_DoseUnit.m_PostMA->Update(m_DoseUnit.m_PostMAS->Get() * 1000.0 / m_DoseUnit.m_PostMS->Get());
- FireNotify(m_DoseUnit.m_PostMA->GetKey(), m_DoseUnit.m_PostMA->JSGet());
- FINFO("Actual exposure parametersMS:{$}", m_DoseUnit.m_PostMS->JSGet().c_str());
- };
- auto HWDAPST = [this](const char* value, int length)
- {
- assert(value);
- int dapStatus = atoi(value);
- if (dapStatus == 1)
- {
- m_bDAPEnable = true;
- m_bAKEnable = false;
- }
- else if (dapStatus == 2)
- {
- m_bDAPEnable = false;
- m_bAKEnable = true;
- }
- else if (dapStatus == 3)
- {
- m_bDAPEnable = true;
- m_bAKEnable = true;
- }
- else
- {
- m_bDAPEnable = false;
- m_bAKEnable = false;
- }
- };
- auto HWDT = [this](const char* value, int length)
- {
- assert(value);
- int dapStatus = atoi(value);
- if (dapStatus == 0)
- {
- m_bDAPEnable = false;
- FINFO("DAP test failed");
- }
- else if (dapStatus == 1)
- {
- m_bDAPEnable = true;
- FINFO("DAP test passed");
- }
- else if (dapStatus == 2)
- {
- m_bDAPEnable = true;
- FINFO("DAP test in progress.");
- }
- };
- auto HWDAP = [this](const char* value, int length)
- {
- assert(value);
- //m_DoseUnit.->Update(atof(value));
- //FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
- //SetEvent(m_hGenPostEvent);
- m_DAP->Update(atof(value)); //should push to subsystem.......
-
- };
- auto HWEL = [this](const char* value, int length)
- {
- HandleError(value, "REMEDY_EL_", "EL");
- };
- auto HWER = [this](const char* value, int length)
- {
- HandleError(value, "REMEDY_ER_", "ER");
- };
- auto HWWARN = [this](const char* value, int length)
- {
- HandleError(value, "REMEDY_WARN_", "EW");
- };
- auto HWEHE = [this](const char* value, int length)
- {
- assert(value);
- int nhe = atoi(value);
- if (m_DoseUnit.m_HE->Update(nhe))
- FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
- };
- //075 FLM100 FLI000 FLT006 FLF2 FLA0 FLS060 FLZ0 FLD0
- auto HWFLK = [this](const char* value, int length)
- {
- assert(value);
- if (length > 20) // Check if length is more than 20
- {
- FINFO("HWFLK={$}", value);
- int tmpflk, tmpflf, tmpfla, tmpfld, tmpflo;
- float tmpflm, tmpfli, tmpflt, tmpfls, tmpflw;
- char tmpbuf[3]{ 0, 0, 0 };
- //flk
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- tmpflk = atoi(tmpbuf);
- if (m_DoseUnit.m_FLKV->Update(tmpflk))
- FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
- // flm
- tmpbuf[0] = value[7];
- tmpbuf[1] = value[8];
- tmpbuf[2] = value[9];
- tmpflm = atof(tmpbuf) / 10.0;
- if (m_DoseUnit.m_FLMA->Update(tmpflm))
- FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
- // fli
- tmpbuf[0] = value[14];
- tmpbuf[1] = value[15];
- tmpbuf[2] = value[16];
- tmpfli = atof(tmpbuf) / 10.0;
- if (m_DoseUnit.m_FLIntTime->Update(tmpfli))
- FireNotify(AttrKey::FLUIntTime, m_DoseUnit.m_FLIntTime->JSGet());
- // flt
- tmpbuf[0] = value[21];
- tmpbuf[1] = value[22];
- tmpbuf[2] = value[23];
- tmpflt = atof(tmpbuf) / 10.0;
- if (m_DoseUnit.m_FLAccTime->Update(tmpflt))
- FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
- // flf
- tmpbuf[0] = value[28];
- tmpbuf[1] = 0;
- tmpbuf[2] = 0;
- tmpflf = atoi(tmpbuf);
- if (m_DoseUnit.m_FLMode->Update(tmpflf))
- FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
- // fla
- tmpbuf[0] = value[33];
- tmpfla = atoi(tmpbuf);
- if (m_DoseUnit.m_ABSStatus->Update(tmpfla))
- FireNotify(AttrKey::FLUABSStatus, m_DoseUnit.m_ABSStatus->JSGet());
- // fls
- tmpbuf[0] = value[38];
- tmpbuf[1] = value[39];
- tmpbuf[2] = value[40];
- tmpfls = atof(tmpbuf) / 10.0;
- if (m_DoseUnit.m_PPS->Update(tmpfls))
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- // fld
- tmpbuf[0] = value[50];
- tmpbuf[1] = 0;
- tmpbuf[2] = 0;
- tmpfld = atoi(tmpbuf);
- if (m_DoseUnit.m_DoseLevel->Update(tmpfld))
- FireNotify(AttrKey::FLUDoseLevel, m_DoseUnit.m_DoseLevel->JSGet());
- FINFO("tmpflk={$}, tmpflf={$}, tmpfla={$}, tmpfld={$}, tmpflm={$}, tmpfli={$}, tmpflt={$}, tmpfls={$};", tmpflk, tmpflf, tmpfla, tmpfld, tmpflm, tmpfli, tmpflt, tmpfls);
- }
- else
- {
- if (m_DoseUnit.m_FLKV->Update(atof(value)))
- FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
- }
- };
- auto HWFLM = [this](const char* value, int length)
- {
- assert(value);
- float tmpflm = atof(value) / 10.0;
- if (m_DoseUnit.m_FLMA->Update(tmpflm))
- FireNotify(AttrKey::FLUMA, m_DoseUnit.m_FLMA->JSGet());
- };
- auto HWFLS = [this](const char* value, int length)
- {
- assert(value);
- FINFO("HWFLS={$}", value);
- float tmppps = atof(value) / 10.0;
- if (m_DoseUnit.m_PPS->Update(tmppps))
- FireNotify(AttrKey::FLUPPS, m_DoseUnit.m_PPS->JSGet());
- };
- auto HWFLX = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 0)
- {
- HWSend("FLX0");
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_XRAYOFF))
- {
- FINFO("Generator exposure process status{$};", "GENERATOR_FLU_XRAYOFF");
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- }
- else
- {
- HWSend("FLX1");
- 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(AttrKey::GENERATOR_FLU_XRAYON))
- {
- FINFO("Generator exposure process status{$};", "GENERATOR_FLU_XRAYON");
- 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 == 0)
- {
- if (m_iLoopTime == REMEDYST_LoopExpTime)
- {
- if ((int)m_GenConfig["loopTime"] >= 100)
- {
- m_iLoopTime = (int)m_GenConfig["loopTime"];
- }
- else
- m_iLoopTime = REMEDYST_LoopDefTime;
- FDEBUG("reduction loopTime[{$}]->[{$}]", REMEDYST_LoopExpTime, m_iLoopTime.load());
- }
- HWSend("FLP0");
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_OFF))
- {
- FINFO("{$};", "GENERATOR_FLU_OFF");
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- RefreshData();
- }
- else
- {
- m_iLoopTime = REMEDYST_LoopExpTime;
- HWSend("FLP1");
- if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_FLU_READY))
- {
- FINFO("Generator exposure process status{$};", "GENERATOR_FLU_READY");
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- }
- };
- auto HWFLF = [this](const char* value, int length)
- {
- assert(value);
- FINFO("HWFLF={$};", value);
- int tmpflf = atoi(value);
- if (m_DoseUnit.m_FLMode->Update(tmpflf))
- FireNotify(AttrKey::FLUMode, m_DoseUnit.m_FLMode->JSGet());
- };
- 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 HWFLW = [this](const char* value, int length)
- {
- assert(value);;
- float tmpflms = atof(value) / 100.0;
- if (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());
- };
- arFrame.clear();
-
- arFrame.push_back(tFrameMapping("KV", 2, HWKV));
- arFrame.push_back(tFrameMapping("TU", 2, HWTU));
- 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("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("VP", 2, HWVPDOSE));
- arFrame.push_back(tFrameMapping("AP", 2, HWAPDOSE));
- arFrame.push_back(tFrameMapping("AT", 2, HWATDOSE));
- arFrame.push_back(tFrameMapping("EL", 2, HWEL));
- arFrame.push_back(tFrameMapping("ER", 2, HWER));
- arFrame.push_back(tFrameMapping("EW", 2, HWWARN));
- arFrame.push_back(tFrameMapping("HE", 2, HWEHE));
- arFrame.push_back(tFrameMapping("FLK", 3, HWFLK));
- arFrame.push_back(tFrameMapping("FLM", 3, HWFLM));
- 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("FLW", 3, HWFLW));
- arFrame.push_back(tFrameMapping("FLI", 3, HWFLI));
- arFrame.push_back(tFrameMapping("FLT", 3, HWFLT));
- 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("ST", 2, HWST));
- arFrame.push_back(tFrameMapping("EC", 2, HWEC));
- arFrame.push_back(tFrameMapping("DS", 2, HWDAPST)); //dap status
- arFrame.push_back(tFrameMapping("DA", 2, HWDAP)); //dap value
- arFrame.push_back(tFrameMapping("DT", 2, HWDT)); //test dap
- }
- bool nsGEN::REMEDYSTDevice::StartHardwareStatusThread()
- {
- FINFO("========================================");
- FINFO("Starting Hardware Status Thread...");
- if (!m_pHardwareStatusThread.joinable())
- {
- FINFO("Creating new hardware status thread");
- m_pHardwareStatusThread = std::thread(HardwareStatusThread, this);
- FINFO("Hardware status thread created successfully");
- FINFO("========================================");
- return true;
- }
- FWARN("Hardware status thread already running");
- FINFO("========================================");
- return false;
- }
- void nsGEN::REMEDYSTDevice::HardwareStatusThread(REMEDYSTDevice* pParam)
- {
- FINFO("========================================");
- FINFO("HardwareStatusThread Entry");
- FINFO("========================================");
- REMEDYSTDevice* pCurGen = pParam;
- if (pCurGen == NULL)
- {
- FERROR("HardwareStatusThread: pParam is NULL, exiting thread");
- return;
- }
- int currtTime = pCurGen->m_iLoopTime;
- int messageIndex = 0;
- int loopCount = 0;
- FINFO("Hardware status monitoring started");
- FINFO("Initial loop time: {$} ms", currtTime);
- while (pCurGen->m_bExtraFlag)
- {
- // 检查循环时间是否变化
- if (currtTime != pCurGen->m_iLoopTime)
- {
- FINFO("Loop time changed from {$} ms to {$} ms", currtTime, pCurGen->m_iLoopTime.load());
- currtTime = pCurGen->m_iLoopTime;
- }
- Sleep(currtTime);
- loopCount++;
- // 每10次循环打印一次统计信息
- if (loopCount % 10 == 0)
- {
- FINFO("Hardware status thread loop count: {$}", loopCount);
- }
- // 发送不同的信息,通过messageIndex循环
- switch (messageIndex)
- {
- case 0:
- FINFO("Sending HE? query (Heat Exchanger status)");
- pCurGen->HWSend("HE?");
- break;
- case 1:
- FINFO("Sending ST query (Status)");
- pCurGen->HWSend("ST");
- break;
- default:
- FERROR("Unexpected messageIndex: {$}", messageIndex);
- break;
- }
- // 更新messageIndex以便下一次发送不同的信息
- messageIndex = (messageIndex + 1) % 2;
- }
- FINFO("========================================");
- FINFO("Hardware status thread stopping...");
- FINFO("Total loop count: {$}", loopCount);
- FINFO("HardwareStatusThread Exit");
- FINFO("========================================");
- }
- //-----------------------------------------------------------------------------
- // REMEDYSTDriver
- //-----------------------------------------------------------------------------
- nsGEN::REMEDYSTDriver::REMEDYSTDriver()
- : m_scfWrapper(std::make_shared<SCFWrapper>())
- {
- }
- nsGEN::REMEDYSTDriver::~REMEDYSTDriver()
- {
- Disconnect();
- }
- auto nsGEN::REMEDYSTDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
- {
- FINFO("CreateDevice in\n");
-
- m_pDevice = new REMEDYSTDevice(EventCenter, m_scfWrapper, m_ConfigFileName);
- auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDevice));
- FINFO("CreateDevice out\n");
- return dev;
- }
- void nsGEN::REMEDYSTDriver::FireNotify(int code, std::string key, std::string content)
- {
- EventCenter->OnNotify(code, key, content);
- }
- void nsGEN::REMEDYSTDriver::Prepare()
- {
- FINFO("========================================");
- FINFO("REMEDYSTDriver::Prepare() Starting...");
- FINFO("========================================");
- // 初始化日志系统
- std::string strLogPath = GetProcessDirectory() + R"(/Conf/log_config.xml)";
- std::string LogHost = "DevREMEDYST";
- std::string moduleName = "DevREMEDYST";
- FINFO("Initializing log module...");
- FINFO("Log config path: {$}", strLogPath.c_str());
- FINFO("Log host: {$}", LogHost.c_str());
- FINFO("Module name: {$}", moduleName.c_str());
- bool ret = initLogModule(
- LogHost, // 主机名(用于日志路径中的{host}占位符)
- moduleName, // 唯一模块名
- strLogPath, // 配置文件路径
- true // 是否输出到控制台(可选)
- );
- if (!ret) {
- std::cerr << "Log init failed!" << std::endl;
- FERROR("Failed to initialize log module");
- return;
- }
- FINFO("Log module initialized successfully");
- Remedy_SetLocalModuleName(moduleName);
- FINFO("Getting connection DLL from config: {$}", m_ConfigFileName.c_str());
- m_SCFDllName = GetConnectDLL(m_ConfigFileName);
- FINFO("SCF DLL name: {$}", m_SCFDllName.c_str());
- FINFO("Calling parent Prepare()...");
- super::Prepare();
- FINFO("========================================");
- FINFO("REMEDYSTDriver::Prepare() Completed");
- FINFO("========================================");
- }
- bool DATA_ACTION nsGEN::REMEDYSTDriver::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;
- }
- }
- void nsGEN::REMEDYSTDriver::Disconnect()
- {
- FINFO("========================================");
- FINFO("REMEDYSTDriver::Disconnect() Entry");
- if (m_scfWrapper) {
- FINFO("Stopping auto receive...");
- m_scfWrapper->StopAutoReceive();
- FINFO("Auto receive stopped");
- FINFO("Disconnecting SCF wrapper...");
- m_scfWrapper->Disconnect();
- FINFO("SCF wrapper disconnected");
- m_connectionState = ConnectionState::Disconnected;
- FINFO("Connection state set to Disconnected");
- } else {
- FWARN("SCF wrapper is null, nothing to disconnect");
- }
- FINFO("REMEDYSTDriver::Disconnect() Completed");
- FINFO("========================================");
- }
- bool nsGEN::REMEDYSTDriver::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::REMEDYSTDriver::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", "REMEDYST");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Drv");
- }
- string ret = HardwareInfo.encode();
- FINFO("DriverProbe out \n");
- return ret;
- }
- std::string nsGEN::REMEDYSTDriver::GetResource()
- {
- ResDataObject temp;
- if (!temp.loadFile(m_ConfigFileName.c_str()))
- return std::string();
- auto r_config = temp["CONFIGURATION"];
- for (auto& Item : m_ConfigInfo)
- {
- string key = Item.GetKey();
- if (key == ConfKey::CcosGeneratorType)
- {
- Item.SetCurrentValue(((string)r_config["VendorID"]).c_str());
- }
- else if (key == ConfKey::CcosGeneratorModel)
- {
- Item.SetCurrentValue(((string)r_config["ProductID"]).c_str());
- }
- else if (key == ConfKey::CcosWSTable || key == ConfKey::CcosWSWall || key == ConfKey::CcosWSFree
- || key == ConfKey::CcosWSTomo || key == ConfKey::CcosWSConventional)
- {
- Item.SetCurrentValue(((string)r_config[key.c_str()]).c_str());
- }
- else if (key == ConfKey::CcosSynTable || key == ConfKey::CcosSynWall || key == ConfKey::CcosSynFree
- || key == ConfKey::CcosSynTomo || key == ConfKey::CcosSynConventional)
- {
- Item.SetCurrentValue(((string)r_config[key.c_str()]).c_str());
- }
- else if (key == ConfKey::CcosSCFType)
- {
- Item.SetCurrentValue(((string)r_config["connections"][0]["type"]).c_str());
- }
- else if (key == ConfKey::CcosSCFPort || key == ConfKey::CcosSCFBaudrate || key == ConfKey::CcosSCFBytesize
- || key == ConfKey::CcosSCFParity || key == ConfKey::CcosSCFStopbits || key == ConfKey::CcosSCFIP)
- {
- if (r_config["connections"][0].GetFirstOf(key.c_str()) >= 0)
- {
- Item.SetCurrentValue(((string)r_config["connections"][0][key.c_str()]).c_str());
- }
- }
- }
- ResDataObject resAttr, resDescription;
- for (auto Item : m_ConfigInfo)
- {
- resAttr.add(Item.GetKey(), Item.GetCurrentValue());
- resDescription.add(Item.GetKey(), Item.GetDescription());
- }
- ResDataObject resDeviceResource;
- resDeviceResource.add(ConfKey::CcosGeneratorAttribute, resAttr);
- resDeviceResource.add(ConfKey::CcosGeneratorDescription, resDescription);
- string res = resDeviceResource.encode();
- //printf("resDeviceResource :%s \n", resDeviceResource.encode());
- FINFO("resDeviceResource :{$} \n", resDeviceResource.encode());
- ResDataObject DescriptionTempEx;
- DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
- m_DeviceConfig.clear();
- m_DeviceConfig = DescriptionTempEx;
- return res;
- }
- bool nsGEN::REMEDYSTDriver::GetDeviceConfig(std::string& Cfg)
- {
- //Cfg = m_DeviceConfigSend.encode();
- Cfg = m_DeviceConfig.encode();
- //printf("GetDeviceConfig over");
- printf("GetDeviceConfig over , %s", Cfg.c_str());
- return true;
- }
- bool nsGEN::REMEDYSTDriver::SetDeviceConfig(std::string Cfg)
- {
- FINFO("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
- return true;
- }
- bool nsGEN::REMEDYSTDriver::SaveConfigFile(bool bSendNotify)
- {
- m_ConfigAll["CONFIGURATION"] = m_Configurations;
- bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
- FINFO("SaveConfigFile over {$}", bRt);
- return true;
- }
- std::string nsGEN::REMEDYSTDriver::DeviceProbe()
- {
- FINFO("std::string nsGEN::PSGRFDriver::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", "REMEDYST");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "1234");
- }
- string ret = HardwareInfo.encode();
- FINFO("std::string nsGEN::PSGRFDriver::DeviceProbe() out\n");
- return ret;
- }
- void nsGEN::REMEDYSTDriver::Dequeue(const char* Packet, DWORD Length)
- {
- DecodeFrame(Packet, Length);
- }
- /*
- ==IN==:KV070 MA00320 MS00063 MX00036
- ==IN==:TU0 WS1 FO0 ET0 FI010 FS001 FN 0 HE000
- how to split the str like up.
- //command+03+sum
- */
- PACKET_RET nsGEN::REMEDYSTDriver::callbackPackageProcess(const char* RecData, uint32_t nLength, uint32_t& PacketLength)
- {
- if (nLength < 1)
- {
- printf("nLength < 1, nLength==%d \n", nLength);
- return PACKET_USELESS;
- }
- for (DWORD i = 0; i < nLength - 1; i++)
- {
- if (RecData[i] == 0x03)
- {
- PacketLength = i + 2;
- char strtemp[100] = { 0 };
- memcpy(strtemp, RecData, i);
- strtemp[i + 1] = 0;
- FINFO("==IN==:{$}\n", strtemp);
- return PACKET_ISPACKET;
- }
- }
- return PACKET_NOPACKET;
- }
- //-----------------------------------------------------------------------------
- // DecodeFrame
- //-----------------------------------------------------------------------------
- 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;
- pc += Item.NbOfCharOfHead;
- Item.fun(pc, length - Item.NbOfCharOfHead);
- return true;
- }
- //-----------------------------------------------------------------------------
- // GetIODriver & CreateIODriver
- //-----------------------------------------------------------------------------
- static nsGEN::REMEDYSTDriver gIODriver;
- extern "C" CCOS::Dev::IODriver * GetIODriver()
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * CreateIODriver()
- {
- return new nsGEN::REMEDYSTDriver();
- }
|