Skip to content

Commit d05b82a

Browse files
committed
tools: optional connection timeout
Add an optional connection timeout parameter to `rpc`, `ota_upgrade` and `bt_log`. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 0777d3b commit d05b82a

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/infuse_iot/tools/bt_log.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,22 @@ def __init__(self, args):
2929
self._decoder = TDF()
3030
self._id = args.id
3131
self._data = args.data
32+
self._conn_timeout = args.conn_timeout
3233

3334
@classmethod
3435
def add_parser(cls, parser):
3536
parser.add_argument("--id", type=lambda x: int(x, 0), help="Infuse ID to receive logs for")
3637
parser.add_argument("--data", action="store_true", help="Subscribe to the data characteristic as well")
38+
parser.add_argument(
39+
"--conn-timeout", type=int, default=10000, help="Timeout to wait for a connection to the device (ms)"
40+
)
3741

3842
def run(self):
3943
try:
4044
types = GatewayRequestConnectionRequest.DataType.LOGGING
4145
if self._data:
4246
types |= GatewayRequestConnectionRequest.DataType.DATA
43-
with self._client.connection(self._id, types) as _:
47+
with self._client.connection(self._id, types, self._conn_timeout) as _:
4448
while evt := self._client.receive():
4549
if evt is None:
4650
continue

src/infuse_iot/tools/ota_upgrade.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class SubCommand(InfuseCommand):
3636

3737
def __init__(self, args):
3838
self._client = LocalClient(default_multicast_address(), 1.0)
39+
self._conn_timeout = args.conn_timeout
3940
self._min_rssi: int | None = args.rssi
4041
self._single_id: int | None = args.id
4142
self._release: ValidRelease = args.release
@@ -70,6 +71,9 @@ def add_parser(cls, parser):
7071
parser.add_argument("--rssi", type=int, help="Minimum RSSI to attempt upgrade process")
7172
parser.add_argument("--id", type=lambda x: int(x, 0), help="Single device to upgrade")
7273
parser.add_argument("--log", type=str, help="File to write upgrade results to")
74+
parser.add_argument(
75+
"--conn-timeout", type=int, default=10000, help="Timeout to wait for a connection to the device (ms)"
76+
)
7377

7478
def progress_table(self):
7579
table = Table()
@@ -173,7 +177,7 @@ def run(self):
173177
self.state_update(live, f"Connecting to {source.infuse_id:016X}")
174178
try:
175179
with self._client.connection(
176-
source.infuse_id, GatewayRequestConnectionRequest.DataType.COMMAND
180+
source.infuse_id, GatewayRequestConnectionRequest.DataType.COMMAND, self._conn_timeout
177181
) as mtu:
178182
self.state_update(live, f"Uploading patch file to {source.infuse_id:016X}")
179183
rpc_client = RpcClient(self._client, mtu, source.infuse_id)

src/infuse_iot/tools/rpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def add_parser(cls, parser):
3434
addr_group.add_argument("--gateway", action="store_true", help="Run command on local gateway")
3535
addr_group.add_argument("--id", type=lambda x: int(x, 0), help="Infuse ID to run command on")
3636
parser.add_argument("--conn-log", action="store_true", help="Request logs from remote device")
37+
parser.add_argument(
38+
"--conn-timeout", type=int, default=10000, help="Timeout to wait for a connection to the device (ms)"
39+
)
3740
command_list_parser = parser.add_subparsers(title="commands", metavar="<command>", required=True)
3841

3942
for _, name, _ in pkgutil.walk_packages(wrappers.__path__):
@@ -75,7 +78,7 @@ def run(self):
7578
types = GatewayRequestConnectionRequest.DataType.COMMAND
7679
if self._args.conn_log:
7780
types |= GatewayRequestConnectionRequest.DataType.LOGGING
78-
with self._client.connection(self._id, types) as mtu:
81+
with self._client.connection(self._id, types, self._args.conn_timeout) as mtu:
7982
self._max_payload = mtu
8083
rpc_client = RpcClient(self._client, mtu, self._id, self.rx_handler)
8184
params = bytes(self._command.request_struct())

0 commit comments

Comments
 (0)