#pragma once #include #include using namespace std; enum EnumPackType { eAscii = 0, eUnsignedDec }; class CTransDataPack //拱幅 沥焊 class. { protected: int m_nIndex; int m_nByte; EnumPackType m_ePackType; char* m_pstrData; public: CTransDataPack() { m_pstrData = NULL; ResetTransDataPack(); } ~CTransDataPack() { ResetTransDataPack(); } CTransDataPack(int Index, int Byte, char* pstrData = NULL, EnumPackType ePackType = eAscii) { m_nIndex = Index; m_nByte = Byte; m_ePackType = ePackType; m_pstrData = new char[m_nByte+1]; memset(m_pstrData,0,sizeof(char)*(m_nByte+1)); if(pstrData != NULL) memcpy(m_pstrData,pstrData,sizeof(char)*m_nByte); } CTransDataPack& operator=(const CTransDataPack& rhs) { if (this != &rhs) { ResetTransDataPack(); m_nIndex = rhs.m_nIndex; m_nByte = rhs.m_nByte; m_ePackType = rhs.m_ePackType; m_pstrData = new char[m_nByte+1]; memset(m_pstrData,0,sizeof(char)*(m_nByte+1)); if(rhs.m_pstrData != NULL) memcpy(m_pstrData,rhs.m_pstrData,sizeof(char)*m_nByte); } return *this; } void ResetTransDataPack() { m_nIndex = 0; m_nByte = 0; m_ePackType = eAscii; if(m_pstrData != NULL) { delete [] m_pstrData; m_pstrData = NULL; } } int GetIndex() {return m_nIndex;}; //拱幅 沥焊狼 鉴辑 int GetByte() {return m_nByte;}; //拱幅 沥焊狼 辨捞. EnumPackType GetPackType() {return m_ePackType;} char* GetValue() {return m_pstrData;}; //拱幅 沥焊狼 蔼 void SetValue(char* pstrData) { if(pstrData == NULL) { memset(m_pstrData,0,sizeof(char)*(m_nByte+1)); } else { memcpy(m_pstrData,pstrData,sizeof(char)*m_nByte); } } }; class CTransDataManager { public: CTransDataManager(); virtual ~CTransDataManager(); CTransDataManager& operator=(const CTransDataManager& rhs); // 檬扁拳 void ResetPackData(); // 16柳荐 -> 10柳荐(int) int Hex2Dec(CString hex_str); // 16柳荐 -> 何龋绝绰 10柳荐(short) short Hex2SignedDec(CString hex_str); // 酒胶虐 -> 16柳荐 巩磊凯 CString Asc2Hex(CStringA hex_str); // 胶飘傅 -> 16柳荐 BOOL StrToHex(CHAR* pchData, CHAR* pchDataSrc, INT nLength, BOOL bWordReverse = FALSE); // 16柳荐 -> 何龋乐绰 10柳荐 UINT Hex2UnsignedDec(CString hex_str); // 况靛 -> 10柳荐 UINT GetDataWord2Dec(CString buff, int ap, BOOL hi_bit); // 况靛 -> 巩磊凯 CString GetDataWord2Str(CString& value, int& addr, int length); // 拱幅 沥焊 辑摹 BOOL SearchValueInMap(CString Name, CString& ReturnValue, int& ByteLength); // 拱幅 沥焊 辑摹 BOOL SearchValueInMap(CString Name, int& nReturnValue, int& ByteLength); // PLC 单捞磐 -> 甘 BOOL InsertPLCValueToPack(CString keyName, char* pstrData); // 蔼 辑摹 BOOL GetPackDataAll(CString &Name, int Index, int &Byte, CString &Value); // 拱幅 单捞磐 傈眉 墨款飘 int GetDataPackTotalNumber(); // 拱幅 单捞磐 傈眉 官捞飘 int GetDataPackTotalByteSize(){return m_DataPackTotalByteSize;}; // PLC 单捞磐 -> 甘 BOOL InsertPLCValueToMap(char* pstrRawData,int nLength); // 拱幅单捞磐 器杆 殿废 void InsertTransItemToMap(CString ItemName, int ItemByte, int Key=-1, EnumPackType ePackType = eAscii); // 拱幅单捞磐 器杆 佬扁 BOOL LoadTransItemFromFile(CString FilePath); CString GetItemName(int nIndex); protected: void ResetData(); private: int m_DataPackTotalByteSize; std::map m_TransDataPackMap; //拱幅沥焊 捞抚, 辨捞, 蔼俊 措茄 甘 牧抛捞呈 std::map::iterator m_TransDataPackMapiterator; //拱幅 沥焊 啊府虐绰 器牢磐 std::vector m_vTransDataList; //拱幅 沥焊 府胶飘 };