2
votes

I have a Simulink model sending data via UDP to another program (Blender) where I can receive the packets, but I have not been able to figure out how to correctly decode them.

In the Simulink model I just have it sending a value that is based upon a sine wave, nothing fancy, just a single value like 1.452 or something. In Blender I have it spitting out the data it receives from the packet, and I'm receiving stuff like:

b'<\xa6ya\x05\x93\xe3?'

I have no idea how to decode this. It seems to have some hex values, but beyond that I'm lost. I'm not even sure what all this data contains. Is it just the value from Simulink, or does it contain information regarding things like the sender and receiver IP addresses, ports, etc...?

UPDATE: I updated the Simulink model to transmit a constant value via UDP for debugging/investigation. The value is 0.5234, and the data that my Python script is spitting out is:

b'\xab>W[\xb1\xbf\xe0?'

Which, when converted into hexadecimal reads (using hexlify):

b'ab3e575bb1bfe03f'

How would I extract/decode 0.5234 out of that?

Thanks for any help!

1

1 Answers

3
votes

You can use struct to decode your binary data, in this case it seems to be a double value:

>>> import struct
>>> struct.unpack('d', b'\xab>W[\xb1\xbf\xe0?')
(0.5234,)