Skip to content

Commit bdb9258

Browse files
authored
Merge branch 'master' into ymodem
2 parents c8052b9 + aed6428 commit bdb9258

File tree

4 files changed

+55
-11
lines changed

4 files changed

+55
-11
lines changed

.drone.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pipeline:
2+
build:
3+
image: maze/drone-python
4+
commands:
5+
- apt-get -qq install lrzsz
6+
- pip install -r requirements-testing.txt
7+
- tox

README.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ Usage
1818
Create a function to get and put character data (to a serial line for
1919
example)::
2020

21+
>>> import serial
2122
>>> from xmodem import XMODEM
23+
>>> ser = serial.Serial('/dev/ttyUSB0', timeout=0) # or whatever port you need
2224
>>> def getc(size, timeout=1):
23-
... return data or None
25+
... return ser.read(size) or None
2426
...
2527
>>> def putc(data, timeout=1):
26-
... return size or None
28+
... return ser.write(data) # note that this ignores the timeout
2729
...
2830
>>> modem = XMODEM(getc, putc)
2931

@@ -49,8 +51,12 @@ For more information, take a look at the documentation_.
4951
Changes
5052
=======
5153

52-
0.4.5:
54+
0.4.6:
5355
* enhancement: added YMODEM ``send()`` capability.
56+
0.4.5:
57+
* bugfix: Remove bogus `assert False` code in ``recv()`` that resulted in
58+
`AssertionError` introduced in version 0.4.0 commit-id `9b03fc20`, `PR #29
59+
<https://github.com/tehmaze/xmodem/pull/29>`_.
5460
0.4.4:
5561
* bugfix: Large file transfers in ``send()`` were more likely to fail for
5662
small values of ``retry``: This value should be the maximum failures per

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='xmodem',
10-
version='0.4.5',
10+
version='0.4.6',
1111
author='Wijnand Modderman, Jeff Quast, Kris Hardy, Michael Tesch',
1212
author_email='[email protected]',
1313
description=('XMODEM/YMODEM protocol implementation.'),

xmodem/__init__.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,32 @@
135135

136136
class XMODEM(object):
137137
'''
138-
XMODEM Protocol handler, expects an object to read from and an object to
139-
write to.
138+
XMODEM Protocol handler, expects two callables which encapsulate the read
139+
and write operations on the underlying stream.
140140
141+
Example functions for reading and writing to a serial line:
142+
143+
>>> import serial
144+
>>> from xmodem import XMODEM
145+
>>> ser = serial.Serial('/dev/ttyUSB0', timeout=0) # or whatever you need
141146
>>> def getc(size, timeout=1):
142-
... return data or None
147+
... return ser.read(size) or None
143148
...
144149
>>> def putc(data, timeout=1):
145-
... return size or None
150+
... return ser.write(data) or None
146151
...
147152
>>> modem = XMODEM(getc, putc)
148153
149154
150-
:param getc: Function to retrieve bytes from a stream
155+
:param getc: Function to retrieve bytes from a stream. The function takes
156+
the number of bytes to read from the stream and a timeout in seconds as
157+
parameters. It must return the bytes which were read, or ``None`` if a
158+
timeout occured.
151159
:type getc: callable
152-
:param putc: Function to transmit bytes to a stream
160+
:param putc: Function to transmit bytes to a stream. The function takes the
161+
bytes to be written and a timeout in seconds as parameters. It must
162+
return the number of bytes written to the stream, or ``None`` in case of
163+
a timeout.
153164
:type putc: callable
154165
:param mode: XMODEM protocol mode
155166
:type mode: string
@@ -204,6 +215,11 @@ def __init__(self, getc, putc, mode='xmodem', pad=b'\x1a'):
204215
def abort(self, count=2, timeout=60):
205216
'''
206217
Send an abort sequence using CAN bytes.
218+
219+
:param count: how many abort characters to send
220+
:type count: int
221+
:param timeout: timeout in seconds
222+
:type timeout: int
207223
'''
208224
for _ in range(count):
209225
self.putc(CAN, timeout)
@@ -430,6 +446,22 @@ def recv(self, stream, crc_mode=1, retry=16, timeout=60, delay=1, quiet=0):
430446
431447
Returns the number of bytes received on success or ``None`` in case of
432448
failure.
449+
450+
:param stream: The stream object to write data to.
451+
:type stream: stream (file, etc.)
452+
:param crc_mode: XMODEM CRC mode
453+
:type crc_mode: int
454+
:param retry: The maximum number of times to try to resend a failed
455+
packet before failing.
456+
:type retry: int
457+
:param timeout: The number of seconds to wait for a response before
458+
timing out.
459+
:type timeout: int
460+
:param delay: The number of seconds to wait between resend attempts
461+
:type delay: int
462+
:param quiet: If ``True``, write transfer information to stderr.
463+
:type quiet: bool
464+
433465
'''
434466

435467
# initiate protocol
@@ -581,7 +613,6 @@ def recv(self, stream, crc_mode=1, retry=16, timeout=60, delay=1, quiet=0):
581613
data = self.getc(1, timeout=1)
582614
if data is None:
583615
break
584-
assert False, data
585616
self.putc(NAK)
586617
# get next start-of-header byte
587618
char = self.getc(1, timeout)

0 commit comments

Comments
 (0)