1
0

16 bit length

This commit is contained in:
2026-02-25 16:36:57 +01:00
parent 7ddacd8545
commit e606802541
4 changed files with 189 additions and 72 deletions

24
xrd.py
View File

@@ -15,7 +15,7 @@ from functools import wraps
from typing import Callable
INITIAL_FREQ = 9500
INITIAL_EQ = False
INITIAL_EQ = True
INITIAL_IMS = True
HOST = os.getenv("HOST") or '0.0.0.0'
@@ -43,7 +43,7 @@ def init_tef():
tef.init(clock=CLOCK)
tef.AUDIO_Set_Mute(False)
tef.AUDIO_Set_Volume(30)
tef.FM_Tune_To(1, INITIAL_FREQ)
tef.FM_Tune_To(TEF6686.TuneTo_Mode.Preset, INITIAL_FREQ)
tef.FM_Set_RDS(1)
tef.FM_Set_ChannelEqualizer(INITIAL_EQ)
tef.FM_Set_MphSuppression(INITIAL_IMS)
@@ -55,11 +55,15 @@ def authenticate(conn: socket.socket):
salt = "".join(secrets.choice(string.ascii_lowercase) for _ in range(SALT_LENGTH))
conn.sendall(salt.encode() + b"\n")
expected_hash = hashlib.sha1((salt + PASSWORD).encode()).hexdigest().encode()
start = time.monotonic()
while True:
data = conn.recv(1024)
if not data: return False
if data.strip() == expected_hash.strip(): return True
try:
data = conn.recv(1024)
if not data: return False
if data.strip() == expected_hash.strip(): return True
except BlockingIOError:
if (time.monotonic() - start) > 3: conn.close() # Close connection if they can't fucking bruteforce the password in 3 seconds
def process_command(tef: TEF6686, data: bytes, state: dict, conn: socket.socket):
out = b""
@@ -67,7 +71,7 @@ def process_command(tef: TEF6686, data: bytes, state: dict, conn: socket.socket)
if cmd.startswith(b"T"):
freq = int(cmd.decode().removeprefix("T").strip()) // 10
if freq < 6500 or freq > 10800: continue
tef.FM_Tune_To(1, freq)
tef.FM_Tune_To(TEF6686.TuneTo_Mode.Preset, freq)
if not freq_allowed(freq): tef.AUDIO_Set_Mute(True)
else: tef.AUDIO_Set_Mute(False)
state['last_tune'] = freq
@@ -92,7 +96,7 @@ def process_command(tef: TEF6686, data: bytes, state: dict, conn: socket.socket)
elif cmd.startswith(b"x"):
out += b"OK\n"
tef.APPL_Set_OperationMode(False) # Enable
tef.FM_Tune_To(1, state["last_tune"])
tef.FM_Tune_To(TEF6686.TuneTo_Mode.Preset, state["last_tune"])
if not freq_allowed(state["last_tune"]): tef.AUDIO_Set_Mute(True)
else: tef.AUDIO_Set_Mute(False)
elif cmd.startswith(b"X"):
@@ -123,7 +127,7 @@ def process_command(tef: TEF6686, data: bytes, state: dict, conn: socket.socket)
if not start: conn.sendall(b", ") # Prevent trailing comma, because the FM-DX-Webserver spectrum plugin treats us as actual firmware and throws as harder api, without it we're treated as a module
start = False
tef.FM_Tune_To(2, freq) # Auto mutes, less commands sent
tef.FM_Tune_To(TEF6686.TuneTo_Mode.Search, freq) # Auto mutes, less commands sent
time.sleep(0.0067) # sick seven
if not freq_allowed(freq):
conn.sendall(f"{freq * 10} = 11.25".encode())
@@ -133,7 +137,7 @@ def process_command(tef: TEF6686, data: bytes, state: dict, conn: socket.socket)
conn.sendall(str(freq * 10).encode() + b" = " + str((level / 10) + 11.25).encode())
conn.sendall(b"\n")
tef.FM_Tune_To(1, state["last_tune"])
tef.FM_Tune_To(TEF6686.TuneTo_Mode.Preset, state["last_tune"])
if not freq_allowed(state["last_tune"]): tef.AUDIO_Set_Mute(True)
else: tef.AUDIO_Set_Mute(False)
tef.FM_Set_Bandwidth((state["bw"] == 0), 2360 if (state["bw"] == 0) else (state["bw"] // 100))
@@ -248,6 +252,7 @@ def run_server():
with conn:
reset_periodic()
print(f"Connected by {addr}")
conn.setblocking(False)
if not authenticate(conn):
print("Authentication failed.")
continue
@@ -259,7 +264,6 @@ def run_server():
conn.sendall(f"D{state['deemp']}\n".encode())
conn.sendall(f"W{state['bw']}\n".encode())
conn.sendall(f"M0\n".encode())
conn.setblocking(False)
while True:
try: