mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
bleeding edge ARQ RPT
no working, but with tooo much debugging output furthermore the frame ACK is not working correctly on the TX side
This commit is contained in:
parent
eb7f98e2e1
commit
6adf7db483
3 changed files with 58 additions and 50 deletions
67
arq.py
67
arq.py
|
@ -25,14 +25,11 @@ static.ARQ_ACK_PAYLOAD_PER_FRAME = 14 - 2#
|
|||
def arq_ack_timeout():
|
||||
static.ARQ_ACK_TIMEOUT = 1
|
||||
|
||||
def arq_rpt_timeout():
|
||||
static.ARQ_RPT_TIMEOUT = True
|
||||
|
||||
def data_received(data_in):
|
||||
|
||||
static.ARQ_RX_TIMEOUT = time.time() + static.ARQ_RX_TIMEOUT_SECONDS
|
||||
while time.time() < static.ARQ_RX_TIMEOUT:
|
||||
|
||||
|
||||
|
||||
|
||||
# arqframe = frame_type + \ # 1 [:1] # frame type and current number of arq frame of (current) burst
|
||||
# bytes([static.ARQ_TX_N_FRAMES_PER_BURST]) + \ # 1 [1:2] # total number of arq frames per (current) burst
|
||||
|
@ -80,8 +77,13 @@ def data_received(data_in):
|
|||
|
||||
#allocate ARQ_RX_BURST_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 burst to N list position so we can explicit search for it
|
||||
print(len(static.ARQ_RX_BURST_BUFFER))
|
||||
print(static.ARQ_N_FRAME)
|
||||
|
||||
|
||||
if static.ARQ_N_RX_FRAMES_PER_BURSTS != len(static.ARQ_RX_BURST_BUFFER) and static.ARQ_N_FRAME == 1 and frame_type != 51:
|
||||
static.ARQ_RX_BURST_BUFFER = []
|
||||
print("ITERATOR!!!!!!!!!!!!!!")
|
||||
for i in range(0,static.ARQ_N_RX_FRAMES_PER_BURSTS+1):
|
||||
static.ARQ_RX_BURST_BUFFER.insert(i,None)
|
||||
|
||||
|
@ -90,12 +92,17 @@ def data_received(data_in):
|
|||
static.ARQ_RX_BURST_BUFFER[static.ARQ_N_FRAME] = bytes(data_in)
|
||||
static.ARQ_RX_FRAME_BUFFER[static.ARQ_RX_N_CURRENT_ARQ_FRAME] = bytes(data_in)
|
||||
|
||||
for i in range(len(static.ARQ_RX_BURST_BUFFER)):
|
||||
print(static.ARQ_RX_BURST_BUFFER[i])
|
||||
|
||||
|
||||
|
||||
|
||||
# - ------------------------- ARQ BURST CHECKER
|
||||
|
||||
# run only if we recieved all ARQ FRAMES per ARQ BURST
|
||||
if static.ARQ_N_FRAME == static.ARQ_N_RX_FRAMES_PER_BURSTS and static.ARQ_RX_BURST_BUFFER.count(None) == 1: #if received bursts are equal to burst number in frame
|
||||
|
||||
#if static.ARQ_N_FRAME == static.ARQ_N_RX_FRAMES_PER_BURSTS and static.ARQ_RX_BURST_BUFFER.count(None) == 1: #if received bursts are equal to burst number in frame
|
||||
if static.ARQ_RX_BURST_BUFFER.count(None) == 1: #count nones
|
||||
logging.info("ARQ | TX | BURST ACK")
|
||||
|
||||
#BUILDING ACK FRAME FOR BURST -----------------------------------------------
|
||||
|
@ -152,8 +159,9 @@ def data_received(data_in):
|
|||
|
||||
# --------------- IF LIST NOT CONTAINS "None" stick everything together
|
||||
complete_data_frame = bytearray()
|
||||
print("static.ARQ_RX_FRAME_BUFFER.count(None)" + str(static.ARQ_RX_FRAME_BUFFER.count(None)))
|
||||
if static.ARQ_RX_FRAME_BUFFER.count(None) == 1: ## 1 because position 0 of list will alaways be None in our case
|
||||
|
||||
print("DECODING FRAME!")
|
||||
for frame in range(1,len(static.ARQ_RX_FRAME_BUFFER)):
|
||||
raw_arq_frame = static.ARQ_RX_FRAME_BUFFER[frame]
|
||||
arq_frame_payload = raw_arq_frame[8:]
|
||||
|
@ -213,13 +221,14 @@ def data_received(data_in):
|
|||
else:
|
||||
logging.info("ARQ | RX | DATA FRAME NOT SUCESSFULLY RECEIVED!")
|
||||
|
||||
break
|
||||
#break
|
||||
|
||||
def burst_ack_received():
|
||||
|
||||
logging.info("ARQ | RX | BURST ACK RCVD!")
|
||||
static.ARQ_ACK_TIMEOUT = 1 #Force timer to stop waiting
|
||||
static.ARQ_ACK_RECEIVED = 1 #Force data loops of TNC to stop and continue with next frame
|
||||
static.RPT_ACK_RECEIVED = False
|
||||
|
||||
def burst_rpt_received(data_in):
|
||||
|
||||
|
@ -312,18 +321,14 @@ def transmit(data_out):
|
|||
logging.debug("ARQ | RX | WAITING FOR BURST ACK")
|
||||
static.ARQ_STATE = 'RECEIVING_ACK'
|
||||
|
||||
|
||||
timer = threading.Timer(static.ARQ_ACK_TIMEOUT_SECONDS, arq_ack_timeout)
|
||||
timer.start()
|
||||
|
||||
|
||||
# --------------------------- WHILE TIMEOUT NOT REACHED AND NO ACK RECEIVED --> LISTEN
|
||||
while static.ARQ_ACK_TIMEOUT == 0 and static.ARQ_RPT_RECEIVED == False and static.ARQ_ACK_RECEIVED == 0:
|
||||
time.sleep(0.01) # lets reduce CPU load a little bit
|
||||
#print(static.ARQ_STATE)
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
if static.ARQ_RPT_RECEIVED == True:
|
||||
|
@ -334,39 +339,37 @@ def transmit(data_out):
|
|||
while static.ARQ_STATE == 'SENDING_DATA':
|
||||
time.sleep(0.05)
|
||||
|
||||
# --------------------------- START TIMER FOR WAITING FOR ACK ---> IF TIMEOUT REACHED, ACK_TIMEOUT = 1
|
||||
#reset timer and ack state
|
||||
static.ARQ_FRAME_ACK_RECEIVED = 0
|
||||
static.ARQ_ACK_RECEIVED = 0
|
||||
static.ARQ_ACK_TIMEOUT = 0
|
||||
|
||||
logging.debug("ARQ | RX | WAITING FOR BURST ACK")
|
||||
static.ARQ_STATE = 'RECEIVING_ACK'
|
||||
|
||||
timer = threading.Timer(static.ARQ_ACK_TIMEOUT_SECONDS, arq_ack_timeout)
|
||||
timer = threading.Timer(static.ARQ_RPT_TIMEOUT_SECONDS, arq_rpt_timeout)
|
||||
timer.start()
|
||||
|
||||
while static.ARQ_ACK_TIMEOUT == 0 and static.ARQ_RPT_RECEIVED == False and static.ARQ_ACK_RECEIVED == 0:
|
||||
print("kommen wir hier überhaupt an?")
|
||||
while static.ARQ_ACK_TIMEOUT == 0 and static.ARQ_ACK_RECEIVED == 0 and static.ARQ_RPT_TIMEOUT == False:
|
||||
time.sleep(0.01) # lets reduce CPU load a little bit
|
||||
#print(static.ARQ_STATE)
|
||||
print("waiting for ack while rpt")
|
||||
if static.ARQ_ACK_RECEIVED == 1:
|
||||
|
||||
print("ACK WHILE RPT")
|
||||
time.sleep(1)
|
||||
static.ARQ_ACK_TIMEOUT = 1
|
||||
static.ARQ_RPT_RECEIVED = False
|
||||
static.ARQ_RPT_TIMEOUT == False
|
||||
|
||||
break
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if static.ARQ_ACK_RECEIVED == 0 and static.ARQ_ACK_TIMEOUT == 1:
|
||||
if static.ARQ_ACK_RECEIVED == 0 and static.ARQ_ACK_TIMEOUT == 1 and static.ARQ_RPT_TIMEOUT == True:
|
||||
#logging.info("ARQ | RX | ACK TIMEOUT | SENDING ARQ BURST AGAIN")
|
||||
pass
|
||||
|
||||
#--------------- BREAK LOOP IF ACK HAS BEEN RECEIVED OR FRAME ACK HAS BEEN RECEIVED
|
||||
if static.ARQ_ACK_RECEIVED == 1:
|
||||
print("der interator increment ist wichtig!")
|
||||
#-----------IF ACK RECEIVED, INCREMENT ITERATOR FOR MAIN LOOP TO PROCEED WITH NEXT FRAMES/BURST
|
||||
static.ARQ_N_SENT_FRAMES = static.ARQ_N_SENT_FRAMES + static.ARQ_TX_N_FRAMES_PER_BURST
|
||||
break
|
||||
|
@ -402,6 +405,6 @@ def transmit(data_out):
|
|||
# BURST MACHINE TO DEFINE N BURSTS PER FRAME ---> LATER WE CAN USE CHANNEL MESSUREMENT TO SET FRAMES PER BURST
|
||||
def get_n_frames_per_burst():
|
||||
|
||||
n_frames_per_burst = randrange(1,10)
|
||||
#n_frames_per_burst = 1
|
||||
#n_frames_per_burst = randrange(1,10)
|
||||
n_frames_per_burst = 4
|
||||
return n_frames_per_burst
|
||||
|
|
16
modem.py
16
modem.py
|
@ -143,6 +143,7 @@ class RF():
|
|||
# GET ARQ BURST FRAME VOM BUFFER AND MODULATE IT
|
||||
def transmit_arq_burst(self):
|
||||
static.ARQ_STATE = 'SENDING_DATA'
|
||||
time.sleep(3)
|
||||
|
||||
self.c_lib.freedv_open.restype = ctypes.POINTER(ctypes.c_ubyte)
|
||||
freedv = self.c_lib.freedv_open(static.FREEDV_DATA_MODE)
|
||||
|
@ -209,9 +210,9 @@ class RF():
|
|||
frame_type = 10 + missing_frame #static.ARQ_TX_N_FRAMES_PER_BURST
|
||||
frame_type = bytes([frame_type])
|
||||
|
||||
payload_data = bytes(static.TX_BUFFER[static.ARQ_N_SENT_FRAMES + missing_frame])
|
||||
payload_data = bytes(static.TX_BUFFER[static.ARQ_N_SENT_FRAMES + missing_frame - 1])
|
||||
|
||||
n_current_arq_frame = static.ARQ_N_SENT_FRAMES + missing_frame + 1
|
||||
n_current_arq_frame = static.ARQ_N_SENT_FRAMES + missing_frame
|
||||
static.ARQ_TX_N_CURRENT_ARQ_FRAME = n_current_arq_frame.to_bytes(2, byteorder='big')
|
||||
|
||||
n_total_arq_frame = len(static.TX_BUFFER)
|
||||
|
@ -253,6 +254,7 @@ class RF():
|
|||
|
||||
#--------------------------------------------------------------------------------------------------------
|
||||
def receive(self,data_mode,signalling_mode):
|
||||
force = False
|
||||
|
||||
self.c_lib.freedv_open.restype = ctypes.POINTER(ctypes.c_ubyte)
|
||||
|
||||
|
@ -294,7 +296,7 @@ class RF():
|
|||
|
||||
self.c_lib.freedv_rawdatarx.argtype = [ctypes.POINTER(ctypes.c_ubyte), data_bytes_out, data_in] # check if really neccessary
|
||||
nbytes = self.c_lib.freedv_rawdatarx(freedv_data, data_bytes_out, data_in) # demodulate audio
|
||||
#print(self.c_lib.freedv_get_rx_status(freedv_data))
|
||||
print(self.c_lib.freedv_get_rx_status(freedv_data))
|
||||
|
||||
|
||||
#-------------STUCK IN SYNC DETECTOR
|
||||
|
@ -340,10 +342,11 @@ class RF():
|
|||
n_frames_per_burst = int.from_bytes(bytes(data_bytes_out[1:2]), "big")
|
||||
|
||||
if 50 >= frametype >= 10:
|
||||
if frame != 3:
|
||||
if frame != 3 or force == True:
|
||||
arq.data_received(bytes(data_bytes_out[:-2])) #send payload data to arq checker without CRC16
|
||||
else:
|
||||
print("---------------------------3er FRAME")
|
||||
force = True
|
||||
else:
|
||||
print("MODE: " + str(data_mode) + " DATA: " + str(bytes(data_bytes_out)))
|
||||
|
||||
|
@ -352,6 +355,9 @@ class RF():
|
|||
if frame == n_frames_per_burst:
|
||||
self.c_lib.freedv_set_sync(freedv_data, 0) #FORCE UNSYNC
|
||||
|
||||
if static.ARQ_RX_BURST_BUFFER.count(None) == 1:
|
||||
self.c_lib.freedv_set_sync(freedv_data, 0)
|
||||
|
||||
|
||||
while static.ARQ_STATE == 'IDLE' or static.ARQ_STATE == 'RECEIVING_ACK':
|
||||
time.sleep(0.01)
|
||||
|
@ -387,7 +393,7 @@ class RF():
|
|||
|
||||
|
||||
rxstatus = self.c_lib.freedv_get_rx_status(freedv_signalling)
|
||||
#print(rxstatus)
|
||||
print(rxstatus)
|
||||
if nbytes == static.FREEDV_SIGNALLING_BYTES_PER_FRAME or rxstatus == 10:
|
||||
self.c_lib.freedv_set_sync(freedv_signalling, 0) #FORCE UNSYNC
|
||||
|
||||
|
|
|
@ -87,9 +87,8 @@ ARQ_FRAME_ACK_RECEIVED = 0 # set to 1 if FRAME ACK received
|
|||
ARQ_ACK_TIMEOUT = 0 # set to 1 if timeut reached
|
||||
ARQ_ACK_TIMEOUT_SECONDS = 4.0 #timeout for waiting for ACK frames
|
||||
|
||||
ARQ_RX_TIMEOUT = 0
|
||||
ARQ_RX_TIMEOUT_SECONDS = 10.0 #timeout for waiting for a frame before resetting RX machine
|
||||
|
||||
ARQ_RPT_TIMEOUT = False
|
||||
ARQ_RPT_TIMEOUT_SECONDS = 4.0
|
||||
ARQ_RPT_RECEIVED = False #indicate if RPT frame has been received
|
||||
ARQ_RPT_FRAMES = []
|
||||
|
||||
|
|
Loading…
Reference in a new issue