Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devices: Add IDs for devices when multiple of the same type are connected #198

Merged
merged 4 commits into from
Mar 2, 2021

Conversation

wernerlewis
Copy link
Contributor

Description

Refactor device detection to allow for use of multiple of the same device, without having to manually remove, and to clarify default flash behavior in this case.

Previously, if a user had multiple of the same mbed-target connected, the behavior of mbed-tools was to use the first device found which matches the given mbed_target, regardless of how many are connected. That leads to unclear behavior with compile -f/--sterm, and sterm subcommands, and requires manual disconnecting of devices to flash or start a serial terminal with a specific device.

Modified the default behavior of compile -f to find all connected devices of the target type, and flash all that are found, rather than just flashing the first one found.

Allow users to specify a device to use with an ID in compile and sterm: mbed_target[ID]. This allows use of -f/--sterm with any connected device even if others of the same type are connected. The unique build targets with the IDs are displayed with detect.

For example the detect output from #181 would now be:

Board name     Serial number             Serial port    Mount point(s)    Build target(s)
-------------  ------------------------  -------------  ----------------  -----------------
NUCLEO-WB55RG  066dff535456807867075351  COM42          F:                NUCLEO_WB55RG[0]
NUCLEO-WB55RG  066dff545057717867195937  COM26          E:                NUCLEO_WB55RG[1]

Added a print statement to compile -f to tell the user how many files were copied, and whether they were .BIN or .HEX.

Fixes #181

Test Coverage

  • This change is covered by existing or additional automated tests.
  • Manual testing has been performed (and evidence provided) as automated testing was not feasible.
  • Additional tests are not required for this change (e.g. documentation update).

@codecov
Copy link

codecov bot commented Feb 19, 2021

Codecov Report

Merging #198 (40b03b5) into master (c4ccaf1) will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #198      +/-   ##
==========================================
+ Coverage   96.57%   96.63%   +0.05%     
==========================================
  Files          94       94              
  Lines        2629     2671      +42     
==========================================
+ Hits         2539     2581      +42     
  Misses         90       90              
Impacted Files Coverage Δ
src/mbed_tools/build/flash.py 100.00% <100.00%> (ø)
src/mbed_tools/cli/build.py 100.00% <100.00%> (ø)
src/mbed_tools/cli/list_connected_devices.py 100.00% <100.00%> (ø)
src/mbed_tools/cli/sterm.py 100.00% <100.00%> (ø)
src/mbed_tools/devices/__init__.py 100.00% <100.00%> (ø)
src/mbed_tools/devices/devices.py 100.00% <100.00%> (ø)

@wernerlewis wernerlewis force-pushed the dev-detect-multiple branch 2 times, most recently from a9fab3e to cbdd242 Compare February 22, 2021 11:24
Comment on lines 61 to 63
if "[" in target:
target_name, target_id = target.replace("]", "").split("[", maxsplit=1)
if target_id.isdigit() and int(target_id) >= 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should factor this repeated logic into a function.

src/mbed_tools/cli/sterm.py Outdated Show resolved Hide resolved
src/mbed_tools/devices/devices.py Outdated Show resolved Hide resolved
src/mbed_tools/cli/build.py Show resolved Hide resolved
src/mbed_tools/cli/build.py Outdated Show resolved Hide resolved
src/mbed_tools/cli/list_connected_devices.py Outdated Show resolved Hide resolved
src/mbed_tools/cli/list_connected_devices.py Outdated Show resolved Hide resolved
src/mbed_tools/cli/list_connected_devices.py Outdated Show resolved Hide resolved
When using compile, find_connected_device would only find the first
device which matches the target given. When multiple devices of the
same type are connected, this can give unclear behavior and require
manual removal of devices to flash others.

Adds find_connected_devices, which finds all matching devices and
returns them in a list sorted by serial number. In the compile command,
these will each then be flashed in sequence. find_connected_device is
now a special case to be used when only one device is wanted, when
using sterm for example.
When multiple devices of the same type are connected, it is not
possible to choose one specific device to flash or to launch a serial
terminal with. This behavior requires the user to manually manage which
devices are connected, rather than being able to select a specific
board in the tools.

This adds support in sterm and compile for formatting target args as
TARGET_NAME[ID], where the ID corresponds to the device's position when
sorted by serial number. This does not affect behavior when only one
device of the given type is connected, in which case no ID is needed.
When multiple devices of the same type are connected, they are listed
in the detect subcommand with non-unique build targets.

Adds unique build targets when multiple of the same board are connected
by including the device's ID in the format TARGET[ID]. This can then be
used in compile and sterm subcommands.
@Patater Patater merged commit 6cd30a7 into ARMmbed:master Mar 2, 2021
@wernerlewis wernerlewis deleted the dev-detect-multiple branch April 13, 2021 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mbedtools detect with multiple targets
3 participants