You've already forked TEF6686_Driver
add a freq lockout range
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import serial
|
import serial
|
||||||
import struct
|
import struct
|
||||||
import time
|
import time
|
||||||
import time
|
|
||||||
|
|
||||||
def crc8(data: bytes) -> int:
|
def crc8(data: bytes) -> int:
|
||||||
crc = 0x00
|
crc = 0x00
|
||||||
|
|||||||
20
xrd.py
20
xrd.py
@@ -16,6 +16,8 @@ HOST = os.getenv("HOST") or '0.0.0.0'
|
|||||||
PORT = int(os.getenv("PORT") or 0) or 7373
|
PORT = int(os.getenv("PORT") or 0) or 7373
|
||||||
DEVICE = os.getenv("DEV") or "COM6"
|
DEVICE = os.getenv("DEV") or "COM6"
|
||||||
|
|
||||||
|
FREQ_NOT_ALLOWED_RANGE = [9490, 9510]
|
||||||
|
|
||||||
PASSWORD = os.getenv("PW") or "test"
|
PASSWORD = os.getenv("PW") or "test"
|
||||||
CLOCK = 12000000 # DP-666
|
CLOCK = 12000000 # DP-666
|
||||||
|
|
||||||
@@ -61,6 +63,7 @@ def process_command(tef: TEF6686, data: bytes, state: dict, conn: socket.socket)
|
|||||||
if freq > 10800: continue
|
if freq > 10800: continue
|
||||||
state['last_tune'] = freq
|
state['last_tune'] = freq
|
||||||
tef.FM_Tune_To(1, freq)
|
tef.FM_Tune_To(1, freq)
|
||||||
|
if FREQ_NOT_ALLOWED_RANGE and freq >= FREQ_NOT_ALLOWED_RANGE[0] and freq <= FREQ_NOT_ALLOWED_RANGE[1]: tef.AUDIO_Set_Mute(True)
|
||||||
out += f"T{freq*10}\n".encode()
|
out += f"T{freq*10}\n".encode()
|
||||||
elif cmd.startswith(b"G"):
|
elif cmd.startswith(b"G"):
|
||||||
eqims = int(cmd.decode().removeprefix("G").strip(), 2)
|
eqims = int(cmd.decode().removeprefix("G").strip(), 2)
|
||||||
@@ -83,6 +86,7 @@ def process_command(tef: TEF6686, data: bytes, state: dict, conn: socket.socket)
|
|||||||
out += b"OK\n"
|
out += b"OK\n"
|
||||||
tef.APPL_Set_OperationMode(False)
|
tef.APPL_Set_OperationMode(False)
|
||||||
tef.FM_Tune_To(1, state["last_tune"])
|
tef.FM_Tune_To(1, state["last_tune"])
|
||||||
|
if FREQ_NOT_ALLOWED_RANGE and state["last_tune"] >= FREQ_NOT_ALLOWED_RANGE[0] and state["last_tune"] <= FREQ_NOT_ALLOWED_RANGE[1]: tef.AUDIO_Set_Mute(True)
|
||||||
elif cmd.startswith(b"X"):
|
elif cmd.startswith(b"X"):
|
||||||
tef.APPL_Set_OperationMode(True)
|
tef.APPL_Set_OperationMode(True)
|
||||||
elif cmd.startswith(b"W"):
|
elif cmd.startswith(b"W"):
|
||||||
@@ -108,17 +112,24 @@ def process_command(tef: TEF6686, data: bytes, state: dict, conn: socket.socket)
|
|||||||
for freq in range(state["scan_start"], state["scan_stop"] + state["scan_step"], state["scan_step"]):
|
for freq in range(state["scan_start"], state["scan_stop"] + state["scan_step"], state["scan_step"]):
|
||||||
tef.FM_Tune_To(2, freq) # Auto mutes, less commands sent
|
tef.FM_Tune_To(2, freq) # Auto mutes, less commands sent
|
||||||
time.sleep(0.0064)
|
time.sleep(0.0064)
|
||||||
|
if FREQ_NOT_ALLOWED_RANGE and freq >= FREQ_NOT_ALLOWED_RANGE[0] and freq <= FREQ_NOT_ALLOWED_RANGE[1]:
|
||||||
|
conn.sendall(f"{freq * 10} = 0, ".encode())
|
||||||
|
continue
|
||||||
_, level, *_ = d if (d := tef.FM_Get_Quality_Data()) else (None, None)
|
_, level, *_ = d if (d := tef.FM_Get_Quality_Data()) else (None, None)
|
||||||
if level is None: continue
|
if level is None: continue
|
||||||
conn.sendall(str(freq * 10).encode() + b" = " + str(level // 10).encode() + b", ")
|
conn.sendall(str(freq * 10).encode() + b" = " + str(level // 10).encode() + b", ")
|
||||||
conn.sendall(b"\n")
|
conn.sendall(b"\n")
|
||||||
|
|
||||||
tef.FM_Tune_To(1, state["last_tune"])
|
tef.FM_Tune_To(1, state["last_tune"])
|
||||||
|
if FREQ_NOT_ALLOWED_RANGE and freq >= FREQ_NOT_ALLOWED_RANGE[0] and freq <= FREQ_NOT_ALLOWED_RANGE[1]: tef.AUDIO_Set_Mute(True)
|
||||||
tef.FM_Set_Bandwidth((state["bw"] == 0), 2360 if (state["bw"] == 0) else (state["bw"] // 100))
|
tef.FM_Set_Bandwidth((state["bw"] == 0), 2360 if (state["bw"] == 0) else (state["bw"] // 100))
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def send_signal_status(tef: TEF6686, conn: socket.socket, state: dict):
|
def send_signal_status(tef: TEF6686, conn: socket.socket, state: dict):
|
||||||
|
if FREQ_NOT_ALLOWED_RANGE and state["last_tune"] >= FREQ_NOT_ALLOWED_RANGE[0] and state["last_tune"] <= FREQ_NOT_ALLOWED_RANGE[1]:
|
||||||
|
conn.sendall(b"Sm0.0,0,0,0\n\n")
|
||||||
|
return
|
||||||
_, _, stereo, _ = d if (d := tef.FM_Get_Processing_Status()) else (None, None, 1000, None)
|
_, _, stereo, _ = d if (d := tef.FM_Get_Processing_Status()) else (None, None, 1000, None)
|
||||||
|
|
||||||
res = tef.FM_Get_Quality_Data()
|
res = tef.FM_Get_Quality_Data()
|
||||||
@@ -135,7 +146,9 @@ def send_signal_status(tef: TEF6686, conn: socket.socket, state: dict):
|
|||||||
data += f"{level},{wam//10},{usn//10},{bandwidth}\n\n".encode()
|
data += f"{level},{wam//10},{usn//10},{bandwidth}\n\n".encode()
|
||||||
conn.sendall(data)
|
conn.sendall(data)
|
||||||
|
|
||||||
def send_rds_data(tef: TEF6686, conn: socket.socket):
|
def send_rds_data(tef: TEF6686, conn: socket.socket, state: dict):
|
||||||
|
if FREQ_NOT_ALLOWED_RANGE and state["last_tune"] >= FREQ_NOT_ALLOWED_RANGE[0] and state["last_tune"] <= FREQ_NOT_ALLOWED_RANGE[1]: return
|
||||||
|
|
||||||
res = tef.FM_Get_RDS_Data__decoder()
|
res = tef.FM_Get_RDS_Data__decoder()
|
||||||
if res is None: return
|
if res is None: return
|
||||||
status, A, B, C, D, dec_error = res
|
status, A, B, C, D, dec_error = res
|
||||||
@@ -221,8 +234,7 @@ def run_server():
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
data = conn.recv(1024)
|
if not (data := conn.recv(1024)): break
|
||||||
if not data: break
|
|
||||||
resp = process_command(tef, data, state, conn)
|
resp = process_command(tef, data, state, conn)
|
||||||
if resp: conn.sendall(resp)
|
if resp: conn.sendall(resp)
|
||||||
except ConnectionResetError: break
|
except ConnectionResetError: break
|
||||||
@@ -232,7 +244,7 @@ def run_server():
|
|||||||
send_signal_status(tef, conn, state)
|
send_signal_status(tef, conn, state)
|
||||||
ss_timer.reset()
|
ss_timer.reset()
|
||||||
if rds_timer.get_time() > RDS_UPDATE_INTERVAL:
|
if rds_timer.get_time() > RDS_UPDATE_INTERVAL:
|
||||||
send_rds_data(tef, conn)
|
send_rds_data(tef, conn, state)
|
||||||
rds_timer.reset()
|
rds_timer.reset()
|
||||||
time.sleep(0.015)
|
time.sleep(0.015)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user