feat: Integrate dongle model detection and refactor scan_devices
This commit integrates the dongle model detection logic into . It refactors the method to: - Handle in list or object format. - Extract and for each device. - Use to identify dongle models. - Return a more detailed device information structure. The previously deleted files were moved to the directory.
This commit is contained in:
parent
0e8d75c85c
commit
183b5659b7
Binary file not shown.
|
Before Width: | Height: | Size: 851 KiB |
@ -78,6 +78,14 @@ class MultiDongle:
|
||||
# 'YCBCR422_Y0CBY1CR': kp.ImageFormat.KP_IMAGE_FORMAT_Y0CBY1CR,
|
||||
}
|
||||
|
||||
DongleModelMap = {
|
||||
"0x100": "KL520",
|
||||
"0x720": "KL720",
|
||||
"0x630": "KL630",
|
||||
"0x730": "KL730",
|
||||
"0x540": "KL540",
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def scan_devices():
|
||||
"""
|
||||
@ -98,67 +106,33 @@ class MultiDongle:
|
||||
|
||||
devices_info = []
|
||||
|
||||
# Handle both dict and object formats
|
||||
if isinstance(device_descriptors, dict):
|
||||
# Handle JSON dict format: {"0": {...}, "1": {...}}
|
||||
print(f' - Found {len(device_descriptors)} device(s):')
|
||||
|
||||
for key, device_desc in device_descriptors.items():
|
||||
# Get device series using product_id
|
||||
series = MultiDongle._get_device_series(device_desc)
|
||||
# Use usb_port_id from the device descriptor
|
||||
port_id = device_desc.get('usb_port_id', 0)
|
||||
# device_descriptors can be a list of devices or a single device object
|
||||
devices = device_descriptors
|
||||
if not isinstance(devices, list):
|
||||
devices = [devices]
|
||||
|
||||
print(f' - Found {len(devices)} device(s):')
|
||||
|
||||
for i, device_desc in enumerate(devices):
|
||||
try:
|
||||
product_id_hex = hex(device_desc.product_id).strip().lower()
|
||||
dongle_model = MultiDongle.DongleModelMap.get(product_id_hex, "Unknown")
|
||||
|
||||
device_info = {
|
||||
'port_id': port_id,
|
||||
'series': series,
|
||||
'port_id': device_desc.usb_port_id,
|
||||
'product_id': product_id_hex,
|
||||
'kn_number': device_desc.kn_number,
|
||||
'dongle': dongle_model,
|
||||
'series': dongle_model, # Assuming series is the same as dongle model
|
||||
'device_descriptor': device_desc
|
||||
}
|
||||
devices_info.append(device_info)
|
||||
|
||||
print(f' [{int(key)+1}] Port ID: {port_id}, Series: {series}, Product ID: {device_desc.get("product_id", "Unknown")}')
|
||||
|
||||
elif isinstance(device_descriptors, (list, tuple)):
|
||||
# Handle list/array format
|
||||
print(f' - Found {len(device_descriptors)} device(s):')
|
||||
|
||||
for i, device_desc in enumerate(device_descriptors):
|
||||
# Get device series
|
||||
series = MultiDongle._get_device_series(device_desc)
|
||||
|
||||
# Extract port_id based on format
|
||||
if isinstance(device_desc, dict):
|
||||
port_id = device_desc.get('usb_port_id', device_desc.get('port_id', 0))
|
||||
else:
|
||||
port_id = getattr(device_desc, 'usb_port_id', getattr(device_desc, 'port_id', 0))
|
||||
|
||||
device_info = {
|
||||
'port_id': port_id,
|
||||
'series': series,
|
||||
'device_descriptor': device_desc
|
||||
}
|
||||
devices_info.append(device_info)
|
||||
|
||||
print(f' [{i+1}] Port ID: {port_id}, Series: {series}')
|
||||
else:
|
||||
# Handle single device or other formats
|
||||
print(' - Found 1 device:')
|
||||
series = MultiDongle._get_device_series(device_descriptors)
|
||||
|
||||
if isinstance(device_descriptors, dict):
|
||||
port_id = device_descriptors.get('usb_port_id', device_descriptors.get('port_id', 0))
|
||||
else:
|
||||
port_id = getattr(device_descriptors, 'usb_port_id', getattr(device_descriptors, 'port_id', 0))
|
||||
|
||||
device_info = {
|
||||
'port_id': port_id,
|
||||
'series': series,
|
||||
'device_descriptor': device_descriptors
|
||||
}
|
||||
devices_info.append(device_info)
|
||||
|
||||
print(f' [1] Port ID: {port_id}, Series: {series}')
|
||||
|
||||
print(f' [{i+1}] Port ID: {device_info["port_id"]}, Series: {device_info["series"]}, Product ID: {device_info["product_id"]}, KN Number: {device_info["kn_number"]}')
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error processing device: {e}")
|
||||
|
||||
return devices_info
|
||||
|
||||
except kp.ApiKPException as exception:
|
||||
@ -177,20 +151,11 @@ class MultiDongle:
|
||||
str: Device series (e.g., 'KL520', 'KL720', etc.)
|
||||
"""
|
||||
try:
|
||||
# TODO: Check Product ID to device series mapping
|
||||
product_id_mapping = {
|
||||
'0x100': 'KL520',
|
||||
'0x720': 'KL720',
|
||||
'0x630': 'KL630',
|
||||
'0x730': 'KL730',
|
||||
'0x540': 'KL540',
|
||||
}
|
||||
|
||||
# Handle dict format (from JSON)
|
||||
if isinstance(device_descriptor, dict):
|
||||
product_id = device_descriptor.get('product_id', '')
|
||||
if product_id in product_id_mapping:
|
||||
return product_id_mapping[product_id]
|
||||
if product_id in MultiDongle.DongleModelMap:
|
||||
return MultiDongle.DongleModelMap[product_id]
|
||||
return f'Unknown ({product_id})'
|
||||
|
||||
# Handle object format (from SDK)
|
||||
@ -198,8 +163,8 @@ class MultiDongle:
|
||||
product_id = device_descriptor.product_id
|
||||
if isinstance(product_id, int):
|
||||
product_id = hex(product_id)
|
||||
if product_id in product_id_mapping:
|
||||
return product_id_mapping[product_id]
|
||||
if product_id in MultiDongle.DongleModelMap:
|
||||
return MultiDongle.DongleModelMap[product_id]
|
||||
return f'Unknown ({product_id})'
|
||||
|
||||
# Legacy chip-based detection (fallback)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user