Mbed Host Tests
conn_primitive.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
"""
3
mbed SDK
4
Copyright (c) 2011-2016 ARM Limited
5
6
Licensed under the Apache License, Version 2.0 (the "License");
7
you may not use this file except in compliance with the License.
8
You may obtain a copy of the License at
9
10
http://www.apache.org/licenses/LICENSE-2.0
11
12
Unless required by applicable law or agreed to in writing, software
13
distributed under the License is distributed on an "AS IS" BASIS,
14
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
See the License for the specific language governing permissions and
16
limitations under the License.
17
"""
18
19
from
mbed_host_tests.host_tests_logger
import
HtrunLogger
20
21
22
class
ConnectorPrimitiveException
(
Exception
):
23
"""
24
Exception in connector primitive module.
25
"""
26
pass
27
28
29
class
ConnectorPrimitive
(
object
):
30
31
def
__init__
(self, name):
32
self.
LAST_ERROR
=
None
33
self.
logger
= HtrunLogger(name)
34
self.
polling_timeout
= 60
35
36
def
write_kv
(self, key, value):
37
"""! Forms and sends Key-Value protocol message.
38
@details On how to parse K-V sent from DUT see KiViBufferWalker::KIVI_REGEX
39
On how DUT sends K-V please see greentea_write_postamble() function in greentea-client
40
@return Returns buffer with K-V message sent to DUT on success, None on failure
41
"""
42
# All Key-Value messages ends with newline character
43
kv_buff =
"{{%s;%s}}"
% (key, value) +
'\n'
44
45
if
self.
write
(kv_buff):
46
self.
logger
.prn_txd(kv_buff.rstrip())
47
return
kv_buff
48
else
:
49
return
None
50
51
def
read
(self, count):
52
"""! Read data from DUT
53
@param count Number of bytes to read
54
@return Bytes read
55
"""
56
raise
NotImplementedError
57
58
def
write
(self, payload, log=False):
59
"""! Read data from DUT
60
@param payload Buffer with data to send
61
@param log Set to True if you want to enable logging for this function
62
@return Payload (what was actually sent - if possible to establish that)
63
"""
64
raise
NotImplementedError
65
66
def
flush
(self):
67
"""! Flush read/write channels of DUT """
68
raise
NotImplementedError
69
70
def
reset
(self):
71
"""! Reset the dut
72
"""
73
raise
NotImplementedError
74
75
def
connected
(self):
76
"""! Check if there is a connection to DUT
77
@return True if there is conenction to DUT (read/write/flush API works)
78
"""
79
raise
NotImplementedError
80
81
def
error
(self):
82
"""! Returns LAST_ERROR value
83
@return Value of self.LAST_ERROR
84
"""
85
return
self.
LAST_ERROR
86
87
def
finish
(self):
88
"""! Handle DUT dtor like (close resource) operations here
89
"""
90
raise
NotImplementedError
mbed_host_tests.host_tests_logger
Definition:
__init__.py:1
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.__init__
def __init__(self, name)
Definition:
conn_primitive.py:31
mbed_host_tests.host_tests_conn_proxy.conn_primitive.ConnectorPrimitive.error
def error(self)
Returns LAST_ERROR value.
Definition:
conn_primitive.py:81
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
object
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.logger
logger
Definition:
conn_primitive.py:33
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
Exception
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.polling_timeout
polling_timeout
Definition:
conn_primitive.py:34
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
Definition:
conn_primitive.py:29
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.ConnectorPrimitiveException
Definition:
conn_primitive.py:22
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.py
Generated by
1.8.20