/********************************************************************* * * file: FileZone.h * * copyright: Shanghai Baosight Software Co., Ltd. * * author: zoufuzhou *********************************************************************/ #ifndef _H_FileZone_H #define _H_FileZone_H #include #include #include #ifdef _WIN32 #include #include #include #include #include #include #include #include #include #include #else #include #include #endif #include #include #include #include #include #include "T_LOV_FDAAITEM.h" #include "T_PDO_CFG.h" #include #include #include #include using namespace baosight; class StoreMode { public: static const int ZONE = 0; /* store data by zone*/ static const int FREQ = 1; /* store data by freq*/ static const int ONE = 2; /* store data to one file*/ static const int PASS = 3; /* store data by pass number*/ static const int PDI = 4; /* store data by entId and save one file*/ }; class AD_MODE{ public: static const short NORMAL = 0; static const short UNKNOW = 1; static const short BINARY = 2; }; struct ITEM{ char name[100]; int mode; char flag[10]; float factor; short telepos; short zdatpos; int teleno; int offset; // offset zone begin pos mm float precision; }; class FileZone { public: /************* * rootdir:save root dir * mode: 0:save by zone, 1:save by length precision 2:save to one file 3:passno 4:pdi * iszip: true zip archive file * islinear: true Linear interpolation, false neighbor interpolation **************/ FileZone(const std::string& rootdir,int mode = 0,bool iszip = true,bool islinear = false); public: virtual ~FileZone(void); public: /************* * write collect data to file * extId: coil num * mode: ed:entry coil num, pr:exit coil num **************/ virtual int write(const std::string& entId,const std::string& extId,std::string mode ="ed"); virtual int read(const std::string& extId,const string& date,string& datastream); virtual int read(int zone,const std::string& extId,const string& date,string& datastream); void dealPreCoil(const std::string& entId,std::string mode = "ed"); protected: /*create file content by zone*/ virtual int fileContent(int zone,int zindex,int start,int end,const std::string& entId,const std::string& extId,Json::Value& jv_zone,Json::Value& jv_stat) = 0; /*create file content by length precision*/ virtual int fileContent(const std::string& entId,const std::string& extId,Json::Value& jvalue,Json::Value& jv_stat) = 0; /*create file content to one file */ virtual int totalContent(const std::string& entId,const std::string& extId, Json::Value& jvalue,Json::Value& jv_stat) = 0; virtual int totalContent(const std::string& entId, Json::Value& jvalue,Json::Value& jv_stat) = 0; virtual int readfile(const std::string& file,std::string& datastream) = 0; /*store each segment elongation */ virtual void storeElongation(const std::string& entId); /*stores statistical process data */ virtual void storeStatData(const std::string& entId,const std::string& extId,Json::Value& jv_stat); private: /*get or make file path*/ std::string getPath(const string& path = ""); /*allocate process*/ // int allocate(const std::string& entId,const std::string& extId,std::string mode); int allocate(const PDO* pdo,std::string mode); /*save to disk*/ int save(const std::string& file,const std::string& str); bool fileCompress(string dir,string data); protected: bool isFinalCut(const std::string& entId); int calcTotalLen(const std::string& entId); void calcElongation(const std::string& entId,int lengthtotal); int GetValue(string coilid,int mode); bool getAddress(int zone,const std::string& entId,const std::string& extId,float elongation,int& zstart ,int& zend); /*get the start,end position of data collection is obtained according to the entId*/ bool getAddress(int zone,const std::string& entId,int& zstart ,int& zend); /*get the length dimension of a zone*/ Json::Value getZoneData(int zindex,int zstart,int zend,float elgfactor,int coillen,ITEM& item); PDO* getPDO(const string& extId); int getLength(const string& extId,bool isL2=false); int getTotalLengthL2(const string& entId); int getCutOutLen(const string& entId); bool Getcoil(int& start ,int& end, const std::string& entId); short Proxy(int eventNo,const string& proxyName, const char* keyValue,int length); /* organize, disassemble alarm into prod coil*/ string organizeAlarm(const string &entId, const string &extId); protected: string m_rootdir; string m_unitno; int m_mode; bool m_iszip; bool m_islinear; float mf_max,mf_min,mf_avg; float mf_unitlen; protected: Json::FastWriter m_writer; protected: BinaryTele* p_btele; std::vector p_zones; CMemTable* mp_fdaa; CMemTable* mp_pdocfg; CMemTrk* p_memtrk; MemCachedClient m_mc; vector mv_zones; vector mv_zelg; CMemTable* pt_pdo; // std::map> mp_zoneitems; std::map> mp_zoneitems; // map> mp_freq; map> mp_freq; CMemCut* mp_cut; CMemPass* mp_pass; CMemTable *mp_alarm; string Pre_entId; }; #endif