I'm working on a laser tag project, and need some help. I'm using hardware serial to transmit/receive messages over IR (which works but sends garbled data occasionally) but have no idea how to implement a protocol to pass messages between units. Basicly I need to send an ID (team and player number), a command (like fire, medic, etc), and data (amount of damage, etc.). I'll probably use Serial.write() to send raw bytes, but I need a reliable way to send and recieve these, and to detect if a message is corrupted. Any suggestions?
Look to use a modulated IR beam for the basic communications feeding from the serial port at a much lower rate than the modulation.
Then you need a protocol which divides the data into packets with one or more check sum. You could even have an element of error correction, this is where you effectively send the same data three or more times with different encoding and check sums and you get a vote on the right answer. This can cope with some garbling.
The better the error correction the less efficient it is.
Thanks for the reply. After some tinkering, I have a decent protocol using raw bytes (not ASCII). What is the max byte size over serial? I.E. can I send the number 999 over serial in one byte? Also, what would be a good way to implement a checksum? Add all the bytes in a message and append the answer to the end? Thanks!