diff --git a/modem.py b/modem.py index 6579f012..2dcdbd3e 100644 --- a/modem.py +++ b/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 diff --git a/sock.py b/sock.py index f5eb3895..ebbc18f0 100644 --- a/sock.py +++ b/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()