Skip to content

Commit ce85de6

Browse files
authored
updates from upstream C++ (#66)
* fix auto-ack pipe 0 address in TX mode * `write()` and `load_ack()` should not exit early on TX FIFO full * adjust unit tests * update docs * revise examples * add FIFO constants and adjust `fifo()` for accuracy * update rf24_lite.py
1 parent ebbdece commit ce85de6

23 files changed

+533
-323
lines changed

.cspell.config.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
version: "0.2"
2+
words:
3+
- abled
4+
- adafruit
5+
- addopts
6+
- armv
7+
- ATSAMD
8+
- autoattribute
9+
- autoclass
10+
- autofunction
11+
- automethod
12+
- automodule
13+
- autoproperty
14+
- baudrate
15+
- bgcolor
16+
- blinka
17+
- busdevice
18+
- busio
19+
- bysource
20+
- bytearray
21+
- capsys
22+
- CELLBORDER
23+
- CELLSPACING
24+
- CIRCUITPY
25+
- circuitpython
26+
- coef
27+
- datasheet
28+
- dhcplist
29+
- digitalio
30+
- Disabl
31+
- Dmitry
32+
- docstitle
33+
- Doherty
34+
- Eddystone
35+
- elif
36+
- Fals
37+
- fontcolor
38+
- fontname
39+
- fontsize
40+
- graphviz
41+
- Grinberg
42+
- hexlified
43+
- HHHBB
44+
- Hinch
45+
- intersphinx
46+
- isascii
47+
- Itsy
48+
- Kbps
49+
- labelloc
50+
- LENG
51+
- levelname
52+
- Mbps
53+
- microcontroller
54+
- microcontrollers
55+
- micropython
56+
- minversion
57+
- MOSI
58+
- multicasted
59+
- multicasting
60+
- multicasts
61+
- multiceiver
62+
- mypy
63+
- newrank
64+
- penwidth
65+
- Pinout
66+
- Pluss
67+
- pytest
68+
- ranksep
69+
- raspberrypi
70+
- repr
71+
- rgba
72+
- Rhys
73+
- Roboto
74+
- seealso
75+
- setlinewidth
76+
- setuptools
77+
- sparkfun
78+
- spidev
79+
- testpaths
80+
- toctree
81+
- twopi
82+
- urandom
83+
- venv
84+
- versionadded
85+
- versionchanged
86+
- viewcode
87+
- WLAN
88+
- xfer

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44

55
repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v4.6.0
7+
rev: v5.0.0
88
hooks:
99
- id: check-yaml
1010
exclude: ^docs/social_cards/layouts
1111
- id: end-of-file-fixer
1212
- id: trailing-whitespace
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.4.8
14+
rev: v0.11.8
1515
hooks:
1616
# Run the linter.
1717
- id: ruff
1818
args: [ --fix ]
1919
# Run the formatter.
2020
- id: ruff-format
2121
- repo: https://github.com/pre-commit/mirrors-mypy
22-
rev: v1.10.0
22+
rev: v1.15.0
2323
hooks:
2424
- id: mypy
2525
name: mypy (library code)

circuitpython_nrf24l01/fake_ble.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def __init__(
195195
self._addr_len = 4 # use only 4 byte address length
196196
self._tx_address[:4] = b"\x71\x91\x7d\x6b"
197197
with self:
198-
super().open_rx_pipe(0, b"\x71\x91\x7d\x6b\0")
198+
super().open_rx_pipe(1, b"\x71\x91\x7d\x6b\0")
199199
#: The internal queue of received BLE payloads' data.
200200
self.rx_queue: List[QueueElement] = []
201201
self.rx_cache: bytearray = bytearray(0)

circuitpython_nrf24l01/network/constants.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,11 @@
7373
MSG_FRAG_MORE = const(149)
7474
#: Used to indicate the last frame of a fragmented message.
7575
MSG_FRAG_LAST = const(150)
76+
77+
# error types used in `header.reserved` attribute
78+
NETWORK_OVERRUN = const(160)
79+
"""Used to indicate that the network was overrun and `RF24Network.available()`
80+
had to exit the internal loop when processing the radio's RX FIFO.
81+
"""
82+
#: Used to indicate the radio's RX FIFO had somehow been corrupted.
83+
NETWORK_CORRUPTION = const(161)

circuitpython_nrf24l01/network/mixins.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@
3636
MSG_FRAG_FIRST,
3737
MSG_FRAG_MORE,
3838
MSG_FRAG_LAST,
39+
NETWORK_CORRUPTION,
3940
NETWORK_DEFAULT_ADDR,
4041
MESH_ADDR_RESPONSE,
4142
MESH_ADDR_REQUEST,
4243
NETWORK_ACK,
4344
NETWORK_EXT_DATA,
45+
NETWORK_OVERRUN,
4446
NETWORK_PING,
4547
NETWORK_POLL,
4648
TX_ROUTED,
@@ -339,15 +341,18 @@ def _pipe_address(self, node_addr: int, pipe_number: int) -> bytearray:
339341
def _net_update(self) -> int:
340342
"""keep the network layer current; returns the received message type"""
341343
ret_val = 0 # sentinel indicating there is nothing to report
344+
timeout = time.monotonic_ns() + 100000000
342345
while True:
346+
if time.monotonic_ns() > timeout:
347+
return NETWORK_OVERRUN
343348
temp_buf = self._rf24.read()
344349
if temp_buf is None:
345350
return ret_val
346-
if (
347-
not self.frame_buf.unpack(temp_buf)
348-
or not is_address_valid(self.frame_buf.header.to_node)
349-
or not is_address_valid(self.frame_buf.header.from_node)
350-
):
351+
if not self.frame_buf.unpack(temp_buf):
352+
return NETWORK_CORRUPTION
353+
if not is_address_valid(
354+
self.frame_buf.header.to_node
355+
) or not is_address_valid(self.frame_buf.header.from_node):
351356
# print("discarding frame due to invalid network addresses.")
352357
continue
353358

@@ -483,7 +488,9 @@ def _write(self, write_direct: int, send_type: int) -> bool:
483488
"""entry point for transmitting the current frame_buf"""
484489
is_ack_t = self.frame_buf.is_ack_type()
485490

486-
to_node, to_pipe, is_multicast = self._logi_2_phys(write_direct, send_type)
491+
to_node, to_pipe, is_multicast = self._logical_2_physical(
492+
write_direct, send_type
493+
)
487494

488495
if send_type == TX_ROUTED and write_direct == to_node and is_ack_t:
489496
time.sleep(0.002)
@@ -501,7 +508,7 @@ def _write(self, write_direct: int, send_type: int) -> bool:
501508
):
502509
self.frame_buf.header.message_type = NETWORK_ACK
503510
self.frame_buf.header.to_node = self.frame_buf.header.from_node
504-
ack_to_node, ack_to_pipe, is_multicast = self._logi_2_phys(
511+
ack_to_node, ack_to_pipe, is_multicast = self._logical_2_physical(
505512
self.frame_buf.header.from_node, TX_ROUTED
506513
)
507514
# ack_ok =
@@ -593,7 +600,7 @@ def _tx_standby(self, delta_time: int) -> bool:
593600
result = self._rf24.resend(send_only=True)
594601
return result
595602

596-
def _logi_2_phys(
603+
def _logical_2_physical(
597604
self, to_node: int, send_type: int, is_multicast: bool = False
598605
) -> Tuple[int, int, bool]:
599606
"""translate msg route into node address, pipe number, & multicast flag."""

0 commit comments

Comments
 (0)