Search code examples
cconnectionchecksummultiplayerfreertos

Checking for bit errors in a (USB) connection between two systems (for a game)


I'm doing a small project where I have two system communicating with each other. Here's a bit of information that might be useful for this question:

  • The language I am using is C, and the game is PONG;

  • I'm using freeRTOS on both systems. (sys1 and sys2, sys 1 has game logic,display, and controller for player1) and the systems are connected trough USB.

  • One system has all game logic, the other one is just a controller for player 2 and also displays some game data (like which player scored or won).

My question is if it's a good idea to do bit checking (for example checksum) when I'm sending data from sys2 to sys1.This data is what moves player2.

Currently it's only checking if the data received is 'a' , and if it is, the player moves. I'm thinking it might be good to implement something, but I couldn't find what would have the least impact on performance. As it is now, Player 2's movements lag when System2 is listening for data from system1.


Solution

  • If you have actual USB interfaces on both ends, then no need for error checking: the USB frames already include CRCs and USB controllers should ensure the data integrity (unless you're doing isochronous transfers, which are a bad choice for your case). Here is an article with nice pics of USB frames, along with other information:

    https://www.totalphase.com/support/articles/200349256-USB-Background

    If there is a USB-to-Serial on either end, then it's a different story, but most likely you won't need to worry about errors even then.