conn_primitive.py
Go to the documentation of this file.
#!/usr/bin/env python
"""
mbed SDK
Copyright (c) 2011-2016 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 mbed_host_tests.host_tests_logger import HtrunLogger
class ConnectorPrimitiveException(Exception):
"""
Exception in connector primitive module.
"""
pass
class ConnectorPrimitive(object):
def __init__(self, name):
self.LAST_ERROR = None
self.logger = HtrunLogger(name)
self.polling_timeout = 60
def write_kv(self, key, value):
"""! Forms and sends Key-Value protocol message.
@details On how to parse K-V sent from DUT see KiViBufferWalker::KIVI_REGEX
On how DUT sends K-V please see greentea_write_postamble() function in greentea-client
@return Returns buffer with K-V message sent to DUT on success, None on failure
"""
# All Key-Value messages ends with newline character
kv_buff = "{{%s;%s}}"% (key, value) + '\n'
if self.write(kv_buff):
self.logger.prn_txd(kv_buff.rstrip())
return kv_buff
else:
return None
def read(self, count):
"""! Read data from DUT
@param count Number of bytes to read
@return Bytes read
"""
raise NotImplementedError
def write(self, payload, log=False):
"""! Read data from DUT
@param payload Buffer with data to send
@param log Set to True if you want to enable logging for this function
@return Payload (what was actually sent - if possible to establish that)
"""
raise NotImplementedError
def flush(self):
"""! Flush read/write channels of DUT """
raise NotImplementedError
def reset(self):
"""! Reset the dut
"""
raise NotImplementedError
def connected(self):
"""! Check if there is a connection to DUT
@return True if there is conenction to DUT (read/write/flush API works)
"""
raise NotImplementedError
def error(self):
"""! Returns LAST_ERROR value
@return Value of self.LAST_ERROR
"""
return self.LAST_ERROR
def finish(self):
"""! Handle DUT dtor like (close resource) operations here
"""
raise NotImplementedError
mbed_host_tests.host_tests_conn_proxy.conn_primitive.ConnectorPrimitive.write_kv
def write_kv(self, key, value)
Forms and sends Key-Value protocol message.
Definition: conn_primitive.py:36
mbed_host_tests.host_tests_conn_proxy.conn_primitive.ConnectorPrimitive.__init__
def __init__(self, name)
Definition: conn_primitive.py:31
mbed_host_tests.host_tests_conn_proxy.conn_primitive.ConnectorPrimitive.read
def read(self, count)
Read data from DUT.
Definition: conn_primitive.py:51
mbed_host_tests.host_tests_conn_proxy.conn_primitive.ConnectorPrimitive
Definition: conn_primitive.py:29
mbed_host_tests.host_tests_conn_proxy.conn_primitive.ConnectorPrimitive.logger
logger
Definition: conn_primitive.py:33
mbed_host_tests.host_tests_logger
Definition: __init__.py:1
mbed_host_tests.host_tests_conn_proxy.conn_primitive.ConnectorPrimitive.polling_timeout
polling_timeout
Definition: conn_primitive.py:34
mbed_host_tests.host_tests_conn_proxy.conn_primitive.ConnectorPrimitiveException
Definition: conn_primitive.py:22
object
mbed_host_tests.host_tests_conn_proxy.conn_primitive.ConnectorPrimitive.LAST_ERROR
LAST_ERROR
Definition: conn_primitive.py:32
mbed_host_tests.host_tests_conn_proxy.conn_primitive.ConnectorPrimitive.error
def error(self)
Returns LAST_ERROR value.
Definition: conn_primitive.py:81
Exception
mbed_host_tests.host_tests_conn_proxy.conn_primitive.ConnectorPrimitive.flush
def flush(self)
Flush read/write channels of DUT.
Definition: conn_primitive.py:66
mbed_host_tests.host_tests_conn_proxy.conn_primitive.ConnectorPrimitive.write
def write(self, payload, log=False)
Read data from DUT.
Definition: conn_primitive.py:58
mbed_host_tests.host_tests_conn_proxy.conn_primitive.ConnectorPrimitive.reset
def reset(self)
Reset the dut.
Definition: conn_primitive.py:70
mbed_host_tests.host_tests_conn_proxy.conn_primitive.ConnectorPrimitive.connected
def connected(self)
Check if there is a connection to DUT.
Definition: conn_primitive.py:75
mbed_host_tests.host_tests_conn_proxy.conn_primitive.ConnectorPrimitive.finish
def finish(self)
Handle DUT dtor like (close resource) operations here.
Definition: conn_primitive.py:87