mrDarker
2025-07-16 1dbe46cd9d0f181d08d5a69f72d8548628a13b9d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#pragma once
 
 
#include <map>
#include <vector>
 
 
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<CString,CTransDataPack*>            m_TransDataPackMap;            //拱幅沥焊 捞抚, 辨捞, 蔼俊 措茄 甘 牧抛捞呈
    std::map<CString,CTransDataPack*>::iterator    m_TransDataPackMapiterator;    //拱幅 沥焊 啊府虐绰 器牢磐 
    std::vector<CString>                        m_vTransDataList;            //拱幅 沥焊 府胶飘
};