GNU Radio 3.5.1 C++ API
gr_uhd_usrp_source.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010-2011 Free Software Foundation, Inc.
00003  * 
00004  * This file is part of GNU Radio
00005  * 
00006  * GNU Radio is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 3, or (at your option)
00009  * any later version.
00010  * 
00011  * GNU Radio is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with GNU Radio; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street,
00019  * Boston, MA 02110-1301, USA.
00020  */
00021 
00022 #ifndef INCLUDED_GR_UHD_USRP_SOURCE_H
00023 #define INCLUDED_GR_UHD_USRP_SOURCE_H
00024 
00025 #include <gr_uhd_api.h>
00026 #include <gr_sync_block.h>
00027 #include <uhd/usrp/multi_usrp.hpp>
00028 
00029 #ifndef INCLUDED_UHD_STREAM_HPP
00030 namespace uhd{
00031     struct GR_UHD_API stream_args_t{
00032         stream_args_t(
00033             const std::string &cpu = "",
00034             const std::string &otw = ""
00035         ){
00036             cpu_format = cpu;
00037             otw_format = otw;
00038         }
00039         std::string cpu_format;
00040         std::string otw_format;
00041         device_addr_t args;
00042         std::vector<size_t> channels;
00043     };
00044 }
00045 #  define INCLUDED_UHD_STREAM_HPP
00046 #else
00047 #  define GR_UHD_USE_STREAM_API
00048 #endif
00049 
00050 class uhd_usrp_source;
00051 
00052 /*!
00053  * \brief Make a new USRP source block.
00054  * \ingroup uhd_blk
00055  *
00056  * The USRP source block receives samples and writes to a stream.
00057  * The source block also provides API calls for receiver settings.
00058  *
00059  * RX Stream tagging:
00060  *
00061  * The following tag keys will be produced by the work function:
00062  *  - pmt::pmt_string_to_symbol("rx_time")
00063  *
00064  * The timstamp tag value is a pmt tuple of the following:
00065  * (uint64 seconds, and double fractional seconds).
00066  * A timestamp tag is produced at start() and after overflows.
00067  *
00068  * See the UHD manual for more detailed documentation:
00069  * http://code.ettus.com/redmine/ettus/projects/uhd/wiki
00070  *
00071  * \param device_addr the address to identify the hardware
00072  * \param io_type the desired output data type
00073  * \param num_channels number of stream from the device
00074  * \return a new USRP source block object
00075  */
00076 GR_UHD_API boost::shared_ptr<uhd_usrp_source> uhd_make_usrp_source(
00077     const uhd::device_addr_t &device_addr,
00078     const uhd::io_type_t &io_type,
00079     size_t num_channels
00080 );
00081 
00082 /*!
00083  * \brief Make a new USRP source block.
00084  *
00085  * The USRP source block receives samples and writes to a stream.
00086  * The source block also provides API calls for receiver settings.
00087  *
00088  * RX Stream tagging:
00089  *
00090  * The following tag keys will be produced by the work function:
00091  *  - pmt::pmt_string_to_symbol("rx_time")
00092  *
00093  * The timstamp tag value is a pmt tuple of the following:
00094  * (uint64 seconds, and double fractional seconds).
00095  * A timestamp tag is produced at start() and after overflows.
00096  *
00097  * See the UHD manual for more detailed documentation:
00098  * http://code.ettus.com/redmine/ettus/projects/uhd/wiki
00099  *
00100  * \param device_addr the address to identify the hardware
00101  * \param stream_args the IO format and channel specification
00102  * \return a new USRP source block object
00103  */
00104 GR_UHD_API boost::shared_ptr<uhd_usrp_source> uhd_make_usrp_source(
00105     const uhd::device_addr_t &device_addr,
00106     const uhd::stream_args_t &stream_args
00107 );
00108 
00109 class GR_UHD_API uhd_usrp_source : virtual public gr_sync_block{
00110 public:
00111 
00112     /*!
00113      * Set the frontend specification.
00114      * \param spec the subdev spec markup string
00115      * \param mboard the motherboard index 0 to M-1
00116      */
00117     virtual void set_subdev_spec(const std::string &spec, size_t mboard = 0) = 0;
00118 
00119     /*!
00120      * Set the sample rate for the usrp device.
00121      * \param rate a new rate in Sps
00122      */
00123     virtual void set_samp_rate(double rate) = 0;
00124 
00125     /*!
00126      * Get the sample rate for the usrp device.
00127      * This is the actual sample rate and may differ from the rate set.
00128      * \return the actual rate in Sps
00129      */
00130     virtual double get_samp_rate(void) = 0;
00131 
00132     /*!
00133      * Get the possible sample rates for the usrp device.
00134      * \return a range of rates in Sps
00135      */
00136     virtual uhd::meta_range_t get_samp_rates(void) = 0;
00137 
00138     /*!
00139      * Tune the usrp device to the desired center frequency.
00140      * \param tune_request the tune request instructions
00141      * \param chan the channel index 0 to N-1
00142      * \return a tune result with the actual frequencies
00143      */
00144     virtual uhd::tune_result_t set_center_freq(
00145         const uhd::tune_request_t tune_request, size_t chan = 0
00146     ) = 0;
00147 
00148     /*!
00149      * Tune the usrp device to the desired center frequency.
00150      * This is a wrapper around set center freq so that in this case,
00151      * the user can pass a single frequency in the call through swig.
00152      * \param freq the desired frequency in Hz
00153      * \param chan the channel index 0 to N-1
00154      * \return a tune result with the actual frequencies
00155      */
00156     uhd::tune_result_t set_center_freq(double freq, size_t chan = 0){
00157         return set_center_freq(uhd::tune_request_t(freq), chan);
00158     }
00159 
00160     /*!
00161      * Get the center frequency.
00162      * \param chan the channel index 0 to N-1
00163      * \return the frequency in Hz
00164      */
00165     virtual double get_center_freq(size_t chan = 0) = 0;
00166 
00167     /*!
00168      * Get the tunable frequency range.
00169      * \param chan the channel index 0 to N-1
00170      * \return the frequency range in Hz
00171      */
00172     virtual uhd::freq_range_t get_freq_range(size_t chan = 0) = 0;
00173 
00174     /*!
00175      * Set the gain for the dboard.
00176      * \param gain the gain in dB
00177      * \param chan the channel index 0 to N-1
00178      */
00179     virtual void set_gain(double gain, size_t chan = 0) = 0;
00180 
00181     /*!
00182      * Set the named gain on the dboard.
00183      * \param gain the gain in dB
00184      * \param name the name of the gain stage
00185      * \param chan the channel index 0 to N-1
00186      */
00187     virtual void set_gain(double gain, const std::string &name, size_t chan = 0) = 0;
00188 
00189     /*!
00190      * Get the actual dboard gain setting.
00191      * \param chan the channel index 0 to N-1
00192      * \return the actual gain in dB
00193      */
00194     virtual double get_gain(size_t chan = 0) = 0;
00195 
00196     /*!
00197      * Get the actual dboard gain setting of named stage.
00198      * \param name the name of the gain stage
00199      * \param chan the channel index 0 to N-1
00200      * \return the actual gain in dB
00201      */
00202     virtual double get_gain(const std::string &name, size_t chan = 0) = 0;
00203 
00204     /*!
00205      * Get the actual dboard gain setting of named stage.
00206      * \param chan the channel index 0 to N-1
00207      * \return the actual gain in dB
00208      */
00209     virtual std::vector<std::string> get_gain_names(size_t chan = 0) = 0;
00210 
00211     /*!
00212      * Get the settable gain range.
00213      * \param chan the channel index 0 to N-1
00214      * \return the gain range in dB
00215      */
00216     virtual uhd::gain_range_t get_gain_range(size_t chan = 0) = 0;
00217 
00218     /*!
00219      * Get the settable gain range.
00220      * \param name the name of the gain stage
00221      * \param chan the channel index 0 to N-1
00222      * \return the gain range in dB
00223      */
00224     virtual uhd::gain_range_t get_gain_range(const std::string &name, size_t chan = 0) = 0;
00225 
00226     /*!
00227      * Set the antenna to use.
00228      * \param ant the antenna string
00229      * \param chan the channel index 0 to N-1
00230      */
00231     virtual void set_antenna(const std::string &ant, size_t chan = 0) = 0;
00232 
00233     /*!
00234      * Get the antenna in use.
00235      * \param chan the channel index 0 to N-1
00236      * \return the antenna string
00237      */
00238     virtual std::string get_antenna(size_t chan = 0) = 0;
00239 
00240     /*!
00241      * Get a list of possible antennas.
00242      * \param chan the channel index 0 to N-1
00243      * \return a vector of antenna strings
00244      */
00245     virtual std::vector<std::string> get_antennas(size_t chan = 0) = 0;
00246 
00247     /*!
00248      * Set the bandpass filter on the RF frontend.
00249      * \param bandwidth the filter bandwidth in Hz
00250      * \param chan the channel index 0 to N-1
00251      */
00252     virtual void set_bandwidth(double bandwidth, size_t chan = 0) = 0;
00253 
00254     /*!
00255      * Enable/disable the automatic DC offset correction.
00256      * The automatic correction subtracts out the long-run average.
00257      *
00258      * When disabled, the averaging option operation is halted.
00259      * Once halted, the average value will be held constant
00260      * until the user re-enables the automatic correction
00261      * or overrides the value by manually setting the offset.
00262      *
00263      * \param enb true to enable automatic DC offset correction
00264      * \param chan the channel index 0 to N-1
00265      */
00266     virtual void set_dc_offset(const bool enb, size_t chan = 0) = 0;
00267 
00268     /*!
00269      * Set a constant DC offset value.
00270      * The value is complex to control both I and Q.
00271      * Only set this when automatic correction is disabled.
00272      * \param offset the dc offset (1.0 is full-scale)
00273      * \param chan the channel index 0 to N-1
00274      */
00275     virtual void set_dc_offset(const std::complex<double> &offset, size_t chan = 0) = 0;
00276 
00277     /*!
00278      * Set the RX frontend IQ imbalance correction.
00279      * Use this to adjust the magnitude and phase of I and Q.
00280      *
00281      * \param correction the complex correction value
00282      * \param chan the channel index 0 to N-1
00283      */
00284     virtual void set_iq_balance(const std::complex<double> &correction, size_t chan = 0) = 0;
00285 
00286     /*!
00287      * Get a RF frontend sensor value.
00288      * \param name the name of the sensor
00289      * \param chan the channel index 0 to N-1
00290      * \return a sensor value object
00291      */
00292     virtual uhd::sensor_value_t get_sensor(const std::string &name, size_t chan = 0) = 0;
00293 
00294     /*!
00295      * Get a list of possible RF frontend sensor names.
00296      * \param chan the channel index 0 to N-1
00297      * \return a vector of sensor names
00298      */
00299     virtual std::vector<std::string> get_sensor_names(size_t chan = 0) = 0;
00300 
00301     //! DEPRECATED use get_sensor
00302     uhd::sensor_value_t get_dboard_sensor(const std::string &name, size_t chan = 0){
00303         return this->get_sensor(name, chan);
00304     }
00305 
00306     //! DEPRECATED use get_sensor_names
00307     std::vector<std::string> get_dboard_sensor_names(size_t chan = 0){
00308         return this->get_sensor_names(chan);
00309     }
00310 
00311     /*!
00312      * Get a motherboard sensor value.
00313      * \param name the name of the sensor
00314      * \param mboard the motherboard index 0 to M-1
00315      * \return a sensor value object
00316      */
00317     virtual uhd::sensor_value_t get_mboard_sensor(const std::string &name, size_t mboard = 0) = 0;
00318 
00319     /*!
00320      * Get a list of possible motherboard sensor names.
00321      * \param mboard the motherboard index 0 to M-1
00322      * \return a vector of sensor names
00323      */
00324     virtual std::vector<std::string> get_mboard_sensor_names(size_t mboard = 0) = 0;
00325 
00326     /*!
00327      * Set the clock configuration.
00328      * DEPRECATED for set_time/clock_source.
00329      * \param clock_config the new configuration
00330      * \param mboard the motherboard index 0 to M-1
00331      */
00332     virtual void set_clock_config(const uhd::clock_config_t &clock_config, size_t mboard = 0) = 0;
00333 
00334      /*!
00335      * Set the time source for the usrp device.
00336      * This sets the method of time synchronization,
00337      * typically a pulse per second or an encoded time.
00338      * Typical options for source: external, MIMO.
00339      * \param source a string representing the time source
00340      * \param mboard which motherboard to set the config
00341      */
00342     virtual void set_time_source(const std::string &source, const size_t mboard = 0) = 0;
00343 
00344     /*!
00345      * Get the currently set time source.
00346      * \param mboard which motherboard to get the config
00347      * \return the string representing the time source
00348      */
00349     virtual std::string get_time_source(const size_t mboard) = 0;
00350 
00351     /*!
00352      * Get a list of possible time sources.
00353      * \param mboard which motherboard to get the list
00354      * \return a vector of strings for possible settings
00355      */
00356     virtual std::vector<std::string> get_time_sources(const size_t mboard) = 0;
00357 
00358     /*!
00359      * Set the clock source for the usrp device.
00360      * This sets the source for a 10 Mhz reference clock.
00361      * Typical options for source: internal, external, MIMO.
00362      * \param source a string representing the clock source
00363      * \param mboard which motherboard to set the config
00364      */
00365     virtual void set_clock_source(const std::string &source, const size_t mboard = 0) = 0;
00366 
00367     /*!
00368      * Get the currently set clock source.
00369      * \param mboard which motherboard to get the config
00370      * \return the string representing the clock source
00371      */
00372     virtual std::string get_clock_source(const size_t mboard) = 0;
00373 
00374     /*!
00375      * Get a list of possible clock sources.
00376      * \param mboard which motherboard to get the list
00377      * \return a vector of strings for possible settings
00378      */
00379     virtual std::vector<std::string> get_clock_sources(const size_t mboard) = 0;
00380 
00381     /*!
00382      * Get the master clock rate.
00383      * \param mboard the motherboard index 0 to M-1
00384      * \return the clock rate in Hz
00385      */
00386     virtual double get_clock_rate(size_t mboard = 0) = 0;
00387 
00388     /*!
00389      * Set the master clock rate.
00390      * \param rate the new rate in Hz
00391      * \param mboard the motherboard index 0 to M-1
00392      */
00393     virtual void set_clock_rate(double rate, size_t mboard = 0) = 0;
00394 
00395     /*!
00396      * Get the current time registers.
00397      * \param mboard the motherboard index 0 to M-1
00398      * \return the current usrp time
00399      */
00400     virtual uhd::time_spec_t get_time_now(size_t mboard = 0) = 0;
00401 
00402     /*!
00403      * Get the time when the last pps pulse occured.
00404      * \param mboard the motherboard index 0 to M-1
00405      * \return the current usrp time
00406      */
00407     virtual uhd::time_spec_t get_time_last_pps(size_t mboard = 0) = 0;
00408 
00409     /*!
00410      * Sets the time registers immediately.
00411      * \param time_spec the new time
00412      * \param mboard the motherboard index 0 to M-1
00413      */
00414     virtual void set_time_now(const uhd::time_spec_t &time_spec, size_t mboard = 0) = 0;
00415 
00416     /*!
00417      * Set the time registers at the next pps.
00418      * \param time_spec the new time
00419      */
00420     virtual void set_time_next_pps(const uhd::time_spec_t &time_spec) = 0;
00421 
00422     /*!
00423      * Sync the time registers with an unknown pps edge.
00424      * \param time_spec the new time
00425      */
00426     virtual void set_time_unknown_pps(const uhd::time_spec_t &time_spec) = 0;
00427 
00428     /*!
00429      * Set the time at which the control commands will take effect.
00430      *
00431      * A timed command will back-pressure all subsequent timed commands,
00432      * assuming that the subsequent commands occur within the time-window.
00433      * If the time spec is late, the command will be activated upon arrival.
00434      *
00435      * \param time_spec the time at which the next command will activate
00436      * \param mboard which motherboard to set the config
00437      */
00438     virtual void set_command_time(const uhd::time_spec_t &time_spec, size_t mboard = 0) = 0;
00439 
00440     /*!
00441      * Clear the command time so future commands are sent ASAP.
00442      *
00443      * \param mboard which motherboard to set the config
00444      */
00445     virtual void clear_command_time(size_t mboard = 0) = 0;
00446 
00447     /*!
00448      * Get access to the underlying uhd dboard iface object.
00449      * \return the dboard_iface object
00450      */
00451     virtual uhd::usrp::dboard_iface::sptr get_dboard_iface(size_t chan = 0) = 0;
00452 
00453     /*!
00454      * Get access to the underlying uhd device object.
00455      * \return the multi usrp device object
00456      */
00457     virtual uhd::usrp::multi_usrp::sptr get_device(void) = 0;
00458 
00459     /*!
00460      * Convenience function for finite data acquisition.
00461      * This is not to be used with the scheduler; rather,
00462      * one can request samples from the USRP in python.
00463      * //TODO multi-channel
00464      * //TODO assumes fc32
00465      */
00466     virtual std::vector<std::complex<float> > finite_acquisition(const size_t nsamps) = 0;
00467 };
00468 
00469 #endif /* INCLUDED_GR_UHD_USRP_SOURCE_H */