mbed-os
Dependents: cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more
tools/detect_targets.py@0:b74591d5ab33, 2017-12-11 (annotated)
- Committer:
- be_bryan
- Date:
- Mon Dec 11 17:54:04 2017 +0000
- Revision:
- 0:b74591d5ab33
motor ++
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
be_bryan | 0:b74591d5ab33 | 1 | #! /usr/bin/env python2 |
be_bryan | 0:b74591d5ab33 | 2 | """ |
be_bryan | 0:b74591d5ab33 | 3 | mbed SDK |
be_bryan | 0:b74591d5ab33 | 4 | Copyright (c) 2011-2013 ARM Limited |
be_bryan | 0:b74591d5ab33 | 5 | |
be_bryan | 0:b74591d5ab33 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
be_bryan | 0:b74591d5ab33 | 7 | you may not use this file except in compliance with the License. |
be_bryan | 0:b74591d5ab33 | 8 | You may obtain a copy of the License at |
be_bryan | 0:b74591d5ab33 | 9 | |
be_bryan | 0:b74591d5ab33 | 10 | http://www.apache.org/licenses/LICENSE-2.0 |
be_bryan | 0:b74591d5ab33 | 11 | |
be_bryan | 0:b74591d5ab33 | 12 | Unless required by applicable law or agreed to in writing, software |
be_bryan | 0:b74591d5ab33 | 13 | distributed under the License is distributed on an "AS IS" BASIS, |
be_bryan | 0:b74591d5ab33 | 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
be_bryan | 0:b74591d5ab33 | 15 | See the License for the specific language governing permissions and |
be_bryan | 0:b74591d5ab33 | 16 | limitations under the License. |
be_bryan | 0:b74591d5ab33 | 17 | """ |
be_bryan | 0:b74591d5ab33 | 18 | import sys |
be_bryan | 0:b74591d5ab33 | 19 | import os |
be_bryan | 0:b74591d5ab33 | 20 | import re |
be_bryan | 0:b74591d5ab33 | 21 | |
be_bryan | 0:b74591d5ab33 | 22 | ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) |
be_bryan | 0:b74591d5ab33 | 23 | sys.path.insert(0, ROOT) |
be_bryan | 0:b74591d5ab33 | 24 | |
be_bryan | 0:b74591d5ab33 | 25 | from tools.options import get_default_options_parser |
be_bryan | 0:b74591d5ab33 | 26 | |
be_bryan | 0:b74591d5ab33 | 27 | # Check: Extra modules which are required by core test suite |
be_bryan | 0:b74591d5ab33 | 28 | from tools.utils import check_required_modules |
be_bryan | 0:b74591d5ab33 | 29 | check_required_modules(['prettytable']) |
be_bryan | 0:b74591d5ab33 | 30 | |
be_bryan | 0:b74591d5ab33 | 31 | # Imports related to mbed build api |
be_bryan | 0:b74591d5ab33 | 32 | from tools.build_api import mcu_toolchain_matrix |
be_bryan | 0:b74591d5ab33 | 33 | from tools.test_api import get_autodetected_MUTS_list |
be_bryan | 0:b74591d5ab33 | 34 | from tools.test_api import get_module_avail |
be_bryan | 0:b74591d5ab33 | 35 | from argparse import ArgumentParser |
be_bryan | 0:b74591d5ab33 | 36 | |
be_bryan | 0:b74591d5ab33 | 37 | try: |
be_bryan | 0:b74591d5ab33 | 38 | import mbed_lstools |
be_bryan | 0:b74591d5ab33 | 39 | except: |
be_bryan | 0:b74591d5ab33 | 40 | pass |
be_bryan | 0:b74591d5ab33 | 41 | |
be_bryan | 0:b74591d5ab33 | 42 | def main(): |
be_bryan | 0:b74591d5ab33 | 43 | """Entry Point""" |
be_bryan | 0:b74591d5ab33 | 44 | try: |
be_bryan | 0:b74591d5ab33 | 45 | # Parse Options |
be_bryan | 0:b74591d5ab33 | 46 | parser = ArgumentParser() |
be_bryan | 0:b74591d5ab33 | 47 | |
be_bryan | 0:b74591d5ab33 | 48 | parser.add_argument("-S", "--supported-toolchains", |
be_bryan | 0:b74591d5ab33 | 49 | action="store_true", |
be_bryan | 0:b74591d5ab33 | 50 | dest="supported_toolchains", |
be_bryan | 0:b74591d5ab33 | 51 | default=False, |
be_bryan | 0:b74591d5ab33 | 52 | help="Displays supported matrix of" |
be_bryan | 0:b74591d5ab33 | 53 | " targets and toolchains") |
be_bryan | 0:b74591d5ab33 | 54 | |
be_bryan | 0:b74591d5ab33 | 55 | parser.add_argument('-f', '--filter', |
be_bryan | 0:b74591d5ab33 | 56 | dest='general_filter_regex', |
be_bryan | 0:b74591d5ab33 | 57 | default=None, |
be_bryan | 0:b74591d5ab33 | 58 | help='Filter targets') |
be_bryan | 0:b74591d5ab33 | 59 | |
be_bryan | 0:b74591d5ab33 | 60 | parser.add_argument("-v", "--verbose", |
be_bryan | 0:b74591d5ab33 | 61 | action="store_true", |
be_bryan | 0:b74591d5ab33 | 62 | dest="verbose", |
be_bryan | 0:b74591d5ab33 | 63 | default=False, |
be_bryan | 0:b74591d5ab33 | 64 | help="Verbose diagnostic output") |
be_bryan | 0:b74591d5ab33 | 65 | |
be_bryan | 0:b74591d5ab33 | 66 | options = parser.parse_args() |
be_bryan | 0:b74591d5ab33 | 67 | |
be_bryan | 0:b74591d5ab33 | 68 | # Only prints matrix of supported toolchains |
be_bryan | 0:b74591d5ab33 | 69 | if options.supported_toolchains: |
be_bryan | 0:b74591d5ab33 | 70 | print mcu_toolchain_matrix( |
be_bryan | 0:b74591d5ab33 | 71 | platform_filter=options.general_filter_regex) |
be_bryan | 0:b74591d5ab33 | 72 | exit(0) |
be_bryan | 0:b74591d5ab33 | 73 | |
be_bryan | 0:b74591d5ab33 | 74 | # If auto_detect attribute is present, we assume other auto-detection |
be_bryan | 0:b74591d5ab33 | 75 | # parameters like 'toolchains_filter' are also set. |
be_bryan | 0:b74591d5ab33 | 76 | muts = get_autodetected_MUTS_list() |
be_bryan | 0:b74591d5ab33 | 77 | |
be_bryan | 0:b74591d5ab33 | 78 | mcu_filter = options.general_filter_regex or ".*" |
be_bryan | 0:b74591d5ab33 | 79 | |
be_bryan | 0:b74591d5ab33 | 80 | count = 0 |
be_bryan | 0:b74591d5ab33 | 81 | for mut in muts.values(): |
be_bryan | 0:b74591d5ab33 | 82 | if re.match(mcu_filter, mut['mcu']): |
be_bryan | 0:b74591d5ab33 | 83 | interface_version = get_interface_version(mut['disk']) |
be_bryan | 0:b74591d5ab33 | 84 | print "" |
be_bryan | 0:b74591d5ab33 | 85 | print "[mbed] Detected %s, port %s, mounted %s, interface version %s:" % \ |
be_bryan | 0:b74591d5ab33 | 86 | (mut['mcu'], mut['port'], mut['disk'], interface_version) |
be_bryan | 0:b74591d5ab33 | 87 | |
be_bryan | 0:b74591d5ab33 | 88 | print "[mbed] Supported toolchains for %s" % mut['mcu'] |
be_bryan | 0:b74591d5ab33 | 89 | print mcu_toolchain_matrix(platform_filter=mut['mcu']) |
be_bryan | 0:b74591d5ab33 | 90 | count += 1 |
be_bryan | 0:b74591d5ab33 | 91 | |
be_bryan | 0:b74591d5ab33 | 92 | if count == 0: |
be_bryan | 0:b74591d5ab33 | 93 | print "[mbed] No mbed targets were detected on your system." |
be_bryan | 0:b74591d5ab33 | 94 | |
be_bryan | 0:b74591d5ab33 | 95 | except KeyboardInterrupt: |
be_bryan | 0:b74591d5ab33 | 96 | print "\n[CTRL+c] exit" |
be_bryan | 0:b74591d5ab33 | 97 | except Exception as exc: |
be_bryan | 0:b74591d5ab33 | 98 | import traceback |
be_bryan | 0:b74591d5ab33 | 99 | traceback.print_exc(file=sys.stdout) |
be_bryan | 0:b74591d5ab33 | 100 | print "[ERROR] %s" % str(exc) |
be_bryan | 0:b74591d5ab33 | 101 | sys.exit(1) |
be_bryan | 0:b74591d5ab33 | 102 | |
be_bryan | 0:b74591d5ab33 | 103 | def get_interface_version(mount_point): |
be_bryan | 0:b74591d5ab33 | 104 | """ Function returns interface version from the target mounted on the specified mount point |
be_bryan | 0:b74591d5ab33 | 105 | |
be_bryan | 0:b74591d5ab33 | 106 | mount_point can be acquired via the following: |
be_bryan | 0:b74591d5ab33 | 107 | muts = get_autodetected_MUTS_list() |
be_bryan | 0:b74591d5ab33 | 108 | for mut in muts.values(): |
be_bryan | 0:b74591d5ab33 | 109 | mount_point = mut['disk'] |
be_bryan | 0:b74591d5ab33 | 110 | |
be_bryan | 0:b74591d5ab33 | 111 | @param mount_point Name of disk where platform is connected to host machine. |
be_bryan | 0:b74591d5ab33 | 112 | """ |
be_bryan | 0:b74591d5ab33 | 113 | if get_module_avail('mbed_lstools'): |
be_bryan | 0:b74591d5ab33 | 114 | try : |
be_bryan | 0:b74591d5ab33 | 115 | mbeds = mbed_lstools.create() |
be_bryan | 0:b74591d5ab33 | 116 | details_txt = mbeds.get_details_txt(mount_point) |
be_bryan | 0:b74591d5ab33 | 117 | |
be_bryan | 0:b74591d5ab33 | 118 | if 'Interface Version' in details_txt: |
be_bryan | 0:b74591d5ab33 | 119 | return details_txt['Interface Version'] |
be_bryan | 0:b74591d5ab33 | 120 | |
be_bryan | 0:b74591d5ab33 | 121 | elif 'Version' in details_txt: |
be_bryan | 0:b74591d5ab33 | 122 | return details_txt['Version'] |
be_bryan | 0:b74591d5ab33 | 123 | |
be_bryan | 0:b74591d5ab33 | 124 | except : |
be_bryan | 0:b74591d5ab33 | 125 | return 'unknown' |
be_bryan | 0:b74591d5ab33 | 126 | |
be_bryan | 0:b74591d5ab33 | 127 | return 'unknown' |
be_bryan | 0:b74591d5ab33 | 128 | |
be_bryan | 0:b74591d5ab33 | 129 | if __name__ == '__main__': |
be_bryan | 0:b74591d5ab33 | 130 | main() |