updated transfer calculation

This commit is contained in:
DJ2LS 2021-09-11 09:21:22 +02:00 committed by GitHub
parent c230660c85
commit f52d0ea452
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 39 deletions

View file

@ -127,7 +127,6 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
print(received_json["parameter"][0]) print(received_json["parameter"][0])
#os.system("python3 main.py --rx 3 --tx 3 --deviceport /dev/ttyUSB0 --deviceid 2028") #os.system("python3 main.py --rx 3 --tx 3 --deviceport /dev/ttyUSB0 --deviceid 2028")
# Start RIGCTLD # Start RIGCTLD
if ptt == "RTS": if ptt == "RTS":
@ -171,6 +170,7 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
if DEBUG: if DEBUG:
process = subprocess.Popen("exec python3 main.py --rx "+ str(rx_audio) +" --tx "+ str(tx_audio) +" --deviceport "+ str(deviceport) +" --deviceid "+ str(deviceid) + " --serialspeed "+ str(serialspeed) + " --ptt "+ str(ptt), shell=True) process = subprocess.Popen("exec python3 main.py --rx "+ str(rx_audio) +" --tx "+ str(tx_audio) +" --deviceport "+ str(deviceport) +" --deviceid "+ str(deviceid) + " --serialspeed "+ str(serialspeed) + " --ptt "+ str(ptt), shell=True)
atexit.register(process.terminate) atexit.register(process.terminate)
else: else:
@ -229,7 +229,9 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
print("Wrong command") print("Wrong command")
print(data) print(data)
e = sys.exc_info()[0] e = sys.exc_info()[0]
print(e) print(e)
exc_type, exc_obj, exc_tb = sys.exc_info() exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno) print(exc_type, fname, exc_tb.tb_lineno)

View file

@ -48,8 +48,10 @@ def arq_data_received(data_in):
static.ARQ_N_FRAME = int.from_bytes(bytes(data_in[:1]), "big") - 10 # get number of burst frame static.ARQ_N_FRAME = int.from_bytes(bytes(data_in[:1]), "big") - 10 # get number of burst frame
static.ARQ_N_RX_FRAMES_PER_BURSTS = int.from_bytes(bytes(data_in[1:2]), "big") # get number of bursts from received frame static.ARQ_N_RX_FRAMES_PER_BURSTS = int.from_bytes(bytes(data_in[1:2]), "big") # get number of bursts from received frame
static.ARQ_RX_N_CURRENT_ARQ_FRAME = int.from_bytes(bytes(data_in[2:4]), "big") # get current number of total frames static.ARQ_RX_N_CURRENT_ARQ_FRAME = int.from_bytes(bytes(data_in[2:4]), "big") # get current number of total frames
static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME = int.from_bytes(bytes(data_in[4:6]), "big") # get get total number of frames static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME = int.from_bytes(bytes(data_in[4:6]), "big") # get total number of frames
static.TOTAL_BYTES = static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME * static.ARQ_PAYLOAD_PER_FRAME # calculate total bytes
logging.debug("----------------------------------------------------------------") logging.debug("----------------------------------------------------------------")
logging.debug("ARQ_N_FRAME: " + str(static.ARQ_N_FRAME)) logging.debug("ARQ_N_FRAME: " + str(static.ARQ_N_FRAME))
logging.debug("ARQ_N_RX_FRAMES_PER_BURSTS: " + str(static.ARQ_N_RX_FRAMES_PER_BURSTS)) logging.debug("ARQ_N_RX_FRAMES_PER_BURSTS: " + str(static.ARQ_N_RX_FRAMES_PER_BURSTS))
@ -64,22 +66,28 @@ def arq_data_received(data_in):
logging.log(24, "ARQ | RX | " + str(static.ARQ_DATA_CHANNEL_MODE) + " | F:[" + str(static.ARQ_N_FRAME) + "/" + str(static.ARQ_N_RX_FRAMES_PER_BURSTS) + "] [" + str(arq_percent_burst).zfill(3) + "%] T:[" + str(static.ARQ_RX_N_CURRENT_ARQ_FRAME) + "/" + str(static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME) + "] [" + str(arq_percent_frame).zfill(3) + "%] [SNR:" + str(static.SNR) + "]") logging.log(24, "ARQ | RX | " + str(static.ARQ_DATA_CHANNEL_MODE) + " | F:[" + str(static.ARQ_N_FRAME) + "/" + str(static.ARQ_N_RX_FRAMES_PER_BURSTS) + "] [" + str(arq_percent_burst).zfill(3) + "%] T:[" + str(static.ARQ_RX_N_CURRENT_ARQ_FRAME) + "/" + str(static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME) + "] [" + str(arq_percent_frame).zfill(3) + "%] [SNR:" + str(static.SNR) + "]")
# allocate ARQ_RX_FRAME_BUFFER as a list with "None" if not already done. This should be done only once per burst! # allocate ARQ_RX_FRAME_BUFFER as a list with "None" if not already done. This should be done only once per burst!
# here we will save the N frame of a data frame to N list position so we can explicit search for it # here we will save the N frame of a data frame to N list position so we can explicit search for it
# delete frame buffer if first frame to make sure the buffer is cleared and no junks of a old frame is remaining # delete frame buffer if first frame to make sure the buffer is cleared and no junks of a old frame is remaining
if static.ARQ_RX_N_CURRENT_ARQ_FRAME == 1: if static.ARQ_RX_N_CURRENT_ARQ_FRAME == 1:
static.ARQ_RX_FRAME_BUFFER = [] static.ARQ_RX_FRAME_BUFFER = []
# we set the start of transmission - 6 seconds, which is more or less the transfer time for the first frame
static.ARQ_START_OF_TRANSMISSION = time.time() - 6
helpers.calculate_transfer_rate()
#try appending data to frame buffer
try: try:
static.ARQ_RX_FRAME_BUFFER[static.ARQ_RX_N_CURRENT_ARQ_FRAME] = bytes(data_in) static.ARQ_RX_FRAME_BUFFER[static.ARQ_RX_N_CURRENT_ARQ_FRAME] = bytes(data_in)
except IndexError: except IndexError:
static.ARQ_RX_FRAME_BUFFER = [] static.ARQ_RX_FRAME_BUFFER = []
#on a new transmission we reset the timer
static.ARQ_START_OF_TRANSMISSION = int(time.time()) + 4
for i in range(0, static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME + 1): for i in range(0, static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME + 1):
static.ARQ_RX_FRAME_BUFFER.insert(i, None) static.ARQ_RX_FRAME_BUFFER.insert(i, None)
@ -87,9 +95,15 @@ def arq_data_received(data_in):
static.ARQ_FRAME_BOF_RECEIVED = False static.ARQ_FRAME_BOF_RECEIVED = False
static.ARQ_FRAME_EOF_RECEIVED = False static.ARQ_FRAME_EOF_RECEIVED = False
if static.ARQ_N_FRAME == 1:
static.ARQ_START_OF_BURST = time.time() - 6
helpers.calculate_transfer_rate()
# try appending data to burst buffer
try: try:
static.ARQ_RX_BURST_BUFFER[static.ARQ_N_FRAME] = bytes(data_in) static.ARQ_RX_BURST_BUFFER[static.ARQ_N_FRAME] = bytes(data_in)
except IndexError: except IndexError:
static.ARQ_RX_BURST_BUFFER = [] static.ARQ_RX_BURST_BUFFER = []
@ -277,7 +291,8 @@ def arq_transmit(data_out):
# This is the total frame with frame header, which will be send # This is the total frame with frame header, which will be send
data_out = frame_payload_crc + static.FRAME_BOF + data_out + static.FRAME_EOF data_out = frame_payload_crc + static.FRAME_BOF + data_out + static.FRAME_EOF
# 2 2 N 2 # 2 2 N 2
# save len of data_out to TOTAL_BYTES for our statistics
static.TOTAL_BYTES = len(data_out)
# --------------------------------------------- LETS CREATE A BUFFER BY SPLITTING THE FILES INTO PEACES # --------------------------------------------- LETS CREATE A BUFFER BY SPLITTING THE FILES INTO PEACES
static.TX_BUFFER = [data_out[i:i + static.ARQ_PAYLOAD_PER_FRAME] for i in range(0, len(data_out), static.ARQ_PAYLOAD_PER_FRAME)] static.TX_BUFFER = [data_out[i:i + static.ARQ_PAYLOAD_PER_FRAME] for i in range(0, len(data_out), static.ARQ_PAYLOAD_PER_FRAME)]
static.TX_BUFFER_SIZE = len(static.TX_BUFFER) static.TX_BUFFER_SIZE = len(static.TX_BUFFER)
@ -529,7 +544,7 @@ def open_dc_and_transmit(data_out, mode, n_frames):
time.sleep(0.01) time.sleep(0.01)
#on a new transmission we reset the timer #on a new transmission we reset the timer
static.ARQ_START_OF_TRANSMISSION = int(time.time()) #static.ARQ_START_OF_TRANSMISSION = int(time.time())
# lets wait a little bit so RX station is ready for receiving # lets wait a little bit so RX station is ready for receiving
wait_before_data_timer = time.time() + 0.5 wait_before_data_timer = time.time() + 0.5
@ -598,7 +613,8 @@ def arq_received_data_channel_opener(data_in):
static.TNC_STATE = 'BUSY' static.TNC_STATE = 'BUSY'
static.ARQ_DATA_CHANNEL_MODE = int.from_bytes(bytes(data_in[12:13]), "big") static.ARQ_DATA_CHANNEL_MODE = int.from_bytes(bytes(data_in[12:13]), "big")
static.ARQ_DATA_CHANNEL_LAST_RECEIVED = int(time.time()) static.ARQ_DATA_CHANNEL_LAST_RECEIVED = int(time.time())
#static.ARQ_START_OF_TRANSMISSION = time.time() + 4
connection_frame = bytearray(14) connection_frame = bytearray(14)
connection_frame[:1] = bytes([226]) connection_frame[:1] = bytes([226])

View file

@ -130,7 +130,8 @@ def arq_reset_frame_machine():
static.ARQ_START_OF_TRANSMISSION = 0 static.ARQ_START_OF_TRANSMISSION = 0
def calculate_transfer_rate(): def calculate_transfer_rate():
if static.ARQ_START_OF_TRANSMISSION > 0:
static.TOTAL_TRANSMISSION_TIME = time.time() - static.ARQ_START_OF_TRANSMISSION
print("ARQ_N_ARQ_FRAMES_PER_DATA_FRAME " + str(static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME)) print("ARQ_N_ARQ_FRAMES_PER_DATA_FRAME " + str(static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME))
@ -148,39 +149,39 @@ def calculate_transfer_rate():
else: else:
total_n_frames = 0 total_n_frames = 0
if static.TOTAL_TRANSMISSION_TIME > 0:
print(arq_n_arq_frames_per_data_frame) #total_transmission_time = time.time() - static.ARQ_START_OF_TRANSMISSION
print(arq_rx_n_current_arq_frame) total_transmission_time = static.TOTAL_TRANSMISSION_TIME
print(total_n_frames) print("total_transmission_time: " + str(total_transmission_time))
print(static.TX_BUFFER_SIZE) print("static.TOTAL_BYTES: " + str(static.TOTAL_BYTES))
print(static.ARQ_PAYLOAD_PER_FRAME)
static.TOTAL_BYTES = (static.TX_BUFFER_SIZE * static.ARQ_PAYLOAD_PER_FRAME)
total_transmission_time = time.time() - static.ARQ_START_OF_TRANSMISSION
burst_bytes = static.ARQ_PAYLOAD_PER_FRAME
burst_transmission_time = time.time() - static.ARQ_START_OF_BURST
static.ARQ_BITS_PER_SECOND = int((static.TOTAL_BYTES * 8) / total_transmission_time)
static.ARQ_BYTES_PER_MINUTE = int(((static.TOTAL_BYTES) / total_transmission_time) * 60) static.ARQ_BITS_PER_SECOND = int((static.TOTAL_BYTES * 8) / total_transmission_time)
static.ARQ_BYTES_PER_MINUTE = int(((static.TOTAL_BYTES) / total_transmission_time) * 60)
burst_bytes = static.ARQ_PAYLOAD_PER_FRAME * static.ARQ_N_RX_FRAMES_PER_BURSTS
burst_transmission_time = time.time() - static.ARQ_START_OF_BURST
print("BURST TRANSMISSION TIME: " + str(burst_transmission_time))
static.ARQ_BITS_PER_SECOND_BURST = int((burst_bytes * 8) / burst_transmission_time)
static.ARQ_BYTES_PER_MINUTE_BURST = int(((burst_bytes) / burst_transmission_time) * 60)
print("static.ARQ_BITS_PER_SECOND_BURST: " + str(static.ARQ_BITS_PER_SECOND_BURST))
print("static.ARQ_BYTES_PER_MINUTE_BURST: " + str(static.ARQ_BYTES_PER_MINUTE_BURST))
static.ARQ_BITS_PER_SECOND_BURST = int((burst_bytes * 8) / burst_transmission_time) # PERCENTAGE FOR TRANSMITTING
static.ARQ_BYTES_PER_MINUTE_BURST = int(((burst_bytes) / burst_transmission_time) * 60)
# calculate transmission percentage
#int(static.ARQ_N_SENT_FRAMES / (static.TX_BUFFER_SIZE
if static.TX_BUFFER_SIZE > 0: if static.TX_BUFFER_SIZE > 0:
static.ARQ_TRANSMISSION_PERCENT = int(arq_rx_n_current_arq_frame / static.TX_BUFFER_SIZE) * 100 static.ARQ_TRANSMISSION_PERCENT = int(arq_rx_n_current_arq_frame / static.TX_BUFFER_SIZE) * 100
# PERCENTAGE FOR RECEIVING
elif arq_n_arq_frames_per_data_frame > 0: elif arq_n_arq_frames_per_data_frame > 0:
static.ARQ_TRANSMISSION_PERCENT = int(arq_rx_n_current_arq_frame / arq_n_arq_frames_per_data_frame) * 100 static.ARQ_TRANSMISSION_PERCENT = int((static.ARQ_RX_N_CURRENT_ARQ_FRAME / static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME) * 100)
else: else:
static.ARQ_TRANSMISSION_PERCENT = 0.0 static.ARQ_TRANSMISSION_PERCENT = 0.0
print(static.ARQ_TRANSMISSION_PERCENT) print("static.ARQ_TRANSMISSION_PERCENT: " + str(static.ARQ_TRANSMISSION_PERCENT))
print("static.ARQ_BYTES_PER_MINUTE: " + str(static.ARQ_BYTES_PER_MINUTE))
print("static.ARQ_BITS_PER_SECOND: " + str(static.ARQ_BITS_PER_SECOND))
return [static.ARQ_BITS_PER_SECOND, static.ARQ_BYTES_PER_MINUTE, static.ARQ_BITS_PER_SECOND_BURST, static.ARQ_BYTES_PER_MINUTE_BURST] return [static.ARQ_BITS_PER_SECOND, static.ARQ_BYTES_PER_MINUTE, static.ARQ_BITS_PER_SECOND_BURST, static.ARQ_BYTES_PER_MINUTE_BURST]

View file

@ -496,7 +496,7 @@ class RF():
if nbytes == bytes_per_frame and bytes(bytes_out[1:2]) == static.MYCALLSIGN_CRC8 or bytes(bytes_out[6:7]) == static.MYCALLSIGN_CRC8 or bytes(bytes_out[1:2]) == b'\x01': if nbytes == bytes_per_frame and bytes(bytes_out[1:2]) == static.MYCALLSIGN_CRC8 or bytes(bytes_out[6:7]) == static.MYCALLSIGN_CRC8 or bytes(bytes_out[1:2]) == b'\x01':
self.calculate_snr(freedv) self.calculate_snr(freedv)
helpers.calculate_transfer_rate()
# CHECK IF FRAMETYPE IS BETWEEN 10 and 50 ------------------------ # CHECK IF FRAMETYPE IS BETWEEN 10 and 50 ------------------------
frametype = int.from_bytes(bytes(bytes_out[:1]), "big") frametype = int.from_bytes(bytes(bytes_out[:1]), "big")
frame = frametype - 10 frame = frametype - 10

View file

@ -186,6 +186,7 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
"ARQ_RX_N_CURRENT_ARQ_FRAME": str(static.ARQ_RX_N_CURRENT_ARQ_FRAME), "ARQ_RX_N_CURRENT_ARQ_FRAME": str(static.ARQ_RX_N_CURRENT_ARQ_FRAME),
"ARQ_N_ARQ_FRAMES_PER_DATA_FRAME": str(int.from_bytes(bytes(static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME), "big")), "ARQ_N_ARQ_FRAMES_PER_DATA_FRAME": str(int.from_bytes(bytes(static.ARQ_N_ARQ_FRAMES_PER_DATA_FRAME), "big")),
"ARQ_BYTES_PER_MINUTE" : str(static.ARQ_BYTES_PER_MINUTE), "ARQ_BYTES_PER_MINUTE" : str(static.ARQ_BYTES_PER_MINUTE),
"ARQ_BYTES_PER_MINUTE_BURST" : str(static.ARQ_BYTES_PER_MINUTE_BURST),
"ARQ_TRANSMISSION_PERCENT" : str(static.ARQ_TRANSMISSION_PERCENT), "ARQ_TRANSMISSION_PERCENT" : str(static.ARQ_TRANSMISSION_PERCENT),
"TOTAL_BYTES" : str(static.TOTAL_BYTES), "TOTAL_BYTES" : str(static.TOTAL_BYTES),

View file

@ -118,7 +118,8 @@ ARQ_TX_N_CURRENT_ARQ_FRAME = 0
## ##
# RX # RX
ARQ_N_ARQ_FRAMES_PER_DATA_FRAME = b'\x00\x00' # total number of arq frames per data frame #ARQ_N_ARQ_FRAMES_PER_DATA_FRAME = b'\x00\x00' # total number of arq frames per data frame
ARQ_N_ARQ_FRAMES_PER_DATA_FRAME = 0 # total number of arq frames per data frame
ARQ_RX_N_CURRENT_ARQ_FRAME = 0 ARQ_RX_N_CURRENT_ARQ_FRAME = 0
## ##
@ -179,9 +180,12 @@ ARQ_DATA_CHANNEL_LAST_RECEIVED = 0
# BIT RATE MESSUREMENT # BIT RATE MESSUREMENT
ARQ_START_OF_TRANSMISSION = 0 ARQ_START_OF_TRANSMISSION = 0
ARQ_START_OF_BURST = 0 ARQ_START_OF_BURST = 0
TOTAL_TRANSMISSION_TIME = 0
#ARQ_END_OF_TRANSMISSION = 0 #ARQ_END_OF_TRANSMISSION = 0
ARQ_BITS_PER_SECOND = 0 ARQ_BITS_PER_SECOND = 0
ARQ_BYTES_PER_MINUTE = 0 ARQ_BYTES_PER_MINUTE = 0
ARQ_BITS_PER_SECOND_BURST = 0
ARQ_BYTES_PER_MINUTE_BURST = 0
ARQ_TRANSMISSION_PERCENT = 0 ARQ_TRANSMISSION_PERCENT = 0
TOTAL_BYTES = 0 TOTAL_BYTES = 0