Pages: [1]   Go Down
Author Topic: Wireless xfer headers and trailers  (Read 430 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I need some orientation for transmitting small data packets between AVRs. I need my transmitter to constantly transmit 3 bytes of data, and I need my receiver to constantly receive those bytes.

How am I to organize this? I guessed I would have a header byte and a trailer of a one-byte checksum.

But that leaves me in doubt: what if all three bytes in the packet body are the same as the header byte, and the receiver gets caught in a loop of always guessing that one of the body bytes is the header?
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27418
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If the prior message had ended with a valid checksum, the next message could be treated as coming in as all good data, yes?
So the data matching the header would not matter - read the header byte, if good read the next three, do the checksum caclulation and see if it matches the checksum byte.

Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't think so.

Suppose the receiver tunes in in time to catch the first byte of the body, interprets it as a header (because it's possible that the body byte equals the header value), then interprets the header as checksum, finds that the checksum doesn't validate the body, so it listens for the next byte that equals the header value, but it ends up right where it started: interpreting the first body byte as the header. So we end up with an infinite loop of looking for a valid packet, never finding it.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27418
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Disagree.
Say header is AA, body whatever, checksum is the sum of the 4 bytes, rolled over and upper bits fallen off.

So AA AA x1 y1 CC,  AA x2 y2 z2 CC,  AA x3 y3 z3 CC

And by coincidence things start up at just the right time so
that first AA is missed;
AA x1 y1 CC AA get processed and discarded due to bad checksum
then x2  y2 z2 CC all get ignored because no AA came in
AA x3 y3 z3 CC arrive & get processed and get you back in sync
So at worst two bytes are lost.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That appears to work if the packet changes each time, but I'm going to send one packet without changing it for minutes on end, during which time that packet may never be received.

 AA AA x1 y1 CC,  AA AA x1 y1 CC,  AA AA x1 y1 CC, etc.

If the receiver interprets the 2nd byte (2nd AA) as the header, it shall continue to interpret the 2nd byte of every subsequent packet as the header until the packet changes (and there is no AA in the body or trailer). Right?
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27418
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Then do something to force the  starting header to move over until you get in sync.
If a packet comes in and fails the checksum, ignore that packet, ignore the  next byte to come in, try the next set:

- - AA x1 y1 CC,  AA  fails checksum, ignore it
skip a byte (AA), then process:
x1 y1 CC,  AA AA  fails checksum, ignore it
skip a byte (x1), then process:
y1 CC,  AA AA x1   fails checksum, ignore it
skip a byte (y1), then process:
CC,  AA AA x1 y1   fails checksum, ignore it
skip a byte (CC), then process:
AA AA x1 y1 CC  - back in sync




 
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks.
Logged

Pages: [1]   Go Up
Jump to: