diff --git a/htdocs/lib/MetaPanel.js b/htdocs/lib/MetaPanel.js index 2c0f0c9..0a3a334 100644 --- a/htdocs/lib/MetaPanel.js +++ b/htdocs/lib/MetaPanel.js @@ -180,6 +180,7 @@ DStarMetaPanel.prototype.update = function(data) { this.setDeparture(data['departure']); this.setDestination(data['destination']); this.setMessage(data['message']); + this.setLocation(data['lat'], data['lon'], data['ourcall']); } else { this.clear(); } @@ -188,7 +189,7 @@ DStarMetaPanel.prototype.update = function(data) { DStarMetaPanel.prototype.setOurCall = function(ourcall) { if (this.ourcall === ourcall) return; this.ourcall = ourcall; - this.el.find('.openwebrx-dstar-ourcall').text(ourcall || ''); + this.el.find('.openwebrx-dstar-ourcall .callsign').text(ourcall || ''); }; DStarMetaPanel.prototype.setYourCall = function(yourcall) { @@ -222,6 +223,18 @@ DStarMetaPanel.prototype.clear = function() { this.setDeparture(); this.setDestination(); this.setMessage(); + this.setLocation(); +}; + +DStarMetaPanel.prototype.setLocation = function(lat, lon, callsign) { + var hasLocation = lat && lon && callsign && callsign != ''; + if (hasLocation === this.hasLocation && this.callsign === callsign) return; + this.hasLocation = hasLocation; this.callsign = callsign; + var html = ''; + if (hasLocation) { + html = ''; + } + this.el.find('.openwebrx-dstar-source .location').html(html); }; MetaPanel.types = { diff --git a/owrx/meta.py b/owrx/meta.py index f246d15..90808c2 100644 --- a/owrx/meta.py +++ b/owrx/meta.py @@ -6,10 +6,21 @@ import logging import threading from owrx.map import Map, LatLngLocation from owrx.parser import Parser +from owrx.aprs import AprsParser, AprsLocation +from abc import ABC, abstractmethod logger = logging.getLogger(__name__) +class Enricher(ABC): + def __init__(self, parser): + self.parser = parser + + @abstractmethod + def enrich(self, meta): + pass + + class DmrCache(object): sharedInstance = None @@ -38,8 +49,9 @@ class DmrCache(object): return self.cache[key]["data"] -class DmrMetaEnricher(object): - def __init__(self): +class DmrMetaEnricher(Enricher): + def __init__(self, parser): + super().__init__(parser) self.threads = {} def downloadRadioIdData(self, id): @@ -71,10 +83,7 @@ class DmrMetaEnricher(object): return meta -class YsfMetaEnricher(object): - def __init__(self, parser): - self.parser = parser - +class YsfMetaEnricher(Enricher): def enrich(self, meta): for key in ["source", "up", "down", "target"]: if key in meta: @@ -89,10 +98,34 @@ class YsfMetaEnricher(object): return meta +class DStarEnricher(Enricher): + def enrich(self, meta): + if "dpmr" in meta: + # we can send the DPMR stuff through our APRS parser to extract the information + # TODO: only thrid-party parsing accepts this format right now + # TODO: we also need to pass a handler, which is not needed + parser = AprsParser(None) + dprsData = parser.parseThirdpartyAprsData(meta["dpmr"]) + logger.debug("decoded APRS data: %s", dprsData) + if "data" in dprsData: + data = dprsData["data"] + if "lat" in data and "lon" in data: + # TODO: we could actually get the symbols from the parsed APRS data and show that + meta["lat"] = data["lat"] + meta["lon"] = data["lon"] + + if "ourcall" in meta: + # send location info to map as well + loc = AprsLocation(data) + Map.getSharedInstance().updateLocation(meta["ourcall"], loc, "APRS", self.parser.getBand()) + + return meta + + class MetaParser(Parser): def __init__(self, handler): super().__init__(handler) - self.enrichers = {"DMR": DmrMetaEnricher(), "YSF": YsfMetaEnricher(self)} + self.enrichers = {"DMR": DmrMetaEnricher(self), "YSF": YsfMetaEnricher(self), "DSTAR": DStarEnricher(self)} def parse(self, meta): fields = meta.split(";")