write fixed point data via fwrite to tcp

2 次查看(过去 30 天)
I have a mx7 array of doubles which I would like to transmit via tcpip using fwrite. However, I would like to transmit each column in it's own format, e.g.
int16 - fixed point - fixed point - double - int16 - fixed point - fixed point
The fixed points are 64bit long (16 + 48).
Now, how can I do this using fwrite? I would like to send the whole array at once and not each row/value on it's own.
Also, I should note that m can be rather large (on the order of 50k)... Can anyone suggest a solution?
  1 个评论
Tom DeLonge
Tom DeLonge 2019-3-14
编辑:Tom DeLonge 2019-3-14
my idea so far was to
  1. rearrange the columns a bit,
  2. typecast the whole thing down to a mx11 single array,
  3. transmit via fwrite as 'single'
the only problem with this approach is that I cannot use typecast on fixed point objects in matlab. I would have to write my own conversion routine for that I guess?

请先登录,再进行评论。

采纳的回答

Tom DeLonge
Tom DeLonge 2019-3-26
Just wanted to answer my own question. I used my own routine to convert a double number to a fixed point, which is then being sent in disguise as a uint64. For a big endian receiver and a 64 bit fixed-point number with a word length of 16 bits, the code is simply
fxpInt64 = swapbytes(int64(dblIn*2^48));
fxpInt64 = swapbytes(typecast(fxpInt64(:),'uint16'));
Then, as can be seen, I in turn typecasted everything to uint16, which was sort of the largest common denominator for my classes.This is then being sent using fwrite and uint16 in it's class argument.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by