[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9461 - in usrp2/trunk/host: apps include/usrp2
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r9461 - in usrp2/trunk/host: apps include/usrp2 |
Date: |
Sat, 30 Aug 2008 13:49:25 -0600 (MDT) |
Author: jcorgan
Date: 2008-08-30 13:49:25 -0600 (Sat, 30 Aug 2008)
New Revision: 9461
Added:
usrp2/trunk/host/include/usrp2/rx_nop_handler.h
Modified:
usrp2/trunk/host/apps/rx_streaming_samples.cc
usrp2/trunk/host/include/usrp2/Makefile.am
Log:
Refactor rx_nop_handler into API class
Modified: usrp2/trunk/host/apps/rx_streaming_samples.cc
===================================================================
--- usrp2/trunk/host/apps/rx_streaming_samples.cc 2008-08-30 19:32:25 UTC
(rev 9460)
+++ usrp2/trunk/host/apps/rx_streaming_samples.cc 2008-08-30 19:49:25 UTC
(rev 9461)
@@ -23,6 +23,7 @@
#include <usrp2/usrp2.h>
#include <usrp2/strtod_si.h>
#include <usrp2/copiers.h>
+#include <usrp2/rx_nop_handler.h>
#include <gruel/realtime.h>
#include <sys/time.h>
#include <iostream>
@@ -59,54 +60,9 @@
// ------------------------------------------------------------------------
-class rx_nop_handler : public usrp2::rx_sample_handler
-{
- uint64_t d_max_samples;
- uint64_t d_nsamples;
- uint64_t d_nframes;
-
-protected:
- bool d_err;
-
-public:
-
- rx_nop_handler(uint64_t max_samples)
- : d_max_samples(max_samples), d_nsamples(0), d_nframes(0), d_err(false) {}
-
- ~rx_nop_handler();
-
- uint64_t nframes() const { return d_nframes; }
- uint64_t nsamples() const { return d_nsamples; }
- uint64_t max_samples() const { return d_max_samples; }
- bool has_errored_p() const { return d_err; }
- bool has_finished_p() const
- { return d_max_samples == 0 ? false : d_nsamples >= d_max_samples; }
-
- bool
- operator()(const uint32_t *items, size_t nitems, const usrp2::rx_metadata
*metadata)
- {
- // printf("W0: %08x TS: %08x\n", metadata->word0, metadata->timestamp);
- // printf("I0: %08x\n", items[0]);
-
- d_nsamples += nitems;
- d_nframes++;
-
- return !has_finished_p();
- }
-};
-
-rx_nop_handler::~rx_nop_handler()
-{
- // nop
-}
-
-typedef boost::shared_ptr<rx_nop_handler> handler_sptr;
-
-// ------------------------------------------------------------------------
-
// FIXME make this a template
-class complex_16_file_writer : public rx_nop_handler
+class complex_16_file_writer : public usrp2::rx_nop_handler
{
FILE *d_fp;
std::string d_filename;
@@ -114,7 +70,7 @@
public:
complex_16_file_writer(const std::string &filename, uint64_t max_samples)
- : rx_nop_handler(max_samples), d_filename(filename)
+ : usrp2::rx_nop_handler(max_samples), d_filename(filename)
{
d_fp = fopen(filename.c_str(), "wb");
if (d_fp == 0){
@@ -158,7 +114,7 @@
// ------------------------------------------------------------------------
-class complex_float_file_writer : public rx_nop_handler
+class complex_float_file_writer : public usrp2::rx_nop_handler
{
FILE *d_fp;
std::string d_filename;
@@ -166,7 +122,7 @@
public:
complex_float_file_writer(const std::string &filename, uint64_t max_samples)
- : rx_nop_handler(max_samples), d_filename(filename)
+ : usrp2::rx_nop_handler(max_samples), d_filename(filename)
{
d_fp = fopen(filename.c_str(), "wb");
if (d_fp == 0){
@@ -210,9 +166,6 @@
// ------------------------------------------------------------------------
-
-
-
static void
usage(const char *progname)
{
@@ -321,16 +274,16 @@
install_sig_handler(SIGINT, sig_handler);
- handler_sptr handler;
+ usrp2::rx_nop_handler::sptr handler;
if (output_filename){
if (output_shorts)
- handler = handler_sptr(new complex_16_file_writer(output_filename,
nsamples));
+ handler = usrp2::rx_nop_handler::sptr(new
complex_16_file_writer(output_filename, nsamples));
else
- handler = handler_sptr(new complex_float_file_writer(output_filename,
nsamples));
+ handler = usrp2::rx_nop_handler::sptr(new
complex_float_file_writer(output_filename, nsamples));
}
else
- handler = handler_sptr(new rx_nop_handler(nsamples));
+ handler = usrp2::rx_nop_handler::sptr(new usrp2::rx_nop_handler(nsamples));
gruel::rt_status_t rt = gruel::enable_realtime_scheduling();
if (rt != gruel::RT_OK)
Modified: usrp2/trunk/host/include/usrp2/Makefile.am
===================================================================
--- usrp2/trunk/host/include/usrp2/Makefile.am 2008-08-30 19:32:25 UTC (rev
9460)
+++ usrp2/trunk/host/include/usrp2/Makefile.am 2008-08-30 19:49:25 UTC (rev
9461)
@@ -25,9 +25,9 @@
copiers.h \
copy_handler.h \
metadata.h \
+ rx_nop_handler.h \
rx_sample_handler.h \
strtod_si.h \
tune_result.h \
usrp2.h \
usrp2_cdefs.h
-
Added: usrp2/trunk/host/include/usrp2/rx_nop_handler.h
===================================================================
--- usrp2/trunk/host/include/usrp2/rx_nop_handler.h
(rev 0)
+++ usrp2/trunk/host/include/usrp2/rx_nop_handler.h 2008-08-30 19:49:25 UTC
(rev 9461)
@@ -0,0 +1,127 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 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_RX_NOP_HANDLER_H
+#define INCLUDED_RX_NOP_HANDLER_H
+
+#include <usrp2/rx_sample_handler.h>
+
+/*!
+ * Base class for receive handlers that must copy into potentially limited
+ * range destination buffers.
+ *
+ * Maintains counters for number of items copied, times invoked, and test
+ * for whether maximum has been reached.
+ *
+ * Derived classes should override the () operator, but call this
+ * parent class method at the end of their own operations.
+ */
+
+namespace usrp2 {
+
+ class rx_nop_handler : public rx_sample_handler
+ {
+ uint64_t d_max_samples;
+ uint64_t d_nsamples;
+ uint64_t d_nframes;
+
+ protected:
+ bool d_err;
+
+ public:
+
+ // Shared pointer to an instance of this class
+ typedef boost::shared_ptr<rx_nop_handler> sptr;
+
+ /*!
+ * Constructor
+ * \p max_samples Maximum number of samples to copy. Use 0 for no maximum.
+ */
+ rx_nop_handler(uint64_t max_samples)
+ : d_max_samples(max_samples), d_nsamples(0), d_nframes(0), d_err(false)
{}
+
+ /*!
+ * Destructor. Derived classes must implement their own, non-inline
destructor.
+ */
+ virtual ~rx_nop_handler();
+
+ /*!
+ * \brief Returns number of frames this copier was called with
+ */
+ uint64_t nframes() const { return d_nframes; }
+
+ /*!
+ * \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; }
+
+
+ /*!
+ * Function operator invoked by USRP2 RX API. Derived classes must
override this method
+ * but then invoke it at the end of their processing. This operator will
always be
+ * called at least once.
+ *
+ * \param items points to the first 32-bit word of uninterpreted sample
data in the frame.
+ * \param nitems is the number of entries in the frame in units of
uint32_t's.
+ * \param metadata is the additional per frame data provided by the USRP2
FPGA.
+ *
+ * \p items points to the raw sample data received off of the ethernet.
The data is
+ * packed into big-endian 32-bit unsigned ints for transport, but the
actual format
+ * of the data is dependent on the current configuration of the USRP2.
The most common
+ * format is 16-bit I & Q, with I in the top of the 32-bit word.
+ *
+ * \returns true if the object wants to be called again with new data;
+ * false if no additional data is wanted.
+ */
+ virtual bool operator()(const uint32_t *items, size_t nitems, const
rx_metadata *metadata)
+ {
+ // printf("W0: %08x TS: %08x\n", metadata->word0, metadata->timestamp);
+ // printf("I0: %08x\n", items[0]);
+
+ d_nsamples += nitems;
+ d_nframes++;
+
+ return !has_finished_p();
+ }
+ };
+
+ rx_nop_handler::~rx_nop_handler()
+ {
+ // nop
+ }
+
+} /* namespace usrp2 */
+
+#endif /* INCLUDED_RX_NOP_HANDLER */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9461 - in usrp2/trunk/host: apps include/usrp2,
jcorgan <=