From b247aca3b48d8875ecb0e638bf6f2de86e16037f Mon Sep 17 00:00:00 2001 From: Charlie Boutier Date: Thu, 17 Aug 2023 18:19:50 +0000 Subject: [PATCH] pandora_server: add support to accept bumble config file --- apps/pandora_server.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/apps/pandora_server.py b/apps/pandora_server.py index 5f92309f..b577f823 100644 --- a/apps/pandora_server.py +++ b/apps/pandora_server.py @@ -1,8 +1,10 @@ import asyncio import click import logging +import json from bumble.pandora import PandoraDevice, serve +from typing import Dict, Any BUMBLE_SERVER_GRPC_PORT = 7999 ROOTCANAL_PORT_CUTTLEFISH = 7300 @@ -18,13 +20,30 @@ ROOTCANAL_PORT_CUTTLEFISH = 7300 help='HCI transport', default=f'tcp-client:127.0.0.1:', ) -def main(grpc_port: int, rootcanal_port: int, transport: str) -> None: +@click.option( + '--config', + help='Bumble json configuration file', +) +def main(grpc_port: int, rootcanal_port: int, transport: str, config: str) -> None: if '' in transport: transport = transport.replace('', str(rootcanal_port)) - device = PandoraDevice({'transport': transport}) + + bumble_config = retrieve_config(config) + if 'transport' not in bumble_config.keys(): + bumble_config.update({'transport': transport}) + device = PandoraDevice(bumble_config) + logging.basicConfig(level=logging.DEBUG) asyncio.run(serve(device, port=grpc_port)) +def retrieve_config(config: str) -> Dict[str, Any]: + if not config: + return {} + + with open(config, 'r') as f: + return json.load(f) + + if __name__ == '__main__': main() # pylint: disable=no-value-for-parameter