Some work on boatdata: waypoints
This commit is contained in:
parent
cbb5462865
commit
dab2d20006
69
boatdata.py
69
boatdata.py
|
@ -80,8 +80,19 @@ import datetime
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
import random
|
import random
|
||||||
|
from enum import Enum
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
#from .lookup import fluidtype
|
#from .lookup import fluidtype
|
||||||
from . import lookup
|
from . import lookup
|
||||||
|
from . import routing
|
||||||
|
|
||||||
|
class CardinalDirection(Enum):
|
||||||
|
NORTH = 'N'
|
||||||
|
SOUTH = 'S'
|
||||||
|
EAST = 'E'
|
||||||
|
WEST = 'W'
|
||||||
|
|
||||||
|
|
||||||
class BoatValue():
|
class BoatValue():
|
||||||
"""
|
"""
|
||||||
|
@ -121,7 +132,10 @@ class BoatValue():
|
||||||
self.valid = True
|
self.valid = True
|
||||||
# if self.history:
|
# if self.history:
|
||||||
# TODO es kann mehrere verschiedene Zeitreihen geben!
|
# 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):
|
def enableHistory(self, size, delta_t):
|
||||||
if self.history:
|
if self.history:
|
||||||
|
@ -132,6 +146,9 @@ class BoatValue():
|
||||||
self.hbuf = HistoryBuffer(size, delta_t)
|
self.hbuf = HistoryBuffer(size, delta_t)
|
||||||
|
|
||||||
def format(self):
|
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.simulated:
|
||||||
if self.valname == "xdrVBat":
|
if self.valname == "xdrVBat":
|
||||||
return "{:.1f}".format(random.uniform(11.8, 14.2))
|
return "{:.1f}".format(random.uniform(11.8, 14.2))
|
||||||
|
@ -194,6 +211,7 @@ class BoatValueDate(BoatValue):
|
||||||
return formatted
|
return formatted
|
||||||
|
|
||||||
class BoatValueTime(BoatValue):
|
class BoatValueTime(BoatValue):
|
||||||
|
# timefmt = hh:mm | hh:mm:ss
|
||||||
def __init__(self, shortname, timezone='UTC'):
|
def __init__(self, shortname, timezone='UTC'):
|
||||||
super().__init__(shortname)
|
super().__init__(shortname)
|
||||||
self.tz = timezone
|
self.tz = timezone
|
||||||
|
@ -203,6 +221,7 @@ class BoatValueTime(BoatValue):
|
||||||
return formatted
|
return formatted
|
||||||
|
|
||||||
class BoatValueSpeed(BoatValue):
|
class BoatValueSpeed(BoatValue):
|
||||||
|
# unit = m/s | kt | km/h
|
||||||
# unsigned? Was ist mit Rückwärts?
|
# unsigned? Was ist mit Rückwärts?
|
||||||
def format(self):
|
def format(self):
|
||||||
if self.simulated:
|
if self.simulated:
|
||||||
|
@ -216,6 +235,7 @@ class BoatValueSpeed(BoatValue):
|
||||||
return formatted
|
return formatted
|
||||||
|
|
||||||
class BoatValueAngle(BoatValue):
|
class BoatValueAngle(BoatValue):
|
||||||
|
# unit = rad | deg
|
||||||
# course, wind, heading, bearing
|
# course, wind, heading, bearing
|
||||||
# roll, pitch, yaw, rudder, keel
|
# roll, pitch, yaw, rudder, keel
|
||||||
def format(self):
|
def format(self):
|
||||||
|
@ -232,6 +252,7 @@ class BoatValueAngle(BoatValue):
|
||||||
return self.placeholder
|
return self.placeholder
|
||||||
|
|
||||||
class BoatValueRotation(BoatValue):
|
class BoatValueRotation(BoatValue):
|
||||||
|
# unit = rad | deg
|
||||||
# signed
|
# signed
|
||||||
def format(self):
|
def format(self):
|
||||||
if self.value < 10 and self.value > -10:
|
if self.value < 10 and self.value > -10:
|
||||||
|
@ -241,6 +262,7 @@ class BoatValueRotation(BoatValue):
|
||||||
return formatted
|
return formatted
|
||||||
|
|
||||||
class BoatValueDepth(BoatValue):
|
class BoatValueDepth(BoatValue):
|
||||||
|
# unit = m | ft
|
||||||
# unsigned
|
# unsigned
|
||||||
def format(self):
|
def format(self):
|
||||||
if self.simulated:
|
if self.simulated:
|
||||||
|
@ -460,6 +482,12 @@ class BoatData():
|
||||||
# Sonderdaten
|
# Sonderdaten
|
||||||
self.rotk = BoatValueAngle("xdrRotK", "deg") # Kielrotation
|
self.rotk = BoatValueAngle("xdrRotK", "deg") # Kielrotation
|
||||||
|
|
||||||
|
# Routen
|
||||||
|
self.routes = {}
|
||||||
|
|
||||||
|
# Wegepunkte ohne Routenzuordnung
|
||||||
|
self.wps = {}
|
||||||
|
|
||||||
# Maschinen
|
# Maschinen
|
||||||
self.engine = {}
|
self.engine = {}
|
||||||
|
|
||||||
|
@ -512,6 +540,7 @@ class BoatData():
|
||||||
'WTemp': self.temp_water,
|
'WTemp': self.temp_water,
|
||||||
'WPLat': self.wplat,
|
'WPLat': self.wplat,
|
||||||
'WPLon': self.wplon,
|
'WPLon': self.wplon,
|
||||||
|
'WPname': self.wpname,
|
||||||
'XTE': self.xte,
|
'XTE': self.xte,
|
||||||
'xdrRotK': self.rotk,
|
'xdrRotK': self.rotk,
|
||||||
'xdrVBat': self.voltage,
|
'xdrVBat': self.voltage,
|
||||||
|
@ -555,19 +584,29 @@ class BoatData():
|
||||||
self.sat[prn_num].lastseen = time.time()
|
self.sat[prn_num].lastseen = time.time()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
out = "Boat Data\n"
|
out = StringIO()
|
||||||
out += f" Voltage: {self.voltage}\n"
|
out.write("Boat Data\n")
|
||||||
out += f" Latitude: {self.lat.value}\n"
|
out.write(" Voltage: {}\n".format(self.voltage))
|
||||||
out += f" Longitude: {self.lon.value}\n"
|
out.write(" Latitude: {}\n".format(self.lat.format()))
|
||||||
out += f" SOG: {self.sog}\n"
|
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():
|
for e in self.engine.values():
|
||||||
out += str(e)
|
out.write(str(e))
|
||||||
for t in self.tank.values():
|
for t in self.tank.values():
|
||||||
out += str(t)
|
out.write(str(t))
|
||||||
out += " Satellite info\n"
|
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():
|
for s in self.sat.values():
|
||||||
out += " {}".format(str(s))
|
out.write(" {}".format(str(s)))
|
||||||
return out
|
return out.getvalue()
|
||||||
|
|
||||||
def updateValid(self, age=None):
|
def updateValid(self, age=None):
|
||||||
# age: Alter eines Meßwerts in Sekunden
|
# age: Alter eines Meßwerts in Sekunden
|
||||||
|
@ -621,3 +660,11 @@ class BoatData():
|
||||||
htype: press, temp, hum
|
htype: press, temp, hum
|
||||||
"""
|
"""
|
||||||
self.history[htype] = history
|
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()
|
||||||
|
|
11
routing.py
11
routing.py
|
@ -1,15 +1,20 @@
|
||||||
'''
|
"""
|
||||||
Routes and waypoints
|
Routes and waypoints
|
||||||
'''
|
|
||||||
|
Some sources have number and name, some only something like id
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
class Waypoint():
|
class Waypoint():
|
||||||
def __init__(self, number, name):
|
def __init__(self, number, name):
|
||||||
self.number = number
|
self.number = number
|
||||||
self.name = name
|
self.name = name
|
||||||
self.lat = None
|
self.lat = None
|
||||||
self.lon = None
|
self.lon = None
|
||||||
|
self.lastusage = None # last usage timestamp for housekeeping
|
||||||
|
|
||||||
class Route():
|
class Route():
|
||||||
def __init__(self, number, name)
|
def __init__(self, number, name):
|
||||||
self.number = number
|
self.number = number
|
||||||
self.name = name
|
self.name = name
|
||||||
self.wps = dict()
|
self.wps = dict()
|
||||||
|
|
Loading…
Reference in New Issue