Last active
June 14, 2020 03:20
-
-
Save Fifty-Nine/158234f6a76b36091412cf03742d8f97 to your computer and use it in GitHub Desktop.
GNURadio-based ZeroMQ repeater for Osmocom-compatible SDRs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from gnuradio import gr | |
from gnuradio import blocks | |
from gnuradio import zeromq | |
import osmosdr | |
import argparse | |
import sys | |
import signal | |
class sdr_zeromq(gr.top_block): | |
def __init__(self, args): | |
gr.top_block.__init__( | |
self, | |
name='ZeroMQ Osmocom Repeater' | |
) | |
self.source = osmosdr.source(args.device) | |
self.source.set_sample_rate(args.rate) | |
self.source.set_center_freq(args.frequency) | |
self.source.set_freq_corr(args.ppm) | |
self.source.set_dc_offset_mode(0, 0) | |
self.source.set_iq_balance_mode(0, 0) | |
self.source.set_gain_mode(False, 0) | |
self.source.set_gain(args.rf_gain, 0) | |
self.source.set_if_gain(args.if_gain, 0) | |
self.source.set_bb_gain(args.bb_gain, 0) | |
self.source.set_antenna('', 0) | |
self.source.set_bandwidth(0, 0) | |
self.sink = zeromq.pub_sink(gr.sizeof_gr_complex, 1, 'tcp://0.0.0.0:42069', 100) | |
self.connect((self.source, 0), (self.sink, 0)) | |
def main(argv): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('frequency', help='Center frequency', type=float) | |
parser.add_argument('-d', '--device', help='Osmocom device args', default='') | |
parser.add_argument('-r', '--rate', help='Sample rate', type=float, default=10e6) | |
parser.add_argument('-p', '--ppm', help='Set the tuning frequency correction offset, in ppm.', default=0) | |
parser.add_argument('--rf-gain', help='Set the RF gain setting, in dB.', default=10) | |
parser.add_argument('--if-gain', help='Set the IF gain setting, in dB.', default=20) | |
parser.add_argument('--bb-gain', help='Set the BB gain setting, in dB.', default=20) | |
parser.add_argument('-l', help='ZeroMQ socket address.', default='tcp://localhost:42069') | |
args = parser.parse_args() | |
top = sdr_zeromq(args) | |
def on_signal(sig=None, frame=None): | |
top.stop() | |
top.wait() | |
sys.exit(0) | |
signal.signal(signal.SIGINT, on_signal) | |
signal.signal(signal.SIGTERM, on_signal) | |
top.start() | |
input() | |
top.stop() | |
top.wait() | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment