diff --git a/modem/modem.py b/modem/modem.py index 86241011..933f7f9b 100644 --- a/modem/modem.py +++ b/modem/modem.py @@ -75,7 +75,8 @@ class RF: self.tx_audio_level = config['AUDIO']['tx_audio_level'] self.enable_audio_auto_tune = config['AUDIO']['enable_auto_tune'] self.enable_fsk = config['MODEM']['enable_fsk'] - self.enable_fft = config['MODEM']['enable_fft'] + #Dynamically enable FFT when a client connects to FFT web socket + self.enable_fft = False self.tx_delay = config['MODEM']['tx_delay'] self.tuning_range_fmin = config['MODEM']['tuning_range_fmin'] self.tuning_range_fmax = config['MODEM']['tuning_range_fmax'] @@ -300,8 +301,10 @@ class RF: x = self.audio_received_queue.get() x = np.frombuffer(x, dtype=np.int16) # x = self.resampler.resample48_to_8(x) - if self.enable_fft: - self.calculate_fft(x) + + #FFT should always be enabled as busy detection is done here + #if self.enable_fft: + self.calculate_fft(x) length_x = len(x) for data_buffer, receive in [ @@ -416,8 +419,8 @@ class RF: if not self.modoutqueue or self.mod_out_locked: data_out48k = np.zeros(frames, dtype=np.int16) - if self.enable_fft: - self.calculate_fft(x) + #if self.enable_fft: + self.calculate_fft(x) else: # TODO Moved to this place for testing # Maybe we can avoid moments of silence before transmitting @@ -425,8 +428,8 @@ class RF: self.event_manager.send_ptt_change(True) data_out48k = self.modoutqueue.popleft() - if self.enable_fft: - self.calculate_fft(data_out48k) + #if self.enable_fft: + self.calculate_fft(data_out48k) except Exception as e: self.log.warning(f"[MDM] audio callback not ready yet: {e}") @@ -1422,11 +1425,11 @@ class RF: if self.channel_busy_delay == 0: self.states.set("channel_busy", False) - # erase queue if greater than 10 - if self.fft_queue.qsize() >= 10: - self.fft_queue = queue.Queue() - - self.fft_queue.put(dfftlist[:315]) # 315 --> bandwidth 3200 + if (self.enable_fft): + # erase queue if greater than 10 + if self.fft_queue.qsize() >= 10: + self.fft_queue = queue.Queue() + self.fft_queue.put(dfftlist[:315]) # 315 --> bandwidth 3200 except Exception as err: self.log.error(f"[MDM] calculate_fft: Exception: {err}") self.log.debug("[MDM] Setting fft=0") @@ -1464,6 +1467,8 @@ class RF: codec2.api.freedv_set_sync(self.dat0_datac4_freedv, 0) codec2.api.freedv_set_sync(self.fsk_ldpc_freedv_0, 0) + def set_FFT_stream(self, enable: bool): + self.enable_fft = enable def open_codec2_instance(mode: int) -> ctypes.c_void_p: """ diff --git a/modem/service_manager.py b/modem/service_manager.py index ee18d06a..53707730 100644 --- a/modem/service_manager.py +++ b/modem/service_manager.py @@ -17,6 +17,7 @@ class SM: self.config = self.app.config_manager.read() self.modem_events = app.modem_events self.modem_fft = app.modem_fft + self.enable_fft = False self.modem_service = app.modem_service self.states = app.state_manager @@ -36,6 +37,7 @@ class SM: self.log.info("------------------ FreeDATA ------------------") self.log.info("------------------ MODEM ------------------") self.start_modem() + elif cmd in ['stop'] and self.modem: self.stop_modem() # we need to wait a bit for avoiding a portaudio crash @@ -47,7 +49,12 @@ class SM: threading.Event().wait(0.5) if self.start_modem(): self.modem_events.put(json.dumps({"freedata": "modem-event", "event": "restart"})) - + elif cmd in ['fft:true']: + self.modem.set_FFT_stream(True) + self.enable_fft=True + elif cmd in ['fft:false']: + self.modem.set_FFT_stream(False) + self.enable_fft=False else: self.log.warning("[SVC] modem command processing failed", cmd=cmd, state=self.states.is_modem_running) @@ -64,11 +71,12 @@ class SM: self.modem = modem.RF(self.config, self.modem_events, self.modem_fft, self.modem_service, self.states) self.data_handler = data_handler.DATA(self.config, self.modem_events, self.states) self.states.set("is_modem_running", True) + self.modem.set_FFT_stream(self.enable_fft) return True elif self.states.is_modem_running: self.log.warning("modem already running") return False - + else: self.log.warning("starting modem failed", input_test=audio_test[0], output_test=audio_test[1]) self.states.set("is_modem_running", False)