From 1997d5ca5d14842fd0f4ab97f57d7baa9d62f40f Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Thu, 17 Feb 2022 00:50:12 -0500 Subject: [PATCH 01/34] Remove Noise Gate from master (moved to its own branch) --- bot.py | 5 ++++- sound.py | 15 +-------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/bot.py b/bot.py index bf1f148..e92f657 100644 --- a/bot.py +++ b/bot.py @@ -88,10 +88,13 @@ class Bot(commands.Bot): voice_connection = await channel.connect() # Create an audio stream from selected device - self.streamHandler = sound.PCMStream(voice_connection) + self.streamHandler = sound.PCMStream() # Ensure the selected device is available and start the audio stream self.streamHandler.change_device(self.DEVICE_ID) + # Play the stream + voice_connection.play(discord.PCMAudio(self.streamHandler)) + # Start the SDR and begin playing to the audio stream self.start_sdr() diff --git a/sound.py b/sound.py index bf0297f..c27ca36 100644 --- a/sound.py +++ b/sound.py @@ -1,6 +1,5 @@ import sounddevice as sd from pprint import pformat -from NoiseGate import NoiseGate DEFAULT = 0 sd.default.channels = 2 @@ -8,14 +7,11 @@ sd.default.dtype = "int16" sd.default.latency = "low" sd.default.samplerate = 48000 -noisegate_obj = NoiseGate() - class PCMStream: globals() - def __init__(self, voice_connection): + def __init__(self): self.stream = None - self.voice_connection = voice_connection def read(self, num_bytes): # frame is 4 bytes @@ -29,10 +25,8 @@ class PCMStream: self.clean_up() self.stream = sd.RawInputStream(device=device_ID) - noisegate_obj.init_stream(device_ID, self.voice_connection, self) self.stream.start() - noisegate_obj.start() def clean_up(self): global noisegate_obj @@ -40,13 +34,6 @@ class PCMStream: self.stream.stop() self.stream.close() - if noisegate_obj.NG_Started.is_set(): - print("Closing the noisegate") - noisegate_obj.stop_NG.set() - noisegate_obj.join() - noisegate_obj = NoiseGate() - print("Started the noisegate") - class DeviceNotFoundError(Exception): def __init__(self): From ae92057986dfa3e6111f3d95fbfbfb21cdb76e46 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Thu, 17 Feb 2022 00:50:39 -0500 Subject: [PATCH 02/34] Added third key for Brent --- main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.py b/main.py index e1a67de..a49a723 100644 --- a/main.py +++ b/main.py @@ -10,6 +10,9 @@ from BotResources import check_if_config_exists, write_config_file, read_config_ # Greada #token = 'NzU2MzI3MjcxNTk3NDczODYz.X2QOqQ.LVLj2b-RXQzPmhNuBC1eGFMcYls' +# Brent +#token = OTQzNzQyMDQwMjU1MTE1MzA0.Yg3eRA.ZxEbRr55xahjfaUmPY8pmS-RHTY + #name = "VoiceMeeter Output" From 6fcf0dcc644258d9ba08e8cabe2bfe1190067b1f Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Thu, 17 Feb 2022 00:51:59 -0500 Subject: [PATCH 03/34] update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8684325..a9c4648 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.idea/ /Releases/ +/Old/ /__pycache__/ */__pycache__/ /venv/ From 882fc5940071eba158b049d0353b153f20150822 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Thu, 17 Feb 2022 01:29:53 -0500 Subject: [PATCH 04/34] Added Support for OP25 --- bot.py | 73 +++++++++++++++++++++++++++++++++++--------------- op25Handler.py | 35 ++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 21 deletions(-) create mode 100644 op25Handler.py diff --git a/bot.py b/bot.py index e92f657..c71541b 100644 --- a/bot.py +++ b/bot.py @@ -5,6 +5,7 @@ import sound import configparser from discord.ext import commands from gqrxHandler import GQRXHandler +from op25Handler import OP25Handler # Init class for bot @@ -43,9 +44,8 @@ class Bot(commands.Bot): self.system_os_type = None self.sdr_started = False - if self.Handler == "gqrx": - print("Starting gqrx handler") - self.GQRXHandler = GQRXHandler() + # Check the handler being used + self.check_handler() # Set linux or windows self.check_os_type() @@ -56,6 +56,16 @@ class Bot(commands.Bot): # Check the ./modules folder for any modules (cog.py) self.check_for_modules() + # Check the handler being used during init + def check_handler(self): + if self.Handler == "gqrx": + print("Starting GQRX handler") + self.GQRXHandler = GQRXHandler() + + elif self.Handler == 'op25': + print("Starting OP25 handler") + self.OP25Handler = OP25Handler() + # Start the bot def start_bot(self): self.run(self.BOT_TOKEN) @@ -126,14 +136,22 @@ class Bot(commands.Bot): # 'Unlock' the bot self.Bot_Connected = False - if self.Handler == 'gqrx': + # Add commands for GQRX and OP25 + if self.Handler == 'gqrx' or self.Handler == 'op25': @self.command(name='chfreq', help="Use this command to change the frequency the bot is listening to. " "\nExample command: '@ chfreq wfm 104700000\n" - "Example command: '@ chfreq fm 154785000", + "Example command: '@ chfreq p25 154.785", brief="Changes radio frequency") async def chfreq(ctx, mode: str, freq: str, member: discord.Member = None): # Possible band-types that can be used - possible_modes = ['wfm', 'fm'] + possible_modes = [] + + if self.Handler == 'gqrx': + possible_modes = ['wfm', 'fm'] + + elif self.Handler == 'op25': + possible_modes = ['d', 'p25'] + member = member or ctx.author.display_name # Check to make sure the frequency input matches the syntax needed @@ -154,22 +172,26 @@ class Bot(commands.Bot): self.start_sdr() await self.set_activity() else: - await ctx.send(f"{str(member).capitalize()}, {mode} is not valid. You may only enter 'fm' or 'wbfm'") + await ctx.send(f"{str(member).capitalize()}, {mode} is not valid." + f" You may only enter {possible_modes}") else: - await ctx.send(f"{str(member).capitalize()}, {freq} is not valid. please refer to the help page '@ help chfreq'") + await ctx.send(f"{str(member).capitalize()}, {freq} is not valid. " + f"Please refer to the help page '@ help chfreq'") - @self.command(name='chsquelch', help="Use this command to change the squelch for the frequency" - "the bot is listening to", - brief="Changes radio squelch") - async def chsquelch(ctx, squelch: float, member: discord.Member = None): - member = member or ctx.author.display_name + # GQRX Specific commands + if self.Handler == 'gqrx': + @self.command(name='chsquelch', help="Use this command to change the squelch for the frequency" + "the bot is listening to", + brief="Changes radio squelch") + async def chsquelch(ctx, squelch: float, member: discord.Member = None): + member = member or ctx.author.display_name - self.squelch = squelch - await ctx.send(f"Ok {str(member).capitalize()}, I'm changing the squelch to {self.squelch}") + self.squelch = squelch + await ctx.send(f"Ok {str(member).capitalize()}, I'm changing the squelch to {self.squelch}") - # If the SDR is started, restart it with the updates - if self.sdr_started: - self.start_sdr() + # If the SDR is started, restart it with the updates + if self.sdr_started: + self.start_sdr() # Hidden admin commands @self.command(name='saveprofile', hidden=True) @@ -205,6 +227,7 @@ class Bot(commands.Bot): async def _stopsdr(ctx, member: discord.Member = None): self.stop_sdr() + # Load the proper OPUS library for the device being used def load_opus(self): # Check the system type and load the correct library if self.system_os_type == 'Linux_32': @@ -263,7 +286,7 @@ class Bot(commands.Bot): # Check to see if there is only one frequency def start_sdr(self): - if self.Handler == 'gqrx': + if self.Handler in ['gqrx', 'op25']: if type(self.freq) == str: # Single freq sent # Stop the SDR if it is running @@ -272,8 +295,12 @@ class Bot(commands.Bot): # Start the radio print(f"Starting freq: {self.freq}") - # Set the settings in GQRX - self.GQRXHandler.set_all_settings(self.mode, self.squelch, self.freq) + if self.Handler == 'gqrx': + # Set the settings in GQRX + self.GQRXHandler.set_all_settings(self.mode, self.squelch, self.freq) + + elif self.Handler == 'op25': + self.OP25Handler.set_op25_parameters(self.freq) # Set the started variable for later checks self.sdr_started = True @@ -282,6 +309,8 @@ class Bot(commands.Bot): def stop_sdr(self): if self.sdr_started: # Wait for the running processes to close + if self.Handler == 'op25': + self.OP25Handler.close_op25() # Need a way to 'close' GQRX self.sdr_started = False @@ -348,3 +377,5 @@ class Bot(commands.Bot): return False else: return False + + diff --git a/op25Handler.py b/op25Handler.py new file mode 100644 index 0000000..f01aad7 --- /dev/null +++ b/op25Handler.py @@ -0,0 +1,35 @@ +import threading +import subprocess +import os + + +class OP25Handler(threading.Thread): + def __init__(self): + super().__init__() + self.OP25Dir: str = "/home/pi/op25/op25/gr-op25_repeater/apps" + self.OP25Proc = None + + self.Frequency = None + + def run(self) -> None: + self.open_op25() + + def set_op25_parameters(self, _frequency): + self.Frequency = _frequency + + def open_op25(self): + if self.OP25Proc is not None: + self.close_op25() + + print(f"Starting OBS") + os.chdir(self.OP25Dir) + + self.OP25Proc = subprocess.Popen([f"./rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", "200000", "-o", + "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2"]) + + def close_op25(self): + print(f"Closing OP25") + try: + self.OP25Proc.kill() + except Exception as e: + print(e) From cf756e32e68c7784a1006d1def0bcb941f79bf00 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Thu, 17 Feb 2022 01:37:07 -0500 Subject: [PATCH 05/34] BUGFIX op25Handler.py - Possible shell issue --- op25Handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/op25Handler.py b/op25Handler.py index f01aad7..8e2eb7f 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -25,7 +25,7 @@ class OP25Handler(threading.Thread): os.chdir(self.OP25Dir) self.OP25Proc = subprocess.Popen([f"./rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", "200000", "-o", - "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2"]) + "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2"], shell=True) def close_op25(self): print(f"Closing OP25") From c4edfae8eefb7ba2b1bd5808b8304b04b1030855 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 00:42:43 -0500 Subject: [PATCH 06/34] BUGFIX op25Handler.py - Padded error and out pipes --- op25Handler.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/op25Handler.py b/op25Handler.py index 8e2eb7f..312bbc9 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -25,7 +25,8 @@ class OP25Handler(threading.Thread): os.chdir(self.OP25Dir) self.OP25Proc = subprocess.Popen([f"./rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", "200000", "-o", - "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2"], shell=True) + "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2"], shell=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) def close_op25(self): print(f"Closing OP25") From 65363e8238ca39a762dca821ae7d9b81f4e78a88 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 00:46:44 -0500 Subject: [PATCH 07/34] Added debug http server to ensure the app is running --- op25Handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/op25Handler.py b/op25Handler.py index 312bbc9..934ff47 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -25,7 +25,7 @@ class OP25Handler(threading.Thread): os.chdir(self.OP25Dir) self.OP25Proc = subprocess.Popen([f"./rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", "200000", "-o", - "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2"], shell=True, + "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2", "-l" "http:0.0.0.0:8080"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) def close_op25(self): From 4dd7539c5b5316accbb4cbef8639f15011cd98e1 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 00:50:21 -0500 Subject: [PATCH 08/34] BUGFIG never started OP25 --- bot.py | 1 + op25Handler.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index c71541b..78261bb 100644 --- a/bot.py +++ b/bot.py @@ -301,6 +301,7 @@ class Bot(commands.Bot): elif self.Handler == 'op25': self.OP25Handler.set_op25_parameters(self.freq) + self.OP25Handler.start() # Set the started variable for later checks self.sdr_started = True diff --git a/op25Handler.py b/op25Handler.py index 934ff47..225cbaf 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -21,7 +21,7 @@ class OP25Handler(threading.Thread): if self.OP25Proc is not None: self.close_op25() - print(f"Starting OBS") + print(f"Starting OP25") os.chdir(self.OP25Dir) self.OP25Proc = subprocess.Popen([f"./rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", "200000", "-o", From 15ce6a7aeab29cfdfb4e53d82d08758b8e104fdf Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 00:58:59 -0500 Subject: [PATCH 09/34] BUGFIG op25 --- op25Handler.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/op25Handler.py b/op25Handler.py index 225cbaf..c5f1b7f 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -28,6 +28,8 @@ class OP25Handler(threading.Thread): "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2", "-l" "http:0.0.0.0:8080"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + print(self.OP25Proc.poll()) + def close_op25(self): print(f"Closing OP25") try: From 8a765ad58e7045f6be91964b1906f0e829bdc8ce Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:00:33 -0500 Subject: [PATCH 10/34] BUGFIG op25 --- bot.py | 2 +- op25Handler.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index 78261bb..e7d082b 100644 --- a/bot.py +++ b/bot.py @@ -301,7 +301,7 @@ class Bot(commands.Bot): elif self.Handler == 'op25': self.OP25Handler.set_op25_parameters(self.freq) - self.OP25Handler.start() + self.OP25Handler.open_op25() # Set the started variable for later checks self.sdr_started = True diff --git a/op25Handler.py b/op25Handler.py index c5f1b7f..4af2da6 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -3,7 +3,7 @@ import subprocess import os -class OP25Handler(threading.Thread): +class OP25Handler: def __init__(self): super().__init__() self.OP25Dir: str = "/home/pi/op25/op25/gr-op25_repeater/apps" From 1e060bcdbacc29c87cc6b1a1b642048b859f8c0e Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:08:50 -0500 Subject: [PATCH 11/34] BUGFIG op25 --- op25Handler.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/op25Handler.py b/op25Handler.py index 4af2da6..d66bca3 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -3,7 +3,7 @@ import subprocess import os -class OP25Handler: +class OP25Handler(threading.Thread): def __init__(self): super().__init__() self.OP25Dir: str = "/home/pi/op25/op25/gr-op25_repeater/apps" @@ -24,12 +24,10 @@ class OP25Handler: print(f"Starting OP25") os.chdir(self.OP25Dir) - self.OP25Proc = subprocess.Popen([f"./rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", "200000", "-o", + self.OP25Proc = subprocess.call([f"./rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", "200000", "-o", "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2", "-l" "http:0.0.0.0:8080"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - print(self.OP25Proc.poll()) - def close_op25(self): print(f"Closing OP25") try: From 3c844e71fa1592ad847eddf85ac122f61189be6f Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:10:52 -0500 Subject: [PATCH 12/34] BUGFIG op25 --- bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.py b/bot.py index e7d082b..78261bb 100644 --- a/bot.py +++ b/bot.py @@ -301,7 +301,7 @@ class Bot(commands.Bot): elif self.Handler == 'op25': self.OP25Handler.set_op25_parameters(self.freq) - self.OP25Handler.open_op25() + self.OP25Handler.start() # Set the started variable for later checks self.sdr_started = True From 71fd0133a15100e92310a58753653ca1bab8ef3b Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:14:03 -0500 Subject: [PATCH 13/34] BUGFIG op25 --- op25Handler.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/op25Handler.py b/op25Handler.py index d66bca3..aed587b 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -22,9 +22,10 @@ class OP25Handler(threading.Thread): self.close_op25() print(f"Starting OP25") - os.chdir(self.OP25Dir) - self.OP25Proc = subprocess.call([f"./rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", "200000", "-o", + print(os.getcwd()) + + self.OP25Proc = subprocess.call(["python3", f"{self.OP25Dir}/rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", "200000", "-o", "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2", "-l" "http:0.0.0.0:8080"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) From 300524d4af7c6db66ec76182158d01456313b902 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:15:30 -0500 Subject: [PATCH 14/34] BUGFIG op25 --- op25Handler.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/op25Handler.py b/op25Handler.py index aed587b..67cdd9b 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -25,9 +25,10 @@ class OP25Handler(threading.Thread): print(os.getcwd()) - self.OP25Proc = subprocess.call(["python3", f"{self.OP25Dir}/rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", "200000", "-o", - "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2", "-l" "http:0.0.0.0:8080"], shell=True, - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + self.OP25Proc = subprocess.Popen(["python3", f"{self.OP25Dir}/rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", + "200000", "-o","25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2", + "-l" "http:0.0.0.0:8080"], shell=True, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) def close_op25(self): print(f"Closing OP25") From 364748c3d4696951718692de546e0f017714dcf0 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:16:44 -0500 Subject: [PATCH 15/34] BUGFIG op25 --- op25Handler.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/op25Handler.py b/op25Handler.py index 67cdd9b..ebd9a89 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -27,8 +27,7 @@ class OP25Handler(threading.Thread): self.OP25Proc = subprocess.Popen(["python3", f"{self.OP25Dir}/rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", "200000", "-o","25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2", - "-l" "http:0.0.0.0:8080"], shell=True, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + "-l" "http:0.0.0.0:8080"], shell=True) def close_op25(self): print(f"Closing OP25") From 4a996f468f53df4e47d58eae151358b36b6e9474 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:18:54 -0500 Subject: [PATCH 16/34] BUGFIG op25 --- op25Handler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/op25Handler.py b/op25Handler.py index ebd9a89..47f8ef8 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -26,8 +26,8 @@ class OP25Handler(threading.Thread): print(os.getcwd()) self.OP25Proc = subprocess.Popen(["python3", f"{self.OP25Dir}/rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", - "200000", "-o","25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2", - "-l" "http:0.0.0.0:8080"], shell=True) + "200000", "-o", "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2", + "-l" "http:0.0.0.0:8080"]) def close_op25(self): print(f"Closing OP25") From 0ca2552567b0bbe07dec22f99fe59a26b7eec2e6 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:20:18 -0500 Subject: [PATCH 17/34] BUGFIG op25 --- op25Handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/op25Handler.py b/op25Handler.py index 47f8ef8..46c6a55 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -25,7 +25,7 @@ class OP25Handler(threading.Thread): print(os.getcwd()) - self.OP25Proc = subprocess.Popen(["python3", f"{self.OP25Dir}/rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", + self.OP25Proc = subprocess.Popen([f"python3 {self.OP25Dir}/rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", "200000", "-o", "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2", "-l" "http:0.0.0.0:8080"]) From ff048ac8f49b4a11f0fbb4856ecfbd4d908e444b Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:21:52 -0500 Subject: [PATCH 18/34] BUGFIG op25 --- op25Handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/op25Handler.py b/op25Handler.py index 46c6a55..5d582de 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -25,7 +25,7 @@ class OP25Handler(threading.Thread): print(os.getcwd()) - self.OP25Proc = subprocess.Popen([f"python3 {self.OP25Dir}/rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", + self.OP25Proc = subprocess.Popen([f".{self.OP25Dir}/rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", "200000", "-o", "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2", "-l" "http:0.0.0.0:8080"]) From 00d8204fdd505a789066492240c4c0bb4a722e0f Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:23:05 -0500 Subject: [PATCH 19/34] BUGFIG op25 --- op25Handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/op25Handler.py b/op25Handler.py index 5d582de..418096e 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -25,7 +25,7 @@ class OP25Handler(threading.Thread): print(os.getcwd()) - self.OP25Proc = subprocess.Popen([f".{self.OP25Dir}/rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", + self.OP25Proc = subprocess.Popen([f"{self.OP25Dir}/rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", "200000", "-o", "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2", "-l" "http:0.0.0.0:8080"]) From b8ad42f66ecc1ccbac12416c2b1245c23a0f6280 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:25:17 -0500 Subject: [PATCH 20/34] BUGFIG op25 --- op25Handler.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/op25Handler.py b/op25Handler.py index 418096e..b0884b4 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -25,7 +25,11 @@ class OP25Handler(threading.Thread): print(os.getcwd()) - self.OP25Proc = subprocess.Popen([f"{self.OP25Dir}/rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", + os.chdir(self.OP25Dir) + + print(os.getcwd()) + + self.OP25Proc = subprocess.Popen([f"./rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", "200000", "-o", "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2", "-l" "http:0.0.0.0:8080"]) From 9ebdb49d37b2211b5e3bf0e95e3e5118a988576e Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:26:17 -0500 Subject: [PATCH 21/34] BUGFIG op25 --- op25Handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/op25Handler.py b/op25Handler.py index b0884b4..1444232 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -29,7 +29,7 @@ class OP25Handler(threading.Thread): print(os.getcwd()) - self.OP25Proc = subprocess.Popen([f"./rx.py", "--args", "'rtl'", "-N", "'LNA:49'", "-s", + self.OP25Proc = subprocess.Popen([f"./rx.py", "--args", "rtl", "-N", "LNA:49", "-s", "200000", "-o", "25600", "-U", "-f", f"{self.Frequency}e6", "-X", "-2", "-l" "http:0.0.0.0:8080"]) From dcfa2301b8f43b5899b6f9f381479ad07545bfed Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:28:53 -0500 Subject: [PATCH 22/34] BUGFIG bot - Missing activity --- bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 78261bb..3b20dc3 100644 --- a/bot.py +++ b/bot.py @@ -318,7 +318,7 @@ class Bot(commands.Bot): # Set the activity of the bot async def set_activity(self, connected=True): if connected: - if self.Handler == 'gqrx': + if self.Handler == ['gqrx', 'op25']: if self.profile_name is None: await self.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=f"{self.freq[:-1]}" From 15a592ad35e2c1ca7d60e68386e8f239c1e625fd Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:29:41 -0500 Subject: [PATCH 23/34] BUGFIG bot - Missing activity --- bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 3b20dc3..65325d8 100644 --- a/bot.py +++ b/bot.py @@ -318,7 +318,7 @@ class Bot(commands.Bot): # Set the activity of the bot async def set_activity(self, connected=True): if connected: - if self.Handler == ['gqrx', 'op25']: + if self.Handler in ['gqrx', 'op25']: if self.profile_name is None: await self.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=f"{self.freq[:-1]}" From 570d09fe450df77d3d3dbe335f44fb0ce74da0f1 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:31:51 -0500 Subject: [PATCH 24/34] BUGFIG bot - Doesn't close properly --- bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot.py b/bot.py index 65325d8..e1d686d 100644 --- a/bot.py +++ b/bot.py @@ -312,6 +312,7 @@ class Bot(commands.Bot): # Wait for the running processes to close if self.Handler == 'op25': self.OP25Handler.close_op25() + self.OP25Handler.join() # Need a way to 'close' GQRX self.sdr_started = False From d288d067fe22efdd9bc30e734a890b59c669c1ee Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:33:56 -0500 Subject: [PATCH 25/34] BUGFIG bot - Doesn't close properly --- op25Handler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/op25Handler.py b/op25Handler.py index 1444232..eff1cfb 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -37,5 +37,6 @@ class OP25Handler(threading.Thread): print(f"Closing OP25") try: self.OP25Proc.kill() + self.OP25Proc.terminate() except Exception as e: print(e) From 4a9cdefa4a3db26c784e9f84d59d01e0dc46b781 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:48:19 -0500 Subject: [PATCH 26/34] BUGFIG bot - Doesn't close properly --- op25Handler.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/op25Handler.py b/op25Handler.py index eff1cfb..29e0dc4 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -1,5 +1,6 @@ import threading import subprocess +import time import os @@ -37,6 +38,14 @@ class OP25Handler(threading.Thread): print(f"Closing OP25") try: self.OP25Proc.kill() - self.OP25Proc.terminate() + + seconds_waited = 0 + while self.OP25Proc.poll() is None: + # Terminate the process every 5 seconds + if seconds_waited % 5 == 0: + self.OP25Proc.terminate() + time.sleep(1) + seconds_waited += 1 + except Exception as e: print(e) From 2d6deeb2122ee5cc2da979f6ee1ec8213338c5a7 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:51:53 -0500 Subject: [PATCH 27/34] BUGFIG bot - Doesn't close properly --- bot.py | 2 +- op25Handler.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bot.py b/bot.py index e1d686d..8be2685 100644 --- a/bot.py +++ b/bot.py @@ -312,7 +312,7 @@ class Bot(commands.Bot): # Wait for the running processes to close if self.Handler == 'op25': self.OP25Handler.close_op25() - self.OP25Handler.join() + #self.OP25Handler.join() # Need a way to 'close' GQRX self.sdr_started = False diff --git a/op25Handler.py b/op25Handler.py index 29e0dc4..f88f6b9 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -4,7 +4,7 @@ import time import os -class OP25Handler(threading.Thread): +class OP25Handler: #(threading.Thread): def __init__(self): super().__init__() self.OP25Dir: str = "/home/pi/op25/op25/gr-op25_repeater/apps" @@ -12,7 +12,7 @@ class OP25Handler(threading.Thread): self.Frequency = None - def run(self) -> None: + def start(self) -> None: self.open_op25() def set_op25_parameters(self, _frequency): From 34b8fe2c0273750330285eb288ccda74f05de825 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:56:11 -0500 Subject: [PATCH 28/34] BUGFIG bot - Doesn't leave properly --- op25Handler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/op25Handler.py b/op25Handler.py index f88f6b9..19610cc 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -43,6 +43,7 @@ class OP25Handler: #(threading.Thread): while self.OP25Proc.poll() is None: # Terminate the process every 5 seconds if seconds_waited % 5 == 0: + print("Terminating OP25") self.OP25Proc.terminate() time.sleep(1) seconds_waited += 1 From 28149abaff1a98f2fb05c521c6f2ed25925163e9 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 01:59:47 -0500 Subject: [PATCH 29/34] Removed noisegate remnants --- sound.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sound.py b/sound.py index c27ca36..be7cf28 100644 --- a/sound.py +++ b/sound.py @@ -29,7 +29,6 @@ class PCMStream: self.stream.start() def clean_up(self): - global noisegate_obj if self.stream is not None: self.stream.stop() self.stream.close() From 44e6deef3de01b11284296cac26030a0ecc85b29 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 20:03:29 -0500 Subject: [PATCH 30/34] Removed noisegate remnants --- op25Handler.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/op25Handler.py b/op25Handler.py index 19610cc..f2a7c58 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -1,6 +1,6 @@ import threading import subprocess -import time +import asyncio import os @@ -45,7 +45,8 @@ class OP25Handler: #(threading.Thread): if seconds_waited % 5 == 0: print("Terminating OP25") self.OP25Proc.terminate() - time.sleep(1) + asyncio.sleep(5) + print(f"Waited {seconds_waited} seconds") seconds_waited += 1 except Exception as e: From 0ff02899974461cf685aa01703a817177a0b7fb4 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 20:07:03 -0500 Subject: [PATCH 31/34] BUGFIG bot - async sleep is in milliseconds --- op25Handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/op25Handler.py b/op25Handler.py index f2a7c58..3926ec0 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -45,7 +45,7 @@ class OP25Handler: #(threading.Thread): if seconds_waited % 5 == 0: print("Terminating OP25") self.OP25Proc.terminate() - asyncio.sleep(5) + asyncio.sleep(1000) print(f"Waited {seconds_waited} seconds") seconds_waited += 1 From fc30c6a183e22c10a290dfc92e4b33e4c86696d4 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 20:32:57 -0500 Subject: [PATCH 32/34] Implemented a global variable for acceptable handlers --- BotResources.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BotResources.py b/BotResources.py index 0d05b7e..4052be6 100644 --- a/BotResources.py +++ b/BotResources.py @@ -2,6 +2,8 @@ import sound import configparser from os.path import exists +PDB_ACCEPTABLE_HANDLERS = ['gqrx', 'op25'] + def check_if_config_exists(): if exists('./config.ini'): @@ -167,7 +169,7 @@ def get_handler(): handler = None while not handler: handler = str(input(f"Please enter the name of the handler you would like to use:\t")) - if handler == "gqrx": + if handler in PDB_ACCEPTABLE_HANDLERS: return handler elif handler == '': return handler From 0fa0018b6656c18c9ce9c958a565f9273ac27099 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 20:35:21 -0500 Subject: [PATCH 33/34] Improved the loading of handlers --- bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index 8be2685..efc1776 100644 --- a/bot.py +++ b/bot.py @@ -4,8 +4,6 @@ import discord import sound import configparser from discord.ext import commands -from gqrxHandler import GQRXHandler -from op25Handler import OP25Handler # Init class for bot @@ -60,10 +58,12 @@ class Bot(commands.Bot): def check_handler(self): if self.Handler == "gqrx": print("Starting GQRX handler") + from gqrxHandler import GQRXHandler self.GQRXHandler = GQRXHandler() elif self.Handler == 'op25': print("Starting OP25 handler") + from op25Handler import OP25Handler self.OP25Handler = OP25Handler() # Start the bot From eb6d09bed9c145a7d34bc3797d39d121c94e9542 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Fri, 18 Feb 2022 20:44:36 -0500 Subject: [PATCH 34/34] Improved help messages --- bot.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index efc1776..c20698a 100644 --- a/bot.py +++ b/bot.py @@ -138,9 +138,12 @@ class Bot(commands.Bot): # Add commands for GQRX and OP25 if self.Handler == 'gqrx' or self.Handler == 'op25': - @self.command(name='chfreq', help="Use this command to change the frequency the bot is listening to. " - "\nExample command: '@ chfreq wfm 104700000\n" - "Example command: '@ chfreq p25 154.785", + @self.command(name='chfreq', help="Use this command to change the frequency the bot is listening to.\n" + "Example GQRX command:\n" + "\tTune to 104.7Mhz Wideband FM (Radio) - '@ chfreq wfm 104700000\n" + "\tTune to 155.505Mhz Narrowband FM (Radio) - '@ chfreq fm 155505000\n" + "Example OP25 command:\n" + "\tTune to 155.310Mhz, decode using P25 - '@ chfreq p25 155.310", brief="Changes radio frequency") async def chfreq(ctx, mode: str, freq: str, member: discord.Member = None): # Possible band-types that can be used @@ -161,8 +164,8 @@ class Bot(commands.Bot): if mode in possible_modes: self.mode = mode - await ctx.send(f"Ok {str(member).capitalize()}, I'm changing the mode to {str(self.mode).upper()} and frequency to" - f" {self.freq}") + await ctx.send(f"Ok {str(member).capitalize()}, I'm changing the mode to " + f"{str(self.mode).upper()} and frequency to {self.freq}") # Reset the profile name since we have made a change to the freq self.profile_name = None @@ -180,8 +183,11 @@ class Bot(commands.Bot): # GQRX Specific commands if self.Handler == 'gqrx': - @self.command(name='chsquelch', help="Use this command to change the squelch for the frequency" - "the bot is listening to", + @self.command(name='chsquelch', help="Use this command to change the squelch for the frequency " + "the bot is listening to\n" + "Example Commands:\n" + "\tNo Squelch\t'@ chsquelch 150'\n" + "\tFully Squelched\t'@ chsquelch 0'", brief="Changes radio squelch") async def chsquelch(ctx, squelch: float, member: discord.Member = None): member = member or ctx.author.display_name