Tracking Tool doesn't like my UDP client

Post Reply
Q2LNY
Posts: 2
Joined: Fri Oct 07, 2011 4:28 pm

Tracking Tool doesn't like my UDP client

Post by Q2LNY »

Hi Community

We own a 12-camera setup and recently we have been trying to streamline our software chain from Tracking tool(PC) to our media computer(MAC). Here comes the problem, today I tried to read the UDP packets from Tracking Tool multicast with a client I wrote in Processing (Processing.org) and its UDP library. I have used the Processing UDP client in other projects and it works just fine. However, when I use the same setup to read data coming from Tracking tool I got a bunch of gibberish instead. Anyone has any idea why this is happening?

This is what I did in code when I receive data from the port:

void receive(byte[] data){
String k="";
for(int i=0;i<data.length;i++){
k+=char(data);
}
}

I thought it might be the data type? need insights!


Thanks,
Kyle
morgan
NaturalPoint Employee
NaturalPoint Employee
Posts: 199
Joined: Tue Jun 24, 2008 2:01 pm
Location: Corvallis, OR, USA
Contact:

Re: Tracking Tool doesn't like my UDP client

Post by morgan »

Not sure which streaming protocol you are using from TrackingTools (NatNet, VRPN, or trackD), but for NatNet:

A NatNet data packet contains mostly multi-byte values, such as 4 byte integers. Converting each byte to a string equivalent, then concatenating, will not work here.

For a given frame of data's byte stream (packet), you will need to know the "bitstream syntax", which is the order of values in the packet and the length/data type of each value, in bytes. Knowing this you can then convert each byte "blob" to its correct value.

The PacketClient.cpp sample in the NatNet SDK shows how to decode the bitstream correctly. This example is in C++ but should port to any other language, such as C#.

hope this helps,

morgan
Q2LNY
Posts: 2
Joined: Fri Oct 07, 2011 4:28 pm

Re: Tracking Tool doesn't like my UDP client

Post by Q2LNY »

Hi Morgan

Thanks for your help! You just saved our installation and dozens of hungery kids. However, I couldn't find an solution with Processing IDE so I wrote everything in UNITY with C# it works nicely. Really appreciate you assistance and point to the PacketClient.cpp. If you know a way to read multi-byte data with Java please do share, thanks again!!



Best,
Kyle
morgan
NaturalPoint Employee
NaturalPoint Employee
Posts: 199
Joined: Tue Jun 24, 2008 2:01 pm
Location: Corvallis, OR, USA
Contact:

Re: Tracking Tool doesn't like my UDP client

Post by morgan »

Hey Kyle,

glad you've got it working.

If possible it would be great if you could share your unity script here with the forum - we have several unity users and other direct depacketizers in the .NET world that could use it a good example.

In general, under C# one approach is to use Buffer.BlockCopy method - something like:

Code: Select all

byte[] b = new byte[1024];
int iRet = s.Receive(b);
Console.WriteLine("Received Bytes : {0}", iRet);
int offset = 0;
int[] iData = new int[100];
float[] fData = new float[500];
Buffer.BlockCopy(b, offset, iData, 0, 2); offset += 2;
Console.WriteLine("Message ID : {0}", iData[0]);
in JAVA, you might try using ByteBuffer class which should have the methods you need. There may be endian issue when using JAVA, you you may need to flip them. I'm afraid I'm not well versed in JAVA - so if anyone else has an appraoch please chime in!

I should also note this is only for folks who need to depacketize the NatNet packets themselves. The NatNet SDK also provides a managed wrapper class library (DLL) for .NET users that can be simply be added to your VB/C# .NET projects - see the Winforms example in the NatNet SDK.

Morgan
Post Reply