State machine based serial parser, and also a lot of debugging code.