mirror of https://github.com/ARMmbed/mbed-os.git
Remove tools/compliance and tools/dev
### Description
These directories have contained exclusively dead code for as long as
I can remember. Now is as good of a time as any to remove them.
### Pull request type
[x] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change
pull/10254/head
parent
801e555121
commit
b62e041143
|
|
@ -1,16 +0,0 @@
|
|||
"""
|
||||
mbed SDK
|
||||
Copyright (c) 2011-2015 ARM Limited
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
"""
|
||||
mbed SDK
|
||||
Copyright (c) 2011-2015 ARM Limited
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
try:
|
||||
from colorama import Fore
|
||||
except:
|
||||
pass
|
||||
|
||||
COLORAMA = 'colorama' in sys.modules
|
||||
|
||||
|
||||
class IOperTestCaseBase():
|
||||
""" Interoperability test case base class
|
||||
@return list of tuple (severity, Description)
|
||||
Example: (result.append((IOperTestSeverity.INFO, ""))
|
||||
"""
|
||||
|
||||
def __init__(self, scope=None):
|
||||
self.PASS = 'PASS'
|
||||
self.INFO = 'INFO'
|
||||
self.ERROR = 'ERROR'
|
||||
self.WARN = 'WARN'
|
||||
|
||||
self.scope = scope # Default test scope (basic, pedantic, mbed-enabled etc...)
|
||||
|
||||
def test(self, param=None):
|
||||
result = []
|
||||
return result
|
||||
|
||||
def RED(self, text):
|
||||
return self.color_text(text, color=Fore.RED, delim=Fore.RESET) if COLORAMA else text
|
||||
|
||||
def GREEN(self, text):
|
||||
return self.color_text(text, color=Fore.GREEN, delim=Fore.RESET) if COLORAMA else text
|
||||
|
||||
def YELLOW(self, text):
|
||||
return self.color_text(text, color=Fore.YELLOW, delim=Fore.RESET) if COLORAMA else text
|
||||
|
||||
def color_text(self, text, color='', delim=''):
|
||||
return color + text + color + delim
|
||||
|
||||
def COLOR(self, severity, text):
|
||||
colors = {
|
||||
self.PASS : self.GREEN,
|
||||
self.ERROR : self.RED,
|
||||
self.WARN : self.YELLOW
|
||||
}
|
||||
if severity in colors:
|
||||
return colors[severity](text)
|
||||
return text
|
||||
|
|
@ -1,125 +0,0 @@
|
|||
#!/usr/bin/env python2
|
||||
"""
|
||||
mbed SDK
|
||||
Copyright (c) 2011-2015 ARM Limited
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
import mbed_lstools
|
||||
from prettytable import PrettyTable
|
||||
|
||||
try:
|
||||
from colorama import init
|
||||
except:
|
||||
pass
|
||||
|
||||
COLORAMA = 'colorama' in sys.modules
|
||||
|
||||
from ioper_base import IOperTestCaseBase
|
||||
from ioper_test_fs import IOperTest_FileStructure_Basic
|
||||
from ioper_test_fs import IOperTest_FileStructure_MbedEnabled
|
||||
from ioper_test_target_id import IOperTest_TargetID_Basic
|
||||
from ioper_test_target_id import IOperTest_TargetID_MbedEnabled
|
||||
|
||||
|
||||
TEST_LIST = [IOperTest_TargetID_Basic('basic'),
|
||||
IOperTest_TargetID_MbedEnabled('mbed-enabled'),
|
||||
IOperTest_FileStructure_Basic('basic'),
|
||||
IOperTest_FileStructure_MbedEnabled('mbed-enabled'),
|
||||
IOperTestCaseBase('all'), # Dummy used to add 'all' option
|
||||
]
|
||||
|
||||
|
||||
class IOperTestRunner():
|
||||
""" Calls all i/face interoperability tests
|
||||
"""
|
||||
|
||||
def __init__(self, scope=None):
|
||||
""" Test scope:
|
||||
'pedantic' - all
|
||||
'mbed-enabled' - let's try to check if this device is mbed-enabled
|
||||
'basic' - just simple, passive tests (no device flashing)
|
||||
"""
|
||||
self.requested_scope = scope # Test scope given by user
|
||||
self.raw_test_results = {} # Raw test results, can be used by exporters: { Platform: [test results]}
|
||||
|
||||
# Test scope definitions
|
||||
self.SCOPE_BASIC = 'basic' # Basic tests, sanity checks
|
||||
self.SCOPE_MBED_ENABLED = 'mbed-enabled' # Let's try to check if this device is mbed-enabled
|
||||
self.SCOPE_PEDANTIC = 'pedantic' # Extensive tests
|
||||
self.SCOPE_ALL = 'all' # All tests, equal to highest scope level
|
||||
|
||||
# This structure will help us sort test scopes so we can include them
|
||||
# e.g. pedantic also includes basic and mbed-enabled tests
|
||||
self.scopes = {self.SCOPE_BASIC : 0,
|
||||
self.SCOPE_MBED_ENABLED : 1,
|
||||
self.SCOPE_PEDANTIC : 2,
|
||||
self.SCOPE_ALL : 99,
|
||||
}
|
||||
|
||||
if COLORAMA:
|
||||
init() # colorama.init()
|
||||
|
||||
def run(self):
|
||||
""" Run tests, calculate overall score and print test results
|
||||
"""
|
||||
mbeds = mbed_lstools.create()
|
||||
muts_list = mbeds.list_mbeds()
|
||||
test_base = IOperTestCaseBase()
|
||||
|
||||
self.raw_test_results = {}
|
||||
for i, mut in enumerate(muts_list):
|
||||
result = []
|
||||
self.raw_test_results[mut['platform_name']] = []
|
||||
|
||||
print "MBEDLS: Detected %s, port: %s, mounted: %s"% (mut['platform_name'],
|
||||
mut['serial_port'],
|
||||
mut['mount_point'])
|
||||
print "Running interoperability test suite, scope '%s'" % (self.requested_scope)
|
||||
for test_case in TEST_LIST:
|
||||
if self.scopes[self.requested_scope] >= self.scopes[test_case.scope]:
|
||||
res = test_case.test(param=mut)
|
||||
result.extend(res)
|
||||
self.raw_test_results[mut['platform_name']].extend(res)
|
||||
|
||||
columns = ['Platform', 'Test Case', 'Result', 'Scope', 'Description']
|
||||
pt = PrettyTable(columns)
|
||||
for col in columns:
|
||||
pt.align[col] = 'l'
|
||||
|
||||
for tr in result:
|
||||
severity, tr_name, tr_scope, text = tr
|
||||
tr = (test_base.COLOR(severity, mut['platform_name']),
|
||||
test_base.COLOR(severity, tr_name),
|
||||
test_base.COLOR(severity, severity),
|
||||
test_base.COLOR(severity, tr_scope),
|
||||
test_base.COLOR(severity, text))
|
||||
pt.add_row(list(tr))
|
||||
print pt.get_string(border=True, sortby='Result')
|
||||
if i + 1 < len(muts_list):
|
||||
print
|
||||
return self.raw_test_results
|
||||
|
||||
def get_available_oper_test_scopes():
|
||||
""" Get list of available test scopes
|
||||
"""
|
||||
scopes = set()
|
||||
for oper_test in TEST_LIST:
|
||||
if oper_test.scope is not None:
|
||||
scopes.add(oper_test.scope)
|
||||
return list(scopes)
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
"""
|
||||
mbed SDK
|
||||
Copyright (c) 2011-2015 ARM Limited
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
|
||||
|
||||
"""
|
||||
|
||||
import os.path
|
||||
from ioper_base import IOperTestCaseBase
|
||||
|
||||
|
||||
class IOperTest_FileStructure(IOperTestCaseBase):
|
||||
|
||||
def __init__(self, scope=None):
|
||||
IOperTestCaseBase.__init__(self, scope)
|
||||
|
||||
def if_file_exist(self, fname, fail_severity=None):
|
||||
file_path = os.path.join(self.param['mount_point'], fname)
|
||||
exist = os.path.isfile(file_path)
|
||||
tr_name = "FILE_EXIST(%s)" % fname.upper()
|
||||
if exist:
|
||||
self.result.append((self.PASS, tr_name, self.scope, "File '%s' exists" % file_path))
|
||||
else:
|
||||
self.result.append((fail_severity if fail_severity else self.ERROR, tr_name, self.scope, "File '%s' not found" % file_path))
|
||||
|
||||
def test(self, param=None):
|
||||
self.result = []
|
||||
if param:
|
||||
pass
|
||||
return self.result
|
||||
|
||||
|
||||
class IOperTest_FileStructure_Basic(IOperTest_FileStructure):
|
||||
def __init__(self, scope=None):
|
||||
IOperTest_FileStructure.__init__(self, scope)
|
||||
|
||||
def test(self, param=None):
|
||||
self.param = param
|
||||
self.result = []
|
||||
if param:
|
||||
self.if_file_exist('mbed.htm', self.ERROR)
|
||||
return self.result
|
||||
|
||||
|
||||
class IOperTest_FileStructure_MbedEnabled(IOperTest_FileStructure):
|
||||
def __init__(self, scope=None):
|
||||
IOperTest_FileStructure.__init__(self, scope)
|
||||
|
||||
def test(self, param=None):
|
||||
self.param = param
|
||||
self.result = []
|
||||
if param:
|
||||
self.if_file_exist('mbed.htm', self.ERROR)
|
||||
self.if_file_exist('DETAILS.TXT', self.ERROR)
|
||||
self.if_file_exist('FAIL.TXT', self.INFO)
|
||||
return self.result
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
"""
|
||||
mbed SDK
|
||||
Copyright (c) 2011-2015 ARM Limited
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
|
||||
|
||||
"""
|
||||
|
||||
from ioper_base import IOperTestCaseBase
|
||||
|
||||
|
||||
class IOperTest_TargetID(IOperTestCaseBase):
|
||||
""" tests related to target_id value
|
||||
"""
|
||||
|
||||
def __init__(self, scope=None):
|
||||
IOperTestCaseBase.__init__(self, scope)
|
||||
self.TARGET_ID_LEN = 24
|
||||
|
||||
def test_target_id_format(self, target_id, target_id_name):
|
||||
# Expected length == 24, eg. "02400203D94B0E7724B7F3CF"
|
||||
result = []
|
||||
target_id_len = len(target_id) if target_id else 0
|
||||
if target_id_len == self.TARGET_ID_LEN:
|
||||
result.append((self.PASS, "TARGET_ID_LEN", self.scope, "%s '%s' is %d chars long " % (target_id_name, target_id, target_id_len)))
|
||||
result.append((self.INFO, "FW_VER_STR", self.scope, "%s Version String is %s.%s.%s " % (target_id_name,
|
||||
target_id[0:4],
|
||||
target_id[4:8],
|
||||
target_id[8:24],
|
||||
)))
|
||||
else:
|
||||
result.append((self.ERROR, "TARGET_ID_LEN", self.scope, "%s '%s' is %d chars long. Expected %d chars" % (target_id_name, target_id, target_id_len, self.TARGET_ID_LEN)))
|
||||
return result
|
||||
|
||||
def test_decode_target_id(self, target_id, target_id_name):
|
||||
result = []
|
||||
target_id_len = len(target_id) if target_id else 0
|
||||
if target_id_len >= 4:
|
||||
result.append((self.INFO, "FW_VEN_CODE", self.scope, "%s Vendor Code is '%s'" % (target_id_name, target_id[0:2])))
|
||||
result.append((self.INFO, "FW_PLAT_CODE", self.scope, "%s Platform Code is '%s'" % (target_id_name, target_id[2:4])))
|
||||
result.append((self.INFO, "FW_VER", self.scope, "%s Firmware Version is '%s'" % (target_id_name, target_id[4:8])))
|
||||
result.append((self.INFO, "FW_HASH_SEC", self.scope, "%s Hash of secret is '%s'" % (target_id_name, target_id[8:24])))
|
||||
return result
|
||||
|
||||
def test(self, param=None):
|
||||
result = []
|
||||
if param:
|
||||
pass
|
||||
return result
|
||||
|
||||
|
||||
class IOperTest_TargetID_Basic(IOperTest_TargetID):
|
||||
""" Basic interoperability tests checking TargetID compliance
|
||||
"""
|
||||
|
||||
def __init__(self, scope=None):
|
||||
IOperTest_TargetID.__init__(self, scope)
|
||||
|
||||
def test(self, param=None):
|
||||
result = []
|
||||
|
||||
if param:
|
||||
result.append((self.PASS, "TARGET_ID", self.scope, "TargetID '%s' found" % param['target_id']))
|
||||
|
||||
# Check if target name can be decoded with mbed-ls
|
||||
if param['platform_name']:
|
||||
result.append((self.PASS, "TARGET_ID_DECODE", self.scope, "TargetID '%s' decoded as '%s'" % (param['target_id'][0:4], param['platform_name'])))
|
||||
else:
|
||||
result.append((self.ERROR, "TARGET_ID_DECODE", self.scope, "TargetID '%s'... not decoded" % (param['target_id'] if param['target_id'] else '')))
|
||||
|
||||
# Test for USBID and mbed.htm consistency
|
||||
if param['target_id_mbed_htm'] == param['target_id_usb_id']:
|
||||
result.append((self.PASS, "TARGET_ID_MATCH", self.scope, "TargetID (USBID) and TargetID (mbed.htm) match"))
|
||||
else:
|
||||
text = "TargetID (USBID) and TargetID (mbed.htm) don't match: '%s' != '%s'" % (param['target_id_usb_id'], param['target_id_mbed_htm'])
|
||||
result.append((self.WARN, "TARGET_ID_MATCH", self.scope, text))
|
||||
else:
|
||||
result.append((self.ERROR, "TARGET_ID", self.scope, "TargetID not found"))
|
||||
return result
|
||||
|
||||
class IOperTest_TargetID_MbedEnabled(IOperTest_TargetID):
|
||||
""" Basic interoperability tests checking TargetID compliance
|
||||
"""
|
||||
|
||||
def __init__(self, scope=None):
|
||||
IOperTest_TargetID.__init__(self, scope)
|
||||
|
||||
def test(self, param=None):
|
||||
result = []
|
||||
|
||||
if param:
|
||||
# Target ID tests:
|
||||
result += self.test_target_id_format(param['target_id_usb_id'], "TargetId (USBID)")
|
||||
result += self.test_target_id_format(param['target_id_mbed_htm'], "TargetId (mbed.htm)")
|
||||
|
||||
# Some extra info about TargetID itself
|
||||
result += self.test_decode_target_id(param['target_id_usb_id'], "TargetId (USBID)")
|
||||
result += self.test_decode_target_id(param['target_id_mbed_htm'], "TargetId (mbed.htm)")
|
||||
return result
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
"""
|
||||
mbed SDK
|
||||
Copyright (c) 2011-2013 ARM Limited
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
"""
|
||||
mbed SDK
|
||||
Copyright (c) 2011-2013 ARM Limited
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
from numpy import sin, arange, pi
|
||||
from scipy.signal import lfilter, firwin
|
||||
from pylab import figure, plot, grid, show
|
||||
|
||||
#------------------------------------------------
|
||||
# Create a signal for demonstration.
|
||||
#------------------------------------------------
|
||||
# 320 samples of (1000Hz + 15000 Hz) at 48 kHz
|
||||
sample_rate = 48000.
|
||||
nsamples = 320
|
||||
|
||||
F_1KHz = 1000.
|
||||
A_1KHz = 1.0
|
||||
|
||||
F_15KHz = 15000.
|
||||
A_15KHz = 0.5
|
||||
|
||||
t = arange(nsamples) / sample_rate
|
||||
signal = A_1KHz * sin(2*pi*F_1KHz*t) + A_15KHz*sin(2*pi*F_15KHz*t)
|
||||
|
||||
#------------------------------------------------
|
||||
# Create a FIR filter and apply it to signal.
|
||||
#------------------------------------------------
|
||||
# The Nyquist rate of the signal.
|
||||
nyq_rate = sample_rate / 2.
|
||||
|
||||
# The cutoff frequency of the filter: 6KHz
|
||||
cutoff_hz = 6000.0
|
||||
|
||||
# Length of the filter (number of coefficients, i.e. the filter order + 1)
|
||||
numtaps = 29
|
||||
|
||||
# Use firwin to create a lowpass FIR filter
|
||||
fir_coeff = firwin(numtaps, cutoff_hz/nyq_rate)
|
||||
|
||||
# Use lfilter to filter the signal with the FIR filter
|
||||
filtered_signal = lfilter(fir_coeff, 1.0, signal)
|
||||
|
||||
#------------------------------------------------
|
||||
# Plot the original and filtered signals.
|
||||
#------------------------------------------------
|
||||
|
||||
# The first N-1 samples are "corrupted" by the initial conditions
|
||||
warmup = numtaps - 1
|
||||
|
||||
# The phase delay of the filtered signal
|
||||
delay = (warmup / 2) / sample_rate
|
||||
|
||||
figure(1)
|
||||
# Plot the original signal
|
||||
plot(t, signal)
|
||||
|
||||
# Plot the filtered signal, shifted to compensate for the phase delay
|
||||
plot(t-delay, filtered_signal, 'r-')
|
||||
|
||||
# Plot just the "good" part of the filtered signal. The first N-1
|
||||
# samples are "corrupted" by the initial conditions.
|
||||
plot(t[warmup:]-delay, filtered_signal[warmup:], 'g', linewidth=4)
|
||||
|
||||
grid(True)
|
||||
|
||||
show()
|
||||
|
||||
#------------------------------------------------
|
||||
# Print values
|
||||
#------------------------------------------------
|
||||
def print_values(label, values):
|
||||
var = "float32_t %s[%d]" % (label, len(values))
|
||||
print "%-30s = {%s}" % (var, ', '.join(["%+.10f" % x for x in values]))
|
||||
|
||||
print_values('signal', signal)
|
||||
print_values('fir_coeff', fir_coeff)
|
||||
print_values('filtered_signal', filtered_signal)
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
"""
|
||||
Copyright (c) 2014-2019 ARM Limited. All rights reserved.
|
||||
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
from intelhex import IntelHex
|
||||
from cStringIO import StringIO
|
||||
|
||||
|
||||
def sections(h):
|
||||
start, last_address = None, None
|
||||
for a in h.addresses():
|
||||
if last_address is None:
|
||||
start, last_address = a, a
|
||||
continue
|
||||
|
||||
if a > last_address + 1:
|
||||
yield (start, last_address)
|
||||
start = a
|
||||
|
||||
last_address = a
|
||||
|
||||
if start:
|
||||
yield (start, last_address)
|
||||
|
||||
|
||||
def print_sections(h):
|
||||
for s in sections(h):
|
||||
print "[0x%08X - 0x%08X]" % s
|
||||
|
||||
|
||||
def decode(record):
|
||||
h = IntelHex()
|
||||
f = StringIO(record)
|
||||
h.loadhex(f)
|
||||
h.dump()
|
||||
|
|
@ -1,190 +0,0 @@
|
|||
"""
|
||||
mbed SDK
|
||||
Copyright (c) 2011-2013 ARM Limited
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
from os.path import join
|
||||
from jinja2 import Template
|
||||
|
||||
from tools.paths import TOOLS_DATA, MBED_RPC
|
||||
|
||||
RPC_TEMPLATES_PATH = join(TOOLS_DATA, "rpc")
|
||||
|
||||
RPC_TEMPLATE = "RPCClasses.h"
|
||||
CLASS_TEMPLATE = "class.cpp"
|
||||
RPC_CLASSES_PATH = join(MBED_RPC, RPC_TEMPLATE)
|
||||
|
||||
|
||||
def get_template(name):
|
||||
return Template(open(join(RPC_TEMPLATES_PATH, name)).read())
|
||||
|
||||
|
||||
def write_rpc_classes(classes):
|
||||
template = get_template(RPC_TEMPLATE)
|
||||
open(RPC_CLASSES_PATH, "w").write(template.render({"classes":classes}))
|
||||
|
||||
|
||||
RPC_CLASSES = (
|
||||
{
|
||||
"name": "DigitalOut",
|
||||
"cons_args": ["PinName"],
|
||||
"methods": [
|
||||
(None , "write", ["int"]),
|
||||
("int", "read" , []),
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "DigitalIn",
|
||||
"cons_args": ["PinName"],
|
||||
"methods": [
|
||||
("int", "read" , []),
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "DigitalInOut",
|
||||
"cons_args": ["PinName"],
|
||||
"methods": [
|
||||
("int", "read" , []),
|
||||
(None , "write" , ["int"]),
|
||||
(None , "input" , []),
|
||||
(None , "output", []),
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "AnalogIn",
|
||||
"required": "ANALOGIN",
|
||||
"cons_args": ["PinName"],
|
||||
"methods": [
|
||||
("float" , "read" , []),
|
||||
("unsigned short", "read_u16", []),
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "AnalogOut",
|
||||
"required": "ANALOGOUT",
|
||||
"cons_args": ["PinName"],
|
||||
"methods": [
|
||||
("float", "read" , []),
|
||||
(None , "write" , ["float"]),
|
||||
(None , "write_u16", ["unsigned short"]),
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "PwmOut",
|
||||
"required": "PWMOUT",
|
||||
"cons_args": ["PinName"],
|
||||
"methods": [
|
||||
("float", "read" , []),
|
||||
(None , "write" , ["float"]),
|
||||
(None , "period" , ["float"]),
|
||||
(None , "period_ms" , ["int"]),
|
||||
(None , "pulsewidth" , ["float"]),
|
||||
(None , "pulsewidth_ms", ["int"]),
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "SPI",
|
||||
"required": "SPI",
|
||||
"cons_args": ["PinName", "PinName", "PinName"],
|
||||
"methods": [
|
||||
(None , "format" , ["int", "int"]),
|
||||
(None , "frequency", ["int"]),
|
||||
("int", "write" , ["int"]),
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Serial",
|
||||
"required": "SERIAL",
|
||||
"cons_args": ["PinName", "PinName"],
|
||||
"methods": [
|
||||
(None , "baud" , ["int"]),
|
||||
("int", "readable" , []),
|
||||
("int", "writeable", []),
|
||||
("int", "putc" , ["int"]),
|
||||
("int", "getc" , []),
|
||||
("int", "puts" , ["const char *"]),
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Timer",
|
||||
"cons_args": [],
|
||||
"methods": [
|
||||
(None , "start" , []),
|
||||
(None , "stop" , []),
|
||||
(None , "reset" , []),
|
||||
("float", "read" , []),
|
||||
("int" , "read_ms", []),
|
||||
("int" , "read_us", []),
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def get_args_proto(args_types, extra=None):
|
||||
args = ["%s a%d" % (s, n) for n, s in enumerate(args_types)]
|
||||
if extra:
|
||||
args.extend(extra)
|
||||
return ', '.join(args)
|
||||
|
||||
|
||||
def get_args_call(args):
|
||||
return ', '.join(["a%d" % (n) for n in range(len(args))])
|
||||
|
||||
|
||||
classes = []
|
||||
class_template = get_template(CLASS_TEMPLATE)
|
||||
|
||||
for c in RPC_CLASSES:
|
||||
c_args = c['cons_args']
|
||||
data = {
|
||||
'name': c['name'],
|
||||
'cons_type': ', '.join(c_args + ['const char*']),
|
||||
"cons_proto": get_args_proto(c_args, ["const char *name=NULL"]),
|
||||
"cons_call": get_args_call(c_args)
|
||||
}
|
||||
|
||||
c_name = "Rpc" + c['name']
|
||||
|
||||
methods = []
|
||||
rpc_methods = []
|
||||
for r, m, a in c['methods']:
|
||||
ret_proto = r if r else "void"
|
||||
args_proto = "void"
|
||||
|
||||
ret_defin = "return " if r else ""
|
||||
args_defin = ""
|
||||
|
||||
if a:
|
||||
args_proto = get_args_proto(a)
|
||||
args_defin = get_args_call(a)
|
||||
|
||||
proto = "%s %s(%s)" % (ret_proto, m, args_proto)
|
||||
defin = "{%so.%s(%s);}" % (ret_defin, m, args_defin)
|
||||
methods.append("%s %s" % (proto, defin))
|
||||
|
||||
rpc_method_type = [r] if r else []
|
||||
rpc_method_type.append(c_name)
|
||||
rpc_method_type.extend(a)
|
||||
rpc_methods.append('{"%s", rpc_method_caller<%s, &%s::%s>}' % (m, ', '.join(rpc_method_type), c_name, m))
|
||||
|
||||
data['methods'] = "\n ".join(methods)
|
||||
data['rpc_methods'] = ",\n ".join(rpc_methods)
|
||||
|
||||
class_decl = class_template.render(data)
|
||||
if 'required' in c:
|
||||
class_decl = "#if DEVICE_%s\n%s\n#endif" % (c['required'], class_decl)
|
||||
|
||||
classes.append(class_decl)
|
||||
|
||||
write_rpc_classes('\n\n'.join(classes))
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
"""
|
||||
mbed SDK
|
||||
Copyright (c) 2011-2013 ARM Limited
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
Utility to find which libraries could define a given symbol
|
||||
"""
|
||||
from argparse import ArgumentParser
|
||||
from os.path import join, splitext
|
||||
from os import walk
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
|
||||
OBJ_EXT = ['.o', '.a', '.ar']
|
||||
|
||||
|
||||
def find_sym_in_lib(sym, obj_path):
|
||||
contain_symbol = False
|
||||
|
||||
out = Popen(["nm", "-C", obj_path], stdout=PIPE, stderr=PIPE).communicate()[0]
|
||||
for line in out.splitlines():
|
||||
tokens = line.split()
|
||||
n = len(tokens)
|
||||
if n == 2:
|
||||
sym_type = tokens[0]
|
||||
sym_name = tokens[1]
|
||||
elif n == 3:
|
||||
sym_type = tokens[1]
|
||||
sym_name = tokens[2]
|
||||
else:
|
||||
continue
|
||||
|
||||
if sym_type == "U":
|
||||
# This object is using this symbol, not defining it
|
||||
continue
|
||||
|
||||
if sym_name == sym:
|
||||
contain_symbol = True
|
||||
|
||||
return contain_symbol
|
||||
|
||||
|
||||
def find_sym_in_path(sym, dir_path):
|
||||
for root, _, files in walk(dir_path):
|
||||
for file in files:
|
||||
|
||||
_, ext = splitext(file)
|
||||
if ext not in OBJ_EXT: continue
|
||||
|
||||
path = join(root, file)
|
||||
if find_sym_in_lib(sym, path):
|
||||
print path
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = ArgumentParser(description='Find Symbol')
|
||||
parser.add_argument('-s', '--sym', required=True,
|
||||
help='The symbol to be searched')
|
||||
parser.add_argument('-p', '--path', required=True,
|
||||
help='The path where to search')
|
||||
args = parser.parse_args()
|
||||
|
||||
find_sym_in_path(args.sym, args.path)
|
||||
Loading…
Reference in New Issue