2020-04-26 13:17:03 +00:00
|
|
|
from owrx.feature import FeatureDetector
|
2021-04-11 16:46:21 +00:00
|
|
|
from owrx.audio import ProfileSource
|
2020-04-26 13:17:03 +00:00
|
|
|
from functools import reduce
|
2021-04-09 16:16:25 +00:00
|
|
|
from abc import ABCMeta, abstractmethod
|
2020-04-26 13:17:03 +00:00
|
|
|
|
|
|
|
|
2020-04-26 16:45:41 +00:00
|
|
|
class Bandpass(object):
|
|
|
|
def __init__(self, low_cut, high_cut):
|
|
|
|
self.low_cut = low_cut
|
|
|
|
self.high_cut = high_cut
|
|
|
|
|
|
|
|
|
2021-08-31 19:53:15 +00:00
|
|
|
class Mode:
|
|
|
|
def __init__(self, modulation: str, name: str, bandpass: Bandpass = None, requirements=None, service=False, squelch=True):
|
2020-04-26 13:17:03 +00:00
|
|
|
self.modulation = modulation
|
|
|
|
self.name = name
|
|
|
|
self.requirements = requirements if requirements is not None else []
|
|
|
|
self.service = service
|
2020-04-26 16:45:41 +00:00
|
|
|
self.bandpass = bandpass
|
2020-05-03 17:55:48 +00:00
|
|
|
self.squelch = squelch
|
2020-04-26 13:17:03 +00:00
|
|
|
|
|
|
|
def is_available(self):
|
|
|
|
fd = FeatureDetector()
|
2020-05-03 17:55:48 +00:00
|
|
|
return reduce(lambda a, b: a and b, [fd.is_available(r) for r in self.requirements], True)
|
2020-04-26 13:17:03 +00:00
|
|
|
|
|
|
|
def is_service(self):
|
|
|
|
return self.service
|
|
|
|
|
2020-12-05 23:36:20 +00:00
|
|
|
def get_bandpass(self):
|
|
|
|
return self.bandpass
|
|
|
|
|
|
|
|
def get_modulation(self):
|
|
|
|
return self.modulation
|
|
|
|
|
2020-04-26 13:17:03 +00:00
|
|
|
|
2020-04-26 16:45:41 +00:00
|
|
|
class AnalogMode(Mode):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class DigitalMode(Mode):
|
2020-05-03 17:55:48 +00:00
|
|
|
def __init__(
|
|
|
|
self, modulation, name, underlying, bandpass: Bandpass = None, requirements=None, service=False, squelch=True
|
|
|
|
):
|
|
|
|
super().__init__(modulation, name, bandpass, requirements, service, squelch)
|
2020-04-26 16:45:41 +00:00
|
|
|
self.underlying = underlying
|
|
|
|
|
2021-08-31 19:53:15 +00:00
|
|
|
def get_underlying_mode(self):
|
|
|
|
return Modes.findByModulation(self.underlying[0])
|
|
|
|
|
2020-12-05 23:36:20 +00:00
|
|
|
def get_bandpass(self):
|
|
|
|
if self.bandpass is not None:
|
|
|
|
return self.bandpass
|
2021-08-31 19:53:15 +00:00
|
|
|
return self.get_underlying_mode().get_bandpass()
|
2020-12-05 23:36:20 +00:00
|
|
|
|
|
|
|
def get_modulation(self):
|
2021-08-31 19:53:15 +00:00
|
|
|
return self.get_underlying_mode().get_modulation()
|
2020-12-05 23:36:20 +00:00
|
|
|
|
2020-04-26 16:45:41 +00:00
|
|
|
|
2021-04-09 16:16:25 +00:00
|
|
|
class AudioChopperMode(DigitalMode, metaclass=ABCMeta):
|
2021-02-15 21:14:56 +00:00
|
|
|
def __init__(self, modulation, name, bandpass=None, requirements=None):
|
|
|
|
if bandpass is None:
|
|
|
|
bandpass = Bandpass(0, 3000)
|
2021-04-09 16:16:25 +00:00
|
|
|
super().__init__(modulation, name, ["usb"], bandpass=bandpass, requirements=requirements, service=True)
|
|
|
|
|
|
|
|
@abstractmethod
|
2021-04-11 16:46:21 +00:00
|
|
|
def get_profile_source(self) -> ProfileSource:
|
2021-04-09 16:16:25 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class WsjtMode(AudioChopperMode):
|
|
|
|
def __init__(self, modulation, name, bandpass=None, requirements=None):
|
2021-02-15 21:14:56 +00:00
|
|
|
if requirements is None:
|
|
|
|
requirements = ["wsjt-x"]
|
2021-04-09 16:16:25 +00:00
|
|
|
super().__init__(modulation, name, bandpass=bandpass, requirements=requirements)
|
|
|
|
|
2021-04-11 16:46:21 +00:00
|
|
|
def get_profile_source(self) -> ProfileSource:
|
2021-04-09 16:16:25 +00:00
|
|
|
# inline import due to circular dependencies
|
2021-04-11 16:46:21 +00:00
|
|
|
from owrx.wsjt import WsjtProfiles
|
|
|
|
return WsjtProfiles.getSource(self.modulation)
|
2021-04-09 16:16:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Js8Mode(AudioChopperMode):
|
|
|
|
def __init__(self, modulation, name, bandpass=None, requirements=None):
|
|
|
|
if requirements is None:
|
|
|
|
requirements = ["js8call"]
|
|
|
|
super().__init__(modulation, name, bandpass, requirements)
|
|
|
|
|
2021-04-11 16:46:21 +00:00
|
|
|
def get_profile_source(self) -> ProfileSource:
|
2021-04-09 16:16:25 +00:00
|
|
|
# inline import due to circular dependencies
|
2021-04-11 16:46:21 +00:00
|
|
|
from owrx.js8 import Js8ProfileSource
|
|
|
|
return Js8ProfileSource()
|
2021-02-15 21:14:56 +00:00
|
|
|
|
|
|
|
|
2020-04-26 13:17:03 +00:00
|
|
|
class Modes(object):
|
|
|
|
mappings = [
|
2020-04-26 16:45:41 +00:00
|
|
|
AnalogMode("nfm", "FM", bandpass=Bandpass(-4000, 4000)),
|
2021-01-14 22:47:12 +00:00
|
|
|
AnalogMode("wfm", "WFM", bandpass=Bandpass(-75000, 75000)),
|
2020-04-26 16:45:41 +00:00
|
|
|
AnalogMode("am", "AM", bandpass=Bandpass(-4000, 4000)),
|
|
|
|
AnalogMode("lsb", "LSB", bandpass=Bandpass(-3000, -300)),
|
|
|
|
AnalogMode("usb", "USB", bandpass=Bandpass(300, 3000)),
|
|
|
|
AnalogMode("cw", "CW", bandpass=Bandpass(700, 900)),
|
2020-05-03 17:55:48 +00:00
|
|
|
AnalogMode("dmr", "DMR", bandpass=Bandpass(-4000, 4000), requirements=["digital_voice_digiham"], squelch=False),
|
2021-01-20 16:01:46 +00:00
|
|
|
AnalogMode(
|
2021-06-08 21:01:49 +00:00
|
|
|
"dstar", "D-Star", bandpass=Bandpass(-3250, 3250), requirements=["digital_voice_digiham"], squelch=False
|
2021-01-20 16:01:46 +00:00
|
|
|
),
|
2021-06-17 12:13:17 +00:00
|
|
|
AnalogMode("nxdn", "NXDN", bandpass=Bandpass(-3250, 3250), requirements=["digital_voice_digiham"], squelch=False),
|
2020-05-03 17:55:48 +00:00
|
|
|
AnalogMode("ysf", "YSF", bandpass=Bandpass(-4000, 4000), requirements=["digital_voice_digiham"], squelch=False),
|
2020-11-23 00:00:25 +00:00
|
|
|
AnalogMode("m17", "M17", bandpass=Bandpass(-4000, 4000), requirements=["digital_voice_m17"], squelch=False),
|
2021-01-20 16:01:46 +00:00
|
|
|
AnalogMode(
|
|
|
|
"freedv", "FreeDV", bandpass=Bandpass(300, 3000), requirements=["digital_voice_freedv"], squelch=False
|
|
|
|
),
|
2020-09-04 16:09:02 +00:00
|
|
|
AnalogMode("drm", "DRM", bandpass=Bandpass(-5000, 5000), requirements=["drm"], squelch=False),
|
2020-04-26 16:45:41 +00:00
|
|
|
DigitalMode("bpsk31", "BPSK31", underlying=["usb"]),
|
|
|
|
DigitalMode("bpsk63", "BPSK63", underlying=["usb"]),
|
2021-02-15 21:14:56 +00:00
|
|
|
WsjtMode("ft8", "FT8"),
|
|
|
|
WsjtMode("ft4", "FT4"),
|
|
|
|
WsjtMode("jt65", "JT65"),
|
|
|
|
WsjtMode("jt9", "JT9"),
|
|
|
|
WsjtMode("wspr", "WSPR", bandpass=Bandpass(1350, 1650)),
|
|
|
|
WsjtMode("fst4", "FST4", requirements=["wsjt-x-2-3"]),
|
|
|
|
WsjtMode("fst4w", "FST4W", bandpass=Bandpass(1350, 1650), requirements=["wsjt-x-2-3"]),
|
|
|
|
WsjtMode("q65", "Q65", requirements=["wsjt-x-2-4"]),
|
2021-04-09 16:16:25 +00:00
|
|
|
Js8Mode("js8", "JS8Call"),
|
2020-05-03 17:55:48 +00:00
|
|
|
DigitalMode(
|
2020-11-30 16:13:03 +00:00
|
|
|
"packet",
|
|
|
|
"Packet",
|
|
|
|
underlying=["nfm", "usb", "lsb"],
|
|
|
|
bandpass=Bandpass(-6250, 6250),
|
|
|
|
requirements=["packet"],
|
|
|
|
service=True,
|
|
|
|
squelch=False,
|
2020-05-03 17:55:48 +00:00
|
|
|
),
|
|
|
|
DigitalMode(
|
|
|
|
"pocsag",
|
|
|
|
"Pocsag",
|
|
|
|
underlying=["nfm"],
|
|
|
|
bandpass=Bandpass(-6000, 6000),
|
|
|
|
requirements=["pocsag"],
|
|
|
|
squelch=False,
|
|
|
|
),
|
2020-04-26 13:17:03 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def getModes():
|
|
|
|
return Modes.mappings
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def getAvailableModes():
|
|
|
|
return [m for m in Modes.getModes() if m.is_available()]
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def getAvailableServices():
|
|
|
|
return [m for m in Modes.getAvailableModes() if m.is_service()]
|
2020-04-26 20:46:30 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def findByModulation(modulation):
|
|
|
|
modes = [m for m in Modes.getAvailableModes() if m.modulation == modulation]
|
|
|
|
if modes:
|
2020-05-03 17:55:48 +00:00
|
|
|
return modes[0]
|