Fix dynamic control of FFT data stream

This commit is contained in:
Mashintime 2023-11-26 12:22:22 -05:00
parent 16af549274
commit 12e5d2ff7a
2 changed files with 12 additions and 14 deletions

View file

@ -75,8 +75,8 @@ class RF:
self.tx_audio_level = config['AUDIO']['tx_audio_level'] self.tx_audio_level = config['AUDIO']['tx_audio_level']
self.enable_audio_auto_tune = config['AUDIO']['enable_auto_tune'] self.enable_audio_auto_tune = config['AUDIO']['enable_auto_tune']
self.enable_fsk = config['MODEM']['enable_fsk'] self.enable_fsk = config['MODEM']['enable_fsk']
#Dynamically enable FFT when a client connects to FFT web socket #Dynamically enable FFT data stream when a client connects to FFT web socket
self.enable_fft = False self.enable_fft_stream = False
self.tx_delay = config['MODEM']['tx_delay'] self.tx_delay = config['MODEM']['tx_delay']
self.tuning_range_fmin = config['MODEM']['tuning_range_fmin'] self.tuning_range_fmin = config['MODEM']['tuning_range_fmin']
self.tuning_range_fmax = config['MODEM']['tuning_range_fmax'] self.tuning_range_fmax = config['MODEM']['tuning_range_fmax']
@ -302,8 +302,6 @@ class RF:
x = np.frombuffer(x, dtype=np.int16) x = np.frombuffer(x, dtype=np.int16)
# x = self.resampler.resample48_to_8(x) # x = self.resampler.resample48_to_8(x)
#FFT should always be enabled as busy detection is done here
#if self.enable_fft:
self.calculate_fft(x) self.calculate_fft(x)
length_x = len(x) length_x = len(x)
@ -419,7 +417,6 @@ class RF:
if not self.modoutqueue or self.mod_out_locked: if not self.modoutqueue or self.mod_out_locked:
data_out48k = np.zeros(frames, dtype=np.int16) data_out48k = np.zeros(frames, dtype=np.int16)
#if self.enable_fft:
self.calculate_fft(x) self.calculate_fft(x)
else: else:
# TODO Moved to this place for testing # TODO Moved to this place for testing
@ -428,7 +425,6 @@ class RF:
self.event_manager.send_ptt_change(True) self.event_manager.send_ptt_change(True)
data_out48k = self.modoutqueue.popleft() data_out48k = self.modoutqueue.popleft()
#if self.enable_fft:
self.calculate_fft(data_out48k) self.calculate_fft(data_out48k)
except Exception as e: except Exception as e:
self.log.warning(f"[MDM] audio callback not ready yet: {e}") self.log.warning(f"[MDM] audio callback not ready yet: {e}")
@ -1423,8 +1419,7 @@ class RF:
# When our channel busy counter reaches 0, toggle state to False # When our channel busy counter reaches 0, toggle state to False
if self.channel_busy_delay == 0: if self.channel_busy_delay == 0:
self.states.set("channel_busy", False) self.states.set("channel_busy", False)
if (self.enable_fft_stream):
if (self.enable_fft):
# erase queue if greater than 10 # erase queue if greater than 10
if self.fft_queue.qsize() >= 10: if self.fft_queue.qsize() >= 10:
self.fft_queue = queue.Queue() self.fft_queue = queue.Queue()
@ -1467,7 +1462,8 @@ class RF:
codec2.api.freedv_set_sync(self.fsk_ldpc_freedv_0, 0) codec2.api.freedv_set_sync(self.fsk_ldpc_freedv_0, 0)
def set_FFT_stream(self, enable: bool): def set_FFT_stream(self, enable: bool):
self.enable_fft = enable # Set config boolean regarding wheter it should sent FFT data to queue
self.enable_fft_stream = enable
def set_audio_volume(datalist: np.ndarray, dB: float) -> np.ndarray: def set_audio_volume(datalist: np.ndarray, dB: float) -> np.ndarray:
""" """

View file

@ -18,7 +18,7 @@ class SM:
self.config = self.app.config_manager.read() self.config = self.app.config_manager.read()
self.modem_events = app.modem_events self.modem_events = app.modem_events
self.modem_fft = app.modem_fft self.modem_fft = app.modem_fft
self.enable_fft = False self.enable_fft_stream = False
self.modem_service = app.modem_service self.modem_service = app.modem_service
self.states = app.state_manager self.states = app.state_manager
@ -51,11 +51,13 @@ class SM:
if self.start_modem(): if self.start_modem():
self.modem_events.put(json.dumps({"freedata": "modem-event", "event": "restart"})) self.modem_events.put(json.dumps({"freedata": "modem-event", "event": "restart"}))
elif cmd in ['fft:true']: elif cmd in ['fft:true']:
#self.modem.set_FFT_stream(True) # Tell modem it should put FFT data in the queue
self.enable_fft=True self.modem.set_FFT_stream(True)
self.enable_fft_stream=True
elif cmd in ['fft:false']: elif cmd in ['fft:false']:
#self.modem.set_FFT_stream(False) # Tell modem it should not put FFT data in the queue
self.enable_fft=False self.modem.set_FFT_stream(False)
self.enable_fft_stream=False
else: else:
self.log.warning("[SVC] modem command processing failed", cmd=cmd, state=self.states.is_modem_running) self.log.warning("[SVC] modem command processing failed", cmd=cmd, state=self.states.is_modem_running)