mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-06-13 12:46:53 +00:00
control codes support: node_discover_req
This commit is contained in:
@@ -7,10 +7,15 @@ from .binary import BinaryCommandHandler
|
||||
from .contact import ContactCommands
|
||||
from .device import DeviceCommands
|
||||
from .messaging import MessagingCommands
|
||||
from .control_data import ControlDataCommandHandler
|
||||
|
||||
|
||||
class CommandHandler(
|
||||
DeviceCommands, ContactCommands, MessagingCommands, BinaryCommandHandler
|
||||
DeviceCommands,
|
||||
ContactCommands,
|
||||
MessagingCommands,
|
||||
BinaryCommandHandler,
|
||||
ControlDataCommandHandler
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
45
src/meshcore/commands/control_data.py
Normal file
45
src/meshcore/commands/control_data.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import logging
|
||||
import random
|
||||
|
||||
from .base import CommandHandlerBase
|
||||
from ..events import EventType, Event
|
||||
from ..packets import ControlType, PacketType
|
||||
|
||||
logger = logging.getLogger("meshcore")
|
||||
|
||||
class ControlDataCommandHandler(CommandHandlerBase):
|
||||
"""Helper functions to handle binary requests through binary commands"""
|
||||
|
||||
async def send_control_data (self, control_type: ControlType, payload: bytes) -> Event:
|
||||
data = bytearray([PacketType.SEND_CONTROL_DATA.value])
|
||||
data.extend(control_type.value.to_bytes(1, "little", signed = False))
|
||||
data.extend(payload)
|
||||
|
||||
result = await self.send(data, [EventType.OK, EventType.ERROR])
|
||||
return result
|
||||
|
||||
async def send_node_discover_req (
|
||||
self,
|
||||
filter: int,
|
||||
tag: int=None,
|
||||
since: int=None
|
||||
) -> Event:
|
||||
|
||||
if tag is None:
|
||||
tag = random.randint(1, 0xFFFFFFFF)
|
||||
|
||||
data = bytearray()
|
||||
data.extend(filter.to_bytes(1, "little", signed=False))
|
||||
data.extend(tag.to_bytes(4, "little"))
|
||||
if not since is None:
|
||||
data.extend(since.to_bytes(4, "little", signed=False))
|
||||
|
||||
logger.debug(f"sending node discover req {data.hex()}")
|
||||
|
||||
res = await self.send_control_data(ControlType.NODE_DISCOVER_REQ, data)
|
||||
|
||||
if res is None:
|
||||
return None
|
||||
else:
|
||||
res.payload["tag"] = tag
|
||||
return res
|
||||
Reference in New Issue
Block a user