mirror of
https://github.com/bluekitchen/btstack.git
synced 2024-12-29 09:26:08 +00:00
tool/dump_pklg: use struct module
This commit is contained in:
parent
53f240c0b0
commit
cac83658f9
@ -13,23 +13,16 @@
|
||||
|
||||
import sys
|
||||
import datetime
|
||||
import struct
|
||||
|
||||
packet_types = [ "CMD =>", "EVT <=", "ACL =>", "ACL <="]
|
||||
|
||||
def read_net_32(f):
|
||||
a = f.read(1)
|
||||
if a == '':
|
||||
return -1
|
||||
b = f.read(1)
|
||||
if b == '':
|
||||
return -1
|
||||
c = f.read(1)
|
||||
if c == '':
|
||||
return -1
|
||||
d = f.read(1)
|
||||
if d == '':
|
||||
return -1
|
||||
return ord(a) << 24 | ord(b) << 16 | ord(c) << 8 | ord(d)
|
||||
def read_header(f):
|
||||
bytes_read = f.read(13)
|
||||
if bytes_read:
|
||||
return struct.unpack(">IIIB", bytes_read)
|
||||
else:
|
||||
return (-1, 0, 0, 0)
|
||||
|
||||
def as_hex(data):
|
||||
str_list = []
|
||||
@ -50,12 +43,9 @@ with open (infile, 'rb') as fin:
|
||||
pos = 0
|
||||
try:
|
||||
while True:
|
||||
len = read_net_32(fin)
|
||||
(len, ts_sec, ts_usec, type) = read_header(fin)
|
||||
if len < 0:
|
||||
break
|
||||
ts_sec = read_net_32(fin)
|
||||
ts_usec = read_net_32(fin)
|
||||
type = ord(fin.read(1))
|
||||
packet_len = len - 9;
|
||||
if (packet_len > 66000):
|
||||
print ("Error parsing pklg at offset %u (%x)." % (pos, pos))
|
||||
|
Loading…
Reference in New Issue
Block a user