-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_uuids.py
More file actions
43 lines (31 loc) · 2.36 KB
/
update_uuids.py
File metadata and controls
43 lines (31 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# from os import system
from json import dumps
import yaml # pip install PyYAML or uv run --with PyYAML update_uuids.py
# system('git submodule update --remote Bluetooth_SIG_UUIDs') # git should also be installed
infiles = ['service_uuids', 'characteristic_uuids', 'descriptors']
outfiles = ['gatt-services', 'gatt-characteristics', 'gatt-descriptors']
varnames = ['SERVICES', 'CHARACTERISTICS', 'DESCRIPTORS']
for i in range(3):
items = yaml.load(open('Bluetooth_SIG_UUIDs/assigned_numbers/uuids/'+infiles[i]+'.yaml', encoding='utf8'), Loader=yaml.Loader)
itemsout = {}
for item in items['uuids']:
desid = item['id'].split('.')[-1]
# restore gap. and gatt. prefixes for certain characteristics and surround with quotes
if '.gap.' in item['id']:
desid = "'gap."+desid+"'"
if '.gatt.' in item['id']:
desid = "'gatt."+desid+"'"
# a dash in the characteristic name also requires putting the item in quotes
if '-' in desid and not '.gatt.' in item['id'] and not '.gap.' in item['id']:
desid = "'"+desid+"'"
itemsout[desid] = hex(item['uuid']).upper().replace('X', 'x')
# generate the final output file
# beginning of the file
result = '/* eslint-disable quote-props */\n// Do not manually edit this file. Contents generated by ../update_uuids.py from https://bitbucket.org/bluetooth-SIG/public/src/main/assigned_numbers/uuids/'+infiles[i]+'.yaml\n// eslint-disable-next-line no-unused-vars\nconst STANDARD_GATT_'+varnames[i]+' = '
# manually add some items to the end of characteristics list for compatibility with Chrome
additionalcharacteristics = ''
if varnames[i] == 'CHARACTERISTICS':
additionalcharacteristics = ",\n // the following were renamed in or removed from the spec but Chrome still ships them\n 'gap.central_address_resolution_support': 0x2AA6,\n 'local_east_coordinate.xml': 0x2AB1,\n analog: 0x2A58,\n digital: 0x2A56,\n two_zone_heart_rate_limit: 0x2A95,\n magnetic_flux_density_2D: 0x2AA0,\n magnetic_flux_density_3D: 0x2AA1"
# convert the JSON format to a JS file format
result = result+dumps(dict(sorted(itemsout.items()))).replace('"', '').replace(',', ",\n ").replace('{', '{\n ').replace('}', additionalcharacteristics+',\n}').replace('\\', '')+';\n'
open('extension/'+outfiles[i]+'.js', 'w').write(result)