Skip to content

Commit e6d3713

Browse files
committed
Detecting jlink and daplink devices
1 parent 4865935 commit e6d3713

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
@@ -203,17 +204,16 @@ def _update_device_from_fs(self, device, include_extra_info):
203204

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

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

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

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

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

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

0 commit comments

Comments
 (0)