How to decode a UDP packet without byte unpack

20 ビュー (過去 30 日間)
Aaron Hamilton
Aaron Hamilton 2021 年 9 月 20 日
編集済み: Jonas 2021 年 9 月 21 日
I'm using simulink udp_receive to get some data. the data is a mix of different data types. I can't use the byte unpack block because it's not supported for code generation. i made a matlab function instead to read this. I'm using something like
function [data1,data2, data3] = fcn(u)
data1 = u(1,1);
data2 = u(2,1);
data3 = u(3:10,1);
end
to read the the specific byte wich works for data1 and data2 because they are 'uint8'. but i can't read data that are double or float in data3. using (3:10) read all the bytes but doesn't assume them as one variable.
Any suggestions?

採用された回答

Jonas
Jonas 2021 年 9 月 21 日
編集済み: Jonas 2021 年 9 月 21 日
You can reassemble those 8 bytes into a 64 byte double by applying a bitshift to each byte to its correct position, using a bitor on all outputs of the bitshifts and then typecast the resulting uint64 to double.
Same can be done for the 4 bytes of a 'single' or float32.
It looks something like this:

その他の回答 (0 件)

カテゴリ

Find more on Simulink Compiler in Help Center and File Exchange

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by