协能can协议
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Device.h 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /*
  2. * Device.h
  3. *
  4. * Created on: 2016年11月10日
  5. * Author: Mr_zhu
  6. * Content:
  7. */
  8. #ifndef SERVICEMODEL_DEVICE_H_
  9. #define SERVICEMODEL_DEVICE_H_
  10. #include <string>
  11. #include <vector>
  12. #include "../common/Type.h"
  13. #include "../externservice/HardwareI.h"
  14. #include "../externservice/ParaAnalysisI.h"
  15. #include "../externservice/ProtocolI.h"
  16. #include "../externservice/SubContractI.h"
  17. #include "Base.h"
  18. #include "Item.h"
  19. #include "Packet.h"
  20. struct HardwareI;
  21. struct ParaAnalysisI;
  22. struct ProtocolI;
  23. struct SubContractI;
  24. struct IHardware;
  25. struct IParaAnalysis;
  26. struct IProtocol;
  27. class Channel;
  28. class Device {
  29. public:
  30. Device() :
  31. m_pptcl(NULL), m_hwtype(-1), m_hwnumber(-1), m_phw(NULL), m_ppara(
  32. NULL), m_psubctact(
  33. NULL), m_enable(1), m_datimer(100), m_datimeout(1000), m_dafaulttime(
  34. 3000), m_readretrycount(0), m_writeretrycount(3), m_faultcount(
  35. 3), m_parent(NULL) {
  36. }
  37. virtual ~Device() {
  38. // if (m_pptcl != NULL) {
  39. // delete m_pptcl;
  40. // m_pptcl = NULL;
  41. // }
  42. // if (m_phw != NULL) {
  43. // delete m_phw;
  44. // m_phw = NULL;
  45. // }
  46. // if (m_ppara != NULL) {
  47. // delete m_ppara;
  48. // m_ppara = NULL;
  49. // }
  50. // if (m_psubctact != NULL) {
  51. // delete m_psubctact;
  52. // m_psubctact = NULL;
  53. // }
  54. }
  55. Base& getBase() {
  56. return m_base;
  57. }
  58. void setBase(const Base& base) {
  59. this->m_base = base;
  60. }
  61. int getEnable() const {
  62. return m_enable;
  63. }
  64. void setEnable(int enable) {
  65. m_enable = enable;
  66. }
  67. CLSID& getHwguid() {
  68. return m_hwguid;
  69. }
  70. void setHwguid(const CLSID& hwguid) {
  71. m_hwguid = hwguid;
  72. }
  73. std::string& getHwname() {
  74. return m_hwname;
  75. }
  76. void setHwname(const std::string& hwname) {
  77. if (!hwname.empty()) {
  78. m_hwname = hwname;
  79. }
  80. }
  81. int getHwnumber() const {
  82. return m_hwnumber;
  83. }
  84. void setHwnumber(int hwnumber) {
  85. m_hwnumber = hwnumber;
  86. }
  87. int getHwtype() const {
  88. return m_hwtype;
  89. }
  90. void setHwtype(int hwtype) {
  91. m_hwtype = hwtype;
  92. }
  93. std::string& getItemtable() {
  94. return m_itemtable;
  95. }
  96. void setItemtable(const std::string& itemtable) {
  97. if (!itemtable.empty()) {
  98. m_itemtable = itemtable;
  99. }
  100. }
  101. CLSID& getParaanalysisguid() {
  102. return m_paraanalysisguid;
  103. }
  104. void setParaanalysisguid(const CLSID& paraanalysisguid) {
  105. m_paraanalysisguid = paraanalysisguid;
  106. }
  107. CLSID& getProtocolguid() {
  108. return m_protocolguid;
  109. }
  110. void setProtocolguid(const CLSID& protocolguid) {
  111. m_protocolguid = protocolguid;
  112. }
  113. const std::string& getProtocolname() const {
  114. return m_protocolname;
  115. }
  116. void setProtocolname(const std::string& protocolname) {
  117. if (!protocolname.empty()) {
  118. m_protocolname = protocolname;
  119. }
  120. }
  121. CLSID& getSubcontractguid() {
  122. return m_subcontractguid;
  123. }
  124. void setSubcontractguid(const CLSID& subcontractguid) {
  125. m_subcontractguid = subcontractguid;
  126. }
  127. Channel* getParent() {
  128. return m_parent;
  129. }
  130. void setParent(Channel* parent) {
  131. this->m_parent = parent;
  132. }
  133. HardwareI* getPhw() {
  134. return m_phw;
  135. }
  136. void setPhw(HardwareI* phw) {
  137. this->m_phw = phw;
  138. }
  139. ParaAnalysisI* getPpara() const {
  140. return m_ppara;
  141. }
  142. void setPpara(ParaAnalysisI* ppara) {
  143. this->m_ppara = ppara;
  144. }
  145. ProtocolI* getPptcl() {
  146. return m_pptcl;
  147. }
  148. void setPptcl(ProtocolI* pptcl) {
  149. this->m_pptcl = pptcl;
  150. }
  151. SubContractI* getPsubctact() const {
  152. return m_psubctact;
  153. }
  154. void setPsubctact(SubContractI* psubctact) {
  155. this->m_psubctact = psubctact;
  156. }
  157. std::vector<Packet* >& getVpacket() {
  158. return m_vpacket;
  159. }
  160. void setVpacket(const std::vector<Packet* >& vpacket) {
  161. this->m_vpacket = vpacket;
  162. }
  163. std::vector<Item* >& getVitem() {
  164. return m_vitem;
  165. }
  166. void setVitem(const std::vector<Item* >& vitem) {
  167. this->m_vitem = vitem;
  168. }
  169. HRESULT addItem(Item* item) {
  170. bool isexist = false;
  171. for (Item*& i : m_vitem) {
  172. if (i->isEqual(*item)) {
  173. isexist = true;
  174. break;
  175. }
  176. }
  177. if (!isexist) {
  178. m_vitem.push_back(item);
  179. return S_OK;
  180. }
  181. return S_FALSE;
  182. }
  183. HRESULT addPacket(Packet* packet) {
  184. bool isexist = false;
  185. for (Packet* & p : m_vpacket) {
  186. if (p->isEqual(*packet)) {
  187. isexist = true;
  188. break;
  189. }
  190. }
  191. if (!isexist) {
  192. m_vpacket.push_back(packet);
  193. return S_OK;
  194. }
  195. return S_FALSE;
  196. }
  197. ULONG getItemCount() {
  198. return m_vitem.size();
  199. }
  200. ULONG getPacketCount() {
  201. return m_vpacket.size();
  202. }
  203. public:
  204. bool isEqual(Device& device) {
  205. if ((isGUIDEqual(this->m_hwguid,((device.getHwguid()))))
  206. && (this->m_hwname == ((device.getHwname())))
  207. && (this->m_hwnumber == device.getHwnumber())
  208. && (this->m_hwtype == device.getHwtype())) {
  209. return true;
  210. }
  211. return false;
  212. }
  213. int getDafaulttime() const {
  214. return m_dafaulttime;
  215. }
  216. void setDafaulttime(int dafaulttime) {
  217. m_dafaulttime = dafaulttime;
  218. }
  219. int getDatimeout() const {
  220. return m_datimeout;
  221. }
  222. void setDatimeout(int datimeout) {
  223. m_datimeout = datimeout;
  224. }
  225. int getDatimer() const {
  226. return m_datimer;
  227. }
  228. void setDatimer(int datimer) {
  229. m_datimer = datimer;
  230. }
  231. int getFaultcount() const {
  232. return m_faultcount;
  233. }
  234. void setFaultcount(int faultcount) {
  235. m_faultcount = faultcount;
  236. }
  237. int getReadretrycount() const {
  238. return m_readretrycount;
  239. }
  240. void setReadretrycount(int readretrycount) {
  241. m_readretrycount = readretrycount;
  242. }
  243. int getWriteretrycount() const {
  244. return m_writeretrycount;
  245. }
  246. void setWriteretrycount(int writeretrycount) {
  247. m_writeretrycount = writeretrycount;
  248. }
  249. void outInfo() {
  250. }
  251. private:
  252. std::string m_protocolname; //----设备通信协议名称
  253. CLSID m_protocolguid; //----设备通信协议组件标识符
  254. ProtocolI* m_pptcl; //----设备通信协议组件句柄
  255. std::string m_hwname; //----设备硬件通道名称
  256. int m_hwtype; //----设备硬件通道类型
  257. int m_hwnumber; //----设备硬件通道号
  258. CLSID m_hwguid; //----设备硬件通道组件标识符
  259. HardwareI* m_phw; //----设备硬件通道组件句柄
  260. CLSID m_paraanalysisguid; //----设备参数解析组件标识符
  261. ParaAnalysisI* m_ppara; //----设备参数分析组件句柄
  262. CLSID m_subcontractguid; //----设备分包参数组件标识符
  263. SubContractI* m_psubctact; //----设备分包组件句柄
  264. std::string m_itemtable; //----设备点表名称
  265. int m_enable; //----设备使能控制
  266. int m_datimer; //----采集周期
  267. int m_datimeout; //----采集超时时间
  268. int m_dafaulttime; //----采集故障恢复时间
  269. int m_readretrycount; //----读重试次数
  270. int m_writeretrycount; //----写重试次数
  271. int m_faultcount; //----采集故障次数
  272. Base m_base; //----公共参数
  273. std::vector<Packet* > m_vpacket; //----设备中的采集包集合
  274. std::vector<Item* > m_vitem; //----设备中采集点集合
  275. Channel* m_parent; //----父句柄
  276. };
  277. #endif /* SERVICEMODEL_DEVICE_H_ */