-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrtl_sdr_iqcapture_250k.py
executable file
·145 lines (114 loc) · 4.05 KB
/
rtl_sdr_iqcapture_250k.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# SPDX-License-Identifier: GPL-3.0
#
# GNU Radio Python Flow Graph
# Title: Store IQ
# GNU Radio version: 3.8.1.0
from gnuradio import blocks
from gnuradio import gr
from gnuradio.filter import firdes
import sys
import signal
from argparse import ArgumentParser
from gnuradio.eng_arg import eng_float, intx
from gnuradio import eng_notation
import osmosdr
import time
import os
from threading import Thread
class mainprog(gr.top_block):
def __init__(self, fname='iq_bb_250k.bin'):
gr.top_block.__init__(self, "Store IQ")
##################################################
# Variables
##################################################
self.samp_rate = samp_rate = 250e3
self.rf_gain = rf_gain = 20
self.rf_bw = rf_bw = 25e3
self.if_gain = if_gain = 20
self.freq = freq = 437.5e6
self.bb_gain = bb_gain = 20
##################################################
# Blocks
##################################################
self.rtlsdr_source_0 = osmosdr.source(
args="numchan=" + str(1) + " " + ""
)
self.rtlsdr_source_0.set_time_now(osmosdr.time_spec_t(time.time()), osmosdr.ALL_MBOARDS)
self.rtlsdr_source_0.set_sample_rate(samp_rate)
self.rtlsdr_source_0.set_center_freq(freq, 0)
self.rtlsdr_source_0.set_freq_corr(0, 0)
self.rtlsdr_source_0.set_gain(rf_gain, 0)
self.rtlsdr_source_0.set_if_gain(if_gain, 0)
self.rtlsdr_source_0.set_bb_gain(bb_gain, 0)
self.rtlsdr_source_0.set_antenna('', 0)
self.rtlsdr_source_0.set_bandwidth(rf_bw, 0)
self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex*1, fname, False)
self.blocks_file_sink_0.set_unbuffered(True)
##################################################
# Connections
##################################################
self.connect((self.rtlsdr_source_0, 0), (self.blocks_file_sink_0, 0))
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.rtlsdr_source_0.set_sample_rate(self.samp_rate)
def get_rf_gain(self):
return self.rf_gain
def set_rf_gain(self, rf_gain):
self.rf_gain = rf_gain
self.rtlsdr_source_0.set_gain(self.rf_gain, 0)
def get_rf_bw(self):
return self.rf_bw
def set_rf_bw(self, rf_bw):
self.rf_bw = rf_bw
self.rtlsdr_source_0.set_bandwidth(self.rf_bw, 0)
def get_if_gain(self):
return self.if_gain
def set_if_gain(self, if_gain):
self.if_gain = if_gain
self.rtlsdr_source_0.set_if_gain(self.if_gain, 0)
def get_freq(self):
return self.freq
def set_freq(self, freq):
self.freq = freq
self.rtlsdr_source_0.set_center_freq(self.freq, 0)
def get_bb_gain(self):
return self.bb_gain
def set_bb_gain(self, bb_gain):
self.bb_gain = bb_gain
self.rtlsdr_source_0.set_bb_gain(self.bb_gain, 0)
def main(top_block_cls=mainprog, options=None, fname = 'iq_bb_250k.bin'):
if gr.enable_realtime_scheduling() != gr.RT_OK:
print("Error: failed to enable real-time scheduling.")
tb = top_block_cls(fname)
def sig_handler(sig=None, frame=None):
tb.stop()
tb.wait()
# sys.exit(0)
signal.signal(signal.SIGINT, sig_handler)
signal.signal(signal.SIGTERM, sig_handler)
tb.start()
tb.wait()
def cause_exit(t = 1):
time.sleep(t)
os.kill(os.getpid(), signal.SIGINT)
if __name__ == '__main__':
if (len(sys.argv) != 3):
print("Invocation: %s <Time to exit> <Output File>\n\n"%(sys.argv[0]))
sys.exit(0)
try:
t = int(sys.argv[1])
except Exception:
print("%s is not valid time"%(sys.argv[1]))
sys.exit(0)
t = 5 if t < 1 else t + 5
thread = Thread(target = cause_exit, args = (t, ))
thread.start()
main(fname = sys.argv[2])
thread.join()
print("Exiting")
sys.exit(0)