From ab44e18e3e37e71c5ebee0e53a2797def9d69d78 Mon Sep 17 00:00:00 2001 From: dj2ls Date: Thu, 29 Dec 2022 17:57:55 +0100 Subject: [PATCH] check channel busy state for ack/nack --- tnc/data_handler.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index 6ba90080..7bd724f7 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -470,6 +470,11 @@ class DATA: ack_frame[2:3] = helpers.snr_to_bytes(snr) ack_frame[3:4] = bytes([int(self.speed_level)]) + # wait while timeout not reached and our busy state is busy + channel_busy_timeout = time.time() + 5 + 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) @@ -485,6 +490,11 @@ class DATA: # ack_frame[7:8] = bytes([int(snr)]) # ack_frame[8:9] = bytes([int(self.speed_level)]) + # wait while timeout not reached and our busy state is busy + channel_busy_timeout = time.time() + 5 + while static.CHANNEL_BUSY and time.time() < channel_busy_timeout: + threading.Event().wait(0.01) + # Transmit frame # TODO: Do we have to send , self.send_ident_frame(False) ? # self.enqueue_frame_for_tx([ack_frame, self.send_ident_frame(False)], c2_mode=FREEDV_MODE.sig1.value, copies=3, repeat_delay=0) @@ -532,7 +542,14 @@ class DATA: # TRANSMIT NACK FRAME FOR BURST # TODO: Do we have to send ident frame? # self.enqueue_frame_for_tx([ack_frame, self.send_ident_frame(False)], c2_mode=FREEDV_MODE.sig1.value, copies=3, repeat_delay=0) + + # wait while timeout not reached and our busy state is busy + channel_busy_timeout = time.time() + 5 + while static.CHANNEL_BUSY and time.time() < channel_busy_timeout: + threading.Event().wait(0.01) + self.enqueue_frame_for_tx([nack_frame], c2_mode=FREEDV_MODE.sig1.value, copies=6, repeat_delay=0) + def send_burst_nack_frame_watchdog(self, snr: bytes) -> None: """Build and send NACK frame for watchdog timeout""" @@ -549,6 +566,11 @@ class DATA: nack_frame[2:3] = helpers.snr_to_bytes(snr) nack_frame[3:4] = bytes([int(self.speed_level)]) + # wait while timeout not reached and our busy state is busy + channel_busy_timeout = time.time() + 5 + while static.CHANNEL_BUSY and time.time() < channel_busy_timeout: + threading.Event().wait(0.01) + # TRANSMIT NACK FRAME FOR BURST self.enqueue_frame_for_tx([nack_frame], c2_mode=FREEDV_MODE.sig1.value, copies=1, repeat_delay=0) @@ -563,6 +585,12 @@ class DATA: # TODO: We need to add the ident frame feature with a seperate PR after publishing latest protocol # TODO: We need to wait some time between last arq related signalling frame and ident frame # TODO: Maybe about 500ms - 1500ms to avoid confusion and too much PTT toggles + + # wait while timeout not reached and our busy state is busy + channel_busy_timeout = time.time() + 5 + while static.CHANNEL_BUSY and time.time() < channel_busy_timeout: + threading.Event().wait(0.01) + self.enqueue_frame_for_tx([disconnection_frame], c2_mode=FREEDV_MODE.sig0.value, copies=6, repeat_delay=0) def arq_data_received(