Skip to content

Commit 758394e

Browse files
committed
Using USB Vendor ID for device type detection
1 parent 281c44a commit 758394e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

mbed_lstools/lstools_base.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ class MbedLsToolsBase(object):
6969
DETAILS_TXT_NAME = 'DETAILS.TXT'
7070
MBED_HTM_NAME = 'mbed.htm'
7171

72+
VENDOR_ID_DEVICE_TYPE_MAP = {
73+
'0483': 'stlink',
74+
'0d28': 'daplink',
75+
'1366': 'jlink'
76+
}
77+
7278
def __init__(self, list_unmounted=False, **kwargs):
7379
""" ctor
7480
"""
@@ -211,13 +217,13 @@ def _update_device_from_fs(self, device, read_details_txt):
211217
try:
212218
directory_entries = os.listdir(device['mount_point'])
213219
device['directory_entries'] = directory_entries
214-
device['device_type'] = self._detect_device_type(directory_entries)
220+
device['device_type'] = self._detect_device_type(device)
215221
device['target_id'] = device['target_id_usb_id']
216222

217223
{
218224
'daplink': self._update_device_details_daplink,
219225
'jlink': self._update_device_details_jlink
220-
}[device['device_type']](device, read_details_txt, directory_entries)
226+
}[device['device_type'] or 'daplink'](device, read_details_txt, directory_entries)
221227
except (OSError, IOError) as e:
222228
logger.warning(
223229
'Marking device with mount point "%s" as unmounted due to the '
@@ -226,13 +232,13 @@ def _update_device_from_fs(self, device, read_details_txt):
226232
device['device_type'] = 'unknown'
227233

228234

229-
def _detect_device_type(self, directory_entries):
235+
def _detect_device_type(self, device):
230236
""" Returns a string of the device type
231-
@param directory_entries List of directories and files on the device
232-
@return 'daplink' or 'jlink'
237+
@param device Dictionary containing device information
238+
@return Device type located in VENDOR_ID_DEVICE_TYPE_MAP or None if unknown
233239
"""
234240

235-
return 'jlink' if 'segger.html' in [e.lower() for e in directory_entries] else 'daplink'
241+
return self.VENDOR_ID_DEVICE_TYPE_MAP.get(device.get('vendor_id'))
236242

237243

238244
def _update_device_details_daplink(self, device, read_details_txt, directory_entries):

0 commit comments

Comments
 (0)