gqrx-panadapter/gqrx-panadapter.py

130 lines
4.3 KiB
Python
Executable File

#!/usr/bin/env python
#
# Copyright 2017 Alexander Fasching
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import print_function, division
import sys
import argparse
import socket
import time
DEBUG=True
usb_if_offset = -2700
lsb_if_offset = 2730
def calc_lnb_lo(freq, if_freq, is_usb=True):
if is_usb:
if DEBUG:
print('USB IF: ' + str(if_freq + usb_if_offset))
return freq - (if_freq - usb_if_offset)
else:
if DEBUG:
print('LSB IF: ' + str(if_freq + lsb_if_offset))
return freq - (if_freq - lsb_if_offset)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-ga', '--gqrx-address', type=str, default='localhost',
metavar='A', help='address that Gqrx is listening on')
parser.add_argument('-gp', '--gqrx-port', type=int, default=7356,
metavar='P', help='remote control port configured in Gqrx')
parser.add_argument('-ra', '--rigctld-address', type=str, default='localhost',
metavar='A', help='address that rigctld is listening on')
parser.add_argument('-rp', '--rigctld-port', type=int, default=4532,
metavar='P', help='listening port of rigctld')
parser.add_argument('-i', '--interval', type=int, default=1000,
metavar='T', help='update interval in milliseconds')
parser.add_argument('-f', '--ifreq', type=float, default=68.33,
metavar='F', help='intermediate frequency in MHz')
args = parser.parse_args()
try:
rs = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
rs.connect((args.rigctld_address, args.rigctld_port))
except Exception as e:
print('Connection to rigctld failed:', e, file=sys.stderr)
return 1
try:
gs = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
gs.connect((args.gqrx_address, args.gqrx_port))
except Exception as e:
print('Connection to Gqrx failed:', e, file=sys.stderr)
return 1
try:
iffreq = int(args.ifreq * 1e6)
old_rigfreq = 0
old_lnbfreq = 0
old_gqrxfreq = 0
while True:
if DEBUG:
print('--------------------')
rs.send(b'm\n')
is_usb = True if rs.recv(1024).splitlines()[0] == "USB" else False
rs.send(b'f\n')
rigfreq = int(rs.recv(1024))
lnbfreq = calc_lnb_lo(rigfreq, iffreq, is_usb)
if lnbfreq != old_lnbfreq:
if DEBUG:
print('LNB Freq: {}'.format(lnbfreq).encode())
gs.send('LNB_LO {}'.format(lnbfreq).encode())
gs.recv(1024)
old_lnbfreq = lnbfreq
if rigfreq != old_rigfreq:
if DEBUG:
print('Rig Freq: {}'.format(rigfreq).encode())
gs.send('F {}'.format(rigfreq).encode())
gs.recv(1024)
old_rigfreq = rigfreq
old_gqrxfreq = rigfreq
# gs.send(b'f\n')
# gqrxfreq = int(gs.recv(1024))
# if DEBUG:
# print('Gqrx freq: {}'.format(gqrxfreq).encode())
# if gqrxfreq != old_gqrxfreq:
# rs.send(b'F ' + str(gqrxfreq) + '\n')
# rs.recv(1024)
# old_gqrxfreq = gqrxfreq
# old_rigfreq = gqrxfreq
#
# lnbfreq = calc_lnb_lo(rigfreq, iffreq), is_usb)
# gs.send('LNB_LO {}'.format(lnbfreq).encode())
# gs.recv(1024)
# old_lnb_freq = lnbfreq
time.sleep(args.interval / 100.0)
except KeyboardInterrupt:
pass
except Exception as e:
print('Unexpected error:', e, file=sys.stderr)
return 1
rs.close()
gs.close()
if __name__ == '__main__':
sys.exit(main() or 0)