Skip to content

Commit 791b4dd

Browse files
authored
Merge pull request #44 from looran/main
add UDP support
2 parents 5b4dc52 + 5d71a02 commit 791b4dd

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

smpmgr/common.py

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from smpclient.generics import SMPRequest, TEr1, TEr2, TRep
1414
from smpclient.transport.ble import SMPBLETransport
1515
from smpclient.transport.serial import SMPSerialTransport
16+
from smpclient.transport.udp import SMPUDPTransport
1617

1718
logger = logging.getLogger(__name__)
1819

@@ -26,6 +27,7 @@
2627
class TransportDefinition:
2728
port: str | None
2829
ble: str | None
30+
ip: str | None
2931

3032

3133
@dataclass(frozen=True)
@@ -56,6 +58,14 @@ def get_custom_smpclient(options: Options, smp_client_cls: Type[TSMPClient]) ->
5658
SMPBLETransport(),
5759
options.transport.ble,
5860
)
61+
elif options.transport.ip is not None:
62+
logger.info(
63+
f"Initializing SMPClient with the SMPUDPTransport, {options.transport.ip=} and MTU 1024"
64+
)
65+
return smp_client_cls(
66+
SMPUDPTransport(1024),
67+
options.transport.ip,
68+
)
5969
else:
6070
typer.echo(
6171
f"A transport option is required; "

smpmgr/main.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
@app.callback(invoke_without_command=True)
4747
def options(
4848
ctx: typer.Context,
49+
ip: str = typer.Option(None, help="The IP address to connect to for UDP transport"),
4950
port: str = typer.Option(
5051
None, help="The serial port to connect to, e.g. COM1, /dev/ttyACM0, etc."
5152
),
@@ -70,7 +71,9 @@ def options(
7071

7172
setup_logging(loglevel, logfile)
7273

73-
ctx.obj = Options(timeout=timeout, transport=TransportDefinition(port=port, ble=ble), mtu=mtu)
74+
ctx.obj = Options(
75+
timeout=timeout, transport=TransportDefinition(port=port, ble=ble, ip=ip), mtu=mtu
76+
)
7477
logger.info(ctx.obj)
7578

7679
if ctx.invoked_subcommand is None:

0 commit comments

Comments
 (0)