3 * Copyright 2009 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <vrt_quadradio_source_32fc.h>
25 #include <vrt/quadradio.h>
26 #include <vrt/rx_packet_handler.h>
29 vrt_quadradio_source_32fc_sptr
30 vrt_make_quadradio_source_32fc(const std::string &ip,
32 size_t samples_per_pkt)
34 return gnuradio::get_initial_sptr(new vrt_quadradio_source_32fc(ip,
39 vrt_quadradio_source_32fc::vrt_quadradio_source_32fc(const std::string &ip,
41 size_t samples_per_pkt)
42 : vrt_source_32fc("quadradio_source_32fc"),
43 d_samples_per_pkt(samples_per_pkt == 0 ? 800 : samples_per_pkt),
44 d_qr(vrt::quadradio::sptr(new vrt::quadradio(ip, rx_bufsize)))
48 vrt_quadradio_source_32fc::~vrt_quadradio_source_32fc()
50 d_qr->stop_streaming();
54 vrt_quadradio_source_32fc::vrt_rx() const
56 return d_qr->vrt_rx();
60 vrt_quadradio_source_32fc::start()
62 // throw away any stale packets before starting
63 vrt::rx_packet_handler nop;
64 vrt_rx()->rx_packets(&nop, true);
67 return d_qr->start_streaming(d_samples_per_pkt);
71 vrt_quadradio_source_32fc::stop()
73 return d_qr->stop_streaming();
77 vrt_quadradio_source_32fc::set_dboard_pins(int which_dboard, int v)
79 return d_qr->set_dboard_pins(which_dboard, v);
83 vrt_quadradio_source_32fc::set_center_freq(double target_freq)
85 return d_qr->set_center_freq(target_freq);
89 vrt_quadradio_source_32fc::set_band_select(const std::string &band)
91 return d_qr->set_band_select(band);
95 //vrt_quadradio_source_32fc::set_10dB_atten(bool on)
97 // return d_qr->set_10dB_atten(on);
101 vrt_quadradio_source_32fc::select_rx_antenna(const std::string &ant)
103 return d_qr->select_rx_antenna(ant);
107 vrt_quadradio_source_32fc::set_attenuation0(int attenuation)
109 return d_qr->set_attenuation0(attenuation);
113 vrt_quadradio_source_32fc::set_attenuation1(int attenuation)
115 return d_qr->set_attenuation1(attenuation);
119 vrt_quadradio_source_32fc::set_adc_gain(bool on){
120 d_qr->set_adc_gain(on);
124 vrt_quadradio_source_32fc::set_dc_offset_comp(bool on){
125 d_qr->set_dc_offset_comp(on);
129 vrt_quadradio_source_32fc::set_digital_gain(float gain){
130 d_qr->set_digital_gain(gain);
134 vrt_quadradio_source_32fc::set_test_signal(int type){
135 d_qr->set_test_signal(static_cast<vrt_test_sig_t>(type));
139 vrt_quadradio_source_32fc::set_setting_reg(int regno, int value)
141 return d_qr->set_setting_reg(regno, value);
145 vrt_quadradio_source_32fc::set_hsadc_conf(int which_dboard, int regno, int value)
147 return d_qr->set_hsadc_conf(which_dboard, regno, value);
151 vrt_quadradio_source_32fc::set_lsdac(int which_dboard, int which_dac, int value)
153 return d_qr->set_lsdac(which_dboard, which_dac, value);
157 vrt_quadradio_source_32fc::set_mem32(int addr, int value)
159 return d_qr->set_mem32(addr, value);
163 vrt_quadradio_source_32fc::set_lo_freq(double freq)
165 return d_qr->set_lo_freq(freq);
169 vrt_quadradio_source_32fc::set_cal_freq(double freq)
171 return d_qr->set_cal_freq(freq);
174 /*--------------------------------------------------------------------*/
175 #define IQ_IMBAL_NUM_TAPS 30
176 #define IQ_IMBAL_REG_NO 162
178 //helper function to set the iq imbalance register with a tap
179 static int get_iq_imbal_reg(bool real, bool init, float tap){
180 int val = int(round(tap));
181 val &= 0x1ffffff; //lower 25 bits for tap
182 val |= (real?0:1) << 30; //30th bit for filter type
183 val |= (init?1:0) << 31; //31st bit for initialization
184 printf("Reg %d Val %x\n", IQ_IMBAL_REG_NO, val);
189 vrt_quadradio_source_32fc::set_iq_imbal_taps(const std::vector<gr_complex> taps){
191 /* set the real part of the taps */
192 get_iq_imbal_reg(true, true, 0);
193 for (i = 0; i < IQ_IMBAL_NUM_TAPS; i++){
194 set_setting_reg(IQ_IMBAL_REG_NO, get_iq_imbal_reg(true, false, taps[IQ_IMBAL_NUM_TAPS-i-1].real()));
196 get_iq_imbal_reg(false, true, 0);
197 /* set the imaginary part of the taps */
198 for (i = 0; i < IQ_IMBAL_NUM_TAPS; i++){
199 set_setting_reg(IQ_IMBAL_REG_NO, get_iq_imbal_reg(false, false, taps[IQ_IMBAL_NUM_TAPS-i-1].imag()));
204 vrt_quadradio_source_32fc::set_beamforming(std::vector<gr_complex> gains){
205 int32_t gains_ints[8];
206 for (int i = 0; i < 4; i++){
207 gains_ints[2*i] = int32_t(gains[i].real());
208 gains_ints[2*i+1] = int32_t(gains[i].imag());
210 return d_qr->set_beamforming(gains_ints);