Skip to content

Instantly share code, notes, and snippets.

@darksidelemm
Created March 19, 2022 10:12
Show Gist options
  • Save darksidelemm/9b9574e71a228aee3bc86da3957093b3 to your computer and use it in GitHub Desktop.
Save darksidelemm/9b9574e71a228aee3bc86da3957093b3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#
# Hacky Rig Sync Utility.
#
# Reads frequency from one rigctld server, and sends it to another rigctld server.
#
# My use-case: Syncing up a SDR++ instance (connected to a remote spyserver) to my
# Icom IC-7610. In my case I'm using wfview's rigctld server to access the Icom.
#
#
# Copyright (C) 2022 Mark Jessop <vk5qi@rfhead.net>
# Released under GNU GPL v3 or later
#
import socket
import time
import logging
import traceback
from threading import Thread
class RIGCTLD(object):
""" rigctld (hamlib) communication class """
# Note: This is a massive hack.
def __init__(self, hostname, port=4533, timeout=1):
""" Open a connection to rigctld """
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.settimeout(timeout)
self.hostname = hostname
self.port = port
def connect(self):
""" Connect to rotctld instance """
self.sock.connect((self.hostname,self.port))
def close(self):
self.sock.close()
def send_command(self, command, check_response = False):
""" Send a command to the connected rotctld instance,
and return the return value.
"""
command = command.encode('ascii')
self.sock.sendall(command+b'\n')
if check_response:
try:
return self.sock.recv(1024).decode('ascii')
except:
return None
else:
return "RPRT 0"
def get_freq(self):
freq = self.send_command('f', check_response=True)
return freq.strip()
def set_freq(self,freq):
self.send_command('F ' + freq)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--srchost", default="localhost", type=str, help="Source RIGCTLD hostname. (Default: localhost)")
parser.add_argument("--srcport", default=4533, type=int, help="Source RIGCTLD Port (Default: 4533)")
parser.add_argument("--dsthost", default="localhost", type=str, help="Destination RIGCTLD hostname. (Default: localhost)")
parser.add_argument("--dstport", default=4532, type=int, help="Destination RIGCTLD Port (Default: 4533)")
parser.add_argument("--pollperiod", default=0.2, type=float, help="Polling period (seconds). (Default: 0.2 seconds)")
args = parser.parse_args()
rig1 = RIGCTLD(
hostname=args.srchost,
port=args.srcport
)
rig1.connect()
rig2 = RIGCTLD(
hostname=args.dsthost,
port=args.dstport
)
rig2.connect()
while True:
# Get Freq from Source Rig
freq = rig1.get_freq()
# Send to destination rig
rig2.set_freq(freq)
print(f"Update frequency: {freq} Hz")
time.sleep(args.pollperiod)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment