#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);
|
|
std::string strTemp;
|
attrubutes.addAttribute(new CAttribute("Dev",
|
("W" + CToolUnits::toHexString(m_nDataDev, strTemp)).c_str(), ""));
|
}
|
|
int CEqReadStep::onReadData()
|
{
|
CReadStep::onReadData();
|
|
|
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) {
|
LOGI("<CEqReadStep>Read data error.");
|
if (m_onReadBlock != nullptr) {
|
m_onReadBlock(RERROR, nullptr, 0);
|
}
|
return -1;
|
}
|
|
LOGI("<CEqReadStep>read data succeed.");
|
if (m_onReadBlock != nullptr) {
|
m_onReadBlock(ROK, szBuffer, m_nReadSize);
|
}
|
|
|
return 0;
|
}
|
|
int CEqReadStep::onComplete()
|
{
|
CReadStep::onComplete();
|
LOGI("<CEqReadStep> onComplete.");
|
if (m_onReadBlock != nullptr) {
|
m_onReadBlock(RCOMPLETE, nullptr, 0);
|
}
|
|
return 0;
|
}
|
|
int CEqReadStep::onTimeout()
|
{
|
CReadStep::onTimeout();
|
LOGI("<CEqReadStep> onTimeout.");
|
if (m_onReadBlock != nullptr) {
|
m_onReadBlock(RTIMEOUT, nullptr, 0);
|
}
|
|
return 0;
|
}
|
}
|