Skip to content

Commit af4869a

Browse files
authored
Merge pull request #298 from ARMmbed/detect-targets
Add detect_targets.py script to list the connected target boards
2 parents 0379af1 + fc04cfb commit af4869a

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

tools/detect_targets.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#! /usr/bin/env python2
2+
"""
3+
mbed SDK
4+
Copyright (c) 2011-2013 ARM Limited
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
19+
TEST BUILD & RUN
20+
"""
21+
import sys
22+
import os
23+
import json
24+
25+
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
26+
sys.path.insert(0, ROOT)
27+
28+
29+
from tools.options import get_default_options_parser
30+
31+
# Check: Extra modules which are required by core test suite
32+
from tools.utils import check_required_modules
33+
check_required_modules(['prettytable'])
34+
35+
# Imports related to mbed build api
36+
from tools.build_api import mcu_toolchain_matrix
37+
from tools.test_api import get_autodetected_MUTS_list
38+
39+
40+
if __name__ == '__main__':
41+
try:
42+
# Parse Options
43+
parser = get_default_options_parser()
44+
45+
parser.add_option("-S", "--supported-toolchains",
46+
action="store_true",
47+
dest="supported_toolchains",
48+
default=False,
49+
help="Displays supported matrix of MCUs and toolchains")
50+
51+
parser.add_option('-f', '--filter',
52+
dest='general_filter_regex',
53+
default=None,
54+
help='For some commands you can use filter to filter out results')
55+
56+
parser.add_option("-v", "--verbose",
57+
action="store_true",
58+
dest="verbose",
59+
default=False,
60+
help="Verbose diagnostic output")
61+
62+
(options, args) = parser.parse_args()
63+
64+
# Only prints matrix of supported toolchains
65+
if options.supported_toolchains:
66+
print mcu_toolchain_matrix(platform_filter=options.general_filter_regex)
67+
exit(0)
68+
69+
# If auto_detect attribute is present, we assume other auto-detection
70+
# parameters like 'toolchains_filter' are also set.
71+
print "[mbed] Detecting connected mbed-enabled devices... "
72+
73+
MUTs = get_autodetected_MUTS_list()
74+
75+
for mut in MUTs.values():
76+
print "[mbed] Detected %s, port: %s, mounted: %s"% (mut['mcu'], mut['port'], mut['disk'])
77+
78+
except KeyboardInterrupt, e:
79+
print "\n[CTRL+c] exit"
80+
except Exception,e:
81+
import traceback
82+
traceback.print_exc(file=sys.stdout)
83+
print "[ERROR] %s" % str(e)
84+
sys.exit(1)

0 commit comments

Comments
 (0)