//WIP V3
Default Radio Settings Update - One location for default radio settings GQRX Changes - Default settings - Simpler check to see if GQRX is started - Working process handler
This commit is contained in:
@@ -26,6 +26,17 @@ LOGGER = logging.getLogger('Discord_Radio_Bot.Bot_Resources')
|
||||
GQRX_BIN_LOCATION = "/usr/bin/"
|
||||
GQRX_BIN = "/usr/bin/gqrx"
|
||||
|
||||
|
||||
# Default radio settings
|
||||
DEFAULT_RADIO_SETTINGS = {
|
||||
'profile_name': None,
|
||||
'freq': "104700000",
|
||||
'mode': "wfm",
|
||||
'squelch': 0,
|
||||
'noisegate_sensitivity': DEFAULT_NOISEGATE_THRESHOLD,
|
||||
}
|
||||
|
||||
|
||||
def check_if_config_exists():
|
||||
if exists('./config.ini'):
|
||||
config = configparser.SafeConfigParser()
|
||||
|
||||
10
bot.py
10
bot.py
@@ -42,11 +42,11 @@ class Bot(commands.Bot):
|
||||
_display_output_devices=False)
|
||||
|
||||
# Init radio parameters
|
||||
self.profile_name = None
|
||||
self.freq = "104700000"
|
||||
self.mode = "wfm"
|
||||
self.squelch = 0
|
||||
self.noisegate_sensitivity = BotResources.DEFAULT_NOISEGATE_THRESHOLD
|
||||
self.profile_name = BotResources.DEFAULT_RADIO_SETTINGS['profile_name']
|
||||
self.freq = BotResources.DEFAULT_RADIO_SETTINGS['freq']
|
||||
self.mode = BotResources.DEFAULT_RADIO_SETTINGS['mode']
|
||||
self.squelch = BotResources.DEFAULT_RADIO_SETTINGS['squelch']
|
||||
self.noisegate_sensitivity = BotResources.DEFAULT_RADIO_SETTINGS['noisegate_sensitivity']
|
||||
|
||||
# Init SDR Variables
|
||||
self.system_os_type = None
|
||||
|
||||
@@ -30,14 +30,15 @@ class GQRXHandler(threading.Thread):
|
||||
self.GQRXDir: str = GQRX_BIN_LOCATION
|
||||
self.GQRXEXE: str = shutil.which(GQRX_BIN)
|
||||
self.GQRXProc = None
|
||||
self.GQRX_Started = False
|
||||
|
||||
self.logger = logging.getLogger("Discord_Radio_Bot.GQRXHandler")
|
||||
|
||||
self.Frequency = None
|
||||
|
||||
self.Mode = None
|
||||
self.Frequency = None
|
||||
self.Squelch = None
|
||||
self.Mode = DEFAULT_RADIO_SETTINGS['mode']
|
||||
self.Frequency = DEFAULT_RADIO_SETTINGS['freq']
|
||||
self.Squelch = DEFAULT_RADIO_SETTINGS['squelch']
|
||||
|
||||
self.Start_GQRX = False
|
||||
self.Stop_GQRX = False
|
||||
@@ -68,11 +69,11 @@ class GQRXHandler(threading.Thread):
|
||||
sleep(.5)
|
||||
|
||||
def set_gqrx_parameters(self, _frequency: str = False, _start: bool = False, _stop: bool = False,
|
||||
_output_device_name: str = None, _fm_mode: str = None, _squelch: int = None,
|
||||
_output_device_name: str = None, _fm_mode: str = None, _squelch: float = None,
|
||||
_hostname: str = None, _port: int = None, _start_dsp: bool = None):
|
||||
if _frequency:
|
||||
self.Frequency = _frequency
|
||||
if self.GQRXProc:
|
||||
if self.GQRX_Started:
|
||||
self.change_freq(_frequency)
|
||||
|
||||
if _output_device_name:
|
||||
@@ -80,12 +81,12 @@ class GQRXHandler(threading.Thread):
|
||||
|
||||
if _fm_mode:
|
||||
self.Mode = _fm_mode
|
||||
if self.GQRXProc:
|
||||
if self.GQRX_Started:
|
||||
self.change_mode(_fm_mode)
|
||||
|
||||
if _squelch:
|
||||
self.Squelch = _squelch
|
||||
if self.GQRXProc:
|
||||
if self.GQRX_Started:
|
||||
self.change_squelch(_squelch)
|
||||
|
||||
if _hostname:
|
||||
@@ -106,10 +107,10 @@ class GQRXHandler(threading.Thread):
|
||||
self.Stop_GQRX = _stop
|
||||
|
||||
def open_gqrx(self):
|
||||
if self.GQRXProc is not None:
|
||||
if self.GQRX_Started:
|
||||
self.close_gqrx()
|
||||
|
||||
gqrx_kwargs = [f"-c", "drb_defaults.conf"]
|
||||
gqrx_kwargs = [f"gqrx", "-c", "drb_defaults.conf"]
|
||||
|
||||
self.logger.info(f"Resetting 'crashed' option in the GQRX config")
|
||||
|
||||
@@ -119,13 +120,15 @@ class GQRXHandler(threading.Thread):
|
||||
|
||||
self.logger.debug(f"GQRX Keyword Args: {gqrx_kwargs}")
|
||||
|
||||
self.GQRXProc = subprocess.Popen(gqrx_kwargs, executable=self.GQRXEXE, shell=False, cwd=self.GQRXDir)
|
||||
self.GQRXProc = subprocess.Popen(gqrx_kwargs, executable=self.GQRXEXE, shell=False)
|
||||
|
||||
while not self.tel_conn:
|
||||
self.create_telnet_connection()
|
||||
sleep(.5)
|
||||
self.logger.debug(f"Waiting for GQRX to start")
|
||||
|
||||
self.GQRX_Started = True
|
||||
|
||||
self.start_dsp()
|
||||
|
||||
self.set_all_settings(_squelch=self.Squelch, _mode=self.Mode, _freq=self.Frequency)
|
||||
@@ -145,6 +148,8 @@ class GQRXHandler(threading.Thread):
|
||||
sleep(1)
|
||||
self.logger.debug(f"Waited {seconds_waited} seconds")
|
||||
seconds_waited += 1
|
||||
self.logger.debug("GQRX Closed")
|
||||
self.GQRX_Started = False
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(e)
|
||||
|
||||
@@ -3,6 +3,7 @@ import shutil
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
from BotResources import DEFAULT_RADIO_SETTINGS
|
||||
|
||||
|
||||
class OP25Handler(threading.Thread):
|
||||
@@ -12,7 +13,7 @@ class OP25Handler(threading.Thread):
|
||||
self.OP25EXE: str = shutil.which("/home/pi/op25/op25/gr-op25_repeater/apps/rx.py")
|
||||
self.OP25Proc = None
|
||||
|
||||
self.Frequency = None
|
||||
self.Frequency = DEFAULT_RADIO_SETTINGS['freq']
|
||||
|
||||
self.HTTP_ENABLED = False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user