| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- /*
- * Device.h
- *
- * Created on: 2016年11月10日
- * Author: Mr_zhu
- * Content:
- */
-
- #ifndef SERVICEMODEL_DEVICE_H_
- #define SERVICEMODEL_DEVICE_H_
-
- #include <string>
- #include <vector>
-
- #include "../common/Type.h"
- #include "../externservice/HardwareI.h"
- #include "../externservice/ParaAnalysisI.h"
- #include "../externservice/ProtocolI.h"
- #include "../externservice/SubContractI.h"
- #include "Base.h"
- #include "Item.h"
- #include "Packet.h"
-
- struct HardwareI;
- struct ParaAnalysisI;
- struct ProtocolI;
-
- struct SubContractI;
-
- struct IHardware;
-
- struct IParaAnalysis;
- struct IProtocol;
-
- class Channel;
-
- class Device {
- public:
- Device() :
- m_pptcl(NULL), m_hwtype(-1), m_hwnumber(-1), m_phw(NULL), m_ppara(
- NULL), m_psubctact(
- NULL), m_enable(1), m_datimer(100), m_datimeout(1000), m_dafaulttime(
- 3000), m_readretrycount(0), m_writeretrycount(3), m_faultcount(
- 3), m_parent(NULL) {
-
- }
- virtual ~Device() {
- // if (m_pptcl != NULL) {
- // delete m_pptcl;
- // m_pptcl = NULL;
- // }
- // if (m_phw != NULL) {
- // delete m_phw;
- // m_phw = NULL;
- // }
- // if (m_ppara != NULL) {
- // delete m_ppara;
- // m_ppara = NULL;
- // }
- // if (m_psubctact != NULL) {
- // delete m_psubctact;
- // m_psubctact = NULL;
- // }
- }
-
- Base& getBase() {
- return m_base;
- }
-
- void setBase(const Base& base) {
- this->m_base = base;
- }
-
- int getEnable() const {
- return m_enable;
- }
-
- void setEnable(int enable) {
- m_enable = enable;
- }
-
- CLSID& getHwguid() {
- return m_hwguid;
- }
-
- void setHwguid(const CLSID& hwguid) {
- m_hwguid = hwguid;
- }
-
- std::string& getHwname() {
- return m_hwname;
- }
-
- void setHwname(const std::string& hwname) {
- if (!hwname.empty()) {
- m_hwname = hwname;
- }
- }
-
- int getHwnumber() const {
- return m_hwnumber;
- }
-
- void setHwnumber(int hwnumber) {
- m_hwnumber = hwnumber;
- }
-
- int getHwtype() const {
- return m_hwtype;
- }
-
- void setHwtype(int hwtype) {
- m_hwtype = hwtype;
- }
-
- std::string& getItemtable() {
- return m_itemtable;
- }
-
- void setItemtable(const std::string& itemtable) {
- if (!itemtable.empty()) {
- m_itemtable = itemtable;
- }
- }
-
- CLSID& getParaanalysisguid() {
- return m_paraanalysisguid;
- }
-
- void setParaanalysisguid(const CLSID& paraanalysisguid) {
- m_paraanalysisguid = paraanalysisguid;
- }
-
- CLSID& getProtocolguid() {
- return m_protocolguid;
- }
-
- void setProtocolguid(const CLSID& protocolguid) {
- m_protocolguid = protocolguid;
- }
-
- const std::string& getProtocolname() const {
- return m_protocolname;
- }
-
- void setProtocolname(const std::string& protocolname) {
- if (!protocolname.empty()) {
- m_protocolname = protocolname;
- }
- }
-
- CLSID& getSubcontractguid() {
- return m_subcontractguid;
- }
-
- void setSubcontractguid(const CLSID& subcontractguid) {
- m_subcontractguid = subcontractguid;
- }
-
- Channel* getParent() {
- return m_parent;
- }
-
- void setParent(Channel* parent) {
- this->m_parent = parent;
- }
-
- HardwareI* getPhw() {
- return m_phw;
- }
-
- void setPhw(HardwareI* phw) {
- this->m_phw = phw;
- }
-
- ParaAnalysisI* getPpara() const {
- return m_ppara;
- }
-
- void setPpara(ParaAnalysisI* ppara) {
- this->m_ppara = ppara;
- }
-
- ProtocolI* getPptcl() {
- return m_pptcl;
- }
-
- void setPptcl(ProtocolI* pptcl) {
- this->m_pptcl = pptcl;
- }
-
- SubContractI* getPsubctact() const {
- return m_psubctact;
- }
-
- void setPsubctact(SubContractI* psubctact) {
- this->m_psubctact = psubctact;
- }
-
- std::vector<Packet* >& getVpacket() {
- return m_vpacket;
- }
-
- void setVpacket(const std::vector<Packet* >& vpacket) {
- this->m_vpacket = vpacket;
- }
-
- std::vector<Item* >& getVitem() {
- return m_vitem;
- }
-
- void setVitem(const std::vector<Item* >& vitem) {
- this->m_vitem = vitem;
- }
-
- HRESULT addItem(Item* item) {
- bool isexist = false;
-
- for (Item*& i : m_vitem) {
- if (i->isEqual(*item)) {
- isexist = true;
- break;
- }
- }
- if (!isexist) {
- m_vitem.push_back(item);
-
- return S_OK;
- }
- return S_FALSE;
- }
-
- HRESULT addPacket(Packet* packet) {
- bool isexist = false;
-
- for (Packet* & p : m_vpacket) {
- if (p->isEqual(*packet)) {
- isexist = true;
- break;
- }
- }
- if (!isexist) {
- m_vpacket.push_back(packet);
- return S_OK;
- }
- return S_FALSE;
- }
-
- ULONG getItemCount() {
- return m_vitem.size();
- }
-
- ULONG getPacketCount() {
- return m_vpacket.size();
- }
-
- public:
- bool isEqual(Device& device) {
-
- if ((isGUIDEqual(this->m_hwguid,((device.getHwguid()))))
- && (this->m_hwname == ((device.getHwname())))
- && (this->m_hwnumber == device.getHwnumber())
- && (this->m_hwtype == device.getHwtype())) {
- return true;
- }
-
- return false;
- }
-
- int getDafaulttime() const {
- return m_dafaulttime;
- }
-
- void setDafaulttime(int dafaulttime) {
- m_dafaulttime = dafaulttime;
- }
-
- int getDatimeout() const {
- return m_datimeout;
- }
-
- void setDatimeout(int datimeout) {
- m_datimeout = datimeout;
- }
-
- int getDatimer() const {
- return m_datimer;
- }
-
- void setDatimer(int datimer) {
- m_datimer = datimer;
- }
-
- int getFaultcount() const {
- return m_faultcount;
- }
-
- void setFaultcount(int faultcount) {
- m_faultcount = faultcount;
- }
-
- int getReadretrycount() const {
- return m_readretrycount;
- }
-
- void setReadretrycount(int readretrycount) {
- m_readretrycount = readretrycount;
- }
-
- int getWriteretrycount() const {
- return m_writeretrycount;
- }
-
- void setWriteretrycount(int writeretrycount) {
- m_writeretrycount = writeretrycount;
- }
-
- void outInfo() {
-
- }
-
- private:
- std::string m_protocolname; //----设备通信协议名称
- CLSID m_protocolguid; //----设备通信协议组件标识符
- ProtocolI* m_pptcl; //----设备通信协议组件句柄
-
- std::string m_hwname; //----设备硬件通道名称
- int m_hwtype; //----设备硬件通道类型
- int m_hwnumber; //----设备硬件通道号
- CLSID m_hwguid; //----设备硬件通道组件标识符
- HardwareI* m_phw; //----设备硬件通道组件句柄
-
- CLSID m_paraanalysisguid; //----设备参数解析组件标识符
- ParaAnalysisI* m_ppara; //----设备参数分析组件句柄
-
- CLSID m_subcontractguid; //----设备分包参数组件标识符
- SubContractI* m_psubctact; //----设备分包组件句柄
-
- std::string m_itemtable; //----设备点表名称
- int m_enable; //----设备使能控制
- int m_datimer; //----采集周期
- int m_datimeout; //----采集超时时间
- int m_dafaulttime; //----采集故障恢复时间
- int m_readretrycount; //----读重试次数
- int m_writeretrycount; //----写重试次数
- int m_faultcount; //----采集故障次数
-
- Base m_base; //----公共参数
-
- std::vector<Packet* > m_vpacket; //----设备中的采集包集合
- std::vector<Item* > m_vitem; //----设备中采集点集合
- Channel* m_parent; //----父句柄
- };
-
- #endif /* SERVICEMODEL_DEVICE_H_ */
|