write fixed point data via fwrite to tcp

2 visualizaciones (últimos 30 días)
Tom DeLonge
Tom DeLonge el 14 de Mzo. de 2019
Respondida: Tom DeLonge el 26 de Mzo. de 2019
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 comentario
Tom DeLonge
Tom DeLonge el 14 de Mzo. de 2019
Editada: Tom DeLonge el 14 de Mzo. de 2019
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?

Iniciar sesión para comentar.

Respuesta aceptada

Tom DeLonge
Tom DeLonge el 26 de Mzo. de 2019
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.

Más respuestas (0)

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by