Skip to content

Commit 9de0df6

Browse files
committed
tools: check gateway comms before starting
For tools that communicate through the gateway scripts, ensure the script is running before the tool attempts to start. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 3448b16 commit 9de0df6

9 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/infuse_iot/tools/audio_record.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
__author__ = "Jordan Yates"
66
__copyright__ = "Copyright 2024, Embeint Holdings Pty Ltd"
77

8+
import sys
89
import time
910
import wave
1011
from contextlib import ExitStack
@@ -107,6 +108,9 @@ def handle_connection(self):
107108
self.handle_channel("right", stack, tdf)
108109

109110
def run(self):
111+
if not self._client.comms_check():
112+
sys.exit("No communications gateway detected (infuse gateway/bt_native)")
113+
110114
try:
111115
types = GatewayRequestConnectionRequest.DataType.DATA
112116
Console.log_info(f"Connecting to 0x{self._id:016x}")

src/infuse_iot/tools/bt_log.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
__author__ = "Jordan Yates"
66
__copyright__ = "Copyright 2024, Embeint Holdings Pty Ltd"
77

8+
import sys
89

910
from infuse_iot.commands import InfuseCommand
1011
from infuse_iot.common import InfuseType
@@ -41,6 +42,9 @@ def add_parser(cls, parser):
4142
)
4243

4344
def run(self):
45+
if not self._client.comms_check():
46+
sys.exit("No communications gateway detected (infuse gateway/bt_native)")
47+
4448
try:
4549
types = GatewayRequestConnectionRequest.DataType.LOGGING
4650
if self._data:

src/infuse_iot/tools/data_logger_sync.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import glob
1010
import os
1111
import pathlib
12+
import sys
1213

1314
from rich.live import Live
1415
from rich.progress import (
@@ -176,6 +177,9 @@ def handle_sync(self, live: Live, device_id: int, state: DeviceState):
176177
self.state_update(live, "Scanning")
177178

178179
def run(self):
180+
if not self._client.comms_check():
181+
sys.exit("No communications gateway detected (infuse gateway/bt_native)")
182+
179183
with Live(self.progress_table(), refresh_per_second=4) as live:
180184
for source, announce in self._client.observe_announce():
181185
self.state_update(live, "Scanning")

src/infuse_iot/tools/localhost.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import asyncio
99
import pathlib
10+
import sys
1011
import threading
1112
import time
1213
from typing import Any
@@ -240,6 +241,9 @@ def recv_thread(self) -> None:
240241
self._data_lock.release()
241242

242243
def run(self):
244+
if not self._client.comms_check():
245+
sys.exit("No communications gateway detected (infuse gateway/bt_native)")
246+
243247
Console.init()
244248
app = web.Application()
245249
# Route for serving the HTML file

src/infuse_iot/tools/ota_upgrade.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ def run_file_copy(self, live: Live, mtu: int, source: HopReceived):
199199
self._pending[source.infuse_id] = time.time() + 60
200200

201201
def run(self):
202+
if not self._client.comms_check():
203+
sys.exit("No communications gateway detected (infuse gateway/bt_native)")
204+
202205
if self._single_diff:
203206
self.gateway_diff_load()
204207

src/infuse_iot/tools/rpc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import importlib
1010
import pkgutil
1111
import random
12+
import sys
1213

1314
import infuse_iot.rpc_wrappers as wrappers
1415
from infuse_iot.commands import InfuseCommand, InfuseRpcCommand
@@ -74,6 +75,9 @@ def rx_handler(self, pkt: ClientNotification):
7475
print(pkt.epacket.payload.decode("utf-8"), end="")
7576

7677
def run(self):
78+
if not self._client.comms_check():
79+
sys.exit("No communications gateway detected (infuse gateway/bt_native)")
80+
7781
try:
7882
types = GatewayRequestConnectionRequest.DataType.COMMAND
7983
if self._args.conn_log:

src/infuse_iot/tools/serial_throughput.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
__copyright__ = "Copyright 2024, Embeint Holdings Pty Ltd"
77

88
import random
9+
import sys
910
import time
1011

1112
from infuse_iot.commands import InfuseCommand
@@ -81,6 +82,9 @@ def run_send_test(self, num, size, queue_size):
8182
print(msg)
8283

8384
def run(self):
85+
if not self._client.comms_check():
86+
sys.exit("No communications gateway detected (infuse gateway/bt_native)")
87+
8488
# No queuing
8589
print(f"Averaged across {self._iterations} packets with no queuing:")
8690
self.run_send_test(self._iterations, 4, 1)

src/infuse_iot/tools/tdf_csv.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
__copyright__ = "Copyright 2024, Embeint Holdings Pty Ltd"
77

88
import os
9+
import sys
910
import time
1011

1112
from infuse_iot.commands import InfuseCommand
@@ -38,6 +39,9 @@ def __init__(self, args):
3839
self.args = args
3940

4041
def run(self):
42+
if not self._client.comms_check():
43+
sys.exit("No communications gateway detected (infuse gateway/bt_native)")
44+
4145
files = {}
4246

4347
while True:

src/infuse_iot/tools/tdf_list.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
__author__ = "Jordan Yates"
66
__copyright__ = "Copyright 2024, Embeint Holdings Pty Ltd"
77

8+
import sys
89
import time
910

1011
import tabulate
@@ -97,6 +98,9 @@ def append_readings(self, table: list[tuple[str | None, str | None, str, str, st
9798
self.append_tdf(table, tdf_name, time_str, t)
9899

99100
def run(self) -> None:
101+
if not self._client.comms_check():
102+
sys.exit("No communications gateway detected (infuse gateway/bt_native)")
103+
100104
while True:
101105
msg = self._client.receive()
102106
if msg is None:

0 commit comments

Comments
 (0)