From c0c68fce4236fca1e0a2781a0e078b9afd145f23 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 25 Jan 2023 13:20:57 +0100 Subject: [PATCH] wait with command processing if already in arq state --- tnc/data_handler.py | 22 +++++++++++++++++++++- tnc/sock.py | 10 +++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index 938a91e0..cb379504 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -237,6 +237,25 @@ class DATA: while True: data = self.data_queue_transmit.get() + # if we are already in ARQ_STATE lets wait with processing data + # this should avoid weird toggle states where both stations + # stuck in IRS + # + # send transmission queued information once + if static.ARQ_STATE: + self.send_data_to_socket_queue( + freedata="tnc-message", + arq="transmission", + status="queued", + uuid=str(data[4], 'UTF-8'), + mycallsign=str(data[5], 'UTF-8'), + dxcallsign=str(data[6], 'UTF-8'), + ) + # now stay in while loop until state released + while static.ARQ_STATE: + threading.Event().wait(0.01) + self.log.debug(f"[TNC] TX DISPATCHER - waiting with processing command ", arq_state=static.ARQ_STATE) + # Dispatch commands known to command_dispatcher if data[0] in self.command_dispatcher: self.log.debug(f"[TNC] TX {self.command_dispatcher[data[0]][1]}...") @@ -475,12 +494,12 @@ class DATA: while static.CHANNEL_BUSY and time.time() < channel_busy_timeout: threading.Event().wait(0.01) - # Transmit frame self.enqueue_frame_for_tx([ack_frame], c2_mode=FREEDV_MODE.sig1.value) # reset burst timeout in case we had to wait too long self.burst_last_received = time.time() + def send_data_ack_frame(self, snr) -> None: """Build and send ACK frame for received DATA frame""" @@ -548,6 +567,7 @@ class DATA: self.enqueue_frame_for_tx([nack_frame], c2_mode=FREEDV_MODE.sig1.value, copies=6, repeat_delay=0) # reset burst timeout in case we had to wait too long self.burst_last_received = time.time() + def send_burst_nack_frame_watchdog(self, snr: bytes) -> None: """Build and send NACK frame for watchdog timeout""" diff --git a/tnc/sock.py b/tnc/sock.py index c02d0629..12f57049 100644 --- a/tnc/sock.py +++ b/tnc/sock.py @@ -25,7 +25,6 @@ import sys import threading import time import wave -from random import randrange import helpers import static import structlog @@ -470,15 +469,15 @@ def process_tnc_commands(data): if received_json["type"] == "arq" and received_json["command"] == "send_raw": static.BEACON_PAUSE = True - # we need to reject a command processing if already in arq state + # we need to warn if already in arq state if static.ARQ_STATE: command_response("send_raw", False) log.warning( - "[SCK] Send raw command execution error", + "[SCK] Send raw command execution warning", e="already in arq state", + i="command queued", command=received_json, ) - return False try: if not static.ARQ_SESSION: @@ -527,9 +526,6 @@ def process_tnc_commands(data): binarydata = base64.b64decode(base64data) - # wait some random time which acts as slightly as collision detection - helpers.wait(randrange(0, 20, 5) / 10.0) - DATA_QUEUE_TRANSMIT.put( ["ARQ_RAW", binarydata, mode, n_frames, arq_uuid, mycallsign, dxcallsign, attempts] )