summaryrefslogtreecommitdiff
path: root/vrt
diff options
context:
space:
mode:
Diffstat (limited to 'vrt')
-rw-r--r--vrt/apps/.gitignore2
-rw-r--r--vrt/apps/Makefile.am18
-rw-r--r--vrt/apps/simple_rx_samples.cc394
-rw-r--r--vrt/include/vrt/Makefile.am4
-rw-r--r--vrt/include/vrt/bits.h46
-rw-r--r--vrt/include/vrt/quadradio.h143
-rw-r--r--vrt/include/vrt/types.h138
-rw-r--r--vrt/lib/Makefile.am4
-rw-r--r--vrt/lib/expanded_header.cc8
-rw-r--r--vrt/lib/quadradio.cc428
10 files changed, 183 insertions, 1002 deletions
diff --git a/vrt/apps/.gitignore b/vrt/apps/.gitignore
index a8e9f886f..dab7a7fd6 100644
--- a/vrt/apps/.gitignore
+++ b/vrt/apps/.gitignore
@@ -2,4 +2,4 @@ Makefile
Makefile.in
.deps
.libs
-simple_rx_samples
+
diff --git a/vrt/apps/Makefile.am b/vrt/apps/Makefile.am
index 631d9020b..45772055b 100644
--- a/vrt/apps/Makefile.am
+++ b/vrt/apps/Makefile.am
@@ -16,21 +16,3 @@
#
include $(top_srcdir)/Makefile.common
-
-AM_CPPFLAGS = \
- $(VRT_INCLUDES) \
- $(STD_DEFINES_AND_INCLUDES) \
- $(CPPUNIT_INCLUDES)
-
-LDADD = \
- $(VRT_LA) \
- $(GRUEL_LA)
-
-
-bin_PROGRAMS =
-
-noinst_PROGRAMS = \
- simple_rx_samples
-
-simple_rx_samples_SOURCES = simple_rx_samples.cc
-
diff --git a/vrt/apps/simple_rx_samples.cc b/vrt/apps/simple_rx_samples.cc
deleted file mode 100644
index 6b09afda5..000000000
--- a/vrt/apps/simple_rx_samples.cc
+++ /dev/null
@@ -1,394 +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.
- */
-
-#include <vrt/quadradio.h>
-#include <vrt/rx.h>
-#include <vrt/copiers.h>
-
-#include <errno.h>
-#include <iostream>
-#include <boost/scoped_ptr.hpp>
-#include <boost/shared_ptr.hpp>
-#include <stdexcept>
-#include <signal.h>
-#include <unistd.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-#include <gruel/realtime.h>
-#include <complex>
-
-#define MIN_IP_LOCAL_PORT 32768
-#define MAX_IP_LOCAL_PORT 61000
-
-static volatile bool signaled = false;
-
-static void
-sig_handler(int sig)
-{
- signaled = true;
-}
-
-static void
-install_sig_handler(int signum,
- void (*new_handler)(int))
-{
- struct sigaction new_action;
- memset (&new_action, 0, sizeof (new_action));
-
- new_action.sa_handler = new_handler;
- sigemptyset (&new_action.sa_mask);
- new_action.sa_flags = 0;
-
- if (sigaction (signum, &new_action, 0) < 0){
- perror ("sigaction (install new)");
- throw std::runtime_error ("sigaction");
- }
-}
-
-// ------------------------------------------------------------------------
-
-class rx_nop_handler : public vrt::rx_packet_handler
-{
-private:
- uint64_t d_max_samples;
- uint64_t d_max_quantum;
- uint64_t d_nsamples;
- uint64_t d_npackets;
- int d_last_pkt_cnt;
- uint64_t d_nwrong_pkt_cnt;
-
-protected:
- bool d_err;
-
-public:
-
- // Shared pointer to an instance of this class
- typedef boost::shared_ptr<rx_nop_handler> sptr;
-
- /*!
- * Constructor
- *
- * \param max_samples Maximum number of samples to copy. Use zero for no maximum.
- * \param max_quantum Maximum number of samples required to accept in one call.
- * Use 0 to indicate no maximum.
- */
- rx_nop_handler(uint64_t max_samples, uint64_t max_quantum=0)
- : d_max_samples(max_samples), d_max_quantum(max_quantum),
- d_nsamples(0), d_npackets(0),
- d_last_pkt_cnt(0xf), d_nwrong_pkt_cnt(0),
- d_err(false){}
-
-
- ~rx_nop_handler();
-
- bool operator()(const uint32_t *payload,
- size_t n32_bit_words,
- const vrt::expanded_header *hdr);
-
- /*!
- * \brief Returns number of packets this copier was called with
- */
- uint64_t npackets() const { return d_npackets; }
-
- /*!
- * \brief Returns actual number of samples copied
- */
- uint64_t nsamples() const { return d_nsamples; }
-
- /*!
- * \brief Returns maximum number of samples that will be copied
- */
- uint64_t max_samples() const { return d_max_samples; }
-
- /*!
- * Returns true if an error has occurred. Derived classes must set d_err to true
- * when an error occurs in the () operator
- */
- bool has_errored_p() const { return d_err; }
-
- /*!
- * \brief Returns true if this instance has reached the maximum number of samples
- */
- bool has_finished_p() const
- { return d_max_samples == 0 ? false : d_nsamples >= d_max_samples-d_max_quantum; }
-
- uint64_t nwrong_pkt_cnt() const { return d_nwrong_pkt_cnt; }
-
-
-};
-
-
-rx_nop_handler::~rx_nop_handler()
-{
-}
-
-bool
-rx_nop_handler::operator()(const uint32_t *payload,
- size_t n32_bit_words,
- const vrt::expanded_header *hdr)
-{
- if (d_npackets != 0 && hdr->pkt_cnt() != ((d_last_pkt_cnt + 1) & 0xf)){
- d_nwrong_pkt_cnt++;
- fprintf(stderr, "bad cnt (pkt %lld)\n", d_npackets);
- }
- d_last_pkt_cnt = hdr->pkt_cnt();
-
- d_nsamples += n32_bit_words;
- d_npackets++;
-
- return !has_finished_p();
-}
-
-// ------------------------------------------------------------------------
-
-class file_writer_16sc : public rx_nop_handler
-{
- FILE *d_fp;
- std::string d_filename;
-
-public:
-
- file_writer_16sc(const std::string &filename, uint64_t max_samples)
- : rx_nop_handler(max_samples), d_filename(filename)
- {
- d_fp = fopen(filename.c_str(), "wb");
- if (d_fp == 0){
- perror(filename.c_str());
- throw std::invalid_argument(filename);
- }
- }
-
- ~file_writer_16sc();
-
- bool
- operator()(const uint32_t *items, size_t nitems, const vrt::expanded_header *hdr)
- {
- bool ok = rx_nop_handler::operator()(items, nitems, hdr);
-
- size_t host_nitems = nitems;
- std::complex<int16_t> host_items[host_nitems];
-
- vrt::copy_net_16sc_to_host_16sc(nitems, items, host_items);
-
- size_t n = 0;
- while (n < host_nitems){
- size_t r = fwrite(&host_items[n], sizeof(host_items[0]), host_nitems - n, d_fp);
- n += r;
- if (r == 0){ // out of space?
- d_err = true;
- perror(d_filename.c_str());
- ok = false;
- break;
- }
- }
-
- return ok;
- }
-};
-
-file_writer_16sc::~file_writer_16sc()
-{
- fclose(d_fp);
-}
-
-// ------------------------------------------------------------------------
-
-class file_writer_32fc : public rx_nop_handler
-{
- FILE *d_fp;
- std::string d_filename;
-
-public:
-
- file_writer_32fc(const std::string &filename, uint64_t max_samples)
- : rx_nop_handler(max_samples), d_filename(filename)
- {
- d_fp = fopen(filename.c_str(), "wb");
- if (d_fp == 0){
- perror(filename.c_str());
- throw std::invalid_argument(filename);
- }
- }
-
- ~file_writer_32fc();
-
- bool
- operator()(const uint32_t *items, size_t nitems, const vrt::expanded_header *hdr)
- {
- bool ok = rx_nop_handler::operator()(items, nitems, hdr);
-
- size_t host_nitems = nitems;
- std::complex<float> host_items[host_nitems];
-
- vrt::copy_net_16sc_to_host_32fc(nitems, items, host_items);
-
- size_t n = 0;
- while (n < host_nitems){
- size_t r = fwrite(&host_items[n], sizeof(host_items[0]), host_nitems - n, d_fp);
- n += r;
- if (r == 0){ // out of space?
- d_err = true;
- perror(d_filename.c_str());
- ok = false;
- break;
- }
- }
-
- return ok;
- }
-};
-
-file_writer_32fc::~file_writer_32fc()
-{
- fclose(d_fp);
-}
-
-// ------------------------------------------------------------------------
-
-static void
-usage(const char *progname)
-{
- const char *p = strrchr(progname, '/'); // drop leading directory path
- if (p)
- p++;
-
- if (strncmp(p, "lt-", 3) == 0) // drop lt- libtool prefix
- p += 3;
-
- fprintf(stderr, "Usage: %s [options]\n\n", p);
- fprintf(stderr, "Options:\n");
- fprintf(stderr, " -h show this message and exit\n");
-//fprintf(stderr, " -e ETH_INTERFACE specify ethernet interface [default=eth0]\n");
-//fprintf(stderr, " -m MAC_ADDR mac address of USRP2 HH:HH [default=first one found]\n");
-//fprintf(stderr, " -f FREQUENCY specify receive center frequency in Hz [default=0.0]\n");
-//fprintf(stderr, " -d DECIM specify receive decimation rate [default=5]\n");
-//fprintf(stderr, " -g GAIN specify receive daughterboard gain [default=0]\n");
- fprintf(stderr, " -N NSAMPLES specify number of samples to receive [default=infinite]\n");
- fprintf(stderr, " -o OUTPUT_FILENAME specify file to receive samples [default=none]\n");
- fprintf(stderr, " -s write complex<short> [default=complex<float>]\n");
- fprintf(stderr, " -S samples_per_pkt specify # of samples per pkt [default=maximum]\n");
-//fprintf(stderr, " -v verbose output\n");
-}
-
-
-int
-main(int argc, char **argv)
-{
- const char *quad_radio_ip = "192.168.123.123";
- size_t rx_bufsize = 62.5e6; // sizeof memory mapped network buffer
- int samples_per_pkt = 0; // use default
- uint64_t nsamples = 0;
- char *output_filename = 0;
- bool output_shorts = false;
- int t;
-
- int ch;
-
- while ((ch = getopt(argc, argv, "hN:o:sS:")) != EOF){
- switch (ch){
- case 'N':
- nsamples = (uint64_t) strtod(optarg, 0);
- break;
-
- case 'o':
- output_filename = optarg;
- break;
-
- case 's':
- output_shorts = true;
- break;
-
- case 'S':
- errno = 0;
- t = strtol(optarg, 0, 0);
- if (errno != 0){
- usage(argv[0]);
- exit(1);
- }
- samples_per_pkt = t;
- break;
-
- case 'h':
- default:
- usage(argv[0]);
- exit(1);
- }
- }
-
-
- install_sig_handler(SIGINT, sig_handler);
-
- gruel::rt_status_t rt = gruel::enable_realtime_scheduling();
- if (rt != gruel::RT_OK)
- std::cerr << "Failed to enable realtime scheduling" << std::endl;
-
-
- vrt::quadradio::sptr qr;
- try {
- qr = vrt::quadradio::sptr(new vrt::quadradio(quad_radio_ip, rx_bufsize));
- }
- catch (...){
- std::cerr << "Failed to create vrt::quadradio\n";
- return 1;
- }
-
-
- rx_nop_handler::sptr handler;
- if (output_filename){
- if (output_shorts)
- handler = rx_nop_handler::sptr(new file_writer_16sc(output_filename, nsamples));
- else
- handler = rx_nop_handler::sptr(new file_writer_32fc(output_filename, nsamples));
- }
- else
- handler = rx_nop_handler::sptr(new rx_nop_handler(nsamples));
-
-
- printf("samples_per_pkt = %d\n", samples_per_pkt);
-
- if (!qr->start_streaming(samples_per_pkt)){
- fprintf(stderr, "failed to send_rx_command\n");
- return 1;
- }
-
- // start receiving packets
-
- while(1
- && !signaled
- && !handler->has_errored_p()
- && !handler->has_finished_p()){
- bool ok = qr->vrt_rx()->rx_packets(handler.get());
- if (!ok){
- fprintf(stderr, "vrt->rx_packets failed\n");
- break;
- }
- }
-
- qr->stop_streaming();
-
- printf("%llu packets received, %llu bad pkt_cnt field values, %llu samples\n",
- handler->npackets(), handler->nwrong_pkt_cnt(), handler->nsamples());
-
- //sleep(1);
-
- return 0;
-}
diff --git a/vrt/include/vrt/Makefile.am b/vrt/include/vrt/Makefile.am
index b710547d9..183eaf9ce 100644
--- a/vrt/include/vrt/Makefile.am
+++ b/vrt/include/vrt/Makefile.am
@@ -25,6 +25,6 @@ vrtinclude_HEADERS = \
bits.h \
copiers.h \
expanded_header.h \
- quadradio.h \
rx.h \
- rx_packet_handler.h
+ rx_packet_handler.h \
+ types.h
diff --git a/vrt/include/vrt/bits.h b/vrt/include/vrt/bits.h
index bb4227db4..54eeec7b4 100644
--- a/vrt/include/vrt/bits.h
+++ b/vrt/include/vrt/bits.h
@@ -1,24 +1,20 @@
/* -*- 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
+ *
+ * This program 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,
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
#ifndef INCLUDED_VRT_BITS_H
#define INCLUDED_VRT_BITS_H
@@ -53,7 +49,9 @@
#define VRTH_TSF_REAL_TIME_PS (0x2 << 20)
#define VRTH_TSF_FREE_RUNNING (0x3 << 20)
+#define VRTH_PKT_CNT_SHIFT 16
#define VRTH_PKT_CNT_MASK (0xf << 16)
+
#define VRTH_PKT_SIZE_MASK 0xffff
@@ -69,4 +67,26 @@ vrth_pkt_size(uint32_t h)
return h & VRTH_PKT_SIZE_MASK;
}
+/*
+ * Trailer bits
+ */
+#define TR_E (1 << 8)
+
+#define TR_ENABLE(x) ((x) << 20)
+#define TR_STATE(x) ((x) << 8)
+
+// Use these with TR_ENABLE and TR_STATE
+#define TR_CAL_TIME (1 << 11)
+#define TR_VALID_DATA (1 << 10)
+#define TR_REF_LOCK (1 << 9)
+#define TR_AGC (1 << 8)
+#define TR_DETECTED_SIG (1 << 7)
+#define TR_SPECTRAL_INVERSION (1 << 6)
+#define TR_OVER_RANGE (1 << 5)
+#define TR_SAMPLE_LOSS (1 << 4)
+#define TR_USER_3 (1 << 3)
+#define TR_USER_2 (1 << 2)
+#define TR_USER_1 (1 << 1)
+#define TR_USER_0 (1 << 0)
+
#endif /* INCLUDED_VRT_BITS_H */
diff --git a/vrt/include/vrt/quadradio.h b/vrt/include/vrt/quadradio.h
deleted file mode 100644
index d30ee14f1..000000000
--- a/vrt/include/vrt/quadradio.h
+++ /dev/null
@@ -1,143 +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; }
-
- // FIXME add rxdspno as the first parameter
- bool start_streaming(int samples_per_pkt = 0);
-
- // FIXME add rxdspno as the first parameter
- bool stop_streaming();
-
- /* 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/include/vrt/types.h b/vrt/include/vrt/types.h
new file mode 100644
index 000000000..edfa4ec37
--- /dev/null
+++ b/vrt/include/vrt/types.h
@@ -0,0 +1,138 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ *
+ * This program 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 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef INCLUDED_VRT_TYPES_H
+#define INCLUDED_VRT_TYPES_H
+
+#include <stdint.h>
+
+/* macros for dealing with fixed point numbers */
+#define _FXPT_C(_type, _x, _rp) ((_type)((_x)*(1ll << _rp)))
+#define _FXPT_TO_INT(_x, _one) (((_x) + ((_one)/2))/(_one))
+#define _FXPT_TO_DOUBLE(_x, _one) ((double)(_x) * (1.0/(_one)))
+
+/***********************************************************************
+ * The VRT Altitude Type (meters)
+ **********************************************************************/
+typedef int32_t vrt_altitude_t;
+#define VRT_ALTITUDE_RP 5
+#define VRT_ALTITUDE_C(_x) _FXPT_C(vrt_altitude_t, _x, VRT_ALTITUDE_RP)
+
+static inline vrt_altitude_t
+double_to_vrt_altitude(double num){
+ return VRT_ALTITUDE_C(num);
+}
+
+static inline int32_t
+vrt_altitude_round_to_int(vrt_altitude_t fx){
+ return _FXPT_TO_INT(fx, VRT_ALTITUDE_C(1));
+}
+
+static inline double
+vrt_altitude_to_double(vrt_altitude_t fx){
+ return _FXPT_TO_DOUBLE(fx, VRT_ALTITUDE_C(1));
+}
+
+/***********************************************************************
+ * The VRT Geolocation Angle Type (degrees)
+ **********************************************************************/
+typedef int32_t vrt_geo_angle_t;
+#define VRT_GEO_ANGLE_RP 22
+#define VRT_GEO_ANGLE_C(_x) _FXPT_C(vrt_geo_angle_t, _x, VRT_GEO_ANGLE_RP)
+
+static inline vrt_geo_angle_t
+double_to_vrt_geo_angle(double num){
+ return VRT_GEO_ANGLE_C(num);
+}
+
+static inline int16_t
+vrt_geo_angle_round_to_int(vrt_geo_angle_t fx){
+ return _FXPT_TO_INT(fx, VRT_GEO_ANGLE_C(1));
+}
+
+static inline double
+vrt_geo_angle_to_double(vrt_geo_angle_t fx){
+ return _FXPT_TO_DOUBLE(fx, VRT_GEO_ANGLE_C(1));
+}
+
+/***********************************************************************
+ * The VRT Frequency Type (Hz)
+ **********************************************************************/
+typedef int64_t vrt_freq_t;
+#define VRT_FREQ_RP 20
+#define VRT_FREQ_C(_x) _FXPT_C(vrt_freq_t, _x, VRT_FREQ_RP)
+
+static inline vrt_freq_t
+double_to_vrt_freq(double num){
+ return VRT_FREQ_C(num);
+}
+
+static inline int64_t
+vrt_freq_round_to_int(vrt_freq_t fx){
+ return _FXPT_TO_INT(fx, VRT_FREQ_C(1));
+}
+
+static inline double
+vrt_freq_to_double(vrt_freq_t fx){
+ return _FXPT_TO_DOUBLE(fx, VRT_FREQ_C(1));
+}
+
+/***********************************************************************
+ * The VRT Gain Type (dB)
+ **********************************************************************/
+typedef int16_t vrt_gain_t;
+#define VRT_GAIN_RP 7
+#define VRT_GAIN_C(_x) _FXPT_C(vrt_gain_t, _x, VRT_GAIN_RP)
+
+static inline vrt_gain_t
+double_to_vrt_gain(double num){
+ return VRT_GAIN_C(num);
+}
+
+static inline int16_t
+vrt_gain_round_to_int(vrt_gain_t fx){
+ return _FXPT_TO_INT(fx, VRT_GAIN_C(1));
+}
+
+static inline double
+vrt_gain_to_double(vrt_gain_t fx){
+ return _FXPT_TO_DOUBLE(fx, VRT_GAIN_C(1));
+}
+
+/***********************************************************************
+ * The VRT Temperature Type (Celcius)
+ **********************************************************************/
+typedef int16_t vrt_temp_t;
+#define VRT_TEMP_RP 6
+#define VRT_TEMP_C(_x) _FXPT_C(vrt_temp_t, _x, VRT_TEMP_RP)
+
+static inline vrt_temp_t
+double_to_vrt_temp(double num){
+ return VRT_TEMP_C(num);
+}
+
+static inline int16_t
+vrt_temp_round_to_int(vrt_temp_t fx){
+ return _FXPT_TO_INT(fx, VRT_TEMP_C(1));
+}
+
+static inline double
+vrt_temp_to_double(vrt_temp_t fx){
+ return _FXPT_TO_DOUBLE(fx, VRT_TEMP_C(1));
+}
+
+#endif /* INCLUDED_VRT_TYPES_H */
diff --git a/vrt/lib/Makefile.am b/vrt/lib/Makefile.am
index 9832c0cd5..3a758eeac 100644
--- a/vrt/lib/Makefile.am
+++ b/vrt/lib/Makefile.am
@@ -20,7 +20,8 @@ include $(top_srcdir)/Makefile.common
AM_CPPFLAGS = \
$(VRT_INCLUDES) \
$(BOOST_CPPFLAGS) \
- $(CPPUNIT_INCLUDES)
+ $(CPPUNIT_INCLUDES) \
+ $(GRUEL_INCLUDES)
bin_PROGRAMS =
@@ -31,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/expanded_header.cc b/vrt/lib/expanded_header.cc
index d5c4ea888..0eb2042d8 100644
--- a/vrt/lib/expanded_header.cc
+++ b/vrt/lib/expanded_header.cc
@@ -23,7 +23,7 @@
#include <config.h>
#endif
#include <vrt/expanded_header.h>
-#include <arpa/inet.h> // needs autoconf'ing
+#include <gruel/inet.h>
//#include <stdio.h>
namespace vrt {
@@ -112,6 +112,12 @@ namespace vrt {
#include "expanded_header_switch_body.h"
}
+ /* is this a if context packet? */
+ if (h->if_context_p()){
+ *payload = p;
+ *n32_bit_words_payload = n32_bit_words_packet;
+ }
+
return true;
}
diff --git a/vrt/lib/quadradio.cc b/vrt/lib/quadradio.cc
deleted file mode 100644
index a8bc3e525..000000000
--- a/vrt/lib/quadradio.cc
+++ /dev/null
@@ -1,428 +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 <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 samples_per_pkt)
-{
- int rxdspno = 0; // FIXME make it the first param
-
- 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 = 0; // FIXME make it the first param
-
- 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)
-{
- uint64_t lo_freq = uint64_t(freq * (uint64_t(1)<<20)); //q20 format
- uint32_t cmd[4];
- cmd[0] = htonl(0); // verb: set
- cmd[1] = htonl(6); // id: lo freq
- cmd[2] = htonl((lo_freq >> 32) & 0xffffffff);
- cmd[3] = htonl((lo_freq >> 0) & 0xffffffff);
-
- return send_and_check(d_ctrl_fd, cmd, sizeof(cmd));
-}
-
-bool
-vrt::quadradio::set_cal_freq(double freq)
-{
- uint64_t cal_freq = uint64_t(freq * (uint64_t(1)<<20)); //q20 format
- uint32_t cmd[4];
- cmd[0] = htonl(0); // verb: set
- cmd[1] = htonl(7); // id: cal freq
- cmd[2] = htonl((cal_freq >> 32) & 0xffffffff);
- cmd[3] = htonl((cal_freq >> 0) & 0xffffffff);
-
- 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));
-}