#pragma once #include "DPC.h" #include "LogicDevice.h" #define LOGICDRIVER_API #define LOGICDRIVER_C_API extern "C" class SubDeviceDescriptList : public BaseJsonDataObject { public: vector m_DeviceList; SubDeviceDescriptList() { SetKey("DeviceList"); }; ~SubDeviceDescriptList() { }; ResDataObject GetResVal() { ResDataObject Sub; try { m_ValString = ""; for (size_t i = 0; i < m_DeviceList.size(); i++) { Sub.add(m_DeviceList[i].c_str(), ""); } } catch (...) { Sub.clear(); } return Sub; }; void GetResDataObject(ResDataObject &obj) { try { ResDataObject Sub; for (size_t i = 0; i < m_DeviceList.size(); i++) { Sub.add(m_DeviceList[i].c_str(), ""); } obj.add(GetKey(), Sub); } catch (...) { } }; bool SetResDataObject(ResDataObject &obj) { bool ret = true; try { // mainkey // subkey1 "" // subkey2 "" // subkey3 "" assert(0);//suppose not using this method } catch (...) { ret = false; } return ret; }; bool AddDevice(const char *pPath) { bool ret = true; try { string path = pPath; for (size_t i = 0; i < m_DeviceList.size(); i++) { if (m_DeviceList[i] == path) { return false; } } m_DeviceList.push_back(path); } catch (...) { ret = false; } return ret; }; bool DelDevice(const char *pPath) { bool ret = false; //key is the path string path = pPath; vector::iterator iter = m_DeviceList.begin(); while (iter != m_DeviceList.end()) { if (*iter == path) { iter = m_DeviceList.erase(iter); ret = true; continue; } ++iter; } return ret; }; }; //单个CONNECTION相关的属性 //Title //type : TCPIP //port : 1234 //ipaddress : 192.168.2.1 //comment : ...... //Title //type : COM //port : COM4 //baudrate : 115200 //bytesize : 8 //parity : 0 //stopbits : 8 //comment : ...... // 此类是从 LogicDriver.dll 导出的 class LOGICDRIVER_API LogicDriver : public DriverDPC,public LogicDevice { protected: ResDataObject m_SerialNo; //设备属性 //XML文件参数 ResDataObject *m_pConfigFile;//不对外公开,内部对象之间共享 //连接状态 BaseJsonDataObject *m_pConnectionStatus; //断线重连Flag,断线重连TimePeriod BaseJsonDataObject *m_pReConnectFlag; BaseJsonDataObject *m_pReConnectTimePeriod; BaseJsonDataObject *m_pHeartBeatTimePeriod; DWORD m_ReConnectLastTryTime; BaseJsonDataObject *m_pSelfTestResult; //connections //Example //Connections //Seq //type : TCPIP //port : 1234 //ipaddress : 192.168.2.1 //comment : Sequance con //Acq //type : TCPIP //port : 1236 //ipaddress : 192.168.2.1 //comment : Used to Acquire Images ResDataObject *m_pConnections; //子【逻辑设备】列表 SubDeviceDescriptList *m_pSubDeviceList; public: std::shared_ptr m_DisConnectionStatusEvt; LogicDriver(void); ~LogicDriver(void); virtual void OnSetClientID() override; virtual void SubscribeSelf() override; //所有子类必须使用 SubscribeTopic 订阅自身topic及资源topic,如果不知道需要DPC代订阅 //内部接口 std::shared_ptr SYSTEM_CALL GetPassiveDisConnectEvtHandle(); void SYSTEM_CALL ReSetPassiveDisConnect(bool DisConnect); void SYSTEM_CALL GetConfiguration(ResDataObject *pConfig); virtual bool SYSTEM_CALL Driver_Probe(ResDataObject& PARAM_OUT DriverInfo); bool SYSTEM_CALL AddDevice(const char *pPath); bool SYSTEM_CALL DelDevice(const char *pPath); void SYSTEM_CALL GetDeviceList(ResDataObject &Object); DWORD SYSTEM_CALL GetLastDisconnectTime(); void SYSTEM_CALL SetLastDisconnectTime(DWORD LastTick); //逻辑设备接口 //get device type virtual bool SYSTEM_CALL GetDeviceType(GUID &DevType); //get device resource virtual RET_STATUS SYSTEM_CALL GetDeviceResource(ResDataObject PARAM_OUT *pDeviceResource); virtual RET_STATUS DATA_ACTION GetDeviceConfig(ResDataObject PARAM_OUT *pDeviceConfig); virtual RET_STATUS DATA_ACTION SetDeviceConfig(ResDataObject PARAM_IN *DeviceConfig); virtual RET_STATUS SYSTEM_CALL GetSEQResource(ResDataObject PARAM_OUT *pDeviceResource); //ResourceCommand Request In and Response Out virtual RET_STATUS SYSTEM_CALL Request(ResDataObject PARAM_IN *pRequest, ResDataObject PARAM_OUT *pResponse); //notify to lower layer virtual RET_STATUS SYSTEM_CALL CmdToLogicDev(ResDataObject PARAM_IN *pCmd); //设备行为 //Connect(OEM必须实现) //DisConnect(OEM必须实现) RET_STATUS DATA_ACTION SetHeartBeatTimePeriod(DWORD TimePeriod); RET_STATUS DATA_ACTION SetReConnectOption(bool Flag, DWORD TimePeriod); RET_STATUS DATA_ACTION GetReConnectOption(bool &Flag, DWORD &TimePeriod); virtual bool SYSTEM_CALL GetConnectionStatus(); ResDataObject& SYSTEM_CALL GetConnectionParam(); RET_STATUS DATA_ACTION GetHeartBeatTimePeriod(DWORD &TimePeriod); RET_STATUS DATA_ACTION SetConnectionParam(const char *pTitle, ResDataObject &ConnectionContext); virtual bool DATA_ACTION Connect(); virtual void DATA_ACTION DisConnect(); virtual RET_STATUS DATA_ACTION SelfTest(); //对象接口 virtual bool SYSTEM_CALL DriverEntry(ResDataObject& PARAM_IN Configuration); //Driver_Probe(OEM实现) //SetDriverWorkPath(OEM实现) //LoadDriver(OEM必须实现) //UnloadDriver(OEM必须实现) //Device_Probe(OEM必须实现) //SetDeviceWorkPath(OEM必须实现) //LoadLogicDevices(OEM必须实现) //UnloadLogicDevices(OEM必须实现) //OnNotify(OEM必须实现) //CALLIN 时机-------------------- //由驱动线程进行CALL IN. //Timeperiod 是 ReConnect用的时间 //函数实现内容------------------- // 计算当前->最后交互时间(R/W) timeperiod // 获取配置文件中的HeartBeat timeperiod // 一旦超时,进行一次 Req -> Res 的交互. // Ex:特定状态下,不允许进行交互,这个由DPC自行判断. // 一旦确认掉线,设置掉线事件,并返回即可. virtual bool SYSTEM_CALL OnHeartBeat(); const char* SYSTEM_CALL GetDpcsSerialNo(); void SYSTEM_CALL SetDpcsIdentifyKey(const char *pszSerialkey); };