I am trying to unpack the following struct from binary data received via UDP from a time attendance clock device(DeviceName=TA8020):
typedef struct _AttLog_{
Int PIN; char verified;time_t time_second; char status;}TAttLog, *PAttLog;
Trying to unpack the data like this:
uid, state, timestamp, space = unpack( '24s1s4s11s', attendancedata.ljust(40)[:40] )
print "%s, %s, %s, %s" % (uid, state, space, decode_time( int( reverseHex( timestamp.encode('hex') ), 16 ) ) )
yields the following result:
5, , , 2016-02-13 11:55:36
The uid and timestamp are correct but I am unable to get the correct values for char verified and char status as you can see unpacking the struct like above they are returned empty.
When trying to unpack the char status and char verified separately like this:
state = unpack('>3c',attendancedata[17:20])
space = unpack('>2c',attendancedata[21:23])
yields:
statem ('\x00', '\x00', '\x00')
statev 0
every time which are not the correct values.(verified by looking at the web interface logs of the time attendance device)
Unpacking like:
oneSet = unpack('24s1s4s11s',attendancedata.ljust(40)[:40])
yields:
('5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00','\x01','h\x1b\xe0\x1e','\x01\x00\x00\x00\x00\x00\x00\x00\x00\xb2\x00')
The API documentation gives details as follows:
Only read command can be used to read all attendance logs. Attendance log can be compressed in long or short mode. The compressing method (if char *Buffer is being read now, the hand will be at the first byte) is: the first 2 bytes are used for storing user PIN (U 16 PIN), the front three bits of the third byte are used for storing verifying state. The fourth and fifth bits are to store verifying method. The sixth bit is to store short and long time sign. If it is short time format, time value is the last two bits of the third byte and the third byte plus the recent long time value (therefore, time format is stored as the misregistration value of the former long time value). Then decode it according to time coding mode (refer to user-defined coding mode) to get the correct time.
Any help would be much appreciated.
What I have tried:
I have tried unpacking it as posted above.