From 68d0e70a612b66baf4fe30feffe5a6e9d4e777de Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 8 Sep 2021 18:23:26 +0200 Subject: [PATCH] reset sock connection on decoding error --- tnc/modem.py | 2 +- tnc/sock.py | 35 ++++++++++++++++------------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/tnc/modem.py b/tnc/modem.py index 4367da06..b1dfa6e6 100644 --- a/tnc/modem.py +++ b/tnc/modem.py @@ -670,7 +670,7 @@ class RF(): # send fft only if receiving if static.CHANNEL_STATE == 'RECEIVING_SIGNALLING' or static.CHANNEL_STATE == 'RECEIVING_DATA': - static.FFT = dfftlist[:400] + static.FFT = dfftlist[20:380] # else send 0 else: static.FFT = [0] * 400 diff --git a/tnc/sock.py b/tnc/sock.py index 264d1a18..a523935a 100644 --- a/tnc/sock.py +++ b/tnc/sock.py @@ -64,26 +64,24 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler): socketTimeout = time.time() + static.SOCKET_TIMEOUT # convert data to json object - # we need to do some error handling in case of socket timeout - + # we need to do some error handling in case of socket timeout or decoding issue try: received_json = json.loads(data) - except ValueError as e: - print("++++++++++++ START OF JSON ERROR +++++++++++++++++++++++") - print(e) - print("-----------------------------------") - print(data) - print("++++++++++++ END OF JSON ERROR +++++++++++++++++++++++++") - received_json = {} - - - try: + #except ValueError as e: + # print("++++++++++++ START OF JSON ERROR +++++++++++++++++++++++") + # print(e) + # print("-----------------------------------") + # print(data) + # print("++++++++++++ END OF JSON ERROR +++++++++++++++++++++++++") + # received_json = {} + # break + #try: # CQ CQ CQ ----------------------------------------------------- if received_json["command"] == "CQCQCQ": - socketTimeout = 0 + #socketTimeout = 0 #asyncio.run(data_handler.transmit_cq()) CQ_THREAD = threading.Thread(target=data_handler.transmit_cq, args=[], name="CQ") CQ_THREAD.start() @@ -241,15 +239,12 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler): #if bufferposition <= len(static.RX_BUFFER) > 0: # print(static.RX_BUFFER[bufferposition]) # self.request.sendall(bytes(static.RX_BUFFER[bufferposition])) - - - - if received_json["type"] == 'SET' and received_json["command"] == 'DEL_RX_BUFFER': static.RX_BUFFER = [] - + + #exception, if JSON cant be decoded #except Exception as e: except ValueError as e: @@ -259,7 +254,9 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler): exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno) - print("############ END OF ERROR #######################") + print("############ END OF ERROR #######################") + print("reset of connection...") + socketTimeout = 0 print("Client disconnected...") def start_cmd_socket():