c - 如何识别 USB ISO 传输中用于 CRC(校验和)的数据字节?

标签 c usb libusb

我正在使用 libusb 从 USB 音频设备实时获取数据。我的最大数据包大小为 196 字节。我知道其中 4 个字节是为校验和添加的。我想识别用于校验和的字节,这样我就可以只存储传输的有用数据,但我有一些疑问:

1) 这些字节是添加在数据包的开头还是末尾?

2)这些字节有保留值吗?

3) 如果在传输中丢失一些数据字节。对于用于校验和的字节,我应该考虑哪些因素?

编辑1

我有这些疑问,因为我的特定设备有一个接口(interface)和替代设置,适用于 48 KHz、2 channel 、16 位深度和 196 字节最大数据包大小的采样率。

因此有 48 个样本 * 2 个两个 channel * 2 个字节 = 192 个字节

那么我的数据包应该是 192 字节,但是当我将设备设置为与该接口(interface)和 alt 设置一起使用时,我开始接收 196 字节的数据包。 OUT ISO 端点的相应接口(interface)和替代设置工作在 48 KHz、2 channel 、16 位深度的采样率和 192 字节的最大数据包大小。

4) 如果这些字节不是来自校验和,为什么要添加这些字节?

最佳答案

enter image description here

我知道其中的 4 个字节是为校验和添加的

Wrong. CRC is 2 bytes for data packet and 5 bits for token packet. Also CRC is never stored/forwarded in/to the user buffer. It gets stripped by the controller during verification of the CRC. So you are not going to see the CRC at all. But if you still want to see the CRC, attach a USB packet analyzer and have a look at the trace.

1) 这些字节是添加在数据包的开头还是末尾?

2 bytes are added at the end.

2)这些字节有保留值吗?

No. Its calculated based on the content of the data packet

3) 如果在传输中丢失一些数据字节。对于用于校验和的字节,我应该考虑哪些因素?

If you are losing some bytes after CRC is already calculated, you are going to get USB transaction error (CRC mismatch from the host). The same transaction will be retried by the host.

PS - 我假设您使用的是高速设备

关于c - 如何识别 USB ISO 传输中用于 CRC(校验和)的数据字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44787524/

相关文章:

c - c中的嵌套链接列表

ios - 如何使用 MFI 配件的 USB 协议(protocol)进行通信

python - 在 VirtualBox 中运行的 Windows 10 上检测 USB 输入设备的插入/移除

usb - 嵌入式Linux USB设备检测端口和地址

python - 使用Python从USB获取数据

c - 结构(搜索)

c++ - 多个文件出现错误 C2027 : use of undefined type,

c# - 如何使用C#删除USB驱动器

linux - 用于 Linux 的 hidapi 与 libusb

c - 在C中查找数组中索引的地址