필터 지우기
필터 지우기

Want to omit some values from TCP packet

조회 수: 1 (최근 30일)
Gavanpreet Singh Bhatia
Gavanpreet Singh Bhatia 2016년 8월 20일
댓글: Gavanpreet Singh Bhatia 2016년 8월 23일
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
>>
-----------------------------------------------------------------

채택된 답변

Walter Roberson
Walter Roberson 2016년 8월 21일
Read the data and throw away the parts you do not want.
data = data(4:6);
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 8월 21일
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.
Gavanpreet Singh Bhatia
Gavanpreet Singh Bhatia 2016년 8월 23일
Thx for info.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming Utilities에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by