From b109ee5c45d84f9102b027a174e5261c699c94e7 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Fri, 25 Aug 2023 21:15:29 +0200 Subject: [PATCH] pass additional data to the map --- htdocs/map.js | 10 +++++++++- owrx/adsb/modes.py | 33 +++++++++++++++++++++++++++------ owrx/map.py | 9 +++++++++ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/htdocs/map.js b/htdocs/map.js index 41b77cf8..6f7a5bfb 100644 --- a/htdocs/map.js +++ b/htdocs/map.js @@ -114,6 +114,7 @@ $(function(){ switch (update.location.type) { case 'latlon': + if (!update.location.lat || !update.location.lon) break; var pos = new google.maps.LatLng(update.location.lat, update.location.lon); var marker; var markerClass = google.maps.Marker; @@ -125,6 +126,7 @@ $(function(){ aprsOptions.speed = update.location.speed; } else if (update.source.icao) { markerClass = PlaneMarker; + aprsOptions = update.location; } if (markers[key]) { marker = markers[key]; @@ -438,8 +440,14 @@ $(function(){ if (receiverMarker) { distance = " at " + distanceKm(receiverMarker.position, marker.position) + " km"; } + var title; + if (marker.icao) { + title = marker.identification || marker.icao; + } else { + linkifySource(source); + } infowindow.setContent( - '

' + linkifySource(source) + distance + '

' + + '

' + title + distance + '

' + '
' + timestring + ' using ' + marker.mode + ( marker.band ? ' on ' + marker.band : '' ) + '
' + commentString ); diff --git a/owrx/adsb/modes.py b/owrx/adsb/modes.py index 68bdf60f..3bc76fb6 100644 --- a/owrx/adsb/modes.py +++ b/owrx/adsb/modes.py @@ -1,6 +1,8 @@ +from abc import ABC + from csdr.module import PickleModule from math import sqrt, atan2, pi, floor, acos, cos -from owrx.map import LatLngLocation, Map +from owrx.map import LatLngLocation, IncrementalUpdate, Location, Map import time import logging @@ -15,9 +17,28 @@ d_lat_even = 360 / (4 * nz) d_lat_odd = 360 / (4 * nz - 1) -class AirplaneLocation(LatLngLocation): +class AirplaneLocation(LatLngLocation, IncrementalUpdate, ABC): def __init__(self, message): - super().__init__(message["lat"], message["lon"]) + self.props = message + if "lat" in message and "lon" in message: + super().__init__(message["lat"], message["lon"]) + else: + self.lat = None + self.lon = None + + def update(self, previousLocation: Location): + props = previousLocation.props + props.update(self.props) + self.props = props + if "lat" in props: + self.lat = props["lat"] + if "lon" in props: + self.lon = props["lon"] + + def __dict__(self): + dict = super().__dict__() + dict.update(self.props) + return dict class CprCache: @@ -54,7 +75,7 @@ class ModeSParser(PickleModule): message["capability"] = input[0] & 0b111 message["icao"] = icao = input[1:4].hex() type = (input[4] & 0b11111000) >> 3 - message["type"] = type + message["adsb_type"] = type if type in [1, 2, 3, 4]: # identification message @@ -181,9 +202,9 @@ class ModeSParser(PickleModule): # Mode-S All-call reply message["icao"] = input[1:4].hex() - if "icao" in message and "lat" in message and "lon" in message: + if "icao" in message and ['lat', 'lon', 'altitude', 'heading', 'groundtrack', 'identification'] & message.keys(): loc = AirplaneLocation(message) - Map.getSharedInstance().updateLocation({"icao": icao}, loc, "ADS-B", None) + Map.getSharedInstance().updateLocation({"icao": message['icao']}, loc, "ADS-B", None) return message diff --git a/owrx/map.py b/owrx/map.py index 30294bce..39d56693 100644 --- a/owrx/map.py +++ b/owrx/map.py @@ -1,6 +1,7 @@ from datetime import datetime, timedelta from owrx.config import Config from owrx.bands import Band +from abc import abstractmethod, ABCMeta import threading import time import sys @@ -88,6 +89,8 @@ class Map(object): ts = datetime.now() key = self._sourceToKey(source) 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.broadcast( [ @@ -148,3 +151,9 @@ class LocatorLocation(Location): def __dict__(self): return {"type": "locator", "locator": self.locator} + + +class IncrementalUpdate(Location, metaclass=ABCMeta): + @abstractmethod + def update(self, previousLocation: Location): + pass