mirror of
https://github.com/jketterl/openwebrx.git
synced 2026-01-19 15:10:21 +01:00
respect timestamps for hfdl locations
This commit is contained in:
parent
dd6fc4581c
commit
f216fea70a
|
|
@ -2,6 +2,7 @@ from pycsdr.modules import ExecModule
|
|||
from pycsdr.types import Format
|
||||
from owrx.aeronautical import AirplaneLocation, AcarsProcessor, IcaoSource
|
||||
from owrx.map import Map, Source
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
import logging
|
||||
|
||||
|
|
@ -83,4 +84,19 @@ class HFDLMessageParser(AcarsProcessor):
|
|||
source = HfdlSource(hfnpdu["flight_id"])
|
||||
else:
|
||||
source = IcaoSource(icao, humanReadable=hfnpdu["flight_id"])
|
||||
Map.getSharedInstance().updateLocation(source, HfdlAirplaneLocation(msg), "HFDL")
|
||||
if "utc_time" in hfnpdu:
|
||||
ts = self.processTimestamp(**hfnpdu["utc_time"])
|
||||
elif "time" in hfnpdu:
|
||||
ts = self.processTimestamp(**hfnpdu["time"])
|
||||
else:
|
||||
ts = None
|
||||
Map.getSharedInstance().updateLocation(source, HfdlAirplaneLocation(msg), "HFDL", timestamp=ts)
|
||||
|
||||
def processTimestamp(self, hour, min, sec) -> datetime:
|
||||
now = datetime.now(timezone.utc)
|
||||
t = now.replace(hour=hour, minute=min, second=sec, microsecond=0)
|
||||
# if we have moved the time to the future, it's most likely that we're close to midnight and the time
|
||||
# we received actually refers to yesterday
|
||||
if t > now:
|
||||
t -= timedelta(days=1)
|
||||
return t
|
||||
|
|
|
|||
19
owrx/map.py
19
owrx/map.py
|
|
@ -1,4 +1,4 @@
|
|||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from owrx.config import Config
|
||||
from owrx.bands import Band
|
||||
from abc import abstractmethod, ABC, ABCMeta
|
||||
|
|
@ -92,19 +92,24 @@ class Map(object):
|
|||
except ValueError:
|
||||
pass
|
||||
|
||||
def updateLocation(self, source: Source, loc: Location, mode: str, band: Band = None):
|
||||
ts = datetime.now()
|
||||
def updateLocation(self, source: Source, loc: Location, mode: str, band: Band = None, timestamp: datetime = None):
|
||||
if timestamp is None:
|
||||
timestamp = datetime.now(timezone.utc)
|
||||
else:
|
||||
# if we get an external timestamp, make sure it's not already expired
|
||||
if datetime.now(timezone.utc) - loc.getTTL() > timestamp:
|
||||
return
|
||||
key = source.getKey()
|
||||
with self.positionsLock:
|
||||
if isinstance(loc, IncrementalUpdate) and key in self.positions:
|
||||
loc.update(self.positions[key]["location"])
|
||||
self.positions[key] = {"source": source, "location": loc, "updated": ts, "mode": mode, "band": band}
|
||||
self.positions[key] = {"source": source, "location": loc, "updated": timestamp, "mode": mode, "band": band}
|
||||
self.broadcast(
|
||||
[
|
||||
{
|
||||
"source": source.__dict__(),
|
||||
"location": loc.__dict__(),
|
||||
"lastseen": ts.timestamp() * 1000,
|
||||
"lastseen": timestamp.timestamp() * 1000,
|
||||
"mode": mode,
|
||||
"band": band.getName() if band is not None else None,
|
||||
}
|
||||
|
|
@ -113,7 +118,7 @@ class Map(object):
|
|||
|
||||
def touchLocation(self, source: Source):
|
||||
# not implemented on the client side yet, so do not use!
|
||||
ts = datetime.now()
|
||||
ts = datetime.now(timezone.utc)
|
||||
key = source.getKey()
|
||||
with self.positionsLock:
|
||||
if key in self.positions:
|
||||
|
|
@ -126,7 +131,7 @@ class Map(object):
|
|||
# TODO broadcast removal to clients
|
||||
|
||||
def removeOldPositions(self):
|
||||
now = datetime.now()
|
||||
now = datetime.now(timezone.utc)
|
||||
|
||||
with self.positionsLock:
|
||||
to_be_removed = [
|
||||
|
|
|
|||
Loading…
Reference in a new issue