| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604 |
- /*
- * Item.h
- *
- * Created on: 2016年11月10日
- * Author: Mr_zhu
- * Content:
- */
-
- #ifndef SERVICEMODEL_ITEM_H_
- #define SERVICEMODEL_ITEM_H_
-
- #include <string>
-
- #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<fdst) {
- // bresult = true;
- // }
- // }
- // else if(condition=="!=") {
- // if(fsrc!=fdst) {
- // bresult = true;
- // }
- // }
- // }
- // else
- // {
- // bresult = false;
- // }
- //
- // return bresult;
- // }
- };
-
- #endif /* SERVICEMODEL_ITEM_H_ */
|