Skip to content

Commit 2d5030c

Browse files
committed
tools: enable --server-port arguments
Added the `--server-port` argument to any tools that act or interact with a gateway. Signed-off-by: Aeyohan Furtado <aeyohan@embeint.com>
1 parent 6b1b364 commit 2d5030c

13 files changed

Lines changed: 45 additions & 28 deletions

src/infuse_iot/tools/annotate_events.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
ClientNotificationConnectionDropped,
2626
GatewayRequestConnectionRequest,
2727
LocalClient,
28-
default_multicast_address,
28+
add_server_port_parser,
2929
)
3030
from infuse_iot.time import InfuseTime
3131
from infuse_iot.util.argparse import InfuseDeviceId, ValidFile
@@ -121,6 +121,8 @@ def add_parser(cls, parser):
121121

122122
parser.add_argument("--id", type=InfuseDeviceId, help="Device to log events to")
123123

124+
add_server_port_parser(parser)
125+
124126
def __init__(self, args):
125127
self._label_type = args.labels
126128
self._time_check = args.time or TimeCheckType.DEFAULT
@@ -153,7 +155,7 @@ def __init__(self, args):
153155
self._labels = []
154156

155157
self._logger: rpc_enum_data_logger = args.logger
156-
self._client = LocalClient(default_multicast_address(), 1.0)
158+
self._client = LocalClient(args.server_sock, 1.0)
157159
self._device_id = args.id
158160
self.rpc_client: RpcClient | None = None
159161
self.connected = False

src/infuse_iot/tools/audio_record.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
ClientNotificationEpacketReceived,
2020
GatewayRequestConnectionRequest,
2121
LocalClient,
22-
default_multicast_address,
22+
add_server_port_parser,
2323
)
2424
from infuse_iot.tdf import TDF
2525
from infuse_iot.util.argparse import InfuseDeviceId
@@ -32,7 +32,7 @@ class SubCommand(InfuseCommand):
3232
DESCRIPTION = "Record audio data to a file from TDF"
3333

3434
def __init__(self, args):
35-
self._client = LocalClient(default_multicast_address(), 1.0)
35+
self._client = LocalClient(args.server_sock, 1.0)
3636
self._decoder = TDF()
3737
if args.gateway:
3838
self._id = InfuseID.GATEWAY
@@ -54,6 +54,8 @@ def add_parser(cls, parser):
5454
)
5555
parser.add_argument("--name", type=str, help="Filename prefix")
5656

57+
add_server_port_parser(parser)
58+
5759
def handle_channel(self, channel: str, stack: ExitStack, tdf: TDF.Reading):
5860
if channel == "left":
5961
chan = self._left

src/infuse_iot/tools/auto_activate.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from infuse_iot.socket_comms import (
1919
GatewayRequestConnectionRequest,
2020
LocalClient,
21-
default_multicast_address,
21+
add_server_port_parser,
2222
)
2323
from infuse_iot.tdf import TDF
2424

@@ -31,7 +31,7 @@ class SubCommand(InfuseCommand):
3131
def __init__(self, args):
3232
self.app_ids = args.app
3333
self.active = args.active or False
34-
self.client = LocalClient(default_multicast_address(), 1.0)
34+
self.client = LocalClient(args.server_sock, 1.0)
3535
self.decoder = TDF()
3636
self.state = "Scanning"
3737
self.name = "Active" if args.active else "Inactive"
@@ -47,6 +47,8 @@ def add_parser(cls, parser):
4747
mode_group.add_argument("--active", action="store_true", help="Move all devices to active state")
4848
mode_group.add_argument("--inactive", action="store_true", help="Move all devices to inactive state")
4949

50+
add_server_port_parser(parser)
51+
5052
def progress_table(self):
5153
table = Table()
5254
table.add_column()

src/infuse_iot/tools/bt_log.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ClientNotificationEpacketReceived,
1616
GatewayRequestConnectionRequest,
1717
LocalClient,
18-
default_multicast_address,
18+
add_server_port_parser,
1919
)
2020
from infuse_iot.tdf import TDF
2121
from infuse_iot.util.argparse import InfuseDeviceId
@@ -28,7 +28,7 @@ class SubCommand(InfuseCommand):
2828
DESCRIPTION = "Connect to remote Bluetooth device serial logs"
2929

3030
def __init__(self, args):
31-
self._client = LocalClient(default_multicast_address(), 1.0)
31+
self._client = LocalClient(args.server_sock, 1.0)
3232
self._decoder = TDF()
3333
self._id = args.id
3434
self._data = args.data
@@ -41,6 +41,7 @@ def add_parser(cls, parser):
4141
parser.add_argument(
4242
"--conn-timeout", type=int, default=10000, help="Timeout to wait for a connection to the device (ms)"
4343
)
44+
add_server_port_parser(parser)
4445

4546
def run(self):
4647
if not self._client.comms_check():

src/infuse_iot/tools/data_logger_sync.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from infuse_iot.socket_comms import (
2929
GatewayRequestConnectionRequest,
3030
LocalClient,
31-
default_multicast_address,
31+
add_server_port_parser,
3232
)
3333
from infuse_iot.util.argparse import ValidDir
3434

@@ -65,7 +65,7 @@ class SubCommand(InfuseCommand):
6565
DESCRIPTION = "Synchronise data logger state from remote devices"
6666

6767
def __init__(self, args):
68-
self._client = LocalClient(default_multicast_address(), 1.0)
68+
self._client = LocalClient(args.server_sock, 1.0)
6969
self._min_rssi: int | None = args.rssi
7070
self._app = args.app
7171
self._out = args.out
@@ -112,6 +112,8 @@ def add_parser(cls, parser):
112112
help="Synchronise removable loggers",
113113
)
114114

115+
add_server_port_parser(parser)
116+
115117
def progress_table(self):
116118
table = Table()
117119
table.add_column("Device ID")

src/infuse_iot/tools/gateway.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
GatewayRequestEpacketSend,
5252
GatewayRequestObservedDevices,
5353
LocalServer,
54-
default_multicast_address,
54+
add_server_port_parser,
5555
)
5656
from infuse_iot.util.argparse import ValidFile
5757
from infuse_iot.util.console import Console
@@ -529,7 +529,7 @@ def add_parser(cls, parser):
529529
)
530530
parser.add_argument("--baud", type=int, default=115200, help="Baudrate for serial port")
531531
parser.add_argument("--root", type=ValidFile, help="Root identity certificate to use instead of cloud")
532-
parser.add_argument("--server-port", type=int, help="Alternate multicast port to use")
532+
add_server_port_parser(parser)
533533

534534
def __init__(self, args: argparse.Namespace):
535535
self.port: SerialLike
@@ -545,8 +545,7 @@ def __init__(self, args: argparse.Namespace):
545545
if args.display_only:
546546
self.server = None
547547
else:
548-
addr = default_multicast_address(args.server_port) if args.server_port else default_multicast_address()
549-
self.server = LocalServer(addr)
548+
self.server = LocalServer(args.server_sock)
550549
self.rpc_server = LocalRpcServer(self.ddb)
551550
self._common = CommonThreadState(self.server, self.port, self.ddb, self.rpc_server)
552551
self.log = args.log

src/infuse_iot/tools/localhost.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from infuse_iot.socket_comms import (
2727
ClientNotificationEpacketReceived,
2828
LocalClient,
29-
default_multicast_address,
29+
add_server_port_parser,
3030
)
3131
from infuse_iot.tdf import TDF
3232
from infuse_iot.time import InfuseTime
@@ -42,6 +42,7 @@ class SubCommand(InfuseCommand):
4242
@classmethod
4343
def add_parser(cls, parser):
4444
parser.add_argument("--port", "-p", type=int, default=8080, help="Port number for localhost server")
45+
add_server_port_parser(parser)
4546

4647
def __init__(self, args):
4748
self._data_lock = threading.Lock()
@@ -51,7 +52,7 @@ def __init__(self, args):
5152
self._data: dict[int, dict] = {}
5253
self._port: int = args.port
5354

54-
self._client = LocalClient(default_multicast_address(), 1.0)
55+
self._client = LocalClient(args.server_sock, 1.0)
5556
self._decoder = TDF()
5657

5758
# Serve the HTML file

src/infuse_iot/tools/native_bt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
GatewayRequestConnectionRequest,
4444
GatewayRequestEpacketSend,
4545
LocalServer,
46-
default_multicast_address,
46+
add_server_port_parser,
4747
)
4848
from infuse_iot.util.argparse import BtLeAddress, ValidFile
4949
from infuse_iot.util.console import Console
@@ -212,11 +212,12 @@ class SubCommand(InfuseCommand):
212212
@classmethod
213213
def add_parser(cls, parser):
214214
parser.add_argument("--root", type=ValidFile, help="Root identity certificate to use instead of cloud")
215+
add_server_port_parser(parser)
215216

216217
def __init__(self, args: argparse.Namespace):
217218
self.infuse_manu = 0x0DE4
218219
self.database = DeviceDatabase(args.root)
219-
self.server = LocalServer(default_multicast_address())
220+
self.server = LocalServer(args.server_sock)
220221
self.bleak_mapping: dict[int, BLEDevice] = {}
221222
self.unknown_networks: set[int] = set()
222223
Console.init()

src/infuse_iot/tools/ota_upgrade.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from infuse_iot.socket_comms import (
2929
GatewayRequestConnectionRequest,
3030
LocalClient,
31-
default_multicast_address,
31+
add_server_port_parser,
3232
)
3333
from infuse_iot.util.argparse import InfuseDeviceId, ValidFile, ValidRelease
3434
from infuse_iot.util.crc import crc16_ccitt
@@ -41,7 +41,7 @@ class SubCommand(InfuseCommand):
4141
DESCRIPTION = "Automatically OTA upgrade observed devices"
4242

4343
def __init__(self, args):
44-
self._client = LocalClient(default_multicast_address(), 1.0)
44+
self._client = LocalClient(args.server_sock, 1.0)
4545
self._conn_timeout = args.conn_timeout
4646
self._min_rssi: int | None = args.rssi
4747
self._explicit_ids: list[int] = []
@@ -107,6 +107,8 @@ def add_parser(cls, parser):
107107
explicit.add_argument("--id", type=InfuseDeviceId, help="Single device to upgrade")
108108
explicit.add_argument("--list", type=ValidFile, help="File containing a list of IDs to upgrade")
109109

110+
add_server_port_parser(parser)
111+
110112
def progress_table(self):
111113
table = Table()
112114
table.add_column(f"{self._app_name}\n{self._new_ver}")

src/infuse_iot/tools/rpc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
ClientNotificationEpacketReceived,
2121
GatewayRequestConnectionRequest,
2222
LocalClient,
23-
default_multicast_address,
23+
add_server_port_parser,
2424
)
2525
from infuse_iot.util.argparse import InfuseDeviceId
2626

@@ -56,9 +56,11 @@ def add_parser(cls, parser):
5656
cmd_parser.set_defaults(rpc_class=cmd_cls)
5757
cmd_cls.add_parser(cmd_parser)
5858

59+
add_server_port_parser(parser)
60+
5961
def __init__(self, args: argparse.Namespace):
6062
self._args = args
61-
self._client = LocalClient(default_multicast_address(), 1.0)
63+
self._client = LocalClient(args.server_sock, 1.0)
6264
self._command: InfuseRpcCommand = args.rpc_class(args)
6365
self._request_id = random.randint(0, 2**32 - 1)
6466
self._max_payload = 0

0 commit comments

Comments
 (0)