You've already forked TEF6686_Driver
better rds thing
This commit is contained in:
35
xrd.py
35
xrd.py
@@ -124,7 +124,7 @@ def process_command(tef: TEF6686, data: bytes, state: dict, conn: socket.socket)
|
||||
start = False
|
||||
|
||||
tef.FM_Tune_To(2, freq) # Auto mutes, less commands sent
|
||||
time.sleep(0.0064)
|
||||
time.sleep(0.0067) # sick seven
|
||||
if not freq_allowed(freq):
|
||||
conn.sendall(f"{freq * 10} = 11.25".encode())
|
||||
continue
|
||||
@@ -137,7 +137,7 @@ def process_command(tef: TEF6686, data: bytes, state: dict, conn: socket.socket)
|
||||
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))
|
||||
|
||||
|
||||
return out
|
||||
|
||||
PERIODIC_FUNCTIONS: list[tuple[Callable, float, libtimer.Timer]] = []
|
||||
@@ -187,29 +187,26 @@ def send_rds_data(tef: TEF6686, conn: socket.socket, state: dict):
|
||||
res = tef.FM_Get_RDS_Data__decoder()
|
||||
if res is None: return
|
||||
status, A, B, C, D, dec_error = res
|
||||
dec_error >>= 8
|
||||
|
||||
if (status & (1 << 9) == 0) or (status & (1 << 15) == 0): return
|
||||
|
||||
data = b""
|
||||
a_error = dec_error >> 6
|
||||
c_error = (dec_error >> 2) & 0b11
|
||||
if (status & (1 << 13) == 0):
|
||||
err = 0
|
||||
err |= ((dec_error >> 8) & 0x30) >> 4
|
||||
err |= ((dec_error >> 8) & 0xC)
|
||||
err |= ((dec_error >> 8) & 3) << 4
|
||||
|
||||
data = b"R"
|
||||
data += f"{B:04X}{C:04X}{D:04X}{err:02X}\n".encode()
|
||||
|
||||
pi_error = (dec_error >> 14) & 0b11
|
||||
if pi_error < 3:
|
||||
data += b"P" + f"{A:04X}".encode()
|
||||
data += b"?" * pi_error + b"\n"
|
||||
elif status & (1 << 12):
|
||||
pi_error = (dec_error >> 10) & 0b11
|
||||
if pi_error < 3:
|
||||
data += b"P" + f"{C:04X}".encode()
|
||||
data += b"?" * pi_error + b"\n"
|
||||
if (status & (1 << 12) == 0):
|
||||
# Type A, PI in A
|
||||
data = f"R{A:04X}{B:04X}{C:04X}".encode()
|
||||
elif (status >> 12) & 1:
|
||||
# Type B, PI in A and C
|
||||
pi = A
|
||||
if c_error < a_error: pi = C
|
||||
data = f"R{pi:04X}{B:04X}{pi:04X}".encode()
|
||||
data += f"{D:04X}{dec_error:02X}\n".encode()
|
||||
else: data = f"P{A:04X}{"?" * a_error}\n".encode() # No group data, only PI
|
||||
|
||||
if not data.strip(): return
|
||||
conn.sendall(data)
|
||||
|
||||
def run_server():
|
||||
|
||||
Reference in New Issue
Block a user