#include "stdafx.h" #include "CCOS.Dev.FPD.CareRayDR.h" #include "common_api.h" #include "DICOMImageHeadKey.h" #include "Detector_CareRayDR.h" namespace nsFPD = CCOS::Dev::Detail::Detector; //----------------------------------------------------------------------------- // FPDDeviceCareRay //----------------------------------------------------------------------------- extern Detector_CareRayDR* g_pDetector; static nsFPD::CareRayDriver gIODriver; Log4CPP::Logger* gLogger = nullptr; extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 ! { return &gIODriver; } extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 ! { return new nsFPD::CareRayDriver(); } nsFPD::CareRayDriver::CareRayDriver() { pObjDev = nullptr; m_bDriverConnect = false; //缺省为false m_pAttribute.reset(new ResDataObject()); m_pDescription.reset(new ResDataObject()); } nsFPD::CareRayDriver::~CareRayDriver() { if (pObjDev != nullptr) { delete pObjDev; pObjDev = nullptr; } } void nsFPD::CareRayDriver::Prepare() { printf("CareRayDR driver module: prepare \r\n"); string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Detector\Conf\Log4CPP.Config.FPD.xml)"; Log4CPP::GlobalContext::Map::Set(ZSKK::Utility::Hash("LogFileName"), "FPD.CareRayDR"); auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str()); gLogger = Log4CPP::LogManager::GetLogger("FPD.CareRayDR"); Info("CareRayDriver::Prepare get logger FPD.CareRayDR"); } bool nsFPD::CareRayDriver::Connect() { printf("CareRay driver module: Connect \r\n"); Info("--Func-- driver connect \n"); pObjDev = new FPDDeviceCareRay(EventCenter, m_ConfigFileName); m_bDriverConnect = true; //connect执行完毕,置为true printf("CareRay driver module: Connect over\r\n"); return true; } void nsFPD::CareRayDriver::Disconnect() { printf("CareRay driver module: Disconnect \r\n"); Info("--Func-- driver disconnect \n"); m_bDriverConnect = false; //disconnect置为false } bool nsFPD::CareRayDriver::isConnected() const { return m_bDriverConnect; } auto nsFPD::CareRayDriver::CreateDevice(int index)->std::unique_ptr { printf("CareRay driver module: CreateDevice \r\n"); Info("--Func-- driver createdevice \n"); auto Device = std::unique_ptr(new IODevice(pObjDev)); pObjDev->CreateDevice(); pObjDev->Register(); return Device; } std::string nsFPD::CareRayDriver::DriverProbe() { printf("CareRayDriver::DriverProbe \r\n"); Info("CareRayDriver::DriverProbe config name:{$}", m_ConfigFileName); 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", "Detector"); HardwareInfo.add("MinorID", "DR"); HardwareInfo.add("VendorID", "CareRay"); HardwareInfo.add("ProductID", "4343W"); HardwareInfo.add("SerialID", "Driver"); } string str = HardwareInfo.encode(); return str; } /*** ** 获取ID和配置 ***/ std::string nsFPD::CareRayDriver::GetResource() { ResDataObject r_config, temp; if (!temp.loadFile(m_ConfigFileName.c_str())) { Error("GetResource load {$} fail!", m_ConfigFileName); 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... string strAccess = ""; //用于存储权限的类型 R/W/RW string strRequired = ""; // TRUE/FALSE string strDefaultValue = ""; string strRangeMin = ""; string strRangeMax = ""; try { string strFPD = (string)r_config["VendorID"]; ConfigInfo FPDVender(ConfKey::CcosDetectorType, "string", "R", "TRUE", strFPD.c_str()); AddConfig(FPDVender); strFPD = (string)r_config["ProductID"]; ConfigInfo FPDModel(ConfKey::CcosDetectorModel, "string", "R", "TRUE", strFPD.c_str()); AddConfig(FPDModel); int nConfigInfoCount = (int)r_config["ConfigToolInfo"].GetKeyCount("AttributeInfo"); for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++) { DescriptionTemp.clear(); ListTemp.clear(); //AttributeType strType = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"]; //AttributeAccess strAccess = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"]; //AttributeRequired strRequired = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"]; //AttributeDefaultValue strDefaultValue = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"]; strTemp = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeKey"]; ConfigInfo FPDAttr(strTemp.c_str(), strType.c_str(), strAccess.c_str(), strRequired.c_str(), strDefaultValue.c_str()); //AttributeKey //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值 strTemp = (string)r_config["ConfigToolInfo"][nInfoIndex]["InnerKey"]; nTemp = (int)r_config["ConfigToolInfo"][nInfoIndex]["PathID"]; GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //2. 赋值 FPDAttr.SetCurrentValue(strValue.c_str()); //AttributeRangeMin strRangeMin = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"]; //AttributeRangeMax strRangeMax = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"]; if (strRangeMax != "" && strRangeMin != "") //不需要的配置项为空 { FPDAttr.SetRange(strRangeMin.c_str(), strRangeMax.c_str()); } //AttributeList nTemp = r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"]; if (nTemp > 0) //ListNum不大于0时说明不需要list配置 { for (int nListIndex = 0; nListIndex < nTemp; nListIndex++) { strTemp = (string)r_config["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex]; sprintf_s(sstream, "%d", nListIndex); ListTemp.add(sstream, strTemp.c_str()); } FPDAttr.SetList(ListTemp.encode()); } AddConfig(FPDAttr); } } catch (ResDataObjectExption& e) { Error("Get config error: {$}", e.what()); return ""; } ResDataObject resAttr, resDescription; for (auto Item : m_ConfigInfo) { resAttr.add(Item.GetKey(), Item.GetCurrentValue()); resDescription.add(Item.GetKey(), Item.GetDescription()); } ResDataObject resDeviceResource; resDeviceResource.add(ConfKey::CcosDetectorAttribute, resAttr); resDeviceResource.add(ConfKey::CcosDetectorDescription, resDescription); ResDataObject DescriptionTempEx; DescriptionTempEx.add(ConfKey::CcosDetectorConfig, resDeviceResource); m_DeviceConfig = DescriptionTempEx; (*m_pAttribute) = resAttr; (*m_pDescription) = resDescription; string res = DescriptionTempEx.encode(); printf("CareRay driver module: get resource over \r\n"); return res; } std::string nsFPD::CareRayDriver::DeviceProbe() { printf("CareRay driver module: Device Probe \r\n"); 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", "CareRay"); HardwareInfo.add("ProductID", "4343W"); HardwareInfo.add("SerialID", "1234"); } string str = HardwareInfo.encode(); return str; } bool nsFPD::CareRayDriver::GetDeviceConfig(std::string& Cfg) { Cfg = m_DeviceConfig.encode(); Info("GetDeviceConfig over"); return true; } bool nsFPD::CareRayDriver::SetDeviceConfig(std::string Cfg) { Info("--Func-- SetDeviceConfig {$}\n", Cfg.c_str()); ResDataObject DeviceConfig; DeviceConfig.decode(Cfg.c_str()); ResDataObject DescriptionTempEx; DescriptionTempEx = DeviceConfig["DeviceConfig"]; bool bSaveFile = false; //true:重新保存配置文件 string strAccess = ""; for (int i = 0; i < DescriptionTempEx.size(); i++) { ResDataObject temp = DescriptionTempEx[i]; Info("{$}", temp.encode()); for (int j = 0; j < temp.size(); j++) { string strKey = temp.GetKey(j); Info("{$}", strKey.c_str()); try { if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0) { strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"]; if ("RW" == strAccess || "rw" == strAccess) { //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值 //1. 修改内存中的值,用于给上层发消息 (*m_pAttribute)[strKey.c_str()] = temp[j]; //2. 拿到Innerkey int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo"); 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, temp[j])) { bSaveFile = true; } } else { Info("{$} is not a RW configuration item", strKey.c_str()); } } } catch (ResDataObjectExption& e) { Error("SetDriverConfig crashed: {$}", e.what()); return false; } } } if (bSaveFile) { //3. 重新保存配置文件 SaveConfigFile(true); } return true; } bool nsFPD::CareRayDriver::SaveConfigFile(bool bSendNotify) { m_ConfigAll["CONFIGURATION"] = m_Configurations; bool ret = m_ConfigAll.SaveFile(m_ConfigFileName.c_str()); if (ret) { Info("SaveConfigFile Success!"); return true; } else { Error("SaveConfigFile Fail!"); return false; } } bool nsFPD::CareRayDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue) { strValue = ""; string strTemp = pInnerKey; 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 = ""; Error("Error Configuration item: {$}", pInnerKey); } } return true; } bool nsFPD::CareRayDriver::SetDeviceConfigValue(ResDataObject &config, const char* pInnerKey, int nPathID, const char* szValue) { string strTemp = pInnerKey; Info("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 || CcosDetectorAttachedFlag == strTemp) { config[pInnerKey] = szValue; } else { Error("Error Configuration item: {$}", pInnerKey); return false; } } return true; } nsFPD::FPDDeviceCareRay::FPDDeviceCareRay(std::shared_ptr center,std::string strConfigPath) : m_nCalibTotalExposureNum(0), m_nCalibCurrentCalibrationRound(0), m_nCalibCurrentExposureIndex(0), m_nCalibCurrentExposureNum(0) { m_bDeviceConnect = false; m_nFullImageHeight = 0; m_nFullImageWidth = 0; m_pFullImgBuffer = nullptr; m_nImgBits = 0; m_nAngle = 0; m_nPixelSpacing = 0; m_nSensitivity = 0; m_fDose = 0; m_eSyncMode = SYNC_SOFTWARE; m_fFactorEXI2UGY = 0.0f; m_nFPDExpReadyTime = 1000; m_strWorkPath = GetProcessDirectory(); m_DetectorCtrlUnit.reset(new OemCtrl(center, this)); m_AcqUnit.reset(new OemAcq(center, this)); m_SyncUnit.reset(new OemSync(center, this)); m_CalibUnit.reset(new OemCalib(center, this)); m_DetectorConfiguration.reset(new DetectorConfiguration(strConfigPath)); m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY)); m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY)); m_WaitCalibDoseEvt = CreateEvent(NULL, FALSE, FALSE, NULL); m_bOnlyHaveFpd = false; EventCenter = center; m_eAppStatus = APP_STATUS_IDLE; } nsFPD::FPDDeviceCareRay::~FPDDeviceCareRay() { if (nullptr != m_pFullImgBuffer) { delete[]m_pFullImgBuffer; m_pFullImgBuffer = nullptr; } if (m_WaitCalibDoseEvt) { CloseHandle(m_WaitCalibDoseEvt); m_WaitCalibDoseEvt = nullptr; } } std::string nsFPD::FPDDeviceCareRay::GetGUID() const { return DetectorUnitType; } bool nsFPD::FPDDeviceCareRay::Prepare() { printf("CareRay device module: Prepare \r\n"); Info("--Func-- device prepare"); EventCenter->OnMaxBlockSize("DrQue", m_stDeviceConfig.nMaxImageWidth * m_stDeviceConfig.nMaxImageWidth * 2, 3, 1500 * 1500 * 2, 1); Connect(); return true; } bool nsFPD::FPDDeviceCareRay::CreateDevice() { Info("CreateDevice start"); if (!LoadConfig()) { return false; } if (nullptr == g_pDetector) { g_pDetector = new Detector_CareRayDR(); } g_pDetector->DriverEntry(this, m_DetectorConfiguration->m_Configurations); Info("CreateDevice end"); return true; } void nsFPD::FPDDeviceCareRay::Register() { auto Disp = &Dispatch; RegisterCtrl(Disp); RegisterAcq(Disp); RegisterSync(Disp); RegisterCalib(Disp); } RET_STATUS nsFPD::FPDDeviceCareRay::Connect() { printf("--Func-- device Connect \r\n"); Info("--Func-- device Connect"); m_DetectorCtrlUnit->SetAttachStatus(to_string(1)); //没有attach功能,直接上发1,使客户端显示探测器状态 RET_STATUS ret = RET_STATUS::RET_FAILED; if (g_pDetector->Connect(this, m_strWorkPath.c_str())) { ret = RET_STATUS::RET_SUCCEED; } return ret; } RET_STATUS nsFPD::FPDDeviceCareRay::EnterExam(int nExamMode) { Info("--Func-- EnterExam {$}", nExamMode); switch (nExamMode) { case APP_STATUS_WORK_BEGIN: Info("Enter into Exam Windows"); m_eAppStatus = APP_STATUS_WORK_BEGIN; break; case APP_STATUS_WORK_END: Info("Quit Exam Windows"); m_eAppStatus = APP_STATUS_WORK_END; break; case APP_STATUS_DETSHARE_BEGIN: Info("Enter into Detector Share Windows"); m_eAppStatus = APP_STATUS_DETSHARE_BEGIN; break; case APP_STATUS_DETSHAR_END: Info("Quit Detector Share Windows"); m_eAppStatus = APP_STATUS_DETSHAR_END; break; case APP_STATUS_CAL_BEGIN: Info("Enter into Calibration Windows"); m_eAppStatus = APP_STATUS_CAL_BEGIN; break; case APP_STATUS_CAL_END: Info("Quit Calibration Windows"); m_eAppStatus = APP_STATUS_CAL_END; break; case APP_STATUS_WORK_IN_SENSITIVITY: Info("Enter into sensitivity test interface"); m_eAppStatus = APP_STATUS_WORK_IN_SENSITIVITY; break; default: break; } g_pDetector->EnterExamMode(nExamMode); return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::FPDDeviceCareRay::SetAcqMode(string strMode) { printf("device module: SetAcqMode(%s) \r\n", strMode); Info("--Func-- SetAcqMode({$})", strMode); RET_STATUS ret = RET_STATUS::RET_FAILED; //如果没连接,不执行 if (!m_bDeviceConnect) { Error("Detector not connected, return"); return ret; } int tempID; if (strMode == "DUALENERGY") { tempID = 3; } try { ResDataObject objModeConfig = m_DetectorConfiguration->m_Configurations; int nModeCount = (int)objModeConfig["ModeTable"].GetKeyCount("DetectorMode"); for (int i = 0; i < nModeCount; i++) { int nAppModeID = (int)objModeConfig["ModeTable"][i]["LogicMode"]; if (nAppModeID == tempID) { m_nAcqMode = tempID; m_nFullImageWidth = (int)objModeConfig["ModeTable"][i]["ImageWidth"]; m_nFullImageHeight = (int)objModeConfig["ModeTable"][i]["ImageHeight"]; m_nImgBits = (int)objModeConfig["ModeTable"][i]["PhySizeInfoBit"]; m_nAngle = (int)objModeConfig["ModeTable"][i]["RotateAngle"]; m_nPixelSpacing = (int)objModeConfig["ModeTable"][i]["PixelPitch"]; m_nSensitivity = (int)objModeConfig["ModeTable"][i]["Sensitivity"]; m_eSyncMode = (SYNC_MODE)(int)objModeConfig["ModeTable"][i]["SyncType"]; m_nFPDExpReadyTime = (int)objModeConfig["ModeTable"][i]["XWindow"]; /*string strDose = (string)objModeConfig["ModeTable"][i]["CalibConfig"]["NodeInfo"]["Dose"]; m_fDose = stof(strDose.c_str());*/ if (nullptr != m_pFullImgBuffer) { delete[]m_pFullImgBuffer; m_pFullImgBuffer = nullptr; } m_pFullImgBuffer = new WORD[(size_t)m_nFullImageWidth * (size_t)m_nFullImageHeight]; if (m_nAngle == 90 || m_nAngle == 270) { m_AcqUnit->SetFulImageInfo(m_nFullImageWidth, m_nFullImageHeight, m_nImgBits, false); } else { m_AcqUnit->SetFulImageInfo(m_nFullImageHeight, m_nFullImageWidth, m_nImgBits, false); } m_AcqUnit->SetPrevImageInfo(false, 0, 0, false); if (g_pDetector->SetAcqMode(tempID)) { ret = RET_STATUS::RET_SUCCEED; } break; } } } catch (ResDataObjectExption& e) { Error("Read configuration failed, Error code: {$}", e.what()); } return ret; } bool nsFPD::FPDDeviceCareRay::GetOnlyHaveFpd() { return m_bOnlyHaveFpd; } int nsFPD::FPDDeviceCareRay::GetGainExposureNum() { return m_nCalibTotalExposureNum; } RET_STATUS nsFPD::FPDDeviceCareRay::GetSyncMode(SYNC_MODE& eSyncMode) { eSyncMode = m_eSyncMode; return RET_STATUS::RET_SUCCEED; } RET_STATUS nsFPD::FPDDeviceCareRay::PrepareAcquisition() { printf("--Func-- PrepareAcquisition \r\n"); Info("--Func-- PrepareAcquisition"); RET_STATUS ret = RET_STATUS::RET_FAILED; if (!m_bDeviceConnect) { Error("Detector not connected, return"); return ret; } if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus()) { if ((m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_RUNNING) || (m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_ACTIVE)) { printf("PrepareAcquisition failed. Detector at Calibration status.\n"); Error("PrepareAcquisition failed. Detector at Calibration status"); } if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus()) { printf("Detector already at Acq status.\n"); Error("Detector already at Acq status"); ret = RET_STATUS::RET_SUCCEED; } } else { m_SyncUnit->FPDReadyNotify(false); //prepare前置为初值 if (g_pDetector->PrepareAcquisition(this)) { ret = RET_STATUS::RET_SUCCEED; //m_SyncUnit->FPDReadyNotify(true); //prepare succeed } } Info("PrepareAcquisition over"); return ret; } RET_STATUS nsFPD::FPDDeviceCareRay::StartAcquisition(string in) { printf("--Func-- StartAcquisition \r\n"); Info("--Func-- StartAcquisition"); RET_STATUS ret = RET_STATUS::RET_FAILED; if (!m_bDeviceConnect) { Error("Detector not connected, return"); return ret; } if (m_nAcqMode != AcqMode::DUAL_ENERGY) { if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus()) { if ((m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_RUNNING) || (m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_ACTIVE)) { printf("PrepareAcquisition failed. Detector at Calibration status.\n"); Error("PrepareAcquisition failed. Detector at Calibration status."); } if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus()) { printf("Detector already at Acq status.\n"); Error("Detector already at Acq status."); } } else { if (g_pDetector->StartAcquisition(this)) { ret = RET_STATUS::RET_SUCCEED; m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ)); } else { m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY)); } } } else { if (g_pDetector->StartAcquisition(this)) { ret = RET_STATUS::RET_SUCCEED; } else { m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY)); } } Info("StartAcquisition over"); return ret; } RET_STATUS CCOS::Dev::Detail::Detector::FPDDeviceCareRay::ToFrameAcq(string in) { //m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ)); return RET_STATUS::RET_SUCCEED; } RET_STATUS CCOS::Dev::Detail::Detector::FPDDeviceCareRay::RequestXray(string in) { RET_STATUS ret = RET_STATUS::RET_FAILED; if (g_pDetector->RequestXray(this)) { ret = RET_STATUS::RET_SUCCEED; } return ret; } RET_STATUS nsFPD::FPDDeviceCareRay::StopAcquisition() { printf("--Func-- StopAcquisition \r\n"); Info("--Func-- StopAcquisition"); RET_STATUS ret = RET_STATUS::RET_FAILED; if (!m_bDeviceConnect) { Error("Detector not connected, return"); return ret; } if (DETECTOR_STATUS_STANDBY == m_DetectorCtrlUnit->GetDetectorStatus()) { printf("Detector already at Acq status.\n"); Info("Detector already at Acq status."); ret = RET_STATUS::RET_SUCCEED; } else { if (g_pDetector->StopAcquisition(this)) { ret = RET_STATUS::RET_SUCCEED; m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY)); } } Info("StopAcquisition over"); return ret; } RET_STATUS nsFPD::FPDDeviceCareRay::ActiveCalibration(CCOS_CALIBRATION_TYPE eType) { printf("--Func-- ActiveCalibration %d \r\n", eType); Info("--Func-- ActiveCalibration {$}", (int)eType); RET_STATUS ret = RET_STATUS::RET_FAILED; if (!m_bDeviceConnect) { Error("Detector not connected, return"); return ret; } if (eType == CCOS_CALIBRATION_TYPE_NONE || eType == CCOS_CALIBRATION_TYPE_MAX) { Error("calibration type is invalid!"); return RET_STATUS::RET_INVALID; } if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus()) { if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus()) { printf("ActiveCalibration failed. Detector at Acq status\r\n"); Error("ActiveCalibration failed. Detector at Acq status"); ret = StopAcquisition(); if (ret != RET_STATUS::RET_SUCCEED) { printf("stop acquisition error\n"); Error("stop acquisition error"); return ret; } } return RET_STATUS::RET_FAILED; } m_eAppStatus = APP_STATUS_CAL_BEGIN; if (eType == CCOS_CALIBRATION_TYPE_XRAY) { printf("calibration type: CCOS_CALIBRATION_TYPE_XRAY\n"); Info("calibration type: CCOS_CALIBRATION_TYPE_XRAY"); int nCalibrationRounds = (int)m_CalibDoseList.size(); g_pDetector->SetCalibRounds(nCalibrationRounds); } if (g_pDetector->ActiveCalibration(this, eType)) { ret = RET_STATUS::RET_SUCCEED; m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_ACTIVE)); m_CalibUnit->SetCalibrationProgress(0); if (eType == CCOS_CALIBRATION_TYPE_XRAY) { Info("start to waitting CalibDoseEvt"); printf("start to waitting CalibDoseEvt\n"); DWORD nRet = WaitForSingleObject(m_WaitCalibDoseEvt, INFINITE); } } else { Error("Active calibration failed"); ret = RET_STATUS::RET_FAILED; } //重置校正流程参数 m_nCalibCurrentCalibrationRound = 1; m_nCalibCurrentExposureIndex = 1; m_nCalibCurrentExposureNum = 0; Info("ActiveCalibration over"); return ret; } RET_STATUS nsFPD::FPDDeviceCareRay::PrepareCalibration() { printf("--Func-- PrepareCalibration------ \n"); Info("==============================PrepareCalibration"); RET_STATUS ret = RET_STATUS::RET_FAILED; if (!m_bDeviceConnect) { printf("Detector not connected, return\n"); Error("Detector not connected, return"); return ret; } m_SyncUnit->FPDReadyNotify(false); //prepare前置为初值 if (g_pDetector->PrepareCalibration(this)) { printf("FPD ready notify------------\n"); ret = RET_STATUS::RET_SUCCEED; m_SyncUnit->FPDReadyNotify(true); //prepare succeed } else { printf("Prepare calibration failed\n"); Error("Prepare calibration failed"); } m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY)); printf("PrepareCalibration over\n"); Info("==============================PrepareCalibration over"); return ret; } RET_STATUS nsFPD::FPDDeviceCareRay::GetRequestedDose(std::string& strDose) { Info("==============================GetRequestedDose"); printf("--Func-- GetRequestedDose------ \n"); RET_STATUS ret = RET_STATUS::RET_FAILED; bool bGetDoseInfo = false; ResDataObject out; if (!m_bDeviceConnect) { Error("Detector not connected, return"); return ret; } CCOS_CALIBRATION_TYPE nCalibrationType = m_CalibUnit->GetCalibrationType(); Info("GetRequestedDose calib type is {$}", (int)nCalibrationType); printf("GetRequestedDose calib type is %d\n", nCalibrationType); if (CCOS_CALIBRATION_TYPE_DARK == nCalibrationType) { out.add("Dose", 0.0f); out.add("kV", 0.0f); out.add("mA", 0.0f); out.add("ms", 0.0f); out.add("mAs", 0.0f); bGetDoseInfo = true; } else if (CCOS_CALIBRATION_TYPE_XRAY == nCalibrationType) { Info("calib dose list size is {$}", m_CalibDoseList.size()); printf("calib dose list size is %d\n", (int)m_CalibDoseList.size()); for (int i = 0; i < m_CalibDoseList.size(); i++) { ResDataObject temp = m_CalibDoseList[i]; int nDose = temp["Dose"]; int nDoseParem = (int)(m_fDoseParam * 1000); if (nDoseParem == nDose) { out.add("Dose", nDoseParem); out.add("kV", temp["kV"]); out.add("mA", temp["mA"]); out.add("ms", temp["ms"]); out.add("mAs", temp["mAs"]); bGetDoseInfo = true; Info("Find target dose parameter"); break; } } } else { Warn("Can not support CalibrationType($)", (int)nCalibrationType); ret = RET_STATUS::RET_FAILED; } if (bGetDoseInfo) { strDose = out.encode(); Info("GetRequestedDose:{$}", strDose.c_str()); ret = RET_STATUS::RET_SUCCEED; } else { Error("GetRequestedDose failed"); } Info("==============================GetRequestedDose over"); return ret; } RET_STATUS nsFPD::FPDDeviceCareRay::GetCalibrationStep(int nDetectorID, string& strCalibrationStepInfo) { Info("==============================GetCalibrationStep"); printf("--func-- GetCalibrationStep\n"); Info("Calibration DetectorID: {$}", nDetectorID); RET_STATUS ret = RET_STATUS::RET_SUCCEED; ResDataObject out; int nCalibrationRounds = (int)m_CalibDoseList.size(); int nExposureNumCurrentRound = (int)m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]["ExpNum"]; if (g_pDetector->GetCalibrationStep(m_nCalibCurrentCalibrationRound, nCalibrationRounds, m_nCalibCurrentExposureIndex, nExposureNumCurrentRound)) { Info("GetCalibrationStep success"); } else { Error("GetCalibrationStep error"); ret = RET_STATUS::RET_FAILED; return ret; } out.add("CalibrationRounds", (int)m_CalibDoseList.size()); out.add("TotalExposureNum", m_nCalibTotalExposureNum); out.add("CurrentCalibrationRound", m_nCalibCurrentCalibrationRound); out.add("ExposureNumCurrentRound", (int)m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]["ExpNum"]); out.add("CurrentExposureIndex", m_nCalibCurrentExposureIndex); out.add("CurrentExposureNum", m_nCalibCurrentExposureNum); strCalibrationStepInfo = out.encode(); Info("GetCalibrationStep over,strCalibrationStepInfo: {$}", strCalibrationStepInfo.c_str()); return ret; } RET_STATUS nsFPD::FPDDeviceCareRay::StartCalibration() { printf("--Func-- StartCalibration \r\n"); Info("--Func-- StartCalibration"); RET_STATUS ret = RET_STATUS::RET_FAILED; if (!m_bDeviceConnect) { Error("Detector not connected, return"); return ret; } if ((m_CalibUnit->GetCalibrationStatus() != CCOS_CALIBRATION_STATUS_PAUSE) && (m_CalibUnit->GetCalibrationStatus() != CCOS_CALIBRATION_STATUS_ACTIVE)) { printf("CCOS_CALIBRATION_STATUS = %d\r\n", (int)m_CalibUnit->GetCalibrationStatus()); Error("Start calibration failed, in {$} status", (int)m_CalibUnit->GetCalibrationStatus()); return ret; } if (DETECTOR_STATUS_STANDBY != m_DetectorCtrlUnit->GetDetectorStatus()) { if (DETECTOR_STATUS_ACQ == m_DetectorCtrlUnit->GetDetectorStatus()) { printf("Start calibration failed. Detector at Acq status.\r\n"); Error("Start calibration failed. Detector at Acq status"); } return ret; } if (m_CalibUnit->GetCalibrationStatus() == CCOS_CALIBRATION_STATUS_RUNNING) { printf("Detector already at calib status.\n"); Error("Detector already at calib status"); return ret; } if (g_pDetector->StartCalibration(this)) { printf("start calibration success set detector status\n"); Info("start calibration success set detector status"); m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ)); m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_RUNNING)); ret = RET_STATUS::RET_SUCCEED; } else { Error("Start calibration failed"); ret = RET_STATUS::RET_FAILED; } Info("StartCalibration over"); return ret; } RET_STATUS nsFPD::FPDDeviceCareRay::StopCalibration() { printf("--Func-- StopCalibration \r\n"); Info("--Func-- StopCalibration"); RET_STATUS ret = RET_STATUS::RET_FAILED; if (!m_bDeviceConnect) { Error("Detector not connected, return"); return ret; } m_eAppStatus = APP_STATUS_CAL_END; if (g_pDetector->StopCalibration(this)) { ret = RET_STATUS::RET_SUCCEED; m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY)); m_CalibUnit->SetCalibrationProgress(to_string(100)); } else { Error("Start calibration failed"); } Info("StopCalibration over"); return ret; } void nsFPD::FPDDeviceCareRay::ConfirmCalExposure() { printf("--Func-- ConfirmCalExposure \r\n"); Info("--Func-- ConfirmCalExposure"); g_pDetector->ConfirmCalExposure(); } void nsFPD::FPDDeviceCareRay::AbortCalibration() { Info("==============================AbortCalibration"); printf("--func-- AbortCalibration\n"); CCOS_CALIBRATION_TYPE nCalibrationType = m_CalibUnit->GetCalibrationType(); if (CCOS_CALIBRATION_TYPE_DARK == nCalibrationType) { m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY)); m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_ERROR)); m_CalibUnit->SetCalibrationProgress(to_string(100)); Info("==============================AbortCalibration over"); return; } m_eAppStatus = APP_STATUS_CAL_END; g_pDetector->AbortCalibration(this); m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY)); m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_ERROR)); m_CalibUnit->SetCalibrationProgress(to_string(100)); m_AcqUnit->SendNoNeedWaitImage(true); Info("==============================AbortCalibration over"); } RET_STATUS nsFPD::FPDDeviceCareRay::AcceptCalibration() { Info("==============================AcceptCalibration"); printf("--func-- AcceptCalibration\n"); RET_STATUS Ret = RET_STATUS::RET_SUCCEED; if (g_pDetector->AcceptCalibration()) { Info("AcceptCalibration over"); Ret = RET_STATUS::RET_SUCCEED; } else { Error("AcceptCalibration error"); Ret = RET_STATUS::RET_FAILED; } int nExposureNumCurrentRound = (int)m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]["ExpNum"]; //完成校正条件:轮数够了,曝光次数够了 if ((m_nCalibCurrentCalibrationRound == (int)m_CalibDoseList.size()) && (m_nCalibCurrentExposureIndex == nExposureNumCurrentRound)) { Info("Calibration Round: {$}, Exposure Index: {$}, Finished", m_nCalibCurrentCalibrationRound, m_nCalibCurrentExposureIndex); m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY)); m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY)); m_CalibUnit->SetCalibrationProgress(to_string(100)); return Ret; } if (m_nCalibCurrentExposureIndex >= nExposureNumCurrentRound) //跳到下一轮校正参数 { m_nCalibCurrentCalibrationRound++; m_nCalibCurrentExposureIndex = 1; ResDataObject temp = m_CalibDoseList[m_nCalibCurrentCalibrationRound - 1]; int nDose = temp["Dose"]; m_fDoseParam = nDose / 1000.0f; } else { m_nCalibCurrentExposureIndex++; } m_nCalibCurrentExposureNum++; m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY)); Info("==============================AcceptCalibration over"); return Ret; } void nsFPD::FPDDeviceCareRay::RejectCalExposure() { printf("--Func-- RejectCalExposure \r\n"); Info("--Func-- RejectCalExposure"); g_pDetector->RejectCalExposure(); } RET_STATUS nsFPD::FPDDeviceCareRay::RejectCalibration() { printf("--Func-- RejectCalibration \n"); Info("==============================RejectCalibration"); RET_STATUS Ret = RET_STATUS::RET_SUCCEED; if (g_pDetector->RejectCalibration()) { Ret = RET_STATUS::RET_SUCCEED; } else { Error("RejectCalibration error"); Ret = RET_STATUS::RET_FAILED; } m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY)); Info("==============================RejectCalibration over"); return Ret; } bool nsFPD::FPDDeviceCareRay::CompleteCalibration() { printf("--func-- CompleteCalibration \n"); Info("==============================CompleteCalibration"); if (!g_pDetector->CompleteCalibration(this)) { Error("CompleteCalibration fail!"); return false; } if (g_pDetector->GetCalibType() == CCOS_CALIBRATION_TYPE_DARK) { printf("CompleteCalibration Calibration Type DARK\n"); Info("CompleteCalibration Calibration Type DARK"); } else if (g_pDetector->GetCalibType() == CCOS_CALIBRATION_TYPE_XRAY) { printf("CompleteCalibration Calibration Type XRAY\n"); Info("CompleteCalibration Calibration Type XRAY"); m_eAppStatus = APP_STATUS_CAL_END; } Info("CompleteCalibration set detector status standby"); m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY)); m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY)); if (m_bOnlyHaveFpd) { //通知子系统结束暗场校正太快了,导致后边的服务通知app的消息混乱了(不是一个进程的原因)acqservice,故此处延时1s printf("Sleep 1s,then send progress 100\n"); Info("Sleep 1s,then send progress 100"); Sleep(1000); } m_CalibUnit->SetCalibrationProgress(to_string(100)); Info("==============================CompleteCalibration over"); return true; } RET_STATUS nsFPD::FPDDeviceCareRay::SaveCalibrationFile(bool bSaveFlag) { printf("--Func-- SaveCalibrationFile \n"); Info("==============================SaveCalibrationFile"); RET_STATUS Ret = RET_STATUS::RET_SUCCEED; Info("SaveCalibrationFile bSaveFlag: {$}", bSaveFlag); if (!bSaveFlag) { Warn("Not save calibration file"); return Ret; } if (g_pDetector->SaveCalibrationFile()) { Info("SaveCalibrationFile over"); m_CalibUnit->SetSaveCalibrationFileFinish(true); Ret = RET_STATUS::RET_SUCCEED; } else { Error("SaveCalibrationFile error"); m_CalibUnit->SetSaveCalibrationFileFinish(false); Ret = RET_STATUS::RET_FAILED; } Info("==============================SaveCalibrationFile over"); return Ret; } bool nsFPD::FPDDeviceCareRay::Support_DarkCalib() { return true; } bool nsFPD::FPDDeviceCareRay::Support_XrayCalib() { return true; } void nsFPD::FPDDeviceCareRay::SendTemperatureValue(float fValue) { int nStatus = 0; m_Temperature->SetTemperature(fValue, nStatus); Info("SendTemperatureValue: {$}, status {$}", fValue, nStatus); return; } void nsFPD::FPDDeviceCareRay::SendWifiValue(int nValue) { int nStatus = 0; m_Wifi->SetSignalValue(nValue, nStatus); Info("SendWifiValue: {$}, status {$}", nValue, nStatus); return; } void nsFPD::FPDDeviceCareRay::SendBatteryValue(int nValue) { int nStatus = 0; m_Battery->SetRemainPowerValue(nValue, nStatus); Info("SendBatteryValue: {$}, status {$}", nValue, nStatus); return; } bool nsFPD::FPDDeviceCareRay::LoadConfig() { Info("LoadConfig start"); if (!m_DetectorConfiguration->LoadConfigurations(m_stDeviceConfig, m_ACQMODElist)) { Error("Load configuration file failed!!!"); return false; } string strDoseOfExi = std::to_string(m_stDeviceConfig.nDoseOfEXI); m_fFactorEXI2UGY = 100.0f / stof(strDoseOfExi) * 1.0f;//统一使用IEC标准 呈现四角信息,无单位 ugy * 100 -ugy。所有Zskk探测器的FactorEXI2UGY均需*100 Info("m_fFactorEXI2UGY = {$} ", m_fFactorEXI2UGY); string strFPDcoef = std::to_string(m_fFactorEXI2UGY); m_DetectorCtrlUnit->SetFPDSensitivity(strFPDcoef);//image process 重算ROIl的EXI需要此值 //string strFPDinfo = std::to_string(m_nSensitivity); //m_DetectorCtrlUnit->SetFPDSensitivity(strFPDinfo); m_DetectorCtrlUnit->SetPixelData(""); m_DetectorCtrlUnit->SetTargetEXI("5000"); //新增一个配置项代表当前系统中是否只有一个真是的平板探测器,其他设备没有或者是demo的 size_t keyCount = m_DetectorConfiguration->m_Configurations.GetKeyCount(OnlyHaveFpd); Info("LoadConfig OnlyHaveFpd keyCount:{$}", keyCount); if (keyCount) { m_bOnlyHaveFpd = (bool)m_DetectorConfiguration->m_Configurations[OnlyHaveFpd]; if (m_bOnlyHaveFpd) Info("current system only have FPD!"); } m_Battery.reset(new DeviceBatteryMould("DetectorBattery", 0, m_stDeviceConfig.nBatteryLimit, m_stDeviceConfig.nBatteryWarning, 100, 100, 0,0,0, EventCenter)); m_Temperature.reset(new DeviceTemperatureMould("DetectorTemperature", 0.0f, m_stDeviceConfig.fTemperatureMin, m_stDeviceConfig.fTemperLowLimit, m_stDeviceConfig.fTemperatureMax, m_stDeviceConfig.fTemperMaxLimit, 0.0f,0,0, EventCenter)); m_Wifi.reset(new DeviceWifiMould("DetectorWifi", 0, m_stDeviceConfig.nWifiLimit, m_stDeviceConfig.nWifiWarning, 100, 100, 0,0,0, EventCenter)); if (!m_DetectorConfiguration->LoadCalibrationDose(m_strWorkPath, m_CalibDoseList, m_nCalibTotalExposureNum)) { Error("Load Calibration Dose failed!!!"); return false; } Info("m_nCalibTotalExposureNum:{$}", m_nCalibTotalExposureNum); Info("LoadConfig end"); return true; } void nsFPD::FPDDeviceCareRay::RegisterCtrl(nsDetail::Dispatch* Dispatch) { Dispatch->Action.Push(ActionKey::EnterExam, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSEnterExam); Dispatch->Action.Push(ActionKey::ExitExam, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSExitExam); Dispatch->Action.Push(ActionKey::SetExposureTimes, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSSetExposureTimes); Dispatch->Action.Push(ActionKey::SetXrayOnNum, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSSetXrayOnNum); Dispatch->Action.Push(ActionKey::CcosActiveDetector, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSActiveDetector); Dispatch->Get.Push(AttrKey::DetectorStatus, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFPDStatus); Dispatch->Get.Push(AttrKey::DetectorType, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorType); Dispatch->Get.Push(AttrKey::Description, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDescription); Dispatch->Get.Push(AttrKey::DetectorID, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetDetectorID); Dispatch->Get.Push(AttrKey::FPDSensitivity, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetFPDSensitivity); Dispatch->Get.Push(AttrKey::PixelData, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetPixelData); Dispatch->Get.Push(AttrKey::TargetEXI, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetTargetEXI); Dispatch->Get.Push(CcosDetectorAttachedFlag, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetAttachStatus);//CcosDetectorAttachedFlag Dispatch->Get.Push(SupportDDR, m_DetectorCtrlUnit.get(), &DetectorCtrlUnit::JSGetSupportDDR); } void nsFPD::FPDDeviceCareRay::RegisterAcq(nsDetail::Dispatch* Dispatch) { Dispatch->Action.Push(ActionKey::SetAcqMode, m_AcqUnit.get(), &AcqUnit::JSSetAcqMode); Dispatch->Get.Push(AttrKey::AcqMode, m_AcqUnit.get(), &AcqUnit::JSGetAcqMode); Dispatch->Get.Push(AttrKey::ZskkFPDState, m_AcqUnit.get(), &AcqUnit::JSGetZskkFPDState); Dispatch->Get.Push(AttrKey::NoNeedWaitImage, m_AcqUnit.get(), &AcqUnit::JSGetNoNeedWaitImage); Dispatch->Get.Push(AttrKey::ImgDataInfo, m_AcqUnit.get(), &AcqUnit::JSGetLastImage); } void nsFPD::FPDDeviceCareRay::RegisterSync(nsDetail::Dispatch* Dispatch) { Dispatch->Action.Push(ActionKey::SetSyncMode, m_SyncUnit.get(), &SyncUnit::JSSetSyncMode); Dispatch->Action.Push(ActionKey::SetXwindowSize, m_SyncUnit.get(), &SyncUnit::JSSetXwindowSize); Dispatch->Action.Push(ActionKey::PrepareAcquisition, m_SyncUnit.get(), &SyncUnit::JSPrepareAcquisition); Dispatch->Action.Push(ActionKey::StartAcquisition, m_SyncUnit.get(), &SyncUnit::JSStartAcquisition); Dispatch->Action.Push(ActionKey::ToFrameAcq, m_SyncUnit.get(), &SyncUnit::JSToFrameAcq); Dispatch->Action.Push(ActionKey::RequestXray, m_SyncUnit.get(), &SyncUnit::JSRequestXray); Dispatch->Action.Push(ActionKey::StopAcquisition, m_SyncUnit.get(), &SyncUnit::JSStopAcquisition); Dispatch->Get.Push(AttrKey::FPDReadyStatus, m_SyncUnit.get(), &SyncUnit::JSGetFPDReady); Dispatch->Get.Push(AttrKey::XwindowStatus, m_SyncUnit.get(), &SyncUnit::JSGetXWindowStatus); Dispatch->Get.Push(AttrKey::ImageReadingStatus, m_SyncUnit.get(), &SyncUnit::JSGetImageReadingStatus); Dispatch->Get.Push(AttrKey::FPDExpReady, m_SyncUnit.get(), &SyncUnit::JSGetExpReadyStatus); Dispatch->Get.Push(AttrKey::SyncMode, m_SyncUnit.get(), &SyncUnit::JSGetSyncMode); } void nsFPD::FPDDeviceCareRay::RegisterCalib(nsDetail::Dispatch* Dispatch) { Dispatch->Action.Push(ActionKey::ActiveCalibration, m_CalibUnit.get(), &CalibUnit::JSActiveCalibration); Dispatch->Action.Push(ActionKey::GetRequestedDose, m_CalibUnit.get(), &CalibUnit::JSGetRequestedDose); Dispatch->Action.Push(ActionKey::SetRequestedDose, m_CalibUnit.get(), &CalibUnit::JSSetRequestedDose); Dispatch->Action.Push(ActionKey::PrepareCalibration, m_CalibUnit.get(), &CalibUnit::JSPrepareCalibration); Dispatch->Action.Push(ActionKey::StartCalibration, m_CalibUnit.get(), &CalibUnit::JSStartCalibration); Dispatch->Action.Push(ActionKey::StopCalibration, m_CalibUnit.get(), &CalibUnit::JSStopCalibration); Dispatch->Action.Push(ActionKey::SetCorrectionType, m_CalibUnit.get(), &CalibUnit::JSSetCorrectionType); Dispatch->Action.Push(ActionKey::AcceptCalibration, m_CalibUnit.get(), &CalibUnit::JSAcceptCalibration); Dispatch->Action.Push(ActionKey::RejectCalibration, m_CalibUnit.get(), &CalibUnit::JSRejectCalibration); Dispatch->Action.Push(ActionKey::SaveCalibrationFile, m_CalibUnit.get(), &CalibUnit::JSSaveCalibrationFile); Dispatch->Action.Push(ActionKey::GetCalibrationStep, m_CalibUnit.get(), &CalibUnit::JSGetCalibrationStep); Dispatch->Get.Push(AttrKey::CalibrationStatus, m_CalibUnit.get(), &CalibUnit::JSGetCalibStatus); Dispatch->Get.Push(AttrKey::CalibrationProgress, m_CalibUnit.get(), &CalibUnit::JSGetCalibProgress); Dispatch->Get.Push(AttrKey::UploadCalibrationFilesResult, m_CalibUnit.get(), &CalibUnit::JSGetUploadCalibrationFilesResult); Dispatch->Get.Push(AttrKey::SupportCalibrationType, m_CalibUnit.get(), &CalibUnit::JSGetSupportCalibrationType); Dispatch->Get.Push(AttrKey::HaveImgCalibration, m_CalibUnit.get(), &CalibUnit::JSGetHaveImgCalibration); Dispatch->Get.Push(AttrKey::SaveCalibrationFileFinish, m_CalibUnit.get(), &CalibUnit::JSGetSaveCalibrationFileFinish); } void nsFPD::FPDDeviceCareRay::RegisterOthers(nsDetail::Dispatch* Dispatch) { Dispatch->Get.Push(AttrKey::Temperature_Value, m_Temperature.get(), &DeviceTemperatureMould::JSGetCurrentTemperatureValue); Dispatch->Get.Push(AttrKey::Remain_Power_Value, m_Battery.get(), &DeviceBatteryMould::JSGetCurrentBatteryValue); Dispatch->Get.Push(AttrKey::Wifi_Strength_Value, m_Wifi.get(), &DeviceWifiMould::JSGetCurrentSignalValue); Dispatch->Get.Push(TempUpperLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureWarningMax); Dispatch->Get.Push(TempLowerLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureWarningMin); Dispatch->Get.Push(TempMaxLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureErrorMax); Dispatch->Get.Push(TempMinLimit, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureErrorMin); Dispatch->Get.Push(Temperature_CalibUpWarn, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureCalibWarningMax); Dispatch->Get.Push(Temperature_CalibLowWarn, m_Temperature.get(), &DeviceTemperatureMould::JSGetTemperatureCalibWarningMin); Dispatch->Get.Push(BatLowerLimit, m_Battery.get(), &DeviceBatteryMould::JSGetBatteryWarningMin); Dispatch->Get.Push(BatMiniLimit, m_Battery.get(), &DeviceBatteryMould::JSGetBatteryErrorMin); Dispatch->Get.Push(WifiLowerLimit, m_Wifi.get(), &DeviceWifiMould::JSGetSignalWarningMin); Dispatch->Get.Push(WifiMiniLimit, m_Wifi.get(), &DeviceWifiMould::JSGetSignalErrorMin); } void nsFPD::FPDDeviceCareRay::OnFPDCallback(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam) { 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::FPDDeviceCareRay::OnEventProcessConf(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam) { Error("Not support this conf({$})", nEventID); } void nsFPD::FPDDeviceCareRay::OnEventProcessInfo(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam) { Error("Not support this info({$})", nEventID); } void nsFPD::FPDDeviceCareRay::OnEventProcessStatus(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam) { switch (nEventID) { case EVT_STATUS_INIT: Info("EVT_STATUS_INIT nParam1:{$}", nParam1); break; case EVT_STATUS_PANEL: { ENUM_PANEL_STATUS m_ePanelStatus = (ENUM_PANEL_STATUS)nParam1; if (PANEL_CLOSE == nParam1) { Info("EVT_STATUS_PANEL PANEL_CLOSE"); m_bDeviceConnect = false; } else if (PANEL_CONNECT == nParam1) { Info("EVT_STATUS_PANEL PANEL_CONNECT"); m_bDeviceConnect = true; } else if (PANEL_STANDBY == nParam1) { Info("EVT_STATUS_PANEL PANEL_STANDBY"); m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY)); } else if (PANEL_SLEEP == nParam1) { Info("EVT_STATUS_PANEL PANEL_NOT_READY"); m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_WAKEUP)); } else if (PANEL_READY_EXP == nParam1) { Info("EVT_STATUS_PANEL PANEL_READY_EXP"); /*string strTemp = pszMsg; if (strTemp.find("true") != std::string::npos) { m_SyncUnit->ExpReadyNotify(m_nFPDExpReadyTime); } else { m_SyncUnit->ExpReadyNotify(0); }*/ m_SyncUnit->FPDReadyNotify(true); m_AcqUnit->SetZskkFPDState(to_string(ZSKK_FPD_STATE_READY)); } else if (PANEL_XWINDOW_ON == nParam1) //Xwindow On { m_stImgCreateTime = { 0 }; GetLocalTime(&m_stImgCreateTime); Info("XWindowOn at {$:d04}-{$:d02}-{$:d02} {$:d02}:{$:d02}:{$:d02}:{$:d03}", m_stImgCreateTime.wYear, m_stImgCreateTime.wMonth, m_stImgCreateTime.wDay, m_stImgCreateTime.wHour, m_stImgCreateTime.wMinute, m_stImgCreateTime.wSecond, m_stImgCreateTime.wMilliseconds); //if (SYNC_SOFTWARE == m_eSyncMode || SYNC_AED == m_eSyncMode) //{ m_SyncUnit->XWindowOnNotify(); Info("m_SyncUnit XWindowOnNotify Finished!"); //} } else if (PANEL_XWINDOW_OFF == nParam1) // Xwindow Off { m_stImgCreateTime = { 0 }; GetLocalTime(&m_stImgCreateTime); Info("XWindowOff at {$:d04}-{$:d02}-{$:d02} {$:d02}:{$:d02}:{$:d02}:{$:d03}", m_stImgCreateTime.wYear, m_stImgCreateTime.wMonth, m_stImgCreateTime.wDay, m_stImgCreateTime.wHour, m_stImgCreateTime.wMinute, m_stImgCreateTime.wSecond, m_stImgCreateTime.wMilliseconds); //if (SYNC_SOFTWARE == m_eSyncMode || SYNC_AED == m_eSyncMode) //探测器的关窗是模拟计算的,所以非软同步模式也没必要发送了 //{ m_SyncUnit->XWindowOffNotify(); //} } else if (PANEL_START_ACQ == nParam1) { Info("EVT_STATUS_PANEL PANEL_START_ACQ"); m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_ACQ)); } break; } case EVT_STATUS_CALIBRATIOIN: { Info("EVT_STATUS_PANEL EVT_STATUS_CALIBRATIOIN"); ENUM_PANEL_EVENT_STATE eStatus = (ENUM_PANEL_EVENT_STATE)nParam1; switch (eStatus) { case PANEL_EVENT_START: break; case PANEL_EVENT_END_OK: case PANEL_EVENT_END_ERROR: m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY)); m_CalibUnit->SetCalibrationStatus(to_string(CCOS_CALIBRATION_STATUS_STANDBY)); m_CalibUnit->SetCalibrationProgress(to_string(100));//make progress break; case PANEL_EVENT_TIMEOUT: break; default: break; } break; } case EVT_STATUS_SINGLEEXP: { Info("EVT_STATUS_PANEL EVT_STATUS_SINGLEEXP"); if (DOSE_ACCEPT == nParam1) { Info("Calibration Result is acceptable"); m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY)); m_CalibUnit->PauseCalibration(); } else { Error("Not support this param({$})", nParam1); } break; } case EVT_STATUS_TEMPERATURE: { Info("EVT_STATUS_PANEL EVT_STATUS_TEMPERATURE"); float fTemperature = fParam2; // if (fTemperature > m_fTemperMaxLimit) // { // AddErrMsg("14", "temperature_toohigh"); // } // else if (fTemperature >= m_fTemperWarning) // { // AddWarnMsg("14", "temperature_high"); // } // else if (fTemperature < m_fTemperMinLimit) // { // AddErrMsg("14", "temperature_toolow"); // } // else if (fTemperature <= m_fTemperLowLimit) // { // AddWarnMsg("14", "temperature_low"); // } // else // { // DelErrMsg("14"); // } SendTemperatureValue(fTemperature); break; } case EVT_STATUS_WIFI: { Info("EVT_STATUS_PANEL EVT_STATUS_WIFI"); int nWifiLevel = nParam1; // if (nWifiLevel < m_nWifiLimit) // { // AddErrMsg("15", "wifi_toolow"); // } // else if (nWifiLevel <= m_nWifiWarning) // { // AddWarnMsg("15", "wifi_low"); // } // else // { // DelErrMsg("15"); // } SendWifiValue(nWifiLevel); break; } case EVT_STATUS_BATTERY_VALUE: { Info("EVT_STATUS_PANEL EVT_STATUS_BATTERY_VALUE"); int nBatteryValue = nParam1; // if (nBatteryValue < m_nBatteryLimit) // { // AddErrMsg("16", "battery_toolow"); // } // else if (nBatteryValue <= m_nBatteryWarning) // { // AddWarnMsg("16", "battery_low"); // } // else // { // DelErrMsg("16"); // } SendBatteryValue(nBatteryValue); break; } default: Error("Not support this event({$})", nEventID); break; } } void nsFPD::FPDDeviceCareRay::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: { Info("EVT_DATA_RAW_IMAGE"); memcpy(m_pFullImgBuffer, pParam, (size_t)m_nFullImageWidth * (size_t)m_nFullImageHeight * sizeof(WORD)); //某些值暂时先用假值,有需要再改 ResDataObject objImageHead, objTemp; objTemp.add(SM_IMAGE_TYPE, (int)IMAGE_FULL); objTemp.add(SM_IMAGE_BIT, m_nImgBits); objTemp.add(SM_IMAGE_TAG, 1); objTemp.add(SM_IMAGE_INDEX, 1); objTemp.add(SM_IMAGE_YEAR, m_stImgCreateTime.wYear); objTemp.add(SM_IMAGE_MONTH, m_stImgCreateTime.wMonth); objTemp.add(SM_IMAGE_DAY, m_stImgCreateTime.wDay); objTemp.add(SM_IMAGE_HOUR, m_stImgCreateTime.wHour); objTemp.add(SM_IMAGE_MINUTE, m_stImgCreateTime.wMinute); objTemp.add(SM_IMAGE_SEC, m_stImgCreateTime.wSecond); objTemp.add(SM_IMAGE_MILLSEC, m_stImgCreateTime.wMilliseconds); objTemp.add(SM_IMAGE_LSB, "5000"); objTemp.add(SM_IMAGE_DOSE, m_nSensitivity); objTemp.add(SM_IMAGE_PIXELSPACING, m_nPixelSpacing); objTemp.add(SM_IMAGE_PIXELREPRESENTATION, "1"); objTemp.add(SM_IMAGE_FLIP, "No"); objTemp.add(SM_IMAGE_ORIGINX, "0"); objTemp.add(SM_IMAGE_ORIGINY, "0"); objTemp.add(SM_IMAGE_EXI2UGY, m_fFactorEXI2UGY); if (0 != m_nAngle) { m_AcqUnit->RotateImage(m_pFullImgBuffer, m_nFullImageHeight, m_nFullImageWidth, m_nAngle); } if (90 == m_nAngle || 270 == m_nAngle) { objTemp.add(SM_IMAGE_WIDTH, m_nFullImageHeight); objTemp.add(SM_IMAGE_HEIGHT, m_nFullImageWidth); objTemp.add(SM_IMAGE_ROTATION, "Yes"); } else { objTemp.add(SM_IMAGE_WIDTH, m_nFullImageWidth); objTemp.add(SM_IMAGE_HEIGHT, m_nFullImageHeight); objTemp.add(SM_IMAGE_ROTATION, "No"); } objImageHead.add(SM_IMAGE_HEAD, objTemp); Info("Full image head: {$}", objImageHead.encode()); //如果环境中只有探测器,那么这里增加一个推送状态 if (m_bOnlyHaveFpd) { Info("OnProcessImage OnlyHaveFpd Sleep 1s then set fpd standby(4)"); Sleep(1000); m_DetectorCtrlUnit->SetDetectorStatus(to_string(DETECTOR_STATUS_STANDBY)); } m_AcqUnit->AddFrameWithRawHead(IMAGE_FULL, objImageHead.encode(), m_pFullImgBuffer, m_nFullImageWidth * m_nFullImageHeight); Info("Add image over"); printf("Add image over\n"); break; } case EVT_DATA_DOSEPARAM: { m_fDoseParam = fParam2; SetEvent(m_WaitCalibDoseEvt); break; } default: Error("Not support this data({$})", nEventID); break; } } void nsFPD::FPDDeviceCareRay::OnEventProcessError(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam) { switch (nEventID) { case EVT_ERR_COMMUNICATE: //{ // string strTemp = pszMsg; // if (strTemp.find("true") != std::string::npos) // { // AddErrMsg("0", "communication error"); // SendTemperatureValue(0); // SendWifiValue(0); // SendBatteryValue(0); // } // else if (strTemp.find("false") != std::string::npos) // { // DelErrMsg("0"); // } //} break; case EVT_ERR_INIT_FAILED: //{ // string strTemp = pszMsg; // if (strTemp.find("true") != std::string::npos) // { // AddErrMsg("6", "initialize error"); // } // else if (strTemp.find("false") != std::string::npos) // { // //一般不可恢复 // } //} break; default: Error("Not support this error({$})", nEventID); break; } } void nsFPD::FPDDeviceCareRay::OnEventProcessWarning(int nDetectorID, int nEventID, int nEventLevel, const char* pszMsg, int nParam1, float fParam2, int nPtrParamLen, void* pParam) { Error("Not support this warn({$})", nEventID); }