#include "stdafx.h" #include #include "All.h" #include "MACHINE_DPC.h" #include "MACHINE_Logical.h" #include "MACHINE_MammoLogic.h" #include "MACHINE_StitchLogic.h" #include "PacketAnalizer.h" #include "common_api.h" #ifdef CMD_ANSYNC #include "RingBuffer.h" #endif #define MACHINERY_TID "DetectorToTableDistance" #define MACHINERY_SID "DistanceSourcetoDetector" #define MACHINERY_ENTRANCE "DistanceSourcetoEntrance" #define MACHINERY_GEOMETRY "GeometryKeyword" #define MACHINERY_PROJECTIONNUM "ProjectionNum" #define MACHINERY_MAXANGLE "ProjectionMaxAngle" #define MACHINERY_DIRECTION "ProjectionDirection" int FormatCMD(char * pCmd, int nSize) { pCmd[nSize] = 0x0d; nSize++; pCmd[nSize] = 0x0a; nSize++; pCmd[nSize] = 0; return nSize; } ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// #define FUNNAME_CREATE_SCF TEXT("GetSCF") #define FUNNAME_RELEASE_SCF TEXT("ReleseSCF") #define OFFSET_CLASSNAME_DOSE 14 #define OFFSET_CLASSNAME_DOSE_SP 22 #define OFFSET_CLASSNAME_LOGIC 17 #define OFFSET_CLASSNAME_LOGIC_SP 25 #define CMD_LEN_MAX 128 #define TIMEOUTVALUE 1000 CMACHINE_DPC::CMACHINE_DPC() { m_pWorkpath = new std::string(); m_pNotify = NULL; m_hConnectFinish = CreateEvent(NULL, true, false, NULL); m_hBeginConnect = CreateEvent(NULL, true, false, NULL); m_hConnection = CreateEvent(NULL, true, false, NULL); m_hMechReady = CreateEvent(NULL, false, false, NULL); m_hMechGetPostionFinished = CreateEvent(NULL, false, false, NULL); m_DetectorToTableDistance.add(MACHINERY_TID, (FLOAT)0.0); m_DistanceSourcetoDetector.add(MACHINERY_SID, (FLOAT)1.0); m_DistanceSourcetoEntrance.add(MACHINERY_ENTRANCE, (FLOAT)15.0); m_GEOMETRY.add(MACHINERY_GEOMETRY, "liner"); m_ProjectionNum.add(MACHINERY_PROJECTIONNUM, (INT)15); m_ProjectionMaxAngle.add(MACHINERY_MAXANGLE, (FLOAT)15.0); m_ProjectionDirection.add(MACHINERY_DIRECTION, (INT)-1); m_pGenVender = new ConfigInfo("Vender"); m_pGenModel = new ConfigInfo("Model"); m_pGenSyncType = new ConfigInfo(DiosSyncType); m_pGenSCFType = new ConfigInfo(DiosSCFType); m_pGenSCFPort = new ConfigInfo(DiosSCFPort); m_pTID = new ConfigInfo(MACHINERY_TID); m_pSID = new ConfigInfo(MACHINERY_SID); m_pENTRANCE = new ConfigInfo(MACHINERY_ENTRANCE); m_pGEOMETRY = new ConfigInfo(MACHINERY_GEOMETRY); } CMACHINE_DPC::~CMACHINE_DPC() { delete m_pWorkpath; delete m_pGenVender; delete m_pGenModel; delete m_pGenSyncType; delete m_pGenSCFType; delete m_pGenSCFPort; delete m_pTID; delete m_pSID; delete m_pENTRANCE; delete m_pGEOMETRY; } //bool CMACHINE_DPC::DpcEntry(ResDataObject &Configuration) //{ // try // { // m_DeviceConfig = Configuration; // } // catch (...) // { // PRINTA_INFO(m_pLog, "Can't get the Configuration for Device"); // } // PRINTA_INFO(m_pLog, "DpcEntry Configuration"); // // return true; //} // //ResDataObject CMACHINE_DPC::GetConnectionType() //{ // return ResDataObject(); //} // //bool CMACHINE_DPC::Connect(ResDataObject &Connection) //{ // m_pSCFServer = m_fpGetSCF(); // // int Result = m_pSCFServer->Connect(Connection, &CMACHINE_DPC::PackageProcess, SCF_PACKET_TRANSFER); // if (Result != SCF_SUCCEED) // { // return false; // } // // return true; //} // //bool CMACHINE_DPC::Probe(ResDataObject &HardwareInfo) //{ //#ifdef ENV_DIOS // HardwareInfo.add("MajorID", "Generator"); // HardwareInfo.add("MinorID", "DR"); // HardwareInfo.add("VendorID", "CPI"); // HardwareInfo.add("ProductID", "SHF"); // HardwareInfo.add("SerialID", "1234"); //#endif // return true; //} // //bool CMACHINE_DPC::SetWorkPath(const char *pWorkPath) //{ // m_strWorkPath = pWorkPath; // return true; //} // //PVOID CMACHINE_DPC::LoadLogicDevices() //{ // DevTree *pTree = new DevTree(); // LogicDevice * pLD = NULL; // // //Load DOSE Logic unit // m_pGenDose = new CMACHINE_Dose(); // m_pGenDose->DPCPoint(this); // pLD = (LogicDevice *)m_pGenDose; // pTree->Add((PVOID)pLD, TYPE_DEVICE); // // //Load SyncGen // m_pGenLogical = new CMACHINE_Logical(); // m_pGenLogical->DPCPoint(this); // pLD = (LogicDevice *)m_pGenLogical; // pTree->Add((PVOID)pLD, TYPE_DEVICE); // //#if 0 // try{ // m_pGenDose->m_DeviceConfig.nTable = (int)(m_DeviceConfig["Table"]); // m_pGenDose->m_DeviceConfig.nWall = (int)(m_DeviceConfig["Wall"]); // m_pGenDose->m_DeviceConfig.nFree = (int)(m_DeviceConfig["Free"]); // m_pGenDose->m_DeviceConfig.nTomo = (int)(m_DeviceConfig["Tomo"]); // m_pGenDose->m_DeviceConfig.nConventional = (int)(m_DeviceConfig["Conventional"]); // } // catch (...) // { // printf("Get Gen config item Crash.\n"); // } //#endif // return (PVOID)pTree; //} // //void CMACHINE_DPC::UnloadLogicDevices(/*LogicDevice*/PVOID p) //{ //#ifdef ENV_DIOS // DevTree *pTree = (DevTree*)p; // size_t Size = pTree->size(); // for (size_t i = 0; i < Size; i++) // { // DevTreeNode node = (*pTree)[i]; // if (node.m_NodeType == TYPE_DEVICE) // { // LogicDevice *pdev = (LogicDevice*)node.m_pObject; // delete pdev; // } // else // { // //tree dev // //do not copy this!!!! // UnloadLogicDevices(node.m_pObject); // } // } // // delete pTree; //#endif //} // //bool CMACHINE_DPC::DisConnect() //{ // m_pSCFServer->Disconnect(); // m_fpReleaseSCF(m_pSCFServer); // return true; //} // //bool CMACHINE_DPC::OnNotify(HANDLE ExitNotify) //{ // Work(); // return true; //} bool CMACHINE_DPC::DriverEntry(ResDataObject &Configuration) { try { m_DeviceConfig = Configuration; } catch (...) { PRINTA_INFO(m_pLog, "Can't get the Configuration for Device"); } PRINTA_INFO(m_pLog, "DpcEntry Configuration"); return LogicDriver::DriverEntry(Configuration); } bool CMACHINE_DPC::Driver_Probe(ResDataObject &HardwareInfo) { ResDataObject Config; GetConfiguration(&Config); HardwareInfo.add("MajorID", (const char*)Config["MajorID"]); HardwareInfo.add("MinorID", (const char*)Config["MinorID"]); HardwareInfo.add("VendorID", (const char*)Config["VendorID"]); HardwareInfo.add("ProductID", (const char*)Config["ProductID"]); HardwareInfo.add("SerialID", (const char*)Config["SerialID"]); return true; } bool SYSTEM_CALL CMACHINE_DPC::SetDriverWorkPath(const char * PARAM_IN pWorkPath) { return true; } PVOID SYSTEM_CALL CMACHINE_DPC::LoadDriver() { return NULL; } void SYSTEM_CALL CMACHINE_DPC::UnloadDriver() { } bool CMACHINE_DPC::Connect() { LogicDriver::Connect(); return true; } bool CMACHINE_DPC::Device_Probe(ResDataObject &HardwareInfo) { ResDataObject Config; GetConfiguration(&Config); HardwareInfo.add("MajorID", (const char*)Config["MajorID"]); HardwareInfo.add("MinorID", (const char*)Config["MinorID"]); HardwareInfo.add("VendorID", (const char*)Config["VendorID"]); HardwareInfo.add("ProductID", (const char*)Config["ProductID"]); HardwareInfo.add("SerialID", "1234"); return true; } bool CMACHINE_DPC::SetDeviceWorkPath(const char *pWorkPath) { (*m_pWorkpath) = pWorkPath; //要把读取单一硬件属性的过程放到此处 return true; } PVOID CMACHINE_DPC::LoadLogicDevices() { DevTree *pTree = (DevTree *)GetDeviceTree(); if ((string)m_DeviceConfig["MechType"] == "0") { m_pGenLogical = new CMACHINE_Logical(); m_pGenLogical->DPCPoint(this); LogicDevice *pret = (LogicDevice *)m_pGenLogical; pTree->Add((PVOID)pret, TYPE_DEVICE); m_pGenLogical->NotifyMachineryReadyState(true); } else if ((string)m_DeviceConfig["MechType"] == "1") { CMACHINE_StitchLogic *pGenLogical = new CMACHINE_StitchLogic(); pGenLogical->DPCPoint(this); LogicDevice *pret = (LogicDevice *)pGenLogical; pTree->Add((PVOID)pret, TYPE_DEVICE); } else { CMACHINE_MammoLogic *pGenLogical = new CMACHINE_MammoLogic(); pGenLogical->DPCPoint(this); LogicDevice *pret = (LogicDevice *)pGenLogical; pTree->Add((PVOID)pret, TYPE_DEVICE); } return (PVOID)pTree; } void CMACHINE_DPC::UnloadLogicDevices() { DevTree *pTree = (DevTree *)GetDeviceTree(); size_t Size = pTree->size(); for (size_t i = 0; i < Size; i++) { DevTreeNode node = (*pTree)[i]; if (node.m_NodeType == TYPE_DEVICE) { LogicDevice *pdev = (LogicDevice*)node.m_pObject; delete pdev; } else { //tree dev //do not copy this!!!! //UnloadLogicDevices(node.m_pObject); } } pTree->clear(); PRINTA_INFO(m_pLog, "UnLoad Over"); } void CMACHINE_DPC::DisConnect() { LogicDriver::DisConnect(); } bool SYSTEM_CALL CMACHINE_DPC::OnHeartBeat() { return true; } void MakeComList(int TotalIdx, string &Result) { Result = ""; ResDataObject Res; for (int i = 0; i < TotalIdx; i++) { string key = FormatstdString("%d", i); string Context = FormatstdString("COM%d", i + 1); Res.add(key.c_str(), Context.c_str()); } Result = Res.encode(); } RET_STATUS SYSTEM_CALL CMACHINE_DPC::GetDeviceResource(ResDataObject PARAM_OUT *pDeviceResource) { RET_STATUS rs = LogicDriver::GetDeviceResource(pDeviceResource); bool ret = true; ResDataObject val = (*pDeviceResource)["Attribute"]; //val.add(MACHINERY_READY, m_MachineryReady[MACHINERY_READY]); val.add(MACHINERY_TID, m_DetectorToTableDistance[MACHINERY_TID]); val.add(MACHINERY_SID, m_DistanceSourcetoDetector[MACHINERY_SID]); val.add(MACHINERY_ENTRANCE, m_DistanceSourcetoEntrance[MACHINERY_ENTRANCE]); val.add(MACHINERY_GEOMETRY, m_GEOMETRY[MACHINERY_GEOMETRY]); val.add(MACHINERY_PROJECTIONNUM, m_ProjectionNum[MACHINERY_PROJECTIONNUM]); val.add(MACHINERY_MAXANGLE, m_ProjectionMaxAngle[MACHINERY_MAXANGLE]); val.add(MACHINERY_DIRECTION, m_ProjectionDirection[MACHINERY_DIRECTION]); string ComList; ResDataObject DeviceConfig; m_pGenVender->SetCurrentValue("ECOM"); m_pGenVender->SetType("string"); m_pGenVender->SetAccessReadOnly(); m_pGenVender->SetRequired(true); m_pGenModel->SetCurrentValue("MACHINE"); m_pGenModel->SetType("string"); m_pGenModel->SetAccessReadOnly(); m_pGenModel->SetRequired(true); m_pGenSCFType->SetCurrentValue("COM"); m_pGenSCFType->SetType("string"); m_pGenSCFType->SetAccessReadOnly(); m_pGenSCFType->SetRequired(true); m_pGenSCFPort->SetCurrentValue(""); m_pGenSCFPort->SetType("string"); m_pGenSCFPort->SetAccessReadWrite(); MakeComList(12, ComList); m_pGenSCFPort->SetList(ComList.c_str()); //m_pGenSCFPort->SetList("COM1;COM2;COM3;COM4;COM5;COM6;COM7;COM8;COM9;COM10;COM11;COM12"); m_pGenSCFPort->SetRequired(true); m_pTID->SetCurrentValue("20"); m_pTID->SetType("int"); m_pTID->SetAccessReadWrite(); m_pTID->SetRequired(true); m_pSID->SetCurrentValue("1000"); m_pSID->SetType("int"); m_pSID->SetAccessReadWrite(); m_pSID->SetRequired(true); m_pENTRANCE->SetCurrentValue("1000"); m_pENTRANCE->SetType("int"); m_pENTRANCE->SetAccessReadWrite(); m_pENTRANCE->SetRequired(true); m_pGEOMETRY->SetCurrentValue("liner"); m_pGEOMETRY->SetType("string"); m_pGEOMETRY->SetAccessReadWrite(); ResDataObject resList; resList.add("0", "liner"); resList.add("1", "arc"); m_pGEOMETRY->SetList(resList.encode()); m_pGEOMETRY->SetRequired(true); GetDeviceConfig(&DeviceConfig); val.add(DeviceConfig.GetKey(0), DeviceConfig[0]); ret &= pDeviceResource->update("Attribute", val); PRINTA_INFO(m_pLog, pDeviceResource->encode()); if (ret) { return RET_SUCCEED; } return RET_FAILED; } ///////////////////////////////////////////////////////////////////////// int CMACHINE_DPC::CMDSet(const char *pKey, int len) { return 1; } RET_STATUS SYSTEM_CALL CMACHINE_DPC::GetDriverDictionary(ResDataObject& PARAM_OUT DriverInfo) { DriverInfo.add("DriverType", "PositionMachine"); DriverInfo.add("DeviceName", "SiemensTOMO"); DriverInfo.add("DateOfManufacture", "2019.4.12"); DriverInfo.add("SoftwareVersion", "Alpha1.0"); DriverInfo.add("HardwareVersion", "Alpha1.0"); DriverInfo.add("Description", "None"); DriverInfo.add("Properties", "None"); return RET_SUCCEED; } bool CMACHINE_DPC::SendDate(void) { return true; } bool CMACHINE_DPC::SendTomoExam(void) { return true; } bool CMACHINE_DPC::StartMove(bool state) { return true; } bool CMACHINE_DPC::ClearMoveState() { return true; } bool CMACHINE_DPC::SendIXRAY(void) { return true; } bool CMACHINE_DPC::MechMoveReady() { return true; } bool CMACHINE_DPC::SetPositionNum(const char* code) { return true; } void OEM_IF CMACHINE_DPC::NotifyTomoParams(FLOAT fSID, FLOAT fTID, FLOAT fMaxAngle, int nDirection, int nProjectionNumber) { //距离单位为mm m_DetectorToTableDistance[MACHINERY_TID] = fTID; m_DistanceSourcetoDetector[MACHINERY_SID] = fSID; m_ProjectionMaxAngle[MACHINERY_MAXANGLE] = fMaxAngle; m_ProjectionNum[MACHINERY_PROJECTIONNUM] = nProjectionNumber; m_ProjectionDirection[MACHINERY_DIRECTION] = nDirection; ResDataObject NotifyData; PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, MACHINERY_TID, (const char *)m_DetectorToTableDistance[MACHINERY_TID]); CmdFromLogicDev(&NotifyData); PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, MACHINERY_SID, (const char *)m_DistanceSourcetoDetector[MACHINERY_SID]); CmdFromLogicDev(&NotifyData); PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, MACHINERY_MAXANGLE, (const char *)m_ProjectionMaxAngle[MACHINERY_MAXANGLE]); CmdFromLogicDev(&NotifyData); PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, MACHINERY_PROJECTIONNUM, (const char *)m_ProjectionNum[MACHINERY_PROJECTIONNUM]); CmdFromLogicDev(&NotifyData); PacketAnalizer::MakeNotify(NotifyData, PACKET_CMD_UPDATE, MACHINERY_DIRECTION, (const char *)m_ProjectionDirection[MACHINERY_DIRECTION]); CmdFromLogicDev(&NotifyData); } bool CMACHINE_DPC::MechGetPosReady() { return true; } bool CMACHINE_DPC::GetPosition(ResDataObject &resangle, ResDataObject &resheight) { resangle = m_MechAngle; resheight = m_MechHeight; return true; } RET_STATUS CMACHINE_DPC::SetDeviceConfig(ResDataObject PARAM_IN *DeviceConfig) { string strKey; printf("\n SetDeviceConfig before : %s\n", DeviceConfig->encode()); ResDataObject &ConfigContext = (*DeviceConfig)[0][0]; for (int i = 0; i < ConfigContext.size(); i++) { strKey = ConfigContext.GetKey(i); printf("\n Key : %s, Value : %s\n", strKey.c_str(), ((string)(ConfigContext)[i]).c_str()); if (strKey == (string)m_pGenSCFPort->GetKey(0)) { m_DeviceConfig["connections"][0][DiosSCFPort] = (ConfigContext)[i]; m_pGenSCFPort->SetCurrentValue((ConfigContext)[i]); } else if (strKey == MACHINERY_TID) { m_DetectorToTableDistance[MACHINERY_TID] = (ConfigContext)[i]; m_DeviceConfig.update(MACHINERY_TID, (ConfigContext)[i]); m_pTID->SetCurrentValue(((string)ConfigContext[i]).c_str()); } else if (strKey == MACHINERY_SID) { m_DistanceSourcetoDetector[MACHINERY_SID] = (ConfigContext)[i]; m_DeviceConfig.update(MACHINERY_SID, (ConfigContext)[i]); m_pSID->SetCurrentValue(((string)ConfigContext[i]).c_str()); } else if (strKey == MACHINERY_ENTRANCE) { m_DistanceSourcetoEntrance[MACHINERY_ENTRANCE] = (ConfigContext)[i]; m_DeviceConfig.update(MACHINERY_ENTRANCE, (ConfigContext)[i]); m_pENTRANCE->SetCurrentValue(((string)ConfigContext[i]).c_str()); } else if (strKey == MACHINERY_GEOMETRY) { m_GEOMETRY[MACHINERY_GEOMETRY] = (ConfigContext)[i]; m_DeviceConfig.update(MACHINERY_GEOMETRY, (ConfigContext)[i]); m_pGEOMETRY->SetCurrentValue(((string)ConfigContext[i]).c_str()); } } printf("\n m_DeviceConfig after : %s\n", m_DeviceConfig.encode()); ResDataObject config, writecontent; LogicDriver::GetConfiguration(&config); string configpath = GetDriverConfigFilePath(); writecontent.add("CONFIGURATION", m_DeviceConfig); writecontent.SaveFile(configpath.c_str()); LogicDriver::SetDeviceConfig(&ConfigContext); return RET_SUCCEED; } RET_STATUS CMACHINE_DPC::GetDeviceConfig(ResDataObject PARAM_OUT *pDeviceConfig) { if (m_DeviceConfig.size() > 0) { printf("\n m_DeviceConfig: %s \n", m_DeviceConfig.encode()); m_pGenSCFType->SetCurrentValue(((string)m_DeviceConfig["connections"][0]["type"]).c_str()); m_pGenSCFPort->SetCurrentValue(((string)m_DeviceConfig["connections"][0][DiosSCFPort]).c_str()); for (int i = 0; i < m_DeviceConfig.size(); i++) { if ((string)m_DeviceConfig.GetKey(i) == MACHINERY_TID) { m_pTID->SetCurrentValue(((string)m_DeviceConfig[i]).c_str()); } else if ((string)m_DeviceConfig.GetKey(i) == MACHINERY_SID) { m_pSID->SetCurrentValue(((string)m_DeviceConfig[i]).c_str()); } else if ((string)m_DeviceConfig.GetKey(i) == MACHINERY_ENTRANCE) { m_pENTRANCE->SetCurrentValue(((string)m_DeviceConfig[i]).c_str()); } else if ((string)m_DeviceConfig.GetKey(i) == MACHINERY_GEOMETRY) { m_pGEOMETRY->SetCurrentValue(((string)m_DeviceConfig[i]).c_str()); } } } ResDataObject temp, DeviceConfig; temp.add(m_pGenVender->GetKey(0), m_pGenVender->GetCurrentValue()); temp.add(m_pGenModel->GetKey(0), m_pGenModel->GetCurrentValue()); temp.add(m_pGenSCFType->GetKey(0), m_pGenSCFType->GetCurrentValue()); temp.add(m_pGenSCFPort->GetKey(0), m_pGenSCFPort->GetCurrentValue()); temp.add(m_pTID->GetKey(0), m_pTID->GetCurrentValue()); temp.add(m_pSID->GetKey(0), m_pSID->GetCurrentValue()); temp.add(m_pENTRANCE->GetKey(0), m_pENTRANCE->GetCurrentValue()); temp.add(m_pGEOMETRY->GetKey(0), m_pGEOMETRY->GetCurrentValue()); DeviceConfig.update("Attribute", temp); ResDataObject resdescription; resdescription += *m_pGenVender; resdescription += *m_pGenModel; resdescription += *m_pGenSCFType; resdescription += *m_pGenSCFPort; resdescription += *m_pTID; resdescription += *m_pSID; resdescription += *m_pENTRANCE; resdescription += *m_pGEOMETRY; DeviceConfig.update("Description", resdescription); pDeviceConfig->add("DeviceConfig", DeviceConfig); //(*pDeviceConfig) = DeviceConfig; LogicDriver::GetDeviceConfig(pDeviceConfig); return RET_SUCCEED; }