diff --git a/tool/bluetooth_company_id.py b/tool/bluetooth_company_id.py index 9c435624e..bdf8f512f 100755 --- a/tool/bluetooth_company_id.py +++ b/tool/bluetooth_company_id.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Scrape GATT UUIDs from Bluetooth SIG page # https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers diff --git a/tool/bluetooth_data_types.py b/tool/bluetooth_data_types.py index 1e72c48b2..d4b868215 100755 --- a/tool/bluetooth_data_types.py +++ b/tool/bluetooth_data_types.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Scrape GAP Data Types from Bluetooth SIG page # Copyright 2016 BlueKitchen GmbH diff --git a/tool/bluetooth_gatt.py b/tool/bluetooth_gatt.py index dbf309bcd..73df2d31b 100755 --- a/tool/bluetooth_gatt.py +++ b/tool/bluetooth_gatt.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Scrape GATT UUIDs from Bluetooth SIG page # Copyright 2016 BlueKitchen GmbH diff --git a/tool/bluetooth_psm.py b/tool/bluetooth_psm.py index 0cac8230e..b0e3d10f3 100755 --- a/tool/bluetooth_psm.py +++ b/tool/bluetooth_psm.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Scrape GATT UUIDs from Bluetooth SIG page # https://www.bluetooth.com/specifications/assigned-numbers/logical-link-control/ diff --git a/tool/bluetooth_sdp.py b/tool/bluetooth_sdp.py index 830358d98..7d7fbfd22 100755 --- a/tool/bluetooth_sdp.py +++ b/tool/bluetooth_sdp.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Scrape SDP UUIDs from Bluetooth SIG page # Copyright 2017 BlueKitchen GmbH @@ -69,11 +69,11 @@ def remove_newlines(remark): def process_rows(fout, rows, pattern): for row in rows: columns = row.getchildren() - name = columns[0].text_content().encode('ascii','ignore') - value = columns[1].text_content().encode('ascii','ignore') + name = columns[0].text_content().replace(u'\u2013','').replace(u'\u200b','') + value = columns[1].text_content().replace(u'\u200b','') remark = '' if (len(columns) > 2): - remark = columns[2].text_content().encode('ascii','ignore') + remark = columns[2].text_content().replace(u'\u200b','') # skip tbody headers if name in ["Protocol Name", "Service Class Name", "Attribute Name", "UUID Name", "Reserved", 'Reserved for HID Attributes', 'Available for HID Language Strings']: @@ -82,6 +82,11 @@ def process_rows(fout, rows, pattern): if value.startswith('(Max value '): continue name = create_pretty_define(name) + print(name) + if name.endswith("DISPLAY"): + for c in name: + print("ord %c = 0x%x" % (c, ord(c))) + # skip duplicate attributes if name in defines: continue diff --git a/tool/btstack_event_generator.py b/tool/btstack_event_generator.py index 536eccde3..e3c3d8426 100755 --- a/tool/btstack_event_generator.py +++ b/tool/btstack_event_generator.py @@ -1,5 +1,5 @@ -#!/usr/bin/env python # BlueKitchen GmbH (c) 2014 +#!/usr/bin/env python3 import glob import re @@ -308,7 +308,7 @@ def create_events(events): else: last_variable_length_field_pos = offset if field_type in 'V': - if last_variable_length_field_pos >= 0: + if last_variable_length_field_pos != '': if offset_is_number: # convert to string offset = '((uint8_t) %u)' % offset diff --git a/tool/btstack_memory_generator.py b/tool/btstack_memory_generator.py index 77db908cf..d56d924a0 100755 --- a/tool/btstack_memory_generator.py +++ b/tool/btstack_memory_generator.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import sys @@ -107,8 +107,11 @@ hfile_header_end = """ """ cfile_header_begin = """ +#define BTSTACK_FILE__ "btstack_memory.c" + + /* - * btstack_memory.h + * btstack_memory.c * * @brief BTstack memory management via configurable memory pools * diff --git a/tool/btstack_parser.py b/tool/btstack_parser.py index e3db82e99..4d64b2406 100755 --- a/tool/btstack_parser.py +++ b/tool/btstack_parser.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # BlueKitchen GmbH (c) 2014 import re diff --git a/tool/btstack_rtos_generator.py b/tool/btstack_rtos_generator.py index ed1dcd446..8bc173740 100755 --- a/tool/btstack_rtos_generator.py +++ b/tool/btstack_rtos_generator.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os, sys, getopt, re, pickle copyright = """/* diff --git a/tool/convert_gatt_service.py b/tool/convert_gatt_service.py index db63fcad4..4a5825d17 100755 --- a/tool/convert_gatt_service.py +++ b/tool/convert_gatt_service.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Convert offical Bluetooth GATT Service definitions into BTstack's .gatt format # Copyright 2016 BlueKitchen GmbH diff --git a/tool/create_makefile_inc.py b/tool/create_makefile_inc.py index b21179993..dcf154c0d 100755 --- a/tool/create_makefile_inc.py +++ b/tool/create_makefile_inc.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Create Makefile.inc file for all source folders # Copyright 2017 BlueKitchen GmbH diff --git a/tool/create_packet_log.py b/tool/create_packet_log.py index 3fbfd8b97..e97fae827 100755 --- a/tool/create_packet_log.py +++ b/tool/create_packet_log.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # BlueKitchen GmbH (c) 2014 # convert log output to PacketLogger format @@ -91,7 +91,7 @@ if len(sys.argv) == 1: print('BTstack Console to PacketLogger converter') print('Copyright 2014, BlueKitchen GmbH') print('') - print('Usage: ', sys.argv[0], 'asci-log-file.txt [hci_dump.pkgl]') + print('Usage: ', sys.argv[0], 'ascii-log-file.txt [hci_dump.pklg]') print('Converted hci_dump.pklg can be viewed with Wireshark and OS X PacketLogger') exit(0) diff --git a/tool/dump_pklg.py b/tool/dump_pklg.py index 5beef05d9..f7e5c211e 100755 --- a/tool/dump_pklg.py +++ b/tool/dump_pklg.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # BlueKitchen GmbH (c) 2014 # primitive dump for PacketLogger format @@ -11,9 +11,7 @@ # uint8_t type; // 0xfc for note # } -import re import sys -import time import datetime packet_types = [ "CMD =>", "EVT <=", "ACL =>", "ACL <="] @@ -36,14 +34,14 @@ def read_net_32(f): def as_hex(data): str_list = [] for byte in data: - str_list.append("{0:02x} ".format(ord(byte))) + str_list.append("{0:02x} ".format(byte)) return ''.join(str_list) if len(sys.argv) == 1: - print 'Dump PacketLogger file' - print 'Copyright 2014, BlueKitchen GmbH' - print '' - print 'Usage: ', sys.argv[0], 'hci_dump.pklg' + print ('Dump PacketLogger file') + print ('Copyright 2014, BlueKitchen GmbH') + print ('') + print ('Usage: ', sys.argv[0], 'hci_dump.pklg') exit(0) infile = sys.argv[1] @@ -66,10 +64,9 @@ with open (infile, 'rb') as fin: pos = pos + 4 + len time = "[%s.%03u]" % (datetime.datetime.fromtimestamp(ts_sec).strftime("%Y-%m-%d %H:%M:%S"), ts_usec / 1000) if type == 0xfc: - print time, "LOG", packet + print (time, "LOG", packet.decode('ascii')) continue if type <= 0x03: - print time, packet_types[type], as_hex(packet) + print (time, packet_types[type], as_hex(packet)) except TypeError: print ("Error parsing pklg at offset %u (%x)." % (pos, pos)) - diff --git a/tool/dump_tlv.py b/tool/dump_tlv.py index e8eed4322..ba135d768 100755 --- a/tool/dump_tlv.py +++ b/tool/dump_tlv.py @@ -1,12 +1,9 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # BlueKitchen GmbH (c) 2017 # primitive dump for .tlv format -import re import sys -import time -import datetime def read_net_32(f): a = f.read(1) @@ -26,14 +23,14 @@ def read_net_32(f): def as_hex(data): str_list = [] for byte in data: - str_list.append("{0:02x} ".format(ord(byte))) + str_list.append("{0:02x} ".format(byte)) return ''.join(str_list) if len(sys.argv) == 1: - print 'Dump TLV file' - print 'Copyright 2017, BlueKitchen GmbH' - print '' - print 'Usage: ', sys.argv[0], 'file.tlv' + print ('Dump TLV file') + print ('Copyright 2017, BlueKitchen GmbH') + print ('') + print ('Usage: ', sys.argv[0], 'file.tlv') exit(0) infile = sys.argv[1] @@ -65,4 +62,3 @@ with open (infile, 'rb') as fin: except TypeError: print ("Error parsing tlv at offset %u (%x)." % (pos, pos)) - diff --git a/tool/java_binding.py b/tool/java_binding.py index 192a6b19a..5dfd04db5 100755 --- a/tool/java_binding.py +++ b/tool/java_binding.py @@ -1,10 +1,6 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # BlueKitchen GmbH (c) 2014 -import glob -import re -import sys - import btstack_parser as parser print(''' @@ -361,7 +357,7 @@ def create_event_factory(events, subevents, defines): if not event_supported(event_name): continue class_name = class_name_for_event(event_name) - print class_name + print(class_name) subcases += java_event_factory_subevent.format(event_type, class_name) with open(outfile, 'wt') as fout: diff --git a/tool/misc/update_copyright.py b/tool/misc/update_copyright.py old mode 100644 new mode 100755 index b1a7f6cd0..ab33ebe40 --- a/tool/misc/update_copyright.py +++ b/tool/misc/update_copyright.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import re @@ -113,8 +113,10 @@ def requiresCopyrightUpdate(file_name): global copyrightString, onlyDumpDifferentCopyright exactCopyrightFound = False - with open(file_name, "rb") as fin: + with open(file_name, "rt") as fin: + print("File: " + file_name) for line in fin: + print("Line: " + line) parts = re.match('.*('+copyrightString+').*',line) if parts: exactCopyrightFound = True diff --git a/tool/python_generator.py b/tool/python_generator.py index b92dae651..6d4183944 100755 --- a/tool/python_generator.py +++ b/tool/python_generator.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # BlueKitchen GmbH (c) 2018 import glob diff --git a/tool/sine_table_generator.py b/tool/sine_table_generator.py index 85e98bdd7..bb7358f28 100755 --- a/tool/sine_table_generator.py +++ b/tool/sine_table_generator.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import math import sys @@ -33,8 +33,8 @@ if __name__ == "__main__": print(usage) sys.exit(1) - sine_num_samples = sine_sample_rate/sine_frequency - + sine_num_samples = int(sine_sample_rate/sine_frequency) + print(type(sine_num_samples).__name__) print(sine_array.format(sine_sample_rate=sine_sample_rate, sine_frequency=sine_frequency)) items = 0 for sample in range(0,sine_num_samples): @@ -42,9 +42,9 @@ if __name__ == "__main__": angle = (sample * 360.0) / sine_num_samples sine = math.sin(math.radians(angle)) rescaled = int(round(sine * 32767)) - print ("%6d, " % rescaled), + print ("%6d, " % rescaled, end=''), if items == VALUES_PER_LINE: items = 0 - print + print("") print( "};") diff --git a/tool/update_filename.py b/tool/update_filename.py index e7b22d5f2..bfe310d6b 100755 --- a/tool/update_filename.py +++ b/tool/update_filename.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import re @@ -70,7 +70,7 @@ def update_filename_tag(dir_name, file_name, has_tag): def get_filename_tag(file_path): basename = os.path.basename(file_path) - with open(file_path, "rb") as fin: + with open(file_path, "rt") as fin: for line in fin: parts = re.match(filetag_re,line) if not parts: diff --git a/tool/uuid128_formats.py b/tool/uuid128_formats.py index 96b64b147..8e2a08847 100755 --- a/tool/uuid128_formats.py +++ b/tool/uuid128_formats.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Parase and dump UUID128 in various formats