本文整理汇总了C++中Port::FullRead方法的典型用法代码示例。如果您正苦于以下问题:C++ Port::FullRead方法的具体用法?C++ Port::FullRead怎么用?C++ Port::FullRead使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Port
的用法示例。
在下文中一共展示了Port::FullRead方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strtoul
/**
* Read three bytes from the port: an asterisk and two hexadecimals
* comprising the given checksum.
*/
static bool
ExpectChecksum(Port &port, uint8_t checksum, OperationEnvironment &env)
{
char data[4];
if (!port.FullRead(data, 3, env, 500) || data[0] != '*')
return false;
data[3] = '\0';
return strtoul(data + 1, nullptr, 16) == checksum;
}
示例2: sizeof
int
CAI302::ReadLargeReply(Port &port, void *buffer, unsigned max_size,
OperationEnvironment &env, unsigned timeout_ms)
{
unsigned char header[5];
if (!port.FullRead(header, sizeof(header), env, timeout_ms))
return -1;
if (header[0] == 0x09 && header[1] >= 0x10 &&
header[3] == 0x0d && header[4] == 0x0a) {
/* this is probably a "short" reply with an upload prompt, due to
a transmission error - now see if the remaining 4 bytes contain
the "up>" prompt */
char prompt[4];
if (port.Read(prompt, 4) == 4 && prompt[0] == 0x0a &&
prompt[1] == 'u' && prompt[2] == 'p' && prompt[3] == '>')
return -2;
return -1;
}
unsigned size = (header[0] << 8) | header[1];
if (size < sizeof(header))
return -1;
size -= sizeof(header);
if (size > max_size)
size = max_size;
if (!port.FullRead(buffer, size, env, timeout_ms))
return -1;
// XXX verify the checksum
if (size < max_size) {
/* fill the rest with zeroes */
char *p = (char *)buffer;
std::fill(p + size, p + max_size, 0);
}
return size;
}