mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
several pep improvements
This commit is contained in:
parent
5a8a563787
commit
7a682219cc
1 changed files with 72 additions and 67 deletions
|
@ -56,6 +56,9 @@ class DATA:
|
|||
self.arq_session_timeout = 30
|
||||
self.session_connect_max_retries = 15
|
||||
|
||||
# actual n retries of burst
|
||||
self.tx_n_retry_of_burst = 0
|
||||
|
||||
self.transmission_uuid = ""
|
||||
|
||||
self.data_channel_last_received = 0.0 # time of last "live sign" of a frame
|
||||
|
@ -75,6 +78,7 @@ class DATA:
|
|||
# 3 bytes for the EOF End of File indicator in a data frame
|
||||
self.data_frame_eof = b"EOF"
|
||||
|
||||
self.tx_n_max_retries_per_burst = 50
|
||||
self.rx_n_max_retries_per_burst = 50
|
||||
self.n_retries_per_burst = 0
|
||||
|
||||
|
@ -131,6 +135,10 @@ class DATA:
|
|||
self.rx_frame_bof_received = False
|
||||
self.rx_frame_eof_received = False
|
||||
|
||||
# TIMEOUTS
|
||||
self.burst_ack_timeout_seconds = 3.0 # timeout for burst acknowledges
|
||||
self.data_frame_ack_timeout_seconds = 3.0 # timeout for data frame acknowledges
|
||||
self.rpt_ack_timeout_seconds = 3.0 # timeout for rpt frame acknowledges
|
||||
self.transmission_timeout = 360 # transmission timeout in seconds
|
||||
|
||||
# Dictionary of functions and log messages used in process_data
|
||||
|
@ -302,8 +310,8 @@ class DATA:
|
|||
):
|
||||
|
||||
# CHECK IF FRAMETYPE IS BETWEEN 10 and 50 ------------------------
|
||||
frame = frametype - 10
|
||||
n_frames_per_burst = int.from_bytes(bytes(bytes_out[1:2]), "big")
|
||||
# frame = frametype - 10
|
||||
# n_frames_per_burst = int.from_bytes(bytes(bytes_out[1:2]), "big")
|
||||
|
||||
# Dispatch activity based on received frametype
|
||||
if frametype in self.rx_dispatcher:
|
||||
|
@ -526,19 +534,19 @@ class DATA:
|
|||
|
||||
# Extract some important data from the frame
|
||||
# Get sequence number of burst frame
|
||||
RX_N_FRAME_OF_BURST = int.from_bytes(bytes(data_in[:1]), "big") - 10
|
||||
rx_n_frame_of_burst = int.from_bytes(bytes(data_in[:1]), "big") - 10
|
||||
# Get number of bursts from received frame
|
||||
RX_N_FRAMES_PER_BURST = int.from_bytes(bytes(data_in[1:2]), "big")
|
||||
rx_n_frames_per_burst = int.from_bytes(bytes(data_in[1:2]), "big")
|
||||
|
||||
# The RX burst buffer needs to have a fixed length filled with "None".
|
||||
# We need this later for counting the "Nones" to detect missing data.
|
||||
# Check if burst buffer has expected length else create it
|
||||
if len(static.RX_BURST_BUFFER) != RX_N_FRAMES_PER_BURST:
|
||||
static.RX_BURST_BUFFER = [None] * RX_N_FRAMES_PER_BURST
|
||||
if len(static.RX_BURST_BUFFER) != rx_n_frames_per_burst:
|
||||
static.RX_BURST_BUFFER = [None] * rx_n_frames_per_burst
|
||||
|
||||
# Append data to rx burst buffer
|
||||
# [frame_type][n_frames_per_burst][CRC24][CRC24]
|
||||
static.RX_BURST_BUFFER[RX_N_FRAME_OF_BURST] = data_in[8:] # type: ignore
|
||||
static.RX_BURST_BUFFER[rx_n_frame_of_burst] = data_in[8:] # type: ignore
|
||||
|
||||
self.log.debug("[TNC] static.RX_BURST_BUFFER", buffer=static.RX_BURST_BUFFER)
|
||||
|
||||
|
@ -618,7 +626,6 @@ class DATA:
|
|||
)
|
||||
static.ARQ_SPEED_LEVEL = self.speed_level
|
||||
|
||||
|
||||
# Update modes we are listening to
|
||||
self.set_listening_modes(self.mode_list[self.speed_level])
|
||||
|
||||
|
@ -634,7 +641,7 @@ class DATA:
|
|||
self.rx_start_of_transmission, len(static.RX_FRAME_BUFFER)
|
||||
)
|
||||
|
||||
elif RX_N_FRAME_OF_BURST == RX_N_FRAMES_PER_BURST - 1:
|
||||
elif rx_n_frame_of_burst == rx_n_frames_per_burst - 1:
|
||||
# We have "Nones" in our rx buffer,
|
||||
# Check if we received last frame of burst - this is an indicator for missed frames.
|
||||
# With this way of doing this, we always MUST receive the last
|
||||
|
@ -642,8 +649,8 @@ class DATA:
|
|||
# TODO: See if a timeout on the send side with re-transmit last burst would help.
|
||||
self.log.debug(
|
||||
"[TNC] all frames in burst received:",
|
||||
frame=RX_N_FRAME_OF_BURST,
|
||||
frames=RX_N_FRAMES_PER_BURST,
|
||||
frame=rx_n_frame_of_burst,
|
||||
frames=rx_n_frames_per_burst,
|
||||
)
|
||||
self.send_retransmit_request_frame(freedv)
|
||||
self.calculate_transfer_rate_rx(
|
||||
|
@ -654,8 +661,8 @@ class DATA:
|
|||
else:
|
||||
self.log.error(
|
||||
"[TNC] data_handler: Should not reach this point...",
|
||||
frame=RX_N_FRAME_OF_BURST,
|
||||
frames=RX_N_FRAMES_PER_BURST,
|
||||
frame=rx_n_frame_of_burst,
|
||||
frames=rx_n_frames_per_burst,
|
||||
)
|
||||
|
||||
# We have a BOF and EOF flag in our data. If we received both we received our frame.
|
||||
|
@ -824,13 +831,6 @@ class DATA:
|
|||
|
||||
self.tx_n_retry_of_burst = 0 # retries we already sent data
|
||||
# Maximum number of retries to send before declaring a frame is lost
|
||||
TX_N_MAX_RETRIES_PER_BURST = 50
|
||||
TX_N_FRAMES_PER_BURST = n_frames_per_burst # amount of n frames per burst
|
||||
|
||||
# TIMEOUTS
|
||||
BURST_ACK_TIMEOUT_SECONDS = 3.0 # timeout for burst acknowledges
|
||||
DATA_FRAME_ACK_TIMEOUT_SECONDS = 3.0 # timeout for data frame acknowledges
|
||||
RPT_ACK_TIMEOUT_SECONDS = 3.0 # timeout for rpt frame acknowledges
|
||||
|
||||
# save len of data_out to TOTAL_BYTES for our statistics --> kBytes
|
||||
# static.TOTAL_BYTES = round(len(data_out) / 1024, 2)
|
||||
|
@ -882,9 +882,9 @@ class DATA:
|
|||
|
||||
# Iterate through data_out buffer
|
||||
while not self.data_frame_ack_received and static.ARQ_STATE:
|
||||
# we have TX_N_MAX_RETRIES_PER_BURST attempts for sending a burst
|
||||
for self.tx_n_retry_of_burst in range(TX_N_MAX_RETRIES_PER_BURST):
|
||||
data_mode = mode
|
||||
# we have self.tx_n_max_retries_per_burst attempts for sending a burst
|
||||
for self.tx_n_retry_of_burst in range(self.tx_n_max_retries_per_burst):
|
||||
# data_mode = mode
|
||||
# self.log.debug("[TNC] FIXED MODE:", mode=FREEDV_MODE(data_mode).name)
|
||||
|
||||
# we are doing a modulo check of transmission retries of the actual burst
|
||||
|
@ -921,14 +921,14 @@ class DATA:
|
|||
# Tempbuffer list for storing our data frames
|
||||
tempbuffer = []
|
||||
|
||||
# Append data frames with TX_N_FRAMES_PER_BURST to tempbuffer
|
||||
# Append data frames with n_frames_per_burst to tempbuffer
|
||||
# TODO: this part needs a complete rewrite!
|
||||
# TX_N_FRAMES_PER_BURST = 1 is working
|
||||
# n_frames_per_burst = 1 is working
|
||||
|
||||
arqheader = bytearray()
|
||||
# arqheader[:1] = bytes([FR_TYPE.BURST_01.value + i])
|
||||
arqheader[:1] = bytes([FR_TYPE.BURST_01.value])
|
||||
arqheader[1:2] = bytes([TX_N_FRAMES_PER_BURST])
|
||||
arqheader[1:2] = bytes([n_frames_per_burst])
|
||||
arqheader[2:3] = self.session_id
|
||||
# arqheader[2:5] = static.DXCALLSIGN_CRC
|
||||
# arqheader[5:8] = static.MYCALLSIGN_CRC
|
||||
|
@ -955,7 +955,7 @@ class DATA:
|
|||
self.log.info(
|
||||
"[TNC] ARQ | TX | FRAMES",
|
||||
mode=FREEDV_MODE(data_mode).name,
|
||||
fpb=TX_N_FRAMES_PER_BURST,
|
||||
fpb=n_frames_per_burst,
|
||||
retry=self.tx_n_retry_of_burst,
|
||||
)
|
||||
|
||||
|
@ -963,13 +963,13 @@ class DATA:
|
|||
self.enqueue_frame_for_tx(t_buf_item, c2_mode=data_mode)
|
||||
|
||||
# After transmission finished, wait for an ACK or RPT frame
|
||||
# burstacktimeout = time.time() + BURST_ACK_TIMEOUT_SECONDS + 100
|
||||
# burstacktimeout = time.time() + self.burst_ack_timeout_seconds + 100
|
||||
# while (not self.burst_ack and not self.burst_nack and
|
||||
# not self.rpt_request_received and not self.data_frame_ack_received and
|
||||
# time.time() < burstacktimeout and static.ARQ_STATE):
|
||||
# time.sleep(0.01)
|
||||
|
||||
# burstacktimeout = time.time() + BURST_ACK_TIMEOUT_SECONDS + 100
|
||||
# burstacktimeout = time.time() + self.burst_ack_timeout_seconds + 100
|
||||
while static.ARQ_STATE and not (
|
||||
self.burst_ack
|
||||
or self.burst_nack
|
||||
|
@ -1016,7 +1016,7 @@ class DATA:
|
|||
self.log.debug(
|
||||
"[TNC] ATTEMPT:",
|
||||
retry=self.tx_n_retry_of_burst,
|
||||
maxretries=TX_N_MAX_RETRIES_PER_BURST,
|
||||
maxretries=self.tx_n_max_retries_per_burst,
|
||||
overflows=static.BUFFER_OVERFLOW_COUNTER,
|
||||
)
|
||||
# End of FOR loop
|
||||
|
@ -1414,7 +1414,8 @@ class DATA:
|
|||
# is intended for this station.
|
||||
# Close the session if the CRC matches the remote station in static.
|
||||
_valid_crc, _ = helpers.check_callsign(static.DXCALLSIGN, bytes(data_in[4:7]))
|
||||
if _valid_crc:
|
||||
_valid_session = helpers.check_session_id(self.session_id, bytes(data_in[1:2]))
|
||||
if _valid_crc or _valid_session:
|
||||
static.ARQ_SESSION_STATE = "disconnected"
|
||||
helpers.add_to_heard_stations(
|
||||
static.DXCALLSIGN,
|
||||
|
@ -1455,7 +1456,6 @@ class DATA:
|
|||
# connection_frame[1:4] = static.DXCALLSIGN_CRC
|
||||
# connection_frame[4:7] = static.MYCALLSIGN_CRC
|
||||
|
||||
|
||||
self.enqueue_frame_for_tx(connection_frame)
|
||||
|
||||
def received_session_heartbeat(self, data_in: bytes) -> None:
|
||||
|
@ -1466,6 +1466,7 @@ class DATA:
|
|||
|
||||
"""
|
||||
# Accept session data if the DXCALLSIGN_CRC matches the station in static or session id.
|
||||
_valid_crc, _ = helpers.check_callsign(static.DXCALLSIGN, bytes(data_in[4:7]))
|
||||
_valid_session = helpers.check_session_id(self.session_id, bytes(data_in[1:2]))
|
||||
if _valid_crc or _valid_session:
|
||||
self.log.debug("[TNC] Received session heartbeat")
|
||||
|
@ -1507,6 +1508,8 @@ class DATA:
|
|||
data_out:bytes:
|
||||
mode:int:
|
||||
n_frames_per_burst:int:
|
||||
transmission_uuid:str:
|
||||
mycallsign:bytes:
|
||||
|
||||
Returns:
|
||||
True if the data session was opened and the data was sent
|
||||
|
@ -1552,6 +1555,7 @@ class DATA:
|
|||
Args:
|
||||
mode:int:
|
||||
n_frames_per_burst:int:
|
||||
mycallsign:bytes:
|
||||
|
||||
Returns:
|
||||
True if the data channel was opened successfully
|
||||
|
@ -1559,9 +1563,10 @@ class DATA:
|
|||
"""
|
||||
self.is_IRS = False
|
||||
|
||||
# init a new random session id
|
||||
# init a new random session id if we are not in an arq session
|
||||
if not static.ARQ_SESSION:
|
||||
self.session_id = randbytes(1)
|
||||
print(session_id)
|
||||
print(self.session_id)
|
||||
|
||||
# Update data_channel timestamp
|
||||
self.data_channel_last_received = int(time.time())
|
||||
|
@ -2141,7 +2146,7 @@ class DATA:
|
|||
"""
|
||||
Transmit a CQ
|
||||
Args:
|
||||
Nothing
|
||||
self
|
||||
|
||||
Returns:
|
||||
Nothing
|
||||
|
@ -2290,7 +2295,7 @@ class DATA:
|
|||
(
|
||||
receivedbytes
|
||||
* static.ARQ_COMPRESSION_FACTOR
|
||||
/ (static.TOTAL_BYTES)
|
||||
/ static.TOTAL_BYTES
|
||||
)
|
||||
* 100
|
||||
),
|
||||
|
@ -2302,7 +2307,7 @@ class DATA:
|
|||
if receivedbytes > 0:
|
||||
static.ARQ_BITS_PER_SECOND = int((receivedbytes * 8) / transmissiontime)
|
||||
static.ARQ_BYTES_PER_MINUTE = int(
|
||||
(receivedbytes) / (transmissiontime / 60)
|
||||
receivedbytes / (transmissiontime / 60)
|
||||
)
|
||||
|
||||
else:
|
||||
|
@ -2356,7 +2361,7 @@ class DATA:
|
|||
|
||||
if sentbytes > 0:
|
||||
static.ARQ_BITS_PER_SECOND = int((sentbytes * 8) / transmissiontime)
|
||||
static.ARQ_BYTES_PER_MINUTE = int((sentbytes) / (transmissiontime / 60))
|
||||
static.ARQ_BYTES_PER_MINUTE = int(sentbytes / (transmissiontime / 60))
|
||||
|
||||
else:
|
||||
static.ARQ_BITS_PER_SECOND = 0
|
||||
|
|
Loading…
Reference in a new issue