adjusted rigctld

This commit is contained in:
DJ2LS 2023-01-31 17:44:46 +01:00
parent 5adeed28ec
commit 5dbc3d8de1
2 changed files with 65 additions and 45 deletions

View file

@ -47,7 +47,6 @@ DAT0_DATAC1_STATE = []
DAT0_DATAC3_STATE = [] DAT0_DATAC3_STATE = []
class RF: class RF:
"""Class to encapsulate interactions between the audio device and codec2""" """Class to encapsulate interactions between the audio device and codec2"""
@ -69,7 +68,6 @@ class RF:
self.AUDIO_CHANNELS = 1 self.AUDIO_CHANNELS = 1
self.MODE = 0 self.MODE = 0
# Locking state for mod out so buffer will be filled before we can use it # Locking state for mod out so buffer will be filled before we can use it
# https://github.com/DJ2LS/FreeDATA/issues/127 # https://github.com/DJ2LS/FreeDATA/issues/127
# https://github.com/DJ2LS/FreeDATA/issues/99 # https://github.com/DJ2LS/FreeDATA/issues/99
@ -112,7 +110,6 @@ class RF:
self.sig1_datac0_nin = \ self.sig1_datac0_nin = \
self.init_codec2_mode(codec2.api.FREEDV_MODE_DATAC0, None) self.init_codec2_mode(codec2.api.FREEDV_MODE_DATAC0, None)
# DATAC1 # DATAC1
self.dat0_datac1_freedv, \ self.dat0_datac1_freedv, \
self.dat0_datac1_bytes_per_frame, \ self.dat0_datac1_bytes_per_frame, \
@ -285,8 +282,6 @@ class RF:
) )
hamlib_set_thread.start() hamlib_set_thread.start()
# self.log.debug("[MDM] Starting worker_receive") # self.log.debug("[MDM] Starting worker_receive")
worker_received = threading.Thread( worker_received = threading.Thread(
target=self.worker_received, name="WORKER_THREAD", daemon=True target=self.worker_received, name="WORKER_THREAD", daemon=True
@ -654,7 +649,8 @@ class RF:
static.IS_CODEC2_TRAFFIC = True static.IS_CODEC2_TRAFFIC = True
self.log.debug( self.log.debug(
"[MDM] [demod_audio] modem state", mode=mode_name, rx_status=rx_status, sync_flag=codec2.api.rx_sync_flags_to_text[rx_status] "[MDM] [demod_audio] modem state", mode=mode_name, rx_status=rx_status,
sync_flag=codec2.api.rx_sync_flags_to_text[rx_status]
) )
else: else:
static.IS_CODEC2_TRAFFIC = False static.IS_CODEC2_TRAFFIC = False
@ -662,8 +658,6 @@ class RF:
if rx_status == 10: if rx_status == 10:
state_buffer.append(rx_status) state_buffer.append(rx_status)
audiobuffer.pop(nin) audiobuffer.pop(nin)
nin = codec2.api.freedv_nin(freedv) nin = codec2.api.freedv_nin(freedv)
if nbytes == bytes_per_frame: if nbytes == bytes_per_frame:
@ -963,15 +957,24 @@ class RF:
- static.HAMLIB_BANDWIDTH - static.HAMLIB_BANDWIDTH
""" """
while True: while True:
# this looks weird, but is necessary for avoiding rigctld packet colission sock
threading.Event().wait(0.25) threading.Event().wait(0.25)
static.HAMLIB_FREQUENCY = self.hamlib.get_frequency() static.HAMLIB_FREQUENCY = self.hamlib.get_frequency()
threading.Event().wait(0.1)
static.HAMLIB_MODE = self.hamlib.get_mode() static.HAMLIB_MODE = self.hamlib.get_mode()
threading.Event().wait(0.1)
static.HAMLIB_BANDWIDTH = self.hamlib.get_bandwidth() static.HAMLIB_BANDWIDTH = self.hamlib.get_bandwidth()
threading.Event().wait(0.1)
static.HAMLIB_STATUS = self.hamlib.get_status() static.HAMLIB_STATUS = self.hamlib.get_status()
threading.Event().wait(0.1)
static.HAMLIB_ALC = self.hamlib.get_alc() static.HAMLIB_ALC = self.hamlib.get_alc()
threading.Event().wait(0.1)
static.HAMLIB_RF = self.hamlib.get_level() static.HAMLIB_RF = self.hamlib.get_level()
threading.Event().wait(0.1)
static.HAMLIB_STRENGTH = self.hamlib.get_strength() static.HAMLIB_STRENGTH = self.hamlib.get_strength()
print(f"ALC: {static.HAMLIB_ALC}, RF: {static.HAMLIB_RF}, STRENGTH: {static.HAMLIB_STRENGTH}") print(f"ALC: {static.HAMLIB_ALC}, RF: {static.HAMLIB_RF}, STRENGTH: {static.HAMLIB_STRENGTH}")
def calculate_fft(self) -> None: def calculate_fft(self) -> None:
""" """
Calculate an average signal strength of the channel to assess Calculate an average signal strength of the channel to assess

View file

@ -173,8 +173,12 @@ class radio:
""" """
if self.data_connected: if self.data_connected:
self.data_connection.setblocking(False)
self.data_connection.settimeout(0.05)
try: try:
self.data_connection.sendall(command + b"\n") self.data_connection.sendall(command + b"\n")
except Exception: except Exception:
self.log.warning( self.log.warning(
"[RIGCTLD] Command not executed!", "[RIGCTLD] Command not executed!",
@ -187,7 +191,20 @@ class radio:
try: try:
# recv seems to be blocking so in case of ptt we don't need the response # recv seems to be blocking so in case of ptt we don't need the response
# maybe this speeds things up and avoids blocking states # maybe this speeds things up and avoids blocking states
return self.data_connection.recv(64) if expect_answer else True recv = True
data = b''
while recv:
try:
data = self.data_connection.recv(64)
except socket.timeout:
recv = False
return data
# return self.data_connection.recv(64) if expect_answer else True
except Exception: except Exception:
self.log.warning( self.log.warning(
"[RIGCTLD] No command response!", "[RIGCTLD] No command response!",
@ -209,7 +226,7 @@ class radio:
rf = data[0].decode("utf-8") rf = data[0].decode("utf-8")
if 'RPRT' not in rf: if 'RPRT' not in rf:
try: try:
self.rf = int(rf) self.rf = str(rf)
except ValueError: except ValueError:
self.rf = str(rf) self.rf = str(rf)
@ -239,7 +256,7 @@ class radio:
alc = data[0].decode("utf-8") alc = data[0].decode("utf-8")
if 'RPRT' not in alc: if 'RPRT' not in alc:
try: try:
self.alc = int(alc) self.alc = float(alc)
except ValueError: except ValueError:
self.alc = str(alc) self.alc = str(alc)