/********************************************* * * Binary message organization and parsing * * copyright Shanghai Baosight Software Co., Ltd. * * create zoufuzhou 20201001 * ************************************************/ #pragma once #ifdef _WIN32 //#include #else #include #endif #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace baosight; typedef vector TVectItem; class BinaryTele { public: BinaryTele(int eventNo=9999,const string& table = "T_LOV_TELEITEM"); virtual ~BinaryTele(); int ReBuild(int eventNo,const char* buff); int ReBuild(int eventNo); //读取最近一次电文结构及数据 int Read(int eventNo); /*按索引获取电文项内容或给当前电文项赋值*/ TeleItem& operator[]( int elem ); /*按电文项名称获取电文项内容或给当前电文项赋值*/ TeleItem& operator[]( const string& itemName); // get index NO. of tele columns ,start No. is :0 int GetItemIndex(const string &itemName); /*输出组织的电文数据,输出时是否高低字节转换*/ char* GetTeleData(bool htol_byte = true); /*取电文处理相关表*/ vector& GetTables(); /*通过读相关表填充 参数:const string& dbtable 出口相关MUCODE const string dbwhere 可以自己为定义的表组织where条件*/ int Fill(const string& dbtable, const string& dbwhere); /*输出电文详细*/ void Print(void); //获取当前电文项数 const int size(void) const; //组织电文完成后取电文长度 const int TeleLen() const; public: //获取电文通信配置 static int GetTeleConf(int eventNo,TeleConf& conf); protected: /*拆分电文串*/ int SplitTele(const char* buffer); //组织电文 ,否高低字节转换 int OrganizeTele(bool htol_byte = true); //zero item value void InitValue(void); private: void reverse_string(char *left, char *right); TeleItem& IsNuLL(); private: vector mv_table; TVectItem *mp_itemvect; //存放当前电文定义 int m_teleLen; //store current bufferlen; static map *mp_telemap; //电文结构池,存储已扩展的电文定义 static map mm_teleconf; //电文通信配置 TeleItem itemnull; //空电文项 static TeleDAO* mp_teledao; std::string m_table; char m_buff[102400]; };