Merge branch 'master' into ble-api-cleanup

Conflicts:
	tool/generate.py
This commit is contained in:
Matthias Ringwald 2015-12-18 21:47:34 +01:00
commit f55dd2ad86
3 changed files with 37 additions and 36 deletions

View File

@ -9,10 +9,10 @@ import re
import sys import sys
import os import os
print ''' print('''
CC256x init script conversion tool for use with BTstack, v0.1 CC256x init script conversion tool for use with BTstack, v0.1
Copyright 2012-2014 BlueKitchen GmbH Copyright 2012-2014 BlueKitchen GmbH
''' ''')
usage = '''This script perpares init scripts for TI's usage = '''This script perpares init scripts for TI's
CC256x chipsets for use with BTstack . CC256x chipsets for use with BTstack .
@ -34,7 +34,7 @@ data_indent = ' '
def read_little_endian_16(f): def read_little_endian_16(f):
low = f.read(1) low = f.read(1)
if low == "": if len(low) == 0:
return -1 return -1
high = f.read(1) high = f.read(1)
return ord(high) << 8 | ord(low) return ord(high) << 8 | ord(low)
@ -113,7 +113,7 @@ def convert_bts(main_bts_file, bts_add_on):
have_power_vector_edr3 = False; have_power_vector_edr3 = False;
have_class2_single_power = False; have_class2_single_power = False;
print "Creating {0}".format(c_file) print("Creating {0}".format(c_file))
part_size = 0 part_size = 0
@ -127,22 +127,23 @@ def convert_bts(main_bts_file, bts_add_on):
with open (bts_file, 'rb') as fin: with open (bts_file, 'rb') as fin:
print "- parsing {0:32}".format(bts_file) print("- parsing {0:32}".format(bts_file))
header = fin.read(32) header = fin.read(32)
if header[0:4] != 'BTSB': if header[0:4].decode('ascii') != 'BTSB':
print 'Error', bts_file, 'is not a valid .BTS file' print('Error', bts_file, 'is not a valid .BTS file')
sys.exit(1) sys.exit(1)
while True: while True:
action_type = read_little_endian_16(fin) action_type = read_little_endian_16(fin)
action_size = read_little_endian_16(fin) action_size = read_little_endian_16(fin)
action_data = fin.read(action_size) action_data = bytearray(fin.read(action_size))
if (action_type == 1): # hci command if (action_type == 1): # hci command
opcode = (ord(action_data[2]) << 8) | ord(action_data[1]) # opcode = (ord(action_data[2]) << 8) | ord(action_data[1])
opcode = (action_data[2] << 8) | action_data[1]
if opcode == 0xFF36: if opcode == 0xFF36:
continue # skip baud rate command continue # skip baud rate command
if opcode == 0xFD0C: if opcode == 0xFD0C:
@ -173,7 +174,7 @@ def convert_bts(main_bts_file, bts_add_on):
counter = 0 counter = 0
str_list.append(data_indent) str_list.append(data_indent)
for byte in action_data: for byte in action_data:
str_list.append("0x{0:02x}, ".format(ord(byte))) str_list.append("0x{0:02x}, ".format(byte))
counter = counter + 1 counter = counter + 1
if (counter != 15): if (counter != 15):
continue continue
@ -196,7 +197,7 @@ def convert_bts(main_bts_file, bts_add_on):
part_size = 0 part_size = 0
if (action_type == 6): # comment if (action_type == 6): # comment
action_data = action_data.rstrip('\0') action_data = action_data.decode('ascii').rstrip('\0')
str_list.append(data_indent) str_list.append(data_indent)
str_list.append("// " + action_data + "\n") str_list.append("// " + action_data + "\n")
@ -232,11 +233,11 @@ def convert_bts(main_bts_file, bts_add_on):
for part_size in part_sizes: for part_size in part_sizes:
part += 1 part += 1
size += part_size size += part_size
print "- part", part, "size", part_size print("- part", part, "size", part_size)
print '- total size', size print('- total size', size)
print "\n".join(additions) print("\n".join(additions))
part = 0 part = 0
@ -269,7 +270,7 @@ def convert_bts(main_bts_file, bts_add_on):
# get list of *.bts files # get list of *.bts files
files = glob.glob('*.bts') files = glob.glob('*.bts')
if not files: if not files:
print usage print(usage)
sys.exit(1) sys.exit(1)
# convert each of them # convert each of them
@ -277,16 +278,17 @@ for name in files:
name_lower = name.lower() name_lower = name.lower()
# skip BLE and AVRP add-ons # skip BLE and AVRP add-ons
if name_lower.startswith('ble_init_cc'): if name_lower.startswith('ble_init_cc'):
print "Skipping BLE add-on", name print("Skipping BLE add-on", name)
continue continue
if name_lower.startswith('avpr_init_cc'): if name_lower.startswith('avpr_init_cc'):
print "Skipping AVPR add-on", name print("Skipping AVPR add-on", name)
continue continue
if re.match("initscripts_tiinit_.*_ble_add-on.bts", name_lower): if re.match("initscripts_tiinit_.*_ble_add-on.bts", name_lower):
print "Skipping BLE add-on", name print("Skipping BLE add-on", name)
continue continue
if re.match("initscripts_tiinit_.*_avpr_add-on.bts", name_lower): if re.match("initscripts_tiinit_.*_avpr_add-on.bts", name_lower):
print "Skipping AVPR add-on", name print("Skipping AVPR add-on", name)
continue
# check for BLE add-on # check for BLE add-on
add_on = "" add_on = ""
@ -295,19 +297,19 @@ for name in files:
potential_add_on = 'BLE_init_%s.bts' % name_parts.group(1) potential_add_on = 'BLE_init_%s.bts' % name_parts.group(1)
if os.path.isfile(potential_add_on): if os.path.isfile(potential_add_on):
add_on = potential_add_on add_on = potential_add_on
print "Found", add_on, "add on for", name print("Found", add_on, "add-on for", name)
name_parts = re.match('initscripts_TIInit_(\d*\.\d*\.\d*)_.*.bts', name) name_parts = re.match('initscripts_TIInit_(\d*\.\d*\.\d*)_.*.bts', name)
if name_parts: if name_parts:
potential_add_on = 'initscripts_TIInit_%s_ble_add-on.bts' % name_parts.group(1) potential_add_on = 'initscripts_TIInit_%s_ble_add-on.bts' % name_parts.group(1)
if os.path.isfile(potential_add_on): if os.path.isfile(potential_add_on):
add_on = potential_add_on add_on = potential_add_on
print "Found", add_on, "add on for", name print("Found", add_on, "add-on for", name)
convert_bts(name, add_on) convert_bts(name, add_on)
# done # done
print '\nConversion(s) successful!\n' print('\nConversion(s) successful!\n')

View File

@ -66,17 +66,17 @@ def dumpPacket(fout, timestamp, type, data):
def handleHexPacket(fout, timestamp, type, text): def handleHexPacket(fout, timestamp, type, text):
try: try:
data = bytearray(map(str2hex, text.strip().split())) data = bytearray(list(map(str2hex, text.strip().split())))
dumpPacket(fout, timestamp, type, data) dumpPacket(fout, timestamp, type, data)
except TypeError: except TypeError:
print 'Cannot parse hexdump', text.strip() print('Cannot parse hexdump', text.strip())
if len(sys.argv) == 1: if len(sys.argv) == 1:
print 'BTstack Console to PacketLogger converter' print('BTstack Console to PacketLogger converter')
print 'Copyright 2014, BlueKitchen GmbH' print('Copyright 2014, BlueKitchen GmbH')
print '' print('')
print 'Usage: ', sys.argv[0], 'asci-log-file.txt [hci_dump.pkgl]' print('Usage: ', sys.argv[0], 'asci-log-file.txt [hci_dump.pkgl]')
print 'Converted hci_dump.pklg can be viewed with Wireshark and OS X PacketLogger' print('Converted hci_dump.pklg can be viewed with Wireshark and OS X PacketLogger')
exit(0) exit(0)
infile = sys.argv[1] infile = sys.argv[1]
@ -86,10 +86,9 @@ if len(sys.argv) > 2:
# with open(outfile, 'w') as fout: # with open(outfile, 'w') as fout:
with open (outfile, 'wb') as fout: with open (outfile, 'wb') as fout:
with open (infile, 'rb') as fin: with open (infile, 'rt') as fin:
packet_counter = 0 packet_counter = 0
for line in fin: for line in fin:
# print line
timestamp = None timestamp = None
parts = parts = re.match('\[(.*)\] (.*)', line) parts = parts = re.match('\[(.*)\] (.*)', line)
if parts and len(parts.groups()) == 2: if parts and len(parts.groups()) == 2:
@ -113,4 +112,4 @@ with open (outfile, 'wb') as fout:
rest = chop(line,'LOG -- ') rest = chop(line,'LOG -- ')
if rest: if rest:
line = rest line = rest
dumpPacket(fout, timestamp, 0xfc, line) dumpPacket(fout, timestamp, 0xfc, line.encode('ascii'))

View File

@ -60,13 +60,13 @@ def updateCopyright(dir_name, file_name):
#print "Update copyright: ", infile #print "Update copyright: ", infile
with open(outfile, 'w') as fout: with open(outfile, 'wt') as fout:
fout.write(copyright) fout.write(copyright)
bufferComment = "" bufferComment = ""
state = State.SearchStartComment state = State.SearchStartComment
with open(infile, 'rb') as fin: with open(infile, 'rt') as fin:
for line in fin: for line in fin:
if state == State.SearchStartComment: if state == State.SearchStartComment:
parts = re.match('\s*(/\*).*(\*/)',line) parts = re.match('\s*(/\*).*(\*/)',line)
@ -129,11 +129,11 @@ def requiresCopyrightUpdate(file_name):
return True return True
if onlyDumpDifferentCopyright: if onlyDumpDifferentCopyright:
print file_name, ": Copyrighter not allowed > ", parts.group() print(file_name, ": Copyrighter not allowed > ", parts.group())
return False return False
if not exactCopyrightFound: if not exactCopyrightFound:
print file_name, ": File has no copyright" print(file_name, ": File has no copyright")
return False return False