mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
smaller pep8 improvements
This commit is contained in:
parent
0cfecd8190
commit
64e3d2abc0
28
tnc/sock.py
28
tnc/sock.py
|
@ -52,11 +52,9 @@ class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# noinspection PyTypeChecker
|
||||||
class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
""" """
|
""" """
|
||||||
|
|
||||||
connection_alive = False
|
|
||||||
|
|
||||||
connection_alive = False
|
connection_alive = False
|
||||||
log = structlog.get_logger("ThreadedTCPRequestHandler")
|
log = structlog.get_logger("ThreadedTCPRequestHandler")
|
||||||
|
|
||||||
|
@ -93,7 +91,8 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
client.send(sock_data)
|
client.send(sock_data)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self.log.info("[SCK] Connection lost", e=err)
|
self.log.info("[SCK] Connection lost", e=err)
|
||||||
# TODO: Check if we really should set connection alive to false. This might disconnect all other clients as well...
|
# TODO: Check if we really should set connection alive to false.
|
||||||
|
# This might disconnect all other clients as well...
|
||||||
self.connection_alive = False
|
self.connection_alive = False
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self.log.debug("[SCK] catch harmless RuntimeError: Set changed size during iteration", e=err)
|
self.log.debug("[SCK] catch harmless RuntimeError: Set changed size during iteration", e=err)
|
||||||
|
@ -136,7 +135,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
# wait some time between processing multiple commands
|
# wait some time between processing multiple commands
|
||||||
# this is only a first test to avoid doubled transmission
|
# this is only a first test to avoid doubled transmission
|
||||||
# we might improve this by only processing one command or
|
# we might improve this by only processing one command or
|
||||||
# doing some kind of selection to determin which commands need to be dropped
|
# doing some kind of selection to determine which commands need to be dropped
|
||||||
# and which one can be processed during a running transmission
|
# and which one can be processed during a running transmission
|
||||||
threading.Event().wait(0.5)
|
threading.Event().wait(0.5)
|
||||||
|
|
||||||
|
@ -186,10 +185,11 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
CONNECTED_CLIENTS.remove(self.request)
|
CONNECTED_CLIENTS.remove(self.request)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
self.log.warning(
|
self.log.warning(
|
||||||
"[SCK] client connection already removed from client list",
|
"[SCK] client connection already removed from client list",
|
||||||
client=self.request,
|
client=self.request,
|
||||||
|
e=e,
|
||||||
)
|
)
|
||||||
|
|
||||||
# ------------------------ TNC COMMANDS
|
# ------------------------ TNC COMMANDS
|
||||||
|
@ -306,7 +306,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
if TESTMODE:
|
if TESTMODE:
|
||||||
ThreadedTCPRequestHandler.tnc_arq_stop_transmission(None, received_json)
|
ThreadedTCPRequestHandler.tnc_arq_stop_transmission(None, received_json)
|
||||||
else:
|
else:
|
||||||
self.tnc_arq_stop_transmission(None, received_json)
|
self.tnc_arq_stop_transmission(received_json)
|
||||||
|
|
||||||
# GET RX BUFFER
|
# GET RX BUFFER
|
||||||
if received_json["type"] == "get" and received_json["command"] == "rx_buffer":
|
if received_json["type"] == "get" and received_json["command"] == "rx_buffer":
|
||||||
|
@ -355,6 +355,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
log.warning(
|
log.warning(
|
||||||
"[SCK] CQ command execution error", e=err, command=received_json
|
"[SCK] CQ command execution error", e=err, command=received_json
|
||||||
)
|
)
|
||||||
|
|
||||||
def tnc_set_record_audio(self, received_json):
|
def tnc_set_record_audio(self, received_json):
|
||||||
try:
|
try:
|
||||||
if not static.AUDIO_RECORD:
|
if not static.AUDIO_RECORD:
|
||||||
|
@ -421,6 +422,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
e=err,
|
e=err,
|
||||||
command=received_json,
|
command=received_json,
|
||||||
)
|
)
|
||||||
|
|
||||||
def tnc_cqcqcq(self, received_json):
|
def tnc_cqcqcq(self, received_json):
|
||||||
try:
|
try:
|
||||||
DATA_QUEUE_TRANSMIT.put(["CQ"])
|
DATA_QUEUE_TRANSMIT.put(["CQ"])
|
||||||
|
@ -445,6 +447,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
e=err,
|
e=err,
|
||||||
command=received_json,
|
command=received_json,
|
||||||
)
|
)
|
||||||
|
|
||||||
def tnc_stop_beacon(self, received_json):
|
def tnc_stop_beacon(self, received_json):
|
||||||
try:
|
try:
|
||||||
log.warning("[SCK] Stopping beacon!")
|
log.warning("[SCK] Stopping beacon!")
|
||||||
|
@ -458,6 +461,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
e=err,
|
e=err,
|
||||||
command=received_json,
|
command=received_json,
|
||||||
)
|
)
|
||||||
|
|
||||||
def tnc_ping_ping(self, received_json):
|
def tnc_ping_ping(self, received_json):
|
||||||
# send ping frame and wait for ACK
|
# send ping frame and wait for ACK
|
||||||
try:
|
try:
|
||||||
|
@ -728,11 +732,6 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
command=received_json,
|
command=received_json,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------ DAEMON COMMANDS
|
# ------------------------ DAEMON COMMANDS
|
||||||
def process_daemon_commands(self, data):
|
def process_daemon_commands(self, data):
|
||||||
"""
|
"""
|
||||||
|
@ -929,8 +928,8 @@ def send_daemon_state():
|
||||||
"input_devices": static.AUDIO_INPUT_DEVICES,
|
"input_devices": static.AUDIO_INPUT_DEVICES,
|
||||||
"output_devices": static.AUDIO_OUTPUT_DEVICES,
|
"output_devices": static.AUDIO_OUTPUT_DEVICES,
|
||||||
"serial_devices": static.SERIAL_DEVICES,
|
"serial_devices": static.SERIAL_DEVICES,
|
||||||
#'cpu': str(psutil.cpu_percent()),
|
# 'cpu': str(psutil.cpu_percent()),
|
||||||
#'ram': str(psutil.virtual_memory().percent),
|
# 'ram': str(psutil.virtual_memory().percent),
|
||||||
"version": "0.1",
|
"version": "0.1",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -944,6 +943,7 @@ def send_daemon_state():
|
||||||
log.warning("[SCK] error", e=err)
|
log.warning("[SCK] error", e=err)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def send_tnc_state():
|
def send_tnc_state():
|
||||||
"""
|
"""
|
||||||
send the tnc state to network
|
send the tnc state to network
|
||||||
|
|
Loading…
Reference in a new issue