Updated start_sdr function

This commit is contained in:
Logan Cusano
2021-12-28 01:16:41 -05:00
parent 7895fd772b
commit 695f5dc2c9

30
bot.py
View File

@@ -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