What would manchester code achieve?
It solves a problem with filtering a digital signal. If you look at stream of digital data it occasionally has blocks of all ones or all zeros and these blocks could be very long. This creates a problem as it means the frequency of your data is quite variable.
It makes it hard to try and filter your signal vs the noise.
eg, a 4kHz data signal of 1111000011110000 looks the same as a 2khz data signal of 11001100.
So you can't just band pass filter around your data clock rate or you will kill any blocks of ones or zeros in your data
Manchester code results in a signal which changes state very often. You never get prolonged high/low states even when you're sending prolonged low or high data.
Google/youtube it if you need to know in detail but basically it works by using the falling/rising edges to represent data rather than the high/low state.
The whole packet loss thing: Yeah, seriously, I'm very new to that stuff, hence why I'm writing in Beginners. Anywhere I could learn about that? What would manchester code achieve? Any example code on how to make sure data is transmitted accurately?
The quick/easy way is to decide on a packet structure and length.
Lets say all packets are 8 bytes long.
Lets say all packets start with SS
Let say all packets have a checksum byte on the end which we call C
And some random data we want to send = 12345
Then a packet would look like
SS12345C
The checksum byte C is calculated by doing an XOR to all bytes in sequence.
so S xor S xor 1 xor 2 xor 3 xor 4 xor 5 = C
The xor operation is a single ^ mark in the C language so real easy to do in code. You can just loop through and calculate what C should be. Or you can calculate the checksum as the bytes come in.
If you get a packet and calculate C should be 55 but 23 was sent in the packet then you know this packet is corrupt.
Note: A checksum will detect most errors but you can get corrupt packets that pass the check sometimes. For better error detection you can use a two byte checksum, one checksum for odd numbers in your packet and one for even.
If you want more reassurance look at a CRC code, however this is more complicated.
For detecting when packets arrive just look for two "S" chars then start buffering the data in an 8byte array until you get the entire frame. Then you can either pass the array to a function to do stuff. or ignore it and clear the buffer if the checksum is bad.