chenluhua1980
2025-11-17 968405dbb155e67a877ab59de7e872824eeb700b
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
#include "stdafx.h"
#include "CEqReadStep.h"
#include "Log.h"
 
 
namespace SERVO {
    CEqReadStep::CEqReadStep() : CReadStep()
    {
        m_nDataDev = 0;
        m_nReadSize = 0;
        m_onReadBlock = nullptr;
    }
 
    CEqReadStep::CEqReadStep(int dev, size_t readSize, ONREAD onReadBlock)
    {
        m_nDataDev = dev;
        m_nReadSize = readSize;
        m_onReadBlock = onReadBlock;
    }
 
    CEqReadStep::~CEqReadStep()
    {
 
    }
 
    void CEqReadStep::getAttributeVector(CAttributeVector& attrubutes)
    {
        CReadStep::getAttributeVector(attrubutes);
 
        unsigned int weight = 31;
        std::string strTemp;
        attrubutes.addAttribute(new CAttribute("Dev",
            ("W" + CToolUnits::toHexString(m_nDataDev, strTemp)).c_str(), "", weight++));
    }
 
    int CEqReadStep::onReadData()
    {
        CReadStep::onReadData();
 
 
        // 20250620ÐÂÔö£¬ÓÐЩ³¡¾°ÊDz»ÐèÒª¶ÁÊý¾ÝµÄ£¬Ö»Òª¼ì²âµ½ÐÅÏ¢¾ÍдÊý¾Ý¸ø»úÆ÷
        if (m_nReadSize == 0) {
            if (m_onReadBlock != nullptr) {
                m_onReadBlock(this, ROK, nullptr, 0);
            }
 
            return 0;
        }
 
 
        // ¶ÁÊý¾Ý
        char szBuffer[READ_BUFFER_MAX];
        int nRet = m_pCclink->ReadData2(m_station, DeviceType::W, m_nDataDev,
            (long)min(READ_BUFFER_MAX, m_nReadSize), szBuffer);
        if (0 != nRet) {
            LOGE("<CEqReadStep>Read data error.");
            if (m_onReadBlock != nullptr) {
                m_onReadBlock(this, RERROR, nullptr, 0);
            }
            return -1;
        }
 
        LOGD("<CEqReadStep>read data succeed.");
        if (m_onReadBlock != nullptr) {
            m_onReadBlock(this, ROK, szBuffer, m_nReadSize);
        }
 
 
        return 0;
    }
 
    int CEqReadStep::onComplete()
    {
        CReadStep::onComplete();
        LOGD("<CEqReadStep> onComplete.");
        if (m_onReadBlock != nullptr) {
            m_onReadBlock(this, RCOMPLETE, nullptr, 0);
        }
 
        return 0;
    }
 
    int CEqReadStep::onTimeout()
    {
        CReadStep::onTimeout();
        LOGE("<CEqReadStep> onTimeout.");
        if (m_onReadBlock != nullptr) {
            m_onReadBlock(this, RTIMEOUT, nullptr, 0);
        }
 
        return 0;
    }
}