parser typing

This commit is contained in:
Jakob Ketterl 2021-09-28 00:27:01 +02:00
parent 757ec01ea4
commit 25e2a8013e
4 changed files with 19 additions and 11 deletions

View File

@ -1,5 +1,5 @@
from csdr.chain.demodulator import ServiceDemodulator, SecondaryDemodulator, DialFrequencyReceiver, SecondarySelectorChain
from owrx.audio.chopper import AudioChopper
from owrx.audio.chopper import AudioChopper, AudioChopperParser
from owrx.aprs.kiss import KissDeframer
from owrx.aprs import Ax25Parser, AprsParser
from pycsdr.modules import Convert, FmDemod, Agc, TimingRecovery, DBPskDecoder, VaricodeDecoder
@ -10,8 +10,7 @@ from owrx.pocsag import PocsagParser
class AudioChopperDemodulator(ServiceDemodulator, DialFrequencyReceiver):
# TODO parser typing
def __init__(self, mode: str, parser):
def __init__(self, mode: str, parser: AudioChopperParser):
self.chopper = AudioChopper(mode, parser)
workers = [Convert(Format.FLOAT, Format.SHORT), self.chopper]
super().__init__(workers)

View File

@ -1,10 +1,12 @@
from owrx.modes import Modes, AudioChopperMode
from owrx.audio import AudioChopperProfile
from itertools import groupby
from owrx.audio import ProfileSourceSubscriber
from owrx.audio.wav import AudioWriter
from owrx.audio.queue import QueueJob
from csdr.module import ThreadModule
from pycsdr.types import Format
from abc import ABC, abstractmethod
import pickle
import logging
@ -13,9 +15,14 @@ logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
class AudioChopperParser(ABC):
@abstractmethod
def parse(self, profile: AudioChopperProfile, frequency: int, line: bytes):
pass
class AudioChopper(ThreadModule, ProfileSourceSubscriber):
# TODO parser typing
def __init__(self, mode_str: str, parser):
def __init__(self, mode_str: str, parser: AudioChopperParser):
self.parser = parser
self.dialFrequency = None
self.doRun = True

View File

@ -1,4 +1,5 @@
from owrx.audio import AudioChopperProfile, ConfigWiredProfileSource
from owrx.audio.chopper import AudioChopperParser
import re
from js8py import Js8
from js8py.frames import Js8FrameHeartbeat, Js8FrameCompound
@ -81,10 +82,10 @@ class Js8TurboProfile(Js8Profile):
return "C"
class Js8Parser:
class Js8Parser(AudioChopperParser):
decoderRegex = re.compile(" ?<Decode(Started|Debug|Finished)>")
def parse(self, profile, freq, raw_msg):
def parse(self, profile: AudioChopperProfile, freq: int, raw_msg: bytes):
try:
band = None
if freq is not None:

View File

@ -4,6 +4,7 @@ from owrx.map import Map, LocatorLocation
from owrx.metrics import Metrics, CounterMetric
from owrx.reporting import ReportingEngine
from owrx.audio import AudioChopperProfile, StaticProfileSource, ConfigWiredProfileSource
from owrx.audio.chopper import AudioChopperParser
from abc import ABC, ABCMeta, abstractmethod
from owrx.config import Config
from enum import Enum
@ -244,8 +245,8 @@ class Q65Profile(WsjtProfile):
return ["jt9", "--q65", "-p", str(self.interval), "-b", self.mode.name, "-d", str(self.decoding_depth()), file]
class WsjtParser:
def parse(self, profile, freq, raw_msg):
class WsjtParser(AudioChopperParser):
def parse(self, profile: WsjtProfile, freq: int, raw_msg: bytes):
try:
band = None
if freq is not None:
@ -310,9 +311,9 @@ class Decoder(ABC):
def parse_timestamp(self, instring):
dateformat = self.profile.getTimestampFormat()
remain = instring[len(dateformat) + 1 :]
remain = instring[len(dateformat) + 1:]
try:
ts = datetime.strptime(instring[0 : len(dateformat)], dateformat)
ts = datetime.strptime(instring[0: len(dateformat)], dateformat)
return remain, int(
datetime.combine(datetime.utcnow().date(), ts.time()).replace(tzinfo=timezone.utc).timestamp() * 1000
)