mje-nz / python_natnet

Python NatNet client library, supporting protocol version 3 (Motive version 2.0).
BSD 3-Clause "New" or "Revised" License
14 stars 15 forks source link

Remote Remote Requests/Commands #2

Open Gnarlywhale opened 6 years ago

Gnarlywhale commented 6 years ago

I've poked around the code a bit and there doesn't seem to be an implementation of sending remote requests/commands as listed on the natnet docs (c# example): https://v20.wiki.optitrack.com/index.php?title=NatNet:_Remote_Requests/Commands#ErrorCode

Is this at all possible?

If not I'm happy to get started implementing it if you could point me in the right direction on where to get started making changes.

mje-nz commented 6 years ago

Hey, thanks for the request. I haven't implemented those as I've never needed them, but it shouldn't be too tricky.

First, get set up with some other application that allows you to send them (e.g. probably WinFormsSample from the NatNet SDK), capture some network traffic with Wireshark or similar, find the request packet and the response packet (they should start with 0x02 0x00 and 0x03 0x00), and dump them to files (as I have for each packet type in test_data/).

Then you can implement a RequestMessage and ResponseMessage class in the protocol module (like the other message classes), using your dumped packets as test data for unit testing.

At that point you should be able to test your code against Motive by sending a command with Connection.send_message and blocking until you get a response with Connection.wait_for_message_with_id.

From there it would just be a matter of adding a send_command method to Client and a handling responses in Client.run_once.

Out of interest, what do you want to use requests or commmands for?

Gnarlywhale commented 6 years ago

Thanks for the pointers, hopefully I'll have some time in the next couple of weeks to get started with a proper implementation.

I'm currently running motive along side an eye tracking system and lab streaming layer for synchronization. I wrote a basic python tool to control each system simultaneously, rather than having to manually trigger and update everything (start/stop recording, update save names, etc). Up to now I was able to get by with hijacking control of the GUIs themselves using pywinauto, but it wasn't worth it to update this method to working with motive 2.0 (we were using 1.9 previously and the UI changed a lot), and we'll soon be adding in more data streams, so I figured I'd do it properly this time.