mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
auto mode optimization
...in other words...gear shifting...
This commit is contained in:
parent
eed50a6f0c
commit
ea89a9e22b
2 changed files with 22 additions and 17 deletions
|
@ -108,12 +108,14 @@ def arq_data_received(data_in:bytes, bytes_per_frame:int, snr:int):
|
|||
if not RX_FRAME_BOF_RECEIVED and not RX_FRAME_EOF_RECEIVED and data_in.find(DATA_FRAME_EOF) < 0:
|
||||
print(RX_FRAME_BOF_RECEIVED)
|
||||
print(RX_FRAME_EOF_RECEIVED)
|
||||
|
||||
|
||||
# create an ack frame
|
||||
ack_frame = bytearray(14)
|
||||
ack_frame[:1] = bytes([60])
|
||||
ack_frame[1:2] = static.DXCALLSIGN_CRC8
|
||||
ack_frame[2:3] = static.MYCALLSIGN_CRC8
|
||||
ack_frame[3:4] = bytes([snr])
|
||||
ack_frame[3:4] = bytes([int(snr)])
|
||||
# and transmit it
|
||||
txbuffer = [ack_frame]
|
||||
structlog.get_logger("structlog").info("[TNC] ARQ | RX | ACK")
|
||||
|
@ -287,22 +289,21 @@ def arq_transmit(data_out:bytes, mode:int, n_frames_per_burst:int):
|
|||
# we have TX_N_MAX_RETRIES_PER_BURST attempts for sending a burst
|
||||
for TX_N_RETRIES_PER_BURST in range(0,TX_N_MAX_RETRIES_PER_BURST):
|
||||
|
||||
|
||||
# TEST WITH MODE GEAR SHIFTING
|
||||
print(mode)
|
||||
print(BURST_ACK_SNR)
|
||||
|
||||
if mode != 255:
|
||||
data_mode = mode
|
||||
print(f"selecting fixed mode {data_mode}")
|
||||
else:
|
||||
if BURST_ACK_SNR == 0:
|
||||
if BURST_ACK_SNR < 10 or TX_N_RETRIES_PER_BURST >= 2:
|
||||
data_mode = 12
|
||||
BURST_ACK_SNR = 15
|
||||
elif BURST_ACK_SNR > 10:
|
||||
print(f"selecting auto mode {data_mode}")
|
||||
|
||||
if BURST_ACK_SNR < 20 and TX_N_RETRIES_PER_BURST == 0:
|
||||
data_mode = 10
|
||||
print(f"selecting auto mode {data_mode}")
|
||||
|
||||
|
||||
print(mode)
|
||||
print(data_mode)
|
||||
# payload information
|
||||
payload_per_frame = modem.get_bytes_per_frame(data_mode) -2
|
||||
# tempbuffer list for storing our data frames
|
||||
|
@ -409,16 +410,18 @@ def arq_transmit(data_out:bytes, mode:int, n_frames_per_burst:int):
|
|||
|
||||
|
||||
|
||||
def burst_ack_received(snr):
|
||||
def burst_ack_received(data_in:bytes):
|
||||
global BURST_ACK_RECEIVED
|
||||
global BURST_ACK_SNR
|
||||
global DATA_CHANNEL_LAST_RECEIVED
|
||||
|
||||
|
||||
|
||||
# only process data if we are in ARQ and BUSY state
|
||||
if static.ARQ_STATE:
|
||||
BURST_ACK_RECEIVED = True # Force data loops of TNC to stop and continue with next frame
|
||||
DATA_CHANNEL_LAST_RECEIVED = int(time.time()) # we need to update our timeout timestamp
|
||||
BURST_ACK_SNR = snr
|
||||
BURST_ACK_SNR = int.from_bytes(bytes(data_in[3:4]), "big")
|
||||
print(BURST_ACK_SNR)
|
||||
|
||||
def frame_ack_received():
|
||||
|
|
10
tnc/modem.py
10
tnc/modem.py
|
@ -377,7 +377,7 @@ class RF():
|
|||
|
||||
# get snr of received data
|
||||
snr = self.calculate_snr(freedv)
|
||||
|
||||
print(f"SNR - {snr}")
|
||||
# send payload data to arq checker without CRC16
|
||||
data_handler.arq_data_received(bytes(bytes_out[:-2]), bytes_per_frame, snr)
|
||||
|
||||
|
@ -390,8 +390,8 @@ class RF():
|
|||
# BURST ACK
|
||||
elif frametype == 60:
|
||||
logging.debug("ACK RECEIVED....")
|
||||
snr = int.from_bytes(bytes(bytes_out[3:4]), "big")
|
||||
data_handler.burst_ack_received(snr)
|
||||
|
||||
data_handler.burst_ack_received(bytes_out[:-2])
|
||||
|
||||
# FRAME ACK
|
||||
elif frametype == 61:
|
||||
|
@ -516,11 +516,13 @@ class RF():
|
|||
self.c_lib.freedv_get_modem_stats(freedv, byref(
|
||||
modem_stats_sync), byref(modem_stats_snr))
|
||||
modem_stats_snr = modem_stats_snr.value
|
||||
|
||||
try:
|
||||
static.SNR = round(modem_stats_snr, 1)
|
||||
return static.SNR
|
||||
except:
|
||||
static.SNR = 0
|
||||
|
||||
return static.SNR
|
||||
|
||||
def update_rig_data(self):
|
||||
while True:
|
||||
|
|
Loading…
Reference in a new issue