summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnuradio-core/src/python/gnuradio/blks2impl/stream_to_vector_decimator.py3
-rw-r--r--gr-vrt/src/vrt_quadradio_source_32fc.cc20
-rw-r--r--gr-vrt/src/vrt_quadradio_source_32fc.h25
-rw-r--r--gr-vrt/src/vrt_source_32fc.cc94
-rw-r--r--gr-vrt/src/vrt_source_32fc.h18
-rw-r--r--gr-wxgui/src/python/forms/forms.py8
-rw-r--r--gruel/src/include/gruel/inet.h.in33
-rw-r--r--vrt/apps/simple_rx_samples.cc4
-rw-r--r--vrt/include/vrt/Makefile.am4
-rw-r--r--vrt/include/vrt/bits.h46
-rw-r--r--vrt/include/vrt/if_context.h243
-rw-r--r--vrt/include/vrt/quadradio.h6
-rw-r--r--vrt/include/vrt/types.h138
-rw-r--r--vrt/lib/Makefile.am3
-rw-r--r--vrt/lib/expanded_header.cc8
-rw-r--r--vrt/lib/quadradio.cc20
16 files changed, 599 insertions, 74 deletions
diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/stream_to_vector_decimator.py b/gnuradio-core/src/python/gnuradio/blks2impl/stream_to_vector_decimator.py
index 39c8b5050..8f75729c9 100644
--- a/gnuradio-core/src/python/gnuradio/blks2impl/stream_to_vector_decimator.py
+++ b/gnuradio-core/src/python/gnuradio/blks2impl/stream_to_vector_decimator.py
@@ -72,8 +72,7 @@ class stream_to_vector_decimator(gr.hier_block2):
self.one_in_n.set_n(self._decim)
def _update_decimator(self):
- self._decim = max(1, int(round(self._sample_rate/self._vec_len/self._vec_rate)))
- self.one_in_n.set_n(self._decim)
+ self.set_decimation(self._sample_rate/self._vec_len/self._vec_rate)
def decimation(self):
"""
diff --git a/gr-vrt/src/vrt_quadradio_source_32fc.cc b/gr-vrt/src/vrt_quadradio_source_32fc.cc
index 0aac86991..cd779bdf5 100644
--- a/gr-vrt/src/vrt_quadradio_source_32fc.cc
+++ b/gr-vrt/src/vrt_quadradio_source_32fc.cc
@@ -29,25 +29,29 @@
vrt_quadradio_source_32fc_sptr
vrt_make_quadradio_source_32fc(const std::string &ip,
size_t rx_bufsize,
- size_t samples_per_pkt)
+ size_t samples_per_pkt,
+ int rxdspno)
{
return gnuradio::get_initial_sptr(new vrt_quadradio_source_32fc(ip,
rx_bufsize,
- samples_per_pkt));
+ 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)
+ size_t samples_per_pkt,
+ int rxdspno)
: vrt_source_32fc("quadradio_source_32fc"),
- d_samples_per_pkt(samples_per_pkt == 0 ? 800 : samples_per_pkt),
- d_qr(vrt::quadradio::sptr(new vrt::quadradio(ip, rx_bufsize)))
+ 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_qr->stop_streaming(d_rxdspno);
}
vrt::rx::sptr
@@ -64,13 +68,13 @@ vrt_quadradio_source_32fc::start()
vrt_rx()->rx_packets(&nop, true);
d_checker.resync();
- return d_qr->start_streaming(d_samples_per_pkt);
+ return d_qr->start_streaming(d_rxdspno, d_samples_per_pkt);
}
bool
vrt_quadradio_source_32fc::stop()
{
- return d_qr->stop_streaming();
+ return d_qr->stop_streaming(d_rxdspno);
}
bool
diff --git a/gr-vrt/src/vrt_quadradio_source_32fc.h b/gr-vrt/src/vrt_quadradio_source_32fc.h
index 6193efa10..bb3935c46 100644
--- a/gr-vrt/src/vrt_quadradio_source_32fc.h
+++ b/gr-vrt/src/vrt_quadradio_source_32fc.h
@@ -33,19 +33,21 @@ typedef boost::shared_ptr<vrt_quadradio_source_32fc> vrt_quadradio_source_32fc_s
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);
+ 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);
+ 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);
+ size_t samples_per_pkt, int rxdspno);
public:
virtual ~vrt_quadradio_source_32fc();
@@ -110,6 +112,23 @@ public:
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;}
};
diff --git a/gr-vrt/src/vrt_source_32fc.cc b/gr-vrt/src/vrt_source_32fc.cc
index beb5ef26d..f9375d31c 100644
--- a/gr-vrt/src/vrt_source_32fc.cc
+++ b/gr-vrt/src/vrt_source_32fc.cc
@@ -27,9 +27,14 @@
#include <vrt_source_32fc.h>
#include <vrt/expanded_header.h>
#include <vrt/copiers.h>
+#include <vrt/types.h>
+#include <vrt/if_context.h>
#include <gr_io_signature.h>
#include <missing_pkt_checker.h>
#include <iostream>
+#include <gruel/inet.h>
+#include <cstdio>
+#include <cstring>
#define VERBOSE 1 // define to 0 or 1
@@ -41,7 +46,8 @@ class rx_32fc_handler : public vrt::rx_packet_handler
int *d_oo; // output index
std::vector< std::complex<float> > &d_remainder;
missing_pkt_checker &d_checker;
-
+ all_context_t d_if_context;
+ size_t d_if_context_n32_bit_words;
public:
@@ -49,13 +55,16 @@ public:
int *oo, std::vector< std::complex<float> > &remainder,
missing_pkt_checker &checker)
: d_noutput_items(noutput_items), d_out(out),
- d_oo(oo), d_remainder(remainder), d_checker(checker) {}
+ d_oo(oo), d_remainder(remainder), d_checker(checker),
+ d_if_context_n32_bit_words(0) {}
~rx_32fc_handler();
bool operator()(const uint32_t *payload,
size_t n32_bit_words,
const vrt::expanded_header *hdr);
+ all_context_t* get_if_context(void){
+ return d_if_context_n32_bit_words? &d_if_context : NULL;};
};
rx_32fc_handler::~rx_32fc_handler()
@@ -67,29 +76,48 @@ rx_32fc_handler::operator()(const uint32_t *payload,
size_t n32_bit_words,
const vrt::expanded_header *hdr)
{
- int nmissing = d_checker.check(hdr);
- if (VERBOSE && nmissing != 0){
- std::cerr << "S" << nmissing;
+ if (hdr->if_data_p()){
+ int nmissing = d_checker.check(hdr);
+ if (VERBOSE && nmissing != 0){
+ std::cerr << "S" << nmissing;
+ }
+
+ // copy as many as will fit into the output buffer.
+
+ size_t n = std::min(n32_bit_words, (size_t)(d_noutput_items - *d_oo));
+ vrt::copy_net_16sc_to_host_32fc(n, payload, &d_out[*d_oo]);
+ *d_oo += n;
+
+ // if there are any left over, copy them into remainder and tell
+ // our caller we're had enough for now.
+
+ size_t r = n32_bit_words - n;
+ if (r > 0){
+ assert(d_remainder.size() == 0);
+ d_remainder.resize(r);
+ vrt::copy_net_16sc_to_host_32fc(r, &payload[n], &d_remainder[0]);
+ return false; // Stop calling us.
+ }
+
+ return true; // Keep calling us, we've got more room
}
-
- // copy as many as will fit into the output buffer.
-
- size_t n = std::min(n32_bit_words, (size_t)(d_noutput_items - *d_oo));
- vrt::copy_net_16sc_to_host_32fc(n, payload, &d_out[*d_oo]);
- *d_oo += n;
-
- // if there are any left over, copy them into remainder and tell
- // our caller we're had enough for now.
-
- size_t r = n32_bit_words - n;
- if (r > 0){
- assert(d_remainder.size() == 0);
- d_remainder.resize(r);
- vrt::copy_net_16sc_to_host_32fc(r, &payload[n], &d_remainder[0]);
- return false; // Stop calling us.
+ else if (hdr->if_context_p()){
+ // print the IF-Context packet
+ fprintf(stderr, "\nIF-Context:\n");
+ //for (size_t i = 0; i < n32_bit_words; i++)
+ // fprintf(stderr, "%04x: %08x\n", (unsigned int) i, ntohl(payload[i]));
+ memcpy(&d_if_context, payload, sizeof(uint32_t)*n32_bit_words);
+ d_if_context_n32_bit_words = n32_bit_words;
+ return true;
+ }
+ else {
+ // It's most likely an Extension Data or Extension Context packet
+ // (that we don't know how to interpret...)
+ fprintf(stderr, "\nIF-Extension:\n");
+ for (size_t i = 0; i < n32_bit_words; i++)
+ fprintf(stderr, "%04x: %08x\n", (unsigned int) i, ntohl(payload[i]));
+ return true;
}
-
- return true; // Keep calling us, we've got more room
}
@@ -140,5 +168,25 @@ vrt_source_32fc::work(int noutput_items,
return -1; // say we're done
}
+ //we have a context packet, grab its useful information...
+ //remember that things are in network byte order!
+ if (h.get_if_context()){
+ //extract caldiv stuff
+ d_lo_freq = vrt_freq_to_double(ntohx(h.get_if_context()->caldiv.lo_freq));
+ d_cal_freq = vrt_freq_to_double(ntohx(h.get_if_context()->caldiv.cal_freq));
+ d_lo_locked = bool(ntohx(h.get_if_context()->caldiv.lo_locked));
+ d_cal_locked = bool(ntohx(h.get_if_context()->caldiv.cal_locked));
+ d_cal_enabled = bool(ntohx(h.get_if_context()->caldiv.cal_enabled));
+ d_caldiv_temp = vrt_temp_to_double(ntohx(h.get_if_context()->caldiv.temp));
+ d_caldiv_rev = ntohx(h.get_if_context()->caldiv.rev);
+ d_caldiv_ser = ntohx(h.get_if_context()->caldiv.ser);
+ d_caldiv_mod = ntohx(h.get_if_context()->caldiv.mod);
+ //extract gps stuff
+ d_utc_time = ntohx(h.get_if_context()->gps.formatted_gps.integer_secs);
+ d_altitude = vrt_altitude_to_double(ntohx(h.get_if_context()->gps.formatted_gps.altitude));
+ d_longitude = vrt_geo_angle_to_double(ntohx(h.get_if_context()->gps.formatted_gps.longitude));
+ d_latitude = vrt_geo_angle_to_double(ntohx(h.get_if_context()->gps.formatted_gps.latitude));
+ }
+
return oo;
}
diff --git a/gr-vrt/src/vrt_source_32fc.h b/gr-vrt/src/vrt_source_32fc.h
index 7ca3e5fe2..c43170e83 100644
--- a/gr-vrt/src/vrt_source_32fc.h
+++ b/gr-vrt/src/vrt_source_32fc.h
@@ -34,6 +34,23 @@ protected:
std::vector< std::complex<float> > d_remainder;
missing_pkt_checker d_checker;
+ //caldiv settings parsed from if context
+ double d_cal_freq;
+ bool d_cal_locked;
+ bool d_cal_enabled;
+ double d_lo_freq;
+ bool d_lo_locked;
+ double d_caldiv_temp;
+ int d_caldiv_rev;
+ int d_caldiv_ser;
+ int d_caldiv_mod;
+
+ //gps settings parsed from if context
+ int d_utc_time;
+ double d_altitude;
+ double d_longitude;
+ double d_latitude;
+
public:
~vrt_source_32fc();
@@ -42,7 +59,6 @@ public:
gr_vector_void_star &output_items);
void reset() { d_remainder.clear(); }
-
};
#endif /* INCLUDED_VRT_SOURCE_32FC_H */
diff --git a/gr-wxgui/src/python/forms/forms.py b/gr-wxgui/src/python/forms/forms.py
index 8dc58367d..19b30ffb0 100644
--- a/gr-wxgui/src/python/forms/forms.py
+++ b/gr-wxgui/src/python/forms/forms.py
@@ -194,15 +194,19 @@ class static_text(_form_base):
@param label title label for this widget (optional)
@param width the width of the form in px
@param bold true to bold-ify the text (default=False)
+ @param units a suffix to add after the text
@param converter forms.str_converter(), int_converter(), float_converter()...
"""
- def __init__(self, label='', width=-1, bold=False, converter=converters.str_converter(), **kwargs):
+ def __init__(self, label='', width=-1, bold=False, units='', converter=converters.str_converter(), **kwargs):
+ self._units = units
_form_base.__init__(self, converter=converter, **kwargs)
self._static_text = wx.StaticText(self._parent, size=wx.Size(width, -1))
if bold: make_bold(self._static_text)
self._add_widget(self._static_text, label)
- def _update(self, label): self._static_text.SetLabel(label); self._parent.Layout()
+ def _update(self, label):
+ if self._units: label += ' ' + self._units
+ self._static_text.SetLabel(label); self._parent.Layout()
########################################################################
# Text Box Form
diff --git a/gruel/src/include/gruel/inet.h.in b/gruel/src/include/gruel/inet.h.in
index a98d83e9c..7ac01eb56 100644
--- a/gruel/src/include/gruel/inet.h.in
+++ b/gruel/src/include/gruel/inet.h.in
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2008 Free Software Foundation, Inc.
+ * Copyright 2008, 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
@@ -19,6 +19,35 @@
#ifndef INCLUDED_INET_H
#define INCLUDED_INET_H
+#include <stdint.h>
+
+#if 1 /* missing htonll or ntohll */
+#if @GR_ARCH_BIGENDIAN@ /* GR_ARCH_BIGENDIAN */
+// Nothing to do...
+static inline uint64_t htonll(uint64_t x){ return x;}
+static inline uint64_t ntohll(uint64_t x){ return x;}
+#else
+#if @GR_HAVE_BYTESWAP@ /* GR_HAVE_BYTESWAP */
+#include <byteswap.h>
+#else
+
+static inline uint64_t
+bswap_64(uint64_t x)
+{
+ return ((x & 0x00000000000000ffull) << 56) | ((x & 0x000000000000ff00ull) << 40) |
+ ((x & 0x0000000000ff0000ull) << 24) | ((x & 0x00000000ff000000ull) << 8) |
+ ((x & 0x000000ff00000000ull) >> 8) | ((x & 0x0000ff0000000000ull) >> 24) |
+ ((x & 0x00ff000000000000ull) >> 40) | ((x & 0xff00000000000000ull) >> 56);
+}
+
+#endif /* GR_HAVE_BYTESWAP */
+
+static inline uint64_t htonll(uint64_t x){ return bswap_64(x);}
+static inline uint64_t ntohll(uint64_t x){ return bswap_64(x);}
+
+#endif /* GR_ARCH_BIGENDIAN */
+#endif /* missing htonll or ntohll */
+
#if @GR_HAVE_ARPA_INET@ /* GR_HAVE_ARPA_INET */
#include <arpa/inet.h>
#elif @GR_HAVE_NETINET_IN@ /* GR_HAVE_NETINET_IN */
@@ -61,8 +90,10 @@ static inline uint16_t ntohs(uint16_t x){ return bswap_16(x); }
static inline uint8_t ntohx(uint8_t x){ return x; }
static inline uint16_t ntohx(uint16_t x){ return ntohs(x); }
static inline uint32_t ntohx(uint32_t x){ return ntohl(x); }
+static inline uint64_t ntohx(uint64_t x){ return ntohll(x);}
static inline uint8_t htonx(uint8_t x){ return x; }
static inline uint16_t htonx(uint16_t x){ return htons(x); }
static inline uint32_t htonx(uint32_t x){ return htonl(x); }
+static inline uint64_t htonx(uint64_t x){ return htonll(x);}
#endif /* INCLUDED_INET_H */
diff --git a/vrt/apps/simple_rx_samples.cc b/vrt/apps/simple_rx_samples.cc
index 6b09afda5..08f01c9cc 100644
--- a/vrt/apps/simple_rx_samples.cc
+++ b/vrt/apps/simple_rx_samples.cc
@@ -365,7 +365,7 @@ main(int argc, char **argv)
printf("samples_per_pkt = %d\n", samples_per_pkt);
- if (!qr->start_streaming(samples_per_pkt)){
+ if (!qr->start_streaming(0, samples_per_pkt)){
fprintf(stderr, "failed to send_rx_command\n");
return 1;
}
@@ -383,7 +383,7 @@ main(int argc, char **argv)
}
}
- qr->stop_streaming();
+ qr->stop_streaming(0);
printf("%llu packets received, %llu bad pkt_cnt field values, %llu samples\n",
handler->npackets(), handler->nwrong_pkt_cnt(), handler->nsamples());
diff --git a/vrt/include/vrt/Makefile.am b/vrt/include/vrt/Makefile.am
index b710547d9..2780d79b0 100644
--- a/vrt/include/vrt/Makefile.am
+++ b/vrt/include/vrt/Makefile.am
@@ -26,5 +26,7 @@ vrtinclude_HEADERS = \
copiers.h \
expanded_header.h \
quadradio.h \
+ if_context.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/if_context.h b/vrt/include/vrt/if_context.h
new file mode 100644
index 000000000..24aba7a9e
--- /dev/null
+++ b/vrt/include/vrt/if_context.h
@@ -0,0 +1,243 @@
+/* -*- 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_IF_CONTEXT_H
+#define INCLUDED_VRT_IF_CONTEXT_H
+
+#include <stdint.h>
+
+// Stream ID's for packet streams (low 8-bits)
+
+#define QR_SID_BEAMFORMER_IF_DATA 0x00 // paired
+#define QR_SID_BEAMFORMER_IF_CNTX 0x00 // paired
+#define QR_SID_DBOARD_0_IF_CNTX 0x01 // src assoc
+#define QR_SID_DBOARD_1_IF_CNTX 0x02 // src assoc
+#define QR_SID_DBOARD_2_IF_CNTX 0x03 // src assoc
+#define QR_SID_DBOARD_3_IF_CNTX 0x04 // src assoc
+#define QR_SID_GPS_IF_CNTX 0x05 // system assoc
+#define QR_SID_SYS_INFO_EXT_CNTX 0x06 // system assoc
+
+// No class id, with 3 words of time.
+// Used for all IF-Context packets
+typedef struct if_context_hdr_tag {
+ uint32_t header; // first word of all packets
+ uint32_t stream_id; // mandatory in context packets
+ uint32_t integer_secs; // integer seconds timestamp
+ uint64_t fractional_secs; // fractional seconds timestamp
+ uint32_t context_indicator; // which context fields follow
+} __attribute__((packed)) if_context_hdr_t;
+
+
+// With class id, with 3 words of time.
+// Used only with Extension Context packets
+typedef struct if_context_hdr_with_classid_tag {
+ uint32_t header; // first word of all packets
+ uint32_t stream_id; // mandatory in context packets
+ uint64_t class_id; // class identifier
+ uint32_t integer_secs; // integer seconds timestamp
+ uint64_t fractional_secs; // fractional seconds timestamp
+ uint32_t context_indicator; // which context fields follow
+} __attribute__((packed)) if_context_hdr_with_classid_t;
+
+
+// ------------------------------------------------------------------------
+// Context Indicator field bits (Table 7.1.5.1-1)
+
+#define CI_CHANGE_INDICATOR (1 << 31)
+#define CI_REF_POINT_ID (1 << 30)
+#define CI_BANDWIDTH (1 << 29)
+#define CI_IF_REF_FREQ (1 << 28)
+#define CI_RF_REF_FREQ (1 << 27)
+#define CI_RF_REF_FREQ_OFFSET (1 << 26)
+#define CI_IF_BAND_OFFSET (1 << 25)
+#define CI_REF_LEVEL (1 << 24)
+#define CI_GAIN (1 << 23)
+#define CI_OVER_RANGE_COUNT (1 << 22)
+#define CI_SAMPLE_RATE (1 << 21)
+#define CI_TIMESTAMP_ADJ (1 << 20)
+#define CI_TIMESTAMP_CAL_TIME (1 << 19)
+#define CI_TEMPERATURE (1 << 18)
+#define CI_DEVICE_ID (1 << 17)
+#define CI_STATE_AND_EVENT_IND (1 << 16)
+#define CI_PAYLOAD_FMT (1 << 15)
+#define CI_FORMATTED_GPS (1 << 14)
+#define CI_FORMATTED_INS (1 << 13)
+#define CI_ECEF_EPHEMERIS (1 << 12)
+#define CI_REL_EPHEMERIS (1 << 11)
+#define CI_EPHEMERIS_REF_ID (1 << 10)
+#define CI_ASCII_GPS (1 << 9)
+#define CI_CNTX_ASSOC_LISTS (1 << 8)
+#define CI_RESERVED_7 (1 << 7)
+#define CI_RESERVED_6 (1 << 6)
+#define CI_RESERVED_5 (1 << 5)
+#define CI_RESERVED_4 (1 << 4)
+#define CI_RESERVED_3 (1 << 3)
+#define CI_RESERVED_2 (1 << 2)
+#define CI_RESERVED_1 (1 << 1)
+#define CI_RESERVED_0 (1 << 0)
+
+
+// ------------------------------------------------------------------------
+// Types that may be in the Context Section
+
+
+// 7.1.5.10 Gain -- two Q10.6 dB fields
+
+static inline uint32_t
+vrt_make_gain_field(int16_t stage1, int16_t stage2)
+{
+ return (((uint32_t) stage2) << 16) | (stage1 & 0xffff);
+}
+
+static inline int16_t
+vrt_gain_stage1(uint32_t field)
+{
+ return (int16_t)(field & 0xffff);
+}
+
+static inline int16_t
+vrt_gain_stage2(uint32_t field)
+{
+ return (int16_t)((field >> 16) & 0xffff);
+}
+
+// See VITA-49.0 section 7.1.5.19
+
+#define VRT_GPS_UNKNOWN_VALUE 0x7fffffff // for SOG, heading, track, and mag var
+
+typedef struct vrt_formatted_gps_tag {
+ uint32_t tsi_tsf_manuf_oui;
+ uint32_t integer_secs; // timestamp of position fix
+ uint64_t fractional_secs; // timestamp of position fix
+ uint32_t latitude; // degrees Q10.22
+ uint32_t longitude; // degrees Q10.22
+ uint32_t altitude; // meters Q27.5
+ uint32_t speed_over_ground;
+ uint32_t heading_angle;
+ uint32_t track_angle;
+ uint32_t magnetic_variation;
+} vrt_formatted_gps_t;
+
+
+// Data Packet Payload Format Field 7.1.5.18
+
+typedef struct vrt_payload_format_tag {
+ uint32_t word0;
+ uint32_t word1;
+} vrt_payload_format_t;
+
+#define DF0_PACKED (1 << 31)
+#define DF0_REAL_CMPLX_TYPE_MASK (0x3 << 29)
+#define DF0_REAL_CMPLX_TYPE_REAL (0 << 29)
+#define DF0_REAL_CMPLX_TYPE_CMPLX_CART (1 << 29)
+#define DF0_REAL_CMPLX_TYPE_CMPLX_POLAR (2 << 29)
+#define DF0_REAL_CMPLX_TYPE_RESERVED (3 << 29)
+#define DF0_ITEM_FMT_MASK (0x1f << 24)
+#define DF0_ITEM_FMT_SIGNED_FIXED_POINT (0x00 << 24)
+#define DF0_ITEM_FMT_UNSIGNED_FIXED_POINT (0x10 << 24)
+// lots more we're not using
+#define DF0_SAMPLE_COMPONENT_REPEATING (1 << 23)
+#define DF0_EVENT_TAG_SIZE_SHIFT 20
+#define DF0_EVENT_TAG_SIZE_MASK (0x7 << 20)
+#define DF0_CHANNEL_TAG_SIZE_SHIFT 16
+#define DF0_CHANNEL_TAG_SIZE_MASK (0xf << 16)
+#define DF0_RESERVED_SHIFT 12
+#define DF0_RESERVED_MASK (0xf << 12)
+#define DF0_ITEM_PACKING_FIELD_SIZE_SHIFT 6
+#define DF0_ITEM_PACKING_FIELD_SIZE_MASK (0x3f << 6)
+#define DF0_DATA_ITEM_SIZE_SHIFT 0
+#define DF0_DATA_ITEM_SIZE_MASK (0x3f << 0)
+
+#define DF1_REPEAT_COUNT_SHIFT 16
+#define DF1_REPEAT_COUNT_MASK (0xffff << 16)
+#define DF1_VECTOR_SIZE_SHIFT 0
+#define DF1_VECTOR_SIZE_MASK (0xffff << 0)
+
+
+// Composite values
+
+// 16-bit I & Q, no events, no channel tags
+#define DF0_16_BIT_IQ \
+ (0 \
+ | DF0_REAL_CMPLX_TYPE_CMPLX_CART \
+ | DF0_ITEM_FMT_SIGNED_FIXED_POINT \
+ | (15 << DF0_ITEM_PACKING_FIELD_SIZE_SHIFT) \
+ | (15 << DF0_DATA_ITEM_SIZE_SHIFT))
+
+// Vector of length 1
+#define DF1_VECTOR_1 (0 << DF1_VECTOR_SIZE_SHIFT)
+
+// Vector of length 4
+#define DF1_VECTOR_4 (3 << DF1_VECTOR_SIZE_SHIFT)
+
+
+// ------------------------------------------------------------------------
+// Our context packets
+
+typedef struct beamformer_if_cntx_tag {
+ if_context_hdr_t cntx_hdr;
+ uint64_t rf_ref_freq; // Q44.20 Hz
+ uint64_t sample_rate; // Q44.20 Hz
+ vrt_payload_format_t format;
+ // FIXME context association lists
+} __attribute__((packed)) beamformer_if_cntx_t;
+
+typedef struct gps_if_cntx_tag {
+ if_context_hdr_t cntx_hdr;
+ vrt_formatted_gps_t formatted_gps;
+} __attribute__((packed)) gps_if_cntx_t;
+
+typedef struct gain_if_cntx_tag {
+ if_context_hdr_t cntx_hdr;
+ uint32_t gain;
+} __attribute__((packed)) gain_if_cntx_t;
+
+typedef struct caldiv_if_cntx_tag {
+ if_context_hdr_t cntx_hdr;
+ uint64_t lo_freq;
+ uint32_t lo_locked;
+ uint64_t cal_freq;
+ uint32_t cal_locked;
+ uint32_t cal_enabled;
+ uint32_t temp;
+ uint32_t rev;
+ uint32_t ser;
+ uint32_t mod;
+} __attribute__((packed)) caldiv_if_cntx_t;
+
+// FIXME the rest...
+
+// ------------------------------------------------------------------------
+// All of them concatenated
+
+#define NCONTEXT_PKTS 7 // number of context pkts aggregated here
+
+typedef struct all_context_tag {
+ beamformer_if_cntx_t beamformer;
+ gain_if_cntx_t db[4];
+
+ // FIXME add Extension Context for board types, revs, serial numbers, temps
+ caldiv_if_cntx_t caldiv;
+
+ gps_if_cntx_t gps; // must be last
+} __attribute__((packed)) all_context_t;
+
+#define SIZEOF_ALL_CONTEXT (sizeof(all_context_t))
+#define SIZEOF_ALL_CONTEXT_BUT_GPS (SIZEOF_ALL_CONTEXT - sizeof(gps_if_cntx_t))
+
+
+#endif /* INCLUDED_IF_CONTEXT_H */
diff --git a/vrt/include/vrt/quadradio.h b/vrt/include/vrt/quadradio.h
index d30ee14f1..525a177a8 100644
--- a/vrt/include/vrt/quadradio.h
+++ b/vrt/include/vrt/quadradio.h
@@ -96,11 +96,9 @@ namespace vrt {
vrt::rx::sptr vrt_rx() const { return d_rx; }
- // FIXME add rxdspno as the first parameter
- bool start_streaming(int samples_per_pkt = 0);
+ bool start_streaming(int rxdspno, int samples_per_pkt = 0);
- // FIXME add rxdspno as the first parameter
- bool stop_streaming();
+ bool stop_streaming(int rxdspno);
/* convenience methods that ultimately write the dboard pins */
bool set_center_freq(double target_freq);
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..d41343a5d 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 =
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
index a8bc3e525..cc810e683 100644
--- a/vrt/lib/quadradio.cc
+++ b/vrt/lib/quadradio.cc
@@ -22,6 +22,8 @@
#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>
@@ -74,19 +76,15 @@ vrt::quadradio::open(const char *ip)
}
bool
-vrt::quadradio::start_streaming(int samples_per_pkt)
+vrt::quadradio::start_streaming(int rxdspno, 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()
+vrt::quadradio::stop_streaming(int rxdspno)
{
- int rxdspno = 0; // FIXME make it the first param
-
return send_stop_rx_command(d_ctrl_fd, rxdspno);
}
@@ -381,12 +379,11 @@ vrt::quadradio::set_mem32(int addr, int value)
bool
vrt::quadradio::set_lo_freq(double freq)
{
- uint64_t lo_freq = uint64_t(freq * (uint64_t(1)<<20)); //q20 format
+ 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
- cmd[2] = htonl((lo_freq >> 32) & 0xffffffff);
- cmd[3] = htonl((lo_freq >> 0) & 0xffffffff);
+ memcpy(cmd+2, &lo_freq, sizeof(lo_freq));
return send_and_check(d_ctrl_fd, cmd, sizeof(cmd));
}
@@ -394,12 +391,11 @@ vrt::quadradio::set_lo_freq(double freq)
bool
vrt::quadradio::set_cal_freq(double freq)
{
- uint64_t cal_freq = uint64_t(freq * (uint64_t(1)<<20)); //q20 format
+ 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
- cmd[2] = htonl((cal_freq >> 32) & 0xffffffff);
- cmd[3] = htonl((cal_freq >> 0) & 0xffffffff);
+ memcpy(cmd+2, &cal_freq, sizeof(cal_freq));
return send_and_check(d_ctrl_fd, cmd, sizeof(cmd));
}