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 <[email protected]>
  • Loading branch information
tormodvolden committed Nov 15, 2024
1 parent 0f946b8 commit 9287e6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions smpmgr/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from smpclient import SMPClient
from smpclient.generics import SMPRequest, TEr1, TEr2, TRep
from smpclient.transport.serial import SMPSerialTransport
from smpclient.transport.ble import SMPBLETransport

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,14 @@ 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
5 changes: 4 additions & 1 deletion smpmgr/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ 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 +72,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 9287e6b

Please sign in to comment.