So I'm currently trying to unpack a struct that has the following format, written in C:
Udp.write(((byte*)&pm), sizeof(struct PressureMonitor));
UDP_IP = '192.168.1.222'
UDP_PORT = 8742
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
data, addr = sock.recvfrom(1024)
You need to tell
struct.unpack that your data isn't padded.
The format string
'cfc' doesn't contain a byte order / alignment character, which is equivalent to specifying
'@' as the byte order / alignment character, so you get native byte ordering and native alignment. Float data is 4 bytes wide and should be aligned on a 4 byte boundary, but since you have a one byte bool before your float 3 padding bytes get added after that first bool to ensure the float is correctly aligned.
You can specify native byte ordering with no padding with a
'=cfc' format string. But it would be better to explicitly indicate the correct byte ordering. If the data is being sent from an Intel machine, that would be
'<cfc'. Please see Byte Order, Size, and Alignment in the
struct module docs for details.