mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
first try with data channel timeout and keep alive
This commit is contained in:
parent
56915c39c0
commit
b2b53386d3
3 changed files with 88 additions and 15 deletions
|
@ -28,6 +28,7 @@ modem = modem.RF()
|
|||
def arq_data_received(data_in):
|
||||
|
||||
static.TNC_STATE = 'BUSY'
|
||||
static.ARQ_DATA_CHANNEL_LAST_RECEIVED = int(time.time())
|
||||
|
||||
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
|
||||
|
@ -520,6 +521,7 @@ async def arq_connect():
|
|||
|
||||
def arq_received_connect(data_in):
|
||||
static.ARQ_STATE = 'CONNECTING'
|
||||
static.ARQ_CONNECTION_KEEP_ALIVE_RECEIVED = int(time.time())
|
||||
|
||||
static.DXCALLSIGN = bytes(data_in[3:9]).rstrip(b'\x00')
|
||||
static.DXCALLSIGN_CRC8 = helpers.get_crc_8(static.DXCALLSIGN)
|
||||
|
@ -541,6 +543,8 @@ def arq_received_connect(data_in):
|
|||
|
||||
|
||||
def arq_transmit_keep_alive():
|
||||
static.ARQ_CONNECTION_KEEP_ALIVE_RECEIVED = int(time.time()) # we need to reset the counter at this point
|
||||
|
||||
frame_type = bytes([221])
|
||||
connection_frame = bytearray(14)
|
||||
connection_frame[:1] = frame_type
|
||||
|
@ -555,7 +559,9 @@ def arq_transmit_keep_alive():
|
|||
def arq_received_connect_keep_alive(data_in):
|
||||
if static.ARQ_SEND_KEEP_ALIVE == True and (static.ARQ_STATE == 'CONNECTING' or static.ARQ_STATE == 'CONNECTED'):
|
||||
logging.info("CONN [" + str(static.MYCALLSIGN, 'utf-8') + "] >|< [" + str(static.DXCALLSIGN, 'utf-8') + "] [BER." + str(static.BER) + "]")
|
||||
|
||||
static.ARQ_STATE = 'CONNECTED'
|
||||
static.ARQ_CONNECTION_KEEP_ALIVE_RECEIVED = int(time.time())
|
||||
|
||||
frame_type = bytes([221])
|
||||
connection_frame = bytearray(14)
|
||||
|
@ -584,6 +590,7 @@ async def arq_open_data_channel():
|
|||
logging.info("DATA [" + str(static.MYCALLSIGN, 'utf-8') + "]>> <<[" + str(static.DXCALLSIGN, 'utf-8') + "] [BER." + str(static.BER) + "]")
|
||||
static.ARQ_SEND_KEEP_ALIVE = False
|
||||
static.ARQ_DATA_CHANNEL_MODE = 12
|
||||
static.ARQ_DATA_CHANNEL_LAST_RECEIVED = int(time.time())
|
||||
|
||||
while static.CHANNEL_STATE == 'SENDING_SIGNALLING':
|
||||
time.sleep(0.01)
|
||||
|
@ -604,8 +611,12 @@ async def arq_open_data_channel():
|
|||
|
||||
def arq_received_data_channel_opener(data_in):
|
||||
logging.info("DATA [" + str(static.MYCALLSIGN, 'utf-8') + "]>> <<[" + str(static.DXCALLSIGN, 'utf-8') + "] [BER." + str(static.BER) + "]")
|
||||
|
||||
static.ARQ_STATE = 'CONNECTED'
|
||||
static.TNC_STATE = 'BUSY'
|
||||
static.ARQ_SEND_KEEP_ALIVE = False
|
||||
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_READY_FOR_DATA = int.from_bytes(bytes(data_in[13:14]), "big")
|
||||
|
||||
connection_frame = bytearray(14)
|
||||
|
@ -619,19 +630,23 @@ def arq_received_data_channel_opener(data_in):
|
|||
while static.CHANNEL_STATE == 'SENDING_SIGNALLING':
|
||||
time.sleep(0.01)
|
||||
|
||||
# print("waiting for data....")
|
||||
print("waiting for data....")
|
||||
static.CHANNEL_STATE = 'RECEIVING_DATA'
|
||||
# einen timeout benötigen wir auch noch....
|
||||
|
||||
|
||||
|
||||
# und ab hier geht es dann in den "RECEIVING_DATA" mode....
|
||||
|
||||
|
||||
def arq_received_channel_is_open(data_in):
|
||||
static.ARQ_SEND_KEEP_ALIVE == False
|
||||
static.ARQ_SEND_KEEP_ALIVE = False
|
||||
static.ARQ_DATA_CHANNEL_LAST_RECEIVED = int(time.time())
|
||||
|
||||
if static.ARQ_DATA_CHANNEL_MODE == int.from_bytes(bytes(data_in[12:13]), "big"):
|
||||
logging.info("DATA [" + str(static.MYCALLSIGN, 'utf-8') + "]>>|<<[" + str(static.DXCALLSIGN, 'utf-8') + "] [BER." + str(static.BER) + "]")
|
||||
time.sleep(1)
|
||||
static.ARQ_READY_FOR_DATA = True
|
||||
static.ARQ_DATA_CHANNEL_LAST_RECEIVED = int(time.time())
|
||||
|
||||
|
||||
# ############################################################################################################
|
||||
|
|
56
helpers.py
56
helpers.py
|
@ -13,6 +13,7 @@ import crcengine
|
|||
|
||||
|
||||
import static
|
||||
import data_handler
|
||||
|
||||
|
||||
def get_crc_8(data):
|
||||
|
@ -42,6 +43,60 @@ def get_crc_16(data):
|
|||
crc_data = crc_data.to_bytes(2, byteorder='big')
|
||||
return crc_data
|
||||
|
||||
def watchdog():
|
||||
"""
|
||||
Author: DJ2LS
|
||||
|
||||
watchdog master function. Frome here we call the watchdogs
|
||||
"""
|
||||
while True:
|
||||
time.sleep(0.01)
|
||||
connection_keep_alive_watchdog()
|
||||
data_channel_keep_alive_watchdog()
|
||||
|
||||
def connection_keep_alive_watchdog():
|
||||
"""
|
||||
Author: DJ2LS
|
||||
|
||||
Function to trigger a DISCONNECT, if timeout for receiving a keep alive frame is reached
|
||||
|
||||
"""
|
||||
|
||||
if static.ARQ_STATE == 'CONNECTED' and not static.ARQ_READY_FOR_DATA and static.TNC_STATE == 'IDLE' and static.ARQ_SEND_KEEP_ALIVE:
|
||||
time.sleep(0.01)
|
||||
if static.ARQ_CONNECTION_KEEP_ALIVE_RECEIVED + 20 > time.time():
|
||||
static.ARQ_SEND_KEEP_ALIVE = True
|
||||
else:
|
||||
# TODO: show time out message
|
||||
static.ARQ_SEND_KEEP_ALIVE = False
|
||||
static.ARQ_CONNECTION_KEEP_ALIVE_RECEIVED = 0
|
||||
static.ARQ_STATE = 'IDLE'
|
||||
print("keep alive timeout")
|
||||
asyncio.run(data_handler.arq_disconnect())
|
||||
|
||||
def data_channel_keep_alive_watchdog():
|
||||
"""
|
||||
Author: DJ2LS
|
||||
|
||||
|
||||
"""
|
||||
|
||||
if static.ARQ_STATE == 'CONNECTED' and static.TNC_STATE == 'BUSY' and not static.ARQ_SEND_KEEP_ALIVE:
|
||||
time.sleep(0.01)
|
||||
if static.ARQ_DATA_CHANNEL_LAST_RECEIVED + 20 > time.time():
|
||||
static.ARQ_SEND_KEEP_ALIVE = False
|
||||
#print("alles okay mit den daten....")
|
||||
else:
|
||||
# TODO: show time out message
|
||||
# static.ARQ_SEND_KEEP_ALIVE = True
|
||||
static.ARQ_DATA_CHANNEL_LAST_RECEIVED = 0
|
||||
print("data keep alive timeout")
|
||||
arq_reset_frame_machine()
|
||||
data_handler.arq_transmit_keep_alive()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
async def set_after_timeout():
|
||||
"""
|
||||
|
@ -135,6 +190,7 @@ def arq_reset_frame_machine():
|
|||
static.CHANNEL_STATE = 'RECEIVING_SIGNALLING'
|
||||
static.ARQ_READY_FOR_DATA = False
|
||||
|
||||
|
||||
def setup_logging():
|
||||
"""
|
||||
Author: DJ2LS
|
||||
|
|
|
@ -154,9 +154,11 @@ TNC_STATE = 'IDLE'
|
|||
# MODE FOR SENDING AN RECEIVING DATA DURING ARQ SESSION
|
||||
ARQ_READY_FOR_DATA = False
|
||||
ARQ_DATA_CHANNEL_MODE = 12
|
||||
ARQ_DATA_CHANNEL_LAST_RECEIVED = 0
|
||||
|
||||
# SEND KEEP ALIVE ONLY IF WE WANT
|
||||
ARQ_SEND_KEEP_ALIVE = True
|
||||
ARQ_CONNECTION_KEEP_ALIVE_RECEIVED = 0
|
||||
#ARQ_WAIT_FOR_DISCONNECT = False
|
||||
|
||||
# ------- TX BUFFER
|
||||
|
|
Loading…
Reference in a new issue