树莓派网络配置与应用全解析
1. USB 数据传输函数 bulk_write
在数据传输过程中, bulk_write 函数起着关键作用。它能够确保完整的消息被传输,即便消息是以小数据块的形式发送。以下是 controlusb.cpp 中的 bulk_write 函数代码:
0133: static int
0134: bulk_write(
0135: libusb_device_handle *hdev,
0136: unsigned char endpoint,
0137: void *buffer,
0138: int buflen,
0139: unsigned timeout_ms
0140: ) {
0141: unsigned char *bufp = (unsigned char*)buffer;
0142: int rc, xlen = 0, total = 0;
0143:
0144: assert(!(endpoint & 0x80));
0145:
0146: for (;;) {
0147: rc = libusb_bulk_transfer(hdev,endpoint,
bufp,buflen,&xlen,timeout_ms);
0148: if ( rc == 0 || rc == LIBUSB_ERROR_TIMEOUT ) {
0149: total += xlen;
0150:
超级会员免费看
订阅专栏 解锁全文
55

被折叠的 条评论
为什么被折叠?



