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.map import Map, LatLngLocation
|
||||||
from owrx.bands import Bandplan
|
from owrx.bands import Bandplan
|
||||||
from owrx.metrics import Metrics, CounterMetric
|
from owrx.metrics import Metrics, CounterMetric
|
||||||
|
from owrx.parser import Parser
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
@ -148,18 +149,15 @@ class AprsLocation(LatLngLocation):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
class AprsParser(object):
|
class AprsParser(Parser):
|
||||||
def __init__(self, handler):
|
def __init__(self, handler):
|
||||||
|
super().__init__(handler)
|
||||||
self.ax25parser = Ax25Parser()
|
self.ax25parser = Ax25Parser()
|
||||||
self.deframer = KissDeframer()
|
self.deframer = KissDeframer()
|
||||||
self.dial_freq = None
|
|
||||||
self.band = None
|
|
||||||
self.handler = handler
|
|
||||||
self.metric = self.getMetric()
|
self.metric = self.getMetric()
|
||||||
|
|
||||||
def setDialFrequency(self, freq):
|
def setDialFrequency(self, freq):
|
||||||
self.dial_freq = freq
|
super().setDialFrequency(freq)
|
||||||
self.band = Bandplan.getSharedInstance().findBand(freq)
|
|
||||||
self.metric = self.getMetric()
|
self.metric = self.getMetric()
|
||||||
|
|
||||||
def getMetric(self):
|
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.meta import MetaParser
|
||||||
from owrx.wsjt import WsjtParser
|
from owrx.wsjt import WsjtParser
|
||||||
from owrx.aprs import AprsParser
|
from owrx.aprs import AprsParser
|
||||||
|
from owrx.pocsag import PocsagParser
|
||||||
from owrx.source import SdrSource
|
from owrx.source import SdrSource
|
||||||
from csdr import csdr
|
from csdr import csdr
|
||||||
import threading
|
import threading
|
||||||
@ -15,9 +16,12 @@ class DspManager(csdr.output):
|
|||||||
def __init__(self, handler, sdrSource):
|
def __init__(self, handler, sdrSource):
|
||||||
self.handler = handler
|
self.handler = handler
|
||||||
self.sdrSource = sdrSource
|
self.sdrSource = sdrSource
|
||||||
self.metaParser = MetaParser(self.handler)
|
self.parsers = {
|
||||||
self.wsjtParser = WsjtParser(self.handler)
|
"meta": MetaParser(self.handler),
|
||||||
self.aprsParser = AprsParser(self.handler)
|
"wsjt_demod": WsjtParser(self.handler),
|
||||||
|
"packet_demod": AprsParser(self.handler),
|
||||||
|
"pocsag_demod": PocsagParser(self.handler),
|
||||||
|
}
|
||||||
|
|
||||||
self.localProps = (
|
self.localProps = (
|
||||||
self.sdrSource.getProps()
|
self.sdrSource.getProps()
|
||||||
@ -53,9 +57,8 @@ class DspManager(csdr.output):
|
|||||||
|
|
||||||
def set_dial_freq(key, value):
|
def set_dial_freq(key, value):
|
||||||
freq = self.localProps["center_freq"] + self.localProps["offset_freq"]
|
freq = self.localProps["center_freq"] + self.localProps["offset_freq"]
|
||||||
self.wsjtParser.setDialFrequency(freq)
|
for parser in self.parsers.values():
|
||||||
self.aprsParser.setDialFrequency(freq)
|
parser.setDialFrequency(freq)
|
||||||
self.metaParser.setDialFrequency(freq)
|
|
||||||
|
|
||||||
self.subscriptions = [
|
self.subscriptions = [
|
||||||
self.localProps.getProperty("audio_compression").wire(self.dsp.set_audio_compression),
|
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,
|
"smeter": self.handler.write_s_meter_level,
|
||||||
"secondary_fft": self.handler.write_secondary_fft,
|
"secondary_fft": self.handler.write_secondary_fft,
|
||||||
"secondary_demod": self.handler.write_secondary_demod,
|
"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]
|
write = writers[t]
|
||||||
|
|
||||||
threading.Thread(target=self.pump(read_fn, write)).start()
|
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
|
import threading
|
||||||
from owrx.map import Map, LatLngLocation
|
from owrx.map import Map, LatLngLocation
|
||||||
from owrx.bands import Bandplan
|
from owrx.bands import Bandplan
|
||||||
|
from owrx.parser import Parser
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -83,17 +84,10 @@ class YsfMetaEnricher(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class MetaParser(object):
|
class MetaParser(Parser):
|
||||||
def __init__(self, handler):
|
def __init__(self, handler):
|
||||||
self.handler = handler
|
super().__init__(handler)
|
||||||
self.enrichers = {"DMR": DmrMetaEnricher(), "YSF": YsfMetaEnricher(self)}
|
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):
|
def parse(self, meta):
|
||||||
fields = meta.split(";")
|
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.bands import Bandplan
|
||||||
from owrx.metrics import Metrics, CounterMetric, DirectMetric
|
from owrx.metrics import Metrics, CounterMetric, DirectMetric
|
||||||
from owrx.pskreporter import PskReporter
|
from owrx.pskreporter import PskReporter
|
||||||
|
from owrx.parser import Parser
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -258,12 +259,7 @@ class Ft4Chopper(WsjtChopper):
|
|||||||
return ["jt9", "--ft4", "-d", str(self.decoding_depth("ft4")), file]
|
return ["jt9", "--ft4", "-d", str(self.decoding_depth("ft4")), file]
|
||||||
|
|
||||||
|
|
||||||
class WsjtParser(object):
|
class WsjtParser(Parser):
|
||||||
def __init__(self, handler):
|
|
||||||
self.handler = handler
|
|
||||||
self.dial_freq = None
|
|
||||||
self.band = None
|
|
||||||
|
|
||||||
modes = {"~": "FT8", "#": "JT65", "@": "JT9", "+": "FT4"}
|
modes = {"~": "FT8", "#": "JT65", "@": "JT9", "+": "FT4"}
|
||||||
|
|
||||||
def parse(self, data):
|
def parse(self, data):
|
||||||
@ -312,10 +308,6 @@ class WsjtParser(object):
|
|||||||
|
|
||||||
metric.inc()
|
metric.inc()
|
||||||
|
|
||||||
def setDialFrequency(self, freq):
|
|
||||||
self.dial_freq = freq
|
|
||||||
self.band = Bandplan.getSharedInstance().findBand(freq)
|
|
||||||
|
|
||||||
|
|
||||||
class Decoder(object):
|
class Decoder(object):
|
||||||
def parse_timestamp(self, instring, dateformat):
|
def parse_timestamp(self, instring, dateformat):
|
||||||
|
Loading…
Reference in New Issue
Block a user