Hi everybody,
I got a little problem reading some streaming data I recieve via socket. It is about a motion capture system, giving me position and orientation of a tracked body.
The developer of the system published a C++ sample client, that recieves the streamed data from the tracking-application. I had a look at it and tried to “convert” it into python.
At this point, I have to admint, that I am not really a programmer! I don’t know much about Python, and even less about C++. So I am not always sure what I am doing here :eyebrowlift2:
I managed to recieve the data blocks, but they look really messed up.
Nothing special so far:
import socket
import struct
ip = "127.0.0.1"
port = 1511
multicastAdd = "239.255.42.99"
mreq = struct.pack('4sl', socket.inet_aton(multicastAdd), socket.INADDR_ANY)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((ip,port))
s.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
data, addr = s.recvfrom(10240)
print data
But here you can see how the data looks in the C++ sample (only the values are from the data paket, the text is generated by the client), and what I get with python:
http://img685.imageshack.us/img685/4614/datastream.jpg
For me, it looks kind of encoded. I had a look at the C++ sample, and could not find any hint of “formant convertion” (e.g. host to network). But finally I found an “unpack” function which seems to read the data bit by bit(?). I am not sure how that pointer and reference stuff in C++ is working, and I also have no idea how to convert that to python. I would be really happy, if someone could help me out with this.
Here is a short sample from the unpack function:
void Unpack(char* pData)
{
char *ptr = pData;
printf("Begin Packet
-------
");
// message ID
int MessageID = 0;
memcpy(&MessageID, ptr, 2); ptr += 2;
printf("Message ID : %d
", MessageID);
// size
int nBytes = 0;
memcpy(&nBytes, ptr, 2); ptr += 2;
printf("Byte count : %d
", nBytes);
...
I would like to attach the complete .cpp, but for some reason the posting rules tell me, that I am not allowed to post attachments.
Would be great if anybody got an idea how to handle this!
Thanks!
Quen