Skip to content

Commit

Permalink
resolve #48 (#50)
Browse files Browse the repository at this point in the history
Uses original bit shifting math (from C++) to compute the level of an address being verified during handshake.
  • Loading branch information
2bndy5 authored Sep 5, 2023
1 parent cc29e0d commit 74df26e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions circuitpython_nrf24l01/rf24_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ def _request_address(self, level: int) -> bool:
if not contacts:
return False

def _get_level(address: int) -> int:
count = 0
while address:
address >>= 3
count += 1
return count

new_addr = None
for contact in contacts:
# print("Requesting address from", oct(contact))
Expand All @@ -199,8 +206,7 @@ def _request_address(self, level: int) -> bool:
and self.frame_buf.header.reserved == self.node_id
):
new_addr = struct.unpack("<H", self.frame_buf.message[:2])[0]
level = 0 if contact < 7 else len(oct(contact)[2:])
test_addr = new_addr & ~(0xFFFF << (level * 3))
test_addr = new_addr & ~(0xFFFF << (_get_level(contact) * 3))
if test_addr != contact:
new_addr = None
else:
Expand Down

0 comments on commit 74df26e

Please sign in to comment.