Downgrading Direwolf code to a previous, pre-ExecModule version.
This commit is contained in:
parent
7f2b59fcef
commit
48ad02b95a
|
|
@ -1,9 +1,11 @@
|
||||||
|
from csdr.module import AutoStartModule
|
||||||
from pycsdr.types import Format
|
from pycsdr.types import Format
|
||||||
from pycsdr.modules import Writer, TcpSource, ExecModule, CallbackWriter
|
from pycsdr.modules import Writer, TcpSource
|
||||||
from csdr.module import LogWriter
|
from subprocess import Popen, PIPE
|
||||||
from owrx.config.core import CoreConfig
|
from owrx.config.core import CoreConfig
|
||||||
from owrx.config import Config
|
from owrx.config import Config
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
|
@ -144,44 +146,50 @@ IGLOGIN {callsign} {password}
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
class DirewolfModule(ExecModule, DirewolfConfigSubscriber):
|
class DirewolfModule(AutoStartModule, DirewolfConfigSubscriber):
|
||||||
def __init__(self, service: bool = False, ais: bool = False):
|
def __init__(self, service: bool = False, ais: bool = False):
|
||||||
|
self.process = None
|
||||||
self.tcpSource = None
|
self.tcpSource = None
|
||||||
self.writer = None
|
|
||||||
self.service = service
|
self.service = service
|
||||||
self.ais = ais
|
self.ais = ais
|
||||||
self.direwolfConfigPath = "{tmp_dir}/openwebrx_direwolf_{myid}.conf".format(
|
self.direwolfConfigPath = "{tmp_dir}/openwebrx_direwolf_{myid}.conf".format(
|
||||||
tmp_dir=CoreConfig().get_temporary_directory(), myid=id(self)
|
tmp_dir=CoreConfig().get_temporary_directory(), myid=id(self)
|
||||||
)
|
)
|
||||||
|
self.direwolfConfig = None
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
def setWriter(self, writer: Writer) -> None:
|
||||||
|
super().setWriter(writer)
|
||||||
|
if self.tcpSource is not None:
|
||||||
|
self.tcpSource.setWriter(writer)
|
||||||
|
|
||||||
|
def getInputFormat(self) -> Format:
|
||||||
|
return Format.SHORT
|
||||||
|
|
||||||
|
def getOutputFormat(self) -> Format:
|
||||||
|
return Format.CHAR
|
||||||
|
|
||||||
|
def start(self):
|
||||||
self.direwolfConfig = DirewolfConfig()
|
self.direwolfConfig = DirewolfConfig()
|
||||||
self.direwolfConfig.wire(self)
|
self.direwolfConfig.wire(self)
|
||||||
self.__writeConfig()
|
file = open(self.direwolfConfigPath, "w")
|
||||||
|
file.write(self.direwolfConfig.getConfig(self.service))
|
||||||
|
file.close()
|
||||||
|
|
||||||
# compose command line
|
# direwolf -c {direwolf_config} -r {audio_rate} -t 0 -q d -q h 1>&2
|
||||||
cmdLine = ["direwolf", "-c", self.direwolfConfigPath, "-r", "48000", "-t", "0", "-q", "d", "-q", "h"]
|
cmdLine = ["direwolf", "-c", self.direwolfConfigPath, "-r", "48000", "-t", "0", "-q", "d", "-q", "h"]
|
||||||
|
|
||||||
# for AIS mode, add -B AIS -A
|
# for AIS mode, add -B AIS -A
|
||||||
if self.ais:
|
if self.ais:
|
||||||
cmdLine += ["-B", "AIS", "-A"]
|
cmdLine += ["-B", "AIS", "-A"]
|
||||||
|
|
||||||
super().__init__(Format.SHORT, Format.CHAR, cmdLine)
|
# launch Direwolf
|
||||||
# direwolf supplies the data via a socket which we tap into in start()
|
self.process = Popen(cmdLine, start_new_session=True, stdin=PIPE)
|
||||||
# the output on its STDOUT is informative, but we still want to log it
|
|
||||||
super().setWriter(LogWriter(__name__))
|
|
||||||
self.start()
|
|
||||||
|
|
||||||
def __writeConfig(self):
|
# resume in case the reader has been stop()ed before
|
||||||
file = open(self.direwolfConfigPath, "w")
|
self.reader.resume()
|
||||||
file.write(self.direwolfConfig.getConfig(self.service))
|
threading.Thread(target=self.pump(self.reader.read, self.process.stdin.write)).start()
|
||||||
file.close()
|
|
||||||
|
|
||||||
def setWriter(self, writer: Writer) -> None:
|
|
||||||
self.writer = writer
|
|
||||||
if self.tcpSource is not None:
|
|
||||||
self.tcpSource.setWriter(writer)
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
delay = 0.5
|
delay = 0.5
|
||||||
retries = 0
|
retries = 0
|
||||||
while True:
|
while True:
|
||||||
|
|
@ -197,16 +205,17 @@ class DirewolfModule(ExecModule, DirewolfConfigSubscriber):
|
||||||
retries += 1
|
retries += 1
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
|
|
||||||
def restart(self):
|
def stop(self):
|
||||||
self.__writeConfig()
|
if self.process is not None:
|
||||||
super().restart()
|
self.process.terminate()
|
||||||
self.start()
|
self.process.wait()
|
||||||
|
self.process = None
|
||||||
def onConfigChanged(self):
|
|
||||||
self.restart()
|
|
||||||
|
|
||||||
def stop(self) -> None:
|
|
||||||
super().stop()
|
|
||||||
os.unlink(self.direwolfConfigPath)
|
os.unlink(self.direwolfConfigPath)
|
||||||
self.direwolfConfig.unwire(self)
|
self.direwolfConfig.unwire(self)
|
||||||
self.direwolfConfig = None
|
self.direwolfConfig = None
|
||||||
|
self.reader.stop()
|
||||||
|
|
||||||
|
def onConfigChanged(self):
|
||||||
|
self.stop()
|
||||||
|
self.start()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue