Skip to content

Commit eb3bfcb

Browse files
committed
Detecting jlink and daplink devices
1 parent 1e62461 commit eb3bfcb

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

mbed_lstools/lstools_base.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def _fs_before_id_check(self, device, filter_function, include_extra_info):
177177
"""Filter device after touching the file system of the device.
178178
Said another way: Touch the file system before filtering
179179
"""
180+
device['target_id'] = device['target_id_usb_id']
180181
self._update_device_from_fs(device, include_extra_info)
181182
if not filter_function or filter_function(device):
182183
return device
@@ -204,17 +205,16 @@ def _update_device_from_fs(self, device, include_extra_info):
204205

205206
device['device_type'] = self._detect_device_type(device['mount_point'])
206207

207-
# details.txt check happens in here now
208+
device['target_id'] = device['target_id_usb_id']
208209
self._update_device_details(device, include_extra_info)
209210

210-
device['platform_name'] = self.plat_db.get(device['target_id'][0:4],
211-
device_type=device['device_type'])
212-
213-
def _detect_device_type(self, device):
211+
def _detect_device_type(self, mount_point):
214212
""" Returns a string of the device type
215213
@return 'daplink' or 'jlink'
216214
"""
217-
raise NotImplementedError
215+
216+
files = [f.lower() for f in os.listdir(mount_point)]
217+
return 'jlink' if 'segger.html' in files else 'daplink'
218218

219219
def _update_device_details(self, device, include_extra_info):
220220
""" Updates device dict with information from the filesystem
@@ -235,8 +235,30 @@ def _update_device_details_daplink(self, device, include_extra_info):
235235
device.update({"daplink_%s" % f.lower().replace(' ', '_'): v
236236
for f, v in details_txt.items()})
237237

238+
device['platform_name'] = self.plat_db.get(device['target_id'][0:4],
239+
device_type='daplink')
240+
238241
def _update_device_details_jlink(self, device, include_extra_info):
239-
raise NotImplementedError
242+
files = os.listdir(device['mount_point'])
243+
lower_case_map = {f.lower(): f for f in files}
244+
245+
if 'board.html' in lower_case_map:
246+
board_file_key = 'board.html'
247+
elif 'user guide.html' in lower_case_map:
248+
board_file_key = 'user guide.html'
249+
250+
board_file_path = os.path.join(device['mount_point'], lower_case_map[board_file_key])
251+
with open(board_file_path, 'r') as board_file:
252+
board_file_lines = board_file.readlines()
253+
254+
for line in board_file_lines:
255+
m = re.search(r'url=([\w\d\:\-/\\\?\.=-_]+)', line)
256+
if m:
257+
device['url'] = m.group(1).strip()
258+
identifier = device['url'].split('/')[-1]
259+
device['platform_name'] = self.plat_db.get(identifier, device_type='jlink')
260+
break
261+
240262

241263
def _update_device_from_htm(self, device):
242264
"""Set the 'target_id', 'target_id_mbed_htm', 'platform_name' and

0 commit comments

Comments
 (0)