12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069 |
- #include "stdafx.h"
- #include <assert.h>
- #include <functional>
- #include "LogicDevice.h"
- #include <unordered_map>
- #include "Helper.JSON.hpp"
- #include "CCOS.Dev.Generator.MERCURY.h"
- using namespace CCOS::Dev::Detail::Generator;
- namespace nsGEN = CCOS::Dev::Detail::Generator;
- using namespace std::placeholders;
- static nsGEN::MERCURYDriver* pIODriver = nullptr;
- //关闭无关警告
- #pragma warning (disable:4244) // warning C4244: “初始化”: 从“double”转换到“float”,可能丢失数据
- #pragma warning (disable:4305) // warning C4305: “参数”: 从“double”到“float”截断
- #pragma warning (disable:4267) // warning C4267 : “初始化”: 从“size_t”转换到“int”,可能丢失数据
- #pragma warning (disable:4805) // warning C4805: “!=”: 在操作中将类型“bool”与类型“int”混合不安全
- #define PSGHR_LARGE_POWER 5
- #define PSGHR_SMALL_POWER 1.1
- #define PSGHR_MAX_HEAT 225
- #define PSGHR_MIN_MA 1.0
- #define PSGHR_MAX_MA 1000.0
- #define PSGHR_MIN_MS 1.0
- #define PSGHR_MAX_MS 10001.0
- //设置相关常量
- #define PSGHR_LoopDefHBTime 1000
- #define PSGHR_LoopExpHBTime 500
- static const int msTimeOut_Lock = 500; //通讯接口锁定时间
- #define PSGHR_Com_NormalLen 150
- #define PSGHR_ETX 0x03
- #define PSGHR_RESOK "$"
- //设置对应通信接口库
- #ifdef _WIN64
- #ifdef _DEBUG
- static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64D.dll";
- #else
- static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64.dll";
- #endif
- #endif
- #ifdef _WIN64
- #ifdef _DEBUG
- static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64D.dll";
- #else
- static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64.dll";
- #endif
- #endif
- Log4CPP::Logger* gLogger = nullptr;
- 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
-
- for (int i = 0; i < len; i++)
- strHead[i] = str[i];
- NbOfCharOfHead = len;
- fun = f;
- }
- };
- //响应操作对照表
- static std::list <tFrameMapping> arFrame;
- //查找响应操作对照表执行对应操作
- static bool DecodeFrame(const char* strFrame, int length)
- {
- auto pr = [strFrame, length](const tFrameMapping& Item)
- {
- for (int i = 0; i < Item.NbOfCharOfHead; i++)
- {
- if (strFrame[i] != Item.strHead[i])
- {
- return false;
- }
- }
- return true;
- };
- auto found = std::find_if(arFrame.begin(), arFrame.end(), pr);//此处pr,是上面定义的 lambda表达式,用来在list中找到对于的包头。
- if (found == arFrame.end())
- {
- return false;
- }
- const auto& Item = *found;
- auto pc = strFrame;
- char data[100] = { 0 };
- memcpy(data, strFrame + Item.NbOfCharOfHead, length - Item.NbOfCharOfHead);
- Item.fun(data, length - Item.NbOfCharOfHead);
- return true;
- }
- //-----------------------------------------------------------------------------
- // MERCURYDevice
- //-----------------------------------------------------------------------------
- atomic<int> nsGEN::MERCURYDevice::m_iLoopTime = PSGHR_LoopDefHBTime;
- atomic<bool> nsGEN::MERCURYDevice::m_bExtraFlag = false;
- static atomic<bool>HeartBeatFlag = false;
- nsGEN::MERCURYDevice::MERCURYDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF, string configfile) : super(center, SCF)
- {
- assert(EventCenter);
- m_bExtraFlag = true;
- //初始化
- ResDataObject temp;
- temp.loadFile(configfile.c_str());
- m_GenConfig = temp["CONFIGURATION"];
- TransJsonText(m_GenConfig);
- m_pHardwareStatusThread = NULL;
- m_pHardwareRsSendThread = NULL;
- m_bExpEnable = false;
- m_iHeartBeats = 0;
- m_bConnectFlag = true;
- m_bGenBusy = false;
- m_bReturnFlag = false;
- m_iLoopTime.store(PSGHR_LoopDefHBTime);
- for (int i = 0; i < 18; i++)
- {
- m_bFaultList[i] = false;
- };
- m_bMAS_MA_AEC = false;
- m_iMaxPower = PSGHR_LARGE_POWER; //KW
- MaxHeatContent = PSGHR_MAX_HEAT; //KJ
- if (m_GenConfig.GetKeyCount("loopEnable") > 0)
- {
- m_bExtraFlag = (int)m_GenConfig["loopEnable"];
- }
- string version;
- if(GetVersion(version, hMyModule))
- FINFO("\n===============log begin : version:{$} ===================\n", version.c_str());
- else
- FINFO("\n===============log begin : version:0.0.0.0 ===================\n");
- //设置发生器属性集合各个值的范围及精度
- m_DoseUnit.m_KV.reset(new KVMould(0.0, 39.0, 151.0, 1.0));
- m_DoseUnit.m_MA.reset(new MAMould(0.0, PSGHR_MIN_MA, PSGHR_MAX_MA, 0.1));
- m_DoseUnit.m_MS.reset(new MSMould(0.0, PSGHR_MIN_MS, PSGHR_MAX_MS, 0.01));
- m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.1, 1000.0, 0.01));
- m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_AEC_MAS_MA, 1));
- m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
- m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_TYPE::FOCUS_LARGE, AttrKey::FOCUS_SMALL, AttrKey::FOCUS_LARGE, 1));
- m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
- m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
- m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -3, 3, 1));
- m_DoseUnit.m_GenHE.reset(new GENHEATMould(0, 0, 100, 1));
- m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
- m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
- m_DoseUnit.m_GenState.reset(new GENSTATEMould(0, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
- m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single));
- m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 16, 1));
- m_DoseUnit.m_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(AttrKey::TUBETARGETMATERIAL_TYPE::MO));
- m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0, -45, 45, 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));
-
- //Actual exposure parameters 值
- m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 40.0, 120.0, 1.0));
- m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 1.0, 1000.0, 0.1));
- m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 1.0, 10000.0, 0.01));
- m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.5, 1000.0, 0.01));
- //发生器告警及错误消息
- m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
-
- m_hGenPostEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- if (m_GenConfig.GetKeyCount(ConfKey::CcosTubeInfo) > 0)
- {
- string tempValue = m_GenConfig[ConfKey::CcosTubeInfo];
- m_DoseUnit.m_TubeInfo.reset(new TUBEINFOMould(tempValue));
- FireNotify(AttrKey::TUBEINFO, m_DoseUnit.m_TubeInfo->JSGet());
- }
- if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusSmall) > 0)
- {
- float tempValue = (float)m_GenConfig[ConfKey::CcosFocusSmall];
- m_DoseUnit.m_FocusSmall = tempValue;
- }
- if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusLarge) > 0)
- {
- float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
- m_DoseUnit.m_FocusLarge = tempValue;
- }
- if (m_GenConfig.GetKeyCount("GenCtrlMode") > 0)
- {
- m_nCtlMode = (float)m_GenConfig["GenCtrlMode"];//default 2
- float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
- }
- m_bDAPEnable = false;
- m_bSaveMSMA = true;
- InitCallBack();
- Register();
- ECHO();
- GetTechMode();
- GetST();
-
- //启动硬件状态轮询进程
- StartHardwareStatusThread();
- }
- nsGEN::MERCURYDevice::~MERCURYDevice()
- {
- m_bExtraFlag = false;
- FINFO("\n===============log end ===================\n");
- CloseHandle(m_hGenPostEvent);
- if (m_pHardwareRsSendThread != NULL)
- {
- WaitForSingleObject(m_pHardwareRsSendThread, INFINITE);
- CloseHandle(m_pHardwareRsSendThread);
- m_pHardwareRsSendThread = NULL;
- }
- if (m_pHardwareStatusThread != NULL)
- {
- WaitForSingleObject(m_pHardwareStatusThread, INFINITE);
- CloseHandle(m_pHardwareStatusThread);
- m_pHardwareStatusThread = NULL;
- }
- arFrame.clear();
- }
- std::string nsGEN::MERCURYDevice::GetGUID() const
- {
- FINFO("===============GetGUID : {$} ===================\n", GeneratorUnitType);
- return GeneratorUnitType;
- }
- void nsGEN::MERCURYDevice::Register()
- {
- auto Disp = &Dispatch;
- superGen::Register(Disp);
- superGen::RegisterRAD(Disp);
- superGen::RegisterExpEnable(Disp);
- superGen::RegisterGeneratortoSyncStatus(Disp);
- Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
- Disp->Get.Push(AttrKey::DENHEAT, [this](std::string& out) { out = m_DoseUnit.m_GenHE->JSGet(); return RET_STATUS::RET_SUCCEED; });
- auto fun_Clear_DAP = [this](auto in, auto& out)
- {
- return Clear_DAP();
- };
- Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
- auto fun_GetValue_DAP = [this](auto in, auto& out)
- {
- float value = 0;
- RET_STATUS ret = GetValue_DAP(value);
- out = ToJSON(value);
- return ret;
- };
- Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
- }
- RET_STATUS nsGEN::MERCURYDevice::SetKV(float value)
- {
- FINFO("{$}KV", value);
- 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, strlen(temp));
- }
- RET_STATUS nsGEN::MERCURYDevice::IncKV()
- {
- FINFO("Inc KV");
- if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("KV+", 3);
- }
- RET_STATUS nsGEN::MERCURYDevice::DecKV()
- {
- FINFO("Dec KV");
- if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("KV-", 3);
- }
- RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::IncKVL()
- {
- FINFO("Inc KVL");
- if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
- return HWSend("KV++", 4);
- }
- RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::DecKVL()
- {
- FINFO("Dec KVL");
- if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
- return HWSend("KV--", 4);
- }
- RET_STATUS nsGEN::MERCURYDevice::IncMA()
- {
- FINFO("Inc MA");
- if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("Techmode is MAS, can't inc MA");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MA+",3);
- }
- RET_STATUS nsGEN::MERCURYDevice::DecMA()
- {
- FINFO("Dec MA");
- if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("Techmode is MAS, can't dec MA");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MA-", 3);
- }
- RET_STATUS nsGEN::MERCURYDevice::SetMA(float value)
- {
- FINFO("{$}MA", value);
- if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- FINFO("Techmode is MAS, can't set MA");
- return RET_STATUS::RET_FAILED;
- }
- char temp[50] = { 0 };
- sprintf_s(temp, "MA%05d", (int)(value * 10));
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::MERCURYDevice::IncMS()
- {
- FINFO("Inc MS");
- if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- FINFO("Techmode is 2Point, Cannot inc MS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MS+",3);
- }
- RET_STATUS nsGEN::MERCURYDevice::DecMS()
- {
- FINFO("Dec MS");
- if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- FINFO("Techmode is 2Point, Cannot dec MS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MS-", 3);;
- }
- RET_STATUS nsGEN::MERCURYDevice::SetMS(float value)
- {
- FINFO("{$}MS", value);
- if (!m_DoseUnit.m_MS->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
- {
- FINFO("Techmode is 2Point, Cannot set MS");
- return RET_STATUS::RET_FAILED;
- }
-
- char temp[50] = { 0 };
- sprintf_s(temp, "MS%06d", (int)(value * 10));
- return HWSend(temp,strlen(temp));
- }
- RET_STATUS nsGEN::MERCURYDevice::IncMAS()
- {
- FINFO("Inc MAS");
- if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- FINFO("Techmode is 3Point, Cannot inc MAS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MX+" , 3);
- }
- RET_STATUS nsGEN::MERCURYDevice::DecMAS()
- {
- FINFO("Dec MAS");
- if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- FINFO("Techmode is 3Point, Cannot dec MAS");
- return RET_STATUS::RET_FAILED;
- }
- return HWSend("MX-", 3);
- }
- RET_STATUS nsGEN::MERCURYDevice::SetMAS(float value)
- {
- FINFO("{$}MAS", value);
- if (!m_DoseUnit.m_MAS->Verify(value)) return RET_STATUS::RET_SUCCEED;
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
- m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
- {
- FINFO("Techmode is 3Point, Cannot set MAS");
- return RET_STATUS::RET_FAILED;
- }
- char temp[50] = { 0 };
- sprintf_s(temp, "MX%06d", (int)(value * 100));
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::MERCURYDevice::SetTechmode(int value)
- {
- FINFO("TechMode: {$}", value);
- if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- sprintf_s(temp, "ET%1d", (int)value);
- HWSend(temp, strlen(temp));
- }
- RET_STATUS nsGEN::MERCURYDevice::SetEXAMMode(std::string value)
- {
- FINFO("Exammode: {$}", value);
- if (value == AttrKey::EXAMMODE_TYPE::MANUAL)
- {
- SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P);
- }
- else if (value == AttrKey::EXAMMODE_TYPE::SEMIAUTO)
- {
- SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
- }
- else if (value == AttrKey::EXAMMODE_TYPE::AUTOMATIC)
- {
- SetTechmode(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::MERCURYDevice::SetAPR(const _tAPRArgs& t)
- {
- m_bGenBusy = true;
- FINFO("APR:KV: {$},MA: {$},MS: {$},MAS: {$},Focus: {$},Techmode: {$},WS: {$},AECDensity: {$},AECField: {$},AECFilm: {$}", t.fKV, t.fMA, t.fMS, t.fMAS, t.nFocus, t.nTechmode, t.nWS, t.nAECDensity, t.nAECField, t.nAECFilm);
- if (t.nFocus < 0)
- {
- FINFO("SetAPR: the focus value is amall than 0, set focus to small focus\n");
- SetFocus(0);
- }
- int nTempAECFilm = 1;
- switch (t.nAECFilm)
- {
- case 0:
- nTempAECFilm = 1;
- break;
- case 1:
- nTempAECFilm = 10;
- break;
- case 2:
- nTempAECFilm = 100;
- break;
- default:
- break;
- }
- GetTechMode();
- SetKV(t.fKV);
- SetFocus(t.nFocus);
- SetWS("Table");
- Sleep(50);
- SetTechmode(t.nTechmode);
- if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_AEC)
- {
- // aec
- Sleep(50);
- SetAECField(t.nAECField);
- Sleep(80);
- SetAECDensity(t.nAECDensity);
- Sleep(50);
- SetAECFilm(nTempAECFilm);
- Sleep(50);
- SetMA(t.fMA);
- Sleep(50);
- SetMS(t.fMS);
- }
- else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)
- {
- // mas
- Sleep(50);
- const float EPSINON = 0.000001;
- if ((t.fMAS >= -EPSINON) && (t.fMAS <= EPSINON))
- {
- SetMAS(t.fMA * t.fMS / 1000);
- }
- else
- {
- SetMAS(t.fMAS);
- }
- }
- else if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_TIME)
- {
- // time
- Sleep(50);
- SetMA(t.fMA);
- Sleep(80);
- SetMS(t.fMS);
- }
- m_bGenBusy = false;
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::MERCURYDevice::SetFocus(int value)
- {
- FINFO("FOCUS: {$}", value);
- if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
- char temp[50] = { 0 };
- sprintf_s(temp, "FO%01d", (int)value);
- return HWSend(temp,strlen(temp));
- }
- RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::SetAECDensity(int value)
- {
- return RET_STATUS();
- }
- RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::SetAECField(int value)
- {
- return RET_STATUS();
- }
- RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::SetAECFilm(int value)
- {
- return RET_STATUS();
- }
- RET_STATUS nsGEN::MERCURYDevice::Reset()
- {
- FDEBUG("clear all errors \n");
- int level = 0;
- m_MSGUnit->DelErrorMessage("0", level, "clear all errors");
- m_MSGUnit->DelWarnMessage("0", level, "clear all Warning");
- HWSend("RE",2);//仅重置错误状态
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::MERCURYDevice::QueryHE(int& value)
- {
- if (!m_bGenBusy)
- return HWSend("HE?", 3);
- return RET_STATUS::RET_SUCCEED;
- }
- void nsGEN::MERCURYDevice::SubscribeSelf(ccos_mqtt_connection* conn)
- {
- //订阅GEN所有Action
- SubscribeTopic(conn, "CCOS/DEVICE/Generator/Action/#");
- }
- RET_STATUS nsGEN::MERCURYDevice::SetVibrationGrid(int value)//发生器暂无此设置
- {
- FINFO("Enter StartVibrationGrid:[{$}]", value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::MERCURYDevice::GetVibrationGridMS(int& value) //发生器暂无此设置
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::MERCURYDevice::SetWS(const string value)
- {
- FINFO("WS: {$}", value);
- int tempws = 0;
- if (value == "Table") tempws = (int)m_GenConfig["WSTable"];
- else if (value == "Wall") tempws = (int)m_GenConfig["WSWall"];
- else if (value == "Direct") tempws = (int)m_GenConfig["WSConventional"];
- else if (value == "Free") tempws = (int)m_GenConfig["WSFree"];
- else if (value == "Tomo") tempws = (int)m_GenConfig["WSTomo"];
- m_DoseUnit.m_WS->Update(tempws);
- char temp[50] = { 0 };
- sprintf_s(temp, "WS%01d", tempws);
- return HWSend(temp, strlen(temp));
- }
- RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::SetGenSynState(int value)
- {
- return RET_STATUS();
- }
- RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::SetGenState(int value)
- {
- return RET_STATUS();
- }
- RET_STATUS nsGEN::MERCURYDevice::QueryPostKV(float& value)
- {
- m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
- value = m_DoseUnit.m_PostKV->Get();
- return HWSend("VP?",3);
- }
- RET_STATUS nsGEN::MERCURYDevice::QueryPostMA(float& value)
- {
- return HWSend("PA?", 3);
- }
- RET_STATUS nsGEN::MERCURYDevice::QueryPostMS(float& value)
- {
- return HWSend("AT?",3);
- }
- RET_STATUS nsGEN::MERCURYDevice::QueryPostMAS(float& value)
- {
- return HWSend("AP?", 3);
- }
- RET_STATUS nsGEN::MERCURYDevice::Clear_DAP()
- {
- if (m_bDAPEnable)
- {
- return HWSend("DZ",2);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::MERCURYDevice::GetValue_DAP(float& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::MERCURYDevice::SetExpMode(std::string value)
- {
- FINFO("Enter SetExpMode...{$} \n",value.c_str());
- m_DoseUnit.m_ExpMode->Update(value);
- //add for dcm iRF hard
- FINFO("SetExpMode:add for dcm iRF hard");
- FireNotify(m_DoseUnit.m_TubeTargetMaterial->GetKey(), m_DoseUnit.m_TubeTargetMaterial->JSGet());
- FireNotify(m_DoseUnit.m_TubeAngle->GetKey(), m_DoseUnit.m_TubeAngle->JSGet());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS CCOS::Dev::Detail::Generator::MERCURYDevice::SetFrameRate(FLOAT frameRate)
- {
- return RET_STATUS();
- }
- RET_STATUS nsGEN::MERCURYDevice::SetExpEnable()
- {
- FINFO("SetExpEnable in\n");
- m_bExpEnable = true;
- if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_ERROR)
- {
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::MERCURYDevice::SetExpDisable()
- {
- if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_ERROR)
- {
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SLEEP);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- }
- FINFO("SetExpDisable in\n");
- m_bExpEnable = false;
- return RET_STATUS::RET_SUCCEED;
- }
- //-----------------------------------------------------------------------------
- // ProcessCmd
- //-----------------------------------------------------------------------------
- RET_STATUS nsGEN::MERCURYDevice::HWSend(const char* strCommand,int lengh, bool reSend, int nTimeOut)
- {
- if (!m_bConnectFlag)
- {
- FERROR("==OUT==: not Connect,[{$}] send failed \n", strCommand);
- return RET_STATUS::RET_FAILED;
- }
- if (!m_SCF) return RET_STATUS::RET_FAILED;
- char strSendCommand[100] = { 0 };
- int len = strlen(strCommand);
- int tmpSum = 0;
- for (int i = 0; i < len; i++)
- {
- tmpSum += (int)strCommand[i];
- }
- char checkSum = char(tmpSum + 3);
- memcpy(strSendCommand, strCommand, len);
- strSendCommand[len + 0] = 0x03;
- strSendCommand[len + 1] = checkSum;
- FINFO("==OUT==: [{$}] \n", strSendCommand);
- int retLength;
- m_SCF.Lock(msTimeOut_Lock)
- .SendPacket(strSendCommand, strlen(strSendCommand), nTimeOut, retLength);
- return RET_STATUS::RET_SUCCEED;
- }
- void nsGEN::MERCURYDevice::FireNotify(string key, int context)
- {
- char szInfo[64] = { 0 };
- sprintf_s(szInfo, "%d", context);
- std::string str = szInfo;
- EventCenter->OnNotify(1, key, str);
- }
- void nsGEN::MERCURYDevice::FireNotify(std::string key, float context)
- {
- char szInfo[16] = { 0 };
- sprintf_s(szInfo,15, "%.2f", context);
- std::string str = szInfo;
- FINFO("FireNotify(float):[{$}][{$}]", szInfo, str.c_str());
- EventCenter->OnNotify(1, key, str);
- }
- void nsGEN::MERCURYDevice::FireNotify(std::string key, std::string context)
- {
- EventCenter->OnNotify(1, key, context);
- }
- void nsGEN::MERCURYDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
- {
- string ErrorCode("PSGHR_ERR_");
- ErrorCode += std::to_string(Code);
- int level = MERCURY_REGULATION_LEVEL::REG_ERRO;
- if (Act)
- {
- FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->AddErrorMessage(ErrorCode.c_str(), level, ResInfo);
- }
- else
- {
- FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo);
- }
- }
- void nsGEN::MERCURYDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
- {
- string ErrorCode("PSGHR_WAR_");
- ErrorCode += std::to_string(Code);
- int level = MERCURY_REGULATION_LEVEL::REG_WARN;
- if (Act)
- {
- FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->AddWarnMessage(ErrorCode.c_str(), level, ResInfo);
- }
- else
- {
- FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->DelWarnMessage(ErrorCode.c_str(), level, ResInfo);
- }
- }
- void CCOS::Dev::Detail::Generator::MERCURYDevice::GetST()
- {
- FINFO("Get Generator Status");
- HWSend("ST?", 3);
- }
- void CCOS::Dev::Detail::Generator::MERCURYDevice::GetTechMode()
- {
- FINFO("Get TechMode");
- HWSend("ET?", 3);
- }
- void CCOS::Dev::Detail::Generator::MERCURYDevice::RefreshConData()
- {
- FINFO("ReFresh Con Data");
- HWSend("RR", 2);
- }
- void CCOS::Dev::Detail::Generator::MERCURYDevice::RespondPR0()
- {
- FINFO("Respond: PRO");
- HWSend("PR0", 3);
- }
- void CCOS::Dev::Detail::Generator::MERCURYDevice::RespondPR1()
- {
- FINFO("Respond: PR1");
- HWSend("PR1", 3);
- }
- void CCOS::Dev::Detail::Generator::MERCURYDevice::RespondPR2()
- {
- FINFO("Respond: PR2");
- HWSend("PR2", 3);
- }
- void CCOS::Dev::Detail::Generator::MERCURYDevice::RespondXR0()
- {
- FINFO("Respond: XR0");
- HWSend("XR0", 3);
- }
- void CCOS::Dev::Detail::Generator::MERCURYDevice::RespondXR1()
- {
- FINFO("Respond: XR1");
- HWSend("XR1", 3);
- }
- void nsGEN::MERCURYDevice::InitCallBack()
- {
- //无 操作
- auto HWNotProcess = [](const char* value, int length) -> void
- {
- FINFO("This commands[{$}] didn't need to process", value);
- };
- auto HWKV = [this](const char* value, int length) -> void
- {
- assert(value);
- int kv = atoi(value);
- if (m_DoseUnit.m_KV->Update(kv))
- FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
- };
- auto HWMAS = [this](const char* value, int length)
- {
- assert(value);
- float fmas = atof(value) / 100.0;
- if (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_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_MS->Update(fms))
- FireNotify(AttrKey::MS, m_DoseUnit.m_MS->JSGet());
- };
- //after kv
- auto HWVP = [this](const char* value, int length)
- {
- assert(value);
- m_DoseUnit.m_PostKV->Update(atof(value));
- FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
- FINFO("Actual exposure parameters KV:{$}", m_DoseUnit.m_PostKV->JSGet().c_str());
- };
- auto HWPA = [this](const char* value, int length)
- {
- assert(value);
- float fma = atof(value) / 10.0;
- m_DoseUnit.m_PostMA->Update(fma);
- FireNotify(AttrKey::POSTMA, m_DoseUnit.m_PostMA->JSGet());
- FINFO("Actual exposure parameters MA:{$}", m_DoseUnit.m_PostMA->JSGet().c_str());
- };
- //after mas
- auto HWAP = [this](const char* value, int length)
- {
- assert(value);
- float fmas = atof(value) / 10.0;
- m_DoseUnit.m_PostMAS->Update(fmas);
- FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet());
- FINFO("Actual exposure parameters MAS:{$}", m_DoseUnit.m_PostMAS->JSGet().c_str());
- };
- //FOCUS
- auto HWFocus = [this](const char* value, int length)
- {
- assert(value);
- int nfous = atoi(value);
- if (m_DoseUnit.m_Focus->Update(nfous))
- FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
- FINFO("Current focus:{$}, FO={$}", atoi(m_DoseUnit.m_Focus->JSGet().c_str()) ? "large focus" : "small focus", m_DoseUnit.m_Focus->JSGet().c_str());
- };
- //TECHMODE
- auto HWTechmode = [this](const char* value, int length)
- {
- assert(value);
- int ntechmode = atoi(value);
- if (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;
- }
- };
- //WROKSTATION
- 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());
- };
- //PR
- auto HWPR = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 2)
- {
- RespondPR2();
- //m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
- }
- else if (nValue == 1)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE);
- RespondPR1();
- }
- else if (nValue == 0)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
- RespondPR0();
- m_bGenBusy = false;
- }
- FINFO("m_DoseUnit.m_GenSynState: {$};", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- };
- //XR
- auto HWXR = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- if (nValue == 2)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
- }
- else if (nValue == 1)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
- RespondXR1();
- }
- else if (nValue == 0)
- {
- m_bGenBusy = false;
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF);
- RespondXR0();
- }
- FINFO("m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet().c_str());
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- };
- auto HWAPDOSE = [this](const char* value, int length)//post mas
- {
- assert(value);
- m_DoseUnit.m_PostMAS->Update(atof(value) / 100.0);
- FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
- FINFO("Actual exposure parameters MAS: {$}", m_DoseUnit.m_PostMAS->JSGet().c_str());
- };
- auto HWATDOSE = [this](const char* value, int length)
- {
- assert(value);
- m_DoseUnit.m_PostMS->Update(atof(value) / 100.0);
- FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
- FINFO("Actual exposure parameters MS: {$}", m_DoseUnit.m_PostMS->JSGet().c_str());
- };
- auto HWDAP = [this](const char* value, int length)
- {
- assert(value);
- FINFO("Recv DAP ={$}", atof(value) / 100.0);
- };
- auto HWEHE = [this](const char* value, int length)
- {
- m_iHeartBeats = 0;
- assert(value);
- int nhe = atoi(value);
- if (m_DoseUnit.m_HE->Update(nhe))
- FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
- };
- auto HWHH = [this](const char* value, int length)
- {
- m_iHeartBeats = 0;
- assert(value);
- int nhe = atoi(value);
- if (m_DoseUnit.m_GenHE->Update(nhe))
- FireNotify(m_DoseUnit.m_GenHE->GetKey(), m_DoseUnit.m_GenHE->JSGet());
- };
- auto HWDS = [this](const char* value, int length)
- {
- assert(value);
- m_bDAPEnable = (bool)atoi(value);
- };
- auto HWFLD = [this](const char* value, int length)
- {
- assert(value);
- };
- auto HWER = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- char tmpbuf[4] = { 0,0,0,0 };
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- if (nValue != 0)
- {
- std::unordered_map<std::string, std::string> errorMessages = {
- {"100", "AEC Back-up Timer - Exposure Terminated"},
- {"101", "AEC mAs Exceeded - Exposure Terminated"},
- {"102", "Door Interlock Error"},
- {"103", "Calibration Data Corrupt Error"},
- {"104", "AEC Data Corrupt Error"},
- {"105", "Receptor Data Corrupt Error"},
- {"106", "Tube Data Corrupt Error"},
- {"107", "Generator Limit Data Corrupt Error"},
- {"108", "mA Correction Data Corrupt Error"},
- {"109", "Not Enabled Error"},
- {"110", "AEC Feedback Error - No Feedback Signal Detected"},
- {"111", "EXP_SW Signal Active in Standby State"},
- {"112", "Calibration Error - No mA"},
- {"113", "Calibration Error - Maximum Filament Current Exceeded"},
- {"114", "MA During Exposure too High"},
- {"115", "MA During Exposure too Low"},
- {"116", "Generator KW Limit"},
- {"117", "Generator KV Limit"},
- {"118", "Generator MA Limit"},
- {"119", "Generator MS Limit"},
- {"120", "Generator MAS Limit"},
- {"121", "Tube KW Limit"},
- {"122", "Tube KV Limit"},
- {"123", "Tube MA Limit"},
- {"124", "Tube MAS Limit"},
- {"125", "Parameter Limit"},
- {"126", "Manually Terminated Exposure"},
- {"127", "Preparation Time-out Error prep time is over 30s or 60s"},
- {"128", "Prep Input Active During Initialization Phase"},
- {"129", "X-ray Input Active During Initialization Phase"},
- {"130", "No Fields Selected in AEC mode"},
- {"131", "Generator AEC Density Limit"},
- {"132", "Calibration Error - Manually Terminated"},
- {"133", "EEPROM Communication Error"},
- {"134", "RTC Communication Error"},
- {"135", "AEC Channel Error"},
- {"136", "Anode Communication Error"},
- {"137", "EXP_OK TimeOut"},
- {"138", "KV TimeOut"},
- {"139", "Mosfet Temperature Limit Exceeded"},
- {"140", "HU Power Limit"},
- {"141", "HU Power Warning"},
- {"142", "Small Focus Disable"},
- {"143", "Large Focus Disable"},
- {"144", "Low Speed Disable"},
- {"145", "High Speed Disable"},
- {"146", "Anode Heat Warning Exceeded"},
- {"147", "Anode Heat Limit Exceeded"},
- {"148", "KV Unbalance"},
- {"149", "Thermal Switch Interlock Error"},
- {"150", "Emergency Error"},
- {"151", "KV Correction Data Corrupt Error"},
- {"152", "Generator Tank Power Limit"},
- {"153", "AEC Standby Signal Error"},
- {"154", "DCBUS Calibration Data Corrupt Error"},
- {"155", "Fluoro Timer Terminated "},
- {"156", "Fluoro Timer Terminated "},
- {"157", "Power Off In X - Ray State"},
- {"158", "DAP Data Corrupt "},
- {"159", "Auto APR TimeOut "},
- {"160", "ERR_FLUORO_ABSFDBNONE"},
- {"200", "FLASH LOCK"},
- {"201", "FLASH REVID_INVALID"},
- {"202", "FLASH ADDR_INVALID"},
- {"203", "FLASH INCORRECT_PARTID"},
- {"204", "FLASH API_SILICON_MISMATCH"},
- {"205", "FLASH ERASE ERROR"},
- {"206", "FLASH FAIL_PROGRAM"},
- {"207", "FLASH FAIL_ZERO_BIT_ERROR"},
- {"208", "FLASH FAIL_VERIFY"},
- {"209", "FLASH BUSY"},
- {"210", "FLASH_PROGRM_ADDR_ERROR"},
- {"211", "UPDATA_VERSION_ERROR"},
- {"212", "UPDATA SN_ERROR"},
- {"213", "UPDATA_BYTE_COUNT_ERROR"},
- {"214", "UPDATA_CHECKSUM_ERROR"}
- };
- char ErrorCode[20];
- sprintf_s(ErrorCode, "PSGHR_ER_%d", nValue);
- char temp[50] = { 0 };
- sprintf_s(temp, "ER%03d", nValue);
- HWSend(temp, strlen(temp));
- int level = 1;
- auto it = errorMessages.find(tmpbuf);
- if (it != errorMessages.end())
- {
- //m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
- //FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
- }
- }
- else
- {
- int level = 1;
- char ErrorCode[20];
- m_MSGUnit->DelWarnMessage(ErrorCode, level, "");
- }
- };
- auto HWEL = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- char tmpbuf[3] = { 0,0,0 };
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- if (nValue != 0)
- {
- std::unordered_map<std::string, std::string> errorMessages = {
- {"001", "Generator CPU Real Time Clock Error"},
- {"002", "Main Contactor Error"},
- {"003", "Rotor Fault"},
- {"004", "DC Bus Voltage too Low"},
- {"005", "DC Bus Voltage too High"},
- {"006", "Filament Adjust Error"},
- {"007", "Filament PowerBoard Not Connected"},
- {"008", "Filament Short Circuit"},
- {"019", "Filament Overcurrent"},
- {"010", "Anode Overcurrent"},
- {"011", "Cathode Overcurrent"},
- {"012", "Anode Overvoltage"},
- {"013", "Cathode Overvoltage"},
- {"014", "ARC"},
- {"015", "Short Current 1"},
- {"016", "Short Current 2"},
- {"017", "Short Current A"},
- {"018", "Short Current B"}
- };
- char ErrorCode[20];
- sprintf_s(ErrorCode, "PSGHR_EL_%d", nValue);
- char temp[50] = { 0 };
- sprintf_s(temp, "EL%03d", nValue);
- HWSend(temp, strlen(temp));
- int level = 1;
- auto it = errorMessages.find(tmpbuf);
- if (it != errorMessages.end())
- {
- m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- m_MSGUnit->AddErrorMessage(ErrorCode, level, it->second.c_str());
- }
- }
- else
- {
- int level = 1;
- char ErrorCode[20];
- m_MSGUnit->DelErrorMessage(ErrorCode, level, "");
- }
- };
- auto HWEI = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- char tmpbuf[3] = { 0,0,0 };
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- if (nValue != 0)
- {
- std::unordered_map<std::string, std::string> errorMessages = {
- {"400", "Enter the service mode"},
- {"401", "Exit the service mode"},
- {"402", "Resonance Overcurrent1"},
- {"403", "Resonance Overcurrent2"},
- {"404", "Resonance Overcurrent3"},
- {"405", "Charging, Please Wait "},
- {"406", "DAC Reset "},
- {"407", "X-Rays State PowerOff "},
- {"408", "Fluoro Disable "},
- {"409", "Fluoro Timer Warning Level Exceeded"},
- {"410", "Anode Heat Warning Exceeded "},
- {"411", "MA Too Low "}
- };
- char ErrorCode[20];
- sprintf_s(ErrorCode, "PSGHR_EI_%d", nValue);
- char temp[50] = { 0 };
- sprintf_s(temp, "EI%03d", nValue);
- HWSend(temp, strlen(temp));
- int level = 1;
- auto it = errorMessages.find(tmpbuf);
- if (it != errorMessages.end())
- {
- //m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
- //FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
- }
- }
- else
- {
- int level = 1;
- char ErrorCode[20];
- m_MSGUnit->DelWarnMessage(ErrorCode, level, "");
- }
- };
- auto HWMSG = [this](const char* value, int length)
- {
- assert(value);
- int nValue = atoi(value);
- char tmpbuf[3] = { 0,0,0 };
- tmpbuf[0] = value[0];
- tmpbuf[1] = value[1];
- tmpbuf[2] = value[2];
- if (nValue != 0)
- {
- std::unordered_map<std::string, std::string> errorMessages = {
- {"001", "Rotating anode protection parameters are incorrectly configured"},
- {"002", "Press emergency stop of high voltage generator"},
- {"003", "The first level hand brake is not triggered, and the second level hand brake is triggered"},
- {"004", "The first level hand brake is pressed during the wake - up or startup process of the high - voltage generator."},
- {"005", "The second level hand brake is pressed during the wake - up or startup process of the high - voltage generator."},
- {"006", "Low battery power of the high - voltage generator, please recharge."},
- {"007", "Anode thermal capacity exceeds the warning value."},
- {"008", "Exposure time interval is too short, please wait for exposure."},
- {"009", "Parameter adjustment is prohibited during exposure."},
- {"010", "High - voltage generator is not ready, please confirm the status."},
- {"011", "The oil tank temperature of the high - voltage generator exceeds the warning value."},
- {"012", "Training cannot be conducted in this state."},
- {"013", "The tube current of the high voltage generator is low."},
- {"014", "The PFC module of the high voltage generator works abnormally."},
- {"015", "Battery output power limits for high voltage generators."},
- {"016", "The battery of the high voltage generator is charging."},
- {"017", "The mA parameter of the high voltage generator exceeds the maximum tube value."},
- {"018", "The kV parameter of the high voltage generator exceeds the limit value."},
- {"019", "The mA parameter of the high voltage generator exceeds the limit value."},
- {"020", "The ms parameter of the high voltage generator exceeds the limit value."},
- {"021", "The mAs parameter of the high voltage generator exceeds the limit value."},
- {"022", "Filament selection parameter exceeds the limit."},
- {"023", "Anode rotation speed selection parameter exceeds the limit."},
- {"024", "The exposure technical parameters of the high voltage generator exceed the limits."},
- {"025", "AEC density parameter exceeds the limit."},
- {"026", "AEC field selection parameter exceeds the limit."},
- {"027", "AEC channel parameter exceeds the limit."},
- {"028", "AEC sensitivity parameter exceeds the limit."},
- {"029", "High - voltage generator power exceeds the limit."},
- {"030", "Tube power exceeds the limit."},
- {"031", "The frame rate parameter of the high voltage generator exceeds the limit value."},
- {"032", "Exposure parameter exceeds the high - voltage generator energy storage limit."},
- {"033", "High voltage generator battery pack alarm."},
- {"035", "Foot brake signal is pressed during the wake - up or startup process of the high - voltage generator."},
- {"036", "Cumulative fluoroscopy time alarm."},
- {"037", "The console of the high voltage generator is not connected, please open the console."},
- {"038", "Tube sleeve thermal capacity exceeds the warning value."},
- {"049", "Bus voltage of the high - voltage generator exceeds the limit."},
- {"050", "High - voltage generator does not support this exposure mode."},
- {"051", "The rotation speed of the rotating anode does not meet the exposure requirements."},
- {"052", "The second level hand brake is not pressed within the specified time."},
- {"053", "Interlock 1 is effective during the exposure process of the high - voltage generator."},
- {"054", "Timeout for feedback signal in flat panel mode."},
- {"055", "The kV establishment timeout of the high voltage generator."},
- {"056", "Anode thermal capacity exceeds the limit."},
- {"057", "Filament calibration data abnormality."},
- {"058", "Tube current is too low during training."},
- {"059", "Release hand brake prematurely during exposure."},
- {"060", "AEC feedback abnormality."},
- {"061", "Inverter temperature of the high - voltage generator exceeds the limit."},
- {"062", "kV is too low during exposure, exposure abnormality aborted."},
- {"063", "kV is too high during exposure, exposure abnormality aborted."},
- {"064", "Oil temperature of the high - voltage generator exceeds the limit."},
- {"065", "Tube sleeve thermal capacity exceeds the limit."},
- {"066", "The current exposure parameters of the high voltage generator exceed the heat capacity limit."},
- {"068", "mA is too high during exposure, exposure abnormality aborted."},
- {"069", "The DRVEN enable of the high voltage generator to establish a timeout."},
- {"070", "Interruption in communication with the rotating anode."},
- {"071", "Emergency stop is pressed during exposure."},
- {"072", "The battery pack of the high voltage generator is faulty."},
- {"073", "Resonant current exceeds the limit, exposure abnormality aborted(software)."},
- {"074", "Anode kV exceeds the limit, exposure abnormality aborted(software)."},
- {"075", "Cathode kV exceeds the limit, exposure abnormality aborted(software)."},
- {"076", "Filament current exceeds the limit(software)."},
- {"078", "Oil tank power limit of the high - voltage generator."},
- {"080", "Deviation of anode kV and cathode kV exceeds the limit, exposure abnormality aborted."},
- {"081", "Power exceeds the limit during exposure, exposure abnormality aborted."},
- {"082", "The external synchronization signal of the high voltage generator has timed out."},
- {"083", "Fan fault in high voltage generator."},
- {"084", "High voltage generator InterLock1 effective."},
- {"085", "High voltage generator InterLock2 effective."},
- {"087", "Release foot brake prematurely during exposure."},
- {"088", "Foot brake signal abnormality."},
- {"089", "The DA chip of the high voltage generator is abnormal."},
- {"090", "Timeout for cumulative fluoroscopy time."},
- {"091", "The external discharge line of the high voltage generator enables the signal to timeout."},
- {"092", "XRAYReady invalid."},
- {"093", "High voltage generator during exposure interlock 2 effective."}
- };
- char ErrorCode[20];
- sprintf_s(ErrorCode, "PSGHR_MSG_%d", nValue);
- int level = 1;
- /*char temp[50] = { 0 };
- sprintf_s(temp, "MSG%03d", nValue);
- HWSend(temp, strlen(temp));*/
- auto it = errorMessages.find(tmpbuf);
- if (it != errorMessages.end())
- {
- FINFO("WarnCode: {$}, Level: {$}, ResInfo: {$}\n", ErrorCode, level, it->second.c_str());
- m_MSGUnit->AddWarnMessage(ErrorCode, level, it->second.c_str());
- }
- }
- else
- {
- int level = 1;
- char WarnCode[20]{ "" };
- m_MSGUnit->DelWarnMessage(WarnCode, level, "");
- }
- };
- auto HWST = [this](const char* value, int length)
- {
- assert(value);
- int genStatus = atoi(value);
- FINFO("genStatus={$}", genStatus);
- switch (genStatus)
- {
- case MERCURY_PHASE_INI:
- //初始化
- FDEBUG("get Gen Status_1:GENSTATE {$} -> STATUS_INIT", m_DoseUnit.m_GenState->JSGet());
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_INIT))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- break;
- case MERCURY_PHASE_STANDBY:
- FDEBUG("get Gen Status_2:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
- if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY))
- FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
- break;
- default:
- FDEBUG("get Gen Status:[{$}] unknown", genStatus);
- break;
- }
- };
- arFrame.clear();
- arFrame.push_back(tFrameMapping("EL", 2, HWEL));
- arFrame.push_back(tFrameMapping("EI", 2, HWEI));
- arFrame.push_back(tFrameMapping("ER", 2, HWER));
- arFrame.push_back(tFrameMapping("MSG", 3, HWMSG));
- //arFrame.push_back(tFrameMapping("TU", 2, HWTU));
- arFrame.push_back(tFrameMapping("EC", 2, HWNotProcess));
- arFrame.push_back(tFrameMapping("PW", 2, HWNotProcess));
-
- arFrame.push_back(tFrameMapping("KV", 2, HWKV));
- arFrame.push_back(tFrameMapping("MX", 2, HWMAS));
- arFrame.push_back(tFrameMapping("MA", 2, HWMA));
- arFrame.push_back(tFrameMapping("MS", 2, HWMS));
- arFrame.push_back(tFrameMapping("VP", 2, HWVP));
- arFrame.push_back(tFrameMapping("PA", 2, HWPA));
- arFrame.push_back(tFrameMapping("AP", 2, HWAPDOSE));
- arFrame.push_back(tFrameMapping("ET", 2, HWTechmode));
- arFrame.push_back(tFrameMapping("FO", 2, HWFocus));
- arFrame.push_back(tFrameMapping("WS", 2, HWWS));
- arFrame.push_back(tFrameMapping("PR", 2, HWPR));
- arFrame.push_back(tFrameMapping("XR", 2, HWXR));
- arFrame.push_back(tFrameMapping("AT", 2, HWATDOSE));
- arFrame.push_back(tFrameMapping("HE", 2, HWEHE));
- arFrame.push_back(tFrameMapping("HH", 2, HWHH));
- arFrame.push_back(tFrameMapping("DA", 2, HWDAP));
- arFrame.push_back(tFrameMapping("DV", 2, HWDAP));
- arFrame.push_back(tFrameMapping("DS", 2, HWDS));
- arFrame.push_back(tFrameMapping("ST", 2, HWST));
- arFrame.push_back(tFrameMapping("PR", 2, HWPR));
- }
- bool nsGEN::MERCURYDevice::ReConnect()
- {
- FINFO("Enter PSG_reConnect");
- m_SCF.Disconnect();
- if (!pIODriver)
- {
- FINFO("PSG_reConnect:Driver null");
- }
- else if (pIODriver->ReConnection(m_SCF))
- {
- FireErrorMessage(false, 1, "lost Connect");
- m_bConnectFlag = true;
- FINFO("PSG_reConnect success");
- return true;
- }
- else
- {
- FINFO("PSG_reConnect failed");
- }
- return false;
- }
- bool nsGEN::MERCURYDevice::EnableBucky(int nbucky)
- {
- char temp[50]{ 0 };
- sprintf_s(temp, "BU%1d", nbucky);
- return HWSend(temp, strlen(temp));
- }
- bool nsGEN::MERCURYDevice::ECHO(void)
- {
- FINFO("Echo");
- return HWSend("EC9", 3);
- }
- bool nsGEN::MERCURYDevice::StartHardwareStatusThread()
- {
- FINFO("enter Start HardwareStatus Thread ");
- if (m_pHardwareStatusThread == NULL)
- {
- DWORD m_HardwareStatusID;
- m_pHardwareStatusThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
- if (m_pHardwareStatusThread == NULL)
- {
- FERROR("Start HardwareStatus Thread Failed");
- return false;
- }
- }
- return true;
- }
- DWORD nsGEN::MERCURYDevice::HardwareStatusThread(LPVOID pParam)
- {
- MERCURYDevice* pCurGen = (MERCURYDevice*)pParam;
- if (pCurGen == NULL)
- {
- return false;
- };
- HeartBeatFlag = true;
- int value = 1;
- if ((int)pCurGen->m_GenConfig["loopTime"] >= 100)
- {
- pCurGen->m_iLoopTime = (int)pCurGen->m_GenConfig["loopTime"];
- }
- FINFO("loopTime = {$}", pCurGen->m_iLoopTime.load());
- int currtTime = pCurGen->m_iLoopTime;
- while (m_bExtraFlag)
- {
- currtTime = pCurGen->m_iLoopTime;
- Sleep(currtTime);
- pCurGen->GetST();
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- // MERCURYDriver
- //-----------------------------------------------------------------------------
- nsGEN::MERCURYDriver::MERCURYDriver()
- {
- m_pAttribute.reset(new ResDataObject());
- m_pDescription.reset(new ResDataObject());
- }
- nsGEN::MERCURYDriver::~MERCURYDriver()
- {
- Close();
- gLogger = nullptr;
- }
- void nsGEN::MERCURYDriver::Prepare()
- {
- string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
- Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.MERCURY");
- auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
- gLogger = Log4CPP::LogManager::GetLogger("GEN.MERCURY");
- m_SCFDllName = GetConnectDLL(m_ConfigFileName);
- super::Prepare();
- }
- std::string nsGEN::MERCURYDriver::DriverProbe()
- {
- FINFO("DriverProbe in");
- 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", "MERCURY");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Drv");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- bool nsGEN::MERCURYDriver::ReConnection(nsSCF::SCF& DevSCF)
- {
- super::Disconnect();
- FINFO("ReConnection:SCF Disconnect");
- ResDataObject Connection = GetConnectParam(m_ConfigFileName);
- FINFO("ReConnection: {$}", Connection.encode());
- auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::MERCURYDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
- if (erCode == SCF_ERR::SCF_SUCCEED)
- {
- Sleep(1000);
- auto rc = super::Connect();
- if (!rc)
- {
- FINFO("ReConnection:super Connect failed");
- }
- else
- {
- DevSCF = m_SCF;
- return true;
- }
- }
- else
- {
- FINFO("ReConnection failed");
- }
- return false;
- }
- bool nsGEN::MERCURYDriver::Connect()
- {
- ResDataObject Connection = GetConnectParam(m_ConfigFileName);
- FINFO("connections: {$}", Connection.encode());
- auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::MERCURYDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
- if (erCode != SCF_ERR::SCF_SUCCEED)
- return false;
- auto rc = super::Connect();
- if (!rc)
- return false;
- return true;
- }
- auto nsGEN::MERCURYDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
- {
- FINFO("CreateDevice in");
- if (!m_SCF.isConnected())
- {
- FERROR("CreateDevice:m_SCF is not Connected \n");
- return nullptr;
- }
- auto dev = std::unique_ptr <IODevice>(new IODevice(new MERCURYDevice(EventCenter, m_SCF, m_ConfigFileName)));
- FINFO("CreateDevice out");
- return dev;
- }
- void nsGEN::MERCURYDriver::FireNotify(int code, std::string key, std::string content)
- {
- EventCenter->OnNotify(code, key, content);
- }
- bool nsGEN::MERCURYDriver::isConnected() const
- {
- if (super::isConnected())
- {
- return true;
- }
- else
- {
- if(HeartBeatFlag)
- return true;
- else
- return false;
- }
- }
- std::string nsGEN::MERCURYDriver::GetResource()
- {
- FDEBUG("GetResource");
- ResDataObject r_config, temp;
- if (!temp.loadFile(m_ConfigFileName.c_str()))
- {
- return "";
- }
- m_ConfigAll = temp;
- r_config = temp["CONFIGURATION"];
- m_Configurations = r_config;
- ResDataObject DescriptionTemp;
- ResDataObject DescriptionSend;
- ResDataObject m_DescriptionSend;
- ResDataObject ListTemp;
- string strTemp = ""; //用于读取字符串配置信息
- string strIndex = ""; //用于读取配置信息中的List项
- int nTemp = -1; //用于读取整型配置信息
- char sstream[10] = { 0 }; //用于转换值
- string strValue = ""; //用于存储配置的值
- string strType = ""; //用于存储配置的类型 int/float/string...
- /***
- * 1. 通过循环,将所有配置项写到pDeviceConfig
- * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
- ***/
- try
- {
- //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
- int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
- m_pAttribute->clear();
- m_pDescription->clear();
- for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
- {
- DescriptionTemp.clear();
- DescriptionSend.clear();
- ListTemp.clear();
- //AttributeType
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
- DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
- DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
- strType = strTemp; //记录配置项的类型
- //AttributeKey
- //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
- nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
- GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
- //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
- //2. 赋值
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- if ("int" == strType)
- {
- (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
- }
- else if ("float" == strType)
- {
- (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
- }
- else //其它先按string类型处理
- {
- (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
- }
- //printf("********************************outkey =%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
- //AttributeAccess
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
- DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
- /*
- //AttributeRangeMin
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
- }
- //AttributeRangeMax
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
- }
- */
- //AttributeList
- nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
- if (nTemp > 0) //ListNum不大于0时说明不需要list配置
- {
- for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
- auto temKey = std::to_string(nListIndex);
- ListTemp.add(temKey.c_str(), strTemp.c_str());
- }
- DescriptionTemp.add(ConfKey::CcosList, ListTemp);
- DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
- }
- //AttributeRequired
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
- DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
- //AttributeDefaultValue
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
- }
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
- m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("Get config error: {$}", e.what());
- return "";
- }
- ResDataObject resDeviceResource;
- resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
- resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
- ResDataObject DescriptionTempEx;
- DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
- m_DeviceConfig.clear();
- m_DeviceConfig = DescriptionTempEx;
- resDeviceResource.clear();
- resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
- resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
- DescriptionTempEx.clear();
- DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
- m_DeviceConfigSend.clear();
- m_DeviceConfigSend = DescriptionTempEx;
- string res = m_DeviceConfigSend.encode();
- return res;
- }
- std::string nsGEN::MERCURYDriver::DeviceProbe()
- {
- FINFO("DeviceProbe() in");
- ResDataObject r_config, HardwareInfo;
- if (r_config.loadFile(m_ConfigFileName.c_str()))
- {
- HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
- HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
- HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
- HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
- HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
- }
- else
- {
- HardwareInfo.add("MajorID", "Generator");
- HardwareInfo.add("MinorID", "Dr");
- HardwareInfo.add("VendorID", "PSGHR");
- HardwareInfo.add("ProductID", "HF");
- HardwareInfo.add("SerialID", "Dev");
- }
- string ret = HardwareInfo.encode();
- FINFO("DeviceProbe() out");
- return ret;
- }
- void nsGEN::MERCURYDriver::Disconnect()
- {
- super::Disconnect();
- m_SCF.Disconnect();
- Close();
- gLogger = nullptr;
- }
- void nsGEN::MERCURYDriver::Dequeue(const char* Packet, DWORD Length)
- {
- DecodeFrame(Packet, Length);
- }
- PACKET_RET nsGEN::MERCURYDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
- {
- if (nLength < 1)
- {
- FINFO("nLength < 1, nLength=={$} \n", nLength);
- return PACKET_USELESS;
- }
- for (DWORD i = 0; i < nLength - 1; i++)
- {
- //1 首先寻找包头
- //if (RecData[i] == 0x02)
- //{
- // if (i != 0)
- // {
- // PacketLength = i; //i之前的数据,全部扔掉
- // char strtemp[100] = { 0 };
- // memcpy(strtemp, RecData, i);
- // strtemp[PacketLength + 1] = 0;
- // printf("==IN error data ==:%s,PacketLength=%d,nLength=%d\n", strtemp, PacketLength, nLength);
- //
- // return PACKET_USELESS;
- // }
- //}
- if (RecData[i] == 0x03)
- {
- PacketLength = i + 2; //+2 because index + ETX + sum.
- char strtemp[100] = { 0 };
- memcpy(strtemp, RecData, i); //RKC005(not include 03 + sum); //only 复制 0x03之前的数据,这样解析时,后面的03 ,sum 都不要了。
- strtemp[PacketLength + 1] = 0;
- FINFO("==IN==:{$}\n", strtemp);
- return PACKET_ISPACKET;
- }
- }
- return PACKET_NOPACKET;
- }
- bool nsGEN::MERCURYDriver::GetDeviceConfig(std::string& Cfg)
- {
- Cfg = m_DeviceConfigSend.encode();
- printf("GetDeviceConfig over , %s", Cfg.c_str());
- return true;
- }
- bool nsGEN::MERCURYDriver::SetDeviceConfig(std::string Cfg)
- {
- FINFO("--Func-- SetDeviceConfig {$}", Cfg.c_str());
- printf("\n--Func-- SetDeviceConfig %s\n", Cfg.c_str());
- ResDataObject DeviceConfig;
- DeviceConfig.decode(Cfg.c_str());
- ResDataObject DescriptionTempEx;
- DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
- FDEBUG("Attribute:{$}", DescriptionTempEx.encode());
- bool bSaveFile = false; //true:重新保存配置文件
- string strAccess = "";
- for (int i = 0; i < DescriptionTempEx.size(); i++)
- {
- string strKey = DescriptionTempEx.GetKey(i);
- FINFO("{$}", strKey.c_str());
- printf("%s\n", strKey.c_str());
- try
- {
- if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
- {
- strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
- if ("RW" == strAccess)
- {
- //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
- //1. 修改内存中的值,用于给上层发消息
- (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
- //2. 拿到Innerkey
- int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
- FINFO("nConfigInfoCount {$}", nConfigInfoCount);
- string strTemp = ""; //存储AttributeKey
- for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- if (strTemp == strKey)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
- break;
- }
- }
- //3. 修改配置文件中的值
- if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
- {
- FDEBUG("SetDeviceConfigValue over");
- bSaveFile = true;
- }
- }
- else
- {
- FINFO("{$} is not a RW configuration item", strKey.c_str());
- }
- }
- else
- {
- FINFO("without this attribute {$}", strKey.c_str());
- }
- }
- catch (ResDataObjectExption& e)
- {
- printf("\nSetDriverConfig crashed: %s\n", e.what());
- FERROR("SetDriverConfig crashed: {$}", e.what());
- return false;
- }
- }
- if (bSaveFile)
- {
- //3. 重新保存配置文件
- SaveConfigFile(true);
- }
- return true;
- }
- bool nsGEN::MERCURYDriver::SaveConfigFile(bool bSendNotify)
- {
- m_ConfigAll["CONFIGURATION"] = m_Configurations;
- bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
- FINFO("SaveConfigFile over {$}", bRt);
- return true;
- }
- bool nsGEN::MERCURYDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
- {
- strValue = "";
- string strTemp = pInnerKey;
- if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
- {
- int pos = 0;
- ResDataObject resTemp = config;
- while ((pos = strTemp.find_first_of(',')) != string::npos)
- {
- string Key = strTemp.substr(0, pos);
- string TempValue = resTemp[Key.c_str()].encode();
- resTemp.clear();
- resTemp.decode(TempValue.c_str());
- strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
- }
- if (strTemp != "")
- {
- strValue = (string)resTemp[strTemp.c_str()];
- }
- else
- {
- strValue = (string)resTemp;
- }
- }
- return true;
- }
- bool nsGEN::MERCURYDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
- {
- string strTemp = pInnerKey;
- FDEBUG("Begin to change {$} item value to {$}", pInnerKey, szValue);
- printf("Begin to change {%s} item value to {%s}\n", pInnerKey, szValue);
- if (1 == nPathID)
- {
- try {
- int pos = 0;
- ResDataObject* resTemp = &config;
- while ((pos = strTemp.find_first_of(',')) != string::npos)
- {
- string Key = strTemp.substr(0, pos);
- resTemp = &(*resTemp)[Key.c_str()];
- strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
- }
- if (strTemp != "")
- {
- (*resTemp)[strTemp.c_str()] = szValue;
- }
- else
- {
- *resTemp = szValue;
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("SetDriverConfigvalue crashed: {$}", e.what());
- return false;
- }
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- // GetIODriver & CreateIODriver
- //-----------------------------------------------------------------------------
- static nsGEN::MERCURYDriver gIODriver;
- extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
- {
- pIODriver = new nsGEN::MERCURYDriver();
- return pIODriver;
- }
|