协能can协议
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Item.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /*
  2. * Item.h
  3. *
  4. * Created on: 2016年11月10日
  5. * Author: Mr_zhu
  6. * Content:
  7. */
  8. #ifndef SERVICEMODEL_ITEM_H_
  9. #define SERVICEMODEL_ITEM_H_
  10. #include <string>
  11. #include "../common/Type.h"
  12. #include "Base.h"
  13. struct ParaAnalysisI;
  14. class Packet;
  15. class Item
  16. {
  17. public:
  18. Item() :
  19. m_ppara(NULL), m_index(0), m_sourcemin(0.0), m_sourcemax(0.0), m_realmin(0.0), m_realmax(0.0), m_enable(0), m_alarmenable(0), m_hisenable(0), m_histimes(
  20. 0), m_parent(NULL), m_ritem(NULL), lupdatetime(0), updatefreq(0), isFault(false), isReset(false)
  21. {
  22. xLock = PTHREAD_MUTEX_INITIALIZER;
  23. xLock_1 = PTHREAD_MUTEX_INITIALIZER;
  24. }
  25. virtual ~Item()
  26. {
  27. }
  28. public:
  29. const std::string& getFaultdata() const
  30. {
  31. return faultdata;
  32. }
  33. void setFaultdata(const std::string& faultdata)
  34. {
  35. this->faultdata = faultdata;
  36. }
  37. const std::string& getFaulttime() const
  38. {
  39. return faulttime;
  40. }
  41. void setFaulttime(const std::string& faulttime)
  42. {
  43. this->faulttime = faulttime;
  44. }
  45. bool isIsFault()
  46. {
  47. return isFault;
  48. }
  49. void setIsFault(bool isFault)
  50. {
  51. this->isFault = isFault;
  52. }
  53. bool isIsReset()
  54. {
  55. return isReset;
  56. }
  57. void setIsReset(bool isReset)
  58. {
  59. this->isReset = isReset;
  60. }
  61. const std::string& getResettime() const
  62. {
  63. return resettime;
  64. }
  65. void setResettime(const std::string& resettime)
  66. {
  67. this->resettime = resettime;
  68. }
  69. Base& getBase()
  70. {
  71. return m_base;
  72. }
  73. void setBase(const Base& base)
  74. {
  75. this->m_base = base;
  76. }
  77. const std::string& getAlarmcondition() const
  78. {
  79. return m_alarmcondition;
  80. }
  81. void setAlarmcondition(const std::string& alarmcondition)
  82. {
  83. if (!alarmcondition.empty())
  84. {
  85. m_alarmcondition = alarmcondition;
  86. }
  87. }
  88. const std::string& getAlarmcontent() const
  89. {
  90. return m_alarmcontent;
  91. }
  92. void setAlarmcontent(const std::string& alarmcontent)
  93. {
  94. if (!alarmcontent.empty())
  95. {
  96. m_alarmcontent = alarmcontent;
  97. }
  98. }
  99. int getAlarmenable() const
  100. {
  101. return m_alarmenable;
  102. }
  103. void setAlarmenable(int alarmenable)
  104. {
  105. m_alarmenable = alarmenable;
  106. }
  107. const std::string& getAlarmvalue() const
  108. {
  109. return m_alarmvalue;
  110. }
  111. void setAlarmvalue(const std::string& alarmvalue)
  112. {
  113. if (!alarmvalue.empty())
  114. {
  115. m_alarmvalue = alarmvalue;
  116. }
  117. }
  118. int getEnable() const
  119. {
  120. return m_enable;
  121. }
  122. void setEnable(int enable)
  123. {
  124. m_enable = enable;
  125. }
  126. int getHisenable() const
  127. {
  128. return m_hisenable;
  129. }
  130. void setHisenable(int hisenable)
  131. {
  132. m_hisenable = hisenable;
  133. }
  134. const std::string& getHistimebase() const
  135. {
  136. return m_histimebase;
  137. }
  138. void setHistimebase(const std::string& histimebase)
  139. {
  140. if (!histimebase.empty())
  141. {
  142. m_histimebase = histimebase;
  143. }
  144. }
  145. int getHistimes() const
  146. {
  147. return m_histimes;
  148. }
  149. void setHistimes(int histimes)
  150. {
  151. m_histimes = histimes;
  152. }
  153. const std::string& getHistype() const
  154. {
  155. return m_histype;
  156. }
  157. void setHistype(const std::string& histype)
  158. {
  159. if (!histype.empty())
  160. {
  161. m_histype = histype;
  162. }
  163. }
  164. int getIndex() const
  165. {
  166. return m_index;
  167. }
  168. void setIndex(int index)
  169. {
  170. m_index = index;
  171. }
  172. const std::string& getInitvalue() const
  173. {
  174. return m_initvalue;
  175. }
  176. void setInitvalue(const std::string& initvalue)
  177. {
  178. if (!initvalue.empty())
  179. {
  180. m_initvalue = initvalue;
  181. }
  182. }
  183. CLSID& getParaanalysisguid()
  184. {
  185. return m_paraanalysisguid;
  186. }
  187. void setParaanalysisguid(const CLSID& paraanalysisguid)
  188. {
  189. m_paraanalysisguid = paraanalysisguid;
  190. }
  191. double getRealmax() const
  192. {
  193. return m_realmax;
  194. }
  195. void setRealmax(double realmax)
  196. {
  197. m_realmax = realmax;
  198. }
  199. double getRealmin() const
  200. {
  201. return m_realmin;
  202. }
  203. void setRealmin(double realmin)
  204. {
  205. m_realmin = realmin;
  206. }
  207. const std::string& getResetcondition() const
  208. {
  209. return m_resetcondition;
  210. }
  211. void setResetcondition(const std::string& resetcondition)
  212. {
  213. if (!resetcondition.empty())
  214. {
  215. m_resetcondition = resetcondition;
  216. }
  217. }
  218. const std::string& getResetvalue() const
  219. {
  220. return m_resetvalue;
  221. }
  222. void setResetvalue(const std::string& resetvalue)
  223. {
  224. if (!resetvalue.empty())
  225. {
  226. m_resetvalue = resetvalue;
  227. }
  228. }
  229. double getSourcemax() const
  230. {
  231. return m_sourcemax;
  232. }
  233. void setSourcemax(double sourcemax)
  234. {
  235. m_sourcemax = sourcemax;
  236. }
  237. double getSourcemin() const
  238. {
  239. return m_sourcemin;
  240. }
  241. void setSourcemin(double sourcemin)
  242. {
  243. m_sourcemin = sourcemin;
  244. }
  245. const std::string& getValue() const
  246. {
  247. return m_value;
  248. }
  249. void setValue(const std::string& value)
  250. {
  251. if (!value.empty())
  252. {
  253. (void) pthread_mutex_lock(&xLock_1);
  254. setValueO(m_value);
  255. char t[256];
  256. double sfvalue = 0;
  257. std::string sdatatype = this->getBase().getParam("数据类型");
  258. if((m_sourcemax-m_sourcemin)!=0)
  259. {
  260. if((sdatatype=="I")||(sdatatype=="B"))
  261. {
  262. int ivalue = strtol(value.c_str(),NULL,10);
  263. sfvalue = (double)(((((double)ivalue-m_sourcemin)*(m_realmax-m_realmin))/(m_sourcemax-m_sourcemin))+m_realmin);
  264. sprintf(t,"%.4f",sfvalue);
  265. std::string str;
  266. str = t;
  267. m_value = str;
  268. }
  269. else
  270. {
  271. double ivalue = strtod(value.c_str(),NULL);
  272. sfvalue = (double)(((((double)ivalue-m_sourcemin)*(m_realmax-m_realmin))/(m_sourcemax-m_sourcemin))+m_realmin);
  273. sprintf(t,"%.4f",sfvalue);
  274. std::string str;
  275. str = t;
  276. m_value = str;
  277. }
  278. }
  279. struct timeval tv;
  280. struct timezone tz;
  281. struct tm *p;
  282. gettimeofday(&tv, &tz);
  283. p = localtime(&tv.tv_sec);
  284. char timechar[255];
  285. snprintf(timechar, 255, "%04d-%02d-%02d %02d:%02d:%02d,%3lf", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec,
  286. (tv.tv_usec) * 0.001);
  287. std::string result = timechar;
  288. setSupdatetime(result);
  289. long diff = (long)(tv.tv_sec * 1000 + tv.tv_usec*0.001) - lupdatetime;
  290. setUpdatefreq(diff);
  291. setLupdatetime((long)(tv.tv_sec * 1000 + tv.tv_usec*0.001));
  292. // if(isTrigFaultOrReset(m_value,this->getAlarmvalue(),this->getAlarmcondition())&&!isFault&&!isReset) {
  293. // this->setIsFault(true);
  294. // trace("Item","报警触发");
  295. // std::cout << isReset << "," << isFault << std::endl;
  296. // }
  297. //
  298. // if(isTrigFaultOrReset(m_value,this->getResetvalue(),this->getResetcondition())&&isFault&&!isReset) {
  299. // this->setIsReset(true);
  300. // trace("Item","报警复位");
  301. // std::cout << isReset << "," << isFault << std::endl;
  302. // }
  303. (void) pthread_mutex_unlock(&xLock_1);
  304. }
  305. }
  306. const std::string& getValueO() const
  307. {
  308. return m_value_o;
  309. }
  310. void setValueO(const std::string& valueO)
  311. {
  312. if (!valueO.empty())
  313. {
  314. m_value_o = valueO;
  315. }
  316. }
  317. const std::string& getWvalue() const
  318. {
  319. return m_wvalue;
  320. }
  321. void setWvalue(const std::string& wvalue)
  322. {
  323. if (!wvalue.empty())
  324. {
  325. (void) pthread_mutex_lock(&xLock);
  326. setWvalueO(m_wvalue);
  327. m_wvalue = wvalue;
  328. (void) pthread_mutex_unlock(&xLock);
  329. }
  330. }
  331. const std::string& getWvalueO() const
  332. {
  333. return m_wvalue_o;
  334. }
  335. void setWvalueO(const std::string& wvalueO)
  336. {
  337. if (!wvalueO.empty())
  338. {
  339. m_wvalue_o = wvalueO;
  340. }
  341. }
  342. const Packet* getParent() const
  343. {
  344. return m_parent;
  345. }
  346. void setParent(Packet* parent)
  347. {
  348. this->m_parent = parent;
  349. }
  350. const ParaAnalysisI* getPpara() const
  351. {
  352. return m_ppara;
  353. }
  354. void setPpara(ParaAnalysisI* ppara)
  355. {
  356. this->m_ppara = ppara;
  357. }
  358. public:
  359. bool isEqual(Item& item)
  360. {
  361. if ((this->getBase().getObjid() == item.getBase().getObjid())
  362. || (this->getBase().getName() == item.getBase().getName()))
  363. {
  364. return true;
  365. }
  366. return false;
  367. }
  368. void outInfo()
  369. {
  370. }
  371. Item*& getRitem()
  372. {
  373. return m_ritem;
  374. }
  375. void setRitem(Item*& ritem)
  376. {
  377. m_ritem = ritem;
  378. }
  379. long getLupdatetime()
  380. {
  381. return lupdatetime;
  382. }
  383. void setLupdatetime(long lupdatetime)
  384. {
  385. this->lupdatetime = lupdatetime;
  386. }
  387. const std::string& getSupdatetime()
  388. {
  389. return supdatetime;
  390. }
  391. void setSupdatetime(const std::string& supdatetime)
  392. {
  393. this->supdatetime = supdatetime;
  394. }
  395. long getUpdatefreq()
  396. {
  397. return updatefreq;
  398. }
  399. void setUpdatefreq(long updatefreq)
  400. {
  401. this->updatefreq = updatefreq;
  402. }
  403. private:
  404. CLSID m_paraanalysisguid; //----item's ParaAnalysisGUID
  405. ParaAnalysisI* m_ppara;//----Item参数分析组件句柄
  406. int m_index;//----item's index
  407. double m_sourcemin;//----item's SourceMin
  408. double m_sourcemax;//----item's SourceMax
  409. double m_realmin;//----item's RealMin
  410. double m_realmax;//----item's RealMax
  411. std::string m_initvalue;//----item's InitValue
  412. std::string m_value;//----item's Value
  413. std::string m_value_o;//----item's Value_o
  414. int m_enable;//----item's Enable
  415. int m_alarmenable;//----item's AlarmEnable
  416. std::string m_alarmcondition;//----item's AlarmCondition
  417. std::string m_alarmvalue;//----item's AlarmValue
  418. std::string m_resetcondition;//----item's ResetCondition
  419. std::string m_resetvalue;//----item's ResetValue
  420. std::string m_alarmcontent;//----item's AlarmContent
  421. int m_hisenable;//----item's HisEnable
  422. std::string m_histype;//----item's HisType
  423. std::string m_histimebase;//----item's HisTimeBase
  424. int m_histimes;//----item's HisTimes
  425. std::string m_wvalue;//----item's write value
  426. std::string m_wvalue_o;//----item's write value_o
  427. Base m_base;
  428. Packet* m_parent;
  429. Item* m_ritem;
  430. std::string supdatetime;
  431. long lupdatetime;
  432. long updatefreq;
  433. private:
  434. pthread_mutex_t xLock;
  435. pthread_mutex_t xLock_1;
  436. private:
  437. bool isFault;//----故障标志位
  438. bool isReset;//----复位标志位
  439. std::string faulttime;//----故障发生时间
  440. std::string resettime;//----故障结束时间
  441. std::string faultdata;//----故障时刻的值
  442. // std::string getLocalTime()
  443. // {
  444. // struct timeval tv;
  445. // struct timezone tz;
  446. // struct tm *p;
  447. // gettimeofday(&tv, &tz);
  448. // p = localtime(&tv.tv_sec);
  449. //
  450. // char timechar[255];
  451. // snprintf(timechar, 255, "%04d-%02d-%02d %02d:%02d:%02d,%3lf",
  452. // 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour,
  453. // p->tm_min, p->tm_sec, (tv.tv_usec) * 0.001);
  454. //
  455. // std::string result = timechar;
  456. // return result;
  457. // }
  458. // bool isTrigFaultOrReset(std::string src, std::string dst, std::string condition) {
  459. // bool bresult = false;
  460. //
  461. // if(this->getAlarmenable()==1) {
  462. // double fsrc = 0.0;
  463. // double fdst = 0.0;
  464. //
  465. // fsrc = strtod(src.c_str(),NULL);
  466. // fdst = strtod(dst.c_str(),NULL);
  467. //
  468. // if(condition==">") {
  469. // if(fsrc>fdst) {
  470. // bresult = true;
  471. // }
  472. // }
  473. // else if(condition==">=") {
  474. // if(fsrc>=fdst) {
  475. // bresult = true;
  476. // }
  477. // }
  478. // else if(condition=="=") {
  479. // if(fsrc==fdst) {
  480. // bresult = true;
  481. // }
  482. // }
  483. // else if(condition=="<=") {
  484. // if(fsrc<=fdst) {
  485. // bresult = true;
  486. // }
  487. // }
  488. // else if(condition=="<") {
  489. // if(fsrc<fdst) {
  490. // bresult = true;
  491. // }
  492. // }
  493. // else if(condition=="!=") {
  494. // if(fsrc!=fdst) {
  495. // bresult = true;
  496. // }
  497. // }
  498. // }
  499. // else
  500. // {
  501. // bresult = false;
  502. // }
  503. //
  504. // return bresult;
  505. // }
  506. };
  507. #endif /* SERVICEMODEL_ITEM_H_ */