From 126ba907afc75d0a6eb626dab3824c9cf342523e Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sat, 19 Mar 2022 01:18:45 -0400 Subject: [PATCH] Testing OP25 Improvements - New system of handling thread --- bot.py | 6 +++--- op25Handler.py | 33 ++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/bot.py b/bot.py index f01c1d3..6d9576b 100644 --- a/bot.py +++ b/bot.py @@ -312,6 +312,7 @@ class Bot(commands.Bot): print("Starting OP25 handler") from op25Handler import OP25Handler self.OP25Handler = OP25Handler() + self.OP25Handler.start() self.possible_modes = BotResources.PDB_ACCEPTABLE_HANDLERS['op25']['Modes'] # Load the proper OPUS library for the device being used @@ -399,8 +400,7 @@ class Bot(commands.Bot): self.GQRXHandler.set_all_settings(self.mode, self.squelch, self.freq) elif self.Handler == 'op25': - self.OP25Handler.set_op25_parameters(self.freq) - self.OP25Handler.start() + self.OP25Handler.set_op25_parameters(self.freq, _start=True) # Set the started variable for later checks self.sdr_started = True @@ -411,7 +411,7 @@ class Bot(commands.Bot): # Wait for the running processes to close # Close the OP25 handler if self.Handler == 'op25': - self.OP25Handler.close_op25() + self.OP25Handler.set_op25_parameters(_stop=True) # self.OP25Handler.join() # Need a way to 'close' GQRX self.sdr_started = False diff --git a/op25Handler.py b/op25Handler.py index a9cdc26..0e39891 100644 --- a/op25Handler.py +++ b/op25Handler.py @@ -15,14 +15,37 @@ class OP25Handler(threading.Thread): self.HTTP_ENABLED = False - #def start(self) -> None: + self.Start_OP25 = False + + self.Stop_OP25 = False + def run(self) -> None: - self.open_op25() + while True: + if self.Start_OP25: + self.open_op25() - def set_op25_parameters(self, _frequency, _http_enabled: bool = True): - self.Frequency = _frequency + self.Start_OP25 = False + self.Stop_OP25 = False - self.HTTP_ENABLED = _http_enabled + while not self.Stop_OP25: + time.sleep(1) + + self.close_op25() + + time.sleep(.5) + + def set_op25_parameters(self, _frequency: str = False, _http_enabled: bool = True, _start: bool = False, _stop: bool = False): + if _frequency: + self.Frequency = _frequency + + if _start: + self.Start_OP25 = _start + + if _stop: + self.Stop_OP25 = _stop + + if _http_enabled: + self.HTTP_ENABLED = _http_enabled def open_op25(self): if self.OP25Proc is not None: