Understanding buffers - Node JS Library to fly with PS3 controller


Hey all, I’m working on a node js library to allow you to fly minidrones with DualShock playstation controllers. I was able to repurpose a bunch of stuff from other node libraries, and it’s working really well. Flying with analog controls is way better than on a touch screen.

I’d like to extend the functionality and fix a few bugs. What’s the best resource to understand buffers and how to write to characteristics over the BT network? I see some of the documentation in the protocol docs but I’m having trouble grasping how to apply the docs to actual code.

For example the takeoff command looks like this, where this.steps is the sequence number, and COMMAND_KEY is ‘fa0c’.

let buffer = new Buffer([0x02, ++this.steps[COMMAND_KEY] & 0xFF, 0x02, 0x00, 0x01, 0x00]);
this.write(COMMAND_KEY, buffer);

The rest I’m a little spacey on. Basically can someone walk me through interpreting the docs, creating buffers, and writing them to actual JS code?



You have a complete explanation of the protocols in this document.

You can see at page 14 the global layout of a buffer ( type + seq + data ), and at page 28 and after the description of the ARCommand format ( project + class + command [ + args ] ).
The description of all commands is available in the libARCommands sources as xml files. For Rolling Spider and derivatives, the commands are located in the common and minidrones files.

In this example, you can see that the takeoff command is in minidrone project (project_id=2), in the piloting class (class_id=0), iis the second command in the class (command_id=1), and has no arguments, so its binary representation is indeed 0x02 0x00 0x0001.



This was really helpful, thank you! I cleaned up a bunch of stuff in my bluetooth code and added the ability to take a picture.