Azzera filtri
Azzera filtri

Want to omit some values from TCP packet

1 visualizzazione (ultimi 30 giorni)
I have successfully created the tcp connection between processing and matlab. I am using oscp5 library for that. I am sending an array containing 3 float values from processing.
But in Matlab, i am getting 5 extra values. Please advise how i can omit these values.
Please note that i can't use another library.
Also, someone suggest me, while creating message, i have assigned it a label "/test". When matlab's server gets the message, it will read this as well as the data in your package as assembled by oscP5. So, I have to teach matlab how to interpret that data. Hence, I need to go to the oscP5 website and review java docs and the source code to understand the packaging format. Here the link
I have no idea about this. If any of you guys aware about this, please help me out.
You can see the code below.
-------------Processing Code-------------
import oscP5.*;
import netP5.*;
OscMessage myMessage;
OscP5 oscP5tcpClient;
void setup() {
size(640, 360);
oscP5tcpClient = new OscP5( this, "141.44.219.204", 1234, OscP5.TCP);
}
void draw() {
background(255);
OscMessage myMessage = new OscMessage("test\");
myMessage.add(new float[] {123.2, 134.5, 52.5}); ==>> Sent Message
oscP5tcpClient.send(myMessage);
print(50+sin(a)*40.0);
}
-----------------------------------------------------------------
--------------------------MATLAB Code----------------------------
>> tcpipServer = tcpip('141.44.219.161',1234,'NetworkRole','Server');
>> fopen(tcpipServer)
>> data = fread(tcpipServer, 8 , 'float32')
data =
0 ===>> want to omit
0.0000 ===>> want to omit
0 ===>> want to omit
123.2000
134.5000
52.5000
0.0000 ===>> want to omit
0 ===>> want to omit
>>
-----------------------------------------------------------------

Risposta accettata

Walter Roberson
Walter Roberson il 21 Ago 2016
Read the data and throw away the parts you do not want.
data = data(4:6);
  3 Commenti
Walter Roberson
Walter Roberson il 21 Ago 2016
I have no idea why you are putting in a label.
If you have data in the packet that you do not want to calculate with, then either do not send the data or else read the unwanted data and throw it away. I doubt there is a way to "position" within a TCP packet using fseek(), but I have not tried.
The only provision fread() has to ignore bytes is through the use of the "skip" parameter, which skips the given number of bytes after each read. But you have leading bytes to skip, and I don't think fread() allows you to specify a count of 0 on the number of items to read.
Perhaps what you should look into is using fread() of uint8's to read the entire packet, access portions of the resulting vector, and typecast() it as needed.
fscanf() does have ways of dropping items, but it is only for formatted data, not for binary data.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming Utilities in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by