Struckt.unpack was mache ich falsch ?
Verfasst: Dienstag 22. Oktober 2013, 09:30
Hallo Leute,
ich empfange von einem C - Programm über ethernet ein Struckt und das möchte ich mit struckt.unpack entpacken aber ich bekommen immer die Fehlermeldung struct.error: unpack requires a string argument of length XY.
Also gehe ich davon aus das mein formatstring nicht dem entspricht was ich empfange nur habe ich alles schon mehrmal überprüft und es sollte eigentlich funktionieren. :K
Die entsprechungen !
Das Struckt in c
Mein Python Testcode
ich empfange von einem C - Programm über ethernet ein Struckt und das möchte ich mit struckt.unpack entpacken aber ich bekommen immer die Fehlermeldung struct.error: unpack requires a string argument of length XY.
Also gehe ich davon aus das mein formatstring nicht dem entspricht was ich empfange nur habe ich alles schon mehrmal überprüft und es sollte eigentlich funktionieren. :K
Die entsprechungen !
Code: Alles auswählen
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef unsigned int tUINT16;
typedef unsigned char BOOL;
Code: Alles auswählen
typedef struct {
WORD TYPE;
WORD ID;
DWORD version;
float translation;
float rotation;
float x_position;
float y_position;
float orientation;
DWORD total_distance; // in m Meter
DWORD robot_alive_time; // in min
WORD Akku_Voltage;
short Akku_Current;
WORD Akku_Status;
WORD Akku_Charge_Ah;
WORD Akku_Discharge_Ah;
WORD Akku_Regen_Ah;
WORD DUMMY_Akku_Portcontroll;
WORD DUMMY_Akku_Project_Status;
BYTE Akku_Max_Cell_Voltage;
BYTE Akku_Min_Cell_Voltage;
BYTE Akku_System_Temp;
BYTE Akku_Max_Cell_Temp;
BYTE Akku_Min_Cell_Temp;
BYTE not_in_use;
// WORD Akku_Cell_Voltage[16];
// WORD Satel_Handnotaus_Sendeleistung;
WORD Bamobil_Initialise[2];
WORD Bamobil_Status[2];
WORD Bamobil_Logic[2];
WORD Bamobil_Error[2];
short Bamobil_latest_upm[2];
short Bamobil_latest_Current[2];
short Bamobil_latest_v_out[2]; // Mittelwert der Ausgangsspannung zu den Motoren
WORD Bamobil_latest_p_motor[2]; //Leistung Motor
WORD Bamobil_latest_t_motor[2]; //Temperatur Motor
WORD Bamobil_latest_t_igbt[2]; //Temperatur Regler
BYTE Front_light_intensity;
BYTE Autonomic_drive;
BYTE flags[3];}
Code: Alles auswählen
import socket
import struct
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.bind(("", 38296))
while True:
daten, addr = s.recvfrom(1024)
int_data = struct.unpack('<hhqfffffqqhhhhhhhhsssssshhhhhhhhhhhhsss',daten)
print "[%s] %s" % (addr[0], daten)
print int_data
if daten == "exit":
break
pass
finally:
s.close()