Skip to content

Instantly share code, notes, and snippets.

@oddstr13
Created January 29, 2016 17:17
Show Gist options
  • Save oddstr13/872da895e618ba5c8d60 to your computer and use it in GitHub Desktop.
Save oddstr13/872da895e618ba5c8d60 to your computer and use it in GitHub Desktop.
#!/usr/bin/python2
import socket
import time
dump_state = []
# rigctld protocol version
dump_state.append( b"0" )
# rig model
dump_state.append( b"1" )
# ITU region
dump_state.append( b"1" ) # Europe, Africa and Northern Asia
#dump_state.append( b"2" ) # North America, South America and Greenland
#dump_state.append( b"3" ) # South Pacific and Southern Asia
# RX frequency ranges
# start, end, modes, low_power, high_power, vfo, ant
#dump_state.append( b"150000.000000 1500000000.000000 0x1ff -1 -1 0x10000003 0x3" )
# AM | CW | USB | LSB | NFM | WFM | DSB
dump_state.append( b"100000.000000 6000000000.000000 0x8006f -1 -1 0x4000000 0x3" ) # HackRF (100kHz - 6GHz), VFO:Main
# End of RX frequency ranges
dump_state.append( b"0 0 0 0 0 0 0" )
# TX frequency ranges
# start, end, modes, low_power, high_power, vfo, ant
dump_state.append( b"100000.000000 6000000000.000000 0x8006f -1 -1 0x4000000 0x3" ) # HackRF (100kHz - 6GHz), VFO:Main
# End of TX frequency ranges
dump_state.append( b"0 0 0 0 0 0 0" )
# Tuning steps
# mode, tuning_step
dump_state.append( b"0x1ff 1" )
dump_state.append( b"0x1ff 0" )
# End of tuning steps
dump_state.append( b"0 0" )
# Filter sizes
# mode, width
dump_state.append( b"0x1e 2400" )
dump_state.append( b"0x2 500" )
dump_state.append( b"0x1 8000" )
dump_state.append( b"0x1 2400" )
dump_state.append( b"0x20 15000" )
dump_state.append( b"0x20 8000" )
dump_state.append( b"0x40 230000" )
# End of filter sizes
dump_state.append( b"0 0" )
# ------ ??? ------
# max_rit
dump_state.append( b"9990" )
# max_xit
dump_state.append( b"9990" )
# max_ifshift
dump_state.append( b"10000" )
# announces
dump_state.append( b"0" )
# MAXDBLSTSIZ preamp
dump_state.append( b"10" )
# MAXDBLSTSIZ attenuator
dump_state.append( b"10 20 30" )
# has_get_func
dump_state.append( b"0x3effffff" )
# has_set_func
dump_state.append( b"0x3effffff" )
# has_get_level
dump_state.append( b"0xfffffffff7ffffff" )
# has_set_level
dump_state.append( b"0xffffffff83ffffff" )
# has_get_parm
dump_state.append( b"0xffffffffffffffff" )
# has_set_parm
dump_state.append( b"0xffffffffffffffbf" )
# END
dump_state = b'\n'.join(dump_state)
ls = socket.socket()
ls.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
ls.bind(("", 10800))
ls.listen(1)
while True:
c, addr = ls.accept()
print("+++ Connected from {}.".format(addr))
s = socket.socket()
s.connect(("127.0.0.1", 7356))
s.setblocking(False)
c.setblocking(False)
while True:
try:
data = c.recv(1024)
print(repr(data))
if not data:
print("--- Client {} closed connection.".format(addr))
s.close()
break
for line in data.strip().split(b'\n'):
print(">>> {}".format(line))
if line.startswith(b"\\dump_state"):
c.send(dump_state + b'\n')
elif line == b"v":
print("### Main")
c.send(b'Main\n')
elif line == b"s":
print("### USB 0 Main")
c.send(b'USB 0 Main\n')
else:
s.send(line + b'\r\n')
except socket.error as e:
if e.errno == 11: # Resource temporarily unavailable
pass
else:
print((type(e), e))
raise
try:
data = s.recv(1024)
print(repr(data))
if not data:
print("--- Server closed connection with {}.".format(addr))
c.close()
break
for line in data.strip().split(b'\n'):
print("<<< {}".format(line))
if line == b"USB":
print("### USB 0")
c.send(b"USB 0\n")
c.send(b"USB 0\n")
else:
c.send(data + b'\n')
except socket.error as e:
if e.errno == 11: # Resource temporarily unavailable
pass
else:
print((type(e), e))
raise
#time.sleep(0.01)
"""
if data:
print("--> {}".format(data))
if data.startswith(rb"\dump_state"):
c.send(dump_state)
else:
os.send(data)
data = os.recv(256)
if data:
print("<-- {}".format(data))
c.send(data)
time.sleep(0.01)
c.close()
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment