Skip to content

Commit

Permalink
Add BLE support
Browse files Browse the repository at this point in the history
References #12

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
  • Loading branch information
tormodvolden committed Nov 15, 2024
1 parent 0f946b8 commit bef4c85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions smpmgr/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -24,6 +25,7 @@
@dataclass(frozen=True)
class TransportDefinition:
port: str | None
ble: str | None


@dataclass(frozen=True)
Expand All @@ -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; "
Expand Down
3 changes: 2 additions & 1 deletion smpmgr/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
Expand All @@ -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:
Expand Down

0 comments on commit bef4c85

Please # to comment.