12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219 |
- // CCOS.Dev.GEN.HaoWei.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include "stdafx.h"
- #include <assert.h>
- #include <functional>
- #include "LogicDevice.h"
- #include "CCOS.Dev.Generator.HaoWei.h"
- #include "Helper.JSON.hpp"
- #include <unordered_map>
- #include <fstream>
- #include <filesystem>
- #include <set>
- using namespace std::placeholders;
- using namespace CCOS::Dev::Detail::Generator;
- namespace nsGEN = CCOS::Dev::Detail::Generator;
- #pragma warning (disable:4244)
- #pragma warning (disable:4305)
- #pragma warning (disable:4267)
- static const int msTimeOut_Lock = 500;
- #ifdef _WIN64
- #ifdef _DEBUG
- static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64D.dll";
- #else
- static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64.dll";
- #endif
- #endif
- #ifdef _WIN64
- #ifdef _DEBUG
- static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64D.dll";
- #else
- static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64.dll";
- #endif
- #endif
- //-----------------------------------------------------------------------------
- // HaoWeiDevice
- //-----------------------------------------------------------------------------
- // 储存的点值
- std::vector<int> R10_MA = { 100, 125, 160, 200, 250, 320, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6300, 8000, 10000 };
- std::vector<int> R10_MS = { 10, 12, 16, 20, 25, 32, 40, 50, 63, 80, 100, 125, 160, 200, 250, 320, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6300, 8000, 10000, 12500, 16000, 20000, 25000, 32000, 40000, 50000, 63000, 80000, 100000 };
- std::vector<int> R10_MAS = { 10, 12, 16, 20, 25, 32, 40, 50, 63, 80, 100, 125, 160, 200, 250, 320, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6300, 8000, 10000, 12500, 16000, 20000, 25000, 32000, 40000, 50000, 63000, 80000, 100000 };
- std::vector<int> R20_MA = { 100, 110, 125, 140, 160, 180, 200, 220, 250, 280, 320, 360, 400, 450, 500, 560, 630, 710, 800, 900, 1000, 1100, 1250, 1400, 1600, 1800, 2000, 2200, 2500, 2800, 3200, 3600, 4000, 4500, 5000, 5600, 6300, 7100, 8000, 9000, 10000 };
- std::vector<int> R20_MS = { 10, 11, 12, 14, 16, 18, 20, 22, 25, 28, 32, 36, 40, 45, 50, 56, 63, 71, 80, 90, 100, 110, 125, 140, 160, 180, 200, 220, 250, 280, 320, 360, 400, 450, 500, 560, 630, 710, 800, 900, 1000, 1100, 1250, 1400, 1600, 1800, 2000, 2200, 2500, 2800, 3200, 3600, 4000, 4500, 5000, 5600, 6300, 7100, 8000, 9000, 10000, 11000, 12500, 14000, 16000, 18000, 20000, 22000, 25000, 28000, 32000, 36000, 40000, 45000, 50000, 56000, 63000, 71000, 80000, 90000, 100000 };
- std::vector<int> R20_MAS = { 10, 11, 12, 14, 16, 18, 20, 22, 25, 28, 32, 36, 40, 45, 50, 56, 63, 71, 80, 90, 100, 110, 125, 140, 160, 180, 200, 220, 250, 280, 320, 360, 400, 450, 500, 560, 630, 710, 800, 900, 1000, 1100, 1250, 1400, 1600, 1800, 2000, 2200, 2500, 2800, 3200, 3600, 4000, 4500, 5000, 5600, 6300, 7100, 8000, 9000, 10000, 11000, 12500, 14000, 16000, 18000, 20000, 22000, 25000, 28000, 32000, 36000, 40000, 45000, 50000, 56000, 63000, 71000, 80000, 90000, 100000 };
- atomic<int> nsGEN::HaoWeiDevice::m_iLoopTime = HaoWei_LoopDefTime;
- std::atomic<std::chrono::steady_clock::time_point> lastValidResponse;
- constexpr auto TIMEOUT = std::chrono::seconds(12); // 超时阈值
- nsGEN::HaoWeiDevice::HaoWeiDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF, string configfile) : super(center, SCF)
- {
- assert(EventCenter);
- 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_pHardwareStatusThread = NULL;
- m_bMasR20 = 0;
- m_bUseEAcmd = 0;
- m_bResetActive = false;
- m_bIsConfigLoaded = false;
- m_bHasInitializedDevice = false;
- lastValidResponse = std::chrono::steady_clock::now();
- m_DoseUnit.m_KV.reset(new KVMould(0.0, 40.0, 125.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(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_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));
- m_hGenPostEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- string strErrConfig = GetProcessDirectory() + R"(\OEMDrivers\Generator\HaoWei\ErrorWarnInfo.json)";
- m_DeviceErrorHandler.reset(new DeviceErrorHandler(center, nsGEN::GeneratorUnitType, strErrConfig));
- OnCallBack();
- Register();
- HWSend("ST?");
- StartHardwareStatusThread();
- }
- nsGEN::HaoWeiDevice::~HaoWeiDevice()
- {
- CloseHandle(m_hGenPostEvent);
- }
- std::string nsGEN::HaoWeiDevice::GetGUID() const
- {
- FINFO("\n===============GetGUID : {$} ===================\n", GeneratorUnitType);
- return GeneratorUnitType;
- }
- void nsGEN::HaoWeiDevice::Register()
- {
- auto Disp = &Dispatch;
- 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::HaoWeiDevice::IncKV()
- {
- FINFO("KV value before calling IncKV: {$}\n", m_DoseUnit.m_KV->JSGet().c_str());
- /*if (!m_DoseUnit.m_KV->CanInc())
- {
- m_DeviceErrorHandler->ParseAndReport("ECOM_KVMAX");
- return RET_STATUS::RET_SUCCEED;
- }*/
- return HWSend("KV+");
- }
- RET_STATUS nsGEN::HaoWeiDevice::DecKV()
- {
- FINFO("KV value before calling DecKV: {$}\n", m_DoseUnit.m_KV->JSGet().c_str());
- /*if (!m_DoseUnit.m_KV->CanDec())
- {
- m_DeviceErrorHandler->ParseAndReport("ECOM_KVMIN");
- return RET_STATUS::RET_SUCCEED;
- }*/
- return HWSend("KV-");
- }
- RET_STATUS nsGEN::HaoWeiDevice::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 };
- sprintf_s(temp, "KV%03d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::HaoWeiDevice::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::HaoWeiDevice::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::HaoWeiDevice::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;
- int index = 0;
- if (m_bMasR20)
- {
- index = FindClosestIndex(R20_MA, static_cast<int>(value));
- }
- else
- {
- index = FindClosestIndex(R10_MA, static_cast<int>(value));
- }
- char temp[50] = { 0 };
- sprintf_s(temp, "MA%02d", index + 1); // index+1 to match the original requirement
- return HWSend(temp);
- }
- RET_STATUS nsGEN::HaoWeiDevice::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("HaoWei_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::HaoWeiDevice::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::HaoWeiDevice::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;
- int index = 0;
- if (m_bMasR20)
- {
- index = FindClosestIndex(R20_MS, static_cast<int>(value));
- }
- else
- {
- index = FindClosestIndex(R10_MS, static_cast<int>(value));
- }
- char temp[50] = { 0 };
- sprintf_s(temp, "MS%02d", index + 1); // index+1 to match the original requirement
- return HWSend(temp);
- }
- RET_STATUS nsGEN::HaoWeiDevice::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("HaoWei_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::HaoWeiDevice::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::HaoWeiDevice::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;
- int index = 0;
- if (m_bMasR20)
- {
- index = FindClosestIndex(R20_MAS, static_cast<int>(value));
- }
- else
- {
- index = FindClosestIndex(R10_MAS, static_cast<int>(value));
- }
- char temp[50] = { 0 };
- sprintf_s(temp, "MX%02d", index + 1); // index+1 to match the original requirement
- return HWSend(temp);
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetTechmode(int value)
- {
- FINFO("Techmode value before calling SetTechmode: {$}\n", m_DoseUnit.m_Techmode->JSGet().c_str());
- char temp[50] = { 0 };
- sprintf_s(temp, "TE%01d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetFocus(int value)
- {
- FINFO("Focus value before calling SetFocus: {$}\n", m_DoseUnit.m_Focus->JSGet().c_str());
- char temp[50] = { 0 };
- sprintf_s(temp, "FO%01d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetAECDensity(int value)
- {
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
- return RET_STATUS::RET_FAILED;
- char temp[50] = { 0 };
- sprintf_s(temp, "FN%01d", (int)(value + 8));
- return HWSend(temp);
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetAECField(int value)
- {
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
- return RET_STATUS::RET_FAILED;
- char temp[50] = { 0 };
- sprintf_s(temp, "FI%03d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetAECFilm(int value)
- {
- if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_AEC)
- return RET_STATUS::RET_FAILED;
- char temp[50] = { 0 };
- sprintf_s(temp, "FS%03d", (int)value);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::HaoWeiDevice::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 };
- sprintf_s(temp, "WS%01d", tempws);
- return HWSend(temp);
- }
- string nsGEN::HaoWeiDevice::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::HaoWeiDevice::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);
- SetMAS(t.fMAS);
- }
- else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_TIME)//3p
- {
- SetTechmode(t.nTechmode);
- SetMA(t.fMA);
- SetMS(t.fMS);
- }
- HWSend("RS?");
- FINFO("*********************Leave SetAPR*********************");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::QueryHE(int& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::QueryPostKV(float& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::QueryPostMA(float& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::QueryPostMS(float& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::QueryPostMAS(float& value)
- {
- value = m_DoseUnit.m_PostMAS->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::Clear_DAP()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::GetValue_DAP(float& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::InitDevice()
- {
- HWSend("AC0");
- HWSend("SF0");
- HWSend("RS?");
- HWSend("FO?");
- GetSoftwareVersion();
- HWSend("GC?");
- SetPriorityCoefficient(m_bMasR20);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::StartMove()
- {
- FINFO("Enter startMove");
- FINFO("end startmove");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::EndMove()
- {
- FINFO("Enter endmove");
- FINFO("end EndMove");
- return RET_STATUS::RET_SUCCEED;
- }
- int CCOS::Dev::Detail::Generator::HaoWeiDevice::GetGenState()
- {
- const int currentState = m_DoseUnit.m_GenState->Get();
- if (currentState == 0)
- {
- m_DeviceErrorHandler->ParseAndReport("ECOM_CommLost");
- }
- return currentState;
- }
- int CCOS::Dev::Detail::Generator::HaoWeiDevice::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;
- }
- m_strConfigPath = configfile;
- 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"];
- }
- HWSend("ST?");
- m_bIsConfigLoaded = true;
- return 0;
- }
- int nsGEN::HaoWeiDevice::SetPriorityCoefficient(int nCoefficient)
- {
- char temp[50] = { 0 };
- sprintf_s(temp, "GC%01d", nCoefficient);
- return HWSend(temp);
- }
- int CCOS::Dev::Detail::Generator::HaoWeiDevice::GetSoftwareVersion()
- {
- FINFO("Enter GetSoftwareVersion...\n");
- return HWSend("GR?");
- }
- int CCOS::Dev::Detail::Generator::HaoWeiDevice::SetPulseSyncMode(int nMode)
- {
- char temp[50] = { 0 };
- sprintf_s(temp, "FMM%01d", nMode);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::HaoWeiDevice::SimulateError(std::string Error)
- {
- FINFO("Enter SimulateError...{$} \n", Error.c_str());
- std::string type = m_DeviceErrorHandler->ParseAndReport(Error);
- if (type == "error")
- {
- FINFO("type == error");
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- int nsGEN::HaoWeiDevice::FindClosestIndex(const std::vector<int>& values, int target)
- {
- auto it = std::lower_bound(values.begin(), values.end(), target);
- if (it == values.end()) {
- return values.size() - 1;
- }
- int index = std::distance(values.begin(), it);
- if (index > 0 && std::abs(values[index - 1] - target) <= std::abs(values[index] - target)) {
- return index - 1;
- }
- return index;
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetGenSynState(int value)
- {
- FINFO("Enter SetGenSynState:[{$}]", value);
- switch (value)
- {
- case AttrKey::GENERATOR_RAD_OFF:
- {
-
- }break;
- case AttrKey::GENERATOR_RAD_PREPARE:
- {
-
- }break;
- case AttrKey::GENERATOR_RAD_READY:
- {
- }break;
- case AttrKey::GENERATOR_RAD_XRAYON:
- {
-
- }break;
- case AttrKey::GENERATOR_RAD_XRAYOFF:
- {
-
- }break;
- case AttrKey::GENERATOR_FLU_OFF:
- {
-
- }break;
- case AttrKey::GENERATOR_FLU_READY:
- {
-
- }break;
- case AttrKey::GENERATOR_FLU_XRAYON:
- {
- int fluMode = m_DoseUnit.m_FLMode->Get();
- FINFO("SetGenSynState: current FluMode[{$}]", fluMode);
- switch (fluMode)
- {
- case AttrKey::GENERATOR_FLMODE_NOTFLU:
- break;
- case AttrKey::GENERATOR_FLMODE_CF:
- case AttrKey::GENERATOR_FLMODE_HCF:
- {
-
- }break;
- case AttrKey::GENERATOR_FLMODE_PF:
- case AttrKey::GENERATOR_FLMODE_HPF:
- {
-
- }break;
- break;
- case AttrKey::GENERATOR_FLMODE_MAX:
- break;
- default:
- break;
- }
- }break;
- case AttrKey::GENERATOR_FLU_XRAYOFF:
- {
-
- }break;
- default:
- break;
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetGenState(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetExpMode(std::string value)
- {
- FINFO("Enter SetExpMode...{$}",value);
- m_DoseUnit.m_ExpMode->Update(value);
- if (!m_DeviceErrorHandler->HasActiveErrors())
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- else
- {
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetFLFMode(std::string value)
- {
- FINFO("Enter SetFLFMode...,FLFMode:{$} \n", value.c_str());
- if (value == "CF")
- {
- m_DoseUnit.m_FLMode->Update(1);
- HWSend("FMF0");
- }
- else if (value == "PF")
- {
- m_DoseUnit.m_FLMode->Update(2);
- HWSend("FMF1");
- }
- else if (value == "HLF")
- {
- m_DoseUnit.m_FLMode->Update(2);
- HWSend("FMF1");
- }
- else
- {
- FINFO("other FluMode : {$}", value.c_str());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::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);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::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("FKV+");
- }
- RET_STATUS nsGEN::HaoWeiDevice::DecFluKV()
- {
- FINFO("FluKV value before calling DecFluKV: {$}\n", m_DoseUnit.m_FLKV->JSGet().c_str());
- // (!m_DoseUnit.m_FLKV->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("FKV-", 4);
- }
- RET_STATUS nsGEN::HaoWeiDevice::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 };
- sprintf_s(temp, "FKV%03d", (int)value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::HaoWeiDevice::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("FMA+");
- }
- RET_STATUS nsGEN::HaoWeiDevice::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("FMA-");
- }
- RET_STATUS nsGEN::HaoWeiDevice::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 };
- sprintf_s(temp, "FMA%04d", (int)(value * 10));
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::HaoWeiDevice::INCPPS()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::DECPPS()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetPPS(float value)
- {
- //if (!m_DoseUnit.m_PPS->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- sprintf_s(temp, "FMN%02d", value);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetABSMode(int nMode)
- {
- if (!m_DoseUnit.m_ABSStatus->Verify(nMode)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- FINFO("SetABSMode[{$}] \n", nMode);
- sprintf_s(temp, "IBS%1d", (int)nMode);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetABSCurve(int curveNum)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::IncABSCurve()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::DecABSCurve()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::GetABSCurve()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- float nsGEN::HaoWeiDevice::GetFluIntTimer()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- float nsGEN::HaoWeiDevice::GetFluAccTimer()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::ResetFluTimer(int ntype)
- {
- FINFO("ReSetFluAccTimer:[{$}] \n", ntype);
- return HWSend("FTC");
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetFluPre(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetFluEXP(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::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::HaoWeiDevice::SetFluDoseLever(int value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- void CCOS::Dev::Detail::Generator::HaoWeiDevice::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::HaoWeiDevice::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;
- }
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetEXAMMode(std::string value)
- {
- //EXAMMODE_TYPE::MANUAL
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::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 };
- sprintf_s(temp, "WS%01d", nSyncModeValue);
- return HWSend(temp);
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetFrameRate(FLOAT frameRate)
- {
- m_DoseUnit.m_FrameRate->Update(frameRate); //this variable should be set when in oncallback.
-
- char temp[50]{ 0 };
- sprintf_s(temp, "FLS%03d", int(frameRate*10));
- return HWSend(temp);
- }
- RET_STATUS nsGEN::HaoWeiDevice::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::HaoWeiDevice::RefreshData()
- {
- HWSend("RS?");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetExpEnable()
- {
- FINFO("SetExpEnable in ...\n");
- if (!m_DeviceErrorHandler->HasActiveErrors())
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- else
- {
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- //return HWSend("EXB1");
- }
- RET_STATUS nsGEN::HaoWeiDevice::SetExpDisable()
- {
- FINFO("SetExpDisable in...\n");
- if (!m_DeviceErrorHandler->HasActiveErrors())
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- else
- {
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- FINFO("SetExpDisable... {$}\n", m_DoseUnit.m_GenState->JSGet().c_str());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::HaoWeiDevice::Reset()
- {
- m_bResetActive = true;
- FINFO("RESET in...\n");
- return HWSend("CLR0");
- m_DeviceErrorHandler->ClearAllErrors();
- m_DeviceErrorHandler->ClearAllWarnings();
- int level = 0;
-
- }
- RET_STATUS nsGEN::HaoWeiDevice::HWSend(char* strCommand, int nTimeOut)
- {
- if (!m_SCF) return RET_STATUS::RET_FAILED;
- char strSendCommand[100] = { 0 };
- int len = strlen(strCommand);
- int totalLength = len + 3;
- int tmpSum = 0;
- for (int i = 0; i < len; i++)
- {
- tmpSum += (int)strCommand[i];
- }
- char checkSum = char(tmpSum + 3); //3 is ETX
- memcpy(strSendCommand, strCommand, len);
- strSendCommand[len] = 0x03;
- strSendCommand[len + 1] = checkSum;
- strSendCommand[len + 2] = 0x00;
- FINFO("==OUT==: {$} \n", strSendCommand);
- int retLength;
- m_SCF.Lock(msTimeOut_Lock)
- .SendPacket(strSendCommand, totalLength, nTimeOut, retLength);
- Sleep(nTimeOut);
-
- return RET_STATUS::RET_SUCCEED;
- }
- //-----------------------------------------------------------------------------
- // ProcessCmd
- //-----------------------------------------------------------------------------
- void nsGEN::HaoWeiDevice::FireNotify(std::string key, std::string content)
- {
- EventCenter->OnNotify(1, key, content);
- }
- struct tFrameMapping
- {
- static const int MaxLen = 5; // 前缀不能超超过 5 个字符 !
- using cbFun = std::function <void(const char*, int)>;
- char strHead[MaxLen];
- int NbOfCharOfHead;
- cbFun fun;
- tFrameMapping(char* str, int len, cbFun f)
- {
- assert(len < MaxLen); //len最大只能是4
- //strHead[0] = 0x02; //STX ----------->note : no package header
- for (int i = 0; i < len; i++) //给strHead赋值
- strHead[i] = str[i];
- NbOfCharOfHead = len;
- fun = f;
- }
- };
- static std::list <tFrameMapping> arFrame;
- static bool DecodeFrame(const char* strFrame, int length);
- void nsGEN::HaoWeiDevice::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);
- int tmpkv = atoi(value);
- 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);
- };
- 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);
- // 获取状态码的首位数字,用来判断阶段
- int statusPrefix = genStatus / 10;
- // 根据阶段处理不同的状态
- switch (statusPrefix)
- {
- case 10:
- // 初始化阶段 (101, 102, 103)
- FINFO("Get Gen Status:GENSTATE {$} -> (Initialization Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_INIT))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- break;
- case 20:
- // 待机阶段 (200)
- if (!m_bHasInitializedDevice)
- {
- InitDevice();
- m_bHasInitializedDevice = true;
- }
- FINFO("Get Gen Status:GENSTATE {$} -> (Standby Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- break;
- case 30:
- // 拍片准备阶段 (300)
- FINFO("Get Gen Status:GENSTATE {$} -> (Film Prep Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
- break;
- case 40:
- // 透视准备阶段 (400)
- FINFO("Get Gen Status:GENSTATE {$} -> (Fluoroscopy Prep Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
- break;
- case 50:
- // 曝光阶段 (500)
- FINFO("Get Gen Status:GENSTATE {$} -> (Exposure Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
- break;
- case 60:
- // 透视阶段 (600)
- FINFO("Get Gen Status:GENSTATE {$} -> (Fluoroscopy Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
- break;
- case 70:
- // 点片曝光阶段 (700)
- FINFO("Get Gen Status:GENSTATE {$} -> (Spot Exposure Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
- break;
- case 80:
- // 故障阶段 (800)
- FINFO("Get Gen Status:GENSTATE {$} -> (Fault Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- break;
- case 90:
- // 灯丝自动校准阶段 (900)
- FINFO("Get Gen Status:GENSTATE {$} -> (Filament Auto Calibration Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
- break;
- case 91:
- // 透视校准阶段 (910)
- FINFO("Get Gen Status:GENSTATE {$} -> (Fluoroscopy Calibration Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
- break;
- case 92:
- // 配置阶段 (920)
- FINFO("Get Gen Status:GENSTATE {$} -> (Configuration Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
- break;
- case 93:
- // 复位阶段 (930)
- FINFO("Get Gen Status:GENSTATE {$} -> (Reset Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
- break;
- case 94:
- // 升级阶段 (940)
- FINFO("Get Gen Status:GENSTATE {$} -> (Upgrade Phase)", m_DoseUnit.m_GenState->JSGet().c_str());
- break;
- default:
- FINFO("Get Gen Status: [{$}] unknown", genStatus);
- break;
- }
- };
- auto HWMAS = [this](const char* value, int length)
- {
- assert(value);
- int index = atoi(value);
- float fmas = (m_bMasR20) ? R20_MAS[index] : R10_MAS[index];
- fmas = fmas / 100.0;
- FINFO("Current MAS:{$}", fmas);
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_TIME)
- {
- m_DoseUnit.m_MAS->Update(fmas);
- 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);
- int index = atoi(value);
- float fma = (m_bMasR20) ? R20_MA[index] : R10_MA[index];
- fma = fma / 10.0;
- FINFO("Current MA:{$}", fma);
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- m_DoseUnit.m_MA->Update(fma);
- 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);
- int index = atoi(value);
- float fms = (m_bMasR20) ? R20_MS[index] : R10_MS[index];
- fms = fms / 10.0;
- FINFO("Current MS:{$}", fms);
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- m_DoseUnit.m_MS->Update(fms);
- 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", 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 = HaoWei_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();
- }
- if (m_iLoopTime == HaoWei_LoopExpTime)
- {
- if ((int)m_GenConfig["loopTime"] >= 100)
- {
- m_iLoopTime = (int)m_GenConfig["loopTime"];
- }
- else
- m_iLoopTime = HaoWei_LoopDefTime;
- FINFO("reduction loopTime[{$}]->[{$}]", HaoWei_LoopExpTime, m_iLoopTime.load());
- }
- }
- };
- 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("AT?");
- }
- }
- };
- 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());
- FireNotify(AttrKey::POSTKV, m_DoseUnit.m_KV->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) / 10.0);
- FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
- m_DoseUnit.m_PostMA->Update(m_DoseUnit.m_MA->Get());
- FireNotify(m_DoseUnit.m_PostMA->GetKey(), m_DoseUnit.m_PostMA->JSGet());
- m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
- FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
- m_DoseUnit.m_PostMAS->Update(m_DoseUnit.m_MAS->Get());
- FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
- FINFO("Actual exposure parameters MS:{$}", 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 HWGR = [this](const char* value, int length)
- {
- assert(value);
- // 提取机器型号、功率版本和功能类型
- std::string version(value, 3); // 前3个字符为机器型号
- char functionalityChar = value[3]; // 第4个字符表示功能类型
- // 功能类型的映射
- std::string functionality;
- if (functionalityChar == '0') {
- functionality = "PR (pet photography)";
- }
- else if (functionalityChar == '1') {
- functionality = "PF (Pet fluoroscopy)";
- }
- else if (functionalityChar == '2') {
- functionality = "MR (Human medical photography)";
- }
- else if (functionalityChar == '3') {
- functionality = "MF (Human medical fluoroscopy)";
- }
- else if (functionalityChar == '4') {
- functionality = "DR (Single tooth)";
- }
- else if (functionalityChar == '5') {
- functionality = "DF (CBCT)";
- }
- else if (functionalityChar == '6') {
- functionality = "IX (industrial circle)";
- }
- else if (functionalityChar == '7') {
- functionality = "0X (other)";
- }
- else {
- functionality = "Unknown Functionality:"+ functionalityChar;
- }
- // 日志打印输出
- FINFO("Version: {$}, Functionality: {$}", version, functionality.c_str());
- };
- auto HWGV = [this](const char* value, int length)
- {
- assert(value);
- // 打印原始值
- FINFO("value: {$}", value);
- int versionNumber = atoi(value);
- // 拆解 versionNumber 为 4个部分(假设数字按版本号分割:10010 -> V1.0.0.10)
- int major = versionNumber / 10000; // 取高位,得到主版本号
- int minor = (versionNumber / 1000) % 10; // 取次高位,得到次版本号
- int patch = (versionNumber / 100) % 10; // 取中位,得到修补版本号
- int build = versionNumber % 100; // 取低位,得到构建版本号
- // 格式化并打印详细版本信息
- FINFO("Software Version: V{$}.{$}.{$}.{$}", major, minor, patch, build);
- };
- auto HWGU = [this](const char* value, int length)
- {
- assert(value);
- // 打印原始值
- FINFO("value: {$}", value);
- std::string versionCode(value, 2);
- // 定义版本类型
- std::string versionType;
- if (versionCode == "00") {
- versionType = "General Version";
- }
- else if (versionCode == "01") {
- versionType = "Custom Version";
- }
- else {
- versionType = "Unknown Version"; // 处理其他情况,可以根据需求扩展
- }
- // 输出详细的版本信息
- FINFO("Software Version: {$}, Type: {$}", value, versionType.c_str());
- };
- auto HWTR = [this](const char* value, int length)
- {
- assert(value);
- if (value)
- {
- FINFO("Start automatic exposure once, after the end of an automatic reset");
- }
- else
- {
- FINFO("Stop automatic exposure");
- }
- };
- auto HWGC = [this](const char* value, int length)
- {
- assert(value);
- if (value)
- {
- FINFO("R20");
- }
- else
- {
- FINFO("R10");
- }
- };
- auto HWER = [this](const char* value, int length)
- {
- assert(value);
- std::string errorCode = "HaoWei_ER" + std::string(value);
- if (m_DeviceErrorHandler->ParseAndReport(errorCode) == "error")
- {
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR))
- {
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- }
- };
- auto HWWAR = [this](const char* value, int length)
- {
- assert(value);
- int nWran = atoi(value);
- if (nWran)
- {
- m_DeviceErrorHandler->ParseAndReport("ECOM_FluoroTimerLimitError");
- }
- };
- auto HWEHE = [this](const char* value, int length)
- {
- assert(value);
- int nhe = atoi(value);
- FINFO("HE{$}%", nhe);
- 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 HWFKV = [this](const char* value, int length)
- {
- assert(value);
- m_DoseUnit.m_FLKV->Update(atof(value));
- FireNotify(AttrKey::FLUKV, m_DoseUnit.m_FLKV->JSGet());
- };
- auto HWFMA = [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 == HaoWei_LoopExpTime)
- {
- if ((int)m_GenConfig["loopTime"] >= 100)
- {
- m_iLoopTime = (int)m_GenConfig["loopTime"];
- }
- else
- m_iLoopTime = HaoWei_LoopDefTime;
- FINFO("reduction loopTime[{$}]->[{$}]", HaoWei_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 = HaoWei_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);
- if (m_DoseUnit.m_FLAccTime->Update(tmpflt))
- FireNotify(AttrKey::FLUAccTime, m_DoseUnit.m_FLAccTime->JSGet());
- };
- // 有部分前缀是包含关系, 长的包含短的, 例如 KVS 包含了 KV.
- // 因此长的在前面, 短的在后面
- // !!! Device 是个短寿命对象, 而 arFrame 是静态变量 !!!
- // !!! 因此, 在添加到 arFrame 之前, 务必先清零 !!!
- 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("TE", 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("ER", 2, HWER));
- arFrame.push_back(tFrameMapping("HE", 2, HWEHE));
- arFrame.push_back(tFrameMapping("ST", 2, HWST));
- arFrame.push_back(tFrameMapping("EC", 2, HWEC));
- arFrame.push_back(tFrameMapping("GR", 2, HWGR));
- arFrame.push_back(tFrameMapping("GV", 2, HWGV));
- arFrame.push_back(tFrameMapping("GU", 2, HWGU));
- arFrame.push_back(tFrameMapping("TR", 2, HWTR));
- 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
- arFrame.push_back(tFrameMapping("WAR", 3, HWWAR));
- arFrame.push_back(tFrameMapping("FKV", 3, HWFKV));
- arFrame.push_back(tFrameMapping("FMA", 3, HWFMA));
- 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("FTS", 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));
- }
- bool nsGEN::HaoWeiDevice::StartHardwareStatusThread()
- {
- FINFO("enter Start HardwareStatus Thread ");
- if (m_pHardwareStatusThread == NULL)
- {
- DWORD m_HardwareStatusID;
- m_pHardwareStatusThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
- if (m_pHardwareStatusThread == NULL)
- {
- Fatal("Start HardwareStatus Thread Failed");
- return false;
- }
- }
- return true;
- }
- DWORD nsGEN::HaoWeiDevice::HardwareStatusThread(LPVOID pParam)
- {
- HaoWeiDevice* pCurGen = (HaoWeiDevice*)pParam;
- if (pCurGen == NULL)
- {
- return false;
- }
-
- FINFO("loopTime = {$}", pCurGen->m_iLoopTime.load());
- int currtTime = pCurGen->m_iLoopTime;
- FINFO("HardwareStatusThread start");
- while (true)
- {
- auto now = std::chrono::steady_clock::now();
- auto last = lastValidResponse.load();
- if (now - last > TIMEOUT && pCurGen->m_DoseUnit.m_GenState->Get() > 0) {
- FINFO("The timeout did not respond");
- pCurGen->m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SHUTDOWN); // 超时未响应则重置状态
- }
- currtTime = pCurGen->m_iLoopTime;
- Sleep(currtTime);
- //获取消息
- //pCurGen->HWSend("ST?");
- }
-
- FINFO("HardwareStatusThread stop");
- return true;
- }
- //-----------------------------------------------------------------------------
- // HaoWeiDriver
- //-----------------------------------------------------------------------------
- nsGEN::HaoWeiDriver::HaoWeiDriver()
- {
- }
- nsGEN::HaoWeiDriver::~HaoWeiDriver()
- {
- }
- auto nsGEN::HaoWeiDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
- {
- FINFO("CreateDevice in\n");
-
- m_pDevice = new HaoWeiDevice(EventCenter, m_SCF, m_ConfigFileName);
- auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDevice));
- FINFO("CreateDevice out\n");
- return dev;
- }
- void nsGEN::HaoWeiDriver::FireNotify(int code, std::string key, std::string content)
- {
- EventCenter->OnNotify(code, key, content);
- }
- Log4CPP::Logger* gLogger = nullptr;
- void nsGEN::HaoWeiDriver::Prepare()
- {
- FINFO("Enter Prepare.");
- string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
- Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.HaoWei");
- auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
- gLogger = Log4CPP::LogManager::GetLogger("GEN.HaoWei");
- m_SCFDllName = GetConnectDLL(m_ConfigFileName);
- super::Prepare();
- }
- bool DATA_ACTION nsGEN::HaoWeiDriver::Connect()
- {
- FINFO("Enter {$},configlef={$}\n", __FUNCTION__, m_ConfigFileName.c_str());
- ResDataObject Connection = GetConnectParam(m_ConfigFileName);
- FINFO("connections:{$} \n", Connection.encode());
- auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::HaoWeiDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
- if (erCode != SCF_ERR::SCF_SUCCEED)
- {
- FINFO("SCF connection failed: erCode != SCF_ERR::SCF_SUCCEED\n");
- return false;
- }
- auto rc = super::Connect();
- if (!rc)
- {
- FINFO("super::Connect() failed\n");
- return false;
- }
-
- return true;
- }
- void nsGEN::HaoWeiDriver::Disconnect()
- {
- super::Disconnect();
- m_SCF.Disconnect();
- }
- bool nsGEN::HaoWeiDriver::isConnected() const
- {
- if (!super::isConnected())
- {
- FINFO("No valid connection!!!\n");
- return false;
- }
- //if (m_pDevice == nullptr)
- //{
- // FINFO("m_pDevice == nullptr\n");
- // return false;
- //}
- //if (m_pDevice->LoadConfig(m_ConfigFileName) == -1)
- //{
- // return false; //return 0;
- //}
- //int genState = m_pDevice->GetGenState();
- FINFO("m_pDevice->GetGenState() == {$}\n", genState);
- //return genState > 0; // 只有返回值大于 0 时才返回 true
- return true;
- }
- std::string nsGEN::HaoWeiDriver::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", "HaoWei");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Drv");
- }
- string ret = HardwareInfo.encode();
- FINFO("DriverProbe out \n");
- return ret;
- }
- std::string nsGEN::HaoWeiDriver::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::HaoWeiDriver::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::HaoWeiDriver::SetDeviceConfig(std::string Cfg)
- {
- FINFO("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
- return true;
- }
- bool nsGEN::HaoWeiDriver::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::HaoWeiDriver::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", "HaoWei");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "1234");
- }
- string ret = HardwareInfo.encode();
- FINFO("std::string nsGEN::PSGRFDriver::DeviceProbe() out\n");
- return ret;
- }
- void nsGEN::HaoWeiDriver::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::HaoWeiDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
- {
- FINFO("==IN==11:[{:02X$}]\n", RecData);
- if (nLength < 1) // 最小有效包为0x03 + checksum + 0x00(3字节)
- {
- return PACKET_USELESS;
- }
- for (DWORD i = 0; i < nLength; ++i) // 遍历所有字节
- {
- if (RecData[i] == 0x00)
- {
- if (i < 2) { // 至少需要0x03、校验和和结束符
- return PACKET_USELESS;
- }
- size_t markerPos = i - 2;
- if (RecData[markerPos] != 0x03) { // 检查0x03标识符
- // 不是有效的起始符,继续查找下一个结束符
- continue;
- }
- //BYTE calcSum = 0;
- //for (size_t j = 0; j <= markerPos; ++j) {
- // calcSum += RecData[j];
- //}
- //BYTE recvSum = RecData[i - 1];
- //if (calcSum != recvSum) {
- // // 校验失败,继续查找后续可能的包
- // continue;
- //}
- PacketLength = static_cast<DWORD>(i - 2); //应该+2.才会把最后的checmsum也包含进来。FO1+03+sum.
- char strtemp[100] = { 0 };
- memcpy(strtemp, RecData, i);
- strtemp[i + 1] = 0;
- FINFO("==IN==:{:02x$}\n", strtemp);
- return PACKET_ISPACKET;
- }
- }
- return PACKET_NOPACKET;
- }
- //-----------------------------------------------------------------------------
- // DecodeFrame
- //-----------------------------------------------------------------------------
- static bool DecodeFrame(const char* strFrame, int length)
- {
- FINFO("==IN==:{:02x$}\n", strFrame);
- 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;
- }
- lastValidResponse.store(std::chrono::steady_clock::now());
- const auto& Item = *found;
- auto pc = strFrame;
- pc += Item.NbOfCharOfHead;
- Item.fun(pc, length - Item.NbOfCharOfHead);
- return true;
- }
- //-----------------------------------------------------------------------------
- // GetIODriver & CreateIODriver
- //-----------------------------------------------------------------------------
- static nsGEN::HaoWeiDriver gIODriver;
- extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
- {
- return new nsGEN::HaoWeiDriver();
- }
|