Fix many, many bugs in sequence numbers, also implement the automatic network tuning

Implement automatic tuning;  fix gratuitous errors in the sequence
number handling.  COMPATIBILITY BREAK:  requires at least firmware
v0.21 since there was a bug in that too (whoops, casting an int to a
char is bad mmkay?)