I created a basic wireless system between two microcontrollers. Each uses the on-chip UART and an HM-TRP radio module to communicate with each other. Eventually I'll have a master-slave setup where many systems are slaves and one is master, but I wont have more than 40 units total.
My Idea
My packet format is basically 16-bytes long, and is similar to a UDP packet, but different in the following ways:
1st byte is an 8-bit address of the local machine.
2nd byte is an 8-bit address of the remote machine.
3rd byte through 15th byte is data
16th byte is 8-bit CRC checksum of all previous bytes.
With this setup, there could be big delays if any hardware is unable to receive any byte of data in time. I'll explain in terms of data.
Suppose Master (ID #34) sends to a slave (ID #12) the full data out numerous times in the correct format and assume FE is the correct checksum. Example:
12 34 01 02 03 04 05 06 07 08 09 10 11 12 13 FE
Now if slave is on and received nothing before this entire packet and the connection is excellent, there would be no problem. But lets say that the receiver didn't receive the first two bytes because of a network (wireless) error. It then receives:
01 02 03 04 05 06 07 08 09 10 11 12 13 FE 12 34
Since my packet format treats the first 2 bytes as machine addresses and the 13 after as data, then the receiver would discard the above data because it picked up 34 as the checksum instead of the expected FE value.
My new idea
Because I have less than 128 machines I'm working with, I thought of stripping one bit off each byte of data and fitting the data in the remaining 7 bits, then using the remaining bit as a flag to indicate start of data. Here's an example in binary:
0mmmmmmm 1rrrrrrr 1ddddddd 1ddddddd 1ddddddd ..... 1ddddddd 1ccccccc
where the m is local address in binary, r is remote address, d is data and c is checksum.
The advantage I see to this method is that the receiver knows not to start anything until it receives 0 as the most significant bit.
Question is, which of these formats are best for guaranteed wireless transmission over such a link and why? and if the formats I have described are not the best, then which format is better?
Remember, I'm working with 8-bit microcontrollers (specifically chip AT89C2051) so my resources are very limited.