This repository has been archived by the owner on Aug 11, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
rp_eclipse.py
executable file
·224 lines (183 loc) · 7.36 KB
/
rp_eclipse.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env python2
"""
Code used to record Virginia Tech HF Shaw AFB radar during Aug 21, 2017 solar eclipse.
Raspberry Pi 3 or Raspberry Pi 2 can handle two streams.
About 140% CPU for Rpi 3, about 180% for Rpi 2 (reported by 'top')
Temperature of fanless, heatsinked Pi 3 was 81'C in ambient 40'C (CPU throttling is said to occur ~ 85'C)
Possibly requires GNU Radio >= v3.7.10 ?
V3.7.9 seemed to hang waiting for Red Pitaya connection.
Michael Hirsch, Ph.D.
"""
import os, sys
from datetime import datetime
from argparse import ArgumentParser
p = ArgumentParser()
p.add_argument("outstem", help="filename stem to write")
p.add_argument("freqMHz", help="frequency in MHz to center on", nargs="+", type=float)
p.add_argument("-i", "--iface", help="network interface to connect to Red Pitaya", default="eth0")
p = p.parse_args()
outstem = os.path.expanduser(p.outstem)
IF = p.iface
# https://github.com/Tom-McDermott/gr-hpsdr/releases
# F = [0]*8 # gr-hpsdr >= v1.2
F = [0] * 2 # gr-hpsdr < v1.2
for i, f in enumerate(p.freqMHz):
F[i] = int(f * 1e6)
print(F)
Fs = int(192e3)
Fsink0 = 0 # display center freq
GUI = False
NRX = len(p.freqMHz)
FTX = 0
if __name__ == "__main__":
import ctypes
if sys.platform.startswith("linux"):
try:
x11 = ctypes.cdll.LoadLibrary("libX11.so")
x11.XInitThreads()
except:
print("Warning: failed to XInitThreads()")
from PyQt4 import Qt
from gnuradio import analog
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio import qtgui
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
import hpsdr
import sip
print(hpsdr.__path__)
class top_block(gr.top_block, Qt.QWidget):
def __init__(self):
global outstem
gr.top_block.__init__(self, "Top Block") # necessary for all cases
def _setupGUI(self):
Qt.QWidget.__init__(self)
self.setWindowTitle("Top Block")
try:
self.setWindowIcon(Qt.QIcon.fromTheme("gnuradio-grc"))
except:
pass
self.top_scroll_layout = Qt.QVBoxLayout()
self.setLayout(self.top_scroll_layout)
self.top_scroll = Qt.QScrollArea()
self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
self.top_scroll_layout.addWidget(self.top_scroll)
self.top_scroll.setWidgetResizable(True)
self.top_widget = Qt.QWidget()
self.top_scroll.setWidget(self.top_widget)
self.top_layout = Qt.QVBoxLayout(self.top_widget)
self.top_grid_layout = Qt.QGridLayout()
self.top_layout.addLayout(self.top_grid_layout)
self.settings = Qt.QSettings("GNU Radio", "top_block")
self.restoreGeometry(self.settings.value("geometry").toByteArray())
# %% FFT display
self.fsink0 = qtgui.freq_sink_c(
1024, # size
firdes.WIN_BLACKMAN_hARRIS, # wintype
Fsink0, # fc
Fs, # bw
"", # name
1, # number of inputs
)
self.fsink0.set_update_time(0.10)
self.fsink0.set_y_axis(-140, -10)
# self.fsink0.set_y_label('RX Level', 'dB')
self.fsink0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
self.fsink0.enable_autoscale(False)
self.fsink0.enable_grid(True)
self.fsink0.set_fft_average(1.0)
# self.fsink0.enable_axis_labels(True)
self.fsink0.enable_control_panel(True)
if not True:
self.fsink0.disable_legend()
if "complex" == "float" or "complex" == "msg_float":
self.fsink0.set_plot_pos_half(not True)
# labels = ['', '', '', '', '',
# '', '', '', '', '']
# widths = [1, 1, 1, 1, 1,
# 1, 1, 1, 1, 1]
# colors = ["blue", "red", "green", "black", "cyan",
# "magenta", "yellow", "dark red", "dark green", "dark blue"]
# alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
# 1.0, 1.0, 1.0, 1.0, 1.0]
# for i in range(2):
# if len(labels[i]) == 0:
# self.fsink0.set_line_label(i, "Data {0}".format(i))
# else:
# self.fsink0.set_line_label(i, labels[i])
# self.fsink0.set_line_width(i, widths[i])
# self.fsink0.set_line_color(i, colors[i])
# self.fsink0.set_line_alpha(i, alphas[i])
self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.fsink0.pyqwidget(), Qt.QWidget)
self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win)
if GUI:
_setupGUI()
# %% Non-gui
# for gr-hpsdr < 1.2
self.hpsdr_hermesNB_0 = hpsdr.hermesNB(
RxFreq0=F[0],
RxFreq1=F[1],
# for gr-hpsdr >= 1.2,
# self.hpsdr_hermesNB_0 = hpsdr.hermesNB(F[0], F[1], F[2], F[3], F[4], F[5], F[6], F[7],
TxFreq=FTX,
RxPre=False,
PTTModeSel=0,
PTTTxMute=True,
PTTRxMute=True,
TxDr=0,
RxSmp=Fs,
Intfc=IF,
ClkS="0xF8",
AlexRA=0,
AlexTA=0,
AlexHPF=0x00,
AlexLPF=0x00,
Verbose=0,
NumRx=NRX,
MACAddr="*",
)
self.dummytx = analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, 0)
# %% write file
now = datetime.now().isoformat(timespec="seconds")
outstem += now
ofn0 = outstem + "_{}MHz.bin".format(F[0] / 1e6)
print("writing", ofn0)
self.file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex * 1, ofn0, False)
self.file_sink_0.set_unbuffered(False)
ofn1 = outstem + "_{}MHz.bin".format(F[1] / 1e6)
print("writing", ofn1)
self.file_sink_1 = blocks.file_sink(gr.sizeof_gr_complex * 1, ofn1, False)
self.file_sink_1.set_unbuffered(False)
# %% Connections
self.connect((self.dummytx, 0), (self.hpsdr_hermesNB_0, 0))
if ofn0 is not None:
self.connect((self.hpsdr_hermesNB_0, 0), (self.file_sink_0, 0))
if ofn1 is not None:
self.connect((self.hpsdr_hermesNB_0, 1), (self.file_sink_1, 0))
if GUI:
self.connect((self.hpsdr_hermesNB_0, 0), (self.fsink0, 0))
# self.connect((self.hpsdr_hermesNB_0, 1), (self.fsink1, 0))
def closeEvent(self, event):
if GUI:
self.settings = Qt.QSettings("GNU Radio", "top_block")
self.settings.setValue("geometry", self.saveGeometry())
event.accept()
def main(top_block_cls=top_block, options=None):
from distutils.version import StrictVersion
if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
style = gr.prefs().get_string("qtgui", "style", "raster")
Qt.QApplication.setGraphicsSystem(style)
qapp = Qt.QApplication(sys.argv)
tb = top_block_cls()
tb.start()
if GUI:
tb.show()
def quitting():
tb.stop()
tb.wait()
qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
qapp.exec_()
if __name__ == "__main__":
main()