Mbed Host Tests
module_copy_jn51xx.py
Go to the documentation of this file.
1 """
2 mbed SDK
3 Copyright (c) 2011-2015 ARM Limited
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 
17 Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
18 """
19 
20 import os
21 from .host_test_plugins import HostTestPluginBase
22 
23 
25 
26  # Plugin interface
27  name = 'HostTestPluginCopyMethod_JN51xx'
28  type = 'CopyMethod'
29  capabilities = ['jn51xx']
30  required_parameters = ['image_path', 'serial']
31 
32  def __init__(self):
33  """ ctor
34  """
35  HostTestPluginBase.__init__(self)
36 
37  def is_os_supported(self, os_name=None):
38  """! In this implementation this plugin only is supporeted under Windows machines
39  """
40  # If no OS name provided use host OS name
41  if not os_name:
42  os_name = self.mbed_os_supportmbed_os_support()
43 
44  # This plugin only works on Windows
45  if os_name and os_name.startswith('Windows'):
46  return True
47  return False
48 
49  def setup(self, *args, **kwargs):
50  """! Configure plugin, this function should be called before plugin execute() method is used.
51  """
52  self.JN51XX_PROGRAMMERJN51XX_PROGRAMMER = 'JN51xxProgrammer.exe'
53  return True
54 
55  def execute(self, capability, *args, **kwargs):
56  """! Executes capability by name
57 
58  @param capability Capability name
59  @param args Additional arguments
60  @param kwargs Additional arguments
61  @details Each capability e.g. may directly just call some command line program or execute building pythonic function
62  @return Capability call return value
63  """
64  if not kwargs['image_path']:
65  self.print_plugin_errorprint_plugin_error("Error: image path not specified")
66  return False
67 
68  if not kwargs['serial']:
69  self.print_plugin_errorprint_plugin_error("Error: serial port not set (not opened?)")
70  return False
71 
72  result = False
73  if self.check_parameterscheck_parameters(capability, *args, **kwargs):
74  if kwargs['image_path'] and kwargs['serial']:
75  image_path = os.path.normpath(kwargs['image_path'])
76  serial_port = kwargs['serial']
77  if capability == 'jn51xx':
78  # Example:
79  # JN51xxProgrammer.exe -s COM15 -f <file> -V0
80  cmd = [self.JN51XX_PROGRAMMERJN51XX_PROGRAMMER,
81  '-s', serial_port,
82  '-f', image_path,
83  '-V0'
84  ]
85  result = self.run_commandrun_command(cmd)
86  return result
87 
88 
90  """ Returns plugin available in this module
91  """
def run_command(self, cmd, shell=True)
Runs command from command line.
def print_plugin_error(self, text)
Interface helper methods - overload only if you need to have custom behaviour.
def check_parameters(self, capability, *args, **kwargs)
This function should be ran each time we call execute() to check if none of the required parameters i...
def is_os_supported(self, os_name=None)
In this implementation this plugin only is supporeted under Windows machines.
def setup(self, *args, **kwargs)
Configure plugin, this function should be called before plugin execute() method is used.
def execute(self, capability, *args, **kwargs)
Executes capability by name.