mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
cleanup & optimized data/cmd socket
This commit is contained in:
parent
a5d0e6e608
commit
4e3d2cc158
2 changed files with 39 additions and 27 deletions
15
modem.py
15
modem.py
|
@ -259,17 +259,16 @@ class RF():
|
|||
stuck_in_sync_10_counter += 1
|
||||
|
||||
|
||||
#print(stuck_in_sync_counter)
|
||||
#if stuck_in_sync_counter == 33 and self.c_lib.freedv_get_rx_status(freedv_data) == 10:
|
||||
# print("stuck in sync #1 --> DOING UNSYNC")
|
||||
# self.c_lib.freedv_set_sync(freedv_data, 0) #FORCE UNSYNC
|
||||
# stuck_in_sync_counter = 0
|
||||
# stuck_in_sync_10_counter = 0
|
||||
# data_in = None
|
||||
if stuck_in_sync_counter == 33 and self.c_lib.freedv_get_rx_status(freedv_data) == 10:
|
||||
logging.critical("stuck in sync #1")
|
||||
self.c_lib.freedv_set_sync(freedv_data, 0) #FORCE UNSYNC
|
||||
stuck_in_sync_counter = 0
|
||||
stuck_in_sync_10_counter = 0
|
||||
data_in = None
|
||||
|
||||
|
||||
if stuck_in_sync_counter >= 66 and stuck_in_sync_10_counter >= 2:
|
||||
logging.critical("modem stuck in sync")
|
||||
logging.critical("stuck in sync #2")
|
||||
self.c_lib.freedv_set_sync(freedv_data, 0) #FORCE UNSYNC
|
||||
stuck_in_sync_counter = 0
|
||||
stuck_in_sync_10_counter = 0
|
||||
|
|
51
sock.py
51
sock.py
|
@ -24,6 +24,15 @@ class DATATCPRequestHandler(socketserver.BaseRequestHandler):
|
|||
self.data += chunk
|
||||
if chunk.endswith(b'\n'):
|
||||
break
|
||||
|
||||
# SEND AN ARQ FRAME -------------------------
|
||||
if self.data.startswith(b'ARQ:'):
|
||||
|
||||
data = self.data.split(b'ARQ:')
|
||||
data_out = data[1]
|
||||
|
||||
TRANSMIT_ARQ = threading.Thread(target=arq.transmit, args=[data_out], name="TRANSMIT_ARQ")
|
||||
TRANSMIT_ARQ.start()
|
||||
|
||||
|
||||
|
||||
|
@ -60,25 +69,29 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
|||
if self.data.startswith(b'SHOWBUFFERSIZE'):
|
||||
self.request.sendall(bytes(static.RX_BUFFER[-1]))
|
||||
print(static.RX_BUFFER_SIZE)
|
||||
|
||||
# BROADCAST PARSER -----------------------------------------------------------
|
||||
|
||||
if self.data.startswith(b'BC:'):
|
||||
#import modem
|
||||
#modem = modem.RF()
|
||||
|
||||
data = self.data.split(b'BC:')
|
||||
#modem.Transmit(data[1])
|
||||
|
||||
|
||||
|
||||
# SEND AN ARQ FRAME -----------------------------------------------------------
|
||||
|
||||
if self.data.startswith(b'ARQ:'):
|
||||
|
||||
data = self.data.split(b'ARQ:')
|
||||
data_out = data[1]
|
||||
|
||||
TRANSMIT_ARQ = threading.Thread(target=arq.transmit, args=[data_out], name="TRANSMIT_ARQ")
|
||||
TRANSMIT_ARQ.start()
|
||||
|
||||
|
||||
def start_cmd_socket():
|
||||
|
||||
try:
|
||||
logging.info("SRV | STARTING TCP/IP SOCKET FOR CMD ON PORT: " + str(static.PORT))
|
||||
socketserver.TCPServer.allow_reuse_address = True #https://stackoverflow.com/a/16641793
|
||||
cmdserver = socketserver.TCPServer((static.HOST, static.PORT), CMDTCPRequestHandler)
|
||||
cmdserver.serve_forever()
|
||||
|
||||
finally:
|
||||
cmdserver.server_close()
|
||||
|
||||
|
||||
def start_data_socket():
|
||||
|
||||
try:
|
||||
logging.info("SRV | STARTING TCP/IP SOCKET FOR DATA ON PORT: " + str(static.PORT + 1))
|
||||
socketserver.TCPServer.allow_reuse_address = True #https://stackoverflow.com/a/16641793
|
||||
dataserver = socketserver.TCPServer((static.HOST, static.PORT + 1), DATATCPRequestHandler)
|
||||
dataserver.serve_forever()
|
||||
|
||||
finally:
|
||||
dataserver.server_close()
|
||||
|
|
Loading…
Reference in a new issue