From 695f5dc2c93ea9e212a84e7a21a6f27e8690c3eb Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Tue, 28 Dec 2021 01:16:41 -0500 Subject: [PATCH] Updated start_sdr function --- bot.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index 87b3556..f1f5eea 100644 --- a/bot.py +++ b/bot.py @@ -1,4 +1,5 @@ import os +import time import discord import sound from discord.ext import commands @@ -22,6 +23,7 @@ class Bot(commands.Bot): self.sdr_process = None self.system_os_type = None self.sdr_output_process = None + self.sdr_started = False # Set linux or windows self.check_os_type() @@ -125,12 +127,26 @@ class Bot(commands.Bot): possible_modes = ['wbfm', 'fm'] if type(freq) == str: # Single freq sent - if self.sdr_process: - self.sdr_process.terminate() - self.sdr_output_process.terminate() - - self.sdr_process = Popen(["rtl_fm", f"-M {mode} -f {freq} -g {gain} -l {squelch} -s {sample_rate}"], + print(f"started: {self.sdr_started}, poll: {self.sdr_process}") + # Wait for the running processes to close + if self.sdr_started: + print(f"SDR Poll: {self.sdr_process.poll()}") + print(f"SDR Out Poll: {self.sdr_output_process.poll()}") + while self.sdr_process.poll() is None and self.sdr_output_process.poll() is None: + print(f"SDR Loop Poll: {self.sdr_process.poll()}") + self.sdr_process.terminate() + self.sdr_process.kill() + time.sleep(1) + self.sdr_output_process.terminate() + self.sdr_output_process.kill() + time.sleep(1) + + self.sdr_started = False + + + print(f"freq: {freq}") + self.sdr_process = Popen(["rtl_fm", "-M", str(mode), "-f", str(freq), "-g", str(gain), "-l", str(squelch), "-s", str(sample_rate)], stdout=PIPE) - self.sdr_output_process = Popen(["play", "-t raw -r 32k -es -b 16 -c 1 -V1 -", "rtl_fm", - f"-M {mode} -f {freq} -g {gain} -l {squelch} -s {sample_rate}"], + self.sdr_output_process = Popen(["play", "-t", "raw", "-r", "32k", "-es", "-b", "16", "-c", "1", "-V1", "-"], stdin=self.sdr_process.stdout) + self.sdr_started = True \ No newline at end of file