This commit is contained in:
Mark Qvist 2023-11-01 16:34:24 +01:00
parent acb67dc9a2
commit 8731be2293
5 changed files with 73 additions and 42 deletions

View File

@ -728,8 +728,9 @@ class SidebandApp(MDApp):
if self.conversations_view != None:
self.conversations_view.update()
if self.sideband.getstate("lxm_uri_ingest.result", allow_cache=True):
info_text = self.sideband.getstate("lxm_uri_ingest.result", allow_cache=True)
imr = self.sideband.getstate("lxm_uri_ingest.result", allow_cache=True)
if imr != None and imr != "None":
info_text = str(imr)
self.sideband.setstate("lxm_uri_ingest.result", False)
ok_button = MDRectangleFlatButton(text="OK",font_size=dp(18))
dialog = MDDialog(
@ -744,8 +745,9 @@ class SidebandApp(MDApp):
ok_button.bind(on_release=dl_ok)
dialog.open()
if self.sideband.getstate("hardware_operation.error", allow_cache=True):
info_text = self.sideband.getstate("hardware_operation.error", allow_cache=True)
hwe = self.sideband.getstate("hardware_operation.error", allow_cache=True)
if hwe != None and hwe != "None":
info_text = str(hwe)
self.sideband.setstate("hardware_operation.error", False)
ok_button = MDRectangleFlatButton(text="OK",font_size=dp(18))
dialog = MDDialog(
@ -3467,6 +3469,12 @@ class SidebandApp(MDApp):
if self.object_details_screen != None:
context_dest = self.object_details_screen.object_hash
if not self.object_details_screen.object_hash == self.sideband.lxmf_destination.hash:
if self.sideband.has_conversation(context_dest):
pass
else:
self.sideband.create_conversation(context_dest)
self.sideband.setstate("app.flags.new_conversations", True)
self.open_conversation(context_dest)
def telemetry_send_update(self, sender=None):

View File

@ -119,6 +119,7 @@ class SidebandCore():
self.telemeter = None
self.telemetry_running = False
self.latest_telemetry = None
self.latest_packed_telemetry = None
self.telemetry_changes = 0
self.pending_telemetry_send = False
self.pending_telemetry_send_try = 0
@ -735,6 +736,7 @@ class SidebandCore():
def should_send_telemetry(self, context_dest):
try:
if self.config["telemetry_enabled"]:
existing_conv = self._db_conversation(context_dest)
if existing_conv != None:
cd = existing_conv["data"]
@ -748,6 +750,9 @@ class SidebandCore():
else:
return False
else:
return False
except Exception as e:
RNS.log("Error while checking telemetry sending for "+RNS.prettyhexrep(context_dest)+": "+str(e), RNS.LOG_ERROR)
return False
@ -1015,13 +1020,15 @@ class SidebandCore():
desired_method = LXMF.LXMessage.DIRECT
lxm_fields = self.get_message_fields(to_addr, is_authorized_telemetry_request=is_authorized_telemetry_request, signal_already_sent=True)
if lxm_fields == False:
if lxm_fields == False and stream == None:
return "already_sent"
if stream != None and len(stream) > 0:
if lxm_fields == False:
lxm_fields = {}
lxm_fields[LXMF.FIELD_TELEMETRY_STREAM] = stream
if lxm_fields != None and (LXMF.FIELD_TELEMETRY in lxm_fields or LXMF.FIELD_TELEMETRY_STREAM in lxm_fields):
if lxm_fields != None and lxm_fields != False and (LXMF.FIELD_TELEMETRY in lxm_fields or LXMF.FIELD_TELEMETRY_STREAM in lxm_fields):
if LXMF.FIELD_TELEMETRY in lxm_fields:
telemeter = Telemeter.from_packed(lxm_fields[LXMF.FIELD_TELEMETRY])
telemetry_timebase = telemeter.read_all()["time"]["utc"]
@ -1654,8 +1661,8 @@ class SidebandCore():
# TODO: Clean out these temporary values at some interval.
# Probably expire after 14 days or so.
self.setpersistent("temp.peer_appearance."+RNS.hexrep(context_dest, delimit=False), ae)
else:
if not from_bulk_telemetry:
data_dict = conv["data"]
if data_dict == None:
data_dict = {}
@ -1663,6 +1670,10 @@ class SidebandCore():
if not "appearance" in data_dict:
data_dict["appearance"] = None
if from_bulk_telemetry and data_dict["appearance"] != SidebandCore.DEFAULT_APPEARANCE:
RNS.log("Aborting appearance update from bulk transfer, since conversation already has appearance set: "+str(appearance)+" / "+str(data_dict["appearance"]), RNS.LOG_DEBUG)
return
if data_dict["appearance"] != appearance:
data_dict["appearance"] = appearance
packed_dict = msgpack.packb(data_dict)
@ -1690,6 +1701,9 @@ class SidebandCore():
data_dict = conv["data"]
else:
data_dict = {}
if data_dict != None:
if not "appearance" in data_dict or data_dict["appearance"] == None:
apd = self.getpersistent("temp.peer_appearance."+RNS.hexrep(context_dest, delimit=False))
if apd != None:
try:
@ -1698,7 +1712,6 @@ class SidebandCore():
RNS.log("Could not get appearance data from database: "+str(e),RNS.LOG_ERROR)
data_dict = None
if data_dict != None:
try:
if data_dict != None and "appearance" in data_dict:
def htf(cbytes):
@ -2098,16 +2111,21 @@ class SidebandCore():
packed_telemetry = self._db_save_telemetry(context_dest, lxm.fields[LXMF.FIELD_TELEMETRY], physical_link=physical_link, source_dest=context_dest)
if LXMF.FIELD_TELEMETRY_STREAM in lxm.fields:
max_timebase = self.getpersistent(f"telemetry.{RNS.hexrep(context_dest, delimit=False)}.timebase") or 0
if lxm.fields[LXMF.FIELD_TELEMETRY_STREAM] != None and len(lxm.fields[LXMF.FIELD_TELEMETRY_STREAM]) > 0:
for telemetry_entry in lxm.fields[LXMF.FIELD_TELEMETRY_STREAM]:
tsource = telemetry_entry[0]
ttstamp = telemetry_entry[1]
tpacked = telemetry_entry[2]
appearance = telemetry_entry[3]
max_timebase = max(max_timebase, ttstamp)
if self._db_save_telemetry(tsource, tpacked, via = context_dest):
RNS.log("Saved telemetry stream entry from "+RNS.prettyhexrep(tsource), RNS.LOG_WARNING)
RNS.log("Saved telemetry stream entry from "+RNS.prettyhexrep(tsource), RNS.LOG_DEBUG)
if appearance != None:
self._db_update_appearance(tsource, ttstamp, appearance, from_bulk_telemetry=True)
RNS.log("Updated appearance entry from "+RNS.prettyhexrep(tsource), RNS.LOG_DEBUG)
self.setpersistent(f"telemetry.{RNS.hexrep(context_dest, delimit=False)}.timebase", max_timebase)
else:
RNS.log("Received telemetry stream field with no data: "+str(lxm.fields[LXMF.FIELD_TELEMETRY_STREAM]), RNS.LOG_DEBUG)
@ -3074,9 +3092,9 @@ class SidebandCore():
telemeter = Telemeter.from_packed(self.latest_packed_telemetry)
telemetry_timebase = telemeter.read_all()["time"]["utc"]
if telemetry_timebase > (self.getpersistent(f"telemetry.{RNS.hexrep(context_dest, delimit=False)}.last_send_success_timebase") or 0):
RNS.log("Embedding telemetry in message since current telemetry is newer than latest successful timebase", RNS.LOG_DEBUG)
RNS.log("Embedding own telemetry in message since current telemetry is newer than latest successful timebase", RNS.LOG_DEBUG)
else:
RNS.log("Not embedding telemetry in message since current telemetry is not newer than latest successful timebase", RNS.LOG_DEBUG)
RNS.log("Not embedding own telemetry in message since current telemetry is not newer than latest successful timebase", RNS.LOG_DEBUG)
send_telemetry = False
send_appearance = False
if signal_already_sent:

View File

@ -29,8 +29,6 @@ class Announces():
self.list = None
if not self.app.root.ids.screen_manager.has_screen("announces_screen"):
# TODO: Remove
RNS.log("Adding announces screen", RNS.LOG_WARNING)
self.screen = Builder.load_string(layout_announces_screen)
self.screen.app = self.app
self.ids = self.screen.ids

View File

@ -341,7 +341,7 @@ class RVDetails(MDRecycleView):
else:
if via != None and via == by:
vstr = self.app.sideband.peer_display_name(via)
formatted_values = f"Received from and collected by [b]{vstr}[/b]"
formatted_values = f"Received from, and collected by [b]{vstr}[/b]"
else:
if via != None:
@ -421,12 +421,20 @@ class RVDetails(MDRecycleView):
else:
alt_str = RNS.prettydistance(alt)
formatted_values = f"Coordinates [b]{fcoords}[/b], altitude [b]{alt_str}[/b]"
if speed != None:
if speed > 0.000001:
speed_formatted_values = f"Speed [b]{speed} Km/h[/b], heading [b]{heading}°[/b]"
else:
speed_formatted_values = f"Speed [b]0 Km/h[/b]"
else:
speed_formatted_values = None
extra_formatted_values = f"Uncertainty [b]{accuracy} meters[/b]"+updated_str
data = {"icon": s["icon"], "text": f"{formatted_values}"}
extra_entries.append({"icon": "map-marker-question", "text": extra_formatted_values})
if speed_formatted_values != None:
extra_entries.append({"icon": "speedometer", "text": speed_formatted_values})
if "distance" in s:
if "orthodromic" in s["distance"]:
@ -513,8 +521,6 @@ class RVDetails(MDRecycleView):
extra_entries.append({"icon": rh_icon, "text": rh_formatted_text})
extra_entries.append({"icon": "speedometer", "text": speed_formatted_values})
def select(e=None):
geo_uri = f"geo:{lat},{lon}"
def lj():

View File

@ -22,6 +22,7 @@ from datetime import datetime
if RNS.vendor.platformutils.get_platform() == "android":
from ui.helpers import ts_format
from android.permissions import request_permissions, check_permission
else:
from .helpers import ts_format