reducing another global...

This commit is contained in:
DJ2LS 2023-11-17 09:53:51 +01:00
parent c19586369e
commit ee709b32ef
2 changed files with 23 additions and 25 deletions

View file

@ -48,6 +48,8 @@ class DATA:
self.mycallsign = config['STATION']['mycall'] self.mycallsign = config['STATION']['mycall']
self.mygrid = config['STATION']['mygrid'] self.mygrid = config['STATION']['mygrid']
self.enable_fsk = config['MODEM']['enable_fsk']
self.dxcallsign = Station.dxcallsign self.dxcallsign = Station.dxcallsign
@ -2553,8 +2555,8 @@ class DATA:
ping_frame[4:7] = helpers.get_crc_24(mycallsign) ping_frame[4:7] = helpers.get_crc_24(mycallsign)
ping_frame[7:13] = helpers.callsign_to_bytes(mycallsign) ping_frame[7:13] = helpers.callsign_to_bytes(mycallsign)
if Modem.enable_fsk: if self.enable_fsk:
self.log.info("[Modem] ENABLE FSK", state=Modem.enable_fsk) self.log.info("[Modem] ENABLE FSK", state=self.enable_fsk)
self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value) self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value)
else: else:
self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.sig0.value) self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.sig0.value)
@ -2624,7 +2626,7 @@ class DATA:
ping_frame[7:11] = helpers.encode_grid(self.mygrid) ping_frame[7:11] = helpers.encode_grid(self.mygrid)
ping_frame[13:14] = helpers.snr_to_bytes(snr) ping_frame[13:14] = helpers.snr_to_bytes(snr)
if Modem.enable_fsk: if self.enable_fsk:
self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value) self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value)
else: else:
self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.sig0.value) self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.sig0.value)
@ -2768,8 +2770,8 @@ class DATA:
beacon_frame[1:7] = helpers.callsign_to_bytes(self.mycallsign) beacon_frame[1:7] = helpers.callsign_to_bytes(self.mycallsign)
beacon_frame[7:11] = helpers.encode_grid(self.mygrid) beacon_frame[7:11] = helpers.encode_grid(self.mygrid)
if Modem.enable_fsk: if self.enable_fsk:
self.log.info("[Modem] ENABLE FSK", state=Modem.enable_fsk) self.log.info("[Modem] ENABLE FSK", state=self.enable_fsk)
self.enqueue_frame_for_tx( self.enqueue_frame_for_tx(
[beacon_frame], [beacon_frame],
c2_mode=FREEDV_MODE.fsk_ldpc_0.value, c2_mode=FREEDV_MODE.fsk_ldpc_0.value,
@ -2851,8 +2853,8 @@ class DATA:
self.log.debug("[Modem] CQ Frame:", data=[cq_frame]) self.log.debug("[Modem] CQ Frame:", data=[cq_frame])
if Modem.enable_fsk: if self.enable_fsk:
self.log.info("[Modem] ENABLE FSK", state=Modem.enable_fsk) self.log.info("[Modem] ENABLE FSK", state=self.enable_fsk)
self.enqueue_frame_for_tx([cq_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value) self.enqueue_frame_for_tx([cq_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value)
else: else:
self.enqueue_frame_for_tx([cq_frame], c2_mode=FREEDV_MODE.sig0.value, copies=1, repeat_delay=0) self.enqueue_frame_for_tx([cq_frame], c2_mode=FREEDV_MODE.sig0.value, copies=1, repeat_delay=0)
@ -2929,8 +2931,8 @@ class DATA:
qrv_frame[7:11] = helpers.encode_grid(self.mygrid) qrv_frame[7:11] = helpers.encode_grid(self.mygrid)
qrv_frame[11:12] = helpers.snr_to_bytes(snr) qrv_frame[11:12] = helpers.snr_to_bytes(snr)
if Modem.enable_fsk: if self.enable_fsk:
self.log.info("[Modem] ENABLE FSK", state=Modem.enable_fsk) self.log.info("[Modem] ENABLE FSK", state=self.enable_fsk)
self.enqueue_frame_for_tx([qrv_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value) self.enqueue_frame_for_tx([qrv_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value)
else: else:
self.enqueue_frame_for_tx([qrv_frame], c2_mode=FREEDV_MODE.sig0.value, copies=1, repeat_delay=0) self.enqueue_frame_for_tx([qrv_frame], c2_mode=FREEDV_MODE.sig0.value, copies=1, repeat_delay=0)

View file

@ -20,7 +20,7 @@ import codec2
import itertools import itertools
import numpy as np import numpy as np
import sounddevice as sd import sounddevice as sd
from global_instances import HamlibParam, ModemParam, Modem from global_instances import HamlibParam, Modem
from static import FRAME_TYPE from static import FRAME_TYPE
import structlog import structlog
import tci import tci
@ -77,6 +77,7 @@ class RF:
self.rx_audio_level = config['AUDIO']['rx_audio_level'] self.rx_audio_level = config['AUDIO']['rx_audio_level']
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_fft = config['MODEM']['enable_fft'] self.enable_fft = config['MODEM']['enable_fft']
self.enable_scatter = config['MODEM']['enable_scatter'] self.enable_scatter = config['MODEM']['enable_scatter']
self.tx_delay = config['MODEM']['tx_delay'] self.tx_delay = config['MODEM']['tx_delay']
@ -304,8 +305,8 @@ class RF:
(self.dat0_datac1_buffer, RECEIVE_DATAC1), (self.dat0_datac1_buffer, RECEIVE_DATAC1),
(self.dat0_datac3_buffer, RECEIVE_DATAC3), (self.dat0_datac3_buffer, RECEIVE_DATAC3),
(self.dat0_datac4_buffer, RECEIVE_DATAC4), (self.dat0_datac4_buffer, RECEIVE_DATAC4),
(self.fsk_ldpc_buffer_0, Modem.enable_fsk), (self.fsk_ldpc_buffer_0, self.enable_fsk),
(self.fsk_ldpc_buffer_1, Modem.enable_fsk), (self.fsk_ldpc_buffer_1, self.enable_fsk),
]: ]:
if ( if (
not (data_buffer.nbuffer + length_x) > data_buffer.size not (data_buffer.nbuffer + length_x) > data_buffer.size
@ -338,8 +339,8 @@ class RF:
(self.dat0_datac1_buffer, RECEIVE_DATAC1), (self.dat0_datac1_buffer, RECEIVE_DATAC1),
(self.dat0_datac3_buffer, RECEIVE_DATAC3), (self.dat0_datac3_buffer, RECEIVE_DATAC3),
(self.dat0_datac4_buffer, RECEIVE_DATAC4), (self.dat0_datac4_buffer, RECEIVE_DATAC4),
(self.fsk_ldpc_buffer_0, Modem.enable_fsk), (self.fsk_ldpc_buffer_0, self.enable_fsk),
(self.fsk_ldpc_buffer_1, Modem.enable_fsk), (self.fsk_ldpc_buffer_1, self.enable_fsk),
]: ]:
if ( if (
not (data_buffer.nbuffer + length_x) > data_buffer.size not (data_buffer.nbuffer + length_x) > data_buffer.size
@ -398,8 +399,8 @@ class RF:
(self.dat0_datac1_buffer, RECEIVE_DATAC1, 2), (self.dat0_datac1_buffer, RECEIVE_DATAC1, 2),
(self.dat0_datac3_buffer, RECEIVE_DATAC3, 3), (self.dat0_datac3_buffer, RECEIVE_DATAC3, 3),
(self.dat0_datac4_buffer, RECEIVE_DATAC4, 4), (self.dat0_datac4_buffer, RECEIVE_DATAC4, 4),
(self.fsk_ldpc_buffer_0, Modem.enable_fsk, 5), (self.fsk_ldpc_buffer_0, self.enable_fsk, 5),
(self.fsk_ldpc_buffer_1, Modem.enable_fsk, 6), (self.fsk_ldpc_buffer_1, self.enable_fsk, 6),
]: ]:
if (audiobuffer.nbuffer + length_x) > audiobuffer.size: if (audiobuffer.nbuffer + length_x) > audiobuffer.size:
self.buffer_overflow_counter[index] += 1 self.buffer_overflow_counter[index] += 1
@ -732,7 +733,7 @@ class RF:
def init_decoders(self): def init_decoders(self):
if Modem.enable_fsk: if self.enable_fsk:
audio_thread_fsk_ldpc0 = threading.Thread( audio_thread_fsk_ldpc0 = threading.Thread(
target=self.audio_fsk_ldpc_0, name="AUDIO_THREAD FSK LDPC0", daemon=True target=self.audio_fsk_ldpc_0, name="AUDIO_THREAD FSK LDPC0", daemon=True
) )
@ -1167,7 +1168,6 @@ class RF:
def get_frequency_offset(self, freedv: ctypes.c_void_p) -> float: def get_frequency_offset(self, freedv: ctypes.c_void_p) -> float:
""" """
Ask codec2 for the calculated (audio) frequency offset of the received signal. Ask codec2 for the calculated (audio) frequency offset of the received signal.
Side-effect: sets ModemParam.frequency_offset
:param freedv: codec2 instance to query :param freedv: codec2 instance to query
:type freedv: ctypes.c_void_p :type freedv: ctypes.c_void_p
@ -1177,7 +1177,6 @@ class RF:
modemStats = codec2.MODEMSTATS() modemStats = codec2.MODEMSTATS()
codec2.api.freedv_get_modem_extended_stats(freedv, ctypes.byref(modemStats)) codec2.api.freedv_get_modem_extended_stats(freedv, ctypes.byref(modemStats))
offset = round(modemStats.foff) * (-1) offset = round(modemStats.foff) * (-1)
ModemParam.frequency_offset = offset
return offset return offset
def get_scatter(self, freedv: ctypes.c_void_p) -> None: def get_scatter(self, freedv: ctypes.c_void_p) -> None:
@ -1225,7 +1224,6 @@ class RF:
""" """
Ask codec2 for data about the received signal and calculate Ask codec2 for data about the received signal and calculate
the signal-to-noise ratio. the signal-to-noise ratio.
Side effect: sets ModemParam.snr
:param freedv: codec2 instance to query :param freedv: codec2 instance to query
:type freedv: ctypes.c_void_p :type freedv: ctypes.c_void_p
@ -1244,15 +1242,13 @@ class RF:
snr = round(modem_stats_snr, 1) snr = round(modem_stats_snr, 1)
self.log.info("[MDM] calculate_snr: ", snr=snr) self.log.info("[MDM] calculate_snr: ", snr=snr)
ModemParam.snr = snr # snr = np.clip(
# ModemParam.snr = np.clip(
# snr, -127, 127 # snr, -127, 127
# ) # limit to max value of -128/128 as a possible fix of #188 # ) # limit to max value of -128/128 as a possible fix of #188
return ModemParam.snr return snr
except Exception as err: except Exception as err:
self.log.error(f"[MDM] calculate_snr: Exception: {err}") self.log.error(f"[MDM] calculate_snr: Exception: {err}")
ModemParam.snr = 0 return 0
return ModemParam.snr
def init_rig_control(self): def init_rig_control(self):
# Check how we want to control the radio # Check how we want to control the radio