From a095ba7e405f34f3dd6195f1d24a59fbb3e13d1b Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Mon, 23 Oct 2023 01:34:20 +0200 Subject: [PATCH] Added physical layer link statistics to reception --- LXMF/LXMF.py | 14 +++++++++++++- LXMF/LXMRouter.py | 13 ++++++++++--- LXMF/LXMessage.py | 3 +++ LXMF/__init__.py | 1 + 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/LXMF/LXMF.py b/LXMF/LXMF.py index d19b423..6e8d479 100644 --- a/LXMF/LXMF.py +++ b/LXMF/LXMF.py @@ -1 +1,13 @@ -APP_NAME = "lxmf" \ No newline at end of file +APP_NAME = "lxmf" + +# WARNING! These specifications are floating and not +# yet final! Consider highly experiemental, and expect +# them to change in the future! You have been warned :) + +FIELD_EMBEDDED_LXMS = 0x01 +FIELD_TELEMETRY = 0x02 +FIELD_ICON_APPEARANCE = 0x03 +FIELD_FILE_ATTACHMENTS = 0x04 +FIELD_IMAGE = 0x05 +FIELD_AUDIO = 0x06 +FIELD_THREAD = 0x07 \ No newline at end of file diff --git a/LXMF/LXMRouter.py b/LXMF/LXMRouter.py index bfcd428..a8963d2 100644 --- a/LXMF/LXMRouter.py +++ b/LXMF/LXMRouter.py @@ -842,10 +842,15 @@ class LXMRouter: self.pending_outbound.append(lxmessage) self.process_outbound() - def lxmf_delivery(self, lxmf_data, destination_type = None): + def lxmf_delivery(self, lxmf_data, destination_type = None, phy_stats = None): try: message = LXMessage.unpack_from_bytes(lxmf_data) + if phy_stats != None: + if "rssi" in phy_stats: message.rssi = phy_stats["rssi"] + if "snr" in phy_stats: message.snr = phy_stats["snr"] + if "q" in phy_stats: message.q = phy_stats["q"] + if destination_type == RNS.Destination.SINGLE: message.transport_encrypted = True message.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_EC @@ -885,7 +890,8 @@ class LXMRouter: else: lxmf_data = data - if self.lxmf_delivery(lxmf_data, packet.destination_type): + phy_stats = {"rssi": packet.rssi, "snr": packet.snr, "q": packet.q} + if self.lxmf_delivery(lxmf_data, packet.destination_type, phy_stats=phy_stats): packet.prove() except Exception as e: @@ -907,7 +913,8 @@ class LXMRouter: def delivery_resource_concluded(self, resource): RNS.log("Transfer concluded for LXMF delivery resource "+str(resource), RNS.LOG_DEBUG) if resource.status == RNS.Resource.COMPLETE: - self.lxmf_delivery(resource.data.read(), resource.link.type) + phy_stats = {"rssi": resource.link.rssi, "snr": resource.link.snr, "q": resource.link.q} + self.lxmf_delivery(resource.data.read(), resource.link.type, phy_stats=phy_stats) ### Peer Sync & Propagation ########################### diff --git a/LXMF/LXMessage.py b/LXMF/LXMessage.py index 6f8a15a..ee83721 100644 --- a/LXMF/LXMessage.py +++ b/LXMF/LXMessage.py @@ -122,6 +122,9 @@ class LXMessage: self.progress = None self.state = LXMessage.DRAFT self.method = LXMessage.UNKNOWN + self.rssi = None + self.snr = None + self.q = None self.propagation_packed = None self.paper_packed = None diff --git a/LXMF/__init__.py b/LXMF/__init__.py index dc0abbb..0458f8d 100644 --- a/LXMF/__init__.py +++ b/LXMF/__init__.py @@ -2,6 +2,7 @@ import os import glob from .LXMessage import LXMessage from .LXMRouter import LXMRouter +from .LXMF import * from ._version import __version__