Committing since I'm about to make a large change. Everything is awesome, except that if a large step size is selected on the rig, then the Gqrx can never successfully set the rig freq.

This commit is contained in:
Rob French 2020-09-29 10:38:56 -05:00
parent 769e1ca274
commit 623956731c
1 changed files with 64 additions and 61 deletions

View File

@ -34,6 +34,7 @@ RIG_CMD = 1
RIG_WAIT = 2
GQRX_CMD = 3
GQRX_WAIT = 4
DELAY = 5
delay_secs = 0.5
timeout = 0.0
@ -118,35 +119,31 @@ 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)
return (int(rs.recv(1024)), is_usb, step)
def set_rig_freq(rs, gs, freq, ifreq, isusb):
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)
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)
if DEBUG:
print('Set GQRX Freq: {}'.format(freq).encode())
gs.send('F {}'.format(freq).encode())
gs.recv(1024)
def get_gqrx_freq(gs):
gs.send(b'f\n')
return int(gs.recv(1024)) #* -1
def set_gqrx_freq(gs, freq, ifreq, isusb):
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:
@ -154,14 +151,7 @@ def set_gqrx_freq(gs, freq, ifreq, isusb):
gs.send('LNB_LO {}'.format(lnb).encode())
gs.recv(1024)
if DEBUG:
print('Set GQRX Freq: {}'.format(freq).encode())
#gs.send('F {}'.format(-1 * freq).encode())
gs.send('F {}'.format(freq).encode())
gs.recv(1024)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-ga', '--gqrx-address', type=str, default='localhost',
@ -199,8 +189,10 @@ def main():
tmp_is_usb = True
old_rig_freq = -1 # force initial update
old_gqrx_freq = -1 # force initial update
tuning_step = -1
(rig_freq, is_usb) = get_rig_freq(rs)
(rig_freq, is_usb, tuning_step) = get_rig_freq(rs)
gqrx_freq = get_gqrx_freq(gs)
state = WAITING
@ -212,10 +204,14 @@ def main():
allow_rig_to_gqrx = window.rig_to_gqrx.get()
allow_gqrx_to_rig = window.gqrx_to_rig.get()
(rig_freq, is_usb) = get_rig_freq(rs)
(rig_freq, is_usb, tuning_step) = get_rig_freq(rs)
gqrx_freq = get_gqrx_freq(gs)
#-----------------------------------------------------------------
# Update the GUI, if the freqs/modes have changed.
#-----------------------------------------------------------------
if rig_freq != old_rig_freq:
if rig_freq != old_rig_freq or is_usb != old_is_usb:
window.rig_freq.set(freq_to_string(rig_freq))
if is_usb:
window.rig_mode.set("USB")
@ -225,47 +221,54 @@ def main():
if gqrx_freq != old_gqrx_freq:
window.gqrx_freq.set(freq_to_string(gqrx_freq))
if state == WAITING:
if (rig_freq != old_rig_freq or is_usb != old_is_usb) and allow_rig_to_gqrx:
set_gqrx_freq(gs, rig_freq, if_freq, is_usb)
timeout = time.time() + delay_secs
state = RIG_CMD
if DEBUG:
print("\nNew state: RIG_CMD\n");
#-----------------------------------------------------------------
# Update the Rig and/or Gqrx, as applicable
#-----------------------------------------------------------------
elif (gqrx_freq != old_gqrx_freq) and allow_gqrx_to_rig:
# Regardless of anything else, if the rig freq changes, the
# LNB LO frequency must be updated.
if (rig_freq != old_rig_freq):
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")
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, gs, gqrx_freq, if_freq, tmp_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");
elif (rig_freq != gqrx_freq) and allow_rig_to_gqrx and allow_gqrx_to_rig:
set_gqrx_freq(gs, rig_freq, if_freq, is_usb)
timeout = time.time() + delay_secs
state = RIG_CMD
if DEBUG:
print("\nNew state: RIG_CMD\n");
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
if DEBUG:
print("\nNew state: WAITING\n");
if state == RIG_CMD:
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
if DEBUG:
print("\nNew state: WAITING\n");
if state == GQRX_CMD:
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
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