37dba94e19219ecc2ed5976b69039b11b6922dd6.svn-base 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #include "realvalue.h"
  2. #include "yt_unit_shm.h"
  3. #include <stdio.h>
  4. extern YT_UNIT_SHM *ytShm;
  5. void set_realtime_io_value(quint8 commid, quint8 busadd, quint8 value, uint timestamp)
  6. {
  7. quint8 alarmStatus = 0x00;
  8. // QDateTime datetime = QDateTime::fromTime_t(timestamp);
  9. if((ytShm->sPointList.sPoint[commid][busadd].PNO_ALARM>0)
  10. &&(ytShm->sPointList.sPoint[commid][busadd].PNO_VALUE<2))
  11. {
  12. if(value==ytShm->sPointList.sPoint[commid][busadd].PNO_VALUE)
  13. alarmStatus = ytShm->sPointList.sPoint[commid][busadd].PNO_ALARM;
  14. }
  15. if(alarmStatus!=ytShm->spStatusList.spStatus[commid][busadd].ALARM_STATUS)
  16. {
  17. ytShm->spStatusList.spStatus[commid][busadd].ALARM_STATUS = alarmStatus;
  18. ytShm->spStatusList.spStatus[commid][busadd].ALARM_TIMESTAMP = timestamp;
  19. if(alarmStatus==0)
  20. {
  21. if(ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT==0x00)
  22. ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT = 0x01;
  23. else
  24. ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT = 0x00;
  25. }
  26. else
  27. ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT = 0x00;
  28. }
  29. ytShm->spStatusList.spStatus[commid][busadd].REALTIME_VALUE = value*1.0;
  30. ytShm->spStatusList.spStatus[commid][busadd].REALTIME_TIMESTAMP = timestamp;
  31. printf("comm:%d\tadd:%d\ttime:%d\tvalue:%.03f\n",commid,busadd,ytShm->spStatusList.spStatus[commid][busadd].REALTIME_TIMESTAMP,ytShm->spStatusList.spStatus[commid][busadd].REALTIME_VALUE);
  32. if(ytShm->spStatusList.spStatus[commid][busadd].COUNT==0)
  33. {
  34. ytShm->spStatusList.spStatus[commid][busadd].MAX_VALUE = value*1.0;
  35. ytShm->spStatusList.spStatus[commid][busadd].MAX_TIMESTAMP = timestamp;
  36. ytShm->spStatusList.spStatus[commid][busadd].MIN_VALUE = value*1.0;
  37. ytShm->spStatusList.spStatus[commid][busadd].MIN_TIMESTAMP = timestamp;
  38. ytShm->spStatusList.spStatus[commid][busadd].TOTAL_VALUE = value*1.0;
  39. ytShm->spStatusList.spStatus[commid][busadd].AVE_VALUE = value*1.0;
  40. ytShm->spStatusList.spStatus[commid][busadd].COUNT = 1;
  41. }else{
  42. ytShm->spStatusList.spStatus[commid][busadd].TOTAL_VALUE += value*1.0;
  43. ytShm->spStatusList.spStatus[commid][busadd].COUNT += 1;
  44. ytShm->spStatusList.spStatus[commid][busadd].AVE_VALUE
  45. = ytShm->spStatusList.spStatus[commid][busadd].TOTAL_VALUE
  46. /ytShm->spStatusList.spStatus[commid][busadd].COUNT;
  47. if(value>ytShm->spStatusList.spStatus[commid][busadd].MAX_VALUE)
  48. {
  49. ytShm->spStatusList.spStatus[commid][busadd].MAX_VALUE = value;
  50. ytShm->spStatusList.spStatus[commid][busadd].MAX_TIMESTAMP = timestamp;
  51. }
  52. if(value<ytShm->spStatusList.spStatus[commid][busadd].MIN_VALUE)
  53. {
  54. ytShm->spStatusList.spStatus[commid][busadd].MIN_VALUE = value;
  55. ytShm->spStatusList.spStatus[commid][busadd].MIN_TIMESTAMP = timestamp;
  56. }
  57. }
  58. }
  59. void set_realtime_real_value(quint8 commid, quint8 busadd, float value, uint timestamp)
  60. {
  61. quint8 alarmStatus = 0x00;
  62. // QDateTime datetime = QDateTime::fromTime_t(timestamp);
  63. if((ytShm->sPointList.sPoint[commid][busadd].PNO_ALARM>0)
  64. &&(ytShm->sPointList.sPoint[commid][busadd].PNO_VALUE<4)
  65. &&(ytShm->sPointList.sPoint[commid][busadd].PNO_VALUE>0))
  66. {
  67. if((ytShm->sPointList.sPoint[commid][busadd].PNO_VALUE&0x01)==0x01)
  68. {
  69. if(value>ytShm->sPointList.sPoint[commid][busadd].ALARM_H)
  70. {
  71. alarmStatus = 0x20|ytShm->sPointList.sPoint[commid][busadd].PNO_ALARM;
  72. }
  73. }
  74. if((ytShm->sPointList.sPoint[commid][busadd].PNO_VALUE&0x02)==0x02)
  75. {
  76. if(value<ytShm->sPointList.sPoint[commid][busadd].ALARM_L)
  77. {
  78. alarmStatus = 0x10|ytShm->sPointList.sPoint[commid][busadd].PNO_ALARM;
  79. }
  80. }
  81. }
  82. if(alarmStatus!=ytShm->spStatusList.spStatus[commid][busadd].ALARM_STATUS)
  83. {
  84. ytShm->spStatusList.spStatus[commid][busadd].ALARM_STATUS = alarmStatus;
  85. ytShm->spStatusList.spStatus[commid][busadd].ALARM_TIMESTAMP = timestamp;
  86. if(alarmStatus==0)
  87. {
  88. if(ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT==0x00)
  89. ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT = 0x01;
  90. else
  91. ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT = 0x00;
  92. }
  93. else
  94. ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT = 0x00;
  95. }
  96. ytShm->spStatusList.spStatus[commid][busadd].REALTIME_VALUE = value*1.0;
  97. ytShm->spStatusList.spStatus[commid][busadd].REALTIME_TIMESTAMP = timestamp;
  98. printf("comm:%d\tadd:%d\ttime:%d\tvalue:%.03f\n",commid,busadd,ytShm->spStatusList.spStatus[commid][busadd].REALTIME_TIMESTAMP,ytShm->spStatusList.spStatus[commid][busadd].REALTIME_VALUE);
  99. if(ytShm->spStatusList.spStatus[commid][busadd].COUNT==0)
  100. {
  101. ytShm->spStatusList.spStatus[commid][busadd].MAX_VALUE = value;
  102. ytShm->spStatusList.spStatus[commid][busadd].MAX_TIMESTAMP = timestamp;
  103. ytShm->spStatusList.spStatus[commid][busadd].MIN_VALUE = value;
  104. ytShm->spStatusList.spStatus[commid][busadd].MIN_TIMESTAMP = timestamp;
  105. ytShm->spStatusList.spStatus[commid][busadd].TOTAL_VALUE = value;
  106. ytShm->spStatusList.spStatus[commid][busadd].AVE_VALUE = value;
  107. ytShm->spStatusList.spStatus[commid][busadd].COUNT = 1;
  108. }else{
  109. ytShm->spStatusList.spStatus[commid][busadd].TOTAL_VALUE += value;
  110. ytShm->spStatusList.spStatus[commid][busadd].COUNT += 1;
  111. ytShm->spStatusList.spStatus[commid][busadd].AVE_VALUE
  112. = ytShm->spStatusList.spStatus[commid][busadd].TOTAL_VALUE
  113. /ytShm->spStatusList.spStatus[commid][busadd].COUNT;
  114. if(value>ytShm->spStatusList.spStatus[commid][busadd].MAX_VALUE)
  115. {
  116. ytShm->spStatusList.spStatus[commid][busadd].MAX_VALUE = value;
  117. ytShm->spStatusList.spStatus[commid][busadd].MAX_TIMESTAMP = timestamp;
  118. }
  119. if(value<ytShm->spStatusList.spStatus[commid][busadd].MIN_VALUE)
  120. {
  121. ytShm->spStatusList.spStatus[commid][busadd].MIN_VALUE = value;
  122. ytShm->spStatusList.spStatus[commid][busadd].MIN_TIMESTAMP = timestamp;
  123. }
  124. }
  125. }
  126. void set_realtime_value(quint8 commid, quint8 busadd, float value, uint timestamp)
  127. {
  128. if(commid<4)
  129. {
  130. if(ytShm->commList.comm[commid].ENABLED==0x01)
  131. {
  132. if(ytShm->sPointList.sPoint[commid][busadd].ENABLED==0x01)
  133. {
  134. switch(ytShm->sPointList.sPoint[commid][busadd].PNO_TYPE)
  135. {
  136. case 0x01://开关量输入
  137. set_realtime_io_value(commid, busadd, (value==0)?0x00:0x01, timestamp);
  138. break;
  139. case 0x02://模拟量输入
  140. set_realtime_real_value(commid, busadd, value, timestamp);
  141. break;
  142. default:
  143. break;
  144. }
  145. }
  146. }
  147. }
  148. }