/* * Item.h * * Created on: 2016年11月10日 * Author: Mr_zhu * Content: */ #ifndef SERVICEMODEL_ITEM_H_ #define SERVICEMODEL_ITEM_H_ #include #include "../common/Type.h" #include "Base.h" struct ParaAnalysisI; class Packet; class Item { public: Item() : 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( 0), m_parent(NULL), m_ritem(NULL), lupdatetime(0), updatefreq(0), isFault(false), isReset(false) { xLock = PTHREAD_MUTEX_INITIALIZER; xLock_1 = PTHREAD_MUTEX_INITIALIZER; } virtual ~Item() { } public: const std::string& getFaultdata() const { return faultdata; } void setFaultdata(const std::string& faultdata) { this->faultdata = faultdata; } const std::string& getFaulttime() const { return faulttime; } void setFaulttime(const std::string& faulttime) { this->faulttime = faulttime; } bool isIsFault() { return isFault; } void setIsFault(bool isFault) { this->isFault = isFault; } bool isIsReset() { return isReset; } void setIsReset(bool isReset) { this->isReset = isReset; } const std::string& getResettime() const { return resettime; } void setResettime(const std::string& resettime) { this->resettime = resettime; } Base& getBase() { return m_base; } void setBase(const Base& base) { this->m_base = base; } const std::string& getAlarmcondition() const { return m_alarmcondition; } void setAlarmcondition(const std::string& alarmcondition) { if (!alarmcondition.empty()) { m_alarmcondition = alarmcondition; } } const std::string& getAlarmcontent() const { return m_alarmcontent; } void setAlarmcontent(const std::string& alarmcontent) { if (!alarmcontent.empty()) { m_alarmcontent = alarmcontent; } } int getAlarmenable() const { return m_alarmenable; } void setAlarmenable(int alarmenable) { m_alarmenable = alarmenable; } const std::string& getAlarmvalue() const { return m_alarmvalue; } void setAlarmvalue(const std::string& alarmvalue) { if (!alarmvalue.empty()) { m_alarmvalue = alarmvalue; } } int getEnable() const { return m_enable; } void setEnable(int enable) { m_enable = enable; } int getHisenable() const { return m_hisenable; } void setHisenable(int hisenable) { m_hisenable = hisenable; } const std::string& getHistimebase() const { return m_histimebase; } void setHistimebase(const std::string& histimebase) { if (!histimebase.empty()) { m_histimebase = histimebase; } } int getHistimes() const { return m_histimes; } void setHistimes(int histimes) { m_histimes = histimes; } const std::string& getHistype() const { return m_histype; } void setHistype(const std::string& histype) { if (!histype.empty()) { m_histype = histype; } } int getIndex() const { return m_index; } void setIndex(int index) { m_index = index; } const std::string& getInitvalue() const { return m_initvalue; } void setInitvalue(const std::string& initvalue) { if (!initvalue.empty()) { m_initvalue = initvalue; } } CLSID& getParaanalysisguid() { return m_paraanalysisguid; } void setParaanalysisguid(const CLSID& paraanalysisguid) { m_paraanalysisguid = paraanalysisguid; } double getRealmax() const { return m_realmax; } void setRealmax(double realmax) { m_realmax = realmax; } double getRealmin() const { return m_realmin; } void setRealmin(double realmin) { m_realmin = realmin; } const std::string& getResetcondition() const { return m_resetcondition; } void setResetcondition(const std::string& resetcondition) { if (!resetcondition.empty()) { m_resetcondition = resetcondition; } } const std::string& getResetvalue() const { return m_resetvalue; } void setResetvalue(const std::string& resetvalue) { if (!resetvalue.empty()) { m_resetvalue = resetvalue; } } double getSourcemax() const { return m_sourcemax; } void setSourcemax(double sourcemax) { m_sourcemax = sourcemax; } double getSourcemin() const { return m_sourcemin; } void setSourcemin(double sourcemin) { m_sourcemin = sourcemin; } const std::string& getValue() const { return m_value; } void setValue(const std::string& value) { if (!value.empty()) { (void) pthread_mutex_lock(&xLock_1); setValueO(m_value); char t[256]; double sfvalue = 0; std::string sdatatype = this->getBase().getParam("数据类型"); if((m_sourcemax-m_sourcemin)!=0) { if((sdatatype=="I")||(sdatatype=="B")) { int ivalue = strtol(value.c_str(),NULL,10); sfvalue = (double)(((((double)ivalue-m_sourcemin)*(m_realmax-m_realmin))/(m_sourcemax-m_sourcemin))+m_realmin); sprintf(t,"%.4f",sfvalue); std::string str; str = t; m_value = str; } else { double ivalue = strtod(value.c_str(),NULL); sfvalue = (double)(((((double)ivalue-m_sourcemin)*(m_realmax-m_realmin))/(m_sourcemax-m_sourcemin))+m_realmin); sprintf(t,"%.4f",sfvalue); std::string str; str = t; m_value = str; } } struct timeval tv; struct timezone tz; struct tm *p; gettimeofday(&tv, &tz); p = localtime(&tv.tv_sec); char timechar[255]; 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, (tv.tv_usec) * 0.001); std::string result = timechar; setSupdatetime(result); long diff = (long)(tv.tv_sec * 1000 + tv.tv_usec*0.001) - lupdatetime; setUpdatefreq(diff); setLupdatetime((long)(tv.tv_sec * 1000 + tv.tv_usec*0.001)); // if(isTrigFaultOrReset(m_value,this->getAlarmvalue(),this->getAlarmcondition())&&!isFault&&!isReset) { // this->setIsFault(true); // trace("Item","报警触发"); // std::cout << isReset << "," << isFault << std::endl; // } // // if(isTrigFaultOrReset(m_value,this->getResetvalue(),this->getResetcondition())&&isFault&&!isReset) { // this->setIsReset(true); // trace("Item","报警复位"); // std::cout << isReset << "," << isFault << std::endl; // } (void) pthread_mutex_unlock(&xLock_1); } } const std::string& getValueO() const { return m_value_o; } void setValueO(const std::string& valueO) { if (!valueO.empty()) { m_value_o = valueO; } } const std::string& getWvalue() const { return m_wvalue; } void setWvalue(const std::string& wvalue) { if (!wvalue.empty()) { (void) pthread_mutex_lock(&xLock); setWvalueO(m_wvalue); m_wvalue = wvalue; (void) pthread_mutex_unlock(&xLock); } } const std::string& getWvalueO() const { return m_wvalue_o; } void setWvalueO(const std::string& wvalueO) { if (!wvalueO.empty()) { m_wvalue_o = wvalueO; } } const Packet* getParent() const { return m_parent; } void setParent(Packet* parent) { this->m_parent = parent; } const ParaAnalysisI* getPpara() const { return m_ppara; } void setPpara(ParaAnalysisI* ppara) { this->m_ppara = ppara; } public: bool isEqual(Item& item) { if ((this->getBase().getObjid() == item.getBase().getObjid()) || (this->getBase().getName() == item.getBase().getName())) { return true; } return false; } void outInfo() { } Item*& getRitem() { return m_ritem; } void setRitem(Item*& ritem) { m_ritem = ritem; } long getLupdatetime() { return lupdatetime; } void setLupdatetime(long lupdatetime) { this->lupdatetime = lupdatetime; } const std::string& getSupdatetime() { return supdatetime; } void setSupdatetime(const std::string& supdatetime) { this->supdatetime = supdatetime; } long getUpdatefreq() { return updatefreq; } void setUpdatefreq(long updatefreq) { this->updatefreq = updatefreq; } private: CLSID m_paraanalysisguid; //----item's ParaAnalysisGUID ParaAnalysisI* m_ppara;//----Item参数分析组件句柄 int m_index;//----item's index double m_sourcemin;//----item's SourceMin double m_sourcemax;//----item's SourceMax double m_realmin;//----item's RealMin double m_realmax;//----item's RealMax std::string m_initvalue;//----item's InitValue std::string m_value;//----item's Value std::string m_value_o;//----item's Value_o int m_enable;//----item's Enable int m_alarmenable;//----item's AlarmEnable std::string m_alarmcondition;//----item's AlarmCondition std::string m_alarmvalue;//----item's AlarmValue std::string m_resetcondition;//----item's ResetCondition std::string m_resetvalue;//----item's ResetValue std::string m_alarmcontent;//----item's AlarmContent int m_hisenable;//----item's HisEnable std::string m_histype;//----item's HisType std::string m_histimebase;//----item's HisTimeBase int m_histimes;//----item's HisTimes std::string m_wvalue;//----item's write value std::string m_wvalue_o;//----item's write value_o Base m_base; Packet* m_parent; Item* m_ritem; std::string supdatetime; long lupdatetime; long updatefreq; private: pthread_mutex_t xLock; pthread_mutex_t xLock_1; private: bool isFault;//----故障标志位 bool isReset;//----复位标志位 std::string faulttime;//----故障发生时间 std::string resettime;//----故障结束时间 std::string faultdata;//----故障时刻的值 // std::string getLocalTime() // { // struct timeval tv; // struct timezone tz; // struct tm *p; // gettimeofday(&tv, &tz); // p = localtime(&tv.tv_sec); // // char timechar[255]; // 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, (tv.tv_usec) * 0.001); // // std::string result = timechar; // return result; // } // bool isTrigFaultOrReset(std::string src, std::string dst, std::string condition) { // bool bresult = false; // // if(this->getAlarmenable()==1) { // double fsrc = 0.0; // double fdst = 0.0; // // fsrc = strtod(src.c_str(),NULL); // fdst = strtod(dst.c_str(),NULL); // // if(condition==">") { // if(fsrc>fdst) { // bresult = true; // } // } // else if(condition==">=") { // if(fsrc>=fdst) { // bresult = true; // } // } // else if(condition=="=") { // if(fsrc==fdst) { // bresult = true; // } // } // else if(condition=="<=") { // if(fsrc<=fdst) { // bresult = true; // } // } // else if(condition=="<") { // if(fsrc