mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-21 21:41:13 +00:00
start on packet log converter
This commit is contained in:
parent
349c7a6328
commit
a985b2fd2e
53
tools/create_packet_log.py
Executable file
53
tools/create_packet_log.py
Executable file
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python
|
||||
# BlueKitchen GmbH (c) 2014
|
||||
|
||||
# convert log output to PacketLogger format
|
||||
# can be viewed with Wireshark
|
||||
|
||||
import re
|
||||
import sys
|
||||
|
||||
def chop(line, prefix):
|
||||
if line.startswith(prefix):
|
||||
return line[len(prefix):]
|
||||
return None
|
||||
|
||||
def str2hex(value):
|
||||
if value:
|
||||
return int(value, 16)
|
||||
return None
|
||||
|
||||
def log(time, type, incmoing, text):
|
||||
data = map(str2hex, text.strip(" ").split(" "))
|
||||
print time, type, data
|
||||
|
||||
# print 'Number of arguments:', len(sys.argv), 'arguments.'
|
||||
# print 'Argument List:', str(sys.argv)
|
||||
|
||||
infile = 'hci_console.txt'
|
||||
if len(sys.argv) > 1:
|
||||
infile = sys.argv[1]
|
||||
|
||||
outfile = 'hci_dump.pklg'
|
||||
if len(sys.argv) > 2:
|
||||
outfile = sys.argv[2]
|
||||
|
||||
# with open(outfile, 'w') as fout:
|
||||
with open (infile, 'rb') as fin:
|
||||
for line in fin:
|
||||
time = None
|
||||
parts = parts = re.match('\[(.*)\] (.*)', line)
|
||||
if parts and len(parts.groups()) == 2:
|
||||
(time, line) = parts.groups()
|
||||
rest = chop(line,'CMD => ')
|
||||
if rest:
|
||||
log(time, 1, 0, rest)
|
||||
rest = chop(line,'EVT <= ')
|
||||
if rest:
|
||||
log(time, 4, 1, rest)
|
||||
rest = chop(line,'ACL => ')
|
||||
if rest:
|
||||
log(time, 4, 0, rest)
|
||||
rest = chop(line,'ACL <= ')
|
||||
if rest:
|
||||
log(time, 4, 1, rest)
|
Loading…
x
Reference in New Issue
Block a user