In <[EMAIL PROTECTED]>, nephish wrote:
> tohex gave me
> '53 54 58
S T X
> 00 00 00 34
Length!? Decimal 57.
> 00 00 00 c8
Type!? Decimal 200.
> 70 69 76 6f 74 72 61 63 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
> 74 72 61 63 31 70 69 76 6f 74 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Payload!?
> 45 4e 58'
E N X
> this is the login message (message type 200)
import struct
data = ('STX'
'\x00\x00\x004'
'\x00\x00\x00\xc8'
'stateman\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
'\x00\x00\x00state1man\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
'\x00\x00\x00\x00ENX')
def split_message(message):
if not (message.startswith('STX') or message.endswith('ENX')):
raise ValueError('missing start or end sequence')
length, message_type = struct.unpack('>II', message[3:11])
return length, message_type, message[11:-3]
print 'length: %d\ntype: %d\n%r' % split_message(data)
The problem I see is the length. The payload without STX, ENX and the two
numbers in front is 47 bytes so there's a 5 byte difference. You have to
look at some more messages to get an idea how the length corresponds to
the actual payloads length.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list