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.arq_session_timeout = 30
|
||||||
self.session_connect_max_retries = 15
|
self.session_connect_max_retries = 15
|
||||||
|
|
||||||
|
# actual n retries of burst
|
||||||
|
self.tx_n_retry_of_burst = 0
|
||||||
|
|
||||||
self.transmission_uuid = ""
|
self.transmission_uuid = ""
|
||||||
|
|
||||||
self.data_channel_last_received = 0.0 # time of last "live sign" of a frame
|
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
|
# 3 bytes for the EOF End of File indicator in a data frame
|
||||||
self.data_frame_eof = b"EOF"
|
self.data_frame_eof = b"EOF"
|
||||||
|
|
||||||
|
self.tx_n_max_retries_per_burst = 50
|
||||||
self.rx_n_max_retries_per_burst = 50
|
self.rx_n_max_retries_per_burst = 50
|
||||||
self.n_retries_per_burst = 0
|
self.n_retries_per_burst = 0
|
||||||
|
|
||||||
|
@ -131,6 +135,10 @@ class DATA:
|
||||||
self.rx_frame_bof_received = False
|
self.rx_frame_bof_received = False
|
||||||
self.rx_frame_eof_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
|
self.transmission_timeout = 360 # transmission timeout in seconds
|
||||||
|
|
||||||
# Dictionary of functions and log messages used in process_data
|
# Dictionary of functions and log messages used in process_data
|
||||||
|
@ -302,8 +310,8 @@ class DATA:
|
||||||
):
|
):
|
||||||
|
|
||||||
# CHECK IF FRAMETYPE IS BETWEEN 10 and 50 ------------------------
|
# CHECK IF FRAMETYPE IS BETWEEN 10 and 50 ------------------------
|
||||||
frame = frametype - 10
|
# frame = frametype - 10
|
||||||
n_frames_per_burst = int.from_bytes(bytes(bytes_out[1:2]), "big")
|
# n_frames_per_burst = int.from_bytes(bytes(bytes_out[1:2]), "big")
|
||||||
|
|
||||||
# Dispatch activity based on received frametype
|
# Dispatch activity based on received frametype
|
||||||
if frametype in self.rx_dispatcher:
|
if frametype in self.rx_dispatcher:
|
||||||
|
@ -403,8 +411,8 @@ class DATA:
|
||||||
"""Build and send ACK frame for burst DATA frame"""
|
"""Build and send ACK frame for burst DATA frame"""
|
||||||
ack_frame = bytearray(self.length_sig_frame)
|
ack_frame = bytearray(self.length_sig_frame)
|
||||||
ack_frame[:1] = bytes([FR_TYPE.BURST_ACK.value])
|
ack_frame[:1] = bytes([FR_TYPE.BURST_ACK.value])
|
||||||
#ack_frame[1:4] = static.DXCALLSIGN_CRC
|
# ack_frame[1:4] = static.DXCALLSIGN_CRC
|
||||||
#ack_frame[4:7] = static.MYCALLSIGN_CRC
|
# ack_frame[4:7] = static.MYCALLSIGN_CRC
|
||||||
ack_frame[1:2] = self.session_id
|
ack_frame[1:2] = self.session_id
|
||||||
ack_frame[7:8] = bytes([int(snr)])
|
ack_frame[7:8] = bytes([int(snr)])
|
||||||
ack_frame[8:9] = bytes([int(self.speed_level)])
|
ack_frame[8:9] = bytes([int(self.speed_level)])
|
||||||
|
@ -417,8 +425,8 @@ class DATA:
|
||||||
ack_frame = bytearray(self.length_sig_frame)
|
ack_frame = bytearray(self.length_sig_frame)
|
||||||
ack_frame[:1] = bytes([FR_TYPE.FR_ACK.value])
|
ack_frame[:1] = bytes([FR_TYPE.FR_ACK.value])
|
||||||
ack_frame[1:2] = self.session_id
|
ack_frame[1:2] = self.session_id
|
||||||
#ack_frame[1:4] = static.DXCALLSIGN_CRC
|
# ack_frame[1:4] = static.DXCALLSIGN_CRC
|
||||||
#ack_frame[4:7] = static.MYCALLSIGN_CRC
|
# ack_frame[4:7] = static.MYCALLSIGN_CRC
|
||||||
ack_frame[7:8] = bytes([int(snr)])
|
ack_frame[7:8] = bytes([int(snr)])
|
||||||
ack_frame[8:9] = bytes([int(self.speed_level)])
|
ack_frame[8:9] = bytes([int(self.speed_level)])
|
||||||
|
|
||||||
|
@ -445,8 +453,8 @@ class DATA:
|
||||||
rpt_frame = bytearray(self.length_sig_frame)
|
rpt_frame = bytearray(self.length_sig_frame)
|
||||||
rpt_frame[:1] = bytes([FR_TYPE.FR_REPEAT.value])
|
rpt_frame[:1] = bytes([FR_TYPE.FR_REPEAT.value])
|
||||||
rpt_frame[1:2] = self.session_id
|
rpt_frame[1:2] = self.session_id
|
||||||
#rpt_frame[1:4] = static.DXCALLSIGN_CRC
|
# rpt_frame[1:4] = static.DXCALLSIGN_CRC
|
||||||
#rpt_frame[4:7] = static.MYCALLSIGN_CRC
|
# rpt_frame[4:7] = static.MYCALLSIGN_CRC
|
||||||
rpt_frame[7:13] = missing_frames
|
rpt_frame[7:13] = missing_frames
|
||||||
|
|
||||||
self.log.info("[TNC] ARQ | RX | Requesting", frames=missing_frames)
|
self.log.info("[TNC] ARQ | RX | Requesting", frames=missing_frames)
|
||||||
|
@ -458,8 +466,8 @@ class DATA:
|
||||||
nack_frame = bytearray(self.length_sig_frame)
|
nack_frame = bytearray(self.length_sig_frame)
|
||||||
nack_frame[:1] = bytes([FR_TYPE.FR_NACK.value])
|
nack_frame[:1] = bytes([FR_TYPE.FR_NACK.value])
|
||||||
nack_frame[1:2] = self.session_id
|
nack_frame[1:2] = self.session_id
|
||||||
#nack_frame[1:4] = static.DXCALLSIGN_CRC
|
# nack_frame[1:4] = static.DXCALLSIGN_CRC
|
||||||
#nack_frame[4:7] = static.MYCALLSIGN_CRC
|
# nack_frame[4:7] = static.MYCALLSIGN_CRC
|
||||||
nack_frame[7:8] = bytes([int(snr)])
|
nack_frame[7:8] = bytes([int(snr)])
|
||||||
nack_frame[8:9] = bytes([int(self.speed_level)])
|
nack_frame[8:9] = bytes([int(self.speed_level)])
|
||||||
|
|
||||||
|
@ -471,8 +479,8 @@ class DATA:
|
||||||
nack_frame = bytearray(self.length_sig_frame)
|
nack_frame = bytearray(self.length_sig_frame)
|
||||||
nack_frame[:1] = bytes([FR_TYPE.BURST_NACK.value])
|
nack_frame[:1] = bytes([FR_TYPE.BURST_NACK.value])
|
||||||
nack_frame[1:2] = self.session_id
|
nack_frame[1:2] = self.session_id
|
||||||
#nack_frame[1:4] = static.DXCALLSIGN_CRC
|
# nack_frame[1:4] = static.DXCALLSIGN_CRC
|
||||||
#nack_frame[4:7] = static.MYCALLSIGN_CRC
|
# nack_frame[4:7] = static.MYCALLSIGN_CRC
|
||||||
nack_frame[7:8] = bytes([int(snr)])
|
nack_frame[7:8] = bytes([int(snr)])
|
||||||
nack_frame[8:9] = bytes([int(self.speed_level)])
|
nack_frame[8:9] = bytes([int(self.speed_level)])
|
||||||
|
|
||||||
|
@ -484,8 +492,8 @@ class DATA:
|
||||||
disconnection_frame = bytearray(self.length_sig_frame)
|
disconnection_frame = bytearray(self.length_sig_frame)
|
||||||
disconnection_frame[:1] = bytes([FR_TYPE.ARQ_SESSION_CLOSE.value])
|
disconnection_frame[:1] = bytes([FR_TYPE.ARQ_SESSION_CLOSE.value])
|
||||||
disconnection_frame[1:2] = self.session_id
|
disconnection_frame[1:2] = self.session_id
|
||||||
#disconnection_frame[1:4] = static.DXCALLSIGN_CRC
|
# disconnection_frame[1:4] = static.DXCALLSIGN_CRC
|
||||||
#disconnection_frame[4:7] = static.MYCALLSIGN_CRC
|
# disconnection_frame[4:7] = static.MYCALLSIGN_CRC
|
||||||
disconnection_frame[7:13] = helpers.callsign_to_bytes(self.mycallsign)
|
disconnection_frame[7:13] = helpers.callsign_to_bytes(self.mycallsign)
|
||||||
|
|
||||||
self.enqueue_frame_for_tx(disconnection_frame, copies=5, repeat_delay=250)
|
self.enqueue_frame_for_tx(disconnection_frame, copies=5, repeat_delay=250)
|
||||||
|
@ -526,19 +534,19 @@ class DATA:
|
||||||
|
|
||||||
# Extract some important data from the frame
|
# Extract some important data from the frame
|
||||||
# Get sequence number of burst 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
|
# 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".
|
# 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.
|
# We need this later for counting the "Nones" to detect missing data.
|
||||||
# Check if burst buffer has expected length else create it
|
# Check if burst buffer has expected length else create it
|
||||||
if len(static.RX_BURST_BUFFER) != 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
|
static.RX_BURST_BUFFER = [None] * rx_n_frames_per_burst
|
||||||
|
|
||||||
# Append data to rx burst buffer
|
# Append data to rx burst buffer
|
||||||
# [frame_type][n_frames_per_burst][CRC24][CRC24]
|
# [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)
|
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
|
static.ARQ_SPEED_LEVEL = self.speed_level
|
||||||
|
|
||||||
|
|
||||||
# Update modes we are listening to
|
# Update modes we are listening to
|
||||||
self.set_listening_modes(self.mode_list[self.speed_level])
|
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)
|
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,
|
# We have "Nones" in our rx buffer,
|
||||||
# Check if we received last frame of burst - this is an indicator for missed frames.
|
# 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
|
# 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.
|
# TODO: See if a timeout on the send side with re-transmit last burst would help.
|
||||||
self.log.debug(
|
self.log.debug(
|
||||||
"[TNC] all frames in burst received:",
|
"[TNC] all frames in burst received:",
|
||||||
frame=RX_N_FRAME_OF_BURST,
|
frame=rx_n_frame_of_burst,
|
||||||
frames=RX_N_FRAMES_PER_BURST,
|
frames=rx_n_frames_per_burst,
|
||||||
)
|
)
|
||||||
self.send_retransmit_request_frame(freedv)
|
self.send_retransmit_request_frame(freedv)
|
||||||
self.calculate_transfer_rate_rx(
|
self.calculate_transfer_rate_rx(
|
||||||
|
@ -654,8 +661,8 @@ class DATA:
|
||||||
else:
|
else:
|
||||||
self.log.error(
|
self.log.error(
|
||||||
"[TNC] data_handler: Should not reach this point...",
|
"[TNC] data_handler: Should not reach this point...",
|
||||||
frame=RX_N_FRAME_OF_BURST,
|
frame=rx_n_frame_of_burst,
|
||||||
frames=RX_N_FRAMES_PER_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.
|
# 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
|
self.tx_n_retry_of_burst = 0 # retries we already sent data
|
||||||
# Maximum number of retries to send before declaring a frame is lost
|
# 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
|
# save len of data_out to TOTAL_BYTES for our statistics --> kBytes
|
||||||
# static.TOTAL_BYTES = round(len(data_out) / 1024, 2)
|
# static.TOTAL_BYTES = round(len(data_out) / 1024, 2)
|
||||||
|
@ -882,9 +882,9 @@ class DATA:
|
||||||
|
|
||||||
# Iterate through data_out buffer
|
# Iterate through data_out buffer
|
||||||
while not self.data_frame_ack_received and static.ARQ_STATE:
|
while not self.data_frame_ack_received and static.ARQ_STATE:
|
||||||
# we have TX_N_MAX_RETRIES_PER_BURST attempts for sending a burst
|
# we have self.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):
|
for self.tx_n_retry_of_burst in range(self.tx_n_max_retries_per_burst):
|
||||||
data_mode = mode
|
# data_mode = mode
|
||||||
# self.log.debug("[TNC] FIXED MODE:", mode=FREEDV_MODE(data_mode).name)
|
# 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
|
# we are doing a modulo check of transmission retries of the actual burst
|
||||||
|
@ -921,17 +921,17 @@ class DATA:
|
||||||
# Tempbuffer list for storing our data frames
|
# Tempbuffer list for storing our data frames
|
||||||
tempbuffer = []
|
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!
|
# 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 = bytearray()
|
||||||
# arqheader[:1] = bytes([FR_TYPE.BURST_01.value + i])
|
# arqheader[:1] = bytes([FR_TYPE.BURST_01.value + i])
|
||||||
arqheader[:1] = bytes([FR_TYPE.BURST_01.value])
|
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:3] = self.session_id
|
||||||
#arqheader[2:5] = static.DXCALLSIGN_CRC
|
# arqheader[2:5] = static.DXCALLSIGN_CRC
|
||||||
#arqheader[5:8] = static.MYCALLSIGN_CRC
|
# arqheader[5:8] = static.MYCALLSIGN_CRC
|
||||||
|
|
||||||
bufferposition_end = bufferposition + payload_per_frame - len(arqheader)
|
bufferposition_end = bufferposition + payload_per_frame - len(arqheader)
|
||||||
|
|
||||||
|
@ -955,7 +955,7 @@ class DATA:
|
||||||
self.log.info(
|
self.log.info(
|
||||||
"[TNC] ARQ | TX | FRAMES",
|
"[TNC] ARQ | TX | FRAMES",
|
||||||
mode=FREEDV_MODE(data_mode).name,
|
mode=FREEDV_MODE(data_mode).name,
|
||||||
fpb=TX_N_FRAMES_PER_BURST,
|
fpb=n_frames_per_burst,
|
||||||
retry=self.tx_n_retry_of_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)
|
self.enqueue_frame_for_tx(t_buf_item, c2_mode=data_mode)
|
||||||
|
|
||||||
# After transmission finished, wait for an ACK or RPT frame
|
# 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
|
# while (not self.burst_ack and not self.burst_nack and
|
||||||
# not self.rpt_request_received and not self.data_frame_ack_received and
|
# not self.rpt_request_received and not self.data_frame_ack_received and
|
||||||
# time.time() < burstacktimeout and static.ARQ_STATE):
|
# time.time() < burstacktimeout and static.ARQ_STATE):
|
||||||
# time.sleep(0.01)
|
# 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 (
|
while static.ARQ_STATE and not (
|
||||||
self.burst_ack
|
self.burst_ack
|
||||||
or self.burst_nack
|
or self.burst_nack
|
||||||
|
@ -1016,7 +1016,7 @@ class DATA:
|
||||||
self.log.debug(
|
self.log.debug(
|
||||||
"[TNC] ATTEMPT:",
|
"[TNC] ATTEMPT:",
|
||||||
retry=self.tx_n_retry_of_burst,
|
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,
|
overflows=static.BUFFER_OVERFLOW_COUNTER,
|
||||||
)
|
)
|
||||||
# End of FOR loop
|
# End of FOR loop
|
||||||
|
@ -1294,8 +1294,8 @@ class DATA:
|
||||||
connection_frame = bytearray(self.length_sig_frame)
|
connection_frame = bytearray(self.length_sig_frame)
|
||||||
connection_frame[:1] = bytes([FR_TYPE.ARQ_SESSION_OPEN.value])
|
connection_frame[:1] = bytes([FR_TYPE.ARQ_SESSION_OPEN.value])
|
||||||
connection_frame[1:2] = self.session_id
|
connection_frame[1:2] = self.session_id
|
||||||
#connection_frame[1:4] = static.DXCALLSIGN_CRC
|
# connection_frame[1:4] = static.DXCALLSIGN_CRC
|
||||||
#connection_frame[4:7] = static.MYCALLSIGN_CRC
|
# connection_frame[4:7] = static.MYCALLSIGN_CRC
|
||||||
connection_frame[7:13] = helpers.callsign_to_bytes(self.mycallsign)
|
connection_frame[7:13] = helpers.callsign_to_bytes(self.mycallsign)
|
||||||
|
|
||||||
while not static.ARQ_SESSION:
|
while not static.ARQ_SESSION:
|
||||||
|
@ -1414,7 +1414,8 @@ class DATA:
|
||||||
# is intended for this station.
|
# is intended for this station.
|
||||||
# Close the session if the CRC matches the remote station in static.
|
# Close the session if the CRC matches the remote station in static.
|
||||||
_valid_crc, _ = helpers.check_callsign(static.DXCALLSIGN, bytes(data_in[4:7]))
|
_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"
|
static.ARQ_SESSION_STATE = "disconnected"
|
||||||
helpers.add_to_heard_stations(
|
helpers.add_to_heard_stations(
|
||||||
static.DXCALLSIGN,
|
static.DXCALLSIGN,
|
||||||
|
@ -1452,9 +1453,8 @@ class DATA:
|
||||||
connection_frame = bytearray(self.length_sig_frame)
|
connection_frame = bytearray(self.length_sig_frame)
|
||||||
connection_frame[:1] = bytes([FR_TYPE.ARQ_SESSION_HB.value])
|
connection_frame[:1] = bytes([FR_TYPE.ARQ_SESSION_HB.value])
|
||||||
connection_frame[1:2] = self.session_id
|
connection_frame[1:2] = self.session_id
|
||||||
#connection_frame[1:4] = static.DXCALLSIGN_CRC
|
# connection_frame[1:4] = static.DXCALLSIGN_CRC
|
||||||
#connection_frame[4:7] = static.MYCALLSIGN_CRC
|
# connection_frame[4:7] = static.MYCALLSIGN_CRC
|
||||||
|
|
||||||
|
|
||||||
self.enqueue_frame_for_tx(connection_frame)
|
self.enqueue_frame_for_tx(connection_frame)
|
||||||
|
|
||||||
|
@ -1466,6 +1466,7 @@ class DATA:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# Accept session data if the DXCALLSIGN_CRC matches the station in static or session id.
|
# 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]))
|
_valid_session = helpers.check_session_id(self.session_id, bytes(data_in[1:2]))
|
||||||
if _valid_crc or _valid_session:
|
if _valid_crc or _valid_session:
|
||||||
self.log.debug("[TNC] Received session heartbeat")
|
self.log.debug("[TNC] Received session heartbeat")
|
||||||
|
@ -1507,6 +1508,8 @@ class DATA:
|
||||||
data_out:bytes:
|
data_out:bytes:
|
||||||
mode:int:
|
mode:int:
|
||||||
n_frames_per_burst:int:
|
n_frames_per_burst:int:
|
||||||
|
transmission_uuid:str:
|
||||||
|
mycallsign:bytes:
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
True if the data session was opened and the data was sent
|
True if the data session was opened and the data was sent
|
||||||
|
@ -1552,6 +1555,7 @@ class DATA:
|
||||||
Args:
|
Args:
|
||||||
mode:int:
|
mode:int:
|
||||||
n_frames_per_burst:int:
|
n_frames_per_burst:int:
|
||||||
|
mycallsign:bytes:
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
True if the data channel was opened successfully
|
True if the data channel was opened successfully
|
||||||
|
@ -1559,9 +1563,10 @@ class DATA:
|
||||||
"""
|
"""
|
||||||
self.is_IRS = False
|
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)
|
self.session_id = randbytes(1)
|
||||||
print(session_id)
|
print(self.session_id)
|
||||||
|
|
||||||
# Update data_channel timestamp
|
# Update data_channel timestamp
|
||||||
self.data_channel_last_received = int(time.time())
|
self.data_channel_last_received = int(time.time())
|
||||||
|
@ -1579,7 +1584,7 @@ class DATA:
|
||||||
connection_frame[1:4] = static.DXCALLSIGN_CRC
|
connection_frame[1:4] = static.DXCALLSIGN_CRC
|
||||||
connection_frame[4:7] = static.MYCALLSIGN_CRC
|
connection_frame[4:7] = static.MYCALLSIGN_CRC
|
||||||
connection_frame[7:13] = helpers.callsign_to_bytes(mycallsign)
|
connection_frame[7:13] = helpers.callsign_to_bytes(mycallsign)
|
||||||
#connection_frame[13:14] = bytes([n_frames_per_burst])
|
# connection_frame[13:14] = bytes([n_frames_per_burst])
|
||||||
connection_frame[13:14] = self.session_id
|
connection_frame[13:14] = self.session_id
|
||||||
|
|
||||||
while not static.ARQ_STATE:
|
while not static.ARQ_STATE:
|
||||||
|
@ -1771,8 +1776,8 @@ class DATA:
|
||||||
connection_frame = bytearray(self.length_sig_frame)
|
connection_frame = bytearray(self.length_sig_frame)
|
||||||
connection_frame[:1] = frametype
|
connection_frame[:1] = frametype
|
||||||
connection_frame[1:2] = self.session_id
|
connection_frame[1:2] = self.session_id
|
||||||
#connection_frame[1:4] = static.DXCALLSIGN_CRC
|
# connection_frame[1:4] = static.DXCALLSIGN_CRC
|
||||||
#connection_frame[4:7] = static.MYCALLSIGN_CRC
|
# connection_frame[4:7] = static.MYCALLSIGN_CRC
|
||||||
connection_frame[8:9] = bytes([self.speed_level])
|
connection_frame[8:9] = bytes([self.speed_level])
|
||||||
|
|
||||||
# For checking protocol version on the receiving side
|
# For checking protocol version on the receiving side
|
||||||
|
@ -2009,8 +2014,8 @@ class DATA:
|
||||||
self.log.warning("[TNC] Stopping transmission!")
|
self.log.warning("[TNC] Stopping transmission!")
|
||||||
stop_frame = bytearray(self.length_sig_frame)
|
stop_frame = bytearray(self.length_sig_frame)
|
||||||
stop_frame[:1] = bytes([FR_TYPE.ARQ_STOP.value])
|
stop_frame[:1] = bytes([FR_TYPE.ARQ_STOP.value])
|
||||||
#stop_frame[1:4] = static.DXCALLSIGN_CRC
|
# stop_frame[1:4] = static.DXCALLSIGN_CRC
|
||||||
#stop_frame[4:7] = static.MYCALLSIGN_CRC
|
# stop_frame[4:7] = static.MYCALLSIGN_CRC
|
||||||
stop_frame[1:2] = self.session_id
|
stop_frame[1:2] = self.session_id
|
||||||
stop_frame[7:13] = helpers.callsign_to_bytes(self.mycallsign)
|
stop_frame[7:13] = helpers.callsign_to_bytes(self.mycallsign)
|
||||||
|
|
||||||
|
@ -2141,7 +2146,7 @@ class DATA:
|
||||||
"""
|
"""
|
||||||
Transmit a CQ
|
Transmit a CQ
|
||||||
Args:
|
Args:
|
||||||
Nothing
|
self
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Nothing
|
Nothing
|
||||||
|
@ -2290,7 +2295,7 @@ class DATA:
|
||||||
(
|
(
|
||||||
receivedbytes
|
receivedbytes
|
||||||
* static.ARQ_COMPRESSION_FACTOR
|
* static.ARQ_COMPRESSION_FACTOR
|
||||||
/ (static.TOTAL_BYTES)
|
/ static.TOTAL_BYTES
|
||||||
)
|
)
|
||||||
* 100
|
* 100
|
||||||
),
|
),
|
||||||
|
@ -2302,7 +2307,7 @@ class DATA:
|
||||||
if receivedbytes > 0:
|
if receivedbytes > 0:
|
||||||
static.ARQ_BITS_PER_SECOND = int((receivedbytes * 8) / transmissiontime)
|
static.ARQ_BITS_PER_SECOND = int((receivedbytes * 8) / transmissiontime)
|
||||||
static.ARQ_BYTES_PER_MINUTE = int(
|
static.ARQ_BYTES_PER_MINUTE = int(
|
||||||
(receivedbytes) / (transmissiontime / 60)
|
receivedbytes / (transmissiontime / 60)
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -2356,7 +2361,7 @@ class DATA:
|
||||||
|
|
||||||
if sentbytes > 0:
|
if sentbytes > 0:
|
||||||
static.ARQ_BITS_PER_SECOND = int((sentbytes * 8) / transmissiontime)
|
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:
|
else:
|
||||||
static.ARQ_BITS_PER_SECOND = 0
|
static.ARQ_BITS_PER_SECOND = 0
|
||||||
|
|
Loading…
Reference in a new issue