Skip to content

Commit

Permalink
updated get_port_by_location
Browse files Browse the repository at this point in the history
  • Loading branch information
AviaAv committed Jan 17, 2024
1 parent 7b03dff commit 3e3344c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 38 deletions.
15 changes: 6 additions & 9 deletions unit-tests/py/rspy/acroname.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(self):
if discover() is None: # raise an error if there is no hub connected
raise NoneFoundError()
self.hub = None
self.all_hubs = None

def connect(self, reset = False, req_spec = None ):
"""
Expand Down Expand Up @@ -95,12 +96,6 @@ def connect(self, reset = False, req_spec = None ):
return
raise RuntimeError("failed to reconnect to Acroname (result={})".format(result))

def find_all_hubs(self):
"""
Yields all hub port numbers
"""
yield from device_hub.find_all_hubs('24ff')


def is_connected(self):
return self.hub is not None and self.hub.isConnected()
Expand Down Expand Up @@ -287,7 +282,7 @@ def _port_power(self, port ):
return volt * amps

if 'windows' in platform.system().lower():
def _get_port_by_loc(self, usb_location, hubs):
def get_port_by_location(self, usb_location):
"""
"""
if usb_location:
Expand All @@ -309,9 +304,11 @@ def _get_port_by_loc(self, usb_location, hubs):
return get_port_from_usb(first_index, second_index)
else:

def _get_port_by_loc(self, usb_location, hubs):
def get_port_by_location(self, usb_location):
"""
"""
if not self.all_hubs:
self.all_hubs = device_hub.find_all_hubs('24ff') # 24ff is Acroname VendorID
if usb_location:
#
# Devices connected through an acroname will be in one of two sub-hubs under the acroname main
Expand All @@ -332,7 +329,7 @@ def _get_port_by_loc(self, usb_location, hubs):
# NOTE: some of our devices are hubs themselves! For example, the SR300 will show as '2-2.3.2.1' --
# we must start a known hub or else the ports we look at are meaningless...
#
for port in hubs:
for port in self.all_hubs:
if usb_location.startswith(port + '.'):
match = re.search(r'^(\d+)\.(\d+)', usb_location[len(port) + 1:])
if match:
Expand Down
13 changes: 1 addition & 12 deletions unit-tests/py/rspy/device_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def disable_ports( self, ports = None, sleep_on_change = 0 ):
pass

@abstractmethod
def _get_port_by_loc(self, usb_location, hubs):
def get_port_by_location(self, usb_location):
"""
"""
pass
Expand All @@ -106,17 +106,6 @@ def recycle_ports(self, portlist = None, timeout = 2 ):
#
return result

def get_port_by_location(self, physical_port, usb_location, hubs):
port = None
try:
port = self._get_port_by_loc(usb_location, hubs)
except Exception as e:
log.e('Failed to get device port:', e)
log.d(' physical port is', physical_port)
log.d(' USB location is', usb_location)

return usb_location, port


#################################

Expand Down
15 changes: 6 additions & 9 deletions unit-tests/py/rspy/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def usage():

_device_by_sn = dict()
_context = None
_hubs = set()


class Device:
Expand All @@ -79,7 +78,12 @@ def __init__( self, sn, dev ):
log.e('Failed to get usb location:', e)
self._port = None
if hub:
self._port = hub.get_port_by_location(self._physical_port, self._usb_location, _hubs)
try:
self._port = hub.get_port_by_location(self._usb_location)
except Exception as e:
log.e('Failed to get device port:', e)
log.d(' physical port is', self._physical_port)
log.d(' USB location is', self._usb_location)

self._removed = False

Expand Down Expand Up @@ -214,10 +218,6 @@ def query( monitor_changes=True, hub_reset=False, recycle_ports=True ):
hub.connect(hub_reset)
hub.disable_ports( sleep_on_change = 5 )
hub.enable_ports( sleep_on_change = MAX_ENUMERATION_TIME )

if platform.system() == 'Linux':
global _hubs
_hubs = set(hub.find_all_hubs())
#
# Get all devices, and store by serial-number
global _device_by_sn, _context, _port_to_sn
Expand Down Expand Up @@ -707,9 +707,6 @@ def _get_usb_location( physical_port ):
if not hub.is_connected():
hub.connect()

if platform.system() == 'Linux':
_hubs = set(hub.find_all_hubs())

action = 'list'
def get_handle(dev):
return dev.handle
Expand Down
11 changes: 3 additions & 8 deletions unit-tests/py/rspy/ykush.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,8 @@ def disable_ports( self, ports = None, sleep_on_change = 0 ):

return result

def find_all_hubs(self):
"""
Yields all hub port numbers
"""
yield from device_hub.find_all_hubs('04d8' )

if 'windows' in platform.system().lower():
def _get_port_by_loc(self, usb_location, hubs):
def get_port_by_location(self, usb_location):
"""
"""
if usb_location:
Expand All @@ -196,9 +190,10 @@ def _get_port_by_loc(self, usb_location, hubs):
return get_port_from_usb(index)
else:

def _get_port_by_loc(self, usb_location, hubs):
def get_port_by_location(self, usb_location):
"""
"""
# if needed at some point, YKUSH VendorID is '04d8'
return get_port_from_usb(int(usb_location.split(".")[1]))


Expand Down

0 comments on commit 3e3344c

Please sign in to comment.