Date: Tue, 24 Aug 1999 15:11:51 -0700 From: Brent Crosby Subject: Re: [OT] CRCs on short packets Say you have a 10-byte fixed length packet. Your receiving routine would typically wait until 10 bytes are in its buffer, then apply the CRC routine. If the CRC does not match, you might empty the buffer, saying that there is garbage coming in, not packets. Well, the routine may not ever synchronize if you do this. As an example, say the transmitter is always sending out valid 10-byte packets. What if the receiver wakes up in the middle of a packet? It receives 5 bytes from the end of the first packet, then 5 bytes from the start of the next packet, applies the CRC, discards the data and then repeats the whole process, staying out of sync, even though there are good packets coming in. The trick is to only discard one byte instead of the whole buffer or a whole packet's worth of bytes. Then the receiver essentially has a sliding 10-byte window, whose CRC will only match up if there is a valid packet in the 10 bytes. Of course, once you do get valid packet, you take the whole packet out at once. Maybe this is obvious to everyone, but it had me stumped for a bit--once I got out of sync it would reject all packets. Brent and Wagner, In my dealings with data packets, I have always included a synchronizing byte. My receiving routine would wake up and then check every byte it received until a synchronizing byte came in. Then it would start reading the number of bytes required to make a packet. In this case, my interpretation of the suggestion was to save the packet that you received with an error and then call for another transmission. Assuming the CRC failed on the second packet also, you would then compare the two packets to determine which bytes were different. Assuming that the bytes that matched were correct, you could mix and match the the non-matching bytes until you got a complete packet. My 2cents, Paul Kolesnikoff