refactor parsers; introduce new pocsag parser
This commit is contained in:
parent
0f8c86a26c
commit
0e528c9267
10
owrx/aprs.py
10
owrx/aprs.py
@ -2,6 +2,7 @@ from owrx.kiss import KissDeframer
|
||||
from owrx.map import Map, LatLngLocation
|
||||
from owrx.bands import Bandplan
|
||||
from owrx.metrics import Metrics, CounterMetric
|
||||
from owrx.parser import Parser
|
||||
from datetime import datetime, timezone
|
||||
import re
|
||||
import logging
|
||||
@ -148,18 +149,15 @@ class AprsLocation(LatLngLocation):
|
||||
return res
|
||||
|
||||
|
||||
class AprsParser(object):
|
||||
class AprsParser(Parser):
|
||||
def __init__(self, handler):
|
||||
super().__init__(handler)
|
||||
self.ax25parser = Ax25Parser()
|
||||
self.deframer = KissDeframer()
|
||||
self.dial_freq = None
|
||||
self.band = None
|
||||
self.handler = handler
|
||||
self.metric = self.getMetric()
|
||||
|
||||
def setDialFrequency(self, freq):
|
||||
self.dial_freq = freq
|
||||
self.band = Bandplan.getSharedInstance().findBand(freq)
|
||||
super().setDialFrequency(freq)
|
||||
self.metric = self.getMetric()
|
||||
|
||||
def getMetric(self):
|
||||
|
21
owrx/dsp.py
21
owrx/dsp.py
@ -2,6 +2,7 @@ from owrx.config import PropertyManager
|
||||
from owrx.meta import MetaParser
|
||||
from owrx.wsjt import WsjtParser
|
||||
from owrx.aprs import AprsParser
|
||||
from owrx.pocsag import PocsagParser
|
||||
from owrx.source import SdrSource
|
||||
from csdr import csdr
|
||||
import threading
|
||||
@ -15,9 +16,12 @@ class DspManager(csdr.output):
|
||||
def __init__(self, handler, sdrSource):
|
||||
self.handler = handler
|
||||
self.sdrSource = sdrSource
|
||||
self.metaParser = MetaParser(self.handler)
|
||||
self.wsjtParser = WsjtParser(self.handler)
|
||||
self.aprsParser = AprsParser(self.handler)
|
||||
self.parsers = {
|
||||
"meta": MetaParser(self.handler),
|
||||
"wsjt_demod": WsjtParser(self.handler),
|
||||
"packet_demod": AprsParser(self.handler),
|
||||
"pocsag_demod": PocsagParser(self.handler),
|
||||
}
|
||||
|
||||
self.localProps = (
|
||||
self.sdrSource.getProps()
|
||||
@ -53,9 +57,8 @@ class DspManager(csdr.output):
|
||||
|
||||
def set_dial_freq(key, value):
|
||||
freq = self.localProps["center_freq"] + self.localProps["offset_freq"]
|
||||
self.wsjtParser.setDialFrequency(freq)
|
||||
self.aprsParser.setDialFrequency(freq)
|
||||
self.metaParser.setDialFrequency(freq)
|
||||
for parser in self.parsers.values():
|
||||
parser.setDialFrequency(freq)
|
||||
|
||||
self.subscriptions = [
|
||||
self.localProps.getProperty("audio_compression").wire(self.dsp.set_audio_compression),
|
||||
@ -115,10 +118,10 @@ class DspManager(csdr.output):
|
||||
"smeter": self.handler.write_s_meter_level,
|
||||
"secondary_fft": self.handler.write_secondary_fft,
|
||||
"secondary_demod": self.handler.write_secondary_demod,
|
||||
"meta": self.metaParser.parse,
|
||||
"wsjt_demod": self.wsjtParser.parse,
|
||||
"packet_demod": self.aprsParser.parse,
|
||||
}
|
||||
for demod, parser in self.parsers.items():
|
||||
writers[demod] = parser.parse
|
||||
|
||||
write = writers[t]
|
||||
|
||||
threading.Thread(target=self.pump(read_fn, write)).start()
|
||||
|
12
owrx/meta.py
12
owrx/meta.py
@ -6,6 +6,7 @@ import logging
|
||||
import threading
|
||||
from owrx.map import Map, LatLngLocation
|
||||
from owrx.bands import Bandplan
|
||||
from owrx.parser import Parser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -83,17 +84,10 @@ class YsfMetaEnricher(object):
|
||||
return None
|
||||
|
||||
|
||||
class MetaParser(object):
|
||||
class MetaParser(Parser):
|
||||
def __init__(self, handler):
|
||||
self.handler = handler
|
||||
super().__init__(handler)
|
||||
self.enrichers = {"DMR": DmrMetaEnricher(), "YSF": YsfMetaEnricher(self)}
|
||||
self.band = None
|
||||
|
||||
def setDialFrequency(self, freq):
|
||||
self.band = Bandplan.getSharedInstance().findBand(freq)
|
||||
|
||||
def getBand(self):
|
||||
return self.band
|
||||
|
||||
def parse(self, meta):
|
||||
fields = meta.split(";")
|
||||
|
20
owrx/parser.py
Normal file
20
owrx/parser.py
Normal file
@ -0,0 +1,20 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from owrx.bands import Bandplan
|
||||
|
||||
|
||||
class Parser(ABC):
|
||||
def __init__(self, handler):
|
||||
self.handler = handler
|
||||
self.dial_freq = None
|
||||
self.band = None
|
||||
|
||||
@abstractmethod
|
||||
def parse(self, raw):
|
||||
pass
|
||||
|
||||
def setDialFrequency(self, freq):
|
||||
self.dial_freq = freq
|
||||
self.band = Bandplan.getSharedInstance().findBand(freq)
|
||||
|
||||
def getBand(self):
|
||||
return self.band
|
8
owrx/pocsag.py
Normal file
8
owrx/pocsag.py
Normal file
@ -0,0 +1,8 @@
|
||||
from owrx.parser import Parser
|
||||
|
||||
|
||||
class PocsagParser(Parser):
|
||||
def parse(self, raw):
|
||||
fields = raw.decode("ascii", "replace").rstrip("\n").split(";")
|
||||
meta = {v[0]: "".join(v[1:]) for v in map(lambda x: x.split(":"), fields) if v[0] != ""}
|
||||
self.handler.write_pocsag_data(meta)
|
12
owrx/wsjt.py
12
owrx/wsjt.py
@ -11,6 +11,7 @@ from owrx.config import PropertyManager
|
||||
from owrx.bands import Bandplan
|
||||
from owrx.metrics import Metrics, CounterMetric, DirectMetric
|
||||
from owrx.pskreporter import PskReporter
|
||||
from owrx.parser import Parser
|
||||
|
||||
import logging
|
||||
|
||||
@ -258,12 +259,7 @@ class Ft4Chopper(WsjtChopper):
|
||||
return ["jt9", "--ft4", "-d", str(self.decoding_depth("ft4")), file]
|
||||
|
||||
|
||||
class WsjtParser(object):
|
||||
def __init__(self, handler):
|
||||
self.handler = handler
|
||||
self.dial_freq = None
|
||||
self.band = None
|
||||
|
||||
class WsjtParser(Parser):
|
||||
modes = {"~": "FT8", "#": "JT65", "@": "JT9", "+": "FT4"}
|
||||
|
||||
def parse(self, data):
|
||||
@ -312,10 +308,6 @@ class WsjtParser(object):
|
||||
|
||||
metric.inc()
|
||||
|
||||
def setDialFrequency(self, freq):
|
||||
self.dial_freq = freq
|
||||
self.band = Bandplan.getSharedInstance().findBand(freq)
|
||||
|
||||
|
||||
class Decoder(object):
|
||||
def parse_timestamp(self, instring, dateformat):
|
||||
|
Loading…
Reference in New Issue
Block a user