Add DASP device discovery to the connect dialog
Send DISCOVER broadcast (type 0) to 255.255.255.255 and the Sedona multicast address 239.255.18.76 to find devices on the network. Responses are listed in a Treeview showing IP and platform ID. Selecting a device fills the Host field; double-click connects. Wait time is configurable (default 10s, range 1-60s). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -945,8 +945,55 @@ class DaspSocket:
|
||||
continue
|
||||
break
|
||||
|
||||
def discover(self, port=DEFAULT_PORT, wait_time=3):
|
||||
"""Send DASP DISCOVER broadcast and collect responding devices.
|
||||
|
||||
Returns a list of (ip_address, platform_id) tuples.
|
||||
"""
|
||||
self._discovered = []
|
||||
self._discover_active = True
|
||||
|
||||
msg = DaspMsg()
|
||||
msg.msg_type = DISCOVER
|
||||
msg.session_id = 0xFFFF
|
||||
msg.seq_num = 0xFFFF
|
||||
msg.include_message_len = False
|
||||
data = msg.encode()
|
||||
|
||||
with self._send_lock:
|
||||
try:
|
||||
self._sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
||||
except OSError:
|
||||
pass
|
||||
try:
|
||||
self._sock.sendto(data, ("255.255.255.255", port))
|
||||
except OSError:
|
||||
pass
|
||||
# also try the multicast address used by the Sedona spec
|
||||
try:
|
||||
self._sock.sendto(data, ("239.255.18.76", port))
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
time.sleep(wait_time)
|
||||
self._discover_active = False
|
||||
|
||||
seen = set()
|
||||
result = []
|
||||
for addr, pid in self._discovered:
|
||||
if addr not in seen:
|
||||
seen.add(addr)
|
||||
result.append((addr, pid or ""))
|
||||
return result
|
||||
|
||||
def _dispatch(self, msg, addr, raw=None):
|
||||
_trace("R", msg, raw)
|
||||
|
||||
# Handle DISCOVER responses (from devices replying to our broadcast)
|
||||
if msg.msg_type == DISCOVER and getattr(self, '_discover_active', False):
|
||||
self._discovered.append((addr[0], msg.platform_id))
|
||||
return
|
||||
|
||||
session_id = msg.session_id
|
||||
with self._sessions_lock:
|
||||
session = self._sessions.get(session_id)
|
||||
|
||||
Reference in New Issue
Block a user