diff options
-rw-r--r-- | gr-vrt/src/Makefile.am | 26 | ||||
-rw-r--r-- | gr-vrt/src/vrt.i | 64 | ||||
-rw-r--r-- | gr-vrt/src/vrt_quadradio_source_32fc.cc | 226 | ||||
-rw-r--r-- | gr-vrt/src/vrt_quadradio_source_32fc.h | 136 | ||||
-rw-r--r-- | vrt/include/vrt/Makefile.am | 1 | ||||
-rw-r--r-- | vrt/include/vrt/quadradio.h | 141 | ||||
-rw-r--r-- | vrt/lib/Makefile.am | 1 | ||||
-rw-r--r-- | vrt/lib/quadradio.cc | 424 |
8 files changed, 12 insertions, 1007 deletions
diff --git a/gr-vrt/src/Makefile.am b/gr-vrt/src/Makefile.am index 4b5fe9b8b..ecd24516e 100644 --- a/gr-vrt/src/Makefile.am +++ b/gr-vrt/src/Makefile.am @@ -54,8 +54,7 @@ lib_LTLIBRARIES = libgnuradio-vrt.la libgnuradio_vrt_la_SOURCES = \ missing_pkt_checker.cc \ vrt_source_base.cc \ - vrt_source_32fc.cc \ - vrt_quadradio_source_32fc.cc + vrt_source_32fc.cc #libgnuradio_vrt_la_SOURCES = \ @@ -77,7 +76,6 @@ libgnuradio_vrt_la_LIBADD = \ grinclude_HEADERS = \ vrt_source_base.h \ vrt_source_32fc.h \ - vrt_quadradio_source_32fc.h \ missing_pkt_checker.h # vrt_source_16sc.h \ @@ -95,28 +93,28 @@ noinst_HEADERS = # _vrt.so # ---------------------------------------------------------------------- -TOP_SWIG_IFILES = \ - vrt.i +#TOP_SWIG_IFILES = \ +# vrt.i # Install so that they end up available as: # import gnuradio.vrt # This ends up at: # ${prefix}/lib/python${python_version}/site-packages/gnuradio -vrt_pythondir_category = \ - gnuradio +#vrt_pythondir_category = \ +# gnuradio # additional arguments to the SWIG command -vrt_swig_args = \ - $(VRT_INCLUDES) +#vrt_swig_args = \ +# $(VRT_INCLUDES) # additional libraries for linking with the SWIG-generated library -vrt_la_swig_libadd = \ - libgnuradio-vrt.la +#vrt_la_swig_libadd = \ +# libgnuradio-vrt.la -include $(top_srcdir)/Makefile.swig +#include $(top_srcdir)/Makefile.swig # add some of the variables generated inside the Makefile.swig.gen -BUILT_SOURCES = $(swig_built_sources) +#BUILT_SOURCES = $(swig_built_sources) # Do not distribute the output of SWIG -no_dist_files = $(swig_built_sources) +#no_dist_files = $(swig_built_sources) diff --git a/gr-vrt/src/vrt.i b/gr-vrt/src/vrt.i deleted file mode 100644 index 9016dc33e..000000000 --- a/gr-vrt/src/vrt.i +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -%include "gnuradio.i" // the common stuff -%import <stdint.i> - -%{ -#include "vrt_quadradio_source_32fc.h" -#include <vrt/quadradio.h> -//#include "vrt_quadradio_source_16sc.h" -//#include "vrt_sink_32fc.h" -//#include "vrt_sink_16sc.h" -%} - -%template(uint32_t_vector) std::vector<uint32_t>; - -// ---------------------------------------------------------------- - -class vrt_source_base : public gr_sync_block -{ -protected: - vrt_source_base() throw (std::runtime_error); - -public: - ~vrt_source_base(); - -}; - -class vrt_source_32fc : public vrt_source_base -{ -protected: - vrt_source_32fc() throw (std::runtime_error); - -public: - ~vrt_source_32fc(); - void reset(); -}; - -// ---------------------------------------------------------------- - -GR_SWIG_BLOCK_MAGIC(vrt,quadradio_source_32fc) - -%include "vrt_quadradio_source_32fc.h" - -%include <vrt/quadradio.h> diff --git a/gr-vrt/src/vrt_quadradio_source_32fc.cc b/gr-vrt/src/vrt_quadradio_source_32fc.cc deleted file mode 100644 index cd779bdf5..000000000 --- a/gr-vrt/src/vrt_quadradio_source_32fc.cc +++ /dev/null @@ -1,226 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <vrt_quadradio_source_32fc.h> -#include <vrt/quadradio.h> -#include <vrt/rx_packet_handler.h> -#include <cstdio> - -vrt_quadradio_source_32fc_sptr -vrt_make_quadradio_source_32fc(const std::string &ip, - size_t rx_bufsize, - size_t samples_per_pkt, - int rxdspno) -{ - return gnuradio::get_initial_sptr(new vrt_quadradio_source_32fc(ip, - rx_bufsize, - samples_per_pkt, - rxdspno)); -} - -vrt_quadradio_source_32fc::vrt_quadradio_source_32fc(const std::string &ip, - size_t rx_bufsize, - size_t samples_per_pkt, - int rxdspno) - : vrt_source_32fc("quadradio_source_32fc"), - d_samples_per_pkt(samples_per_pkt == 0 ? (rxdspno == 0 ? 800 : 200) : samples_per_pkt), - d_qr(vrt::quadradio::sptr(new vrt::quadradio(ip, rx_bufsize))), - d_rxdspno(rxdspno) -{ -} - -vrt_quadradio_source_32fc::~vrt_quadradio_source_32fc() -{ - d_qr->stop_streaming(d_rxdspno); -} - -vrt::rx::sptr -vrt_quadradio_source_32fc::vrt_rx() const -{ - return d_qr->vrt_rx(); -} - -bool -vrt_quadradio_source_32fc::start() -{ - // throw away any stale packets before starting - vrt::rx_packet_handler nop; - vrt_rx()->rx_packets(&nop, true); - d_checker.resync(); - - return d_qr->start_streaming(d_rxdspno, d_samples_per_pkt); -} - -bool -vrt_quadradio_source_32fc::stop() -{ - return d_qr->stop_streaming(d_rxdspno); -} - -bool -vrt_quadradio_source_32fc::set_dboard_pins(int which_dboard, int v) -{ - return d_qr->set_dboard_pins(which_dboard, v); -} - -bool -vrt_quadradio_source_32fc::set_center_freq(double target_freq) -{ - return d_qr->set_center_freq(target_freq); -} - -bool -vrt_quadradio_source_32fc::set_band_select(int band) -{ - return d_qr->set_band_select(static_cast<vrt_band_sel_t>(band)); -} - -int -vrt_quadradio_source_32fc::get_band_select(void) -{ - return static_cast<int>(d_qr->get_band_select()); -} - -//void -//vrt_quadradio_source_32fc::set_10dB_atten(bool on) -//{ -// return d_qr->set_10dB_atten(on); -//} - -bool -vrt_quadradio_source_32fc::select_rx_antenna(const std::string &ant) -{ - return d_qr->select_rx_antenna(ant); -} - -bool -vrt_quadradio_source_32fc::set_attenuation0(int attenuation) -{ - return d_qr->set_attenuation0(attenuation); -} - -bool -vrt_quadradio_source_32fc::set_attenuation1(int attenuation) -{ - return d_qr->set_attenuation1(attenuation); -} - -void -vrt_quadradio_source_32fc::set_adc_gain(bool on){ - d_qr->set_adc_gain(on); -} - -void -vrt_quadradio_source_32fc::set_dc_offset_comp(bool on){ - d_qr->set_dc_offset_comp(on); -} - -void -vrt_quadradio_source_32fc::set_digital_gain(float gain){ - d_qr->set_digital_gain(gain); -} - -void -vrt_quadradio_source_32fc::set_test_signal(int type){ - d_qr->set_test_signal(static_cast<vrt_test_sig_t>(type)); -} - -bool -vrt_quadradio_source_32fc::set_setting_reg(int regno, int value) -{ - return d_qr->set_setting_reg(regno, value); -} - -bool -vrt_quadradio_source_32fc::set_hsadc_conf(int which_dboard, int regno, int value) -{ - return d_qr->set_hsadc_conf(which_dboard, regno, value); -} - -bool -vrt_quadradio_source_32fc::set_lsdac(int which_dboard, int which_dac, int value) -{ - return d_qr->set_lsdac(which_dboard, which_dac, value); -} - -bool -vrt_quadradio_source_32fc::set_mem32(int addr, int value) -{ - return d_qr->set_mem32(addr, value); -} - -bool -vrt_quadradio_source_32fc::set_lo_freq(double freq) -{ - return d_qr->set_lo_freq(freq); -} - -bool -vrt_quadradio_source_32fc::set_cal_freq(double freq) -{ - return d_qr->set_cal_freq(freq); -} - -/*--------------------------------------------------------------------*/ -#define IQ_IMBAL_NUM_TAPS 30 -#define IQ_IMBAL_REG_NO 162 - -//helper function to set the iq imbalance register with a tap -static int get_iq_imbal_reg(bool real, bool init, float tap){ - int val = int(round(tap)); - val &= 0x1ffffff; //lower 25 bits for tap - val |= (real?0:1) << 30; //30th bit for filter type - val |= (init?1:0) << 31; //31st bit for initialization - printf("Reg %d Val %x\n", IQ_IMBAL_REG_NO, val); - return val; -} - -void -vrt_quadradio_source_32fc::set_iq_imbal_taps(const std::vector<gr_complex> taps){ - int i = 0; - /* set the real part of the taps */ - get_iq_imbal_reg(true, true, 0); - for (i = 0; i < IQ_IMBAL_NUM_TAPS; i++){ - set_setting_reg(IQ_IMBAL_REG_NO, get_iq_imbal_reg(true, false, taps[IQ_IMBAL_NUM_TAPS-i-1].real())); - } - get_iq_imbal_reg(false, true, 0); - /* set the imaginary part of the taps */ - for (i = 0; i < IQ_IMBAL_NUM_TAPS; i++){ - set_setting_reg(IQ_IMBAL_REG_NO, get_iq_imbal_reg(false, false, taps[IQ_IMBAL_NUM_TAPS-i-1].imag())); - } -} - -bool -vrt_quadradio_source_32fc::set_beamforming(std::vector<gr_complex> gains){ - int32_t gains_ints[8]; - for (int i = 0; i < 4; i++){ - gains_ints[2*i] = int32_t(gains[i].real()); - gains_ints[2*i+1] = int32_t(gains[i].imag()); - } - return d_qr->set_beamforming(gains_ints); -} - -bool -vrt_quadradio_source_32fc::set_cal_enb(bool enb){ - return d_qr->set_cal_enb(enb); -} diff --git a/gr-vrt/src/vrt_quadradio_source_32fc.h b/gr-vrt/src/vrt_quadradio_source_32fc.h deleted file mode 100644 index bb3935c46..000000000 --- a/gr-vrt/src/vrt_quadradio_source_32fc.h +++ /dev/null @@ -1,136 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_VRT_QUADRADIO_SOURCE_32FC_H -#define INCLUDED_VRT_QUADRADIO_SOURCE_32FC_H - -#include <vrt_source_32fc.h> - -namespace vrt { - class quadradio; -}; - -class vrt_quadradio_source_32fc; -typedef boost::shared_ptr<vrt_quadradio_source_32fc> vrt_quadradio_source_32fc_sptr; - -vrt_quadradio_source_32fc_sptr -vrt_make_quadradio_source_32fc(const std::string &ip, - size_t rx_bufsize = 0, - size_t samples_per_pkt = 0, - int rxdspno = 0); - -class vrt_quadradio_source_32fc : public vrt_source_32fc -{ - size_t d_samples_per_pkt; - boost::shared_ptr<vrt::quadradio> d_qr; - int d_rxdspno; - - vrt_quadradio_source_32fc(const std::string &ip, size_t rx_bufsize, - size_t samples_per_pkt, int rxdspno); - - friend vrt_quadradio_source_32fc_sptr - vrt_make_quadradio_source_32fc(const std::string &ip, size_t rx_bufsize, - size_t samples_per_pkt, int rxdspno); - -public: - virtual ~vrt_quadradio_source_32fc(); - virtual vrt::rx::sptr vrt_rx() const; - - /*! - * \brief Called by scheduler when starting flowgraph - */ - virtual bool start(); - - /*! - * \brief Called by scheduler when stopping flowgraph - */ - virtual bool stop(); - - /*! - * \brief Set the LO frequency (actually just sets the band select for now). - */ - bool set_center_freq(double target_freq); - - /*! - * \brief Set the band select dboard bits. - */ - bool set_band_select(int band); - int get_band_select(void); - - /*! - * \brief Turn the 10 dB attenuation on/off. - */ - //void set_10dB_atten(bool on); - - /*! - * \brief Set the antenna type to the main rf or calibrator. - * \param ant "rf" or "cal" - */ - bool select_rx_antenna(const std::string &ant); - - /*! - * \brief Set the attenuation. - * \param attenuation 0 to 31 in dB - */ - bool set_attenuation0(int attenuation); - bool set_attenuation1(int attenuation); - - void set_iq_imbal_taps(const std::vector<gr_complex> taps); - - void set_adc_gain(bool on); - void set_dc_offset_comp(bool on); - void set_digital_gain(float gain); - void set_test_signal(int type); - - bool set_setting_reg(int regno, int value); - - /*! - * \brief write \p v to daugherboard control setting register - */ - bool set_dboard_pins(int which_dboard, int v); - bool set_hsadc_conf(int which_dboard, int regno, int value); - bool set_lsdac(int which_dboard, int which_dac, int value); - bool set_mem32(int addr, int value); - bool set_lo_freq(double freq); - bool set_cal_freq(double freq); - bool set_beamforming(std::vector<gr_complex> gains); - bool set_cal_enb(bool enb); - - //caldiv public access methods - double get_cal_freq(void){return d_cal_freq;} - bool get_cal_locked(void){return d_cal_locked;} - bool get_cal_enabled(void){return d_cal_enabled;} - double get_lo_freq(void){return d_lo_freq;} - bool get_lo_locked(void){return d_lo_locked;} - double get_caldiv_temp(void){return d_caldiv_temp;} - int get_caldiv_revision(void){return d_caldiv_rev;} - int get_caldiv_serial(void){return d_caldiv_ser;} - int get_caldiv_model(void){return d_caldiv_mod;} - - //gps public access methods - int get_utc_time(void){return d_utc_time;} - double get_altitude(void){return d_altitude;} - double get_longitude(void){return d_longitude;} - double get_latitude(void){return d_latitude;} -}; - - - -#endif /* INCLUDED_VRT_QUADRADIO_SOURCE_32FC_H */ diff --git a/vrt/include/vrt/Makefile.am b/vrt/include/vrt/Makefile.am index 2780d79b0..fac95d427 100644 --- a/vrt/include/vrt/Makefile.am +++ b/vrt/include/vrt/Makefile.am @@ -25,7 +25,6 @@ vrtinclude_HEADERS = \ bits.h \ copiers.h \ expanded_header.h \ - quadradio.h \ if_context.h \ rx.h \ rx_packet_handler.h \ diff --git a/vrt/include/vrt/quadradio.h b/vrt/include/vrt/quadradio.h deleted file mode 100644 index 525a177a8..000000000 --- a/vrt/include/vrt/quadradio.h +++ /dev/null @@ -1,141 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_VRT_QUADRADIO_H -#define INCLUDED_VRT_QUADRADIO_H - -#include <vrt/rx.h> - -#include <arpa/inet.h> -#include <netinet/in.h> -#include <sys/types.h> -#include <sys/socket.h> - -typedef enum{ - VRT_TEST_SIG_NORMAL=0, - VRT_TEST_SIG_ZEROS=1, - VRT_TEST_SIG_ONES=2, - VRT_TEST_SIG_TOGGLE=3, - VRT_TEST_SIG_RAMP=4, - VRT_TEST_SIG_CUSTOM=5, - - } vrt_test_sig_t; - -typedef enum{ - VRT_BAND_SEL_A='A', - VRT_BAND_SEL_B='B', - VRT_BAND_SEL_C='C', - VRT_BAND_SEL_D='D', - - } vrt_band_sel_t; - -namespace vrt { - - /* - * We're not committing to this interface. It's just here so we can make progress... - * - * This implements the ad-hoc control for bringup and has-a vrt::rx - */ - class quadradio - { - int d_ctrl_fd; // socket for control - struct in_addr d_ctrl_port_inaddr; // our ip addr - int d_data_fd; // socket for data (owned by d_rx) - int d_data_port; // our data port number - vrt::rx::sptr d_rx; // has-a rx - - vrt_band_sel_t d_band_select; // band select setting - int d_rx_antenna; // antenna type rf/cal - int d_attenuation0; // attenuation setting - int d_attenuation1; // attenuation setting - bool d_10dB_atten; // 10dB attenuation on/of - - static bool - open_sockets(const char *quad_radio_ip, int quad_radio_ctrl_port, - int *ctrl_fd_ptr, struct in_addr *ctrl_port_inaddr, - int *data_fd_ptr, int *data_port_ptr); - - // dsprxno selects the Rx DSP pipe (0 or 1) to configure - static bool - send_rx_command(int ctrl_fd, int rxdspno, bool start, - struct in_addr addr, int data_port, int samples_per_pkt); - - // dsprxno selects the Rx DSP pipe (0 or 1) to stop - static bool - send_stop_rx_command(int ctrl_fd, int rxdspno); - - static int control_port() { return 790; } - int data_socket_fd() const { return d_data_fd; } - - bool open(const char *ip); - - void update_dboard_pins(void); - - public: - typedef boost::shared_ptr<quadradio> sptr; - - quadradio(const std::string &ip, size_t rx_bufsize = 0); - ~quadradio(); - - vrt::rx::sptr vrt_rx() const { return d_rx; } - - bool start_streaming(int rxdspno, int samples_per_pkt = 0); - - bool stop_streaming(int rxdspno); - - /* convenience methods that ultimately write the dboard pins */ - bool set_center_freq(double target_freq); - bool set_band_select(vrt_band_sel_t band); - vrt_band_sel_t get_band_select(void){return d_band_select;} - //void set_10dB_atten(bool on); - bool set_attenuation0(int attenuation); - bool select_rx_antenna(const std::string &ant); - bool set_attenuation1(int attenuation); - - /* convenience methods that ultimately call set_hsadc_conf */ - void set_adc_gain(bool on); - void set_dc_offset_comp(bool on); - void set_digital_gain(float gain); - void set_test_signal(vrt_test_sig_t type); - - /* primitives */ - bool set_setting_reg(int regno, int value); - bool set_mem32(int addr, int value); // poke a 32-bit value - bool set_lo_freq(double freq); - bool set_cal_freq(double freq); - bool set_beamforming(int32_t gains[8]); - bool set_cal_enb(bool enb); - /* - * The first parameter for these is a bitmask which indicates which - * daughterboard or daughterboards to apply the operation to. - * 0x1 -> dboard 0 - * 0x2 -> dboard 1 - * 0x3 -> dboard 0 and 1... - */ - bool set_dboard_pins(int dboard_bitmask, int v); - bool set_hsadc_conf(int dboard_bitmask, int regno, int value); - bool set_lsdac(int dboard_bitmask, int which_dac, int value); - - }; - -}; - - -#endif /* INCLUDED_QUADRADIO_H */ diff --git a/vrt/lib/Makefile.am b/vrt/lib/Makefile.am index d41343a5d..3a758eeac 100644 --- a/vrt/lib/Makefile.am +++ b/vrt/lib/Makefile.am @@ -32,7 +32,6 @@ libvrt_la_SOURCES = \ copiers.cc \ data_handler.cc \ expanded_header.cc \ - quadradio.cc \ rx.cc \ rx_packet_handler.cc \ socket_rx_buffer.cc diff --git a/vrt/lib/quadradio.cc b/vrt/lib/quadradio.cc deleted file mode 100644 index cc810e683..000000000 --- a/vrt/lib/quadradio.cc +++ /dev/null @@ -1,424 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <vrt/quadradio.h> -#include <vrt/types.h> -#include <gruel/inet.h> -#include <errno.h> -#include <string.h> -#include <stdio.h> -#include <stdexcept> -#include <math.h> - -#define MIN_IP_LOCAL_PORT 32768 -#define MAX_IP_LOCAL_PORT 61000 - -#define ALL_DBOARDS 0xf - -static bool -send_and_check(int fd, void *buf, size_t len) -{ - int r = send(fd, buf, len, 0); - if (r < 0){ - perror("send"); - return false; - } - if ((size_t) r != len){ - fprintf(stderr, "send: short return value. expected %zd, got %d\n", len, r); - return false; - } - return true; -} - - -vrt::quadradio::quadradio(const std::string &ip, size_t rx_bufsize) - : d_ctrl_fd(0), d_data_fd(0), d_data_port(0), - d_band_select(VRT_BAND_SEL_A), d_rx_antenna(0), d_attenuation0(0), d_attenuation1(0)//d_10dB_atten(true) -{ - if (!open(ip.c_str())) - throw std::runtime_error("vrt::quadradio: failed to open " + ip + "\n"); - - d_rx = vrt::rx::make(data_socket_fd(), rx_bufsize); - set_test_signal(VRT_TEST_SIG_NORMAL); -} - -vrt::quadradio::~quadradio() -{ - ::close(d_ctrl_fd); -} - -bool -vrt::quadradio::open(const char *ip) -{ - return open_sockets(ip, control_port(), - &d_ctrl_fd, &d_ctrl_port_inaddr, - &d_data_fd, &d_data_port); -} - -bool -vrt::quadradio::start_streaming(int rxdspno, int samples_per_pkt) -{ - return send_rx_command(d_ctrl_fd, rxdspno, true, d_ctrl_port_inaddr, - d_data_port, samples_per_pkt); -} - -bool -vrt::quadradio::stop_streaming(int rxdspno) -{ - return send_stop_rx_command(d_ctrl_fd, rxdspno); -} - -bool -vrt::quadradio::set_center_freq(double target_freq){ - if (target_freq < 700e6) return false; - if (target_freq <= 1.0e9) return set_band_select(VRT_BAND_SEL_A); - if (target_freq <= 1.5e9) return set_band_select(VRT_BAND_SEL_B); - if (target_freq <= 2.2e9) return set_band_select(VRT_BAND_SEL_C); - if (target_freq <= 3.0e9) return set_band_select(VRT_BAND_SEL_D); - return false; -} - -bool -vrt::quadradio::set_band_select(vrt_band_sel_t band){ - d_band_select = band; - update_dboard_pins(); - return true; -} - -//void -//vrt::quadradio::set_10dB_atten(bool on){ -// d_10dB_atten = on; -// update_dboard_pins(); -//} - -bool -vrt::quadradio::select_rx_antenna(const std::string &ant){ - if (ant == "rf") d_rx_antenna = 0; - else if (ant == "cal") d_rx_antenna = 1; - else return true; - update_dboard_pins(); - return true; -} - -bool -vrt::quadradio::set_attenuation0(int attenuation){ - if (attenuation < 0 || attenuation > 31) return false; - d_attenuation0 = attenuation; - update_dboard_pins(); - return true; -} - -bool -vrt::quadradio::set_attenuation1(int attenuation){ - if (attenuation < 0 || attenuation > 31) return false; - d_attenuation1 = attenuation; - update_dboard_pins(); - return true; -} - -//bit reversal, length in bits -static int reverse_bits(int input, int len){ - int reversed = 0; - for (int i = 0; i < len; i++){ - reversed += (input & (1<<i))?(1 << (len-i-1)):0; - } - return reversed; -} - -void -vrt::quadradio::update_dboard_pins(void){ - //convert the band ID to bits - int band_select; - switch (d_band_select){ - case VRT_BAND_SEL_A: band_select = 3; break; - case VRT_BAND_SEL_B: band_select = 2; break; - case VRT_BAND_SEL_C: band_select = 1; break; - case VRT_BAND_SEL_D: band_select = 0; break; - default: band_select = 0; - } - //calculate the control bits - int db_ctrl = \ - ((reverse_bits(d_attenuation0, 5) & 0x1f) << 10) | \ - ((reverse_bits(~d_attenuation1, 5) & 0x1f) << 03) | \ - ((band_select & 0x03) << 01) | \ - ((d_rx_antenna & 0x01) << 00); - set_dboard_pins(ALL_DBOARDS, db_ctrl); // FIXME sets them all -} - -void -vrt::quadradio::set_adc_gain(bool on){ - set_hsadc_conf(ALL_DBOARDS, 0x14, on ? 0x90 : 0x80); -} - -void -vrt::quadradio::set_dc_offset_comp(bool on){ - if (on) { - set_hsadc_conf(ALL_DBOARDS, 0x1B, 0x80); - set_hsadc_conf(ALL_DBOARDS, 0x1A, 0x00); //bits 6:4 set time constant - } - else set_hsadc_conf(ALL_DBOARDS, 0x1B, 0x00); -} - -void -vrt::quadradio::set_digital_gain(float gain){ - int gain_q1 = static_cast<int>(round(gain*2.0)); - set_hsadc_conf(ALL_DBOARDS, 0x17, gain_q1); -} - -void -vrt::quadradio::set_test_signal(vrt_test_sig_t type){ - set_hsadc_conf(ALL_DBOARDS, 0x16, type); -} - -bool -vrt::quadradio::open_sockets(const char *quad_radio_ip, int quad_radio_ctrl_port, - int *ctrl_fd_ptr, struct in_addr *ctrl_port_inaddr, - int *data_fd_ptr, int *data_port_ptr) -{ - int ctrl_fd; // socket for control - int data_fd; // socket fd for data - int data_port; // our port number - - // - // create a udp socket and connect it to the quad radio control port - // - - ctrl_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (ctrl_fd == -1){ - perror("socket: ctrl_fd"); - return false; - } - - struct sockaddr_in si_other; - memset(&si_other, 0, sizeof(si_other)); - si_other.sin_family = AF_INET; - si_other.sin_port = htons(quad_radio_ctrl_port); - if (inet_pton(AF_INET, quad_radio_ip, &si_other.sin_addr) <= 0){ - perror("inet_pton"); - return false; - } - - if (connect(ctrl_fd, (struct sockaddr *) &si_other, sizeof(si_other)) != 0){ - perror("connect"); - return false; - } - - // get our ip address associated with the interface connected to the control port - - struct sockaddr_in si_me; - memset(&si_me, 0, sizeof(si_me)); - socklen_t sockname_len = sizeof(si_me); - if (getsockname(ctrl_fd, (struct sockaddr *) &si_me, &sockname_len) != 0){ - perror("getsockname"); - } - - *ctrl_port_inaddr = si_me.sin_addr; - - if (1){ - char buf[128]; - const char *s = inet_ntop(si_me.sin_family, &si_me.sin_addr, buf, sizeof(buf)); - if (s == 0){ - perror("inet_ntop"); - return false; - } - // printf("our ip addr associated with ctrl port: %s\n", s); - } - - // - // create a udp socket to use to receive data - // - - data_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (data_fd == -1){ - perror("socket: data_fd"); - return false; - } - - // bind it to a local port on the interface that connects to the ctrl port. - // FIXME this assumes that interface connected to the control port and the - // interface connected to the data port are the same. If we're using - // both ethernet ports on the quad radio, this may not be the case. - - data_port = -1; - for (int port = MIN_IP_LOCAL_PORT; port <= MAX_IP_LOCAL_PORT; port++){ - struct sockaddr_in si_me; - memset(&si_me, 0, sizeof(si_me)); - si_me.sin_family = AF_INET; - si_me.sin_port = htons(port); - si_me.sin_addr.s_addr = htonl(INADDR_ANY); - - if (bind(data_fd, (struct sockaddr *) &si_me, sizeof(si_me)) == 0){ // found one! - data_port = port; - break; - } - } - - if (data_port == -1){ - fprintf(stderr, "failed to bind to a local port\n"); - return false; - } - - // printf("our data port = %d\n", data_port); - - *ctrl_fd_ptr = ctrl_fd; - *data_fd_ptr = data_fd; - *data_port_ptr = data_port; - - return true; -} - -// ------------------------------------------------------------------------ - -bool -vrt::quadradio::send_rx_command(int ctrl_fd, int rxdspno, bool start, - struct in_addr addr, int data_port, - int samples_per_pkt) -{ - uint32_t cmd[7]; - cmd[0] = htonl(0); // verb: set - cmd[1] = htonl(0); // id: rx_streaming - cmd[2] = htonl(start ? 1: 0); // start or stop? - cmd[3] = addr.s_addr; // ip address to send data to (already network endian) - cmd[4] = htonl(data_port); // port to send data to - cmd[5] = htonl(samples_per_pkt); - cmd[6] = htonl(rxdspno); // the DSP pipeline to configure - - return send_and_check(ctrl_fd, cmd, sizeof(cmd)); -} - -bool -vrt::quadradio::send_stop_rx_command(int ctrl_fd, int rxdspno) -{ - struct in_addr in_addr; - in_addr.s_addr = 0; - return send_rx_command(ctrl_fd, rxdspno, false, in_addr, 0, 0); -} - -bool -vrt::quadradio::set_dboard_pins(int dboard_bitmask, int v) -{ - uint32_t cmd[4]; - cmd[0] = htonl(0); // verb: set - cmd[1] = htonl(1); // id: dboard_pins - cmd[2] = htonl(dboard_bitmask); - cmd[3] = htonl(v); // value - - return send_and_check(d_ctrl_fd, cmd, sizeof(cmd)); -} - -bool -vrt::quadradio::set_setting_reg(int regno, int value) -{ - uint32_t cmd[4]; - cmd[0] = htonl(0); // verb: set - cmd[1] = htonl(2); // id: SR - cmd[2] = htonl(regno); - cmd[3] = htonl(value); - - return send_and_check(d_ctrl_fd, cmd, sizeof(cmd)); -} - -bool -vrt::quadradio::set_hsadc_conf(int dboard_bitmask, int regno, int value) -{ - uint32_t cmd[5]; - cmd[0] = htonl(0); // verb: set - cmd[1] = htonl(3); // id: HSADC_CONF - cmd[2] = htonl(dboard_bitmask); - cmd[3] = htonl(regno); - cmd[4] = htonl(value); - - return send_and_check(d_ctrl_fd, cmd, sizeof(cmd)); -} - -bool -vrt::quadradio::set_lsdac(int dboard_bitmask, int which_dac, int value) -{ - uint32_t cmd[5]; - cmd[0] = htonl(0); // verb: set - cmd[1] = htonl(4); // id: LSDAC - cmd[2] = htonl(dboard_bitmask); - cmd[3] = htonl(which_dac); - cmd[4] = htonl(value); - - return send_and_check(d_ctrl_fd, cmd, sizeof(cmd)); -} - -bool -vrt::quadradio::set_mem32(int addr, int value) -{ - uint32_t cmd[4]; - cmd[0] = htonl(0); // verb: set - cmd[1] = htonl(5); // id: MEM32 - cmd[2] = htonl(addr); - cmd[3] = htonl(value); - - return send_and_check(d_ctrl_fd, cmd, sizeof(cmd)); -} - -bool -vrt::quadradio::set_lo_freq(double freq) -{ - vrt_freq_t lo_freq = htonll(double_to_vrt_freq(freq)); - uint32_t cmd[4]; - cmd[0] = htonl(0); // verb: set - cmd[1] = htonl(6); // id: lo freq - memcpy(cmd+2, &lo_freq, sizeof(lo_freq)); - - return send_and_check(d_ctrl_fd, cmd, sizeof(cmd)); -} - -bool -vrt::quadradio::set_cal_freq(double freq) -{ - vrt_freq_t cal_freq = htonll(double_to_vrt_freq(freq)); - uint32_t cmd[4]; - cmd[0] = htonl(0); // verb: set - cmd[1] = htonl(7); // id: cal freq - memcpy(cmd+2, &cal_freq, sizeof(cal_freq)); - - return send_and_check(d_ctrl_fd, cmd, sizeof(cmd)); -} - -bool -vrt::quadradio::set_beamforming(int32_t gains[8]){ - uint32_t cmd[2+8]; - cmd[0] = htonl(0); // verb: set - cmd[1] = htonl(8); // id: beamformin - for (int i = 0; i < 8; i++){ - //printf("%d\n", gains[i]); - cmd[i+2] = htonl(gains[i]); - } - return send_and_check(d_ctrl_fd, cmd, sizeof(cmd)); -} - -bool -vrt::quadradio::set_cal_enb(bool enb) -{ - uint32_t cmd[3]; - cmd[0] = htonl(0); // verb: set - cmd[1] = htonl(9); // id: cal enb - cmd[2] = htonl(enb); - - return send_and_check(d_ctrl_fd, cmd, sizeof(cmd)); -} |