mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-01 09:08:06 +00:00
GATT Compiler: support #import <..> and ".." directives
This commit is contained in:
parent
c8771c2096
commit
60b51a4c4e
@ -13,6 +13,7 @@ import io
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
|
import sys
|
||||||
|
|
||||||
header = '''
|
header = '''
|
||||||
// {0} generated from {1} for BTstack
|
// {0} generated from {1} for BTstack
|
||||||
@ -29,8 +30,6 @@ usage = '''
|
|||||||
Usage: ./compile_gatt.py profile.gatt profile.h
|
Usage: ./compile_gatt.py profile.gatt profile.h
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
|
|
||||||
print('''
|
print('''
|
||||||
BLE configuration generator for use with BTstack, v0.1
|
BLE configuration generator for use with BTstack, v0.1
|
||||||
@ -77,6 +76,7 @@ property_flags = {
|
|||||||
'RELIABLE_WRITE': 0x10000,
|
'RELIABLE_WRITE': 0x10000,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btstack_root = ''
|
||||||
services = dict()
|
services = dict()
|
||||||
characteristic_indices = dict()
|
characteristic_indices = dict()
|
||||||
presentation_formats = dict()
|
presentation_formats = dict()
|
||||||
@ -504,14 +504,10 @@ def parseNumberOfDigitals(fout, parts):
|
|||||||
fout.write("\n")
|
fout.write("\n")
|
||||||
handle = handle + 1
|
handle = handle + 1
|
||||||
|
|
||||||
|
def parseLines(fname_in, fin, fout):
|
||||||
def parse(fname_in, fin, fname_out, fout):
|
|
||||||
global handle
|
global handle
|
||||||
global total_size
|
global total_size
|
||||||
|
|
||||||
fout.write(header.format(fname_out, fname_in))
|
|
||||||
fout.write('{\n')
|
|
||||||
|
|
||||||
line_count = 0;
|
line_count = 0;
|
||||||
for line in fin:
|
for line in fin:
|
||||||
line = line.strip("\n\r ")
|
line = line.strip("\n\r ")
|
||||||
@ -521,8 +517,31 @@ def parse(fname_in, fin, fname_out, fout):
|
|||||||
fout.write(" //" + line.lstrip('/') + '\n')
|
fout.write(" //" + line.lstrip('/') + '\n')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if line.startswith("#"):
|
if line.startswith("#import"):
|
||||||
print ("WARNING: #TODO in line %u not handled, skipping declaration:" % line_count)
|
imported_file = ''
|
||||||
|
parts = re.match('#import\s+<(.*)>\w*',line)
|
||||||
|
if parts and len(parts.groups()) == 1:
|
||||||
|
imported_file = btstack_root+'/src/ble/' + parts.groups()[0]
|
||||||
|
parts = re.match('#import\s+"(.*)"\w*',line)
|
||||||
|
if parts and len(parts.groups()) == 1:
|
||||||
|
imported_file = os.path.abspath(os.path.dirname(fname_in) + '/'+parts.groups()[0])
|
||||||
|
if len(imported_file) == 0:
|
||||||
|
print('ERROR: #import in file %s - line %u neither <name.gatt> nor "name.gatt" form', (fname_in, line_count))
|
||||||
|
continue
|
||||||
|
|
||||||
|
print("Importing %s" % imported_file)
|
||||||
|
try:
|
||||||
|
imported_fin = codecs.open (imported_file, encoding='utf-8')
|
||||||
|
fout.write(' // ' + line + ' -- BEGIN\n')
|
||||||
|
parseLines(imported_file, imported_fin, fout)
|
||||||
|
fout.write(' // ' + line + ' -- END\n')
|
||||||
|
except IOError as e:
|
||||||
|
print('ERROR: Import failed. Please check path.')
|
||||||
|
|
||||||
|
continue
|
||||||
|
|
||||||
|
if line.startswith("#TODO"):
|
||||||
|
print ("WARNING: #TODO in file %s - line %u not handled, skipping declaration:" % (fname_in, line_count))
|
||||||
print ("'%s'" % line)
|
print ("'%s'" % line)
|
||||||
fout.write("// " + line + '\n')
|
fout.write("// " + line + '\n')
|
||||||
continue
|
continue
|
||||||
@ -628,7 +647,16 @@ def parse(fname_in, fin, fname_out, fout):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
print("WARNING: unknown token: %s\n" % (parts[0]))
|
print("WARNING: unknown token: %s\n" % (parts[0]))
|
||||||
|
|
||||||
|
def parse(fname_in, fin, fname_out, fout):
|
||||||
|
global handle
|
||||||
|
global total_size
|
||||||
|
|
||||||
|
fout.write(header.format(fname_out, fname_in))
|
||||||
|
fout.write('{\n')
|
||||||
|
|
||||||
|
parseLines(fname_in, fin, fout)
|
||||||
|
|
||||||
serviceDefinitionComplete(fout)
|
serviceDefinitionComplete(fout)
|
||||||
write_indent(fout)
|
write_indent(fout)
|
||||||
fout.write("// END\n");
|
fout.write("// END\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user