refactor the metaparser into a modules and use accordingly

This commit is contained in:
Jakob Ketterl 2021-09-09 15:11:33 +02:00
parent ca0f7af1d0
commit 66cf940523
4 changed files with 68 additions and 21 deletions

View File

@ -1,11 +1,12 @@
from csdr.chain.demodulator import BaseDemodulatorChain, FixedAudioRateChain, FixedIfSampleRateChain from csdr.chain.demodulator import BaseDemodulatorChain, FixedAudioRateChain, FixedIfSampleRateChain, DialFrequencyReceiver
from pycsdr.modules import FmDemod, Agc, Writer from pycsdr.modules import FmDemod, Agc, Writer, Buffer
from pycsdr.types import Format from pycsdr.types import Format
from digiham.modules import DstarDecoder, DcBlock, FskDemodulator, GfskDemodulator, DigitalVoiceFilter, MbeSynthesizer, NarrowRrcFilter, NxdnDecoder, DmrDecoder, WideRrcFilter, YsfDecoder from digiham.modules import DstarDecoder, DcBlock, FskDemodulator, GfskDemodulator, DigitalVoiceFilter, MbeSynthesizer, NarrowRrcFilter, NxdnDecoder, DmrDecoder, WideRrcFilter, YsfDecoder
from digiham.ambe import Modes from digiham.ambe import Modes
from owrx.meta import MetaParser
class DigihamChain(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain): class DigihamChain(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain, DialFrequencyReceiver):
def __init__(self, fskDemodulator, decoder, mbeMode, filter=None, codecserver: str = ""): def __init__(self, fskDemodulator, decoder, mbeMode, filter=None, codecserver: str = ""):
self.decoder = decoder self.decoder = decoder
if codecserver is None: if codecserver is None:
@ -23,6 +24,7 @@ class DigihamChain(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateC
DigitalVoiceFilter(), DigitalVoiceFilter(),
agc agc
] ]
self.metaParser = None
super().__init__(workers) super().__init__(workers)
def getFixedIfSampleRate(self): def getFixedIfSampleRate(self):
@ -32,11 +34,26 @@ class DigihamChain(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateC
return 8000 return 8000
def setMetaWriter(self, writer: Writer): def setMetaWriter(self, writer: Writer):
self.decoder.setMetaWriter(writer) if self.metaParser is None:
self.metaParser = MetaParser()
buffer = Buffer(Format.CHAR)
self.decoder.setMetaWriter(buffer)
self.metaParser.setReader(buffer.getReader())
self.metaParser.setWriter(writer)
def supportsSquelch(self): def supportsSquelch(self):
return False return False
def setDialFrequency(self, frequency: int) -> None:
if self.metaParser is None:
return
self.metaParser.setDialFrequency(frequency)
def stop(self):
if self.metaParser is not None:
self.metaParser.stop()
super().stop()
class Dstar(DigihamChain): class Dstar(DigihamChain):
def __init__(self, codecserver: str = ""): def __init__(self, codecserver: str = ""):

View File

@ -420,7 +420,12 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
self.send({"type": "features", "value": features}) self.send({"type": "features", "value": features})
def write_metadata(self, metadata): def write_metadata(self, metadata):
self.send({"type": "metadata", "value": metadata}) io = BytesIO(metadata.tobytes())
try:
while True:
self.send({"type": "metadata", "value": pickle.load(io)})
except EOFError:
pass
def write_dial_frequencies(self, frequencies): def write_dial_frequencies(self, frequencies):
self.send({"type": "dial_frequencies", "value": frequencies}) self.send({"type": "dial_frequencies", "value": frequencies})

View File

@ -1,4 +1,3 @@
from owrx.meta import MetaParser
from owrx.wsjt import WsjtParser from owrx.wsjt import WsjtParser
from owrx.js8 import Js8Parser from owrx.js8 import Js8Parser
from owrx.source import SdrSourceEventClient, SdrSourceState, SdrClientClass from owrx.source import SdrSourceEventClient, SdrSourceState, SdrClientClass
@ -192,6 +191,8 @@ class ClientDemodulatorChain(Chain):
if self.centerFrequency is None or self.frequencyOffset is None: if self.centerFrequency is None or self.frequencyOffset is None:
return return
dialFrequency = self.centerFrequency + self.frequencyOffset dialFrequency = self.centerFrequency + self.frequencyOffset
if isinstance(self.demodulator, DialFrequencyReceiver):
self.demodulator.setDialFrequency(dialFrequency)
if isinstance(self.secondaryDemodulator, DialFrequencyReceiver): if isinstance(self.secondaryDemodulator, DialFrequencyReceiver):
self.secondaryDemodulator.setDialFrequency(dialFrequency) self.secondaryDemodulator.setDialFrequency(dialFrequency)
@ -286,9 +287,6 @@ class DspManager(Output, SdrSourceEventClient):
def __init__(self, handler, sdrSource): def __init__(self, handler, sdrSource):
self.handler = handler self.handler = handler
self.sdrSource = sdrSource self.sdrSource = sdrSource
self.parsers = {
"meta": MetaParser(self.handler),
}
self.props = PropertyStack() self.props = PropertyStack()
@ -527,9 +525,8 @@ class DspManager(Output, SdrSourceEventClient):
"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.handler.write_metadata,
} }
for demod, parser in self.parsers.items():
writers[demod] = parser.parse
write = writers[t] write = writers[t]

View File

@ -1,12 +1,18 @@
from owrx.config import Config
from urllib import request
import json import json
from datetime import datetime, timedelta
import logging import logging
import threading import threading
from owrx.map import Map, LatLngLocation import pickle
from owrx.aprs import AprsParser, AprsLocation
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from datetime import datetime, timedelta
from urllib import request
from pycsdr.types import Format
from csdr.module import ThreadModule
from owrx.aprs import AprsParser, AprsLocation
from owrx.config import Config
from owrx.map import Map, LatLngLocation
from owrx.bands import Bandplan
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -158,9 +164,8 @@ class DStarEnricher(Enricher):
return meta return meta
class MetaParser: class MetaParser(ThreadModule):
def __init__(self, handler): def __init__(self):
self.handler = handler
self.enrichers = { self.enrichers = {
"DMR": RadioIDEnricher("dmr", self), "DMR": RadioIDEnricher("dmr", self),
"YSF": YsfMetaEnricher(self), "YSF": YsfMetaEnricher(self),
@ -168,6 +173,23 @@ class MetaParser:
"NXDN": RadioIDEnricher("nxdn", self), "NXDN": RadioIDEnricher("nxdn", self),
} }
self.currentMetaData = None self.currentMetaData = None
self.band = None
super().__init__()
def getInputFormat(self) -> Format:
return Format.CHAR
def getOutputFormat(self) -> Format:
return Format.CHAR
def run(self):
while self.doRun:
data = self.reader.read()
if data is None:
self.doRun = False
else:
for result in self.parse(data):
self.writer.write(pickle.dumps(result))
def parse(self, raw: memoryview): def parse(self, raw: memoryview):
try: try:
@ -185,10 +207,16 @@ class MetaParser:
protocol = meta["protocol"] protocol = meta["protocol"]
if protocol in self.enrichers: if protocol in self.enrichers:
self.currentMetaData = meta = self.enrichers[protocol].enrich(meta, self.receive) self.currentMetaData = meta = self.enrichers[protocol].enrich(meta, self.receive)
self.handler.write_metadata(meta) yield meta
def receive(self, meta): def receive(self, meta):
# we may have moved on in the meantime # we may have moved on in the meantime
if meta is not self.currentMetaData: if meta is not self.currentMetaData:
return return
self.handler.write_metadata(meta) self.writer.write(pickle.dumps(meta))
def setDialFrequency(self, freq):
self.band = Bandplan.getSharedInstance().findBand(freq)
def getBand(self):
return self.band