Using mbedls for smartcopy

pull/1356/head
Brian Daniels 2015-09-10 18:21:42 -05:00
parent 1eacabd7c3
commit 19978dd9a8
1 changed files with 91 additions and 26 deletions

View File

@ -17,11 +17,12 @@ limitations under the License.
import os
import sys
from os.path import join, basename, exists
import mbed_lstools
import ctypes
from os.path import join, basename, exists, abspath, dirname
from time import sleep
from host_test_plugins import HostTestPluginBase
class HostTestPluginCopyMethod_Smart(HostTestPluginBase):
# Plugin interface
@ -55,39 +56,68 @@ class HostTestPluginCopyMethod_Smart(HostTestPluginBase):
if os.name == 'posix':
cmd = ['cp', image_path, destination_path]
result = self.run_command(cmd, shell=False)
cmd = ['sync']
result = self.run_command(cmd, shell=False)
# Give the OS and filesystem time to settle down
sleep(3)
elif os.name == 'nt':
cmd = ['copy', image_path, destination_path]
result = self.run_command(cmd, shell=True)
if not target_mcu == 'LPC1768':
remount_complete = False
for i in range(0, 60):
# Give the OS and filesystem time to settle down
sleep(3)
platform_name_filter = [target_mcu]
muts_list = {}
remount_complete = False
for i in range(0, 60):
oldError = None
if os.name == 'nt':
# Disable Windows error box temporarily
oldError = ctypes.windll.kernel32.SetErrorMode(1) #note that SEM_FAILCRITICALERRORS = 1
print('Looking for %s with MBEDLS' % target_mcu)
mbeds = mbed_lstools.create()
detect_muts_list = mbeds.list_mbeds()
if os.name == 'nt':
ctypes.windll.kernel32.SetErrorMode(oldError)
muts_list = get_autodetected_MUTS(detect_muts_list, platform_name_filter=platform_name_filter)
if 1 in muts_list:
mut = muts_list[1]
destination_disk = mut['disk']
destination_path = join(destination_disk, image_base_name)
if mut['mcu'] == 'LPC1768' or mut['mcu'] == 'LPC11U24':
if exists(destination_disk) and exists(destination_path):
remount_complete = True
break;
else:
if exists(destination_disk) and not exists(destination_path):
remount_complete = True
break
else:
sleep(1)
break;
if remount_complete:
print('Remount complete')
else:
print('Remount FAILED')
sleep(1)
if exists(destination_disk):
print('Disk exists')
else:
print('Disk does not exist')
if remount_complete:
print('Remount complete')
else:
print('Remount FAILED')
if exists(destination_path):
print('Image exists')
else:
print('Image does not exist')
result = None
if exists(destination_disk):
print('Disk exists')
else:
print('Disk does not exist')
if exists(destination_path):
print('Image exists')
else:
print('Image does not exist')
result = None
return result
@ -95,3 +125,38 @@ def load_plugin():
""" Returns plugin available in this module
"""
return HostTestPluginCopyMethod_Smart()
def get_autodetected_MUTS(mbeds_list, platform_name_filter=None):
""" Function detects all connected to host mbed-enabled devices and generates artificial MUTS file.
If function fails to auto-detect devices it will return empty dictionary.
if get_module_avail('mbed_lstools'):
mbeds = mbed_lstools.create()
mbeds_list = mbeds.list_mbeds()
@param mbeds_list list of mbeds captured from mbed_lstools
@param platform_name You can filter 'platform_name' with list of filtered targets from 'platform_name_filter'
"""
result = {} # Should be in muts_all.json format
# Align mbeds_list from mbed_lstools to MUT file format (JSON dictionary with muts)
# mbeds_list = [{'platform_name': 'NUCLEO_F302R8', 'mount_point': 'E:', 'target_id': '07050200623B61125D5EF72A', 'serial_port': u'COM34'}]
index = 1
for mut in mbeds_list:
# Filter the MUTS if a filter is specified
if platform_name_filter and not mut['platform_name'] in platform_name_filter:
continue
# For mcu_unique - we are assigning 'platform_name_unique' value from mbedls output (if its existing)
# if not we are creating our own unique value (last few chars from platform's target_id).
m = {'mcu': mut['platform_name'],
'mcu_unique' : mut['platform_name_unique'] if 'platform_name_unique' in mut else "%s[%s]" % (mut['platform_name'], mut['target_id'][-4:]),
'port': mut['serial_port'],
'disk': mut['mount_point'],
'peripherals': [] # No peripheral detection
}
if index not in result:
result[index] = {}
result[index] = m
index += 1
return result