diff options
author | Josh Blum | 2010-04-14 12:16:43 -0700 |
---|---|---|
committer | Josh Blum | 2010-04-14 12:16:43 -0700 |
commit | b89d6edb60a069215d02fb78614c9dbfb46b4899 (patch) | |
tree | 914453edab4185d2867b904cab1a7218022bc8b9 | |
parent | 7dadb34647bddee0cbb36771370ea2318495e68d (diff) | |
download | gnuradio-b89d6edb60a069215d02fb78614c9dbfb46b4899.tar.gz gnuradio-b89d6edb60a069215d02fb78614c9dbfb46b4899.tar.bz2 gnuradio-b89d6edb60a069215d02fb78614c9dbfb46b4899.zip |
added more access methods to uhd source and sink
-rw-r--r-- | gr-uhd/lib/uhd_simple_sink.cc | 31 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_simple_sink.h | 57 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_simple_source.cc | 31 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_simple_source.h | 57 | ||||
-rw-r--r-- | gr-uhd/lib/utils.cc | 14 | ||||
-rw-r--r-- | gr-uhd/lib/utils.h | 2 |
6 files changed, 190 insertions, 2 deletions
diff --git a/gr-uhd/lib/uhd_simple_sink.cc b/gr-uhd/lib/uhd_simple_sink.cc index 107a4ef6c..bf2b02d31 100644 --- a/gr-uhd/lib/uhd_simple_sink.cc +++ b/gr-uhd/lib/uhd_simple_sink.cc @@ -57,7 +57,8 @@ uhd_simple_sink::~uhd_simple_sink(void){ } void uhd_simple_sink::set_samp_rate(double rate){ - return _dev->set_tx_rate(rate); + _dev->set_tx_rate(rate); + do_samp_rate_error_message(rate, get_samp_rate()); } double uhd_simple_sink::get_samp_rate(void){ @@ -68,6 +69,34 @@ uhd::tune_result_t uhd_simple_sink::set_center_freq(double freq){ return _dev->set_tx_freq(freq); } +uhd::freq_range_t uhd_simple_sink::get_freq_range(void){ + return _dev->get_tx_freq_range(); +} + +void uhd_simple_sink::set_gain(float gain){ + return _dev->set_tx_gain(gain); +} + +float uhd_simple_sink::get_gain(void){ + return _dev->get_tx_gain(); +} + +uhd::gain_range_t uhd_simple_sink::get_gain_range(void){ + return _dev->get_tx_gain_range(); +} + +void uhd_simple_sink::set_antenna(const std::string &ant){ + return _dev->set_tx_antenna(ant); +} + +std::string uhd_simple_sink::get_antenna(void){ + return _dev->get_tx_antenna(); +} + +std::vector<std::string> uhd_simple_sink::get_antennas(void){ + return _dev->get_tx_antennas(); +} + /*********************************************************************** * Work **********************************************************************/ diff --git a/gr-uhd/lib/uhd_simple_sink.h b/gr-uhd/lib/uhd_simple_sink.h index 735f72bdd..0229e38ca 100644 --- a/gr-uhd/lib/uhd_simple_sink.h +++ b/gr-uhd/lib/uhd_simple_sink.h @@ -36,11 +36,68 @@ public: uhd_simple_sink(const std::string &args, const uhd::io_type_t &type); ~uhd_simple_sink(void); + /*! + * Set the sample rate for the usrp device. + * \param rate a new rate in Sps + */ void set_samp_rate(double rate); + + /*! + * Get the sample rate for the usrp device. + * This is the actual sample rate and may differ from the rate set. + * \return the actual rate in Sps + */ double get_samp_rate(void); + /*! + * Tune the usrp device to the desired center frequency. + * \param freq the desired frequency in Hz + * \return a tune result with the actual frequencies + */ uhd::tune_result_t set_center_freq(double freq); + /*! + * Get the tunable frequency range. + * \return the frequency range in Hz + */ + uhd::freq_range_t get_freq_range(void); + + /*! + * Set the gain for the dboard. + * \param gain the gain in dB + */ + void set_gain(float gain); + + /*! + * Get the actual dboard gain setting. + * \return the actual gain in dB + */ + float get_gain(void); + + /*! + * Get the settable gain range. + * \return the gain range in dB + */ + uhd::gain_range_t get_gain_range(void); + + /*! + * Set the antenna to use. + * \param ant the antenna string + */ + void set_antenna(const std::string &ant); + + /*! + * Get the antenna in use. + * \return the antenna string + */ + std::string get_antenna(void); + + /*! + * Get a list of possible antennas. + * \return a vector of antenna strings + */ + std::vector<std::string> get_antennas(void); + int work( int noutput_items, gr_vector_const_void_star &input_items, diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index 85e7f8f37..e63fe9647 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -66,7 +66,8 @@ void uhd_simple_source::set_streaming(bool enb){ } void uhd_simple_source::set_samp_rate(double rate){ - return _dev->set_rx_rate(rate); + _dev->set_rx_rate(rate); + do_samp_rate_error_message(rate, get_samp_rate()); } double uhd_simple_source::get_samp_rate(void){ @@ -77,6 +78,34 @@ uhd::tune_result_t uhd_simple_source::set_center_freq(double freq){ return _dev->set_rx_freq(freq); } +uhd::freq_range_t uhd_simple_source::get_freq_range(void){ + return _dev->get_rx_freq_range(); +} + +void uhd_simple_source::set_gain(float gain){ + return _dev->set_rx_gain(gain); +} + +float uhd_simple_source::get_gain(void){ + return _dev->get_rx_gain(); +} + +uhd::gain_range_t uhd_simple_source::get_gain_range(void){ + return _dev->get_rx_gain_range(); +} + +void uhd_simple_source::set_antenna(const std::string &ant){ + return _dev->set_rx_antenna(ant); +} + +std::string uhd_simple_source::get_antenna(void){ + return _dev->get_rx_antenna(); +} + +std::vector<std::string> uhd_simple_source::get_antennas(void){ + return _dev->get_rx_antennas(); +} + /*********************************************************************** * Work **********************************************************************/ diff --git a/gr-uhd/lib/uhd_simple_source.h b/gr-uhd/lib/uhd_simple_source.h index c498c5715..7d286f09c 100644 --- a/gr-uhd/lib/uhd_simple_source.h +++ b/gr-uhd/lib/uhd_simple_source.h @@ -36,11 +36,68 @@ public: uhd_simple_source(const std::string &args, const uhd::io_type_t &type); ~uhd_simple_source(void); + /*! + * Set the sample rate for the usrp device. + * \param rate a new rate in Sps + */ void set_samp_rate(double rate); + + /*! + * Get the sample rate for the usrp device. + * This is the actual sample rate and may differ from the rate set. + * \return the actual rate in Sps + */ double get_samp_rate(void); + /*! + * Tune the usrp device to the desired center frequency. + * \param freq the desired frequency in Hz + * \return a tune result with the actual frequencies + */ uhd::tune_result_t set_center_freq(double freq); + /*! + * Get the tunable frequency range. + * \return the frequency range in Hz + */ + uhd::freq_range_t get_freq_range(void); + + /*! + * Set the gain for the dboard. + * \param gain the gain in dB + */ + void set_gain(float gain); + + /*! + * Get the actual dboard gain setting. + * \return the actual gain in dB + */ + float get_gain(void); + + /*! + * Get the settable gain range. + * \return the gain range in dB + */ + uhd::gain_range_t get_gain_range(void); + + /*! + * Set the antenna to use. + * \param ant the antenna string + */ + void set_antenna(const std::string &ant); + + /*! + * Get the antenna in use. + * \return the antenna string + */ + std::string get_antenna(void); + + /*! + * Get a list of possible antennas. + * \return a vector of antenna strings + */ + std::vector<std::string> get_antennas(void); + int work( int noutput_items, gr_vector_const_void_star &input_items, diff --git a/gr-uhd/lib/utils.cc b/gr-uhd/lib/utils.cc index e81241303..ddc36eb99 100644 --- a/gr-uhd/lib/utils.cc +++ b/gr-uhd/lib/utils.cc @@ -21,3 +21,17 @@ */ #include "utils.h" //local include +#include <boost/format.hpp> +#include <iostream> +#include <cmath> + +void do_samp_rate_error_message(double target_rate, double actual_rate){ + static const double max_allowed_error = 1.0; //Sps + if (std::abs(target_rate - actual_rate) > max_allowed_error){ + std::cerr << boost::format( + "The hardware does not support the requested sample rate:\n" + " Target sample rate: %f MSps\n" + " Actual sample rate: %f MSps\n" + ) % (target_rate/1e6) % (actual_rate/1e6) << std::endl; + } +} diff --git a/gr-uhd/lib/utils.h b/gr-uhd/lib/utils.h index 9e3acf571..cf349e5aa 100644 --- a/gr-uhd/lib/utils.h +++ b/gr-uhd/lib/utils.h @@ -23,4 +23,6 @@ #ifndef INCLUDED_NOINST_UTILS_H #define INCLUDED_NOINST_UTILS_H +void do_samp_rate_error_message(double target_rate, double actual_rate); + #endif /* INCLUDED_NOINST_UTILS_H */ |