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,
|
# 'YCBCR422_Y0CBY1CR': kp.ImageFormat.KP_IMAGE_FORMAT_Y0CBY1CR,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DongleModelMap = {
|
||||||
|
"0x100": "KL520",
|
||||||
|
"0x720": "KL720",
|
||||||
|
"0x630": "KL630",
|
||||||
|
"0x730": "KL730",
|
||||||
|
"0x540": "KL540",
|
||||||
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def scan_devices():
|
def scan_devices():
|
||||||
"""
|
"""
|
||||||
@ -98,66 +106,32 @@ class MultiDongle:
|
|||||||
|
|
||||||
devices_info = []
|
devices_info = []
|
||||||
|
|
||||||
# Handle both dict and object formats
|
# device_descriptors can be a list of devices or a single device object
|
||||||
if isinstance(device_descriptors, dict):
|
devices = device_descriptors
|
||||||
# Handle JSON dict format: {"0": {...}, "1": {...}}
|
if not isinstance(devices, list):
|
||||||
print(f' - Found {len(device_descriptors)} device(s):')
|
devices = [devices]
|
||||||
|
|
||||||
for key, device_desc in device_descriptors.items():
|
print(f' - Found {len(devices)} device(s):')
|
||||||
# Get device series using product_id
|
|
||||||
series = MultiDongle._get_device_series(device_desc)
|
for i, device_desc in enumerate(devices):
|
||||||
# Use usb_port_id from the device descriptor
|
try:
|
||||||
port_id = device_desc.get('usb_port_id', 0)
|
product_id_hex = hex(device_desc.product_id).strip().lower()
|
||||||
|
dongle_model = MultiDongle.DongleModelMap.get(product_id_hex, "Unknown")
|
||||||
|
|
||||||
device_info = {
|
device_info = {
|
||||||
'port_id': port_id,
|
'port_id': device_desc.usb_port_id,
|
||||||
'series': series,
|
'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
|
'device_descriptor': device_desc
|
||||||
}
|
}
|
||||||
devices_info.append(device_info)
|
devices_info.append(device_info)
|
||||||
|
|
||||||
print(f' [{int(key)+1}] Port ID: {port_id}, Series: {series}, Product ID: {device_desc.get("product_id", "Unknown")}')
|
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"]}')
|
||||||
|
|
||||||
elif isinstance(device_descriptors, (list, tuple)):
|
except Exception as e:
|
||||||
# Handle list/array format
|
print(f"Error processing device: {e}")
|
||||||
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}')
|
|
||||||
|
|
||||||
return devices_info
|
return devices_info
|
||||||
|
|
||||||
@ -177,20 +151,11 @@ class MultiDongle:
|
|||||||
str: Device series (e.g., 'KL520', 'KL720', etc.)
|
str: Device series (e.g., 'KL520', 'KL720', etc.)
|
||||||
"""
|
"""
|
||||||
try:
|
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)
|
# Handle dict format (from JSON)
|
||||||
if isinstance(device_descriptor, dict):
|
if isinstance(device_descriptor, dict):
|
||||||
product_id = device_descriptor.get('product_id', '')
|
product_id = device_descriptor.get('product_id', '')
|
||||||
if product_id in product_id_mapping:
|
if product_id in MultiDongle.DongleModelMap:
|
||||||
return product_id_mapping[product_id]
|
return MultiDongle.DongleModelMap[product_id]
|
||||||
return f'Unknown ({product_id})'
|
return f'Unknown ({product_id})'
|
||||||
|
|
||||||
# Handle object format (from SDK)
|
# Handle object format (from SDK)
|
||||||
@ -198,8 +163,8 @@ class MultiDongle:
|
|||||||
product_id = device_descriptor.product_id
|
product_id = device_descriptor.product_id
|
||||||
if isinstance(product_id, int):
|
if isinstance(product_id, int):
|
||||||
product_id = hex(product_id)
|
product_id = hex(product_id)
|
||||||
if product_id in product_id_mapping:
|
if product_id in MultiDongle.DongleModelMap:
|
||||||
return product_id_mapping[product_id]
|
return MultiDongle.DongleModelMap[product_id]
|
||||||
return f'Unknown ({product_id})'
|
return f'Unknown ({product_id})'
|
||||||
|
|
||||||
# Legacy chip-based detection (fallback)
|
# Legacy chip-based detection (fallback)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user