Learn more about the DCT protocol and make this program smarter.

--

Figure out how to handle out-of-order packets.  For example, when
initializing the box, we may or may not get a channel status
after sending initialize_2.  If we wait for a channel status
and one never comes, then there's an unnecessary delay.
It would be better if we could just send our next command,
and while waiting for the acknowledgement for the new command,
properly handle a channel status that shows up.  Currently,
this won't work because sending the new command depends on the
sequence number of the previously received one, so the simple
algorithm gets messed up due to the misordering of the packets
(because the two link directions are asynchronous).
Also, the box may at any time send a 0x10 0x70 which means
it wants to get reinitalized, and we should handle that.

The "proper" thing to do, I think, is:

1) Figure out how to handle sequence numbers when we want to send two
   packets in a row without waiting for a response, etc.  It's more
   than just the simple "increment low nibble" or "increment high
   nibble" algorithm that is currently used.
2) Move all packet receiving to a separate thread that blocks 
   on reading from the serial port.
3) When we send a packet and expect a response, add it to some list or
   queue.
4) When we receive a packet, 
   a) Check to see if the box is requesting reinitialization.
      If so, reinitialize it and re-send all pending packets from 
      the list in #3.
   b) See if it's a response to any of the packets in the list in #3
      and if so, flag that they were answered.
5) In the main code, rather than waiting for a set amount of time for
   a single packet, wait a set amount of time for the flag set in #4.

So checking channel status should be something like

   packet p;
   make_channel_status_packet(&p, 1234);
   pthread_queue_put(send_queue, &p);
   pthread_cond_wait(1234, TIMEOUT);

Man, who ever thought changing a channel could be so hard?
I'm sure there are more complicated things you can do that warrant
having such a complicated protocol, but I really wish they had
provided a secondary, simpler interface for doing simple tasks.
