From dab2d2000677c0455fda09961df6f1c4c4c11cfb Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Thu, 28 Aug 2025 19:49:34 +0200 Subject: [PATCH] Some work on boatdata: waypoints --- boatdata.py | 69 ++++++++++++++++++++++++++++++++++++++++++++--------- routing.py | 11 ++++++--- 2 files changed, 66 insertions(+), 14 deletions(-) diff --git a/boatdata.py b/boatdata.py index 17cf8bb..4b1250e 100644 --- a/boatdata.py +++ b/boatdata.py @@ -80,8 +80,19 @@ import datetime import time import math import random +from enum import Enum +from io import StringIO + #from .lookup import fluidtype from . import lookup +from . import routing + +class CardinalDirection(Enum): + NORTH = 'N' + SOUTH = 'S' + EAST = 'E' + WEST = 'W' + class BoatValue(): """ @@ -121,7 +132,10 @@ class BoatValue(): self.valid = True # if self.history: # TODO es kann mehrere verschiedene Zeitreihen geben! - # Implementierung nich unklar. + # Implementierung noch unklar. + + def getPlaceholder(self): + return self.placeholder def enableHistory(self, size, delta_t): if self.history: @@ -132,6 +146,9 @@ class BoatValue(): self.hbuf = HistoryBuffer(size, delta_t) def format(self): + # TODO kein schöner Code hier! + if not type(self.value) in (int, float): + return self.value if self.simulated: if self.valname == "xdrVBat": return "{:.1f}".format(random.uniform(11.8, 14.2)) @@ -194,6 +211,7 @@ class BoatValueDate(BoatValue): return formatted class BoatValueTime(BoatValue): + # timefmt = hh:mm | hh:mm:ss def __init__(self, shortname, timezone='UTC'): super().__init__(shortname) self.tz = timezone @@ -203,6 +221,7 @@ class BoatValueTime(BoatValue): return formatted class BoatValueSpeed(BoatValue): + # unit = m/s | kt | km/h # unsigned? Was ist mit Rückwärts? def format(self): if self.simulated: @@ -216,6 +235,7 @@ class BoatValueSpeed(BoatValue): return formatted class BoatValueAngle(BoatValue): + # unit = rad | deg # course, wind, heading, bearing # roll, pitch, yaw, rudder, keel def format(self): @@ -232,6 +252,7 @@ class BoatValueAngle(BoatValue): return self.placeholder class BoatValueRotation(BoatValue): + # unit = rad | deg # signed def format(self): if self.value < 10 and self.value > -10: @@ -241,6 +262,7 @@ class BoatValueRotation(BoatValue): return formatted class BoatValueDepth(BoatValue): + # unit = m | ft # unsigned def format(self): if self.simulated: @@ -460,6 +482,12 @@ class BoatData(): # Sonderdaten self.rotk = BoatValueAngle("xdrRotK", "deg") # Kielrotation + # Routen + self.routes = {} + + # Wegepunkte ohne Routenzuordnung + self.wps = {} + # Maschinen self.engine = {} @@ -512,6 +540,7 @@ class BoatData(): 'WTemp': self.temp_water, 'WPLat': self.wplat, 'WPLon': self.wplon, + 'WPname': self.wpname, 'XTE': self.xte, 'xdrRotK': self.rotk, 'xdrVBat': self.voltage, @@ -555,19 +584,29 @@ class BoatData(): self.sat[prn_num].lastseen = time.time() def __str__(self): - out = "Boat Data\n" - out += f" Voltage: {self.voltage}\n" - out += f" Latitude: {self.lat.value}\n" - out += f" Longitude: {self.lon.value}\n" - out += f" SOG: {self.sog}\n" + out = StringIO() + out.write("Boat Data\n") + out.write(" Voltage: {}\n".format(self.voltage)) + out.write(" Latitude: {}\n".format(self.lat.format())) + out.write(" Longitude: {}\n".format(self.lon.format())) + out.write(" SOG: {}\n".format(self.sog.format())) + out.write(" Waypoint: {}\n".format(self.wpname.format())) + out.write(" Distance: {}\n".format(self.wpdist.format())) + out.write(" Bearing: {}\n".format(self.bearing.format())) for e in self.engine.values(): - out += str(e) + out.write(str(e)) for t in self.tank.values(): - out += str(t) - out += " Satellite info\n" + out.write(str(t)) + out.write(" Routes\n") + for r in self.routes: + out.write(" {}".format(r)) + out.write(" Waypoints\n") + for w in self.wps: + out.write(" {}".format(w)) + out.write(" Satellite info\n") for s in self.sat.values(): - out += " {}".format(str(s)) - return out + out.write(" {}".format(str(s))) + return out.getvalue() def updateValid(self, age=None): # age: Alter eines Meßwerts in Sekunden @@ -621,3 +660,11 @@ class BoatData(): htype: press, temp, hum """ self.history[htype] = history + + def addRoute(self, route_id): + if not route_id in self.routes: + self.routes[route_id] = routing.Route() + + def addWaypoint(self, waypoint_id): + if not waypoint_id in self.wps: + self.wps[waypoint_id] = routing.Waypoint() diff --git a/routing.py b/routing.py index 1524b95..b762753 100644 --- a/routing.py +++ b/routing.py @@ -1,15 +1,20 @@ -''' +""" Routes and waypoints -''' + +Some sources have number and name, some only something like id + +""" + class Waypoint(): def __init__(self, number, name): self.number = number self.name = name self.lat = None self.lon = None + self.lastusage = None # last usage timestamp for housekeeping class Route(): - def __init__(self, number, name) + def __init__(self, number, name): self.number = number self.name = name self.wps = dict()