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
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ class DATA:
|
||||||
# List for minimum SNR operating level for the corresponding mode in self.mode_list
|
# List for minimum SNR operating level for the corresponding mode in self.mode_list
|
||||||
self.snr_list_low_bw = [-100]
|
self.snr_list_low_bw = [-100]
|
||||||
# List for time to wait for corresponding mode in seconds
|
# List for time to wait for corresponding mode in seconds
|
||||||
self.time_list_low_bw = [6+5]
|
self.time_list_low_bw = [6 + 5]
|
||||||
|
|
||||||
# --------------------- HIGH BANDWIDTH
|
# --------------------- HIGH BANDWIDTH
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ class DATA:
|
||||||
# test with 6,7 --> caused sometimes a frame timeout if ack frame takes longer
|
# test with 6,7 --> caused sometimes a frame timeout if ack frame takes longer
|
||||||
# TODO: Need to check why ACK frames needs more time
|
# TODO: Need to check why ACK frames needs more time
|
||||||
# TODO: Adjust these times
|
# TODO: Adjust these times
|
||||||
self.time_list_high_bw = [6+5, 7, 10]
|
self.time_list_high_bw = [6 + 5, 7, 10]
|
||||||
# -------------- AVAILABLE MODES END-----------
|
# -------------- AVAILABLE MODES END-----------
|
||||||
|
|
||||||
# Mode list for selecting between low bandwidth ( 500Hz ) and modes with higher bandwidth
|
# Mode list for selecting between low bandwidth ( 500Hz ) and modes with higher bandwidth
|
||||||
|
@ -224,7 +224,7 @@ class DATA:
|
||||||
|
|
||||||
}
|
}
|
||||||
self.command_dispatcher = {
|
self.command_dispatcher = {
|
||||||
#"CONNECT": (self.arq_session_handler, "CONNECT"),
|
# "CONNECT": (self.arq_session_handler, "CONNECT"),
|
||||||
"CQ": (self.transmit_cq, "CQ"),
|
"CQ": (self.transmit_cq, "CQ"),
|
||||||
"DISCONNECT": (self.close_session, "DISCONNECT"),
|
"DISCONNECT": (self.close_session, "DISCONNECT"),
|
||||||
"SEND_TEST_FRAME": (self.send_test_frame, "TEST"),
|
"SEND_TEST_FRAME": (self.send_test_frame, "TEST"),
|
||||||
|
@ -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:
|
||||||
|
|
||||||
|
@ -388,11 +384,11 @@ class DATA:
|
||||||
or _valid4
|
or _valid4
|
||||||
or frametype
|
or frametype
|
||||||
in [
|
in [
|
||||||
FR_TYPE.CQ.value,
|
FR_TYPE.CQ.value,
|
||||||
FR_TYPE.QRV.value,
|
FR_TYPE.QRV.value,
|
||||||
FR_TYPE.PING.value,
|
FR_TYPE.PING.value,
|
||||||
FR_TYPE.BEACON.value,
|
FR_TYPE.BEACON.value,
|
||||||
FR_TYPE.IS_WRITING.value,
|
FR_TYPE.IS_WRITING.value,
|
||||||
]
|
]
|
||||||
):
|
):
|
||||||
|
|
||||||
|
@ -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:
|
||||||
|
@ -443,7 +437,7 @@ class DATA:
|
||||||
|
|
||||||
def enqueue_frame_for_tx(
|
def enqueue_frame_for_tx(
|
||||||
self,
|
self,
|
||||||
frame_to_tx, # : list[bytearray], # this causes a crash on python 3.7
|
frame_to_tx, # : list[bytearray], # this causes a crash on python 3.7
|
||||||
c2_mode=FREEDV_MODE.sig0.value,
|
c2_mode=FREEDV_MODE.sig0.value,
|
||||||
copies=1,
|
copies=1,
|
||||||
repeat_delay=0,
|
repeat_delay=0,
|
||||||
|
@ -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
|
||||||
|
@ -576,13 +579,13 @@ class DATA:
|
||||||
rpt_frame = bytearray(self.length_sig1_frame)
|
rpt_frame = bytearray(self.length_sig1_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[2:2+len(missing_frames)] = missing_frames
|
rpt_frame[2:2 + len(missing_frames)] = missing_frames
|
||||||
|
|
||||||
self.log.info("[TNC] ARQ | RX | Requesting", frames=missing_frames)
|
self.log.info("[TNC] ARQ | RX | Requesting", frames=missing_frames)
|
||||||
# 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
|
||||||
|
@ -690,7 +700,7 @@ class DATA:
|
||||||
self.rx_n_frame_of_burst = int.from_bytes(bytes(data_in[:1]), "big") - 10
|
self.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
|
||||||
self.rx_n_frames_per_burst = int.from_bytes(bytes(data_in[1:2]), "big")
|
self.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
|
||||||
|
@ -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,
|
||||||
|
@ -737,7 +746,7 @@ class DATA:
|
||||||
"[TNC] ARQ | RX | wrong byteorder received - dropping data"
|
"[TNC] ARQ | RX | wrong byteorder received - dropping data"
|
||||||
)
|
)
|
||||||
# we need to run a return here, so we are not sending an ACK
|
# we need to run a return here, so we are not sending an ACK
|
||||||
#return
|
# return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.warning(
|
self.log.warning(
|
||||||
"[TNC] ARQ | RX | wrong byteorder check failed", e=e
|
"[TNC] ARQ | RX | wrong byteorder check failed", e=e
|
||||||
|
@ -801,15 +810,14 @@ 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
|
||||||
# Create and send ACK frame
|
# Create and send ACK frame
|
||||||
self.log.info("[TNC] ARQ | RX | SENDING ACK", finished=static.ARQ_SECONDS_UNTIL_FINISH,
|
self.log.info("[TNC] ARQ | RX | SENDING ACK", finished=static.ARQ_SECONDS_UNTIL_FINISH,
|
||||||
bytesperminute=static.ARQ_BYTES_PER_MINUTE)
|
bytesperminute=static.ARQ_BYTES_PER_MINUTE)
|
||||||
|
|
||||||
self.send_burst_ack_frame(snr)
|
self.send_burst_ack_frame(snr)
|
||||||
|
|
||||||
# Reset n retries per burst counter
|
# Reset n retries per burst counter
|
||||||
|
@ -835,7 +843,7 @@ class DATA:
|
||||||
irs=helpers.bool_to_string(self.is_IRS)
|
irs=helpers.bool_to_string(self.is_IRS)
|
||||||
)
|
)
|
||||||
|
|
||||||
#elif self.rx_n_frame_of_burst == self.rx_n_frames_per_burst:
|
# elif self.rx_n_frame_of_burst == self.rx_n_frames_per_burst:
|
||||||
# # 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
|
||||||
|
@ -851,19 +859,20 @@ class DATA:
|
||||||
# self.rx_start_of_transmission, len(static.RX_FRAME_BUFFER)
|
# self.rx_start_of_transmission, len(static.RX_FRAME_BUFFER)
|
||||||
# )
|
# )
|
||||||
|
|
||||||
#elif self.rx_n_frame_of_burst not in [self.rx_n_frames_per_burst - 1]:
|
# elif self.rx_n_frame_of_burst not in [self.rx_n_frames_per_burst - 1]:
|
||||||
# self.log.info(
|
# self.log.info(
|
||||||
# "[TNC] data_handler: received burst",
|
# "[TNC] data_handler: received burst",
|
||||||
# frame=self.rx_n_frame_of_burst + 1,
|
# frame=self.rx_n_frame_of_burst + 1,
|
||||||
# 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,75 +1016,95 @@ 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
|
||||||
self.set_listening_modes(False, True, self.mode_list[self.speed_level])
|
self.set_listening_modes(False, True, self.mode_list[self.speed_level])
|
||||||
|
|
||||||
def arq_process_received_data_frame(self, data_frame, snr):
|
def arq_process_received_data_frame(self, data_frame, snr):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# transmittion duration
|
# transmittion duration
|
||||||
duration = time.time() - self.rx_start_of_transmission
|
duration = time.time() - self.rx_start_of_transmission
|
||||||
self.calculate_transfer_rate_rx(
|
self.calculate_transfer_rate_rx(
|
||||||
self.rx_start_of_transmission, len(static.RX_FRAME_BUFFER)
|
self.rx_start_of_transmission, len(static.RX_FRAME_BUFFER)
|
||||||
)
|
)
|
||||||
self.log.info("[TNC] ARQ | RX | DATA FRAME SUCCESSFULLY RECEIVED", nacks=self.frame_nack_counter,
|
self.log.info("[TNC] ARQ | RX | DATA FRAME SUCCESSFULLY RECEIVED", nacks=self.frame_nack_counter,
|
||||||
bytesperminute=static.ARQ_BYTES_PER_MINUTE, total_bytes=static.TOTAL_BYTES, duration=duration)
|
bytesperminute=static.ARQ_BYTES_PER_MINUTE, total_bytes=static.TOTAL_BYTES, duration=duration)
|
||||||
|
|
||||||
# Decompress the data frame
|
# Decompress the data frame
|
||||||
data_frame_decompressed = lzma.decompress(data_frame)
|
data_frame_decompressed = lzma.decompress(data_frame)
|
||||||
static.ARQ_COMPRESSION_FACTOR = len(data_frame_decompressed) / len(
|
static.ARQ_COMPRESSION_FACTOR = len(data_frame_decompressed) / len(
|
||||||
data_frame
|
data_frame
|
||||||
)
|
)
|
||||||
data_frame = data_frame_decompressed
|
data_frame = data_frame_decompressed
|
||||||
|
|
||||||
self.transmission_uuid = str(uuid.uuid4())
|
self.transmission_uuid = str(uuid.uuid4())
|
||||||
timestamp = int(time.time())
|
timestamp = int(time.time())
|
||||||
|
|
||||||
# Re-code data_frame in base64, UTF-8 for JSON UI communication.
|
# Re-code data_frame in base64, UTF-8 for JSON UI communication.
|
||||||
base64_data = base64.b64encode(data_frame).decode("UTF-8")
|
base64_data = base64.b64encode(data_frame).decode("UTF-8")
|
||||||
|
|
||||||
# check if RX_BUFFER isn't full
|
# check if RX_BUFFER isn't full
|
||||||
if not RX_BUFFER.full():
|
if not RX_BUFFER.full():
|
||||||
# make sure we have always the correct buffer size
|
# make sure we have always the correct buffer size
|
||||||
RX_BUFFER.maxsize = int(static.RX_BUFFER_SIZE)
|
RX_BUFFER.maxsize = int(static.RX_BUFFER_SIZE)
|
||||||
else:
|
else:
|
||||||
# if full, free space by getting an item
|
# if full, free space by getting an item
|
||||||
self.log.info(
|
|
||||||
"[TNC] ARQ | RX | RX_BUFFER FULL - dropping old data",
|
|
||||||
buffer_size=RX_BUFFER.qsize(),
|
|
||||||
maxsize=int(static.RX_BUFFER_SIZE)
|
|
||||||
)
|
|
||||||
RX_BUFFER.get()
|
|
||||||
|
|
||||||
# add item to RX_BUFFER
|
|
||||||
self.log.info(
|
self.log.info(
|
||||||
"[TNC] ARQ | RX | saving data to rx buffer",
|
"[TNC] ARQ | RX | RX_BUFFER FULL - dropping old data",
|
||||||
buffer_size=RX_BUFFER.qsize() + 1,
|
buffer_size=RX_BUFFER.qsize(),
|
||||||
maxsize=RX_BUFFER.maxsize
|
maxsize=int(static.RX_BUFFER_SIZE)
|
||||||
)
|
)
|
||||||
|
RX_BUFFER.get()
|
||||||
|
|
||||||
|
# add item to RX_BUFFER
|
||||||
|
self.log.info(
|
||||||
|
"[TNC] ARQ | RX | saving data to rx buffer",
|
||||||
|
buffer_size=RX_BUFFER.qsize() + 1,
|
||||||
|
maxsize=RX_BUFFER.maxsize
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
RX_BUFFER.put(
|
||||||
|
[
|
||||||
|
self.transmission_uuid,
|
||||||
|
timestamp,
|
||||||
|
static.DXCALLSIGN,
|
||||||
|
static.DXGRID,
|
||||||
|
base64_data,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
# File "/usr/lib/python3.7/queue.py", line 133, in put
|
||||||
|
# if self.maxsize > 0
|
||||||
|
# TypeError: '>' not supported between instances of 'str' and 'int'
|
||||||
|
#
|
||||||
|
# Occurs on Raspberry Pi and Python 3.7
|
||||||
|
self.log.error(
|
||||||
|
"[TNC] ARQ | RX | error occurred when saving data!",
|
||||||
|
e=e,
|
||||||
|
uuid=self.transmission_uuid,
|
||||||
|
timestamp=timestamp,
|
||||||
|
dxcall=static.DXCALLSIGN,
|
||||||
|
dxgrid=static.DXGRID,
|
||||||
|
data=base64_data
|
||||||
|
)
|
||||||
|
|
||||||
|
if static.ARQ_SAVE_TO_FOLDER:
|
||||||
try:
|
try:
|
||||||
RX_BUFFER.put(
|
self.save_data_to_folder(
|
||||||
[
|
self.transmission_uuid,
|
||||||
self.transmission_uuid,
|
timestamp,
|
||||||
timestamp,
|
self.mycallsign,
|
||||||
static.DXCALLSIGN,
|
static.DXCALLSIGN,
|
||||||
static.DXGRID,
|
static.DXGRID,
|
||||||
base64_data,
|
data_frame
|
||||||
]
|
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# File "/usr/lib/python3.7/queue.py", line 133, in put
|
|
||||||
# if self.maxsize > 0
|
|
||||||
# TypeError: '>' not supported between instances of 'str' and 'int'
|
|
||||||
#
|
|
||||||
# Occurs on Raspberry Pi and Python 3.7
|
|
||||||
self.log.error(
|
self.log.error(
|
||||||
"[TNC] ARQ | RX | error occurred when saving data!",
|
"[TNC] ARQ | RX | can't save file to folder",
|
||||||
e=e,
|
e=e,
|
||||||
uuid=self.transmission_uuid,
|
uuid=self.transmission_uuid,
|
||||||
timestamp=timestamp,
|
timestamp=timestamp,
|
||||||
|
@ -1083,75 +1113,51 @@ class DATA:
|
||||||
data=base64_data
|
data=base64_data
|
||||||
)
|
)
|
||||||
|
|
||||||
if static.ARQ_SAVE_TO_FOLDER:
|
self.send_data_to_socket_queue(
|
||||||
try:
|
freedata="tnc-message",
|
||||||
self.save_data_to_folder(
|
arq="transmission",
|
||||||
self.transmission_uuid,
|
status="received",
|
||||||
timestamp,
|
uuid=self.transmission_uuid,
|
||||||
self.mycallsign,
|
percent=static.ARQ_TRANSMISSION_PERCENT,
|
||||||
static.DXCALLSIGN,
|
bytesperminute=static.ARQ_BYTES_PER_MINUTE,
|
||||||
static.DXGRID,
|
compression=static.ARQ_COMPRESSION_FACTOR,
|
||||||
data_frame
|
timestamp=timestamp,
|
||||||
)
|
finished=0,
|
||||||
except Exception as e:
|
mycallsign=str(self.mycallsign, "UTF-8"),
|
||||||
self.log.error(
|
dxcallsign=str(static.DXCALLSIGN, "UTF-8"),
|
||||||
"[TNC] ARQ | RX | can't save file to folder",
|
dxgrid=str(static.DXGRID, "UTF-8"),
|
||||||
e=e,
|
data=base64_data,
|
||||||
uuid=self.transmission_uuid,
|
irs=helpers.bool_to_string(self.is_IRS)
|
||||||
timestamp=timestamp,
|
)
|
||||||
dxcall=static.DXCALLSIGN,
|
|
||||||
dxgrid=static.DXGRID,
|
|
||||||
data=base64_data
|
|
||||||
)
|
|
||||||
|
|
||||||
self.send_data_to_socket_queue(
|
if static.ENABLE_STATS:
|
||||||
freedata="tnc-message",
|
duration = time.time() - self.rx_start_of_transmission
|
||||||
arq="transmission",
|
self.stats.push(frame_nack_counter=self.frame_nack_counter, status="received", duration=duration)
|
||||||
status="received",
|
|
||||||
uuid=self.transmission_uuid,
|
|
||||||
percent=static.ARQ_TRANSMISSION_PERCENT,
|
|
||||||
bytesperminute=static.ARQ_BYTES_PER_MINUTE,
|
|
||||||
compression=static.ARQ_COMPRESSION_FACTOR,
|
|
||||||
timestamp=timestamp,
|
|
||||||
finished=0,
|
|
||||||
mycallsign=str(self.mycallsign, "UTF-8"),
|
|
||||||
dxcallsign=str(static.DXCALLSIGN, "UTF-8"),
|
|
||||||
dxgrid=str(static.DXGRID, "UTF-8"),
|
|
||||||
data=base64_data,
|
|
||||||
irs=helpers.bool_to_string(self.is_IRS)
|
|
||||||
)
|
|
||||||
|
|
||||||
if static.ENABLE_STATS:
|
self.log.info(
|
||||||
duration = time.time() - self.rx_start_of_transmission
|
"[TNC] ARQ | RX | SENDING DATA FRAME ACK")
|
||||||
self.stats.push(frame_nack_counter=self.frame_nack_counter, status="received", duration=duration)
|
|
||||||
|
|
||||||
self.log.info(
|
self.send_data_ack_frame(snr)
|
||||||
"[TNC] ARQ | RX | SENDING DATA FRAME ACK")
|
# Update statistics AFTER the frame ACK is sent
|
||||||
|
self.calculate_transfer_rate_rx(
|
||||||
|
self.rx_start_of_transmission, len(static.RX_FRAME_BUFFER)
|
||||||
|
)
|
||||||
|
|
||||||
self.send_data_ack_frame(snr)
|
self.log.info(
|
||||||
# Update statistics AFTER the frame ACK is sent
|
"[TNC] | RX | DATACHANNEL ["
|
||||||
self.calculate_transfer_rate_rx(
|
+ str(self.mycallsign, "UTF-8")
|
||||||
self.rx_start_of_transmission, len(static.RX_FRAME_BUFFER)
|
+ "]<< >>["
|
||||||
)
|
+ str(static.DXCALLSIGN, "UTF-8")
|
||||||
|
+ "]",
|
||||||
|
snr=snr,
|
||||||
|
)
|
||||||
|
|
||||||
self.log.info(
|
def arq_transmit(self, data_out: bytes):
|
||||||
"[TNC] | RX | DATACHANNEL ["
|
|
||||||
+ str(self.mycallsign, "UTF-8")
|
|
||||||
+ "]<< >>["
|
|
||||||
+ str(static.DXCALLSIGN, "UTF-8")
|
|
||||||
+ "]",
|
|
||||||
snr=snr,
|
|
||||||
)
|
|
||||||
|
|
||||||
def arq_transmit(self, data_out: bytes, mode: int, n_frames_per_burst: int):
|
|
||||||
"""
|
"""
|
||||||
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
|
||||||
|
@ -1263,17 +1269,23 @@ class DATA:
|
||||||
tempbuffer = []
|
tempbuffer = []
|
||||||
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])
|
||||||
arqheader[1:2] = bytes([n_frames_per_burst])
|
arqheader[1:2] = bytes([n_frames_per_burst])
|
||||||
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!")
|
||||||
|
@ -1294,7 +1306,7 @@ class DATA:
|
||||||
)
|
)
|
||||||
frame = arqheader + extended_data_out
|
frame = arqheader + extended_data_out
|
||||||
|
|
||||||
######tempbuffer = frame # [frame]
|
# #####tempbuffer = frame # [frame]
|
||||||
tempbuffer.append(frame)
|
tempbuffer.append(frame)
|
||||||
# add data to our repeat request buffer for easy access if we received a request
|
# add data to our repeat request buffer for easy access if we received a request
|
||||||
self.rpt_request_buffer.append(frame)
|
self.rpt_request_buffer.append(frame)
|
||||||
|
@ -1313,11 +1325,11 @@ class DATA:
|
||||||
|
|
||||||
# After transmission finished, wait for an ACK or RPT frame
|
# After transmission finished, wait for an ACK or RPT frame
|
||||||
while (
|
while (
|
||||||
static.ARQ_STATE
|
static.ARQ_STATE
|
||||||
and not self.burst_ack
|
and not self.burst_ack
|
||||||
and not self.burst_nack
|
and not self.burst_nack
|
||||||
and not self.rpt_request_received
|
and not self.rpt_request_received
|
||||||
and not self.data_frame_ack_received
|
and not self.data_frame_ack_received
|
||||||
):
|
):
|
||||||
threading.Event().wait(0.01)
|
threading.Event().wait(0.01)
|
||||||
|
|
||||||
|
@ -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,11 +1628,10 @@ 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())
|
||||||
#self.rpt_request_buffer = []
|
# self.rpt_request_buffer = []
|
||||||
|
|
||||||
missing_area = bytes(data_in[2:12]) # 1:9
|
missing_area = bytes(data_in[2:12]) # 1:9
|
||||||
missing_area = missing_area.strip(b"\x00")
|
missing_area = missing_area.strip(b"\x00")
|
||||||
|
@ -1626,16 +1640,15 @@ 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])
|
||||||
|
|
||||||
self.log.info("[TNC] SENDING REPEAT....")
|
self.log.info("[TNC] SENDING REPEAT....")
|
||||||
data_mode = self.mode_list[self.speed_level]
|
data_mode = self.mode_list[self.speed_level]
|
||||||
self.enqueue_frame_for_tx(tempbuffer_rptframes, c2_mode=data_mode)
|
self.enqueue_frame_for_tx(tempbuffer_rptframes, c2_mode=data_mode)
|
||||||
|
|
||||||
#for i in range(0, 6, 2):
|
# for i in range(0, 6, 2):
|
||||||
# if not missing_area[i: i + 2].endswith(b"\x00\x00"):
|
# if not missing_area[i: i + 2].endswith(b"\x00\x00"):
|
||||||
# self.rpt_request_buffer.insert(0, missing_area[i: i + 2])
|
# self.rpt_request_buffer.insert(0, missing_area[i: i + 2])
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -2150,7 +2163,7 @@ class DATA:
|
||||||
arq="transmission",
|
arq="transmission",
|
||||||
status="opening",
|
status="opening",
|
||||||
mycallsign=str(mycallsign, 'UTF-8'),
|
mycallsign=str(mycallsign, 'UTF-8'),
|
||||||
dxcallsign=str(self.dxcallsign,'UTF-8'),
|
dxcallsign=str(self.dxcallsign, 'UTF-8'),
|
||||||
irs=helpers.bool_to_string(self.is_IRS)
|
irs=helpers.bool_to_string(self.is_IRS)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2182,7 +2195,7 @@ class DATA:
|
||||||
|
|
||||||
self.enqueue_frame_for_tx([connection_frame], c2_mode=FREEDV_MODE.sig0.value, copies=1, repeat_delay=0)
|
self.enqueue_frame_for_tx([connection_frame], c2_mode=FREEDV_MODE.sig0.value, copies=1, repeat_delay=0)
|
||||||
|
|
||||||
timeout = time.time() + self.duration_sig1_frame * 3 + (static.TX_DELAY/1000 * 2)
|
timeout = time.time() + self.duration_sig1_frame * 3 + (static.TX_DELAY / 1000 * 2)
|
||||||
while time.time() < timeout:
|
while time.time() < timeout:
|
||||||
threading.Event().wait(0.01)
|
threading.Event().wait(0.01)
|
||||||
# Stop waiting if data channel is opened
|
# Stop waiting if data channel is opened
|
||||||
|
@ -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)):
|
||||||
|
@ -2595,7 +2607,7 @@ class DATA:
|
||||||
uuid=str(uuid.uuid4()),
|
uuid=str(uuid.uuid4()),
|
||||||
timestamp=int(time.time()),
|
timestamp=int(time.time()),
|
||||||
dxgrid=str(static.DXGRID, "UTF-8"),
|
dxgrid=str(static.DXGRID, "UTF-8"),
|
||||||
dxcallsign = str(dxcallsign, "UTF-8"),
|
dxcallsign=str(dxcallsign, "UTF-8"),
|
||||||
mycallsign=str(mycallsign, "UTF-8"),
|
mycallsign=str(mycallsign, "UTF-8"),
|
||||||
snr=str(static.SNR),
|
snr=str(static.SNR),
|
||||||
)
|
)
|
||||||
|
@ -2641,7 +2653,7 @@ class DATA:
|
||||||
uuid=str(uuid.uuid4()),
|
uuid=str(uuid.uuid4()),
|
||||||
timestamp=int(time.time()),
|
timestamp=int(time.time()),
|
||||||
dxgrid=str(static.DXGRID, "UTF-8"),
|
dxgrid=str(static.DXGRID, "UTF-8"),
|
||||||
dxcallsign = str(static.DXCALLSIGN, "UTF-8"),
|
dxcallsign=str(static.DXCALLSIGN, "UTF-8"),
|
||||||
mycallsign=str(mycallsign, "UTF-8"),
|
mycallsign=str(mycallsign, "UTF-8"),
|
||||||
snr=str(static.SNR),
|
snr=str(static.SNR),
|
||||||
dxsnr=str(dxsnr)
|
dxsnr=str(dxsnr)
|
||||||
|
@ -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)
|
||||||
|
@ -3286,7 +3300,7 @@ class DATA:
|
||||||
|
|
||||||
timeout = self.burst_last_received + (self.time_list[self.speed_level] * frames_left)
|
timeout = self.burst_last_received + (self.time_list[self.speed_level] * frames_left)
|
||||||
# TODO: Enable this for development
|
# TODO: Enable this for development
|
||||||
#print(f"timeout expected in:{round(timeout - time.time())} | frames left: {frames_left} of {self.rx_n_frames_per_burst} | speed level: {self.speed_level}")
|
# print(f"timeout expected in:{round(timeout - time.time())} | frames left: {frames_left} of {self.rx_n_frames_per_burst} | speed level: {self.speed_level}")
|
||||||
if timeout <= time.time() or modem_error_state:
|
if timeout <= time.time() or modem_error_state:
|
||||||
self.log.warning(
|
self.log.warning(
|
||||||
"[TNC] Burst decoding error or timeout",
|
"[TNC] Burst decoding error or timeout",
|
||||||
|
@ -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,13 +3341,12 @@ 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)
|
||||||
|
|
||||||
# Update data_channel timestamp
|
# Update data_channel timestamp
|
||||||
# TODO: Disabled this one for testing.
|
# TODO: Disabled this one for testing.
|
||||||
#self.data_channel_last_received = time.time()
|
# self.data_channel_last_received = time.time()
|
||||||
self.n_retries_per_burst += 1
|
self.n_retries_per_burst += 1
|
||||||
else:
|
else:
|
||||||
# print((self.data_channel_last_received + self.time_list[self.speed_level])-time.time())
|
# print((self.data_channel_last_received + self.time_list[self.speed_level])-time.time())
|
||||||
|
@ -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']:
|
||||||
|
@ -3546,4 +3561,4 @@ class DATA:
|
||||||
file.write(message)
|
file.write(message)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.error("[TNC] error saving data to folder", e=e)
|
self.log.error("[TNC] error saving data to folder", e=e)
|
||||||
|
|
|
@ -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
|
||||||
|
@ -141,7 +139,8 @@ INFO: list = []
|
||||||
# ------- CODEC2 SETTINGS
|
# ------- CODEC2 SETTINGS
|
||||||
TUNING_RANGE_FMIN: float = -50.0
|
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