reset sock connection on decoding error

This commit is contained in:
DJ2LS 2021-09-08 18:23:26 +02:00 committed by GitHub
parent 65c52ce9b0
commit 68d0e70a61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 20 deletions

View file

@ -670,7 +670,7 @@ class RF():
# send fft only if receiving # send fft only if receiving
if static.CHANNEL_STATE == 'RECEIVING_SIGNALLING' or static.CHANNEL_STATE == 'RECEIVING_DATA': 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 send 0
else: else:
static.FFT = [0] * 400 static.FFT = [0] * 400

View file

@ -64,26 +64,24 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
socketTimeout = time.time() + static.SOCKET_TIMEOUT socketTimeout = time.time() + static.SOCKET_TIMEOUT
# convert data to json object # 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: try:
received_json = json.loads(data) received_json = json.loads(data)
except ValueError as e: #except ValueError as e:
print("++++++++++++ START OF JSON ERROR +++++++++++++++++++++++") # print("++++++++++++ START OF JSON ERROR +++++++++++++++++++++++")
print(e) # print(e)
print("-----------------------------------") # print("-----------------------------------")
print(data) # print(data)
print("++++++++++++ END OF JSON ERROR +++++++++++++++++++++++++") # print("++++++++++++ END OF JSON ERROR +++++++++++++++++++++++++")
received_json = {} # received_json = {}
# break
#try:
try:
# CQ CQ CQ ----------------------------------------------------- # CQ CQ CQ -----------------------------------------------------
if received_json["command"] == "CQCQCQ": if received_json["command"] == "CQCQCQ":
socketTimeout = 0 #socketTimeout = 0
#asyncio.run(data_handler.transmit_cq()) #asyncio.run(data_handler.transmit_cq())
CQ_THREAD = threading.Thread(target=data_handler.transmit_cq, args=[], name="CQ") CQ_THREAD = threading.Thread(target=data_handler.transmit_cq, args=[], name="CQ")
CQ_THREAD.start() CQ_THREAD.start()
@ -241,15 +239,12 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
#if bufferposition <= len(static.RX_BUFFER) > 0: #if bufferposition <= len(static.RX_BUFFER) > 0:
# print(static.RX_BUFFER[bufferposition]) # print(static.RX_BUFFER[bufferposition])
# self.request.sendall(bytes(static.RX_BUFFER[bufferposition])) # self.request.sendall(bytes(static.RX_BUFFER[bufferposition]))
if received_json["type"] == 'SET' and received_json["command"] == 'DEL_RX_BUFFER': if received_json["type"] == 'SET' and received_json["command"] == 'DEL_RX_BUFFER':
static.RX_BUFFER = [] static.RX_BUFFER = []
#exception, if JSON cant be decoded #exception, if JSON cant be decoded
#except Exception as e: #except Exception as e:
except ValueError as e: except ValueError as e:
@ -259,7 +254,9 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
exc_type, exc_obj, exc_tb = sys.exc_info() exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno) 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...") print("Client disconnected...")
def start_cmd_socket(): def start_cmd_socket():