From d572772df3d133eb12b021174b073c8694f93036 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Tue, 27 Dec 2022 17:11:46 +0100 Subject: [PATCH] use busy detection while opening a channel --- tnc/data_handler.py | 60 +++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index fd66a7f0..44552860 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -1840,36 +1840,7 @@ class DATA: # for calculating transmission statistics # static.ARQ_COMPRESSION_FACTOR = len(data_out) / len(lzma.compress(data_out)) - # Let's check if we have a busy channel and if we are not in a running arq session. - if static.CHANNEL_BUSY and not static.ARQ_SESSION: - self.log.warning("[TNC] Channel busy, waiting until free...") - self.send_data_to_socket_queue( - freedata="tnc-message", - arq="transmission", - status="waiting", - mycallsign=str(self.mycallsign, 'UTF-8'), - dxcallsign=str(self.dxcallsign, 'UTF-8'), - ) - # wait while timeout not reached and our busy state is busy - channel_busy_timeout = time.time() + 30 - while static.CHANNEL_BUSY and time.time() < channel_busy_timeout: - threading.Event().wait(0.01) - - # if channel busy timeout reached, stop connecting - if time.time() > channel_busy_timeout: - self.log.warning("[TNC] Channel busy, try again later...") - static.ARQ_SESSION_STATE = "failed" - self.send_data_to_socket_queue( - freedata="tnc-message", - arq="transmission", - status="failed", - reason="busy", - mycallsign=str(self.mycallsign, 'UTF-8'), - dxcallsign=str(self.dxcallsign, 'UTF-8'), - ) - static.ARQ_SESSION_STATE = "disconnected" - return False self.arq_open_data_channel(mode, n_frames_per_burst, mycallsign) @@ -1945,6 +1916,37 @@ class DATA: attempt=f"{str(attempt + 1)}/{str(self.data_channel_max_retries)}", ) + # Let's check if we have a busy channel and if we are not in a running arq session. + if static.CHANNEL_BUSY and not static.ARQ_STATE: + self.log.warning("[TNC] Channel busy, waiting until free...") + self.send_data_to_socket_queue( + freedata="tnc-message", + arq="transmission", + status="waiting", + mycallsign=str(self.mycallsign, 'UTF-8'), + dxcallsign=str(self.dxcallsign, 'UTF-8'), + ) + + # wait while timeout not reached and our busy state is busy + channel_busy_timeout = time.time() + 30 + while static.CHANNEL_BUSY and time.time() < channel_busy_timeout: + threading.Event().wait(0.01) + + # if channel busy timeout reached, stop connecting + if time.time() > channel_busy_timeout: + self.log.warning("[TNC] Channel busy, try again later...") + static.ARQ_SESSION_STATE = "failed" + self.send_data_to_socket_queue( + freedata="tnc-message", + arq="transmission", + status="failed", + reason="busy", + mycallsign=str(self.mycallsign, 'UTF-8'), + dxcallsign=str(self.dxcallsign, 'UTF-8'), + ) + static.ARQ_SESSION_STATE = "disconnected" + return False + self.enqueue_frame_for_tx([connection_frame], c2_mode=FREEDV_MODE.datac0.value, copies=1, repeat_delay=0) timeout = time.time() + 3