1#!/usr/bin/env python3 2# 3# Convert format UUID16 // SERVICE_NAME into bluetooth_gatt.h defines 4# Copyright 2021 BlueKitchen GmbH 5# 6import os, sys, getopt 7 8tag_description = { 9 "-c" : "ORG_BLUETOOTH_CHARACTERISTIC", 10 "-s" : "ORG_BLUETOOTH_SERVICE" 11} 12 13def main(argv): 14 cmd = "\nUSAGE: %s [-s|-c] [-f filename]" % sys.argv[0] 15 cmd += "\n -s: for SERVICE_UUID" 16 cmd += "\n -c: for CHARACTERISTICS_UUID" 17 cmd += "\n -f filename: input file with UUID and comment, i.e. 0x2B29 // Client Supported Features\n" 18 19 tag_define = None 20 filename = None 21 22 try: 23 opts, args = getopt.getopt(argv[1:],"scf:") 24 except getopt.GetoptError: 25 print("ERROR: wrong options") 26 print (cmd) 27 sys.exit(2) 28 29 print(opts) 30 31 for opt, arg in opts: 32 if opt == '-s' or opt == '-c': 33 tag_define = tag_description[opt] 34 elif opt == '-f': 35 print("filename") 36 filename = arg 37 else: 38 print("ERROR: wrong options") 39 print (cmd) 40 sys.exit(2) 41 42 if (not tag_define) or (not filename): 43 print("ERROR: wrong options") 44 print (cmd) 45 sys.exit(2) 46 47 with open (filename, 'rt') as fin: 48 for line in fin: 49 data = line.strip('\n').split(" // ") 50 if len(data) != 2: 51 continue 52 else: 53 uuid = data[0] 54 summary = data[1] 55 56 tag = summary.upper().replace('.', '_').replace('-','_').replace(' ', '_') 57 print("#define %s_%-80s %s // %s" % (tag_define, tag, uuid, summary)) 58 59 60 61if __name__ == "__main__": 62 main(sys.argv) 63