Skip to content

Commit bfb6ff2

Browse files
authored
Merge pull request #1824 from N3xp7im3/txchunk
driver: introduce txchunk argument for console drivers
2 parents 5e74a80 + 5eb9316 commit bfb6ff2

12 files changed

Lines changed: 45 additions & 13 deletions

File tree

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ New Features in 25.1
1212
``add_port_forward()`` and ``remove_port_forward()`` in case there is more
1313
than one network interface defined.
1414
- Guermok HDMI to USB 3.0 capture dongle supported
15+
- The `consoleexpectmixin` now supports chunking of multiple bytes
16+
with the ``txchunk`` attribute.
1517

1618
Breaking changes in 25.1
1719
~~~~~~~~~~~~~~~~~~~~~~~~

doc/configuration.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,13 +1963,15 @@ Binds to:
19631963
19641964
SerialDriver:
19651965
txdelay: 0.05
1966+
txchunk: 1
19661967
19671968
Implements:
19681969
- :any:`ConsoleProtocol`
19691970
- :any:`ResetProtocol`
19701971

19711972
Arguments:
1972-
- txdelay (float, default=0.0): time in seconds to wait before sending each byte
1973+
- txdelay (float, default=0.0): time in seconds to wait before sending a chunk
1974+
- txchunk (int, default=1): number of bytes the `txdelay` should apply to
19731975
- timeout (float, default=3.0): time in seconds to wait for a network serial port before
19741976
an error occurs
19751977

@@ -2223,10 +2225,12 @@ Implements:
22232225
ExternalConsoleDriver:
22242226
cmd: 'microcom /dev/ttyUSB2'
22252227
txdelay: 0.05
2228+
txchunk: 1
22262229
22272230
Arguments:
22282231
- cmd (str): command to execute and then bind to.
2229-
- txdelay (float, default=0.0): time in seconds to wait before sending each byte
2232+
- txdelay (float, default=0.0): time in seconds to wait before sending a chunk
2233+
- txchunk (int, default=1): number of bytes the `txdelay` should apply to
22302234

22312235
AndroidFastbootDriver
22322236
~~~~~~~~~~~~~~~~~~~~~

doc/overview.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ specific driver set a binding mapping before creating the driver:
147147
>>> t.set_binding_map({"port": "Second"})
148148
>>> sd = SerialDriver(t, "Driver")
149149
>>> sd
150-
SerialDriver(target=Target(name='Test', env=None), name='Driver', state=<BindingState.bound: 1>, txdelay=0.0, timeout=3.0)
150+
SerialDriver(target=Target(name='Test', env=None), name='Driver', state=<BindingState.bound: 1>, txdelay=0.0, txchunk=1, timeout=3.0)
151151
>>> sd.port
152152
SerialPort(target=Target(name='Test', env=None), name='Second', state=<BindingState.bound: 1>, avail=True, port=None, speed=115200)
153153

doc/usage.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ Active drivers can be accessed by class (any :any:`Driver <labgrid.driver>` or
283283
>>> console = FakeConsoleDriver(target, 'console')
284284
>>> target.activate(console)
285285
>>> target[FakeConsoleDriver]
286-
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0)
286+
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0, txchunk=1)
287287
>>> target[FakeConsoleDriver, 'console']
288-
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0)
288+
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0, txchunk=1)
289289

290290
Driver Deactivation
291291
^^^^^^^^^^^^^^^^^^^
@@ -302,7 +302,7 @@ Driver deactivation works in a similar manner:
302302
.. doctest:: driver-deactivation
303303

304304
>>> target.deactivate(console)
305-
[FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.bound: 1>, txdelay=0.0)]
305+
[FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.bound: 1>, txdelay=0.0, txchunk=1)]
306306

307307
Drivers need to be deactivated in the following cases:
308308

@@ -393,7 +393,7 @@ To access the target's console, the correct driver object can be found by using
393393

394394
>>> cp = t.get_driver('ConsoleProtocol')
395395
>>> cp
396-
SerialDriver(target=Target(name='example', env=Environment(config_file='example-env.yaml')), name=None, state=<BindingState.active: 2>, txdelay=0.0, timeout=3.0)
396+
SerialDriver(target=Target(name='example', env=Environment(config_file='example-env.yaml')), name=None, state=<BindingState.active: 2>, txdelay=0.0, txchunk=1, timeout=3.0)
397397
>>> cp.write(b'test')
398398
4
399399

examples/strategy/local.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ targets:
88
name: "example"
99
SerialDriver:
1010
txdelay: 0.01
11+
txchunk: 1
1112
BareboxDriver:
1213
prompt: 'barebox@[^:]+:[^ ]+ '
1314
bootstring: 'Modules linked in'

labgrid/driver/consoleexpectmixin.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ def read(self, size=1, timeout=0.0, max_size=None):
3434
@step(args=['data'], tag='console')
3535
def write(self, data):
3636
if self.txdelay:
37-
self.logger.debug("Write %i bytes: %s (with %fs txdelay)",
38-
len(data), data, self.txdelay)
37+
self.logger.debug("Write %i bytes: %s (with %fs txdelay per %i bytes)",
38+
len(data), data, self.txdelay, self.txchunk)
39+
3940
count = 0
40-
for i in range(len(data)):
41+
for i in range(0, len(data), self.txchunk):
4142
time.sleep(self.txdelay)
42-
count += self._write(data[i:i+1])
43+
count += self._write(data[i:i+self.txchunk])
44+
4345
return count
4446

4547
self.logger.debug("Write %i bytes: %s", len(data), data)

labgrid/driver/externalconsoledriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ExternalConsoleDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):
2121
"""
2222
cmd = attr.ib(validator=attr.validators.instance_of(str))
2323
txdelay = attr.ib(default=0.0, validator=attr.validators.instance_of(float))
24+
txchunk = attr.ib(default=1, validator=attr.validators.instance_of(int))
2425

2526
def __attrs_post_init__(self):
2627
super().__attrs_post_init__()

labgrid/driver/fake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
@attr.s(eq=False)
1515
class FakeConsoleDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):
1616
txdelay = attr.ib(default=0.0, validator=attr.validators.instance_of(float))
17+
txchunk = attr.ib(default=1, validator=attr.validators.instance_of(int))
1718

1819
def __attrs_post_init__(self):
1920
super().__attrs_post_init__()

labgrid/driver/qemudriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def __attrs_post_init__(self):
9999
super().__attrs_post_init__()
100100
self.status = 0
101101
self.txdelay = None
102+
self.txchunk = None
102103
self._child = None
103104
self._tempdir = None
104105
self._socket = None

labgrid/driver/serialdriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class SerialDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):
2020
bindings = {"port": {"SerialPort", "NetworkSerialPort"}, }
2121

2222
txdelay = attr.ib(default=0.0, validator=attr.validators.instance_of(float))
23+
txchunk = attr.ib(default=1, validator=attr.validators.instance_of(int))
2324
timeout = attr.ib(default=3.0, validator=attr.validators.instance_of(float))
2425

2526
def __attrs_post_init__(self):

0 commit comments

Comments
 (0)