Simplified, solved the tuning step problem, but now tuning is backwards again (if I disable Swap I/Q), or just wrong (if I enable Swap I/Q).

This commit is contained in:
Rob French 2020-09-29 11:48:12 -05:00
parent 623956731c
commit b3887bc68d

View File

@ -28,15 +28,7 @@ from Tkinter import *
DEBUG=True
# States
WAITING = 0
RIG_CMD = 1
RIG_WAIT = 2
GQRX_CMD = 3
GQRX_WAIT = 4
DELAY = 5
delay_secs = 0.5
delay_secs = 0.05 # 50 msec delay
timeout = 0.0
usb_if_offset = 0 #-2250
@ -119,16 +111,12 @@ def calc_lnb_lo(freq, ifreq, isusb=True):
def get_rig_freq(rs):
rs.send(b'm\n')
is_usb = True if rs.recv(1024).splitlines()[0] == "USB" else False
rs.send(b'n\n')
print(rs.recv(1024))
step = 1000
rs.send(b'f\n')
return (int(rs.recv(1024)), is_usb, step)
return (int(rs.recv(1024)), is_usb)
def set_rig_freq(rs, freq):
if DEBUG:
print('Set Rig freq: {}'.format(freq).encode())
rs.send(b'F ' + str(freq) + '\n')
rs.recv(1024)
@ -139,16 +127,13 @@ def get_gqrx_freq(gs):
def set_gqrx_freq(gs, freq):
if DEBUG:
print('Set GQRX Freq: {}'.format(freq).encode())
gs.send('F {}'.format(freq).encode())
gs.recv(1024)
def set_gqrx_lnb_lo(gs, freq, ifreq, isusb):
lnb = calc_lnb_lo(freq, ifreq, isusb)
if DEBUG:
print('Set LNB Freq: {}'.format(lnb).encode())
gs.send('LNB_LO {}'.format(lnb).encode())
gs.recv(1024)
@ -185,18 +170,13 @@ def main():
try:
if_freq = int(args.ifreq * 1e6)
old_is_usb = True
tmp_is_usb = True
old_is_usb = False
old_rig_freq = -1 # force initial update
old_gqrx_freq = -1 # force initial update
tuning_step = -1
(rig_freq, is_usb, tuning_step) = get_rig_freq(rs)
(rig_freq, is_usb) = get_rig_freq(rs)
gqrx_freq = get_gqrx_freq(gs)
state = WAITING
tk = Tk()
window = MainWindow(tk)
@ -204,7 +184,7 @@ def main():
allow_rig_to_gqrx = window.rig_to_gqrx.get()
allow_gqrx_to_rig = window.gqrx_to_rig.get()
(rig_freq, is_usb, tuning_step) = get_rig_freq(rs)
(rig_freq, is_usb) = get_rig_freq(rs)
gqrx_freq = get_gqrx_freq(gs)
#-----------------------------------------------------------------
@ -226,53 +206,39 @@ def main():
#-----------------------------------------------------------------
# Regardless of anything else, if the rig freq changes, the
# LNB LO frequency must be updated.
if (rig_freq != old_rig_freq):
# LNB LO frequency must be updated (even if allow_rig_to_gqrx is
# false).
if rig_freq != old_rig_freq or is_usb != old_is_usb:
if DEBUG:
print("\nRig freq changed -- update LNB LO\n")
set_gqrx_lnb_lo(gs, rig_freq, if_freq, is_usb)
set_gqrx_freq(gs, gqrx_freq)
if DEBUG:
print("\nFreq mismatch, updated LNB LO\n")
#time.sleep(delay_secs)
if state == WAITING:
if allow_rig_to_gqrx and ((rig_freq != old_rig_freq or is_usb != old_is_usb) or (rig_freq != gqrx_freq)):
set_gqrx_lnb_lo(gs, rig_freq, if_freq, is_usb)
set_gqrx_freq(gs, rig_freq)
timeout = time.time() + delay_secs
if DEBUG:
print("\nNew state: RIG_CMD\n")
elif allow_gqrx_to_rig and ((gqrx_freq != old_gqrx_freq) or (abs(rig_freq - gqrx_freq) >= tuning_step)):
tmp_is_usb = is_usb
set_rig_freq(rs, gqrx_freq)
set_gqrx_lnb_lo(gs, gqrx_freq, if_freq, is_usb)
set_gqrx_freq(gs, gqrx_freq)
timeout = time.time() + delay_secs
state = GQRX_CMD
if DEBUG:
print("\nNew state: GQRX_CMD\n");
if allow_rig_to_gqrx and (rig_freq != old_rig_freq or is_usb != old_is_usb):
if DEBUG:
print("\nRig freq to Gqrx freq\n")
set_gqrx_lnb_lo(gs, rig_freq, if_freq, is_usb)
set_gqrx_freq(gs, rig_freq)
#time.sleep(delay_secs)
if state == RIG_CMD and (time.time() > timeout or rig_freq == gqrx_freq):
#if rig_freq != old_rig_freq or is_usb != old_is_usb:
# set_gqrx_freq(gs, rig_freq, if_freq, is_usb)
# timeout = time.time() + delay_secs
#elif time.time() > timeout or rig_freq == gqrx_freq:
state = WAITING
elif allow_gqrx_to_rig and gqrx_freq != old_gqrx_freq:
if DEBUG:
print("\nNew state: WAITING\n");
print("\nGqrx freq to Rig freq\n")
if state == GQRX_CMD and (time.time() > timeout or (abs(rig_freq - gqrx_freq) < tuning_step)):
#if gqrx_freq != old_gqrx_freq:
# set_rig_freq(rs, gs, gqrx_freq, if_freq, tmp_is_usb)
# timeout = time.time() + delay_secs
#elif time.time() > timeout or rig_freq == gqrx_freq:
state = WAITING
if DEBUG:
print("\nNew state: WAITING\n");
is_usb = tmp_is_usb
else:
pass
# First set the rig frequency,then wait to ensure it takes.
set_rig_freq(rs, gqrx_freq)
#time.sleep(delay_secs)
# Now grab the rig frequency and use it to re-set the Gqrx
# frequency. This is due to the fact that tuning steps on
# the rig may prevent the actual Gqrx frequency from being
# set, so Gqrx will use whatever the rig accepted.
(rig_freq, is_usb) = get_rig_freq(rs)
set_gqrx_lnb_lo(gs, rig_freq, if_freq, is_usb)
set_gqrx_freq(gs, rig_freq)
#time.sleep(delay_secs)
tk.update_idletasks()
tk.update()
time.sleep(args.interval / 1000.0)