diff --git a/tnc/data_handler.py b/tnc/data_handler.py index 52cba795..f96492eb 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -218,8 +218,18 @@ def arq_data_received(data_in:bytes, bytes_per_frame:int): else: static.INFO.append("ARQ;RECEIVING;FAILED") structlog.get_logger("structlog").warning("[TNC] ARQ | RX | DATA FRAME NOT SUCESSFULLY RECEIVED!", e="wrong crc", expected=data_frame_crc, received=data_frame_crc_received) - - + + # BUILDING NACK FRAME FOR DATA FRAME + nack_frame = bytearray(14) + nack_frame[:1] = bytes([63]) + nack_frame[1:2] = static.DXCALLSIGN_CRC8 + nack_frame[2:3] = static.MYCALLSIGN_CRC8 + + # TRANSMIT NACK FRAME FOR BURST + txbuffer = [nack_frame] + modem.transmit(mode=14, repeats=1, repeat_delay=0, frames=txbuffer) + + # And finally we do a cleanup of our buffers and states arq_cleanup() @@ -260,10 +270,8 @@ def arq_transmit(data_out:bytes, mode:int, n_frames_per_burst:int): static.ARQ_COMPRESSION_FACTOR = len(data_out) / len(data_frame_compressed) data_out = data_frame_compressed - - - tx_start_of_transmission = time.time() # reset statistics + tx_start_of_transmission = time.time() calculate_transfer_rate_tx(tx_start_of_transmission, 0, len(data_out)) # append a crc and beginn and end of file indicators @@ -403,6 +411,12 @@ def frame_ack_received(): DATA_CHANNEL_LAST_RECEIVED = int(time.time()) # we need to update our timeout timestamp +def frame_nack_received(): + static.INFO.append("ARQ;TRANSMITTING;FAILED") + arq_cleanup() + + + def burst_rpt_received(data_in:bytes): global RPT_REQUEST_RECEIVED global RPT_REQUEST_BUFFER diff --git a/tnc/modem.py b/tnc/modem.py index fc548c3f..817e9703 100644 --- a/tnc/modem.py +++ b/tnc/modem.py @@ -396,6 +396,11 @@ class RF(): logging.debug("REPEAT REQUEST RECEIVED....") data_handler.burst_rpt_received(bytes_out[:-2]) + # FRAME NACK + elif frametype == 63: + logging.debug("FRAME NOT ACK RECEIVED....") + data_handler.frame_nack_received(bytes_out[:-2]) + # CQ FRAME elif frametype == 200: logging.debug("CQ RECEIVED....") @@ -435,10 +440,12 @@ class RF(): data_handler.arq_received_channel_is_open(bytes_out[:-2]) # ARQ CONNECT ACK / KEEP ALIVE + # this is outdated and we may remove it elif frametype == 230: logging.debug("BEACON RECEIVED") data_handler.received_beacon(bytes_out[:-2]) + # TESTFRAMES elif frametype == 255: structlog.get_logger("structlog").debug("TESTFRAME RECEIVED", frame=bytes_out[:]) @@ -448,6 +455,7 @@ class RF(): # DO UNSYNC AFTER LAST BURST by checking the frame nums against the total frames per burst + # this should be changed to a timeout based unsync if frame == n_frames_per_burst: logging.info("LAST FRAME ---> UNSYNC") self.c_lib.freedv_set_sync(freedv, 0) # FORCE UNSYNC