diff --git a/smpmgr/common.py b/smpmgr/common.py index 54b97c5..3e196e1 100644 --- a/smpmgr/common.py +++ b/smpmgr/common.py @@ -11,6 +11,7 @@ from smp.exceptions import SMPBadStartDelimiter from smpclient import SMPClient from smpclient.generics import SMPRequest, TEr1, TEr2, TRep +from smpclient.transport.ble import SMPBLETransport from smpclient.transport.serial import SMPSerialTransport logger = logging.getLogger(__name__) @@ -24,6 +25,7 @@ @dataclass(frozen=True) class TransportDefinition: port: str | None + ble: str | None @dataclass(frozen=True) @@ -48,6 +50,12 @@ def get_custom_smpclient(options: Options, smp_client_cls: Type[TSMPClient]) -> ) else: return smp_client_cls(SMPSerialTransport(), options.transport.port) + elif options.transport.ble is not None: + logger.info(f"Initializing SMPClient with the SMPBLETransport, {options.transport.ble=}") + return smp_client_cls( + SMPBLETransport(), + options.transport.ble, + ) else: typer.echo( f"A transport option is required; " diff --git a/smpmgr/main.py b/smpmgr/main.py index 28f16b4..6522068 100644 --- a/smpmgr/main.py +++ b/smpmgr/main.py @@ -49,6 +49,7 @@ def options( port: str = typer.Option( None, help="The serial port to connect to, e.g. COM1, /dev/ttyACM0, etc." ), + ble: str = typer.Option(None, help="The Bluetooth address to connect to"), timeout: float = typer.Option( 2.0, help="Transport timeout in seconds; how long to wait for requests" ), @@ -69,7 +70,7 @@ def options( setup_logging(loglevel, logfile) - ctx.obj = Options(timeout=timeout, transport=TransportDefinition(port=port), mtu=mtu) + ctx.obj = Options(timeout=timeout, transport=TransportDefinition(port=port, ble=ble), mtu=mtu) logger.info(ctx.obj) if ctx.invoked_subcommand is None: