#include "realvalue.h" #include "yt_unit_shm.h" #include extern YT_UNIT_SHM *ytShm; void set_realtime_io_value(quint8 commid, quint8 busadd, quint8 value, uint timestamp) { quint8 alarmStatus = 0x00; // QDateTime datetime = QDateTime::fromTime_t(timestamp); if((ytShm->sPointList.sPoint[commid][busadd].PNO_ALARM>0) &&(ytShm->sPointList.sPoint[commid][busadd].PNO_VALUE<2)) { if(value==ytShm->sPointList.sPoint[commid][busadd].PNO_VALUE) alarmStatus = ytShm->sPointList.sPoint[commid][busadd].PNO_ALARM; } if(alarmStatus!=ytShm->spStatusList.spStatus[commid][busadd].ALARM_STATUS) { ytShm->spStatusList.spStatus[commid][busadd].ALARM_STATUS = alarmStatus; ytShm->spStatusList.spStatus[commid][busadd].ALARM_TIMESTAMP = timestamp; if(alarmStatus==0) { if(ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT==0x00) ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT = 0x01; else ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT = 0x00; } else ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT = 0x00; } ytShm->spStatusList.spStatus[commid][busadd].REALTIME_VALUE = value*1.0; ytShm->spStatusList.spStatus[commid][busadd].REALTIME_TIMESTAMP = timestamp; 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); if(ytShm->spStatusList.spStatus[commid][busadd].COUNT==0) { ytShm->spStatusList.spStatus[commid][busadd].MAX_VALUE = value*1.0; ytShm->spStatusList.spStatus[commid][busadd].MAX_TIMESTAMP = timestamp; ytShm->spStatusList.spStatus[commid][busadd].MIN_VALUE = value*1.0; ytShm->spStatusList.spStatus[commid][busadd].MIN_TIMESTAMP = timestamp; ytShm->spStatusList.spStatus[commid][busadd].TOTAL_VALUE = value*1.0; ytShm->spStatusList.spStatus[commid][busadd].AVE_VALUE = value*1.0; ytShm->spStatusList.spStatus[commid][busadd].COUNT = 1; }else{ ytShm->spStatusList.spStatus[commid][busadd].TOTAL_VALUE += value*1.0; ytShm->spStatusList.spStatus[commid][busadd].COUNT += 1; ytShm->spStatusList.spStatus[commid][busadd].AVE_VALUE = ytShm->spStatusList.spStatus[commid][busadd].TOTAL_VALUE /ytShm->spStatusList.spStatus[commid][busadd].COUNT; if(value>ytShm->spStatusList.spStatus[commid][busadd].MAX_VALUE) { ytShm->spStatusList.spStatus[commid][busadd].MAX_VALUE = value; ytShm->spStatusList.spStatus[commid][busadd].MAX_TIMESTAMP = timestamp; } if(valuespStatusList.spStatus[commid][busadd].MIN_VALUE) { ytShm->spStatusList.spStatus[commid][busadd].MIN_VALUE = value; ytShm->spStatusList.spStatus[commid][busadd].MIN_TIMESTAMP = timestamp; } } } void set_realtime_real_value(quint8 commid, quint8 busadd, float value, uint timestamp) { quint8 alarmStatus = 0x00; // QDateTime datetime = QDateTime::fromTime_t(timestamp); if((ytShm->sPointList.sPoint[commid][busadd].PNO_ALARM>0) &&(ytShm->sPointList.sPoint[commid][busadd].PNO_VALUE<4) &&(ytShm->sPointList.sPoint[commid][busadd].PNO_VALUE>0)) { if((ytShm->sPointList.sPoint[commid][busadd].PNO_VALUE&0x01)==0x01) { if(value>ytShm->sPointList.sPoint[commid][busadd].ALARM_H) { alarmStatus = 0x20|ytShm->sPointList.sPoint[commid][busadd].PNO_ALARM; } } if((ytShm->sPointList.sPoint[commid][busadd].PNO_VALUE&0x02)==0x02) { if(valuesPointList.sPoint[commid][busadd].ALARM_L) { alarmStatus = 0x10|ytShm->sPointList.sPoint[commid][busadd].PNO_ALARM; } } } if(alarmStatus!=ytShm->spStatusList.spStatus[commid][busadd].ALARM_STATUS) { ytShm->spStatusList.spStatus[commid][busadd].ALARM_STATUS = alarmStatus; ytShm->spStatusList.spStatus[commid][busadd].ALARM_TIMESTAMP = timestamp; if(alarmStatus==0) { if(ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT==0x00) ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT = 0x01; else ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT = 0x00; } else ytShm->spStatusList.spStatus[commid][busadd].ALARM_SENT = 0x00; } ytShm->spStatusList.spStatus[commid][busadd].REALTIME_VALUE = value*1.0; ytShm->spStatusList.spStatus[commid][busadd].REALTIME_TIMESTAMP = timestamp; 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); if(ytShm->spStatusList.spStatus[commid][busadd].COUNT==0) { ytShm->spStatusList.spStatus[commid][busadd].MAX_VALUE = value; ytShm->spStatusList.spStatus[commid][busadd].MAX_TIMESTAMP = timestamp; ytShm->spStatusList.spStatus[commid][busadd].MIN_VALUE = value; ytShm->spStatusList.spStatus[commid][busadd].MIN_TIMESTAMP = timestamp; ytShm->spStatusList.spStatus[commid][busadd].TOTAL_VALUE = value; ytShm->spStatusList.spStatus[commid][busadd].AVE_VALUE = value; ytShm->spStatusList.spStatus[commid][busadd].COUNT = 1; }else{ ytShm->spStatusList.spStatus[commid][busadd].TOTAL_VALUE += value; ytShm->spStatusList.spStatus[commid][busadd].COUNT += 1; ytShm->spStatusList.spStatus[commid][busadd].AVE_VALUE = ytShm->spStatusList.spStatus[commid][busadd].TOTAL_VALUE /ytShm->spStatusList.spStatus[commid][busadd].COUNT; if(value>ytShm->spStatusList.spStatus[commid][busadd].MAX_VALUE) { ytShm->spStatusList.spStatus[commid][busadd].MAX_VALUE = value; ytShm->spStatusList.spStatus[commid][busadd].MAX_TIMESTAMP = timestamp; } if(valuespStatusList.spStatus[commid][busadd].MIN_VALUE) { ytShm->spStatusList.spStatus[commid][busadd].MIN_VALUE = value; ytShm->spStatusList.spStatus[commid][busadd].MIN_TIMESTAMP = timestamp; } } } void set_realtime_value(quint8 commid, quint8 busadd, float value, uint timestamp) { if(commid<4) { if(ytShm->commList.comm[commid].ENABLED==0x01) { if(ytShm->sPointList.sPoint[commid][busadd].ENABLED==0x01) { switch(ytShm->sPointList.sPoint[commid][busadd].PNO_TYPE) { case 0x01://开关量输入 set_realtime_io_value(commid, busadd, (value==0)?0x00:0x01, timestamp); break; case 0x02://模拟量输入 set_realtime_real_value(commid, busadd, value, timestamp); break; default: break; } } } } }