Skip to content

Commit a616162

Browse files
committed
support only_prefix flag on discover node
1 parent d3c9c8d commit a616162

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "meshcore"
7-
version = "2.1.21"
7+
version = "2.1.22"
88
authors = [
99
{ name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
1010
{ name="Alex Wolden", email="awolden@gmail.com" },

src/meshcore/commands/control_data.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
class ControlDataCommandHandler(CommandHandlerBase):
1111
"""Helper functions to handle binary requests through binary commands"""
1212

13-
async def send_control_data (self, control_type: ControlType, payload: bytes) -> Event:
13+
async def send_control_data (self, control_type: int, payload: bytes) -> Event:
1414
data = bytearray([PacketType.SEND_CONTROL_DATA.value])
15-
data.extend(control_type.value.to_bytes(1, "little", signed = False))
15+
data.extend(control_type.to_bytes(1, "little", signed = False))
1616
data.extend(payload)
1717

1818
result = await self.send(data, [EventType.OK, EventType.ERROR])
@@ -21,6 +21,7 @@ async def send_control_data (self, control_type: ControlType, payload: bytes) ->
2121
async def send_node_discover_req (
2222
self,
2323
filter: int,
24+
prefix_only: bool=True,
2425
tag: int=None,
2526
since: int=None
2627
) -> Event:
@@ -36,7 +37,11 @@ async def send_node_discover_req (
3637

3738
logger.debug(f"sending node discover req {data.hex()}")
3839

39-
res = await self.send_control_data(ControlType.NODE_DISCOVER_REQ, data)
40+
flags = 0
41+
flags = flags | 1 if prefix_only else flags
42+
43+
res = await self.send_control_data(
44+
ControlType.NODE_DISCOVER_REQ.value|flags, data)
4045

4146
if res is None:
4247
return None

src/meshcore/reader.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,14 @@ async def handle_rx(self, data: bytearray):
618618
ndr["node_type"] = payload_type & 0x0F
619619
ndr["SNR_in"] = int.from_bytes(pbuf.read(1), byteorder="little", signed=True)/4
620620
ndr["tag"] = pbuf.read(4).hex()
621-
ndr["pubkey"] = pbuf.read(32).hex()
621+
622+
pubkey = pbuf.read()
623+
if len(pubkey) < 32:
624+
pubkey = pubkey[0:8]
625+
else:
626+
pubkey = pubkey[0:32]
627+
628+
ndr["pubkey"] = pubkey.hex()
622629

623630
attributes = {
624631
"node_type" : ndr["node_type"],

0 commit comments

Comments
 (0)