-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcal_rec.py
executable file
·147 lines (110 loc) · 4.04 KB
/
pcal_rec.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
#!/usr/bin/env python
#
# Dual channel double precision digital down conversion
# record continuously to disk with digital_rf
#
# (c) 2015 Juha Vierinen
#
from PyQt4 import Qt
from gnuradio import qtgui
import sys, sip, time
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio import uhd
from gnuradio.eng_option import eng_option
from optparse import OptionParser
from gnuradio import filter
from gnuradio import blocks
from gnuradio.filter import firdes
import sys, time, os, math, re
import drf
import sampler_util
import numpy
import scipy
import scipy.signal
import serial
def create_simple_scope(samp_rate):
snk = qtgui.time_sink_c(1024,samp_rate,"Phase",1)
snk_win = sip.wrapinstance(snk.pyqwidget(), Qt.QWidget)
snk_win.show()
return(snk)
def create_simple_scope_f(samp_rate):
snk = qtgui.time_sink_f(1024,samp_rate,"Phase",1)
snk.set_y_axis(-4,4)
snk_win = sip.wrapinstance(snk.pyqwidget(), Qt.QWidget)
snk_win.show()
return(snk)
debug = True
parser = OptionParser(option_class=eng_option)
parser.add_option("-m", "--mainboard", dest="main_board", type="string", default="192.168.10.2",
help="Mainboard address. (default %default)")
parser.add_option("-0", "--centerfreq0",dest="centerfreq0", action="store", type="string",
default="5e6",help="Center frequency (default %default)")
parser.add_option("-1", "--centerfreq1",dest="centerfreq1", action="store", type="string",
default="214791314.0*100e6/float(2**32)",help="Center frequency (default %default)")
parser.add_option("-r", "--samplerate",dest="samplerate", action="store", type="long", default=25000000,
help="Sample rate (default %default)")
parser.add_option("-i", "--window_len",dest="window_len", action="store", type="int", default=250000,
help="Averaging window length (default %default)")
parser.add_option("-n", "--name",dest="name", action="store", default="data",
type="string",
help="Prefix of data directory.")
(op, args) = parser.parse_args()
op.centerfreq0 = eval(op.centerfreq0)
op.centerfreq1 = eval(op.centerfreq1)
# create usrp source block
u = uhd.usrp_source(
device_addr="addr=%s,recv_buff_size=1000000000"%(op.main_board),
stream_args=uhd.stream_args(
cpu_format="sc16",
otw_format="sc16",
channels=range(1),
),
)
# tbd fix hardcoded directory
os.system("mkdir -p /data/phasecal/000")
os.system("mkdir -p /data/phasecal/001")
u.set_clock_source("external", 0)
u.set_time_source("external", 0)
u.set_subdev_spec("A:AB", 0)
u.set_samp_rate(op.samplerate)
u.set_auto_dc_offset(False,0)
tt = time.time()
while tt-math.floor(tt) < 0.2 or tt-math.floor(tt) > 0.3:
tt = time.time()
time.sleep(0.01)
print("Latching at "+str(tt))
print(tt)
u.set_time_unknown_pps(uhd.time_spec(math.ceil(tt)+1.0))
op.starttime = math.ceil(time.time())+5
op.starttime = sampler_util.find_next(op.starttime,1)
u.set_start_time(uhd.time_spec(op.starttime))
fg = gr.top_block()
dst = []
win_len = op.window_len
window = numpy.array(numpy.real(scipy.signal.blackmanharris(win_len)),dtype=numpy.float64)
window.tofile("/data/phasecal/coeffs.bin")
# two channel decimating all double precision digital down converter
# with user defined filter coefficients.
# - 100 samples per file.
# - let the block know that the sample rate is 25 MHz also
# - expects real valued samples with channel 0 and 1 as interleaved little endian 16 bit ints.
# - dies if packet drop detected.
dddc = drf.dddc("/data/phasecal/coeffs.bin", win_len, op.centerfreq0, op.centerfreq1, 100, 25000000.0)
fg.connect((u, 0), (dddc,0))
if debug:
print "Starting at %d"%(op.starttime)
fg.start()
# die if loss of lock.
lt0 = time.time()
while(True):
tnow = time.time()
# if not locked to reference, die!
if tnow - lt0 > 10:
lock = str(u.get_mboard_sensor("ref_locked"))
if lock != "Ref: locked":
print(lock)
print("Reference unlocked!")
exit(0)
lt0=tnow
time.sleep(0.1)