I'm trying to send a C++ struct over a UDP socket to a Python app.
This is the C++ code to send the struct:
// my struct
struct S_telemetryPacket {
// sensors
float temperatureSensor1;
float accelerometer1_x;
float accelerometer1_y;
float accelerometer1_z;
float batteryVoltage1;
float powerDraw1;
// motors
int motor1;
int motor2;
int motor3;
int motor4;
} S_telemetryPacket;
// ... some other code populates the struct
// then the struct is sent over UDP
int res = sendto(relaySocket, (char *)&S_telemetryPacket, sizeof(S_telemetryPacket), NULL, (SOCKADDR *)&addrGroundstation, addrGroundstationSize);
And this is the raw data received in Python:
\x00P\x03E\x00\x00\xfaD\x00\x00\x00\x00\x00@\xfbD\x00`\xfbD\x00@\x03Ed\x00\x00\x00e\x00\x00\x00n\x00\x00\x00o\x00\x00\x00
When I try to unpack it using the struct library, I get an error.
print struct.unpack('eeeeeeiiii', raw_data)
This error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> struct.error: bad char in struct format
Can anyone shed some light? The data I receive looks weird, there are symbols I wouldn't expect like `, or @, or o, etc.
Could it be something wrong with how the struct is sent from the C++ side?