123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- #pragma once
- #include "DPC.h"
- #include "LogicDevice.h"
- #define LOGICDRIVER_API
- #define LOGICDRIVER_C_API extern "C"
- class SubDeviceDescriptList : public BaseJsonDataObject<bool>
- {
- public:
- vector<string> 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<string>::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<bool> *m_pConnectionStatus;
- //断线重连Flag,断线重连TimePeriod
- BaseJsonDataObject<bool> *m_pReConnectFlag;
- BaseJsonDataObject<DWORD> *m_pReConnectTimePeriod;
- BaseJsonDataObject<DWORD> *m_pHeartBeatTimePeriod;
- DWORD m_ReConnectLastTryTime;
- BaseJsonDataObject<DWORD> *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<LinuxEvent> m_DisConnectionStatusEvt;
- LogicDriver(void);
- ~LogicDriver(void);
- virtual void OnSetClientID() override;
- virtual void SubscribeSelf() override; //所有子类必须使用 SubscribeTopic 订阅自身topic及资源topic,如果不知道需要DPC代订阅
- //内部接口
- std::shared_ptr<LinuxEvent> 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);
- };
|