openwebrx-clone/owrx/source/direct.py

55 lines
1.5 KiB
Python
Raw Permalink Normal View History

2019-12-27 23:26:45 +00:00
from abc import ABCMeta
from . import SdrSource
import logging
logger = logging.getLogger(__name__)
class DirectSource(SdrSource, metaclass=ABCMeta):
def onPropertyChange(self, name, value):
2019-12-28 00:24:07 +00:00
logger.debug(
"restarting sdr source due to property change: {0} changed to {1}".format(
name, value
)
)
2019-12-27 23:26:45 +00:00
self.stop()
self.sleepOnRestart()
self.start()
def getEventNames(self):
return super().getEventNames() + [
"nmux_memory",
]
def getNmuxCommand(self):
props = self.rtlProps
nmux_bufcnt = nmux_bufsize = 0
while nmux_bufsize < props["samp_rate"] / 4:
nmux_bufsize += 4096
while nmux_bufsize * nmux_bufcnt < props["nmux_memory"] * 1e6:
nmux_bufcnt += 1
if nmux_bufcnt == 0 or nmux_bufsize == 0:
raise ValueError(
"Error: nmux_bufsize or nmux_bufcnt is zero. "
"These depend on nmux_memory and samp_rate options in config_webrx.py"
)
2019-12-28 15:44:45 +00:00
return ["nmux --bufsize %d --bufcnt %d --port %d --address 127.0.0.1" % (
2019-12-27 23:26:45 +00:00
nmux_bufsize,
nmux_bufcnt,
self.port,
2019-12-28 15:44:45 +00:00
)]
2019-12-27 23:26:45 +00:00
def getCommand(self):
2019-12-28 15:44:45 +00:00
return super().getCommand() + self.getFormatConversion() + self.getNmuxCommand()
2019-12-27 23:26:45 +00:00
# override this in subclasses, if necessary
def getFormatConversion(self):
2019-12-28 15:44:45 +00:00
return []
2019-12-27 23:26:45 +00:00
# override this in subclasses, if necessary
def sleepOnRestart(self):
pass