felixge/node-ar-drone — pull request #76 by wiseman (2013-10-14 20:32:20+00:00)
Title: Added handling of ACK for config commands.

Sending this for discussion/review. I've only done minimal testing so far; I wanted to get some feedback before spending more time on it.

We now have two classes of commands: blocking and non-blocking. `CONFIG` is blocking, all others are non-blocking. When a blocking command is sent, no other blocking commands will be sent until an ACK is received (and cleared) from the AR.Drone.

Blocking commands can also have a callback & a timeout value (currently defaults to 50 ms). The callback is called when the ACK is received or when a timeout occurred (an error object is passed in the timeout case). For example,

client.config(
'general:navdata_demo', 'TRUE',
{
timeout: 100,
callback: function(error) {
if (error) {
console.log('Oh no: ' + error);
} else {
console.log('FINALLY');
}
}
});

I'm thinking of adding a `numRetries` option to blocking commands that would cause them to automatically be re-sent for the first N timeouts before signaling an error.

Handling CONFIG commands in a separate queue will help with implementation of multiconfig, which I am planning on doing next.

Note that sequence numbers are now generated in UdpControl, and there is another legal navdata header value (which may have additional data included with it, but the existing parser seems to at least successfully parse what's there).

See issue #33, issue #47, and https://gist.github.com/bkw/4416785 for reference.