eis/inc/zio/FileZone.h

208 lines
5.6 KiB
C
Raw Normal View History

/*********************************************************************
*
* file: FileZone.h
*
* copyright: Shanghai Baosight Software Co., Ltd.
*
* author: zoufuzhou
*********************************************************************/
#ifndef _H_FileZone_H
#define _H_FileZone_H
#include <vector>
#include <dirent.h>
#include <stdarg.h>
#ifdef _WIN32
#include <Winsock2.h>
#include <windows.h>
#include <time.h>
#include <sstream>
#include <fstream>
#include <shlwapi.h>
#include <atlstr.h>
#include <direct.h>
#include <string>
#include <io.h>
#else
#include <sys/stat.h>
#include <unistd.h>
#endif
#include <zlib/MemTrk.h>
#include <zlib/coilDef.h>
#include <glob/BinaryTele.h>
#include <zlib/MemCachedClient.h>
#include <zlib/MemTable.hpp>
#include "T_LOV_FDAAITEM.h"
#include "T_PDO_CFG.h"
#include <json/json.h>
#include <zlib/MemCut.h>
#include <zlib/MemPass.h>
#include <zalarm/AlarmDefine.h>
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<ZONE_ROW*> p_zones;
CMemTable<T_LOV_FDAAITEM::STR_T_LOV_FDAAITEM>* mp_fdaa;
CMemTable<T_PDO_CFG::STR_T_PDO_CFG>* mp_pdocfg;
CMemTrk* p_memtrk;
MemCachedClient m_mc;
vector<string> mv_zones;
vector<float> mv_zelg;
CMemTable<PDO>* pt_pdo;
// std::map<zone,vector<ITEM>> mp_zoneitems;
std::map<string,vector<ITEM>> mp_zoneitems;
// map<zone,vector<string>> mp_freq;
map<string,vector<string>> mp_freq;
CMemCut* mp_cut;
CMemPass* mp_pass;
CMemTable<zalarm::AlarmData> *mp_alarm;
string Pre_entId;
};
#endif