Brent Crosby wrote: > Wagner: > > 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. > Guys, If you want to do either forwared error control (ie receiver can detect AND correct) or just a simple receiver detects errors (and then either discards or requests re-transmission) you need to be able to locate the packet! This is called framing. Check out any computer networks text - the issue cited above (jumping into the middle of a packet) is trivially solved by framing - look for start-of-frame and discard everything till you get one. This is how all networking protocols work. As in all life, don't re-invent wheels where this ain't required. I thought the original poster was asking about CRC's for really small frames - you might be better off with forward error control - if you use hamming codes (for example) and have 12 bits of data you need an additional 5 bits to be able to correct single bit errors. Again, get thee to a text book. Hamming codes and CRCs are trivially implemented (even my students could do this...) CRCs require little more than XOR's (and you do this byte by byte as you receive) and Hamming codes are just parity computations. Andy Tanenbaum's book on Computer Networks has a pretty readable description of both. Anyway my $0.02 Cheers /Kevin ----------- Kevin J. Maciunas Net: kevin@cs.adelaide.edu.au Dept. of Computer Science Ph : +61 8 8303 5845 University of Adelaide Fax: +61 8 8303 4366 Adelaide 5005 SOUTH AUSTRALIA