本文整理汇总了C++中XsByteArray::append方法的典型用法代码示例。如果您正苦于以下问题:C++ XsByteArray::append方法的具体用法?C++ XsByteArray::append怎么用?C++ XsByteArray::append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XsByteArray
的用法示例。
在下文中一共展示了XsByteArray::append方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: waitForData
/*! \brief Wait for data to arrive or a timeout to occur.
\details The function waits until \c maxLength data is available or until a timeout occurs.
The function returns success if data is available or XsResultValue::TIMEOUT if a
timeout occurred. A timeout value of 0 indicates that the default timeout stored
in the class should be used.
\param maxLength The maximum number of bytes to read before returning
\param data The buffer to put the read data in.
\returns XRV_OK if \a maxLength bytes were read, XRV_TIMEOUT if less was read, XRV_TIMEOUTNODATA if nothing was read
*/
XsResultValue SerialInterface::waitForData(XsSize maxLength, XsByteArray& data)
{
data.clear();
data.reserve(maxLength);
//char *data = (char *)&_data[0];
JLTRACE(gJournal, "timeout=" << m_timeout << ", maxLength=" << maxLength);
uint32_t timeout = m_timeout;
uint32_t eTime = XsTime_getTimeOfDay(NULL, NULL) + timeout;
// uint32_t newLength = 0;
while ((data.size() < maxLength) && (XsTime_getTimeOfDay(NULL, NULL) <= eTime))
{
XsByteArray raw;
if (readData(maxLength - data.size(), raw) != XRV_OK)
return m_lastResult;
data.append(raw);
}
JLTRACE(gJournal, "Read " << data.size() << " of " << maxLength << " bytes");
if (data.size() < maxLength)
return (m_lastResult = XRV_TIMEOUT);
else
return (m_lastResult = XRV_OK);
}
示例2: threadFunc
//.........这里部分代码省略.........
m_fixedBuffer[m_readIdx],
(ULONG)m_fixedBufferSize,
0,
&m_overlapped[m_readIdx]); //lint !e534
m_readIdx = (m_readIdx + 1) % m_oCount;
int64_t tBegin = XsTime_timeStampNow(0);
DWORD waitResult = ::WaitForMultipleObjects(1+m_oCount, handles, FALSE, INFINITE);
#if 0 // not sure if this causes problems, but it should help in catching up
int64_t tEnd = XsTime_timeStampNow(0);
switch (tEnd - tBegin)
{
case 0:
if (++fastCount > m_fastPolicyThreshold && !policyFast)
{
policyFast = true;
// set fast policy
UCHAR enable = TRUE;
m_winUsb.SetPipePolicy(m_usbHandle[1], m_bulkInPipe, IGNORE_SHORT_PACKETS, sizeof(UCHAR), &enable); //lint !e534
}
break;
case 1:
if (fastCount)
--fastCount;
if (policyFast && fastCount <= m_fastPolicyThreshold)
{
// reset policy
policyFast = false;
UCHAR enable = FALSE;
m_winUsb.SetPipePolicy(m_usbHandle[1], m_bulkInPipe, IGNORE_SHORT_PACKETS, sizeof(UCHAR), &enable); //lint !e534
}
break;
default:
fastCount = 0;
if (policyFast)
{
// reset policy
policyFast = false;
UCHAR enable = FALSE;
m_winUsb.SetPipePolicy(m_usbHandle[1], m_bulkInPipe, IGNORE_SHORT_PACKETS, sizeof(UCHAR), &enable); //lint !e534
}
break;
}
#endif
// handle data
switch (waitResult)
{
case WAIT_TIMEOUT:
case WAIT_FAILED:
case WAIT_OBJECT_0:
run = false;
break;
default:
if (waitResult >= WAIT_ABANDONED_0)
{
JLDEBUG(gJournal, "WFMO abandoned: " << (waitResult - WAIT_OBJECT_0));
break;
}
#ifndef XSENS_RELEASE
JLDEBUG(gJournal, "WFMO trigger: " << (waitResult - WAIT_OBJECT_0));
#endif
{
// put data into buffer
int idx = m_readIdx;
DWORD dataRead = 0;
if (!m_winUsb.GetOverlappedResult(m_usbHandle[0], &m_overlapped[idx], &dataRead, FALSE))
{
// error
DWORD err = ::GetLastError();
switch (err)
{
case ERROR_SEM_TIMEOUT:
case ERROR_IO_INCOMPLETE:
//JLDEBUG(gJournal, "m_winUsb.GetOverlappedResult resulted in acceptable windows error " << err);
break;
default:
JLALERT(gJournal, "m_winUsb.GetOverlappedResult resulted in windows error " << err);
run = false;
break;
}
//assert (err == ERROR_IO_INCOMPLETE);
}
else
{
// append unread data to var buffer
JLTRACE(gJournal, "m_winUsb.GetOverlappedResult resulted in " << dataRead << " bytes being read");
XsByteArray ref(&m_fixedBuffer[idx][0], dataRead, XSDF_None);
::EnterCriticalSection(&m_mutex);
m_varBuffer.append(ref);
::LeaveCriticalSection(&m_mutex);
}
} break;
}
}
}