Skip to content

Commit 298ffdf

Browse files
authored
Merge pull request #16 from basilfx/feature/tinylink_next
Add async support and improve resiliency
2 parents 1a31075 + 1c12043 commit 298ffdf

17 files changed

Lines changed: 888 additions & 619 deletions

.flake8

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
[flake8]
2-
ignore = E203, W503
32
max-line-length = 88
3+
4+
# Necessary for compatibility with the Black formatter.
5+
ignore = E203, W503

.github/workflows/lint.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ jobs:
1010
lint:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v4
1414

15-
- uses: actions/setup-python@v2
15+
- uses: actions/setup-python@v5
1616
with:
17-
python-version: "3.10"
17+
python-version: "3.12"
1818

19-
- uses: actions/cache@v2
19+
- uses: actions/cache@v4
2020
with:
2121
path: ~/.local
22-
key: poetry-1.2.2
22+
key: poetry-1.8.0
2323

2424
- uses: snok/install-poetry@v1
2525
with:
26-
version: 1.2.2
26+
version: 1.8.0
2727
virtualenvs-create: true
2828
virtualenvs-in-project: true
2929

30-
- uses: actions/cache@v2
30+
- uses: actions/cache@v4
3131
id: cache-deps
3232
with:
3333
path: .venv

.github/workflows/test.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ jobs:
1010
lint:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v4
1414

15-
- uses: actions/setup-python@v2
15+
- uses: actions/setup-python@v5
1616
with:
17-
python-version: "3.10"
17+
python-version: "3.12"
1818

19-
- uses: actions/cache@v2
19+
- uses: actions/cache@v4
2020
with:
2121
path: ~/.local
22-
key: poetry-1.2.2
22+
key: poetry-1.8.0
2323

2424
- uses: snok/install-poetry@v1
2525
with:
26-
version: 1.2.2
26+
version: 1.8.0
2727
virtualenvs-create: true
2828
virtualenvs-in-project: true
2929

30-
- uses: actions/cache@v2
30+
- uses: actions/cache@v4
3131
id: cache-deps
3232
with:
3333
path: .venv

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
__pycache__/
2+
.history
23
.mypy_cache/
34
.pytest_cache/
45
.vscode/

CHANGELOG.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
Highlights:
6+
* Added: support for asynchronous handles.
7+
* Added: escaping of the header and body (protocol).
8+
* Changed: minimal Python version is Python 3.12.
9+
* Changed: body checksum is always included (protocol).
10+
* Changed: body checksum is now calculated over header and payload (protocol).
11+
* Fixed: preamble is now read as string of bytes.
12+
* Improved: CLI is more interactive.
13+
* Improved: consistent terminology and naming.
14+
* Removed: reserved flags (protocol).
15+
316
## v2.0.0
417
Released 17 September 2015
518

619
Highlights:
720
* Added: Python 3.4 support.
8-
* Improved: More strict handling of bytes.
9-
* Improved: Formatted code according to PEP8.
21+
* Improved: more strict handling of bytes.
22+
* Improved: formatted code according to PEP8.
1023
* Changed: ResetFrame is now a Frame, with correct flags set.
1124
* Changed: DamagedFrame is now a property on a Frame.
1225

README.md

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,26 @@ streaming protocol for low-speed embedded applications, such as serial
1010
connected devices. It allowes the receiver to 'jump into' a stream of data
1111
frames. Every frame starts with a preamble, so the receiver can synchronize.
1212

13-
A payload is optional.
14-
1513
The format of a frame is as follows:
1614

1715
```
16+
| Preamble | Header | Body |
1817
| 0xAA 0x55 0xAA 0x55 | AA AA BB BB CC | XX XX .. .. .. .. XX XX YY YY YY YY |
19-
| Preamble | Header | Body (optional) |
2018
2119
Fields:
22-
A = Length
23-
B = Flags
20+
A = Flags
21+
B = Length
2422
C = XOR checksum over header
25-
X = Body payload (max. 65536 bytes)
26-
Y = CRC32 checksum over header + body
23+
X = Payload (max. 65536 bytes)
24+
Y = CRC32 checksum over header + payload
2725
```
2826

29-
The flags field can have arbitrary values, but the following flags are
30-
reserved.
27+
The flags field can be used for arbitrary purposes. The payload is optional.
3128

32-
* `0x01 = RESET`
33-
* `0x02 = ERROR`
34-
* `0x04 = PRIORITY`
29+
Escaping of the header and body are performed using byte-stuffing, to ensure
30+
that the header and body can contain bytes of the preamble.
3531

36-
Error correction is not implemented and the bytes are not aligned. The
32+
Error correction is not implemented and the bytes are not strictly aligned. The
3733
endianness is customizable.
3834

3935
## State chart diagram
@@ -45,15 +41,16 @@ The latest development version can be installed via
4541
`pip install git+https://github.com/basilfx/python-tinylink`.
4642

4743
## CLI
48-
A simple serial CLI is included. When installed, run
44+
A CLI is included to experiment with TinyLink. When installed, run
4945
`tinylink /dev/tty.PORT_HERE` to start it. You can use it to send raw bytes via
5046
the link and display what comes back.
5147

5248
The CLI supports so-called modifiers to modify the outgoing data. For example,
53-
the input `\flags=1 hello world` would send a reset frame with the value
54-
'hello world'.
49+
the input `\flags=16 hello world` would send a frame with the flags equal to 16
50+
and the payload 'hello world'
5551

56-
PySerial is required to run this CLI.
52+
The CLI requires additional dependencies, that are installed using the `cli`
53+
dependency specification (`poetry install --extras cli`).
5754

5855
## Tests
5956
To run the tests, please clone this repository and run `poetry run pytest`.

docs/statechart.dot

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,20 @@ digraph G {
88
receiving_header[shape=box, style=rounded, label="Receiving\nheader"]
99
receiving_body[shape=box, style=rounded, label="Receiving\nbody"]
1010

11-
output_reset_frame[shape=box, style=rounded, label="Output\nreset frame"]
12-
output_data_frame[shape=box, style=rounded, label="Output\ndata frame"]
11+
output_frame[shape=box, style=rounded, label="Output frame"]
1312

1413
start -> waiting_for_preamble
1514

1615
waiting_for_preamble -> waiting_for_preamble[label="Byte received"]
1716
waiting_for_preamble -> receiving_header[label="Preamble detected"]
1817

1918
receiving_header -> receiving_header[label="Byte received"]
20-
receiving_header -> receiving_body[label="Header complete,\nbody expected"]
19+
receiving_header -> receiving_body[label="Header complete,\nchecksum OK"]
2120
receiving_header -> waiting_for_preamble[label="Header invalid"]
2221

23-
receiving_header -> output_reset_frame[label="Header complete,\nreset frame"]
24-
output_reset_frame -> waiting_for_preamble
25-
2622
receiving_body -> receiving_body[label="Byte received"]
2723
receiving_body -> waiting_for_preamble[label="Body invalid"]
2824

29-
receiving_body -> output_data_frame[label="Body complete,\ndata frame"]
30-
output_data_frame -> waiting_for_preamble
25+
receiving_body -> output_frame[label="Body complete,\nchecksum OK"]
26+
output_frame -> waiting_for_preamble
3127
}

docs/statechart.png

-8.83 KB
Loading

0 commit comments

Comments
 (0)