mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
pep8 improvements and some cleanup, also potential fix of buffer position
This commit is contained in:
parent
a0a6bae6b4
commit
8fc1cc6243
|
@ -26,7 +26,7 @@ import structlog
|
||||||
import stats
|
import stats
|
||||||
import ujson as json
|
import ujson as json
|
||||||
from codec2 import FREEDV_MODE, FREEDV_MODE_USED_SLOTS
|
from codec2 import FREEDV_MODE, FREEDV_MODE_USED_SLOTS
|
||||||
from exceptions import NoCallsign
|
# from exceptions import NoCallsign
|
||||||
from queues import DATA_QUEUE_RECEIVED, DATA_QUEUE_TRANSMIT, RX_BUFFER
|
from queues import DATA_QUEUE_RECEIVED, DATA_QUEUE_TRANSMIT, RX_BUFFER
|
||||||
from static import FRAME_TYPE as FR_TYPE
|
from static import FRAME_TYPE as FR_TYPE
|
||||||
|
|
||||||
|
@ -346,18 +346,14 @@ class DATA:
|
||||||
# [0] bytes
|
# [0] bytes
|
||||||
# [1] freedv instance
|
# [1] freedv instance
|
||||||
# [2] bytes_per_frame
|
# [2] bytes_per_frame
|
||||||
self.process_data(
|
self.process_data(bytes_out=data[0])
|
||||||
bytes_out=data[0], freedv=data[1], bytes_per_frame=data[2]
|
|
||||||
)
|
|
||||||
|
|
||||||
def process_data(self, bytes_out, freedv, bytes_per_frame: int) -> None:
|
def process_data(self, bytes_out) -> None:
|
||||||
"""
|
"""
|
||||||
Process incoming data and decide what to do with the frame.
|
Process incoming data and decide what to do with the frame.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
bytes_out:
|
bytes_out:
|
||||||
freedv:
|
|
||||||
bytes_per_frame:
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
|
@ -414,9 +410,7 @@ class DATA:
|
||||||
snr = static.SNR
|
snr = static.SNR
|
||||||
self.log.debug("[TNC] RX SNR", snr=snr)
|
self.log.debug("[TNC] RX SNR", snr=snr)
|
||||||
# send payload data to arq checker without CRC16
|
# send payload data to arq checker without CRC16
|
||||||
self.arq_data_received(
|
self.arq_data_received(bytes(bytes_out[:-2]), snr)
|
||||||
bytes(bytes_out[:-2]), bytes_per_frame, snr, freedv
|
|
||||||
)
|
|
||||||
|
|
||||||
# if we received the last frame of a burst or the last remaining rpt frame, do a modem unsync
|
# if we received the last frame of a burst or the last remaining rpt frame, do a modem unsync
|
||||||
# if static.RX_BURST_BUFFER.count(None) <= 1 or (frame+1) == n_frames_per_burst:
|
# if static.RX_BURST_BUFFER.count(None) <= 1 or (frame+1) == n_frames_per_burst:
|
||||||
|
@ -463,7 +457,11 @@ class DATA:
|
||||||
print(frame_to_tx[0])
|
print(frame_to_tx[0])
|
||||||
print(frame_to_tx)
|
print(frame_to_tx)
|
||||||
frame_type = FR_TYPE(int.from_bytes(frame_to_tx[0][:1], byteorder="big")).name
|
frame_type = FR_TYPE(int.from_bytes(frame_to_tx[0][:1], byteorder="big")).name
|
||||||
self.log.debug("[TNC] enqueue_frame_for_tx", c2_mode=FREEDV_MODE(c2_mode).name, data=frame_to_tx, type=frame_type)
|
self.log.debug("[TNC] enqueue_frame_for_tx",
|
||||||
|
c2_mode=FREEDV_MODE(c2_mode).name,
|
||||||
|
data=frame_to_tx,
|
||||||
|
type=frame_type
|
||||||
|
)
|
||||||
|
|
||||||
# Set the TRANSMITTING flag before adding an object to the transmit queue
|
# Set the TRANSMITTING flag before adding an object to the transmit queue
|
||||||
# TODO: This is not that nice, we could improve this somehow
|
# TODO: This is not that nice, we could improve this somehow
|
||||||
|
@ -511,7 +509,7 @@ class DATA:
|
||||||
# finally push data to our network queue
|
# finally push data to our network queue
|
||||||
sock.SOCKET_QUEUE.put(json_data_out)
|
sock.SOCKET_QUEUE.put(json_data_out)
|
||||||
|
|
||||||
def send_ident_frame(self, transmit) -> None:
|
def send_ident_frame(self, transmit) -> bytearray:
|
||||||
"""Build and send IDENT frame """
|
"""Build and send IDENT frame """
|
||||||
ident_frame = bytearray(self.length_sig1_frame)
|
ident_frame = bytearray(self.length_sig1_frame)
|
||||||
ident_frame[:1] = bytes([FR_TYPE.IDENT.value])
|
ident_frame[:1] = bytes([FR_TYPE.IDENT.value])
|
||||||
|
@ -541,7 +539,6 @@ class DATA:
|
||||||
# Transmit frame
|
# Transmit frame
|
||||||
self.enqueue_frame_for_tx([ack_frame], c2_mode=FREEDV_MODE.sig1.value)
|
self.enqueue_frame_for_tx([ack_frame], c2_mode=FREEDV_MODE.sig1.value)
|
||||||
|
|
||||||
|
|
||||||
def send_data_ack_frame(self, snr) -> None:
|
def send_data_ack_frame(self, snr) -> None:
|
||||||
"""Build and send ACK frame for received DATA frame"""
|
"""Build and send ACK frame for received DATA frame"""
|
||||||
|
|
||||||
|
@ -559,13 +556,19 @@ class DATA:
|
||||||
self.burst_last_received = time.time() + channel_busy_timeout + 8
|
self.burst_last_received = time.time() + channel_busy_timeout + 8
|
||||||
# Transmit frame
|
# Transmit frame
|
||||||
# TODO: Do we have to send , self.send_ident_frame(False) ?
|
# 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)
|
# self.enqueue_frame_for_tx([ack_frame, self.send_ident_frame(False)],
|
||||||
self.enqueue_frame_for_tx([ack_frame], c2_mode=FREEDV_MODE.sig1.value, copies=3, repeat_delay=0)
|
# c2_mode=FREEDV_MODE.sig1.value,
|
||||||
|
# copies=3,
|
||||||
|
# repeat_delay=0)
|
||||||
|
|
||||||
|
self.enqueue_frame_for_tx([ack_frame], c2_mode=FREEDV_MODE.sig1.value, copies=3, repeat_delay=0)
|
||||||
|
|
||||||
def send_retransmit_request_frame(self) -> None:
|
def send_retransmit_request_frame(self) -> None:
|
||||||
# check where a None is in our burst buffer and do frame+1, because lists start at 0
|
# check where a None is in our burst buffer and do frame+1, because lists start at 0
|
||||||
# FIXME: Check to see if there's a `frame - 1` in the receive portion. Remove both if there is.
|
# FIXME: Check to see if there's a `frame - 1` in the receive portion. Remove both if there is.
|
||||||
|
|
||||||
|
self.burst_rpt_counter += 1
|
||||||
|
|
||||||
print(static.RX_BURST_BUFFER)
|
print(static.RX_BURST_BUFFER)
|
||||||
missing_frames = [
|
missing_frames = [
|
||||||
frame + 1
|
frame + 1
|
||||||
|
@ -582,7 +585,7 @@ class DATA:
|
||||||
# Transmit frame
|
# Transmit frame
|
||||||
self.enqueue_frame_for_tx([rpt_frame], c2_mode=FREEDV_MODE.sig1.value, copies=1, repeat_delay=0)
|
self.enqueue_frame_for_tx([rpt_frame], c2_mode=FREEDV_MODE.sig1.value, copies=1, repeat_delay=0)
|
||||||
|
|
||||||
def send_burst_nack_frame(self, snr: bytes) -> None:
|
def send_burst_nack_frame(self, snr: float) -> None:
|
||||||
"""Build and send NACK frame for received DATA frame"""
|
"""Build and send NACK frame for received DATA frame"""
|
||||||
|
|
||||||
nack_frame = bytearray(self.length_sig1_frame)
|
nack_frame = bytearray(self.length_sig1_frame)
|
||||||
|
@ -592,11 +595,13 @@ class DATA:
|
||||||
nack_frame[3:4] = bytes([int(self.speed_level)])
|
nack_frame[3:4] = bytes([int(self.speed_level)])
|
||||||
nack_frame[4:8] = len(static.RX_FRAME_BUFFER).to_bytes(4, byteorder="big")
|
nack_frame[4:8] = len(static.RX_FRAME_BUFFER).to_bytes(4, byteorder="big")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# TRANSMIT NACK FRAME FOR BURST
|
# TRANSMIT NACK FRAME FOR BURST
|
||||||
# TODO: Do we have to send ident frame?
|
# 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)
|
# 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
|
# wait while timeout not reached and our busy state is busy
|
||||||
channel_busy_timeout = time.time() + 5
|
channel_busy_timeout = time.time() + 5
|
||||||
|
@ -607,7 +612,7 @@ class DATA:
|
||||||
# reset burst timeout in case we had to wait too long
|
# reset burst timeout in case we had to wait too long
|
||||||
self.burst_last_received = time.time()
|
self.burst_last_received = time.time()
|
||||||
|
|
||||||
def send_burst_nack_frame_watchdog(self, snr: bytes, tx_n_frames_per_burst) -> None:
|
def send_burst_nack_frame_watchdog(self, snr: float, tx_n_frames_per_burst) -> None:
|
||||||
"""Build and send NACK frame for watchdog timeout"""
|
"""Build and send NACK frame for watchdog timeout"""
|
||||||
|
|
||||||
# increment nack counter for transmission stats
|
# increment nack counter for transmission stats
|
||||||
|
@ -643,7 +648,12 @@ class DATA:
|
||||||
disconnection_frame[1:2] = self.session_id
|
disconnection_frame[1:2] = self.session_id
|
||||||
disconnection_frame[2:5] = static.DXCALLSIGN_CRC
|
disconnection_frame[2:5] = static.DXCALLSIGN_CRC
|
||||||
# TODO: Needed? disconnection_frame[7:13] = helpers.callsign_to_bytes(self.mycallsign)
|
# TODO: Needed? disconnection_frame[7:13] = helpers.callsign_to_bytes(self.mycallsign)
|
||||||
# self.enqueue_frame_for_tx([disconnection_frame, self.send_ident_frame(False)], c2_mode=FREEDV_MODE.sig0.value, copies=5, repeat_delay=0)
|
# self.enqueue_frame_for_tx([disconnection_frame,
|
||||||
|
# self.send_ident_frame(False)],
|
||||||
|
# c2_mode=FREEDV_MODE.sig0.value,
|
||||||
|
# copies=5,
|
||||||
|
# repeat_delay=0
|
||||||
|
# )
|
||||||
# TODO: We need to add the ident frame feature with a seperate PR after publishing latest protocol
|
# 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: 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
|
# TODO: Maybe about 500ms - 1500ms to avoid confusion and too much PTT toggles
|
||||||
|
@ -656,15 +666,12 @@ class DATA:
|
||||||
self.enqueue_frame_for_tx([disconnection_frame], c2_mode=FREEDV_MODE.sig0.value, copies=3, repeat_delay=0)
|
self.enqueue_frame_for_tx([disconnection_frame], c2_mode=FREEDV_MODE.sig0.value, copies=3, repeat_delay=0)
|
||||||
|
|
||||||
def arq_data_received(
|
def arq_data_received(
|
||||||
self, data_in: bytes, bytes_per_frame: int, snr: float, freedv
|
self, data_in: bytes, snr: float
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
data_in:bytes:
|
data_in:bytes:
|
||||||
bytes_per_frame:int:
|
|
||||||
snr:float:
|
snr:float:
|
||||||
freedv:
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
# We've arrived here from process_data which already checked that the frame
|
# We've arrived here from process_data which already checked that the frame
|
||||||
|
@ -673,7 +680,10 @@ class DATA:
|
||||||
|
|
||||||
# only process data if we are in ARQ and BUSY state else return to quit
|
# only process data if we are in ARQ and BUSY state else return to quit
|
||||||
if not static.ARQ_STATE and static.TNC_STATE not in ["BUSY"]:
|
if not static.ARQ_STATE and static.TNC_STATE not in ["BUSY"]:
|
||||||
self.log.warning("[TNC] wrong tnc state - dropping data", arq_state=static.ARQ_STATE, tnc_state=static.TNC_STATE)
|
self.log.warning("[TNC] wrong tnc state - dropping data",
|
||||||
|
arq_state=static.ARQ_STATE,
|
||||||
|
tnc_state=static.TNC_STATE
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.arq_file_transfer = True
|
self.arq_file_transfer = True
|
||||||
|
@ -700,7 +710,6 @@ class DATA:
|
||||||
# Append data to rx burst buffer
|
# Append data to rx burst buffer
|
||||||
static.RX_BURST_BUFFER[self.rx_n_frame_of_burst] = data_in[self.arq_burst_header_size:] # type: ignore
|
static.RX_BURST_BUFFER[self.rx_n_frame_of_burst] = data_in[self.arq_burst_header_size:] # type: ignore
|
||||||
|
|
||||||
|
|
||||||
static.DXGRID = b'------'
|
static.DXGRID = b'------'
|
||||||
helpers.add_to_heard_stations(
|
helpers.add_to_heard_stations(
|
||||||
static.DXCALLSIGN,
|
static.DXCALLSIGN,
|
||||||
|
@ -801,8 +810,7 @@ class DATA:
|
||||||
and not self.rx_frame_eof_received
|
and not self.rx_frame_eof_received
|
||||||
and data_in.find(self.data_frame_eof) < 0
|
and data_in.find(self.data_frame_eof) < 0
|
||||||
):
|
):
|
||||||
|
self.arq_calculate_speed_level()
|
||||||
self.arq_calculate_speed_level(snr)
|
|
||||||
|
|
||||||
self.data_channel_last_received = int(time.time()) + 6 + 6
|
self.data_channel_last_received = int(time.time()) + 6 + 6
|
||||||
self.burst_last_received = int(time.time()) + 6 + 6
|
self.burst_last_received = int(time.time()) + 6 + 6
|
||||||
|
@ -858,12 +866,13 @@ class DATA:
|
||||||
# frames=self.rx_n_frames_per_burst,
|
# frames=self.rx_n_frames_per_burst,
|
||||||
# )
|
# )
|
||||||
|
|
||||||
#else:
|
# send repeat without waiting for timeout
|
||||||
# self.log.error(
|
# --> this should speed up requesting instead of waiting
|
||||||
# "[TNC] data_handler: Should not reach this point...",
|
elif self.rx_n_frame_of_burst == self.rx_n_frames_per_burst and self.burst_rpt_counter == 0:
|
||||||
# frame=self.rx_n_frame_of_burst + 1,
|
frames_left = static.RX_BURST_BUFFER.count(None)
|
||||||
# frames=self.rx_n_frames_per_burst,
|
self.burst_last_received = time.time() + self.time_list[self.speed_level] * frames_left
|
||||||
# )
|
self.send_retransmit_request_frame()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.log.warning(
|
self.log.warning(
|
||||||
"[TNC] data_handler: missing data in burst buffer...",
|
"[TNC] data_handler: missing data in burst buffer...",
|
||||||
|
@ -939,7 +948,10 @@ class DATA:
|
||||||
if static.ENABLE_STATS:
|
if static.ENABLE_STATS:
|
||||||
self.stats.push(frame_nack_counter=self.frame_nack_counter, status="wrong_crc", duration=duration)
|
self.stats.push(frame_nack_counter=self.frame_nack_counter, status="wrong_crc", duration=duration)
|
||||||
|
|
||||||
self.log.info("[TNC] ARQ | RX | Sending NACK", finished=static.ARQ_SECONDS_UNTIL_FINISH, bytesperminute=static.ARQ_BYTES_PER_MINUTE)
|
self.log.info("[TNC] ARQ | RX | Sending NACK",
|
||||||
|
finished=static.ARQ_SECONDS_UNTIL_FINISH,
|
||||||
|
bytesperminute=static.ARQ_BYTES_PER_MINUTE
|
||||||
|
)
|
||||||
self.send_burst_nack_frame(snr)
|
self.send_burst_nack_frame(snr)
|
||||||
|
|
||||||
# Update arq_session timestamp
|
# Update arq_session timestamp
|
||||||
|
@ -982,8 +994,7 @@ class DATA:
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def arq_calculate_speed_level(self):
|
||||||
def arq_calculate_speed_level(self, snr):
|
|
||||||
self.frame_received_counter += 1
|
self.frame_received_counter += 1
|
||||||
# try increasing speed level only if we had two successful decodes
|
# try increasing speed level only if we had two successful decodes
|
||||||
if self.frame_received_counter >= 2:
|
if self.frame_received_counter >= 2:
|
||||||
|
@ -995,7 +1006,6 @@ class DATA:
|
||||||
if static.SNR >= self.snr_list[new_speed_level]:
|
if static.SNR >= self.snr_list[new_speed_level]:
|
||||||
self.speed_level = new_speed_level
|
self.speed_level = new_speed_level
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.log.info("[TNC] ARQ | increasing speed level not possible because of SNR limit",
|
self.log.info("[TNC] ARQ | increasing speed level not possible because of SNR limit",
|
||||||
given_snr=static.SNR,
|
given_snr=static.SNR,
|
||||||
|
@ -1006,7 +1016,6 @@ class DATA:
|
||||||
if not self.check_if_mode_fits_to_busy_slot():
|
if not self.check_if_mode_fits_to_busy_slot():
|
||||||
self.speed_level = 0
|
self.speed_level = 0
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
@ -1143,15 +1152,12 @@ class DATA:
|
||||||
snr=snr,
|
snr=snr,
|
||||||
)
|
)
|
||||||
|
|
||||||
def arq_transmit(self, data_out: bytes, mode: int, n_frames_per_burst: int):
|
def arq_transmit(self, data_out: bytes):
|
||||||
"""
|
"""
|
||||||
Transmit ARQ frame
|
Transmit ARQ frame
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
data_out:bytes:
|
data_out:bytes:
|
||||||
mode:int:
|
|
||||||
n_frames_per_burst:int:
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# set signalling modes we want to listen to
|
# set signalling modes we want to listen to
|
||||||
|
@ -1215,8 +1221,7 @@ class DATA:
|
||||||
# Initial bufferposition is 0
|
# Initial bufferposition is 0
|
||||||
bufferposition = 0
|
bufferposition = 0
|
||||||
bufferposition_end = 0
|
bufferposition_end = 0
|
||||||
bufferposition_temp = 0
|
bufferposition_burst_start = 0
|
||||||
|
|
||||||
|
|
||||||
# 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:
|
||||||
|
@ -1244,13 +1249,14 @@ class DATA:
|
||||||
self.log.info("[TNC] early buffer info",
|
self.log.info("[TNC] early buffer info",
|
||||||
bufferposition=bufferposition,
|
bufferposition=bufferposition,
|
||||||
bufferposition_end=bufferposition_end,
|
bufferposition_end=bufferposition_end,
|
||||||
bufferposition_temp=bufferposition_temp
|
bufferposition_burst_start=bufferposition_burst_start
|
||||||
)
|
)
|
||||||
|
|
||||||
# check for maximum frames per burst for remaining data
|
# check for maximum frames per burst for remaining data
|
||||||
n_frames_per_burst = 1
|
n_frames_per_burst = 1
|
||||||
if self.max_n_frames_per_burst > 1:
|
if self.max_n_frames_per_burst > 1:
|
||||||
while (payload_per_frame * n_frames_per_burst) % len(data_out[bufferposition_temp:]) == (payload_per_frame * n_frames_per_burst):
|
while (payload_per_frame * n_frames_per_burst) % len(data_out[bufferposition_burst_start:]) == (
|
||||||
|
payload_per_frame * n_frames_per_burst):
|
||||||
threading.Event().wait(0.01)
|
threading.Event().wait(0.01)
|
||||||
print((payload_per_frame * n_frames_per_burst) % len(data_out))
|
print((payload_per_frame * n_frames_per_burst) % len(data_out))
|
||||||
n_frames_per_burst += 1
|
n_frames_per_burst += 1
|
||||||
|
@ -1264,6 +1270,10 @@ class DATA:
|
||||||
self.rpt_request_buffer = []
|
self.rpt_request_buffer = []
|
||||||
# Append data frames with n_frames_per_burst to tempbuffer
|
# Append data frames with n_frames_per_burst to tempbuffer
|
||||||
for n_frame in range(0, n_frames_per_burst):
|
for n_frame in range(0, n_frames_per_burst):
|
||||||
|
|
||||||
|
if n_frame == 0:
|
||||||
|
bufferposition = bufferposition_burst_start
|
||||||
|
|
||||||
arqheader = bytearray()
|
arqheader = bytearray()
|
||||||
arqheader[:1] = bytes([FR_TYPE.BURST_01.value + n_frame])
|
arqheader[:1] = bytes([FR_TYPE.BURST_01.value + n_frame])
|
||||||
# ####arqheader[:1] = bytes([FR_TYPE.BURST_01.value])
|
# ####arqheader[:1] = bytes([FR_TYPE.BURST_01.value])
|
||||||
|
@ -1271,9 +1281,11 @@ class DATA:
|
||||||
arqheader[2:3] = self.session_id
|
arqheader[2:3] = self.session_id
|
||||||
|
|
||||||
# only check for buffer position if at least one NACK received
|
# only check for buffer position if at least one NACK received
|
||||||
self.log.info("[TNC] ----- data buffer position:", iss_buffer_pos=bufferposition, irs_bufferposition=self.irs_buffer_position)
|
self.log.info("[TNC] ----- data buffer position:", iss_buffer_pos=bufferposition,
|
||||||
|
irs_bufferposition=self.irs_buffer_position)
|
||||||
if self.frame_nack_counter > 0 and self.irs_buffer_position != bufferposition:
|
if self.frame_nack_counter > 0 and self.irs_buffer_position != bufferposition:
|
||||||
self.log.error("[TNC] ----- data buffer offset:", iss_buffer_pos=bufferposition, irs_bufferposition=self.irs_buffer_position)
|
self.log.error("[TNC] ----- data buffer offset:", iss_buffer_pos=bufferposition,
|
||||||
|
irs_bufferposition=self.irs_buffer_position)
|
||||||
# only adjust buffer position for experimental versions
|
# only adjust buffer position for experimental versions
|
||||||
if 'exp' in static.VERSION:
|
if 'exp' in static.VERSION:
|
||||||
self.log.warning("[TNC] ----- data adjustment disabled!")
|
self.log.warning("[TNC] ----- data adjustment disabled!")
|
||||||
|
@ -1326,14 +1338,16 @@ class DATA:
|
||||||
self.burst_ack = False # reset ack state
|
self.burst_ack = False # reset ack state
|
||||||
self.tx_n_retry_of_burst = 0 # reset retries
|
self.tx_n_retry_of_burst = 0 # reset retries
|
||||||
self.log.debug(
|
self.log.debug(
|
||||||
"[TNC] arq_transmit: Received BURST ACK. Sending next chunk."
|
"[TNC] arq_transmit: Received BURST ACK. Sending next chunk.",
|
||||||
, irs_snr=self.burst_ack_snr)
|
irs_snr=self.burst_ack_snr)
|
||||||
# update temp bufferposition for n frames per burst early calculation
|
# update temp bufferposition for n frames per burst early calculation
|
||||||
bufferposition_temp = bufferposition_end
|
bufferposition_burst_start = bufferposition_end # pylint: disable=unused-variable
|
||||||
break # break retry loop
|
break # break retry loop
|
||||||
|
|
||||||
if self.burst_nack:
|
if self.burst_nack:
|
||||||
self.burst_nack = False # reset nack state
|
self.burst_nack = False # reset nack state
|
||||||
|
# fall back to starting bufferposition
|
||||||
|
bufferposition = bufferposition_burst_start
|
||||||
|
|
||||||
if self.data_frame_ack_received:
|
if self.data_frame_ack_received:
|
||||||
self.log.debug(
|
self.log.debug(
|
||||||
|
@ -1362,6 +1376,7 @@ class DATA:
|
||||||
|
|
||||||
# update buffer position
|
# update buffer position
|
||||||
bufferposition = bufferposition_end
|
bufferposition = bufferposition_end
|
||||||
|
bufferposition_burst_start = bufferposition_end
|
||||||
|
|
||||||
# update stats
|
# update stats
|
||||||
self.calculate_transfer_rate_tx(
|
self.calculate_transfer_rate_tx(
|
||||||
|
@ -1613,7 +1628,6 @@ class DATA:
|
||||||
|
|
||||||
self.log.info("[TNC] ARQ REPEAT RECEIVED")
|
self.log.info("[TNC] ARQ REPEAT RECEIVED")
|
||||||
|
|
||||||
|
|
||||||
# self.rpt_request_received = True
|
# self.rpt_request_received = True
|
||||||
# Update data_channel timestamp
|
# Update data_channel timestamp
|
||||||
self.data_channel_last_received = int(time.time())
|
self.data_channel_last_received = int(time.time())
|
||||||
|
@ -1626,7 +1640,6 @@ class DATA:
|
||||||
|
|
||||||
tempbuffer_rptframes = []
|
tempbuffer_rptframes = []
|
||||||
for i in range(0, len(missing_area)):
|
for i in range(0, len(missing_area)):
|
||||||
|
|
||||||
print(missing_area[i])
|
print(missing_area[i])
|
||||||
missing_frames_buffer_position = missing_area[i] - 1
|
missing_frames_buffer_position = missing_area[i] - 1
|
||||||
tempbuffer_rptframes.append(self.rpt_request_buffer[missing_frames_buffer_position])
|
tempbuffer_rptframes.append(self.rpt_request_buffer[missing_frames_buffer_position])
|
||||||
|
@ -1823,7 +1836,7 @@ class DATA:
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def received_session_opener(self, data_in: bytes) -> None:
|
def received_session_opener(self, data_in: bytes) -> bool:
|
||||||
"""
|
"""
|
||||||
Received a session open request packet.
|
Received a session open request packet.
|
||||||
|
|
||||||
|
@ -2095,7 +2108,7 @@ class DATA:
|
||||||
threading.Event().wait(0.01)
|
threading.Event().wait(0.01)
|
||||||
|
|
||||||
if static.ARQ_STATE:
|
if static.ARQ_STATE:
|
||||||
self.arq_transmit(data_out, mode, n_frames_per_burst)
|
self.arq_transmit(data_out)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
@ -2327,7 +2340,6 @@ class DATA:
|
||||||
# initially set speed_level 0 in case of bad SNR and no matching mode
|
# initially set speed_level 0 in case of bad SNR and no matching mode
|
||||||
self.speed_level = 0
|
self.speed_level = 0
|
||||||
|
|
||||||
|
|
||||||
# TODO: MOVE THIS TO arq_calculate_speed_level()
|
# TODO: MOVE THIS TO arq_calculate_speed_level()
|
||||||
# calculate speed level in correlation to latest known SNR
|
# calculate speed level in correlation to latest known SNR
|
||||||
for i in range(len(self.mode_list)):
|
for i in range(len(self.mode_list)):
|
||||||
|
@ -2904,7 +2916,7 @@ class DATA:
|
||||||
# self.duration_sig1_frame * 4 == 4 slots
|
# self.duration_sig1_frame * 4 == 4 slots
|
||||||
# in self.duration_sig1_frame increments.
|
# in self.duration_sig1_frame increments.
|
||||||
self.log.info("[TNC] Waiting for QRV slot...")
|
self.log.info("[TNC] Waiting for QRV slot...")
|
||||||
helpers.wait(randrange(0, int(self.duration_sig1_frame*4), self.duration_sig1_frame*10 // 10.0))
|
helpers.wait(randrange(0, int(self.duration_sig1_frame * 4), int(self.duration_sig1_frame)))
|
||||||
self.send_data_to_socket_queue(
|
self.send_data_to_socket_queue(
|
||||||
freedata="tnc-message",
|
freedata="tnc-message",
|
||||||
qrv="transmitting",
|
qrv="transmitting",
|
||||||
|
@ -3024,7 +3036,8 @@ class DATA:
|
||||||
static.ARQ_BYTES_PER_MINUTE = int(
|
static.ARQ_BYTES_PER_MINUTE = int(
|
||||||
receivedbytes / (transmissiontime / 60)
|
receivedbytes / (transmissiontime / 60)
|
||||||
)
|
)
|
||||||
static.ARQ_SECONDS_UNTIL_FINISH = int(((static.TOTAL_BYTES - receivedbytes) / (static.ARQ_BYTES_PER_MINUTE * static.ARQ_COMPRESSION_FACTOR)) * 60) -20 # offset because of frame ack/nack
|
static.ARQ_SECONDS_UNTIL_FINISH = int(((static.TOTAL_BYTES - receivedbytes) / (
|
||||||
|
static.ARQ_BYTES_PER_MINUTE * static.ARQ_COMPRESSION_FACTOR)) * 60) - 20 # offset because of frame ack/nack
|
||||||
|
|
||||||
speed_chart = {"snr": static.SNR, "bpm": static.ARQ_BYTES_PER_MINUTE, "timestamp": int(time.time())}
|
speed_chart = {"snr": static.SNR, "bpm": static.ARQ_BYTES_PER_MINUTE, "timestamp": int(time.time())}
|
||||||
# check if data already in list
|
# check if data already in list
|
||||||
|
@ -3084,10 +3097,11 @@ 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))
|
||||||
static.ARQ_SECONDS_UNTIL_FINISH = int(((tx_buffer_length - sentbytes) / (static.ARQ_BYTES_PER_MINUTE* static.ARQ_COMPRESSION_FACTOR)) * 60 )
|
static.ARQ_SECONDS_UNTIL_FINISH = int(((tx_buffer_length - sentbytes) / (
|
||||||
|
static.ARQ_BYTES_PER_MINUTE * static.ARQ_COMPRESSION_FACTOR)) * 60)
|
||||||
|
|
||||||
|
speed_chart = {"snr": self.burst_ack_snr, "bpm": static.ARQ_BYTES_PER_MINUTE,
|
||||||
speed_chart = {"snr": self.burst_ack_snr, "bpm": static.ARQ_BYTES_PER_MINUTE, "timestamp": int(time.time())}
|
"timestamp": int(time.time())}
|
||||||
# check if data already in list
|
# check if data already in list
|
||||||
if speed_chart not in static.SPEED_LIST:
|
if speed_chart not in static.SPEED_LIST:
|
||||||
static.SPEED_LIST.append(speed_chart)
|
static.SPEED_LIST.append(speed_chart)
|
||||||
|
@ -3296,12 +3310,12 @@ class DATA:
|
||||||
modem_error_state=modem_error_state
|
modem_error_state=modem_error_state
|
||||||
)
|
)
|
||||||
|
|
||||||
print(f"frames_per_burst {self.rx_n_frame_of_burst} / {self.rx_n_frames_per_burst}, Repeats: {self.burst_rpt_counter} Nones: {static.RX_BURST_BUFFER.count(None)}")
|
print(
|
||||||
|
f"frames_per_burst {self.rx_n_frame_of_burst} / {self.rx_n_frames_per_burst}, Repeats: {self.burst_rpt_counter} Nones: {static.RX_BURST_BUFFER.count(None)}")
|
||||||
|
|
||||||
if self.rx_n_frames_per_burst > 1 and self.burst_rpt_counter < 3 and static.RX_BURST_BUFFER.count(None) > 0:
|
if self.rx_n_frames_per_burst > 1 and self.burst_rpt_counter < 3 and static.RX_BURST_BUFFER.count(None) > 0:
|
||||||
# reset self.burst_last_received
|
# reset self.burst_last_received
|
||||||
self.burst_last_received = time.time() + self.time_list[self.speed_level] * frames_left
|
self.burst_last_received = time.time() + self.time_list[self.speed_level] * frames_left
|
||||||
self.burst_rpt_counter += 1
|
|
||||||
self.send_retransmit_request_frame()
|
self.send_retransmit_request_frame()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -3327,7 +3341,6 @@ class DATA:
|
||||||
# Update modes we are listening to
|
# Update modes we are listening to
|
||||||
self.set_listening_modes(True, True, self.mode_list[self.speed_level])
|
self.set_listening_modes(True, True, self.mode_list[self.speed_level])
|
||||||
|
|
||||||
|
|
||||||
# TODO: Does SNR make sense for NACK if we dont have an actual SNR information?
|
# TODO: Does SNR make sense for NACK if we dont have an actual SNR information?
|
||||||
self.send_burst_nack_frame_watchdog(0, tx_n_frames_per_burst)
|
self.send_burst_nack_frame_watchdog(0, tx_n_frames_per_burst)
|
||||||
|
|
||||||
|
@ -3454,7 +3467,7 @@ class DATA:
|
||||||
frame_to_tx=[fec_frame], c2_mode=codec2.FREEDV_MODE[mode].value
|
frame_to_tx=[fec_frame], c2_mode=codec2.FREEDV_MODE[mode].value
|
||||||
)
|
)
|
||||||
|
|
||||||
def send_fec_is_writing(self, mycallsign) -> None:
|
def send_fec_is_writing(self, mycallsign) -> bool:
|
||||||
"""Send an empty test frame"""
|
"""Send an empty test frame"""
|
||||||
|
|
||||||
fec_frame = bytearray(14)
|
fec_frame = bytearray(14)
|
||||||
|
@ -3522,6 +3535,8 @@ class DATA:
|
||||||
else:
|
else:
|
||||||
message = b''
|
message = b''
|
||||||
filename = b''
|
filename = b''
|
||||||
|
data = b''
|
||||||
|
checksum_delivered = b''
|
||||||
|
|
||||||
# save file to folder
|
# save file to folder
|
||||||
if filename not in [b'', b'undefined']:
|
if filename not in [b'', b'undefined']:
|
||||||
|
|
|
@ -12,7 +12,7 @@ import subprocess
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
CHANNEL_BUSY_SLOT = [False] * 5
|
CHANNEL_BUSY_SLOT = [False] * 5
|
||||||
|
|
||||||
VERSION = "0.9.0-alpha-exp.4"
|
VERSION = "0.9.0-alpha-exp.5"
|
||||||
|
|
||||||
ENABLE_EXPLORER = False
|
ENABLE_EXPLORER = False
|
||||||
ENABLE_STATS = False
|
ENABLE_STATS = False
|
||||||
|
@ -88,8 +88,6 @@ AUDIO_ENABLE_TCI: bool = False
|
||||||
TCI_IP: str = '127.0.0.1'
|
TCI_IP: str = '127.0.0.1'
|
||||||
TCI_PORT: int = '9000'
|
TCI_PORT: int = '9000'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AUDIO_DBFS: int = 0
|
AUDIO_DBFS: int = 0
|
||||||
FFT: list = [0]
|
FFT: list = [0]
|
||||||
ENABLE_FFT: bool = True
|
ENABLE_FFT: bool = True
|
||||||
|
@ -143,6 +141,7 @@ TUNING_RANGE_FMIN: float = -50.0
|
||||||
TUNING_RANGE_FMAX: float = 50.0
|
TUNING_RANGE_FMAX: float = 50.0
|
||||||
IS_CODEC2_TRAFFIC: bool = False # true if we have codec2 signalling mode traffic on channel
|
IS_CODEC2_TRAFFIC: bool = False # true if we have codec2 signalling mode traffic on channel
|
||||||
|
|
||||||
|
|
||||||
class FRAME_TYPE(Enum):
|
class FRAME_TYPE(Enum):
|
||||||
"""Lookup for frame types"""
|
"""Lookup for frame types"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue