Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .cspell.config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
version: "0.2"
words:
- abled
- adafruit
- addopts
- armv
- ATSAMD
- autoattribute
- autoclass
- autofunction
- automethod
- automodule
- autoproperty
- baudrate
- bgcolor
- blinka
- busdevice
- busio
- bysource
- bytearray
- capsys
- CELLBORDER
- CELLSPACING
- CIRCUITPY
- circuitpython
- coef
- datasheet
- dhcplist
- digitalio
- Disabl
- Dmitry
- docstitle
- Doherty
- Eddystone
- elif
- Fals
- fontcolor
- fontname
- fontsize
- graphviz
- Grinberg
- hexlified
- HHHBB
- Hinch
- intersphinx
- isascii
- Itsy
- Kbps
- labelloc
- LENG
- levelname
- Mbps
- microcontroller
- microcontrollers
- micropython
- minversion
- MOSI
- multicasted
- multicasting
- multicasts
- multiceiver
- mypy
- newrank
- penwidth
- Pinout
- Pluss
- pytest
- ranksep
- raspberrypi
- repr
- rgba
- Rhys
- Roboto
- seealso
- setlinewidth
- setuptools
- sparkfun
- spidev
- testpaths
- toctree
- twopi
- urandom
- venv
- versionadded
- versionchanged
- viewcode
- WLAN
- xfer
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-yaml
exclude: ^docs/social_cards/layouts
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.8
rev: v0.11.8
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
rev: v1.15.0
hooks:
- id: mypy
name: mypy (library code)
Expand Down
2 changes: 1 addition & 1 deletion circuitpython_nrf24l01/fake_ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def __init__(
self._addr_len = 4 # use only 4 byte address length
self._tx_address[:4] = b"\x71\x91\x7d\x6b"
with self:
super().open_rx_pipe(0, b"\x71\x91\x7d\x6b\0")
super().open_rx_pipe(1, b"\x71\x91\x7d\x6b\0")
#: The internal queue of received BLE payloads' data.
self.rx_queue: List[QueueElement] = []
self.rx_cache: bytearray = bytearray(0)
Expand Down
8 changes: 8 additions & 0 deletions circuitpython_nrf24l01/network/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,11 @@
MSG_FRAG_MORE = const(149)
#: Used to indicate the last frame of a fragmented message.
MSG_FRAG_LAST = const(150)

# error types used in `header.reserved` attribute
NETWORK_OVERRUN = const(160)
"""Used to indicate that the network was overrun and `RF24Network.available()`
had to exit the internal loop when processing the radio's RX FIFO.
"""
#: Used to indicate the radio's RX FIFO had somehow been corrupted.
NETWORK_CORRUPTION = const(161)
23 changes: 15 additions & 8 deletions circuitpython_nrf24l01/network/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
MSG_FRAG_FIRST,
MSG_FRAG_MORE,
MSG_FRAG_LAST,
NETWORK_CORRUPTION,
NETWORK_DEFAULT_ADDR,
MESH_ADDR_RESPONSE,
MESH_ADDR_REQUEST,
NETWORK_ACK,
NETWORK_EXT_DATA,
NETWORK_OVERRUN,
NETWORK_PING,
NETWORK_POLL,
TX_ROUTED,
Expand Down Expand Up @@ -339,15 +341,18 @@
def _net_update(self) -> int:
"""keep the network layer current; returns the received message type"""
ret_val = 0 # sentinel indicating there is nothing to report
timeout = time.monotonic_ns() + 100000000

Check warning on line 344 in circuitpython_nrf24l01/network/mixins.py

View check run for this annotation

Codecov / codecov/patch

circuitpython_nrf24l01/network/mixins.py#L344

Added line #L344 was not covered by tests
while True:
if time.monotonic_ns() > timeout:
return NETWORK_OVERRUN

Check warning on line 347 in circuitpython_nrf24l01/network/mixins.py

View check run for this annotation

Codecov / codecov/patch

circuitpython_nrf24l01/network/mixins.py#L346-L347

Added lines #L346 - L347 were not covered by tests
temp_buf = self._rf24.read()
if temp_buf is None:
return ret_val
if (
not self.frame_buf.unpack(temp_buf)
or not is_address_valid(self.frame_buf.header.to_node)
or not is_address_valid(self.frame_buf.header.from_node)
):
if not self.frame_buf.unpack(temp_buf):
return NETWORK_CORRUPTION
if not is_address_valid(

Check warning on line 353 in circuitpython_nrf24l01/network/mixins.py

View check run for this annotation

Codecov / codecov/patch

circuitpython_nrf24l01/network/mixins.py#L351-L353

Added lines #L351 - L353 were not covered by tests
self.frame_buf.header.to_node
) or not is_address_valid(self.frame_buf.header.from_node):
# print("discarding frame due to invalid network addresses.")
continue

Expand Down Expand Up @@ -483,7 +488,9 @@
"""entry point for transmitting the current frame_buf"""
is_ack_t = self.frame_buf.is_ack_type()

to_node, to_pipe, is_multicast = self._logi_2_phys(write_direct, send_type)
to_node, to_pipe, is_multicast = self._logical_2_physical(
write_direct, send_type
)

if send_type == TX_ROUTED and write_direct == to_node and is_ack_t:
time.sleep(0.002)
Expand All @@ -501,7 +508,7 @@
):
self.frame_buf.header.message_type = NETWORK_ACK
self.frame_buf.header.to_node = self.frame_buf.header.from_node
ack_to_node, ack_to_pipe, is_multicast = self._logi_2_phys(
ack_to_node, ack_to_pipe, is_multicast = self._logical_2_physical(

Check warning on line 511 in circuitpython_nrf24l01/network/mixins.py

View check run for this annotation

Codecov / codecov/patch

circuitpython_nrf24l01/network/mixins.py#L511

Added line #L511 was not covered by tests
self.frame_buf.header.from_node, TX_ROUTED
)
# ack_ok =
Expand Down Expand Up @@ -593,7 +600,7 @@
result = self._rf24.resend(send_only=True)
return result

def _logi_2_phys(
def _logical_2_physical(
self, to_node: int, send_type: int, is_multicast: bool = False
) -> Tuple[int, int, bool]:
"""translate msg route into node address, pipe number, & multicast flag."""
Expand Down
Loading