@@ -69,6 +69,12 @@ class MbedLsToolsBase(object):
69
69
DETAILS_TXT_NAME = 'DETAILS.TXT'
70
70
MBED_HTM_NAME = 'mbed.htm'
71
71
72
+ VENDOR_ID_DEVICE_TYPE_MAP = {
73
+ '0483' : 'stlink' ,
74
+ '0d28' : 'daplink' ,
75
+ '1366' : 'jlink'
76
+ }
77
+
72
78
def __init__ (self , list_unmounted = False , ** kwargs ):
73
79
""" ctor
74
80
"""
@@ -211,13 +217,14 @@ def _update_device_from_fs(self, device, read_details_txt):
211
217
try :
212
218
directory_entries = os .listdir (device ['mount_point' ])
213
219
device ['directory_entries' ] = directory_entries
214
- device ['device_type' ] = self ._detect_device_type (directory_entries )
220
+ device ['device_type' ] = self ._detect_device_type (device )
215
221
device ['target_id' ] = device ['target_id_usb_id' ]
216
222
217
223
{
218
- 'daplink' : self ._update_device_details_daplink ,
224
+ 'daplink' : self ._update_device_details_daplink_compatible ,
225
+ 'stlink' : self ._update_device_details_daplink_compatible ,
219
226
'jlink' : self ._update_device_details_jlink
220
- }[device ['device_type' ]](device , read_details_txt , directory_entries )
227
+ }[device ['device_type' ] or 'daplink' ](device , read_details_txt )
221
228
except (OSError , IOError ) as e :
222
229
logger .warning (
223
230
'Marking device with mount point "%s" as unmounted due to the '
@@ -226,23 +233,22 @@ def _update_device_from_fs(self, device, read_details_txt):
226
233
device ['device_type' ] = 'unknown'
227
234
228
235
229
- def _detect_device_type (self , directory_entries ):
236
+ def _detect_device_type (self , device ):
230
237
""" Returns a string of the device type
231
- @param directory_entries List of directories and files on the device
232
- @return 'daplink' or 'jlink'
238
+ @param device Dictionary containing device information
239
+ @return Device type located in VENDOR_ID_DEVICE_TYPE_MAP or None if unknown
233
240
"""
234
241
235
- return 'jlink' if 'segger.html' in [ e . lower () for e in directory_entries ] else 'daplink'
242
+ return self . VENDOR_ID_DEVICE_TYPE_MAP . get ( device . get ( 'vendor_id' ))
236
243
237
244
238
- def _update_device_details_daplink (self , device , read_details_txt , directory_entries ):
245
+ def _update_device_details_daplink_compatible (self , device , read_details_txt ):
239
246
""" Updates the daplink-specific device information based on files from its 'mount_point'
240
247
@param device Dictionary containing device information
241
248
@param read_details_txt A boolean controlling the presense of the
242
249
output dict attributes read from other files present on the 'mount_point'
243
- @param directory_entries List of directories and files on the device
244
250
"""
245
- lowercase_directory_entries = [e .lower () for e in directory_entries ]
251
+ lowercase_directory_entries = [e .lower () for e in device [ ' directory_entries' ] ]
246
252
if self .MBED_HTM_NAME .lower () in lowercase_directory_entries :
247
253
self ._update_device_from_htm (device )
248
254
elif not read_details_txt :
@@ -271,12 +277,11 @@ def _update_device_details_daplink(self, device, read_details_txt, directory_ent
271
277
else :
272
278
device ['platform_name' ] = None
273
279
274
- def _update_device_details_jlink (self , device , _ , directory_entries ):
280
+ def _update_device_details_jlink (self , device , _ ):
275
281
""" Updates the jlink-specific device information based on files from its 'mount_point'
276
282
@param device Dictionary containing device information
277
- @param directory_entries List of directories and files on the device
278
283
"""
279
- lower_case_map = {e .lower (): e for e in directory_entries }
284
+ lower_case_map = {e .lower (): e for e in device [ ' directory_entries' ] }
280
285
281
286
if 'board.html' in lower_case_map :
282
287
board_file_key = 'board.html'
0 commit comments