mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
beacon placeholder and connect optimization
This commit is contained in:
parent
812e00a403
commit
697106b567
|
@ -197,7 +197,7 @@ def data_received(data_in):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.error("ARQ | RX | DATA FRAME NOT SUCESSFULLY RECEIVED!")
|
logging.error("ARQ | RX | DATA FRAME NOT SUCESSFULLY RECEIVED!")
|
||||||
static.TNC_STATE = b'IDLE'
|
static.ARQ_STATE = b'IDLE'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -258,13 +258,13 @@ def transmit(data_out):
|
||||||
TRANSMIT_ARQ_BURST_THREAD.start()
|
TRANSMIT_ARQ_BURST_THREAD.start()
|
||||||
|
|
||||||
# lets wait during sending. After sending is finished we will continue
|
# lets wait during sending. After sending is finished we will continue
|
||||||
while static.ARQ_STATE == 'SENDING_DATA':
|
while static.CHANNEL_STATE == 'SENDING_DATA':
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
# --------------------------- START TIMER FOR WAITING FOR ACK ---> IF TIMEOUT REACHED, ACK_TIMEOUT = 1
|
# --------------------------- START TIMER FOR WAITING FOR ACK ---> IF TIMEOUT REACHED, ACK_TIMEOUT = 1
|
||||||
|
|
||||||
logging.debug("ARQ | RX | WAITING FOR BURST ACK")
|
logging.debug("ARQ | RX | WAITING FOR BURST ACK")
|
||||||
static.ARQ_STATE = 'RECEIVING_SIGNALLING'
|
static.CHANNEL_STATE = 'RECEIVING_SIGNALLING'
|
||||||
|
|
||||||
helpers.arq_reset_timeout(False)
|
helpers.arq_reset_timeout(False)
|
||||||
helpers.arq_reset_ack(False)
|
helpers.arq_reset_ack(False)
|
||||||
|
@ -298,7 +298,7 @@ def transmit(data_out):
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
|
||||||
static.ARQ_STATE = 'RECEIVING_SIGNALLING'
|
static.CHANNEL_STATE = 'RECEIVING_SIGNALLING'
|
||||||
|
|
||||||
helpers.arq_reset_timeout(False)
|
helpers.arq_reset_timeout(False)
|
||||||
helpers.arq_reset_ack(False)
|
helpers.arq_reset_ack(False)
|
||||||
|
@ -368,7 +368,7 @@ def transmit(data_out):
|
||||||
|
|
||||||
frametimer = threading.Timer(static.ARQ_RX_FRAME_TIMEOUT_SECONDS, helpers.arq_frame_timeout)
|
frametimer = threading.Timer(static.ARQ_RX_FRAME_TIMEOUT_SECONDS, helpers.arq_frame_timeout)
|
||||||
frametimer.start()
|
frametimer.start()
|
||||||
static.ARQ_STATE = 'RECEIVING_SIGNALLING'
|
static.CHANNEL_STATE = 'RECEIVING_SIGNALLING'
|
||||||
|
|
||||||
# wait for frame ACK if we processed the last frame/burst
|
# wait for frame ACK if we processed the last frame/burst
|
||||||
while static.ARQ_FRAME_ACK_RECEIVED == False and static.ARQ_RX_FRAME_TIMEOUT == False and static.ARQ_N_SENT_FRAMES == static.TX_BUFFER_SIZE:
|
while static.ARQ_FRAME_ACK_RECEIVED == False and static.ARQ_RX_FRAME_TIMEOUT == False and static.ARQ_N_SENT_FRAMES == static.TX_BUFFER_SIZE:
|
||||||
|
@ -448,6 +448,7 @@ def burst_rpt_received(data_in):
|
||||||
#############################################################################################################
|
#############################################################################################################
|
||||||
|
|
||||||
def arq_connect(callsign):
|
def arq_connect(callsign):
|
||||||
|
static.ARQ_STATE = 'CONNECTING'
|
||||||
logging.info("CONNECTING ["+ str(static.MYCALLSIGN, 'utf-8') + "]-> <-["+ callsign + "]")
|
logging.info("CONNECTING ["+ str(static.MYCALLSIGN, 'utf-8') + "]-> <-["+ callsign + "]")
|
||||||
frame_type = bytes([220])
|
frame_type = bytes([220])
|
||||||
connection_frame = frame_type + static.MYCALLSIGN
|
connection_frame = frame_type + static.MYCALLSIGN
|
||||||
|
@ -456,6 +457,7 @@ def arq_connect(callsign):
|
||||||
TRANSMIT_CONNECT_THREAD.start()
|
TRANSMIT_CONNECT_THREAD.start()
|
||||||
|
|
||||||
def arq_received_connect(data_in):
|
def arq_received_connect(data_in):
|
||||||
|
static.ARQ_STATE = 'CONNECTING'
|
||||||
dxcallsign = data_in[1:6]
|
dxcallsign = data_in[1:6]
|
||||||
static.DXCALLSIGN = bytes(dxcallsign)
|
static.DXCALLSIGN = bytes(dxcallsign)
|
||||||
static.DXCALLSIGN_CRC8 = helpers.get_crc_8(static.DXCALLSIGN)
|
static.DXCALLSIGN_CRC8 = helpers.get_crc_8(static.DXCALLSIGN)
|
||||||
|
@ -467,12 +469,37 @@ def arq_received_connect(data_in):
|
||||||
TRANSMIT_CONNECT_THREAD.start()
|
TRANSMIT_CONNECT_THREAD.start()
|
||||||
|
|
||||||
def arq_received_connect_keep_alive(data_in):
|
def arq_received_connect_keep_alive(data_in):
|
||||||
|
static.ARQ_STATE = 'CONNECTED'
|
||||||
logging.info("CONNECTED ["+ str(static.MYCALLSIGN, 'utf-8') + "] >< ["+ str(static.DXCALLSIGN, 'utf-8') + "]")
|
logging.info("CONNECTED ["+ str(static.MYCALLSIGN, 'utf-8') + "] >< ["+ str(static.DXCALLSIGN, 'utf-8') + "]")
|
||||||
frame_type = bytes([221])
|
frame_type = bytes([221])
|
||||||
connection_frame = frame_type + static.MYCALLSIGN
|
connection_frame = frame_type + static.MYCALLSIGN
|
||||||
TRANSMIT_CONNECT_THREAD = threading.Thread(target=modem.transmit_signalling, args=[connection_frame], name="TRANSMIT_ARQ")
|
|
||||||
TRANSMIT_CONNECT_THREAD.start()
|
|
||||||
|
|
||||||
|
acktimer = threading.Timer(3.0, modem.transmit_signalling, args=[connection_frame])
|
||||||
|
acktimer.start()
|
||||||
|
#TRANSMIT_CONNECT_THREAD = threading.Thread(target=modem.transmit_signalling, args=[connection_frame], name="TRANSMIT_ARQ")
|
||||||
|
#TRANSMIT_CONNECT_THREAD.start()
|
||||||
|
|
||||||
|
|
||||||
|
def arq_disconnect():
|
||||||
|
static.ARQ_STATE = 'DISCONNECTING'
|
||||||
|
logging.info("DISCONNECTING ["+ str(static.MYCALLSIGN, 'utf-8') + "] <--> ["+ str(static.DXCALLSIGN, 'utf-8') + "]")
|
||||||
|
frame_type = bytes([222])
|
||||||
|
disconnection_frame = frame_type + static.MYCALLSIGN
|
||||||
|
TRANSMIT_DISCONNECT_THREAD = threading.Thread(target=modem.transmit_signalling, args=[disconnection_frame], name="TRANSMIT_ARQ")
|
||||||
|
TRANSMIT_DISCONNECT_THREAD.start()
|
||||||
|
|
||||||
|
logging.info("DISCONNECTED ["+ str(static.MYCALLSIGN, 'utf-8') + "] < > ["+ str(static.DXCALLSIGN, 'utf-8') + "]")
|
||||||
|
static.ARQ_STATE = 'IDLE'
|
||||||
|
static.DXCALLSIGN = b''
|
||||||
|
static.DXCALLSIGN_CRC8 = b''
|
||||||
|
|
||||||
|
def arq_disconnect_received(data_in):
|
||||||
|
static.ARQ_STATE = 'DISCONNECTED'
|
||||||
|
logging.info("DISCONNECTED ["+ str(static.MYCALLSIGN, 'utf-8') + "] >< ["+ str(static.DXCALLSIGN, 'utf-8') + "]")
|
||||||
|
static.ARQ_STATE = 'DISCONNECTED'
|
||||||
|
static.TNC_STATE = 'IDLE'
|
||||||
|
static.DXCALLSIGN = b''
|
||||||
|
static.DXCALLSIGN_CRC8 = b''
|
||||||
|
|
||||||
#############################################################################################################
|
#############################################################################################################
|
||||||
# PING HANDLER
|
# PING HANDLER
|
||||||
|
@ -501,8 +528,6 @@ def received_ping(data_in):
|
||||||
TRANSMIT_PING_THREAD = threading.Thread(target=modem.transmit_signalling, args=[ping_frame], name="TRANSMIT_ARQ")
|
TRANSMIT_PING_THREAD = threading.Thread(target=modem.transmit_signalling, args=[ping_frame], name="TRANSMIT_ARQ")
|
||||||
TRANSMIT_PING_THREAD.start()
|
TRANSMIT_PING_THREAD.start()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def received_ping_ack(data_in):
|
def received_ping_ack(data_in):
|
||||||
|
|
||||||
dxcallsign = data_in[1:6]
|
dxcallsign = data_in[1:6]
|
||||||
|
@ -523,3 +548,12 @@ def transmit_cq():
|
||||||
modem.transmit_signalling(cq_frame)
|
modem.transmit_signalling(cq_frame)
|
||||||
|
|
||||||
|
|
||||||
|
def transmit_beacon():
|
||||||
|
logging.info("BEACON")
|
||||||
|
frame_type = bytes([230])
|
||||||
|
print(frame_type)
|
||||||
|
beacon_frame = frame_type + static.MYCALLSIGN
|
||||||
|
while static.TNC_STATE = 'BEACON':
|
||||||
|
time.sleep(0.01)
|
||||||
|
beacontimer = threading.Timer(60.0, modem.transmit_signalling, args=[beacon_frame])
|
||||||
|
beacontimer.start()
|
||||||
|
|
20
modem.py
20
modem.py
|
@ -96,7 +96,7 @@ class RF():
|
||||||
def transmit_signalling(self,ack_buffer):
|
def transmit_signalling(self,ack_buffer):
|
||||||
#print(ack_buffer)
|
#print(ack_buffer)
|
||||||
#static.ARQ_STATE = 'SENDING_ACK'
|
#static.ARQ_STATE = 'SENDING_ACK'
|
||||||
static.ARQ_STATE = 'SENDING_SIGNALLING'
|
static.CHANNEL_STATE = 'SENDING_SIGNALLING'
|
||||||
static.PTT_STATE = True
|
static.PTT_STATE = True
|
||||||
self.my_rig.set_ptt(self.hamlib_ptt_type,1)
|
self.my_rig.set_ptt(self.hamlib_ptt_type,1)
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ class RF():
|
||||||
self.my_rig.set_ptt(self.hamlib_ptt_type,0)
|
self.my_rig.set_ptt(self.hamlib_ptt_type,0)
|
||||||
static.PTT_STATE = False
|
static.PTT_STATE = False
|
||||||
|
|
||||||
static.ARQ_STATE = 'RECEIVING_SIGNALLING'
|
static.CHANNEL_STATE = 'RECEIVING_SIGNALLING'
|
||||||
#static.ARQ_STATE = 'RECEIVING_DATA'
|
#static.ARQ_STATE = 'RECEIVING_DATA'
|
||||||
#--------------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------------
|
||||||
# GET ARQ BURST FRAME VOM BUFFER AND MODULATE IT
|
# GET ARQ BURST FRAME VOM BUFFER AND MODULATE IT
|
||||||
|
@ -144,7 +144,7 @@ class RF():
|
||||||
|
|
||||||
self.my_rig.set_ptt(self.hamlib_ptt_type,1)
|
self.my_rig.set_ptt(self.hamlib_ptt_type,1)
|
||||||
static.PTT_STATE = True
|
static.PTT_STATE = True
|
||||||
static.ARQ_STATE = 'SENDING_DATA'
|
static.CHANNEL_STATE = 'SENDING_DATA'
|
||||||
|
|
||||||
self.c_lib.freedv_open.restype = ctypes.POINTER(ctypes.c_ubyte)
|
self.c_lib.freedv_open.restype = ctypes.POINTER(ctypes.c_ubyte)
|
||||||
freedv = self.c_lib.freedv_open(static.FREEDV_DATA_MODE)
|
freedv = self.c_lib.freedv_open(static.FREEDV_DATA_MODE)
|
||||||
|
@ -243,7 +243,7 @@ class RF():
|
||||||
# -------------- transmit audio
|
# -------------- transmit audio
|
||||||
self.stream_tx.write(bytes(txbuffer))
|
self.stream_tx.write(bytes(txbuffer))
|
||||||
#static.ARQ_STATE = 'IDLE'
|
#static.ARQ_STATE = 'IDLE'
|
||||||
static.ARQ_STATE = 'RECEIVING_SIGNALLING'
|
static.CHANNEL_STATE = 'RECEIVING_SIGNALLING'
|
||||||
static.PTT_STATE = False
|
static.PTT_STATE = False
|
||||||
self.my_rig.set_ptt(self.hamlib_ptt_type,0)
|
self.my_rig.set_ptt(self.hamlib_ptt_type,0)
|
||||||
#--------------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------------
|
||||||
|
@ -278,7 +278,7 @@ class RF():
|
||||||
stuck_in_sync_10_counter = 0
|
stuck_in_sync_10_counter = 0
|
||||||
#
|
#
|
||||||
|
|
||||||
while static.ARQ_STATE == 'RECEIVING_DATA':
|
while static.CHANNEL_STATE == 'RECEIVING_DATA':
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
nin = self.c_lib.freedv_nin(freedv_data)
|
nin = self.c_lib.freedv_nin(freedv_data)
|
||||||
|
@ -362,7 +362,7 @@ class RF():
|
||||||
|
|
||||||
|
|
||||||
#while static.ARQ_STATE == 'IDLE' or static.ARQ_STATE == 'RECEIVING_SIGNALLING':
|
#while static.ARQ_STATE == 'IDLE' or static.ARQ_STATE == 'RECEIVING_SIGNALLING':
|
||||||
while static.ARQ_STATE == 'RECEIVING_SIGNALLING':
|
while static.CHANNEL_STATE == 'RECEIVING_SIGNALLING':
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
nin = self.c_lib.freedv_nin(freedv_signalling)
|
nin = self.c_lib.freedv_nin(freedv_signalling)
|
||||||
|
@ -418,6 +418,14 @@ class RF():
|
||||||
logging.debug("ARQ CONNECT ACK RECEIVED / KEEP ALIVE....")
|
logging.debug("ARQ CONNECT ACK RECEIVED / KEEP ALIVE....")
|
||||||
data_handler.arq_received_connect_keep_alive(signalling_bytes_out[:-2])
|
data_handler.arq_received_connect_keep_alive(signalling_bytes_out[:-2])
|
||||||
|
|
||||||
|
# ARQ CONNECT ACK / KEEP ALIVE
|
||||||
|
elif frametype == 222:
|
||||||
|
logging.debug("ARQ DISCONNECT RECEIVED")
|
||||||
|
data_handler.arq_disconnect_received(signalling_bytes_out[:-2])
|
||||||
|
|
||||||
|
# ARQ CONNECT ACK / KEEP ALIVE
|
||||||
|
elif frametype == 230:
|
||||||
|
logging.debug("BEACON RECEIVED")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.info("OTHER FRAME: " + str(signalling_bytes_out[:-2]))
|
logging.info("OTHER FRAME: " + str(signalling_bytes_out[:-2]))
|
||||||
|
|
28
sock.py
28
sock.py
|
@ -33,13 +33,13 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
data = data[:-1] # remove b'\n'
|
data = data[:-1] # remove b'\n'
|
||||||
data = str(data, 'utf-8')
|
data = str(data, 'utf-8')
|
||||||
|
|
||||||
# SOCKETTEST
|
# SOCKETTEST ---------------------------------------------------
|
||||||
if data == 'SOCKETTEST':
|
if data == 'SOCKETTEST':
|
||||||
cur_thread = threading.current_thread()
|
cur_thread = threading.current_thread()
|
||||||
response = bytes("WELL DONE! YOU ARE ABLE TO COMMUNICATE WITH THE TNC", encoding)
|
response = bytes("WELL DONE! YOU ARE ABLE TO COMMUNICATE WITH THE TNC", encoding)
|
||||||
self.request.sendall(response)
|
self.request.sendall(response)
|
||||||
|
|
||||||
# CQ CQ CQ
|
# CQ CQ CQ -----------------------------------------------------
|
||||||
if data == 'CQCQCQ':
|
if data == 'CQCQCQ':
|
||||||
for i in range(0,3):
|
for i in range(0,3):
|
||||||
data_handler.transmit_cq()
|
data_handler.transmit_cq()
|
||||||
|
@ -48,7 +48,7 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# PING
|
# PING ----------------------------------------------------------
|
||||||
if data.startswith('PING:'):
|
if data.startswith('PING:'):
|
||||||
#send ping frame and wait for ACK
|
#send ping frame and wait for ACK
|
||||||
pingcommand = data.split('PING:')
|
pingcommand = data.split('PING:')
|
||||||
|
@ -56,22 +56,32 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
data_handler.transmit_ping(dxcallsign)
|
data_handler.transmit_ping(dxcallsign)
|
||||||
|
|
||||||
|
|
||||||
# ARQ CONNECT TO CALLSIGN
|
# ARQ CONNECT TO CALLSIGN ----------------------------------------
|
||||||
if data.startswith('ARQ:CONNECT:'):
|
if data.startswith('ARQ:CONNECT:'):
|
||||||
if static.TNC_STATE == b'CONNECTED':
|
arqconnectcommand = data.split('ARQ:CONNECT:')
|
||||||
|
dxcallsign = arqconnectcommand[1]
|
||||||
|
if static.ARQ_STATE == b'CONNECTED':
|
||||||
# here we should disconnect
|
# here we should disconnect
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if static.TNC_STATE == b'IDLE':
|
if static.TNC_STATE == b'IDLE':
|
||||||
# here we send an "CONNECT FRAME
|
# here we send an "CONNECT FRAME
|
||||||
pass
|
|
||||||
|
ARQ_CONNECT_THREAD = threading.Thread(target=data_handler.arq_connect, args=[dxcallsign], name="ARQ_CONNECT")
|
||||||
|
ARQ_CONNECT_THREAD.start()
|
||||||
|
|
||||||
|
# ARQ DISCONNECT FROM CALLSIGN ----------------------------------------
|
||||||
|
if data == 'ARQ:DISCONNECT':
|
||||||
|
|
||||||
|
ARQ_DISCONNECT_THREAD = threading.Thread(target=data_handler.arq_disconnect, name="ARQ_DISCONNECT")
|
||||||
|
ARQ_DISCONNECT_THREAD.start()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# TRANSMIT ARQ MESSAGE
|
# TRANSMIT ARQ MESSAGE ------------------------------------------
|
||||||
# wen need to change the TNC_STATE to "CONNECTE" and need to make sure we have a valid callsign and callsign crc8 of the DX station
|
# wen need to change the TNC_STATE to "CONNECTE" and need to make sure we have a valid callsign and callsign crc8 of the DX station
|
||||||
if data.startswith('ARQ:') and static.TNC_STATE == b'IDLE':
|
if data.startswith('ARQ:DATA') and static.TNC_STATE == b'IDLE':
|
||||||
logging.info("CMD | NEW ARQ DATA")
|
logging.info("CMD | NEW ARQ DATA")
|
||||||
static.TNC_STATE = b'BUSY'
|
static.TNC_STATE = b'BUSY'
|
||||||
arqdata = data.split('ARQ:')
|
arqdata = data.split('ARQ:')
|
||||||
|
@ -82,7 +92,7 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# SETTINGS AND STATUS
|
# SETTINGS AND STATUS ---------------------------------------------
|
||||||
if data.startswith('SET:MYCALLSIGN:'):
|
if data.startswith('SET:MYCALLSIGN:'):
|
||||||
data = data.split('SET:MYCALLSIGN:')
|
data = data.split('SET:MYCALLSIGN:')
|
||||||
if bytes(data[1], encoding) == b'':
|
if bytes(data[1], encoding) == b'':
|
||||||
|
|
|
@ -148,7 +148,7 @@ ARQ_N_SENT_FRAMES = 0 #counter for already sent frames
|
||||||
# DISCONNECTED
|
# DISCONNECTED
|
||||||
# CONNECTING
|
# CONNECTING
|
||||||
# DISCONNECTING
|
# DISCONNECTING
|
||||||
ARQ_STATE = 'RECEIVING_SIGNALLING'
|
ARQ_STATE = 'IDLE'
|
||||||
|
|
||||||
# RECEIVING_SIGNALLING
|
# RECEIVING_SIGNALLING
|
||||||
# RECEIVING_DATA_10
|
# RECEIVING_DATA_10
|
||||||
|
|
Loading…
Reference in a new issue