mirror of
https://github.com/liberatedsystems/Sideband_CE.git
synced 2024-09-03 04:13:27 +02:00
Improved telemetry display and handling
This commit is contained in:
parent
b2958517a4
commit
cf6d88f17e
@ -1,4 +1,4 @@
|
|||||||
__debug_build__ = False
|
__debug_build__ = True
|
||||||
__disable_shaders__ = False
|
__disable_shaders__ = False
|
||||||
__version__ = "0.7.0"
|
__version__ = "0.7.0"
|
||||||
__variant__ = "beta"
|
__variant__ = "beta"
|
||||||
@ -3059,10 +3059,16 @@ class SidebandApp(MDApp):
|
|||||||
self.sideband.config["telemetry_s_angular_velocity"] = self.telemetry_screen.ids.telemetry_s_gyroscope.active
|
self.sideband.config["telemetry_s_angular_velocity"] = self.telemetry_screen.ids.telemetry_s_gyroscope.active
|
||||||
self.sideband.config["telemetry_s_acceleration"] = self.telemetry_screen.ids.telemetry_s_accelerometer.active
|
self.sideband.config["telemetry_s_acceleration"] = self.telemetry_screen.ids.telemetry_s_accelerometer.active
|
||||||
self.sideband.config["telemetry_s_proximity"] = self.telemetry_screen.ids.telemetry_s_proximity.active
|
self.sideband.config["telemetry_s_proximity"] = self.telemetry_screen.ids.telemetry_s_proximity.active
|
||||||
self.sideband.config["telemetry_s_information"] = self.telemetry_screen.ids.telemetry_s_information.active
|
|
||||||
self.sideband.config["telemetry_s_information_text"] = self.telemetry_screen.ids.telemetry_s_information_text.text
|
|
||||||
|
|
||||||
run_telemetry_update = False
|
run_telemetry_update = False
|
||||||
|
if self.sideband.config["telemetry_s_information"] != self.telemetry_screen.ids.telemetry_s_information.active:
|
||||||
|
self.sideband.config["telemetry_s_information"] = self.telemetry_screen.ids.telemetry_s_information.active
|
||||||
|
run_telemetry_update = True
|
||||||
|
|
||||||
|
if self.sideband.config["telemetry_s_information_text"] != self.telemetry_screen.ids.telemetry_s_information_text.text:
|
||||||
|
self.sideband.config["telemetry_s_information_text"] = self.telemetry_screen.ids.telemetry_s_information_text.text
|
||||||
|
run_telemetry_update = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
alt = float(self.telemetry_screen.ids.telemetry_s_fixed_altitude.text.strip().replace(" ", ""))
|
alt = float(self.telemetry_screen.ids.telemetry_s_fixed_altitude.text.strip().replace(" ", ""))
|
||||||
self.telemetry_screen.ids.telemetry_s_fixed_altitude.text = str(alt)
|
self.telemetry_screen.ids.telemetry_s_fixed_altitude.text = str(alt)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
__debug_build__ = False
|
__debug_build__ = True
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import RNS
|
import RNS
|
||||||
|
@ -779,7 +779,11 @@ class SidebandCore():
|
|||||||
def peer_telemetry(self, context_dest, after = None, before = None, limit = None):
|
def peer_telemetry(self, context_dest, after = None, before = None, limit = None):
|
||||||
if context_dest == self.lxmf_destination.hash and limit == 1:
|
if context_dest == self.lxmf_destination.hash and limit == 1:
|
||||||
try:
|
try:
|
||||||
|
if self.latest_telemetry != None and self.latest_packed_telemetry != None:
|
||||||
return [[self.latest_telemetry["time"]["utc"], self.latest_packed_telemetry]]
|
return [[self.latest_telemetry["time"]["utc"], self.latest_packed_telemetry]]
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("An error occurred while retrieving telemetry from the database: "+str(e), RNS.LOG_ERROR)
|
RNS.log("An error occurred while retrieving telemetry from the database: "+str(e), RNS.LOG_ERROR)
|
||||||
return []
|
return []
|
||||||
@ -868,6 +872,25 @@ class SidebandCore():
|
|||||||
RNS.log("Error while setting state over RPC: "+str(e), RNS.LOG_DEBUG)
|
RNS.log("Error while setting state over RPC: "+str(e), RNS.LOG_DEBUG)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def service_set_latest_telemetry(self, latest_telemetry, latest_packed_telemetry):
|
||||||
|
if not RNS.vendor.platformutils.is_android():
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if self.is_service:
|
||||||
|
self.latest_telemetry = latest_telemetry
|
||||||
|
self.latest_packed_telemetry = latest_packed_telemetry
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
if self.rpc_connection == None:
|
||||||
|
self.rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key)
|
||||||
|
self.rpc_connection.send({"latest_telemetry": (latest_telemetry, latest_packed_telemetry)})
|
||||||
|
response = self.rpc_connection.recv()
|
||||||
|
return response
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log("Error while setting telemetry over RPC: "+str(e), RNS.LOG_DEBUG)
|
||||||
|
return False
|
||||||
|
|
||||||
def getstate(self, prop, allow_cache=False):
|
def getstate(self, prop, allow_cache=False):
|
||||||
# TODO: remove
|
# TODO: remove
|
||||||
# us = time.time()
|
# us = time.time()
|
||||||
@ -924,6 +947,11 @@ class SidebandCore():
|
|||||||
elif "setstate" in call:
|
elif "setstate" in call:
|
||||||
prop, val = call["setstate"]
|
prop, val = call["setstate"]
|
||||||
connection.send(self.setstate(prop, val))
|
connection.send(self.setstate(prop, val))
|
||||||
|
elif "latest_telemetry" in call:
|
||||||
|
t,p = call["latest_telemetry"]
|
||||||
|
self.latest_telemetry = t
|
||||||
|
self.latest_packed_telemetry = p
|
||||||
|
connection.send(True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Error on client RPC connection: "+str(e), RNS.LOG_ERROR)
|
RNS.log("Error on client RPC connection: "+str(e), RNS.LOG_ERROR)
|
||||||
connection.close()
|
connection.close()
|
||||||
@ -1770,6 +1798,7 @@ class SidebandCore():
|
|||||||
def stop_telemetry(self):
|
def stop_telemetry(self):
|
||||||
self.telemetry_running = False
|
self.telemetry_running = False
|
||||||
self.telemeter.stop_all()
|
self.telemeter.stop_all()
|
||||||
|
self.update_telemeter_config()
|
||||||
self.setstate("app.flags.last_telemetry", time.time())
|
self.setstate("app.flags.last_telemetry", time.time())
|
||||||
|
|
||||||
def update_telemetry(self):
|
def update_telemetry(self):
|
||||||
@ -1793,12 +1822,27 @@ class SidebandCore():
|
|||||||
else:
|
else:
|
||||||
telemetry_changed = True
|
telemetry_changed = True
|
||||||
|
|
||||||
|
if self.latest_telemetry != None:
|
||||||
|
for sn in self.latest_telemetry:
|
||||||
|
if telemetry_changed:
|
||||||
|
break
|
||||||
|
|
||||||
|
if sn != "time":
|
||||||
|
if not sn in telemetry:
|
||||||
|
telemetry_changed = True
|
||||||
|
|
||||||
if telemetry_changed:
|
if telemetry_changed:
|
||||||
self.telemetry_changes += 1
|
self.telemetry_changes += 1
|
||||||
self.latest_telemetry = telemetry
|
self.latest_telemetry = telemetry
|
||||||
self.latest_packed_telemetry = packed_telemetry
|
self.latest_packed_telemetry = packed_telemetry
|
||||||
self.setstate("app.flags.last_telemetry", time.time())
|
self.setstate("app.flags.last_telemetry", time.time())
|
||||||
|
|
||||||
|
if self.is_client:
|
||||||
|
try:
|
||||||
|
self.service_set_latest_telemetry(self.latest_telemetry, self.latest_packed_telemetry)
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log("Error while sending latest telemetry to service: "+str(e), RNS.LOG_ERROR)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Error while updating telemetry: "+str(e), RNS.LOG_ERROR)
|
RNS.log("Error while updating telemetry: "+str(e), RNS.LOG_ERROR)
|
||||||
|
|
||||||
@ -1807,10 +1851,19 @@ class SidebandCore():
|
|||||||
if self.telemeter == None:
|
if self.telemeter == None:
|
||||||
self.telemeter = Telemeter()
|
self.telemeter = Telemeter()
|
||||||
|
|
||||||
sensors = ["location", "battery", "pressure", "temperature", "humidity", "magnetic_field", "ambient_light", "gravity", "angular_velocity", "acceleration", "proximity"]
|
sensors = ["location", "information", "battery", "pressure", "temperature", "humidity", "magnetic_field", "ambient_light", "gravity", "angular_velocity", "acceleration", "proximity"]
|
||||||
for sensor in sensors:
|
for sensor in sensors:
|
||||||
if self.config["telemetry_s_"+sensor]:
|
if self.config["telemetry_s_"+sensor]:
|
||||||
self.telemeter.enable(sensor)
|
self.telemeter.enable(sensor)
|
||||||
|
else:
|
||||||
|
if sensor == "location":
|
||||||
|
if "location" in self.telemeter.sensors:
|
||||||
|
if self.telemeter.sensors["location"].active:
|
||||||
|
if self.telemeter.sensors["location"].synthesized:
|
||||||
|
if not self.config["telemetry_s_fixed_location"]:
|
||||||
|
self.telemeter.disable(sensor)
|
||||||
|
else:
|
||||||
|
self.telemeter.disable(sensor)
|
||||||
else:
|
else:
|
||||||
self.telemeter.disable(sensor)
|
self.telemeter.disable(sensor)
|
||||||
|
|
||||||
@ -1819,25 +1872,37 @@ class SidebandCore():
|
|||||||
self.telemeter.sensors["location"].latitude = self.config["telemetry_s_fixed_latlon"][0]
|
self.telemeter.sensors["location"].latitude = self.config["telemetry_s_fixed_latlon"][0]
|
||||||
self.telemeter.sensors["location"].longtitude = self.config["telemetry_s_fixed_latlon"][1]
|
self.telemeter.sensors["location"].longtitude = self.config["telemetry_s_fixed_latlon"][1]
|
||||||
self.telemeter.sensors["location"].altitude = self.config["telemetry_s_fixed_altitude"]
|
self.telemeter.sensors["location"].altitude = self.config["telemetry_s_fixed_altitude"]
|
||||||
|
self.telemeter.sensors["location"].stale_time = 30
|
||||||
|
|
||||||
if self.config["telemetry_s_information"]:
|
if self.config["telemetry_s_information"]:
|
||||||
self.telemeter.synthesize("information")
|
self.telemeter.synthesize("information")
|
||||||
self.telemeter.sensors["information"].contents = self.config["telemetry_s_information_text"]
|
self.telemeter.sensors["information"].contents = self.config["telemetry_s_information_text"]
|
||||||
|
|
||||||
|
else:
|
||||||
|
self.telemeter = None
|
||||||
|
self.latest_telemetry = None
|
||||||
|
self.latest_packed_telemetry = None
|
||||||
|
|
||||||
def get_telemetry(self):
|
def get_telemetry(self):
|
||||||
if self.config["telemetry_enabled"] == True:
|
if self.config["telemetry_enabled"] == True:
|
||||||
self.update_telemeter_config()
|
self.update_telemeter_config()
|
||||||
|
if self.telemeter != None:
|
||||||
return self.telemeter.read_all()
|
return self.telemeter.read_all()
|
||||||
else:
|
else:
|
||||||
return {}
|
return {}
|
||||||
|
else:
|
||||||
|
return {}
|
||||||
|
|
||||||
def get_packed_telemetry(self):
|
def get_packed_telemetry(self):
|
||||||
if self.config["telemetry_enabled"] == True:
|
if self.config["telemetry_enabled"] == True:
|
||||||
self.update_telemeter_config()
|
self.update_telemeter_config()
|
||||||
|
if self.telemeter != None:
|
||||||
packed = self.telemeter.packed()
|
packed = self.telemeter.packed()
|
||||||
return packed
|
return packed
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def is_known(self, dest_hash):
|
def is_known(self, dest_hash):
|
||||||
try:
|
try:
|
||||||
@ -1988,7 +2053,7 @@ class SidebandCore():
|
|||||||
target_port = self.owner_app.usb_devices[0]["port"]
|
target_port = self.owner_app.usb_devices[0]["port"]
|
||||||
RNS.Interfaces.Android.RNodeInterface.RNodeInterface.bluetooth_control(port=target_port, pairing_mode = True)
|
RNS.Interfaces.Android.RNodeInterface.RNodeInterface.bluetooth_control(port=target_port, pairing_mode = True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.setstate("hardware_operation.error", "An error ocurred while trying to communicate with the device. Please make sure that Sideband has been granted permissions to access the device.\n\nThe reported error was:\n\n[i]"+str(e)+"[/i]")
|
self.setstate("hardware_operation.error", "An error occurred while trying to communicate with the device. Please make sure that Sideband has been granted permissions to access the device.\n\nThe reported error was:\n\n[i]"+str(e)+"[/i]")
|
||||||
else:
|
else:
|
||||||
RNS.log("Could not execute RNode Bluetooth control command, no USB devices available", RNS.LOG_ERROR)
|
RNS.log("Could not execute RNode Bluetooth control command, no USB devices available", RNS.LOG_ERROR)
|
||||||
self.setstate("executing.bt_pair", False)
|
self.setstate("executing.bt_pair", False)
|
||||||
@ -2072,7 +2137,7 @@ class SidebandCore():
|
|||||||
|
|
||||||
if self.is_standalone or self.is_client:
|
if self.is_standalone or self.is_client:
|
||||||
if self.config["telemetry_enabled"]:
|
if self.config["telemetry_enabled"]:
|
||||||
self.latest_telemetry = self.run_telemetry()
|
self.run_telemetry()
|
||||||
|
|
||||||
def __add_localinterface(self, delay=None):
|
def __add_localinterface(self, delay=None):
|
||||||
self.interface_local_adding = True
|
self.interface_local_adding = True
|
||||||
|
@ -190,6 +190,14 @@ class Sensor():
|
|||||||
self.last_update = time.time()
|
self.last_update = time.time()
|
||||||
self._data = value
|
self._data = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def stale_time(self):
|
||||||
|
return self._stale_time
|
||||||
|
|
||||||
|
@stale_time.setter
|
||||||
|
def stale_time(self, value):
|
||||||
|
self._stale_time = value
|
||||||
|
|
||||||
def update_data(self):
|
def update_data(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@ -485,7 +493,7 @@ class Battery(Sensor):
|
|||||||
if p >= 70: rendered["icon"] = "battery-70"
|
if p >= 70: rendered["icon"] = "battery-70"
|
||||||
if p >= 80: rendered["icon"] = "battery-80"
|
if p >= 80: rendered["icon"] = "battery-80"
|
||||||
if p >= 90: rendered["icon"] = "battery-90"
|
if p >= 90: rendered["icon"] = "battery-90"
|
||||||
if p >= 100: rendered["icon"]= "battery-100"
|
if p >= 97: rendered["icon"] = "battery"
|
||||||
|
|
||||||
return rendered
|
return rendered
|
||||||
|
|
||||||
@ -570,6 +578,7 @@ class Location(Sensor):
|
|||||||
super().__init__(type(self).SID, type(self).STALE_TIME)
|
super().__init__(type(self).SID, type(self).STALE_TIME)
|
||||||
|
|
||||||
self._raw = None
|
self._raw = None
|
||||||
|
self._last_update = None
|
||||||
self._min_distance = Location.MIN_DISTANCE
|
self._min_distance = Location.MIN_DISTANCE
|
||||||
self._accuracy_target = Location.ACCURACY_TARGET
|
self._accuracy_target = Location.ACCURACY_TARGET
|
||||||
|
|
||||||
@ -632,6 +641,13 @@ class Location(Sensor):
|
|||||||
try:
|
try:
|
||||||
if self.synthesized:
|
if self.synthesized:
|
||||||
if self.latitude != None and self.longtitude != None:
|
if self.latitude != None and self.longtitude != None:
|
||||||
|
|
||||||
|
now = time.time()
|
||||||
|
if self._last_update == None:
|
||||||
|
self._last_update = now
|
||||||
|
elif now > self._last_update + self._stale_time:
|
||||||
|
self._last_update = now
|
||||||
|
|
||||||
if self.altitude == None: self.altitude = 0.0
|
if self.altitude == None: self.altitude = 0.0
|
||||||
if self.accuracy == None: self.accuracy = 0.01
|
if self.accuracy == None: self.accuracy = 0.01
|
||||||
if self.speed == None: self.speed = 0.0
|
if self.speed == None: self.speed = 0.0
|
||||||
@ -643,7 +659,7 @@ class Location(Sensor):
|
|||||||
"speed": round(self.speed, 2),
|
"speed": round(self.speed, 2),
|
||||||
"bearing": round(self.bearing, 2),
|
"bearing": round(self.bearing, 2),
|
||||||
"accuracy": round(self.accuracy, 2),
|
"accuracy": round(self.accuracy, 2),
|
||||||
"last_update": int(time.time()),
|
"last_update": int(self._last_update),
|
||||||
}
|
}
|
||||||
|
|
||||||
elif RNS.vendor.platformutils.is_android():
|
elif RNS.vendor.platformutils.is_android():
|
||||||
|
@ -376,7 +376,7 @@ class RVDetails(MDRecycleView):
|
|||||||
self.entries.append(extra)
|
self.entries.append(extra)
|
||||||
|
|
||||||
if len(self.entries) == 0:
|
if len(self.entries) == 0:
|
||||||
self.entries.append({"icon": "account-question-outline", "text": f"No information known about this peer"})
|
self.entries.append({"icon": "timeline-question-outline", "text": f"No telemetry available for this device"})
|
||||||
|
|
||||||
self.data = self.entries
|
self.data = self.entries
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user