I have udp packet which sends 12 objects positions in each packets in hex format + some headers
I need to convert hex to numbers and save the value into an array.
the packet look like this :
0000 00 16 cf 5c 0d c2 ec 55 f9 44 c8 9b 08 00 45 00 ...\...U .D....E.
0010 00 dc 1c f9 00 00 80 11 9b 9a c0 a8 00 16 c0 a8 ........ ........
0020 00 17 04 bd 0b b8 00 c8 e5 1a 40 46 6c cc c0 00 ........ ..@Fl...
0030 00 00 3f e6 66 66 60 00 00 00 40 62 1e 66 60 00 ..?.ff`.
..@b.f`.
0040 00 00 bf c9 99 99 a0 00 00 00 40 4d c0 00 00 00 ........ ..@M....
0050 00 00 40 0f 33 33 40 00 00 00 40 6f e0 00 00 00 ..@.33@. ..@o....
0060 00 00 40 59 80 00 00 00 00 00 40 46 6c cc c0 00 ..@Y.... ..@Fl...
0070 00 00 3f d9 99 99 a0 00 00 00 40 6f e0 00 00 00 ..?..... ..@o....
0080 00 00 40 59 80 00 00 00 00 00 40 48 b3 33 40 00 ..@Y.... ..@H.3@.
0090 00 00 3f f4 cc cc c0 00 00 00 40 50 e9 99 a0 00 ..?..... ..@P....
00a0 00 00 40 11 cc cc c0 00 00 00 40 6f e0 00 00 00 ..@..... ..@o....
00b0 00 00 c0 39 99 99 a0 00 00 00 40 6f e0 00 00 00 ...9.... ..@o....
00c0 00 00 c0 39 99 99 a0 00 00 00 40 6f e0 00 00 00 ...9.... ..@o....
00d0 00 00 c0 39 99 99 a0 00 00 00 40 6f e0 00 00 00 ...9.... ..@o....
00e0 00 00 c0 39 99 99 a0 00 00 00
now , I should convert 16 byte from the end of each of the packets and this is the y coordinates of object 12 .
the next 16 bytes from the end is for x coordinates of object 12
and I want to put this 2 into array12.
and the same things for object 11 ,10 , .... 1
it seems really complicated , how can I do this ?
this is my UDP code that receive this positions :
import hypermedia.net.*;
int PORT_RX=3000; //port
String HOST_IP="192.168.0.21"; //
UDP udp;
String receivedFromUDP = "";
void setup() {
size(400,400);
udp= new UDP(this,PORT_RX,HOST_IP);
udp.log(true);
udp.listen(true);
super.start();
}
void draw() {
background(0);
text(receivedFromUDP, 50, 50);
}
void receive(byte[] data, String HOST_IP, int PORT_RX) {
receivedFromUDP ="";
for (int i = 0; i < data.length; i++) {
receivedFromUDP += str(data[i]) + " ";
}
println(data);
}
1