improve performance
This commit is contained in:
@@ -11,6 +11,7 @@ from functools import wraps
|
|||||||
from typing import Callable
|
from typing import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
|
import select
|
||||||
|
|
||||||
class Modulation(IntEnum):
|
class Modulation(IntEnum):
|
||||||
FM = 0
|
FM = 0
|
||||||
@@ -90,12 +91,6 @@ def init_tef():
|
|||||||
tef.FM_Set_ChannelEqualizer(INITIAL_EQ)
|
tef.FM_Set_ChannelEqualizer(INITIAL_EQ)
|
||||||
tef.FM_Set_MphSuppression(INITIAL_IMS)
|
tef.FM_Set_MphSuppression(INITIAL_IMS)
|
||||||
|
|
||||||
tef.FM_Set_LevelStep(-1, -1, -1, -1, -4, -8, 0)
|
|
||||||
tef.FM_Set_Highcut_Mph(0)
|
|
||||||
tef.FM_Set_Highcut_Max(False)
|
|
||||||
tef.FM_Set_Lowcut_Max(True, 60)
|
|
||||||
tef.FM_Set_Stereo_Time(60, 120, 100, 200)
|
|
||||||
|
|
||||||
tef.FM_Set_Stereo_Max(STEREO_BLENDING)
|
tef.FM_Set_Stereo_Max(STEREO_BLENDING)
|
||||||
tef.APPL_Set_OperationMode(True) # Turn off
|
tef.APPL_Set_OperationMode(True) # Turn off
|
||||||
return tef
|
return tef
|
||||||
@@ -216,9 +211,8 @@ def reset_periodic():
|
|||||||
|
|
||||||
def run_periodic(*args, **kwargs):
|
def run_periodic(*args, **kwargs):
|
||||||
for (func, t, timer) in PERIODIC_FUNCTIONS:
|
for (func, t, timer) in PERIODIC_FUNCTIONS:
|
||||||
max_catchup = 10
|
|
||||||
count = 0
|
count = 0
|
||||||
while timer.get_time() > t and count < max_catchup:
|
while timer.get_time() > t and count < 5:
|
||||||
func(*args, **kwargs)
|
func(*args, **kwargs)
|
||||||
timer.subtract(t)
|
timer.subtract(t)
|
||||||
count += 1
|
count += 1
|
||||||
@@ -321,7 +315,6 @@ def run_server():
|
|||||||
if not authenticate(conn):
|
if not authenticate(conn):
|
||||||
print("Authentication failed.")
|
print("Authentication failed.")
|
||||||
continue
|
continue
|
||||||
conn.setblocking(False)
|
|
||||||
|
|
||||||
# Send initial state
|
# Send initial state
|
||||||
conn.sendall(f"T{state.last_tune_fm*10}\n".encode())
|
conn.sendall(f"T{state.last_tune_fm*10}\n".encode())
|
||||||
@@ -331,27 +324,26 @@ def run_server():
|
|||||||
conn.sendall(f"W{state.bw_fm}\n".encode())
|
conn.sendall(f"W{state.bw_fm}\n".encode())
|
||||||
conn.sendall(f"M{tef.modulation}\n".encode())
|
conn.sendall(f"M{tef.modulation}\n".encode())
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
readable, _, _ = select.select([conn], [], [], 0.03)
|
||||||
|
if readable:
|
||||||
|
data = conn.recv(256)
|
||||||
|
if not data: break
|
||||||
try:
|
try:
|
||||||
if not (data := conn.recv(1024)): break
|
resp = process_command(tef, data, state, conn)
|
||||||
|
if resp: conn.sendall(resp)
|
||||||
|
except Exception as e:
|
||||||
try:
|
try:
|
||||||
resp = process_command(tef, data, state, conn)
|
print(e)
|
||||||
if resp: conn.sendall(resp)
|
conn.sendall(b"!" + str(e).encode() + b"\n")
|
||||||
except Exception as e:
|
except Exception: pass
|
||||||
try:
|
else:
|
||||||
print(e)
|
try: run_periodic(tef, conn, state)
|
||||||
conn.sendall(b"!" + str(e).encode() + b"\n")
|
except Exception as e:
|
||||||
except Exception: pass
|
try:
|
||||||
except ConnectionResetError: break
|
print(e)
|
||||||
except ConnectionAbortedError: break
|
conn.sendall(b"!" + str(e).encode() + b"\n")
|
||||||
except BlockingIOError:
|
except Exception: pass
|
||||||
try: run_periodic(tef, conn, state)
|
|
||||||
except Exception as e:
|
|
||||||
try:
|
|
||||||
print(e)
|
|
||||||
conn.sendall(b"!" + str(e).encode() + b"\n")
|
|
||||||
except Exception: pass
|
|
||||||
time.sleep(0.03)
|
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user