implement binary requests

This commit is contained in:
Florent 2025-07-15 10:34:38 +02:00
parent a4f6114870
commit cb6379e4c5
5 changed files with 25 additions and 14 deletions

View file

@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "meshcore"
version = "1.9.14"
version = "1.9.15"
authors = [
{ name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
{ name="Alex Wolden", email="awolden@gmail.com" },

View file

@ -80,7 +80,7 @@ class CommandHandler:
"""
if not self.dispatcher:
raise RuntimeError("Dispatcher not set, cannot send commands")
# Use the provided timeout or fall back to default_timeout
timeout = timeout if timeout is not None else self.default_timeout
@ -389,6 +389,12 @@ class CommandHandler:
data = b"\x27\x00\x00\x00" + dst_bytes
return await self.send(data, [EventType.MSG_SENT, EventType.ERROR])
async def send_binary_req(self, dst: DestinationType, bin_data) -> Event :
dst_bytes = _validate_destination(dst, prefix_length=32)
logger.debug(f"Binary request to {dst_bytes.hex()}")
data = b"\x32" + dst_bytes + bin_data
return await self.send(data, [EventType.MSG_SENT, EventType.ERROR])
async def get_self_telemetry(self) -> Event :
logger.debug(f"Getting self telemetry")
data = b"\x27\x00\x00\x00"
@ -404,11 +410,6 @@ class CommandHandler:
data = b"\x29" + key.encode("utf-8") + b":" + value.encode("utf-8")
return await self.send(data, [EventType.OK, EventType.ERROR])
async def send_cli(self, cmd) -> Event:
logger.debug(f"Sending CLI command: {cmd}")
data = b"\x32" + cmd.encode('utf-8')
return await self.send(data, [EventType.CLI_RESPONSE, EventType.ERROR])
async def get_channel(self, channel_idx: int) -> Event:
logger.debug(f"Getting channel info for channel {channel_idx}")
data = b"\x1f" + channel_idx.to_bytes(1, 'little')

View file

@ -18,7 +18,6 @@ class EventType(Enum):
CONTACT_URI = "contact_uri"
BATTERY = "battery_info"
DEVICE_INFO = "device_info"
CLI_RESPONSE = "cli_response"
MSG_SENT = "message_sent"
NEW_CONTACT = "new_contact"
@ -35,6 +34,7 @@ class EventType(Enum):
TRACE_DATA = "trace_data"
RX_LOG_DATA = "rx_log_data"
TELEMETRY_RESPONSE = "telemetry_response"
BINARY_RESPONSE = "binary_response"
CUSTOM_VARS = "custom_vars"
CHANNEL_INFO = "channel_info"

View file

@ -24,7 +24,8 @@ class PacketType(Enum):
SIGN_START = 19
SIGNATURE = 20
CUSTOM_VARS = 21
CLI_RESPONSE = 50
BINARY_REQ = 50
FACTORY_RESET = 51
# Push notifications
ADVERTISEMENT = 0x80
@ -39,3 +40,4 @@ class PacketType(Enum):
TRACE_DATA = 0x89
PUSH_CODE_NEW_ADVERT = 0x8A
TELEMETRY_RESPONSE = 0x8B
BINARY_RESPONSE = 0x8C

View file

@ -213,11 +213,6 @@ class MessageReader:
res["ver"] = data[60:80].decode().replace("\0","")
await self.dispatcher.dispatch(Event(EventType.DEVICE_INFO, res))
elif packet_type_value == PacketType.CLI_RESPONSE.value:
res = {}
res["response"] = data[1:].decode()
await self.dispatcher.dispatch(Event(EventType.CLI_RESPONSE, res))
elif packet_type_value == PacketType.CUSTOM_VARS.value:
logger.debug(f"received custom vars response: {data.hex()}")
res = {}
@ -449,6 +444,19 @@ class MessageReader:
await self.dispatcher.dispatch(Event(EventType.TELEMETRY_RESPONSE, res, attributes))
elif packet_type_value == PacketType.BINARY_RESPONSE.value:
logger.debug(f"Received binary data: {data.hex()}")
res = {}
res["tag"] = data[2:6].hex()
res["data"] = data[6:].hex()
attributes = {
"tag" : res["tag"]
}
await self.dispatcher.dispatch(Event(EventType.BINARY_RESPONSE, res, attributes))
else:
logger.debug(f"Unhandled data received {data}")
logger.debug(f"Unhandled packet type: {packet_type_value}")