Skip to content

Commit

Permalink
Merge pull request #127 from ConorPKeegan/issue_126
Browse files Browse the repository at this point in the history
Add check for USB ID when getting COM port
  • Loading branch information
mazimkhan authored Sep 9, 2016
2 parents 1fb0b7e + 1442ea0 commit 8793f14
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions mbed_lstools/lstools_win7.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,15 @@ def list_mbeds(self):

def discover_connected_mbeds(self, defs={}):
"""! Function produces list of mbeds with additional information and bind mbed with correct TargetID
@return Returns [(<mbed_mount_point>, <mbed_id>, <com port>, <board model>), ..]
@return Returns [(<mbed_mount_point>, <mbed_id>, <com port>, <board model>,
<usb_target_id>, <htm_target_id>), ..]
@details Notice: this function is permissive: adds new elements in-places when and if found
"""
mbeds = [(m[0], m[1], None, None) for m in self.get_connected_mbeds()]
for i in range(len(mbeds)):
mbed = mbeds[i]
mnt = mbed[0]
mbed_htm_target_id = self.get_mbed_htm_target_id(mnt)
# Deducing mbed-enabled TargetID based on available targetID definition DB.
# If TargetID from USBID is not recognized we will try to check URL in mbed.htm
mbed_id = mbed_htm_target_id if mbed_htm_target_id is not None else mbed[1]
mbed_id, mbed_htm_target_id = self.get_mbed_target_id(mnt, mbed[1])
mbed_id_prefix = mbed_id[0:4]
board = defs[mbed_id_prefix] if mbed_id_prefix in defs else None
port = self.get_mbed_com_port(mbed[1])
Expand Down Expand Up @@ -124,6 +122,14 @@ def get_mbed_com_port(self, tid):
return port
except:
pass

# Check for a target USB ID from tid
target_usb_ids = self.get_connected_mbeds_usb_ids()
if tid in target_usb_ids:
if target_usb_ids[tid] != tid:
# Try again with the target USB ID
return self.get_mbed_com_port(target_usb_ids[tid])

# If everything fails, return None
return None

Expand All @@ -134,6 +140,18 @@ def get_connected_mbeds(self):
"""
return [m for m in self.get_mbeds() if self.mount_point_ready(m[0])]

def get_connected_mbeds_usb_ids(self):
"""! Function return mbeds with existing mount point's
target ID mapped to their target USB ID
@return Returns {<target_id>: <target_usb_id>, ...}
@details Helper function
"""
connected_mbeds_ids = {}
for mbed in self.get_connected_mbeds():
target_id, htm_target_id = self.get_mbed_target_id(mbed[0], mbed[1])
connected_mbeds_ids[target_id] = mbed[1]
return connected_mbeds_ids

def get_mbeds(self):
"""! Function filters devices' mount points for valid TargetID
@return Returns [(<mbed_mount_point>, <mbed_id>), ..]
Expand All @@ -148,6 +166,19 @@ def get_mbeds(self):
self.debug(self.get_mbeds.__name__, (mountpoint, tid))
return mbeds

def get_mbed_target_id(self, mnt, target_usb_id):
"""! Function gets the mbed target and HTM IDs
@param mnt mbed mount point (disk / drive letter)
@param target_usb_id mbed target USB ID
@return Function returns (<target_id>, <htm_target_id>)
@details Helper function
"""
mbed_htm_target_id = self.get_mbed_htm_target_id(mnt)
# Deducing mbed-enabled TargetID based on available targetID definition DB.
# If TargetID from USBID is not recognized we will try to check URL in mbed.htm
mbed_id = mbed_htm_target_id if mbed_htm_target_id is not None else target_usb_id
return mbed_id, mbed_htm_target_id

# =============================== Registry ====================================

def iter_keys_as_str(self, key):
Expand Down

0 comments on commit 8793f14

Please sign in to comment.