Wow, these methods you proposed made me realize that I was using the
wrong endian method on my UNIX server, it has to be ntohl(). Now I got
it correct, and I am receiving data (bytes) in the correct order.
*>>>: 0 0 0 2 0 10 114 26 0 0 0 51 0 16 242 78
*
Sample data might be 2 1000000 51 2000.56, which could be read in the
data ... somewhat :)*
**Now my question is, how do I get four compact numbers to work with?*
Now I have a series of bytes, but at least in the correct order.
I haven't been able to extract the data using [bytes2any] and [route],
so I prepared a small patch to demonstrate the problem, maybe you can
show me by modifying it?
//Petar
On 11/3/13 2:31 PM, Martin Peach wrote:
On 2013-03-10 17:58, Petar Jercic wrote:
Sorry, I can't use ASCII text as communication method, since I plan to
send large quantities of data at high speed rates, I need to optimize it
as much as possible. Compared to streaming bytes, ASCII is inefficient
up to a several orders of magnitude.
Is there a method for correct endianness in Pure Data, like these C
functions:
ntohs()--"Network to Host Short"
ntohl()--"Network to Host Long"
You can do that with Pd like this (ntohs):
[unpack 0 0]
| |
[* 256] |
| |
[+ ]
|
[ \
or
[unpack 0 0]
| |
| [* 256]
| |
[+ ]
|
[ \
for littleendian.
Floats are harder but still possible. The main difficulty is in
splitting the incoming stream in the right places. (I think ASCII is
not orders of magnitude slower, and it is also less ambiguous).
Martin
On 09/3/13 5:15 PM, Martin Peach wrote:
It's probably safer to get the server to send the numbers as ASCII
text, to avoid disagreements about endianness and floating-point
representation.
Then, to extract the numbers, you could use [moocow/bytes2any] or make
a custom parser using [pdlua].
Martin
On 2013-03-09 10:55, Petar Jercic wrote:
Apparently [netclient] on the Pure Data side cannot receive nothing
else
than ; delimited messages.
So the solution for the problem:
*My question is, is there a way to send something other than string
message to Pure Data, like byte-stream or serialized number stream?
Can
Pure Data receive such messages?*
The solution is to use [tcpclient], it can receive byte-stream data.
Now I have another problem regarding the data read, on how to
convert it
back to usable numbers.
From my UNIX server I am sending a structure
typedef struct {
int var_code;
int sample_time;
int hr;
float hs;
} phy_data;
Sample data might be 2 1000000 51 2000.56
When received and printed in Pure Data I get output like this:
>>>: 2 0 0 0 104 34 9 0 51 0 0 0 235 50 48 69
You can notice number 2 and number 51 clearly, I guess the others are
correct as well. Might be some network inversion of LSB/MSB.
*How can I get these numbers back to a usable format and get them in
separate variables?
*//Petar*
*
_______________________________________________
[email protected] mailing list
UNSUBSCRIBE and account-management ->
http://lists.puredata.info/listinfo/pd-list
#N canvas 854 72 607 550 10;
#X declare -lib maxlib -lib oscx -lib mrpeach;
#X declare -lib mrpeach -lib moocow;
#X msg 85 75 disconnect;
#X text 168 74 <-- disconnect when you are done to free the port;
#X msg 64 48 connect comj3426.com.bth.se 9035;
#X obj 82 186 unpack 0 0 0 0;
#X floatatom 82 209 3 0 0 0 - - -;
#X floatatom 113 209 3 0 0 0 - - -;
#X floatatom 145 209 3 0 0 0 - - -;
#X floatatom 177 209 3 0 0 0 - - -;
#X text 42 208 from;
#X obj 102 160 tgl 15 0 empty empty connected 18 7 0 8 -24198 -13381
-1 0 1;
#X text 113 260 Received messages are output as a list of bytes;
#X obj 62 261 spigot;
#X obj 101 238 tgl 15 0 empty empty enable_print 18 7 0 8 -24198 -13381
-1 0 1;
#X obj 62 290 print >>>;
#X obj 62 134 tcpclient;
#X obj 62 466 import maxlib oscx mrpeach;
#X obj 63 425 import mrpeach moocow;
#X text 278 47 <-- first connect to the server;
#X text 134 290 data is: typedef struct int var_code \; int sample_time
\; int hr \; float hs \; phy_data \;;
#X text 221 206 First number 2 [fixed] in bytes;
#X connect 0 0 14 0;
#X connect 2 0 14 0;
#X connect 3 0 4 0;
#X connect 3 1 5 0;
#X connect 3 2 6 0;
#X connect 3 3 7 0;
#X connect 11 0 13 0;
#X connect 12 0 11 1;
#X connect 14 0 11 0;
#X connect 14 0 3 0;
#X connect 14 2 9 0;
_______________________________________________
[email protected] mailing list
UNSUBSCRIBE and account-management ->
http://lists.puredata.info/listinfo/pd-list