1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041 |
- #include "stdafx.h"
- #include "CCOS.Dev.FPD.iRayDM.h"
- #include "IRayDMCtrl.h"
- #include "FileVersion.hpp"
- #include "DICOMImageHeadKey.h"
- #pragma comment(lib, "Version.lib")
- namespace nsFPD = CCOS::Dev::Detail::Detector;
- Log4CPP::Logger* //mLog::gLogger = nullptr;
- static nsFPD::IRayDriver gIODriver;
- //=================================================================================================================================================================================
- // GetIODriver & CreateIODriver
- //=================================================================================================================================================================================
- extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
- {
- return new nsFPD::IRayDriver();
- }
- //==============================================================================
- // 驱动对象
- //==============================================================================
- nsFPD::IRayDriver::IRayDriver()
- {
- dev = NULL;
- m_bConnect = false;
- m_pAttribute.reset(new ResDataObject());
- m_pDescription.reset(new ResDataObject());
- }
- nsFPD::IRayDriver::~IRayDriver()
- {
- }
- //驱动准备
- void nsFPD::IRayDriver::Prepare()
- {
- string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Detector\Conf\Log4CPP.Config.FPD.xml)";
- Log4CPP::GlobalContext::Map::Set(ZSKK::Utility::Hash("LogFileName"), "FPD.iRayDM");
- bool bRet = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
- if (bRet == false)
- {
- return;
- }
- //mLog::gLogger = Log4CPP::LogManager::GetLogger("FPD.iRayDM");
- string szMouldPath = GetProcessDirectory() + R"(\OEMDrivers\Detector\IRayDM\CCOS.Dev.FPD.iRayDM.dll)";
- #ifdef _WIN64
- //mLog::Force("------------------------ Version: {$} (64-bit) ------------------------", FileVersion(szMouldPath.c_str()).GetVersionString());
- #else
- //mLog::Force("------------------------ Version: {$} (32-bit) ------------------------", FileVersion(szMouldPath.c_str()).GetVersionString());
- #endif
- //mLog::Info("IRay Driver Prepare");
- dev = new FPDDeviceIRay(EventCenter, m_ConfigFileName);
- //mLog::Info("new FPDDeviceIRay over");
- }
- //驱动连接
- bool nsFPD::IRayDriver::Connect()
- {
- //mLog::Info("IRay Driver Connect");
- m_bConnect = true;
- return true;
- }
- //驱动断连
- void nsFPD::IRayDriver::Disconnect()
- {
- m_bConnect = false;
- }
- //判断驱动是否连接
- bool nsFPD::IRayDriver::isConnected() const
- {
- return m_bConnect;
- }
- //驱动创建设备对象
- auto nsFPD::IRayDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
- {
- //mLog::Info("CreateDevice({$})", index);
- auto Driver = std::unique_ptr <IODevice>(new IODevice(dev));
- dev->CreateDevice();
- dev->Register();
- return Driver;
- }
- //驱动探针
- std::string nsFPD::IRayDriver::DriverProbe()
- {
- //mLog::Info("Driver Probe");
- 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", "iRay");
- HardwareInfo.add("ProductID", "Mars");
- HardwareInfo.add("SerialID", "Driver");
- }
- string ret = HardwareInfo.encode();
- //mLog::Info("Diver_Probe over");
- return ret;
- }
- //获取驱动配置
- bool nsFPD::IRayDriver::GetDeviceConfig(std::string& Cfg)
- {
- Cfg = m_DeviceConfig.encode();
- //mLog::Info("GetDeviceConfig over");
- return true;
- }
- //驱动设置设备配置
- bool nsFPD::IRayDriver::SetDeviceConfig(std::string Cfg)
- {
- //mLog::Info("SetDeviceConfig {$} ", Cfg.c_str());
- //mLog::Info("SetDeviceConfig over");
- return true;
- ResDataObject DeviceConfig;
- DeviceConfig.decode(Cfg.c_str());
- ResDataObject DescriptionTempEx;
- DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
- //mLog::Info("Attribute:{$}", DescriptionTempEx.encode());
- bool bSaveFile = false; //true:重新保存配置文件
- string strAccess = "";
- for (int i = 0; i < DescriptionTempEx.size(); i++)
- {
- string strKey = DescriptionTempEx.GetKey(i);
- //mLog::Info("{$}", 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");
- //mLog::Info("ConfigInfo Count: {$}", 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]))
- {
- bSaveFile = true;
- }
- }
- else
- {
- //mLog::Info("{$} is not a RW configuration item", strKey.c_str());
- }
- }
- else
- {
- //mLog::Warn("without this attribute {$}", strKey.c_str());
- }
- }
- catch (...)
- {
- //mLog::Error("SetDriverConfig crashed");
- return false;
- }
- }
- if (bSaveFile)
- {
- //3. 重新保存配置文件
- m_ConfigAll["CONFIGURATION"] = m_Configurations;
- m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
- //mLog::Info("SaveConfigFile over");
- }
- //mLog::Info("SetDriverConfig over");
- return true;
- }
- //驱动获取设备配置内容
- bool nsFPD::IRayDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
- {
- strValue = "";
- string strTemp = pInnerKey;
- ////mLog::Trace("Inner key: {$}", strTemp);
- if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
- {
- if (WiredIP == strTemp || WirelessIP == strTemp || LocalIP == strTemp)
- {
- strValue = (string)config["connections"][pInnerKey];
- }
- else if (DetectorVender == strTemp || DetectorModel == strTemp ||
- DetectorDescription == strTemp || DetectorSerialNumber == strTemp)
- {
- strValue = (string)config[pInnerKey];
- }
- else if (SyncType == strTemp || FPDWorkStation == strTemp ||
- ImageWidth == strTemp || ImageHeight == strTemp)
- {
- strValue = (string)config["ModeTable"]["DetectorMode"][pInnerKey];
- }
- else if (TempMaxLimit == strTemp || ReConnect == strTemp ||
- TempUpperLimit == strTemp || TempLowerLimit == strTemp || TempMinLimit == strTemp ||
- BatLowerLimit == strTemp || BatMiniLimit == strTemp ||
- BatLowerLimitInCali == strTemp || WifiLowerLimit == strTemp ||
- WifiMiniLimit == strTemp || HighPowerTimeout == strTemp ||
- ShowTemperature == strTemp || ShowWifi == strTemp ||
- ShowBattery == strTemp || ShowBluetooth == strTemp ||
- FPDExamMode == strTemp || FPDAcqMode == strTemp || FPDModeMatch == strTemp || CcosDetectorAttachedFlag == strTemp)
- {
- strValue = (string)config[pInnerKey];
- }
- else
- {
- strValue = "";
- //mLog::Warn("Error Configuration item: {$}", pInnerKey);
- }
- }
- return true;
- }
- //驱动设置设备配置文件内容
- bool nsFPD::IRayDriver::SetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, const char* szValue)
- {
- string strTemp = pInnerKey;
- //mLog::Trace("Begin to change {$} item value to {$}", pInnerKey, szValue);
- if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
- {
- if (WiredIP == strTemp || WirelessIP == strTemp || LocalIP == strTemp)
- {
- config["connections"][pInnerKey] = szValue;
- }
- else if (DetectorVender == strTemp || DetectorModel == strTemp ||
- DetectorDescription == strTemp || DetectorSerialNumber == strTemp)
- {
- config[pInnerKey] = szValue;
- }
- else if (SyncType == strTemp || FPDWorkStation == strTemp ||
- ImageWidth == strTemp || ImageHeight == strTemp)
- {
- config["ModeTable"]["DetectorMode"][pInnerKey] = szValue;
- }
- else if (TempMaxLimit == strTemp || ReConnect == strTemp ||
- TempUpperLimit == strTemp || TempLowerLimit == strTemp ||
- BatLowerLimit == strTemp || BatMiniLimit == strTemp ||
- BatLowerLimitInCali == strTemp || WifiLowerLimit == strTemp ||
- WifiMiniLimit == strTemp || HighPowerTimeout == strTemp ||
- ShowTemperature == strTemp || ShowWifi == strTemp ||
- ShowBattery == strTemp || ShowBluetooth == strTemp ||
- FPDExamMode == strTemp || FPDAcqMode == strTemp || FPDModeMatch == strTemp)
- {
- config[pInnerKey] = szValue;
- }
- else
- {
- //mLog::Warn("Error Configuration item: {$}", pInnerKey);
- return false;
- }
- }
- return true;
- }
- //获取设备资源
- std::string nsFPD::IRayDriver::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 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
- {
- int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
- ////mLog::Trace(g_pFPDCtrlLog, "ConfigInfo Count: {$}", nConfigInfoCount);
- m_pAttribute->clear();
- m_pDescription->clear();
- for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
- {
- DescriptionTemp.clear();
- ListTemp.clear();
- //AttributeType
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
- DescriptionTemp.add(AttributeType, strTemp.c_str());
- ////mLog::Trace(g_pFPDCtrlLog, "--> {$}: {$}", AttributeType, strTemp.c_str());
- 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);
- //2. 赋值
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- if ("int" == strType)
- {
- (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
- ////mLog::Trace(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), atoi(strValue.c_str()));
- }
- else if ("float" == strType)
- {
- (*m_pAttribute).add(strTemp.c_str(), atof(strValue.c_str()));
- ////mLog::Trace(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), atof(strValue.c_str()));
- }
- else //其它先按string类型处理
- {
- (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
- ////mLog::Trace(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), strValue.c_str());
- }
- //AttributeAccess
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
- DescriptionTemp.add(AttributeAccess, strTemp.c_str());
- ////mLog::Trace(g_pFPDCtrlLog, "{$}: {$}", AttributeAccess, strTemp.c_str());
- //AttributeRangeMin
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(AttributeRangeMin, strTemp.c_str());
- ////mLog::Trace(g_pFPDCtrlLog, "{$}: {$}", AttributeRangeMin, strTemp.c_str());
- }
- //AttributeRangeMax
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(AttributeRangeMax, strTemp.c_str());
- ////mLog::Trace(g_pFPDCtrlLog, "{$}: {$}", AttributeRangeMax, 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];
- sprintf_s(sstream, "%d", nListIndex);
- ListTemp.add(sstream, strTemp.c_str());
- ////mLog::Trace(g_pFPDCtrlLog, "list {$}: {$}", nListIndex, strTemp.c_str());
- }
- DescriptionTemp.add(AttributeList, ListTemp);
- }
- //AttributeRequired
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
- DescriptionTemp.add(AttributeRequired, strTemp.c_str());
- ////mLog::Trace(g_pFPDCtrlLog, "{$}: {$}", AttributeRequired, strTemp.c_str());
- //AttributeDefaultValue
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(AttributeDefaultValue, strTemp.c_str());
- ////mLog::Trace(g_pFPDCtrlLog, "{$}: {$}", AttributeDefaultValue, strTemp.c_str());
- }
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
- }
- }
- catch (exception e)
- {
- //mLog::Error("Get config error: {$}", e.what());
- return "";
- }
- ResDataObject resDeviceResource;
- resDeviceResource.add(ConfKey::CcosDetectorAttribute, (*m_pAttribute));
- resDeviceResource.add(ConfKey::CcosDetectorDescription, (*m_pDescription));
- ResDataObject DescriptionTempEx;
- DescriptionTempEx.add(ConfKey::CcosDetectorConfig, resDeviceResource);
- m_DeviceConfig = DescriptionTempEx;
- string res = DescriptionTempEx.encode();
- ////mLog::Debug("resDeviceResource :{$} ", DescriptionTempEx.encode());
- //if (dev)
- //{
- // dev->SyncErrorList();
- //}
- return res;
- }
- //设备探针
- std::string nsFPD::IRayDriver::DeviceProbe()
- {
- ResDataObject r_config, HardwareInfo;
- if (r_config.loadFile(m_ConfigFileName.c_str()))
- {
- HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
- HardwareInfo.add("MinorID", "Device");
- 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", "Detector");
- HardwareInfo.add("MinorID", "Device");
- HardwareInfo.add("VendorID", "iRay");
- HardwareInfo.add("ProductID", "Mars");
- HardwareInfo.add("SerialID", "1234");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- //=================================================================================================================================================================================
- // 设备对象
- //=================================================================================================================================================================================
- extern IRayCtrl* g_pIRayCtrl;
- #define MAX_STRING 1024
- nsFPD::FPDDeviceIRay::FPDDeviceIRay(std::shared_ptr <IOEventCenter> center, string ConfigPath)
- :m_strWorkPath(""),
- m_nDeviceIndex(0),
- m_eAppStatus(APP_STATUS_WORK_END),
- m_bHasGrid(false),
- m_nGridLicense(0),
- m_strVoltage(""),
- m_strLastError(""),
- m_strCalibTime(""),
- m_strLogFilePath(""),
- m_bOpened(false),
- m_bBatteryCharging(false),
- m_bRecoveringImage(false),
- m_bAbortRecover(false),
- m_bSNListExisted(false),
- m_bUIReady(false),
- m_bImagePendingOrNot(false),
- m_bResetDetector(false),
- m_nTemperCheckResult(0),
- m_nXCUStatus(0),
- m_nBatteryCapacity(0),
- m_nBatteryCharges(0),
- m_nShockCounts(0),
- m_nWorkStation(0),
- m_fDoseParam(0),
- m_nFullImgWidth(0),
- m_nFullImgHeight(0),
- m_nTopOffset(0),
- m_nLeftOffset(0),
- m_nImageBits(0),
- m_fFactorEXI2UGY(0.0f),
- m_bPreviewEnable(false),
- m_bTestSensitivity(false),
- m_fBatteryTemperature(0.0f),
- m_nXrayCalibNum(0),
- m_bCalibReportFailed(false),
- m_pwFullImageData(nullptr),
- m_pwRawImageData(nullptr),
- m_pwPreviewImg(nullptr),
- m_pPreviewImageHead(nullptr),
- m_pFullImageHead(nullptr),
- m_pDetectors(nullptr),
- m_bConnect2XCU(false),
- m_bXCUresult(false),
- m_nActiveState(FPD_NOT_ACTIVE),
- m_bDueDateWarnSend(false),
- m_bCallFDConnectOver(false),
- m_bDisConnected(false),
- m_ExitEvt(nullptr),
- m_bAttached(false),
- m_hNotifyThread(nullptr),
- m_bRecoverImageStatusInit(false),
- m_bSaveRaw(false),
- m_bUIConfirmRecover(false),
- m_nCalibrationType(CCOS_CALIBRATION_TYPE_MAX),
- m_fLTEthreshold(450.0f),
- m_CalTemperlowWarn(0.0f),
- m_CalTemperupWarn(0.0f),
- m_LETCalTemperlowWarn(0.0f),
- m_LETCalTemperupWarn(0.0f),
- m_CalTemperWarnInitialed(false),
- m_lowBatteryBuda(0),
- m_pmsLoginStatus(false),
- m_nClinicalApplicationMode(0),
- m_nFilterMode(0),
- m_bStatusInAEC(false)
- {
- g_strAppPath = GetProcessDirectory() + "\\";
- m_AcqUnit.reset(new OemAcq(center, this));
- m_SyncUnit.reset(new OemSync(center, this));
- m_CalibUnit.reset(new OemCalib(center, this));
- m_DetectorCtrlUnit.reset(new OemDetectorCtrl(center, this));
- m_Battery.reset(new DeviceBatteryMould("DetectorIRayBattery", 0, 10, 20, 30, 40, 100, 100, 0, center));
- //m_Temperature.reset(new DeviceTemperatureMould("DetectorIRayTemperature", ABS_ZERO_TEMPERATURE, 0.0f, 10.0f, 60.0f, 20.0f, 40.0f, 70.0f, 0.0f, center));
- m_Wifi.reset(new DeviceWifiMould("DetectorIRayWifi", 0, 20, 30, 40, 50, 100, 100, 0, center));
- m_DetectorConfiguration.reset(new DetectorConfiguration(ConfigPath));
- m_WarnAndError.reset(new FPDErrorWarning(center, DetectorUnitType, g_strAppPath));
- m_CalibProcess.reset(new CalibrationProcess());
- m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
- m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY));
- m_WaitCalibDoseEvt = CreateEvent(0, 1, 0, 0);
- m_OffsetCalibrationEvt = CreateEvent(0, 0, 0, 0);
- m_PauseCalibrationEvt = CreateEvent(0, 1, 0, 0);
- m_CompleteCalibrationEvt = CreateEvent(0, 1, 0, 0);
- m_CrateCalibReportEvt = CreateEvent(0, 0, 0, 0);
- m_UploadCalibMapOver = CreateEvent(0, 1, 0, 0);
- m_hXCUresult = CreateEvent(0, 1, 0, 0);
- m_ExitEvt = CreateEvent(0, 1, 0, 0);
- m_CalibGapEvt = CreateEvent(0, 1, 0, 0);
- m_WriteCumstomFileEvt = CreateEvent(0, 1, 0, 0);
- EventCenter = center;
- }
- nsFPD::FPDDeviceIRay::~FPDDeviceIRay()
- {
- SetEvent(m_ExitEvt);
- CloseHandle(m_WaitCalibDoseEvt);
- CloseHandle(m_OffsetCalibrationEvt);
- CloseHandle(m_PauseCalibrationEvt);
- CloseHandle(m_CompleteCalibrationEvt);
- CloseHandle(m_CrateCalibReportEvt);
- CloseHandle(m_WriteCumstomFileEvt);
- CloseHandle(m_UploadCalibMapOver);
- CloseHandle(m_hXCUresult);
- CloseHandle(m_CalibGapEvt);
- if (m_hNotifyThread != NULL)
- {
- CloseHandle(m_hNotifyThread);
- }
- }
- std::string nsFPD::FPDDeviceIRay::GetGUID() const
- {
- return DetectorUnitType;
- }
- bool nsFPD::FPDDeviceIRay::Prepare()
- {
- //mLog::Info("Device Prepare");
- //EventCenter->OnMaxBlockSize("DrQue", 3000 * 3000 * 2, 3, 1500 * 1500 * 2, 1);
- //SetMaxBlockSize(const char *pQueName, DWORD FullBlockSize, DWORD FullBlockCount, DWORD PrevBlockSize, DWORD PrevBlockCount)
- EventCenter->OnMaxBlockSize("RfQue", 6000 * 6000 * 2, 8, 3000 * 3000 * 2, 8); //开辟共享内存
- Connect();
- return true;
- }
- void nsFPD::FPDDeviceIRay::RegisterCtrl(nDetail::Dispatch* Dispatch)
- {
- Dispatch->Action.Push(ActionKey::GetDetectorInfo, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorInfo);
- Dispatch->Action.Push("ActiveDetector", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSActiveDetector);
- Dispatch->Action.Push("RESET", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSRESET);
- Dispatch->Action.Push("EnterExam", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSEnterExam);
- Dispatch->Action.Push("ExitExam", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSExitExam);
- Dispatch->Action.Push("RecoverImage", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSRecoverImage);
- Dispatch->Action.Push("ResetConnect", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSResetConnect);
- Dispatch->Action.Push("DisConnectFPD", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSDisConnectFPD);
- Dispatch->Action.Push("DisConnectFPDForce", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSDisConnectFPDForce);
- Dispatch->Action.Push("UpdateFirmware", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSUpdateFirmware);
- Dispatch->Action.Push("SaveSensitivity", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSSaveSensitivity);
- Dispatch->Action.Push("GetRecoverImageState", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetRecoverImageState);
- Dispatch->Get.Push("RecoverImageState", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetRecoverImageState);//event
- Dispatch->Get.Push("RecoverImageEvent", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetRecoverImageEvent);//event
- Dispatch->Get.Push(CcosDetectorStatus, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFPDStatus);
- Dispatch->Get.Push(CcosDetectorConnectStatus, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetConnectStatus);
- Dispatch->Get.Push(CcosDetectorAttach, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetAttachResult);
- Dispatch->Get.Push(CcosDetectorAttachedFlag, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetAttachStatus);
- Dispatch->Get.Push(CcosDetectorInitialStatus, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetInitialStatus);
- Dispatch->Get.Push(CcosDetectorUpdateFWStatus, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetUpdateFWStatus);
- Dispatch->Get.Push("FPDShockSensorInfo", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetShockSensorInfo);
- Dispatch->Get.Push("FieldofViewShape", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFieldofViewShape);
- Dispatch->Get.Push("FieldofViewDimension", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFieldofViewDimension);
- Dispatch->Get.Push("DetectorType", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorType);
- Dispatch->Get.Push("Description", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDescription);
- Dispatch->Get.Push("DetectorID", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorID);
- Dispatch->Get.Push("DateofLastDetectorCalibration", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDateofLastDetectorCalibration);
- Dispatch->Get.Push("TimeofLastDetectorCalibration", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetTimeofLastDetectorCalibration);
- Dispatch->Get.Push("DetectorConditionsNominalFlag", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorConditionsNominalFlag);
- Dispatch->Get.Push("FPDSensitivity", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFPDSensitivity);
- Dispatch->Get.Push("FPDSensitivityResult", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFPDSensitivityResult);
- Dispatch->Get.Push("PixelData", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetPixelData);
- Dispatch->Get.Push("TargetEXI", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetTargetEXI);
- Dispatch->Get.Push("FPDLastError", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetLastError);
- //Dispatch->Get.Push("FirmwareStatus", m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFirmwareStatus);
- }
- void nsFPD::FPDDeviceIRay::RegisterAcq(nDetail::Dispatch* Dispatch)
- {
- Dispatch->Action.Push("SetAcqMode", m_AcqUnit.get(), &AcqUnit::JSSetAcqMode);
- Dispatch->Get.Push(CcosZskkFPDState, m_AcqUnit.get(), &AcqUnit::JSGetZskkFPDState);
- Dispatch->Get.Push("NoNeedWaitImage", m_AcqUnit.get(), &AcqUnit::JSGetNoNeedWaitImage);
- Dispatch->Get.Push("ImgDataInfo", m_AcqUnit.get(), &AcqUnit::JSGetLastImage);
- }
- void nsFPD::FPDDeviceIRay::RegisterSync(nDetail::Dispatch* Dispatch)
- {
- Dispatch->Action.Push("SetSyncMode", m_SyncUnit.get(), &SyncUnit::JSSetSyncMode);
- Dispatch->Action.Push("SetXwindowSize", m_SyncUnit.get(), &SyncUnit::JSSetXwindowSize);
- Dispatch->Action.Push("PrepareAcquisition", m_SyncUnit.get(), &SyncUnit::JSPrepareAcquisition);
- Dispatch->Action.Push("StartAcquisition", m_SyncUnit.get(), &SyncUnit::JSStartAcquisition);
- Dispatch->Action.Push("StopAcquisition", m_SyncUnit.get(), &SyncUnit::JSStopAcquisition);
- Dispatch->Get.Push(CcosFPDReadyStatus, m_SyncUnit.get(), &SyncUnit::JSGetFPDReady);
- Dispatch->Get.Push(CcosXwindowStatus, m_SyncUnit.get(), &SyncUnit::JSGetXWindowStatus);
- Dispatch->Get.Push(CcosImageReadingStatus, m_SyncUnit.get(), &SyncUnit::JSGetImageReadingStatus);
- }
- void nsFPD::FPDDeviceIRay::RegisterCalib(nDetail::Dispatch* Dispatch)
- {
- Dispatch->Action.Push("UploadCalibrationFiles", m_CalibUnit.get(), &CalibUnit::JSUploadCalibrationFiles);
- Dispatch->Action.Push("SetSID", m_CalibUnit.get(), &CalibUnit::JSSetSID);
- Dispatch->Action.Push("ActiveCalibration", m_CalibUnit.get(), &CalibUnit::JSActiveCalibration);
- Dispatch->Action.Push("GetRequestedDose", m_CalibUnit.get(), &CalibUnit::JSGetRequestedDose);
- Dispatch->Action.Push("PrepareCalibration", m_CalibUnit.get(), &CalibUnit::JSPrepareCalibration);
- Dispatch->Action.Push("StartCalibration", m_CalibUnit.get(), &CalibUnit::JSStartCalibration);
- Dispatch->Action.Push("StopCalibration", m_CalibUnit.get(), &CalibUnit::JSStopCalibration);
- Dispatch->Action.Push("SetCorrectionType", m_CalibUnit.get(), &CalibUnit::JSSetCorrectionType);
- Dispatch->Get.Push(AttrKey::CalibrationStatus, m_CalibUnit.get(), &CalibUnit::JSGetCalibStatus);
- Dispatch->Get.Push(AttrKey::CalibrationProgress, m_CalibUnit.get(), &CalibUnit::JSGetCalibProgress);
- Dispatch->Get.Push("UploadCalibrationFilesResult", m_CalibUnit.get(), &CalibUnit::JSGetUploadCalibrationFilesResult);
- }
- void nsFPD::FPDDeviceIRay::Register()
- {
- auto Disp = &Dispatch;
- RegisterCtrl(Disp);
- RegisterAcq(Disp);
- RegisterSync(Disp);
- RegisterCalib(Disp);
- }
- void nsFPD::FPDDeviceIRay::OnFPDCallback(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
- {
- m_nDeviceIndex = nDetectorID;
- switch (nEventLevel)
- {
- case EVT_LEVEL_CONFIGURATION:
- {
- OnEventProcessConf(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
- break;
- }
- case EVT_LEVEL_INFORMATOION:
- {
- OnEventProcessInfo(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
- break;
- }
- case EVT_LEVEL_STATUS:
- {
- OnEventProcessStatus(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
- break;
- }
- case EVT_LEVEL_DATA:
- {
- OnEventProcessData(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
- break;
- }
- case EVT_LEVEL_WARNING:
- {
- OnEventProcessWarning(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
- break;
- }
- case EVT_LEVEL_ERROR:
- {
- OnEventProcessError(nDetectorID, nEventID, nEventLevel, pszMsg, nParam1, fParam2, nPtrParamLen, pParam);
- break;
- }
- default:
- {
- break;
- }
- }
- }
- void nsFPD::FPDDeviceIRay::OnEventProcessConf(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
- {
- switch (nEventID)
- {
- case EVT_CONF_PANEL_SERIAL:
- {
- m_stDeviceConfig.strPanelSerial = pszMsg;
- //mLog::Info("Receive Panel {$} SN {$}", nDetectorID, pszMsg);
- char cDetectorID[17] = { 0 };
- memcpy(cDetectorID, m_stDeviceConfig.strPanelSerial.c_str(), 16);
- string strDetectorID = cDetectorID;
- m_DetectorCtrlUnit->SetDetectorID(strDetectorID);
- //mLog::Info("SedDetectorID {$}", strDetectorID.c_str());
- if (!m_bRecoverImageStatusInit)
- {
- m_RecoverImageStatus.add("DetectorName", m_stDeviceConfig.strDeviceName.c_str());
- m_RecoverImageStatus.add("DetectorSN", m_stDeviceConfig.strPanelSerial.c_str());
- m_RecoverImageStatus.add("DetectorWifiSignal", "1");
- m_RecoverImageStatus.add("Result", "-1");
- m_bRecoverImageStatusInit = true;
- }
- break;
- }
- case EVT_CONF_RAW_WIDTH:
- {
- if (m_stDeviceConfig.nFullImageWidth != nParam1)
- {
- m_stDeviceConfig.nFullImageWidth = nParam1;
- }
- //mLog::Info("Panel {$} nRawWidth:{$}", nDetectorID, m_stDeviceConfig.nRawWidth);
- break;
- }
- case EVT_CONF_RAW_HIGHT:
- {
- if (m_stDeviceConfig.nFullImageHeight != nParam1)
- {
- m_stDeviceConfig.nFullImageHeight = nParam1;
- }
- //mLog::Info("Panel {$} nRawHeight:{$}", nDetectorID, m_stDeviceConfig.nRawHeight);
- break;
- }
- case EVT_CONF_RAW_BITS:
- {
- m_stDeviceConfig.nImageBits = nParam1;
- //mLog::Info("Panel {$} nImageBits:{$}", nDetectorID, m_stDeviceConfig.nImageBits);
- break;
- }
- case EVT_CONF_PIXELSPACE:
- {
- m_stDeviceConfig.nPixelSpace = (int)fParam2;
- //mLog::Info("Panel {$} nPixelSpace:{$}", nDetectorID, m_stDeviceConfig.nPixelSpace);
- break;
- }
- case EVT_CONF_PREVIEW_WIDTH:
- {
- if (m_stDeviceConfig.nPreviewWidth != nParam1)
- {
- m_stDeviceConfig.nPreviewWidth = nParam1;
- }
- //mLog::Info("Panel {$} nPreviewWidth:{$}", nDetectorID, m_stDeviceConfig.nPreviewWidth);
- break;
- }
- case EVT_CONF_PREVIEW_HIGHT:
- {
- if (m_stDeviceConfig.nPreviewHeight != nParam1)
- {
- m_stDeviceConfig.nPreviewHeight = nParam1;
- }
- //mLog::Info("Panel {$} nPreviewHeight:{$}", nDetectorID, m_stDeviceConfig.nPreviewHeight);
- break;
- }
- case EVT_CONF_FIRWARE_UPDATE:
- {
- m_stDeviceConfig.nFirmwareStatus = nParam1;
- m_DetectorCtrlUnit->SetFirmwareStatus(to_string(nParam1));
- //mLog::Info("Panel {$} FirmwareUpdate:{$}", nDetectorID, m_stDeviceConfig.nFirmwareStatus);
- break;
- }
- case EVT_CONF_PART_NUMBER:
- {
- m_stDeviceConfig.strPartNumber = pszMsg;
- //mLog::Info("Panel {$} PartNumber:{$}", nDetectorID, pszMsg);
- break;
- }
- case EVT_CONF_WIFI_SSID:
- {
- m_stDeviceConfig.strWifiSSID = pszMsg;
- //mLog::Info("Panel {$} WifiSSID:{$}", nDetectorID, pszMsg);
- break;
- }
- case EVT_CONF_IFBOARD:
- {
- m_stDeviceConfig.strInterfaceBoard = pszMsg;
- //mLog::Info("Panel {$} InterfaceBoard:{$}", nDetectorID, pszMsg);
- break;
- }
- case EVT_CONF_DATECODE:
- {
- m_stDeviceConfig.strDateCode = pszMsg;
- //mLog::Info("Panel {$} DateCode:{$}", nDetectorID, pszMsg);
- break;
- }
- default:
- {
- break;
- }
- }
- }
- void nsFPD::FPDDeviceIRay::OnEventProcessInfo(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
- {
- int nID = nDetectorID;
- switch (nEventID)
- {
- case EVT_INFO_POWER_ON:
- {
- int nPowerOn = nParam1;
- //mLog::Info("Detector {$} PowerOn:{$}", nID, nPowerOn);
- m_stDeviceConfig.nPowerOn = nPowerOn;
- break;
- }
- case EVT_INFO_WIFI_DATARATE:
- {
- m_stDeviceConfig.nWifiDataRate = nParam1;
- //mLog::Info("Detector {$} WifiDataRate:{$}", nID, m_stDeviceConfig.nWifiDataRate);
- break;
- }
- case EVT_INFO_WIFI_CHANNEL:
- {
- m_stDeviceConfig.nWifiChannel = nParam1;
- //mLog::Info("Panel {$} WifiChannel:{$}", nID, m_stDeviceConfig.nWifiChannel);
- break;
- }
- case EVT_INFO_WIFI_SIGNALPOWER:
- {
- m_stDeviceConfig.nWifiSignalPower = nParam1;
- break;
- }
- case EVT_INFO_WIFI_NOISEPOWER:
- {
- m_stDeviceConfig.nWifiNoisePower = nParam1;
- //mLog::Info("Panel {$} WifiNoisePower:{$}", nID, m_stDeviceConfig.nWifiNoisePower);
- break;
- }
- case EVT_INFO_CALIBRATIOIN_TIMEL:
- {
- m_stDeviceConfig.strCalibrationLTETime = pszMsg;
- //mLog::Info("Panel {$} LTE Calibration Time:{$}", nID, pszMsg);
- break;
- }
- case EVT_INFO_FPVOLTAGE:
- {
- m_strVoltage = pszMsg;
- break;
- }
- default:
- {
- break;
- }
- }
- }
- void nsFPD::FPDDeviceIRay::OnEventProcessStatus(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
- {
- string strWarnErrorCode = "";
- switch (nEventID)
- {
- case EVT_STATUS_INIT:
- {
- if (PANEL_EVENT_END_OK == nParam1)
- {
- //OnInitResult(true);
- m_stDeviceConfig.bConnectStatus = true;
- m_stDeviceConfig.bInitOK = true;
- }
- else if (PANEL_EVENT_END_ERROR == nParam1)
- {
- //OnInitResult(false);
- }
- else if (PANEL_EVENT_END == nParam1) //未连接探测器
- {
- m_DetectorCtrlUnit->SetInitialStatus(to_string(DETECTOR_INI_SUCCESS));
- }
- else if (PANEL_EVENT_START == nParam1)
- {
- m_DetectorCtrlUnit->SetInitialStatus(to_string(DETECTOR_INI_START));
- }
- break;
- }
- case EVT_STATUS_SELECTPANEL:
- {
- break;
- }
- case EVT_STATUS_PANEL:
- {
- ENUM_PANEL_STATUS m_ePanelStatus = (ENUM_PANEL_STATUS)nParam1;
- if (PANEL_STANDBY == nParam1)
- {
- //mLog::Info("Panel Status:PREPARE");
- }
- else if (PANEL_READY_EXP == nParam1)
- {
- //mLog::Info("Panel Status:READY");
- m_SyncUnit->FPDReadyNotify(true);
- }
- else if (PANEL_OFFSET_CAL == nParam1)
- {
- //mLog::Info("Panel Status:PANEL_OFFSET_CAL");
- }
- else if (PANEL_OFFSET_FINISH == nParam1)
- {
- //mLog::Info("Panel Status:PANEL_OFFSET_FINISH");
- //StopCalibrationInside();
- }
- else if (PANEL_OFFSET_FAILED == nParam1)
- {
- //mLog::Info("Panel Status:PANEL_OFFSET_FAILED");
- //AbortCalibration();
- }
- else if (PANEL_XWINDOW_ON == nParam1) //Xwindow On
- {
- //mLog::Info("Panel Status: XWINDOW_ON");
- XWindowOnNotify();
- }
- else if (PANEL_XWINDOW_OFF == nParam1) // Xwindow Off
- {
- //mLog::Info("Panel Status: XWINDOW_OFF");
- XWindowOffNotify();
- }
- else if (PANEL_GAIN_FINISH == nParam1)
- {
- //mLog::Info("Panel Status:CALIBRATION_FINISH");
- }
- else if (PANEL_GAIN_PREPARE == nParam1)
- {
- //mLog::Info("Detector Notify Xray Prepare");
- }
- else if (PANEL_GAIN_READY_EXP == nParam1)
- {
- m_SyncUnit->FPDReadyNotify(true);
- }
- else
- {
- //mLog::Info("Panel {$} Status Unknown: {$}", nDetectorID, (int)m_ePanelStatus);
- }
- break;
- }
- case EVT_STATUS_CALIBRATIOIN:
- {
- ENUM_PANEL_EVENT_STATE eStatus = (ENUM_PANEL_EVENT_STATE)nParam1;
- //string strSNote;
- switch (eStatus)
- {
- case PANEL_EVENT_START:
- break;
- case PANEL_EVENT_END_OK:
- //mLog::Info("Calibration process is success");
- //CompleteCalibration();
- SetEvent(m_CompleteCalibrationEvt);
- break;
- case PANEL_EVENT_END_ERROR:
- //mLog::Info("Calibration process is failed");
- break;
- case PANEL_EVENT_TIMEOUT:
- //mLog::Info("Calibration timeout");
- //mLog::Info("Calibration process is failed");
- break;
- default:
- break;
- }
- break;
- }
- case EVT_STATUS_SAVECALIB:
- {
- if (PANEL_EVENT_START == nParam1)
- {
- //mLog::Info("Begin to Save Calibration Files");
- }
- else if (PANEL_EVENT_END_ERROR == nParam1)
- {
- SetEvent(m_UploadCalibMapOver);
- //mLog::Info("Save Calibration Files failed");
- }
- else if (PANEL_EVENT_END == nParam1)
- {
- SetEvent(m_UploadCalibMapOver);
- //mLog::Info("Save Calibration Files Success");
- }
- break;
- }
- case EVT_STATUS_SAVEDEFECT:
- {
- if (PANEL_EVENT_START == nParam1)
- {
- //mLog::Info("Begin to Save Defect Files");
- }
- else if (PANEL_EVENT_END_ERROR == nParam1)
- {
- SetEvent(m_UploadCalibMapOver);
- //mLog::Info("Save Defect Files failed");
- }
- else if (PANEL_EVENT_END == nParam1)
- {
- m_stDeviceConfig.bTaskEnd = true;
- //mLog::Info("Save Defect Files Success");
- SetEvent(m_UploadCalibMapOver);
- }
- break;
- }
- case EVT_STATUS_ACQUISITION:
- {
- ENUM_PANEL_EVENT_STATE eStatus = (ENUM_PANEL_EVENT_STATE)nParam1;
- switch (eStatus)
- {
- case PANEL_EVENT_START:
- break;
- case PANEL_EVENT_END_OK:
- break;
- case PANEL_EVENT_END_ERROR: //由于断线造成指令执行失败
- {
- string strWarnErrorCode = ERR_FPD_ACQ_FAILED;
- break;
- }
- default:
- break;
- }
- break;
- }
- case EVT_STATUS_PREPARE_EDNCALIBRATION:
- break;
- case EVT_STATUS_IMAGEPENDING:
- {
- string strTemp = pszMsg;
- if (strTemp.find("true") != std::string::npos)
- {
- m_bImagePendingOrNot = true;
- }
- else
- {
- m_bImagePendingOrNot = false;
- }
- break;
- }
- case EVT_STATUS_IMAGERECOVERAUTO:
- {
- m_RecoverImageStatus["Result"] = "0";
- //mLog::Info("m_RecoverImageStatus[Result] = 0 by auto");
- m_DetectorCtrlUnit->SetRecoverImageState(m_RecoverImageStatus.encode());
- m_bAbortRecover = false; //终止恢复图像的变量也要重置
- m_bRecoveringImage = false; //不再恢复图像过程中
- m_nRecoverImageTimes = 0; //下次恢复图像,重置
- m_bSendRecoverMessage = false; //下次恢复图像仍需判断;
- break;
- }
- case EVT_STATUS_TEMPERATURE:
- {
- float fTemperature = fParam2;
- //OnProcessTemperature(nID, fTemperature);
- m_stDeviceConfig.fCurrentTemperValue = fTemperature;
- //mLog::Info("Detector {$} Temperature Value:{$}", nDetectorID, fTemperature);
- //SendTemperatureValue(fTemperature);
- break;
- }
- case EVT_STATUS_WIFI:
- {
- int nWifiLevel = nParam1;
- //mLog::Info("Detector {$} Wifi Value:{$}", nDetectorID, nWifiLevel);
- m_stDeviceConfig.nCurrentWifiValue = nWifiLevel;
- //SendWifiValue(nWifiLevel);
- break;
- }
- case EVT_STATUS_BATTERY_VALUE:
- {
- int nBatteryValue = nParam1;
- m_lowBatteryBuda = m_lowBatteryBuda + 1;
- if (m_lowBatteryBuda >= 10000)
- {
- m_lowBatteryBuda = 10000;
- }
- //mLog::Info("Detector {$} Battery:{$}", nDetectorID, nParam1);
- //SendInfoLog("DEV_LOG_FPD_BATTERY", nBatteryValue);
- if (nBatteryValue < m_stDeviceConfig.nBatteryLimit)
- {
- //battery error
- if (!m_bBatteryCharging) //如果没有充电;
- {
- strWarnErrorCode = ERR_FPD_BATTERY_LOW;
- //OnError(strWarnErrorCode);
- strWarnErrorCode = WAR_FPD_BATTERY_LOW;
- //OnWarnX(strWarnErrorCode);
- }
- }
- else if (nBatteryValue < m_stDeviceConfig.nBatteryWarning)
- {
- strWarnErrorCode = ERR_FPD_BATTERY_LOW;
- //OnErrorX(strWarnErrorCode);
- strWarnErrorCode = WAR_FPD_BATTERY_LOW;
- }
- else
- {
- strWarnErrorCode = ERR_FPD_BATTERY_LOW;
- //OnErrorX(strWarnErrorCode);
- strWarnErrorCode = WAR_FPD_BATTERY_LOW;
- //OnWarnX(strWarnErrorCode);
- }
- m_stDeviceConfig.nCurrentBatteryValue = nBatteryValue;
- //mLog::Info("Detector {$} Battery Value:{$}", nDetectorID, nBatteryValue);
- if (nBatteryValue < m_stDeviceConfig.nBatteryWarning)
- {
- //防止探测器电池电量状态异常跳变
- if (m_lowBatteryBuda >= 2)
- {
- //SendBatteryValue(nBatteryValue);
- }
- }
- else
- {
- //SendBatteryValue(nBatteryValue);
- }
- break;
- }
- case EVT_STATUS_BATTERY_CHARGING:
- {
- string strTemp = pszMsg;
- if (strTemp.find("true") != std::string::npos)
- {
- m_bBatteryCharging = true;
- }
- else
- {
- m_bBatteryCharging = false;
- }
- break;
- }
- case EVT_STATUS_SHOCK_SENSOR:
- {
- m_nShockCounts = nParam1;
- string strWarn = WAR_FPD_MAX_SHOCK_NUM;
- //mLog::Info("Panel {$} Shock Sensor Number:{$}", nDetectorID, m_nShockCounts);
- m_stDeviceConfig.nShockTimes = m_nShockCounts;
- break;
- }
- case EVT_STATUS_HALL_SENSOR:
- {
- int nWorkstaion = nParam1;
- //mLog::Info("Update Hall Status : {$} ", nWorkstaion);
- //mLog::Info("Panel {$} WS:{$},Current OGP WS:{$} ", nDetectorID, nWorkstaion, m_nWorkStation);
- m_stDeviceConfig.nWorkstation = nWorkstaion;
- break;
- }
- case EVT_STATUS_PING:
- {
- break;
- }
- case EVT_STATUS_RESET:
- {
- int nStatus = nParam1;
- if (PANEL_RESET_BEGIN == nStatus)
- {
- }
- else if (PANEL_RESET_OK == nStatus)
- {
- m_bResetDetector = false;
- }
- else if (PANEL_RESET_ERROR == nStatus)
- {
- }
- break;
- }
- default:
- {
- break;
- }
- }
- }
- void nsFPD::FPDDeviceIRay::OnEventProcessData(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
- {
- switch (nEventID)
- {
- case EVT_DATA_RAW_IMAGE:
- {
- //mLog::Info("Image Arrive");
- if (APP_STATUS_IDLE == m_eAppStatus)
- {
- //mLog::Error("Omit Image in Idle Status");
- return;
- }
- //mLog::Info("Currenct FPD FullImage Width:{$}, FullImage Height:{$}", m_stDeviceConfig.nFullImageWidth, m_stDeviceConfig.nFullImageHeight);
- float fImageReferUGY = 2.5f;
- if (APP_STATUS_WORK_BEGIN == m_eAppStatus)
- {
- fImageReferUGY = 2.5f;
- }
- if (NULL == m_pwRawImageData)
- {
- m_pwRawImageData = new WORD[m_stDeviceConfig.nFullImageWidth * m_stDeviceConfig.nFullImageHeight];
- }
- memcpy(m_pwRawImageData, pParam, m_stDeviceConfig.nFullImageWidth * m_stDeviceConfig.nFullImageHeight * sizeof(WORD));
- if (m_bSaveRaw)
- {
- //SaveRaw("iRaySDK");
- string strFullImageName = "FullImage.raw";
- SaveRawImage(strFullImageName, m_pwRawImageData, m_stDeviceConfig.nFullImageWidth, m_stDeviceConfig.nFullImageHeight);
- }
- OnProcessImage(m_pwRawImageData, m_stDeviceConfig.nFullImageWidth, m_stDeviceConfig.nFullImageHeight, fImageReferUGY);
- m_bStatusInAEC = false;
- break;
- }
- case EVT_DATA_PREVIEW_IMAGE:
- {
- //mLog::Info("Preview Image Arrive");
- m_SyncUnit->ImageReadingNotify();
- if (NULL == m_pwPreviewImg)
- {
- m_pwPreviewImg = new WORD[m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight];
- }
- memcpy(m_pwPreviewImg, pParam, m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight * sizeof(WORD));
- OnProcessPreviewImage(m_pwPreviewImg, m_stDeviceConfig.nPreviewWidth, m_stDeviceConfig.nPreviewHeight);
- break;
- }
- case EVT_DATA_AEC_PREEXP_IMAGE:
- {
- //mLog::Info("AEC PreExp Image Arrive");
- if (NULL == m_pwPreviewImg)
- {
- m_pwPreviewImg = new WORD[m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight];
- }
- memcpy(m_pwPreviewImg, pParam, m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight * sizeof(WORD));
- if (m_bSaveRaw)
- {
- //SaveImage(L"PreviewImage.raw", pwRawImage, nHeight, nWidth);
- string strImageName = "PreExpImage.raw";
- SaveRawImage(strImageName, m_pwPreviewImg, m_stDeviceConfig.nPreviewWidth, m_stDeviceConfig.nPreviewHeight);
- }
- OnProcessPreExpImage(m_pwPreviewImg, m_stDeviceConfig.nPreviewWidth, m_stDeviceConfig.nPreviewHeight);
- m_bStatusInAEC = true;
- break;
- }
- case EVT_DATA_DOSEPARAM:
- {
- m_fDoseParam = nParam1;// static_cast<int>(fParam2 * 1000);
- //mLog::Info("calibration dose {$}, Param1 {$}", m_fDoseParam, nParam1);
- SetEvent(m_WaitCalibDoseEvt);
- break;
- }
- default:
- {
- break;
- }
- }
- }
- void nsFPD::FPDDeviceIRay::OnEventProcessError(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
- {
- string strErrorName = "";
- switch (nEventID)
- {
- case EVT_ERR_COMMUNICATE:
- {
- strErrorName = ERR_FPD_DISCONNECT;
- string strTemp = pszMsg;
- if (strTemp.find("true") != std::string::npos)
- {
- m_stDeviceConfig.nWorkstation = -1;
- m_stDeviceConfig.bConnectStatus = false;
- m_nBatteryCapacity = 0;
- //SendDetectorInfo();
- m_lowBatteryBuda = 0;
- m_stDeviceConfig.nCurrentWifiValue = 0;
- m_stDeviceConfig.nCurrentBatteryValue = 0;
- }
- else if (strTemp.find("false") != std::string::npos)//成功时交给WIFI发送SendDetectorInfo
- {
- m_stDeviceConfig.bConnectStatus = true;
- }
- break;
- }
- case EVT_ERR_EXP_REQUEST:
- {
- string strTemp = pszMsg;
- strErrorName = ERR_FPD_ACQ_FAILED;
- break;
- }
- case EVT_ERR_GET_IMAGE:
- {
- string strTemp = pszMsg;
- if (strTemp.find("true") != std::string::npos)
- {
- if (APP_STATUS_WORK_BEGIN != m_eAppStatus) //如果不在检查界面;
- {
- //mLog::Fatal("there are image exist in current detector,do you want to continue");
- }
- else //if (m_bSiemensCmd)
- {
- //mLog::Fatal("FPD has exposed Image!");
- }
- //endif
- }
- else if (strTemp.find("false") != std::string::npos)
- {
- m_bAbortRecover = false; //终止恢复图像的变量也要重置
- m_bRecoveringImage = false; //不再恢复图像过程中
- m_nRecoverImageTimes = 0; //下次恢复图像,重置
- m_bSendRecoverMessage = false; //下次恢复图像仍需判断;
- }
- break;
- }
- case EVT_ERR_INIT_FAILED:
- {
- strErrorName = ERR_FPD_FATAL_ERROR;
- string strTemp = pszMsg;
- break;
- }
- default:
- {
- break;
- }
- }
- }
- void nsFPD::FPDDeviceIRay::OnEventProcessWarning(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam)
- {
- }
- DWORD nsFPD::FPDDeviceIRay::OnNotify(LPVOID pParam)
- {
- return 0;
- }
- bool nsFPD::FPDDeviceIRay::CreateDevice()
- {
- if (!LoadConfig())
- {
- //mLog::Info("Load configuration file failed!!!");
- return false;
- }
- bool bDemo = false;
- bool bRet = false;
- int nDemo = (int)m_DetectorConfiguration->m_Configurations["DemoEnable"];
- if (nDemo != 0)
- {
- bDemo = true;
- }
- if (bDemo)
- {
- return bRet;
- }
- if ((g_pIRayCtrl != nullptr) || (m_pDetectors != nullptr))
- {
- //mLog::Info("CreateDevice failed!");
- return false;
- }
-
- m_pDetectors = new IRayCtrl();
- g_pIRayCtrl = reinterpret_cast<IRayCtrl*>(m_pDetectors);
- bRet = m_pDetectors->Init(g_strAppPath);
- m_pDetectors->AddDPCs(this, m_DetectorConfiguration->m_Configurations, m_stDeviceConfig);
- //mLog::Info("Create Device over");
- return bRet;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::Connect()
- {
- //mLog::Info("------------------------ FPD type {$}, Device {$} Start running. ------------------------ ", m_stDeviceConfig.strDeviceName.c_str(), this);
- bool bRet = m_pDetectors->Connect(g_strAppPath, this);
- if (!bRet)
- {
- //SendConnectStatusToUI(false);
- return RET_STATUS::RET_FAILED;
- }
- //mLog::Info("Device Connect detector over ");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::GetDeviceDictionary(std::string& out)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::EnterExam(int nExamStatus)
- {
- //mLog::Info("EnterExam");
- switch (nExamStatus)
- {
- case APP_STATUS_WORK_BEGIN:
- //mLog::Info("Enter into Exam Windows");
- m_eAppStatus = APP_STATUS_WORK_BEGIN;
- break;
- case APP_STATUS_WORK_END:
- //mLog::Info("Quit Exam Windows");
- m_bTestSensitivity = false;
- m_eAppStatus = APP_STATUS_WORK_END;
- break;
- case APP_STATUS_CAL_BEGIN:
- //mLog::Info("Enter into Calibration Windows");
- m_eAppStatus = APP_STATUS_CAL_BEGIN;
- break;
- case APP_STATUS_CAL_END:
- //mLog::Info("Quit Calibration Windows");
- m_eAppStatus = APP_STATUS_CAL_END;
- break;
- default:
- break;
- }
- m_pDetectors->EnterExam(m_eAppStatus);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::ActiveDetector(bool bActive)
- {
- if (bActive)
- {
- //mLog::Info("ActiveDetector");
- m_nActiveState = FPD_ACTIVE;
- bool bRet = (m_pDetectors)->ActivePanel(this, bActive);
- if (!bRet)
- {
- return RET_STATUS::RET_FAILED;
- }
- }
- else
- {
- //mLog::Info("UnActiveDetector");
- bool bRet = (m_pDetectors)->ActivePanel(this, bActive);
- if (!bRet)
- {
- return RET_STATUS::RET_FAILED;
- }
- m_nActiveState = FPD_NOT_ACTIVE;
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::SetAcqMode(int mode)
- {
- /*if (!m_stDeviceConfig.bConnectStatus)
- {
- //mLog::Error("m_stDeviceConfig.bConnectStatus = false ");
- return RET_STATUS::RET_THREAD_INVALID;
- }*/
- //mLog::Info("Device SetAcqMode: {$}", mode);
- int nOmMode = 1;
- int nFilterMode = m_stDeviceConfig.nFilterMode;
- int nPanelID = m_nDeviceIndex + 1;
- if (m_bStatusInAEC == true)
- {
- //mLog::Info("In AEC MainExposure...");
- //激活应用配置模式:Manual曝光
- //m_pDetectors->ActiveConfigurationMode(nPanelID, 1);
- return RET_STATUS::RET_SUCCEED;
- }
-
- if (mode == 3) //AEC模式
- {
- nOmMode = 2;
- //mLog::Info("In AEC PreExposure...");
- //激活应用配置模式:AEC PreExp曝光
- m_pDetectors->ActiveConfigurationMode(nPanelID, nOmMode);
- }
- else
- {
- nOmMode = 1;
- //激活应用配置模式:Manual曝光
- m_pDetectors->ActiveConfigurationMode(nPanelID, nOmMode);
- }
- m_pDetectors->SelectMode(0, nOmMode, nFilterMode);
-
- try
- {
- //nOmMode = m_ACQMODElist[CcosAcqModeIdx];
- /*if (nOmMode != mode)
- {
- //mLog::Info("input param invalid, can not support ");
- return RET_STATUS::RET_INVALID;
- }*/
- //int nWidth = (int)m_ACQMODElist[CcosImageWidth];
- //int nheight = (int)m_ACQMODElist[CcosImageHeight];
- //int nbit = (int)m_ACQMODElist[CcosImageBits];
- m_AcqUnit->SetFulImageInfo(m_stDeviceConfig.nFullImageHeight, m_stDeviceConfig.nFullImageWidth, m_stDeviceConfig.nImageBits, false);
- m_AcqUnit->SetPrevImageInfo(m_stDeviceConfig.bPreviewEnable, m_stDeviceConfig.nPreviewHeight, m_stDeviceConfig.nPreviewWidth, false);
- }
- catch (...)
- {
- //mLog::Info("Illegal mode index!!! ");
- return RET_STATUS::RET_NOSUPPORT;
- }
- if (m_pDetectors->SelectExamMode(nOmMode, this))
- {
- return RET_STATUS::RET_SUCCEED;
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::SetSyncMode(SYNC_MODE nSyncMode, HARDWARE_TRIGGER_MODE TriggerMode)
- {
- if (!(m_pDetectors->SetSyncMode(nSyncMode, TriggerMode)))
- {
- return RET_STATUS::RET_FAILED;
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::SetXwindow(float XwindowSize)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::SetSID(int nSID)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::ActiveCalibration(CCOS_CALIBRATION_TYPE in)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::PrepareCalibration()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::GetRequestedDose(string& strDose)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::StartCalibration()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::StopCalibration()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::SetCorrectionType(CCOS_CORRECTION_TYPE in)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::ResetConnect()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::DisConnectFPD()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::RecoverImage(bool bRecoverIt)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::GetRecoverImageState(string& strREI)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::GetDetectorInfo(string& strFDI)
- {
- string strTempTemp = " ";
- //mLog::Info("Get Detector Info");
- strFDI = "jishinull";
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::UploadCalibrationFiles(string strFileName)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::ResetError()
- {
- return RET_STATUS::RET_SUCCEED;
- }
- bool nsFPD::FPDDeviceIRay::LoadConfig()
- {
- if (!m_DetectorConfiguration->LoadConfigurations(m_stDeviceConfig, m_ACQMODElist))
- {
- //mLog::Fatal("Load configuration file failed!!! ");
- return false;
- }
- //mLog::Info("m_ACQMODElist: {$} ", m_ACQMODElist.encode());
- m_nFullImgWidth = m_stDeviceConfig.nFullImageWidth;
- m_nFullImgHeight = m_stDeviceConfig.nFullImageHeight;
- m_nTopOffset = m_stDeviceConfig.nImageTopffset;
- m_nBottomOffset = m_stDeviceConfig.nImageBottomOffset;
- m_nLeftOffset = m_stDeviceConfig.nImageLeftOffset;
- m_nRightOffset = m_stDeviceConfig.nImageRightOffset;
- m_bPreviewEnable = m_stDeviceConfig.bPreviewEnable;
- //mLog::Info("set previewEnable {$} ", m_bPreviewEnable ? "true" : "false");
- if (m_stDeviceConfig.nForceGridSuppress > 0)
- {
- m_bForceGridSuppress = true;
- }
- else
- {
- m_bForceGridSuppress = false;
- }
- int nAttached = (int)m_DetectorConfiguration->m_Configurations[CcosDetectorAttachedFlag];
- m_stDeviceConfig.bConnectStatus = false;
-
- m_bSaveRaw = (bool)m_DetectorConfiguration->m_Configurations["SaveRaw"];
- //mLog::Info("set SaveRaw {$} ", m_bSaveRaw ? "true" : "false");
- m_nClinicalApplicationMode = (int)m_DetectorConfiguration->m_Configurations["ClinicalApplicationMode"];
- //mLog::Info("Clinical Application Mode: {$} ", m_nClinicalApplicationMode);
- m_nFilterMode = (int)m_DetectorConfiguration->m_Configurations["FilterMode"];
- //mLog::Info("Clinical Filter Mode: {$} ", m_nFilterMode);
- string strFPDinfo;
- strFPDinfo = (string)m_DetectorConfiguration->m_Configurations["FieldofViewShape"];
- m_DetectorCtrlUnit->SetFieldofViewShape(strFPDinfo);
- strFPDinfo = (string)m_DetectorConfiguration->m_Configurations["FieldofViewDimension"];
- //m_DetectorCtrlUnit->SetFieldofViewDimension(strFPDinfo);
- strFPDinfo = (string)m_DetectorConfiguration->m_Configurations["VendorID"];
- //m_DetectorCtrlUnit->SetDetectorType("IRAY1012F2");
- strFPDinfo = (string)m_DetectorConfiguration->m_Configurations["Description"];
- //m_DetectorCtrlUnit->SetDescription(strFPDinfo);
- auto szFDinfo = std::to_string(m_stDeviceConfig.nDoseOfEXI);
- m_fFactorEXI2UGY = 100.0f / (float)atof(szFDinfo.c_str()) * 1.0f;//统一使用IEC标准 呈现四角信息,无单位 ugy * 100 -ugy。所有Zskk探测器的FactorEXI2UGY均需*100
- //mLog::Info("m_fFactorEXI2UGY = {$} ", m_fFactorEXI2UGY);
- auto strFPDcoef = std::to_string(m_fFactorEXI2UGY);
- m_DetectorCtrlUnit->SetFPDSensitivity(strFPDcoef);//image process 重算ROIl的EXI需要此值
- //m_DetectorCtrlUnit->SetPixelData("");
- //m_DetectorCtrlUnit->SetTargetEXI("5000");
- return true;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::PrepareAcquisition()
- {
- //mLog::Info("==============================PrepareAcquisition");
- /*if (!m_stDeviceConfig.bConnectStatus)
- {
- return RET_STATUS::RET_THREAD_INVALID;
- }
- if (!m_stDeviceConfig.bInitOK)
- {
- return RET_STATUS::RET_FAILED;
- }*/
- m_SyncUnit->FPDReadyNotify(false);
- if (m_pDetectors->PrepareAcquisition(this) == RET_STATUS::RET_SUCCEED)
- {
- m_SyncUnit->FPDReadyNotify(true);
- //mLog::Info("Send FPD Ready to Subsystem");
- }
- //mLog::Info("PrepareAcquisition over");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::StartAcquisition(string in)
- {
- //mLog::Info("StartAcquisition");
- m_bAbortRecover = false; //能执行StartAcq,说明没有错误可以ready曝光。不再影响abort后再次recoverimage功能
- RET_STATUS Ret = RET_STATUS::RET_FAILED;
- if (RET_STATUS::RET_SUCCEED == m_pDetectors->StartAcquisition(this))
- {
- Ret = RET_STATUS::RET_SUCCEED;
- m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ));
- //mLog::Info("Send DETECTOR_STATUS_ACQ to Subsystem");
- }
- else
- {
- m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
- //mLog::Info("Send DETECTOR_STATUS_STANDBY to Subsystem");
- //mLog::Error("StartAcquisition failed");
- }
- //mLog::Info("StartAcquisition over");
- return Ret;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::StopAcquisition()
- {
- //mLog::Info("StopAcquisition ");
- /*if (!m_stDeviceConfig.bConnectStatus)
- {
- return RET_STATUS::RET_THREAD_INVALID;
- }*/
- RET_STATUS Ret = RET_STATUS::RET_FAILED;
- if (RET_STATUS::RET_SUCCEED == m_pDetectors->StopAcquisition(this))
- {
- m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY));
- //mLog::Info("Send DETECTOR_STATUS_STANDBY to Subsystem");
- Ret = RET_STATUS::RET_SUCCEED;
- }
- //mLog::Info("StopAcquisition over ");
- return Ret;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::XWindowOnNotify()
- {
- RET_STATUS Ret = RET_STATUS::RET_FAILED;
- m_SyncUnit->XWindowOnNotify();
- //mLog::Info("--- WindowOn ---");
- m_stImgCreateTime = { 0 };
- GetLocalTime(&m_stImgCreateTime);
- //mLog::Info("Full image create time-{$}:{$}:{$}:{$}", m_stImgCreateTime.wHour, m_stImgCreateTime.wMinute, m_stImgCreateTime.wSecond, m_stImgCreateTime.wMilliseconds);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsFPD::FPDDeviceIRay::XWindowOffNotify()
- {
- RET_STATUS Ret = RET_STATUS::RET_FAILED;
- m_SyncUnit->XWindowOffNotify();
- //mLog::Info("--- WindowOff ---");
- return RET_STATUS::RET_SUCCEED;
- }
- string nsFPD::FPDDeviceIRay::MakeImageHead(IMAGE_VIEW_TYPE Type)
- {
- if (Type == IMAGE_FULL)
- {
- if (m_pFullImageHead == NULL)
- {
- m_pFullImageHead = new ResDataObject;
- ResDataObject json;
- json.add(SM_IMAGE_TYPE, (int)Type);
- json.add(SM_IMAGE_WIDTH, m_stDeviceConfig.nFullImageWidth);
- json.add(SM_IMAGE_HEIGHT, m_stDeviceConfig.nFullImageHeight);
- json.add(SM_IMAGE_BIT, 16);
- json.add(SM_IMAGE_TAG, 1);
- json.add(SM_IMAGE_INDEX, 1);
- json.add(SM_IMAGE_YEAR, m_stImgCreateTime.wYear);
- json.add(SM_IMAGE_MONTH, m_stImgCreateTime.wMonth);
- json.add(SM_IMAGE_DAY, m_stImgCreateTime.wDay);
- json.add(SM_IMAGE_HOUR, m_stImgCreateTime.wHour);
- json.add(SM_IMAGE_MINUTE, m_stImgCreateTime.wMinute);
- json.add(SM_IMAGE_SEC, m_stImgCreateTime.wSecond);
- json.add(SM_IMAGE_MILLSEC, m_stImgCreateTime.wMilliseconds);
- json.add(SM_IMAGE_LSB, "5000");
- json.add(SM_IMAGE_DOSE, m_stDeviceConfig.nDoseOfEXI);
- json.add(SM_IMAGE_PIXELREPRESENTATION, "0");
- json.add(SM_IMAGE_PIXELSPACING, m_stDeviceConfig.nPixelSpace);
- json.add(SM_IMAGE_ROTATION, "No");
- json.add(SM_IMAGE_FLIP, "No");
- json.add(SM_IMAGE_ORIGINX, "0");
- json.add(SM_IMAGE_ORIGINY, "0");
- json.add(SM_IMAGE_EXI2UGY, m_fFactorEXI2UGY);
- json.add(SM_IMAGE_TEMP, m_stDeviceConfig.fCurrentTemperValue);
- m_pFullImageHead->add(SM_IMAGE_HEAD, json);
- }
- else
- {
- (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_YEAR] = m_stImgCreateTime.wYear;
- (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MONTH] = m_stImgCreateTime.wMonth;
- (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_DAY] = m_stImgCreateTime.wDay;
- (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_HOUR] = m_stImgCreateTime.wHour;
- (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MINUTE] = m_stImgCreateTime.wMinute;
- (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_SEC] = m_stImgCreateTime.wSecond;
- (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MILLSEC] = m_stImgCreateTime.wMilliseconds;
- (*m_pFullImageHead)[SM_IMAGE_HEAD][SM_IMAGE_TEMP] = m_stDeviceConfig.fCurrentTemperValue;
- }
- //mLog::Info((*m_pFullImageHead).encode());
- return (*m_pFullImageHead).encode();
- }
- else
- {
- if (m_pPreviewImageHead == NULL)
- {
- m_pPreviewImageHead = new ResDataObject;
- ResDataObject json;
- json.add(SM_IMAGE_TYPE, (int)Type);
- json.add(SM_IMAGE_WIDTH, m_stDeviceConfig.nPreviewWidth);
- json.add(SM_IMAGE_HEIGHT, m_stDeviceConfig.nPreviewHeight);
- json.add(SM_IMAGE_BIT, 16);
- json.add(SM_IMAGE_TAG, 1);
- json.add(SM_IMAGE_INDEX, 1);
- json.add(SM_IMAGE_YEAR, m_stImgCreateTime.wYear);
- json.add(SM_IMAGE_MONTH, m_stImgCreateTime.wMonth);
- json.add(SM_IMAGE_DAY, m_stImgCreateTime.wDay);
- json.add(SM_IMAGE_HOUR, m_stImgCreateTime.wHour);
- json.add(SM_IMAGE_MINUTE, m_stImgCreateTime.wMinute);
- json.add(SM_IMAGE_SEC, m_stImgCreateTime.wSecond);
- json.add(SM_IMAGE_MILLSEC, m_stImgCreateTime.wMilliseconds);
- json.add(SM_IMAGE_LSB, "5000");
- json.add(SM_IMAGE_DOSE, m_stDeviceConfig.nDoseOfEXI);
- json.add(SM_IMAGE_ROTATION, "No");
- json.add(SM_IMAGE_FLIP, "No");
- json.add(SM_IMAGE_ORIGINX, "0");
- json.add(SM_IMAGE_ORIGINY, "0");
- json.add(SM_IMAGE_PIXELSPACING, m_stDeviceConfig.nPixelSpace);
- json.add(SM_IMAGE_PIXELREPRESENTATION, "0");
- json.add(SM_IMAGE_TEMP, m_stDeviceConfig.fCurrentTemperValue);
- m_pPreviewImageHead->add(SM_IMAGE_HEAD, json);
- }
- else
- {
- (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_YEAR] = m_stImgCreateTime.wYear;
- (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MONTH] = m_stImgCreateTime.wMonth;
- (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_DAY] = m_stImgCreateTime.wDay;
- (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_HOUR] = m_stImgCreateTime.wHour;
- (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MINUTE] = m_stImgCreateTime.wMinute;
- (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_SEC] = m_stImgCreateTime.wSecond;
- (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_MILLSEC] = m_stImgCreateTime.wMilliseconds;
- (*m_pPreviewImageHead)[SM_IMAGE_HEAD][SM_IMAGE_TEMP] = m_stDeviceConfig.fCurrentTemperValue;
- }
- return (*m_pPreviewImageHead).encode();
- }
- return "";
- }
- RET_STATUS nsFPD::FPDDeviceIRay::AddFrameWithRawHead(IMAGE_VIEW_TYPE Type, WORD* pFrameBuff, DWORD FrameSize)
- {
- string strImageHead = MakeImageHead(Type);
- return m_AcqUnit->AddFrameWithRawHead(Type, strImageHead, pFrameBuff, FrameSize);
- }
- //======================================================================预览图==================================================================//
- bool nsFPD::FPDDeviceIRay::OnProcessPreviewImage(WORD* pwRawImage, int nWidth, int nHeight)
- {
- //m_stFPDHeader.fFPDHeaderVersion = 0.0;
- //m_stFPDHeader.nImageType = m_nCurrentAcqMode;
- //m_stFPDHeader.nImageHeight = nHeight;
- //m_stFPDHeader.nImageWidth = nWidth;
- //m_stFPDHeader.nImageBits = m_nImageBits;
- //m_stFPDHeader.fFactorEXI2UGY = m_fFactorEXI2UGY;
- //m_stFPDHeader.fImageReferUGY = 2.5f;
- //m_stFPDHeader.fTemperature = m_stDeviceConfig.fCurrentTemperValue;
- //m_stFPDHeader.fPixelSpace = m_stDeviceConfig.fPixelSpace;
- //mLog::Info("Currenct PreviewImage Width:{$}, Height:{$}", m_stDeviceConfig.nPreviewWidth, m_stDeviceConfig.nPreviewHeight);
- if (m_stDeviceConfig.nSaveRaw > 1)
- {
- //SaveImage(L"PreviewImage.raw", pwRawImage, nHeight, nWidth);
- }
- return true;
- }
- void nsFPD::FPDDeviceIRay::PrevImageDateArrived(WORD* pImg)
- {
- AddFrameWithRawHead(IMAGE_PREVIEW, pImg, m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight);
- }
- //======================================================================AEC预曝光图============================================================//
- bool nsFPD::FPDDeviceIRay::OnProcessPreExpImage(WORD* pwRawImage, int nWidth, int nHeight)
- {
- //m_stFPDHeader.fFPDHeaderVersion = 0.0;
- //m_stFPDHeader.nImageType = m_nCurrentAcqMode;
- //m_stFPDHeader.nImageHeight = nHeight;
- //m_stFPDHeader.nImageWidth = nWidth;
- //m_stFPDHeader.nImageBits = m_nImageBits;
- //m_stFPDHeader.fFactorEXI2UGY = m_fFactorEXI2UGY;
- //m_stFPDHeader.fImageReferUGY = 2.5f;
- //m_stFPDHeader.fTemperature = m_stDeviceConfig.fCurrentTemperValue;
- //m_stFPDHeader.fPixelSpace = m_stDeviceConfig.fPixelSpace;
- //mLog::Info("Currenct AEC PreExp Image Width:{$}, Height:{$}", m_stDeviceConfig.nPreviewWidth, m_stDeviceConfig.nPreviewHeight);
- PreExpImageDateArrived(pwRawImage);
- return true;
- }
- void nsFPD::FPDDeviceIRay::PreExpImageDateArrived(WORD* pImg)
- {
- AddFrameWithRawHead(IMAGE_AEC_PREVIEW, pImg, m_stDeviceConfig.nPreviewWidth * m_stDeviceConfig.nPreviewHeight);
- }
- //======================================================================大图==================================================================//
- bool nsFPD::FPDDeviceIRay::OnProcessImage(WORD* pwRawImage, int nImageWidth, int nImageHeight, float fImageReferUGY)
- {
- //mLog::Info("Process Full Image");
- //mLog::Info("Currenct Full Image Width:{$}, Height:{$}", m_stDeviceConfig.nFullImageWidth, m_stDeviceConfig.nFullImageHeight);
- //mLog::Info("Image EXI2UGY factor: {$}, Image Refer UGY: {$}", m_fFactorEXI2UGY, fImageReferUGY);
- //图像预处理完成
- FullImageDateArrived(pwRawImage);
- //mLog::Info("Write Frame Over");
- return true;
- }
- void nsFPD::FPDDeviceIRay::FullImageDateArrived(WORD* pImg)
- {
- AddFrameWithRawHead(IMAGE_FULL, pImg, m_stDeviceConfig.nFullImageWidth * m_stDeviceConfig.nFullImageHeight);
- }
- void nsFPD::FPDDeviceIRay::SaveRaw(string RawName)
- {
- //mLog::Info("Begin save image");
- char szTemp[30] = { 0 };
- FILE* fp;
- string strFileName = g_strAppPath + "Image\\" + RawName + ".raw";
- if ((fp = fopen(strFileName.c_str(), "wb")) == NULL)
- {
- DWORD dw = GetLastError();
- //mLog::Error("fopen %s failed, %d", strFileName.c_str(), dw);
- return;
- }
- fwrite(m_pwRawImageData, sizeof(WORD), m_stDeviceConfig.nFullImageWidth * m_stDeviceConfig.nFullImageHeight, fp);
- fclose(fp);
- //mLog::Info("Save image over");
- }
- bool nsFPD::FPDDeviceIRay::SaveRawImage(string strImageName, WORD* pwRawImage, int nWidth, int nHeight)
- {
- //mLog::Info("Save raw image: {$}", strImageName);
- char szTemp[30] = { 0 };
- FILE* fp;
- string strFileName = g_strAppPath + "Image\\" + strImageName;
- if ((fp = fopen(strFileName.c_str(), "wb")) == NULL)
- {
- DWORD dw = GetLastError();
- //mLog::Error("fopen %s failed, %d", strFileName.c_str(), dw);
- return false;
- }
- fwrite(pwRawImage, sizeof(WORD), nWidth * nHeight, fp);
- fclose(fp);
- //mLog::Info("Save raw image over");
- return true;
- }
|