How to ensure data integrity during transmission

  1. XMODEM. It‘s old, it‘s bad, but it is widely supported both in hardware and in software, with libraries available for literally every language and market niche.
  2. HDLC - High-Level Data Link Control. It‘s the protocol which has fathered lots of reliable protocols over the last 3 decades, including the TCP/IP. You can‘t use it directly, but it is a template how to develop your own protocol. Basic premise is:
    • every data byte (or packet) is numbered
    • both sides of communication maintain locally two numbers: last received and last sent
    • every packet contains the copy of two number
    • every successful transmission is confirmed by sending back an empty (or not) packet with the updated numbers
    • if transmission is not confirmed within some timeout, send again.

    For special handling (synchronization) add flags to the packet (often only one bit is sufficient, to tell that the packet is special and use). And do not forget the CRC.

Neither of the protocols has any kind of session support. But you can introduce one by simply adding another layer - a simple state machine and a timer:

  • session starts with a special packet
  • there should be at least one (potentially empty) packet within specified timeout
  • if this side hasn‘t sent a packet within the timeout/2, send an empty packet
  • if there was no packet seen from the other side of communication within the timeout, the session has been termianted
  • one can use another special packet for graceful session termination

That is as simple as session control can get.

=----------------from StackOverflow  Dummy00001

If you want reliable data transfer, there is absolutely no way to use any USB-to-serial bridge correctly without hardware flow control, and without dedicating at least all remaining RAM in your microcontroller as the serial buffer (or at least until you can store ~1s worth of data).

I‘ve been using FTDI devices since FT232AM was a hot new thing, and here‘s how I implement them:

  1. (At least) four lines go between the bridge and the MCU: RXD, TXD, RTS#, CTS#.
  2. Flow control is enabled on the PC side of things.
  3. Flow control is enabled on the MCU side of things.
  4. MCU code is only sending communications when it can fit a complete reply packet into the buffer. Otherwise, it lets the PC side of it time out and retry the request. For requests that stream data back, the entire frame is dropped if it can‘t fit in the transmit buffer at the time the frame is ready.
  5. If you wish the PC to be reliably notified of new data, say every number of completesamples/frames, you must use event characters to flush the FTDI buffers to the hist, and encode your data. HDLC works great for that purpose and is documented in free standards (RFCs and ITU X and Q series - all free!).
  6. The VCP driver, or the D2XX port bring-up is set up to have transfer sizes and latencies set for the needs of the application.
  7. The communication protocol is framed, with CRCs. I usually use a cut-down version if X.25/Q.921/HDLC, limited to SNRM(E) mode for simple "dumb" command-and-respond devices, and SABM(E) for devices that stream data.

The size of FTDI buffers is immaterial, your MCU should have at least an order of magnitude more storage available to buffer things.

If you‘re running hard real-time code, such as signal processing, make sure that you account for the overhead of lots of transmit interrupts running "back-to-back". Once the FTDI device purges its buffers after a USB transfer, and indicates that it‘s ready to receive more data from your MCU, your code can potentially transmit a full FTDI buffer‘s worth of data at once.

If you‘re close to running out of cycles in your realtime code, you can use a timer as a source of transmit interrupts instead of the UART interrupt. You can then set the timer rate much lower than the UART speed. This allows you to pace the transmission slower without lowering the baudrate. If you‘re running in setup/preoperational mode or with lower real-time task load, you can then trivially raise the transmit rate without changing the baudrate. You can use a similar trick to pace the receives by flipping the RTS# output on the MCU under timer control. Of course this isn‘t a problem is you use DMA or a sufficiently fast MCU.

If you‘re out of timers, note that many other peripherals can also be repurposed as a source of timer interrupts.

This advice applies no matter what is the USB host. --from StackOverFlow Kuba Ober

时间: 2025-01-08 00:49:05

How to ensure data integrity during transmission的相关文章

[PostgreSQL] Use Foreign Keys to Ensure Data Integrity in Postgres

Every movie needs a director and every rented movie needs to exist in the store. How do we make sure something in another table exists before inserting new data? This lesson will teach us about foreign keys and references. CREATE TABLE directors ( id

[svc]对称加密/非对称加密细枝末节-如何做到数据传输的authentication/data integrity/confidentiality(私密)

对称/非对称/混合加密的冷知识 数据在互联网上传输,要考虑安全性. 讲到安全,要从三方面考虑: 1.authentication 每一个IP包的认证,确保合法源的数据 2.data integrity 验证数据完整性,保证在传输过程中没有被人为改动 3.confidentiality (私密性)数据包的加密 下面谈谈如何对数据加密. 于是有了非对称加密 对称加密 对称加密算法---使用一把密匙来对信息提供安全的保护.只有一个密匙,即用来加密,也用来解密 特点: - 1.速度快 - 2.密文紧凑

数据完整性(Data Integrity)笔记

因数据库存储数据要持之以恒,数据库中的表需要一些方法验证各种数据类型.不仅仅局限于数据类型,还有唯一值,值的范围,或者某列的值和另外一个表中的列匹配. 当你在定义表的时候其用这些数据验证方法.这叫做声明数据完整性.也就是我们说的表约束. USE tempdb GO CREATE TABLE s ( sid VARCHAR(20) , sname VARCHAR(20) , ssex VARCHAR(2) CHECK ( ssex = '男' OR ssex = '女' ) DEFAULT '男'

Java Secure Socket Extension (JSSE) Reference Guide

Skip to Content Oracle Technology Network Software Downloads Documentation Search Java Secure Socket Extension (JSSE) Reference Guide This guide covers the following topics: Skip Navigation Links Introduction Features and Benefits JSSE Standard API S

对称加密与非对称加密

(一)对称加密(Symmetric Cryptography) 对称加密是最快速.最简单的一种加密方式,加密(encryption)与解密(decryption)用的是同样的密钥(secret key).对称加密有很多种算法,由于它效率很高,所以被广泛使用在很多加密协议的核心当中. 对称加密通常使用的是相对较小的密钥,一般小于256 bit.因为密钥越大,加密越强,但加密与解密的过程越慢.如果你只用1 bit来做这个密钥,那黑客们可以先试着用0来解密,不行的话就再用1解:但如果你的密钥有1 MB

STM32 DFU -- Device Firmware Upgrade

DFU Class Requests Get Status The Host employs the DFU_GETSTATUS request to facilitate synchronization with the device. This status gives information on the execution of the previous request: in progress/OK/Fail/... The device responds to the DFU_GET

Apache Avro? 1.7.6 Specification

Apache Avro? 1.7.6 Specification Introduction Schema Declaration Primitive Types Complex Types Records Enums Arrays Maps Unions Fixed Names Aliases Data Serialization Encodings Binary Encoding Primitive Types Complex Types JSON Encoding Sort Order Ob

Clustered filesystem with membership version support

A computer system with read/write access to storage devices creates a snapshot of a data volume at a point in time while continuing to accept access requests to the mirrored data volume by copying before making changes to the base data volume. Multip

对称加密和不对称加密原理

私钥加密(对称加密 symmetric cryptography):私钥加密算法使用单个私钥来加密和解密数据.由于具有密钥的任意一方都可以使用该密钥解密数据,因此必须保护密钥不被未经授权的代理得到.私钥加密又称为对称加密,因为同一密钥既用于加密又用于解密.私钥加密算法非常快(与公钥算法相比),特别适用于对较大的数据流执行加密转换.Well-known secret key cryptographic algorithms include the Data Encryption Standard