From 8dad802f53336ae4c7c986fbdfe4e76976095870 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 20 Oct 2023 17:27:15 +0200 Subject: [PATCH] Added ability to discern telemetry changes --- sbapp/sideband/core.py | 38 ++++++++++++++++++++++++++++++++------ sbapp/sideband/sense.py | 4 ++-- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index a74dba4..0dcfbc2 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -72,7 +72,9 @@ class SidebandCore(): SERVICE_JOB_INTERVAL = 1 PERIODIC_JOBS_INTERVAL = 60 PERIODIC_SYNC_RETRY = 360 - TELEMETRY_INTERVAL = 60 + # TODO: Reset + # TELEMETRY_INTERVAL = 60 + TELEMETRY_INTERVAL = 10 IF_CHANGE_ANNOUNCE_MIN_INTERVAL = 6 # In seconds AUTO_ANNOUNCE_RANDOM_MIN = 90 # In minutes @@ -101,6 +103,7 @@ class SidebandCore(): self.telemeter = None self.telemetry_running = False self.latest_telemetry = None + self.telemetry_changes = 0 self.app_dir = plyer.storagepath.get_home_dir()+"/.config/sideband" if self.app_dir.startswith("file://"): @@ -1396,7 +1399,29 @@ class SidebandCore(): self.telemeter.stop_all() def update_telemetry(self): - self.latest_telemetry = self.get_telemetry() + telemetry = self.get_telemetry() + packed_telemetry = self.get_packed_telemetry() + telemetry_changed = False + + if telemetry != None and packed_telemetry != None: + if self.latest_telemetry == None or len(telemetry) != len(self.latest_telemetry): + telemetry_changed = True + + for sn in telemetry: + if telemetry_changed: + break + + if sn != "time": + if sn in self.latest_telemetry: + if telemetry[sn] != self.latest_telemetry[sn]: + telemetry_changed = True + else: + telemetry_changed = True + + if telemetry_changed: + self.telemetry_changes += 1 + self.latest_telemetry = telemetry + self.latest_packed_telemetry = packed_telemetry def update_telemeter_config(self): if self.config["telemetry_enabled"] == True: @@ -1418,7 +1443,7 @@ class SidebandCore(): self.update_telemeter_config() packed = self.telemeter.packed() # TODO: Remove - RNS.log(str(packed), RNS.LOG_WARNING) + RNS.log("Packed telemetry: "+str(packed), RNS.LOG_WARNING) return packed def is_known(self, dest_hash): @@ -1636,11 +1661,12 @@ class SidebandCore(): self.lxmf_announce() self.last_if_change_announce = time.time() - if self.config["telemetry_enabled"]: - self.latest_telemetry = self.run_telemetry() - self.periodic_thread = threading.Thread(target=self._periodic_jobs, daemon=True) self.periodic_thread.start() + + if self.is_standalone or self.is_client: + if self.config["telemetry_enabled"]: + self.latest_telemetry = self.run_telemetry() def __start_jobs_immediate(self): if self.log_verbose: diff --git a/sbapp/sideband/sense.py b/sbapp/sideband/sense.py index 3be8d6e..6f3dd57 100644 --- a/sbapp/sideband/sense.py +++ b/sbapp/sideband/sense.py @@ -277,8 +277,8 @@ class Barometer(Sensor): class Location(Sensor): SID = Sensor.SID_LOCATION - STALE_TIME = 60*5 - MIN_DISTANCE = 5 + STALE_TIME = 15 + MIN_DISTANCE = 4 ACCURACY_TARGET = 250 def __init__(self):