GNU Radio 3.6.5 C++ API

gr_uhd_usrp_sink.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2010-2012 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_SINK_H
00023 #define INCLUDED_GR_UHD_USRP_SINK_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_sink;
00051 
00052 /*!
00053  * \brief Make a new USRP sink block.
00054  * \ingroup uhd_blk
00055  *
00056  * The USRP sink block reads a stream and transmits the samples.
00057  * The sink block also provides API calls for transmitter settings.
00058  *
00059  * TX Stream tagging:
00060  *
00061  * The following tag keys will be consumed by the work function:
00062  *  - pmt::pmt_string_to_symbol("tx_sob")
00063  *  - pmt::pmt_string_to_symbol("tx_eob")
00064  *  - pmt::pmt_string_to_symbol("tx_time")
00065  *
00066  * The sob and eob (start and end of burst) tag values are pmt booleans.
00067  * When present, burst tags should be set to true (pmt::PMT_T).
00068  *
00069  * The timstamp tag value is a pmt tuple of the following:
00070  * (uint64 seconds, and double fractional seconds).
00071  *
00072  * See the UHD manual for more detailed documentation:
00073  * http://code.ettus.com/redmine/ettus/projects/uhd/wiki
00074  *
00075  * \param device_addr the address to identify the hardware
00076  * \param io_type the desired input data type
00077  * \param num_channels number of stream from the device
00078  * \return a new USRP sink block object
00079  */
00080 GR_UHD_API boost::shared_ptr<uhd_usrp_sink> uhd_make_usrp_sink(
00081     const uhd::device_addr_t &device_addr,
00082     const uhd::io_type_t &io_type,
00083     size_t num_channels
00084 );
00085 
00086 /*!
00087  * \brief Make a new USRP sink block.
00088  *
00089  * The USRP sink block reads a stream and transmits the samples.
00090  * The sink block also provides API calls for transmitter settings.
00091  *
00092  * TX Stream tagging:
00093  *
00094  * The following tag keys will be consumed by the work function:
00095  *  - pmt::pmt_string_to_symbol("tx_sob")
00096  *  - pmt::pmt_string_to_symbol("tx_eob")
00097  *  - pmt::pmt_string_to_symbol("tx_time")
00098  *
00099  * The sob and eob (start and end of burst) tag values are pmt booleans.
00100  * When present, burst tags should be set to true (pmt::PMT_T).
00101  *
00102  * The timstamp tag value is a pmt tuple of the following:
00103  * (uint64 seconds, and double fractional seconds).
00104  *
00105  * See the UHD manual for more detailed documentation:
00106  * http://code.ettus.com/redmine/ettus/projects/uhd/wiki
00107  *
00108  * \param device_addr the address to identify the hardware
00109  * \param stream_args the IO format and channel specification
00110  * \return a new USRP sink block object
00111  */
00112 GR_UHD_API boost::shared_ptr<uhd_usrp_sink> uhd_make_usrp_sink(
00113     const uhd::device_addr_t &device_addr,
00114     const uhd::stream_args_t &stream_args
00115 );
00116 
00117 class GR_UHD_API uhd_usrp_sink : virtual public gr_sync_block{
00118 public:
00119 
00120     /*!
00121      * Set the start time for outgoing samples.
00122      * To control when samples are transmitted,
00123      * set this value before starting the flow graph.
00124      * The value is cleared after each run.
00125      * When not specified, the start time will be:
00126      *  - Immediately for the one channel case
00127      *  - in the near future for multi-channel
00128      *
00129      * \param time the absolute time for transmission to begin
00130      */
00131     virtual void set_start_time(const uhd::time_spec_t &time) = 0;
00132 
00133     /*!
00134      * Returns identifying information about this USRP's configuration.
00135      * Returns motherboard ID, name, and serial.
00136      * Returns daughterboard TX ID, subdev name and spec, serial, and antenna.
00137      * \param chan channel index 0 to N-1
00138      * \return TX info
00139      */
00140     virtual uhd::dict<std::string, std::string> get_usrp_info(size_t chan = 0) = 0;
00141 
00142     /*!
00143      * Set the frontend specification.
00144      * \param spec the subdev spec markup string
00145      * \param mboard the motherboard index 0 to M-1
00146      */
00147     virtual void set_subdev_spec(const std::string &spec, size_t mboard = 0) = 0;
00148 
00149 
00150      /*!
00151      * Get the TX frontend specification.
00152      * \param mboard the motherboard index 0 to M-1
00153      * \return the frontend specification in use
00154      */
00155     virtual std::string get_subdev_spec (size_t mboard = 0) = 0;
00156 
00157     /*!
00158      * Set the sample rate for the usrp device.
00159      * \param rate a new rate in Sps
00160      */
00161     virtual void set_samp_rate(double rate) = 0;
00162 
00163     /*!
00164      * Get the sample rate for the usrp device.
00165      * This is the actual sample rate and may differ from the rate set.
00166      * \return the actual rate in Sps
00167      */
00168     virtual double get_samp_rate(void) = 0;
00169 
00170     /*!
00171      * Get the possible sample rates for the usrp device.
00172      * \return a range of rates in Sps
00173      */
00174     virtual uhd::meta_range_t get_samp_rates(void) = 0;
00175 
00176     /*!
00177      * Tune the usrp device to the desired center frequency.
00178      * \param tune_request the tune request instructions
00179      * \param chan the channel index 0 to N-1
00180      * \return a tune result with the actual frequencies
00181      */
00182     virtual uhd::tune_result_t set_center_freq(
00183         const uhd::tune_request_t tune_request, size_t chan = 0
00184     ) = 0;
00185 
00186     /*!
00187      * Tune the usrp device to the desired center frequency.
00188      * This is a wrapper around set center freq so that in this case,
00189      * the user can pass a single frequency in the call through swig.
00190      * \param freq the desired frequency in Hz
00191      * \param chan the channel index 0 to N-1
00192      * \return a tune result with the actual frequencies
00193      */
00194     uhd::tune_result_t set_center_freq(double freq, size_t chan = 0){
00195         return set_center_freq(uhd::tune_request_t(freq), chan);
00196     }
00197 
00198     /*!
00199      * Get the center frequency.
00200      * \param chan the channel index 0 to N-1
00201      * \return the frequency in Hz
00202      */
00203     virtual double get_center_freq(size_t chan = 0) = 0;
00204 
00205     /*!
00206      * Get the tunable frequency range.
00207      * \param chan the channel index 0 to N-1
00208      * \return the frequency range in Hz
00209      */
00210     virtual uhd::freq_range_t get_freq_range(size_t chan = 0) = 0;
00211 
00212     /*!
00213      * Set the gain for the dboard.
00214      * \param gain the gain in dB
00215      * \param chan the channel index 0 to N-1
00216      */
00217     virtual void set_gain(double gain, size_t chan = 0) = 0;
00218 
00219     /*!
00220      * Set the named gain on the dboard.
00221      * \param gain the gain in dB
00222      * \param name the name of the gain stage
00223      * \param chan the channel index 0 to N-1
00224      */
00225     virtual void set_gain(double gain, const std::string &name, size_t chan = 0) = 0;
00226 
00227     /*!
00228      * Get the actual dboard gain setting.
00229      * \param chan the channel index 0 to N-1
00230      * \return the actual gain in dB
00231      */
00232     virtual double get_gain(size_t chan = 0) = 0;
00233 
00234     /*!
00235      * Get the actual dboard gain setting of named stage.
00236      * \param name the name of the gain stage
00237      * \param chan the channel index 0 to N-1
00238      * \return the actual gain in dB
00239      */
00240     virtual double get_gain(const std::string &name, size_t chan = 0) = 0;
00241 
00242     /*!
00243      * Get the actual dboard gain setting of named stage.
00244      * \param chan the channel index 0 to N-1
00245      * \return the actual gain in dB
00246      */
00247     virtual std::vector<std::string> get_gain_names(size_t chan = 0) = 0;
00248 
00249     /*!
00250      * Get the settable gain range.
00251      * \param chan the channel index 0 to N-1
00252      * \return the gain range in dB
00253      */
00254     virtual uhd::gain_range_t get_gain_range(size_t chan = 0) = 0;
00255 
00256     /*!
00257      * Get the settable gain range.
00258      * \param name the name of the gain stage
00259      * \param chan the channel index 0 to N-1
00260      * \return the gain range in dB
00261      */
00262     virtual uhd::gain_range_t get_gain_range(const std::string &name, size_t chan = 0) = 0;
00263 
00264     /*!
00265      * Set the antenna to use.
00266      * \param ant the antenna string
00267      * \param chan the channel index 0 to N-1
00268      */
00269     virtual void set_antenna(const std::string &ant, size_t chan = 0) = 0;
00270 
00271     /*!
00272      * Get the antenna in use.
00273      * \param chan the channel index 0 to N-1
00274      * \return the antenna string
00275      */
00276     virtual std::string get_antenna(size_t chan = 0) = 0;
00277 
00278     /*!
00279      * Get a list of possible antennas.
00280      * \param chan the channel index 0 to N-1
00281      * \return a vector of antenna strings
00282      */
00283     virtual std::vector<std::string> get_antennas(size_t chan = 0) = 0;
00284 
00285     /*!
00286      * Set the bandpass filter on the RF frontend.
00287      * \param chan the channel index 0 to N-1
00288      * \param bandwidth the filter bandwidth in Hz
00289      */
00290     virtual void set_bandwidth(double bandwidth, size_t chan = 0) = 0;
00291 
00292     /*!
00293      * Get the bandpass filter setting on the RF frontend.
00294      * \param chan the channel index 0 to N-1
00295      * \return bandwidth of the filter in Hz
00296      */
00297     virtual double get_bandwidth(size_t chan = 0) = 0;
00298 
00299     /*!
00300      * Get the bandpass filter range of the RF frontend.
00301      * \param chan the channel index 0 to N-1
00302      * \return the range of the filter bandwidth in Hz
00303      */
00304     virtual uhd::freq_range_t get_bandwidth_range(size_t chan = 0) = 0;
00305 
00306     /*!
00307      * Set a constant DC offset value.
00308      * The value is complex to control both I and Q.
00309      * \param offset the dc offset (1.0 is full-scale)
00310      * \param chan the channel index 0 to N-1
00311      */
00312     virtual void set_dc_offset(const std::complex<double> &offset, size_t chan = 0) = 0;
00313 
00314     /*!
00315      * Set the RX frontend IQ imbalance correction.
00316      * Use this to adjust the magnitude and phase of I and Q.
00317      *
00318      * \param correction the complex correction (1.0 is full-scale)
00319      * \param chan the channel index 0 to N-1
00320      */
00321     virtual void set_iq_balance(const std::complex<double> &correction, size_t chan = 0) = 0;
00322 
00323     /*!
00324      * Get an RF frontend sensor value.
00325      * \param name the name of the sensor
00326      * \param chan the channel index 0 to N-1
00327      * \return a sensor value object
00328      */
00329     virtual uhd::sensor_value_t get_sensor(const std::string &name, size_t chan = 0) = 0;
00330 
00331     /*!
00332      * Get a list of possible RF frontend sensor names.
00333      * \param chan the channel index 0 to N-1
00334      * \return a vector of sensor names
00335      */
00336     virtual std::vector<std::string> get_sensor_names(size_t chan = 0) = 0;
00337 
00338     //! DEPRECATED use get_sensor
00339     uhd::sensor_value_t get_dboard_sensor(const std::string &name, size_t chan = 0){
00340         return this->get_sensor(name, chan);
00341     }
00342 
00343     //! DEPRECATED use get_sensor_names
00344     std::vector<std::string> get_dboard_sensor_names(size_t chan = 0){
00345         return this->get_sensor_names(chan);
00346     }
00347 
00348     /*!
00349      * Get a motherboard sensor value.
00350      * \param name the name of the sensor
00351      * \param mboard the motherboard index 0 to M-1
00352      * \return a sensor value object
00353      */
00354     virtual uhd::sensor_value_t get_mboard_sensor(const std::string &name, size_t mboard = 0) = 0;
00355 
00356     /*!
00357      * Get a list of possible motherboard sensor names.
00358      * \param mboard the motherboard index 0 to M-1
00359      * \return a vector of sensor names
00360      */
00361     virtual std::vector<std::string> get_mboard_sensor_names(size_t mboard = 0) = 0;
00362 
00363     /*!
00364      * Set the clock configuration.
00365      * DEPRECATED for set_time/clock_source.
00366      * \param clock_config the new configuration
00367      * \param mboard the motherboard index 0 to M-1
00368      */
00369     virtual void set_clock_config(const uhd::clock_config_t &clock_config, size_t mboard = 0) = 0;
00370 
00371     /*!
00372      * Set the time source for the usrp device.
00373      * This sets the method of time synchronization,
00374      * typically a pulse per second or an encoded time.
00375      * Typical options for source: external, MIMO.
00376      * \param source a string representing the time source
00377      * \param mboard which motherboard to set the config
00378      */
00379     virtual void set_time_source(const std::string &source, const size_t mboard = 0) = 0;
00380 
00381     /*!
00382      * Get the currently set time source.
00383      * \param mboard which motherboard to get the config
00384      * \return the string representing the time source
00385      */
00386     virtual std::string get_time_source(const size_t mboard) = 0;
00387 
00388     /*!
00389      * Get a list of possible time sources.
00390      * \param mboard which motherboard to get the list
00391      * \return a vector of strings for possible settings
00392      */
00393     virtual std::vector<std::string> get_time_sources(const size_t mboard) = 0;
00394 
00395     /*!
00396      * Set the clock source for the usrp device.
00397      * This sets the source for a 10 Mhz reference clock.
00398      * Typical options for source: internal, external, MIMO.
00399      * \param source a string representing the clock source
00400      * \param mboard which motherboard to set the config
00401      */
00402     virtual void set_clock_source(const std::string &source, const size_t mboard = 0) = 0;
00403 
00404     /*!
00405      * Get the currently set clock source.
00406      * \param mboard which motherboard to get the config
00407      * \return the string representing the clock source
00408      */
00409     virtual std::string get_clock_source(const size_t mboard) = 0;
00410 
00411     /*!
00412      * Get a list of possible clock sources.
00413      * \param mboard which motherboard to get the list
00414      * \return a vector of strings for possible settings
00415      */
00416     virtual std::vector<std::string> get_clock_sources(const size_t mboard) = 0;
00417 
00418     /*!
00419      * Get the master clock rate.
00420      * \param mboard the motherboard index 0 to M-1
00421      * \return the clock rate in Hz
00422      */
00423     virtual double get_clock_rate(size_t mboard = 0) = 0;
00424 
00425     /*!
00426      * Set the master clock rate.
00427      * \param rate the new rate in Hz
00428      * \param mboard the motherboard index 0 to M-1
00429      */
00430     virtual void set_clock_rate(double rate, size_t mboard = 0) = 0;
00431 
00432     /*!
00433      * Get the current time registers.
00434      * \param mboard the motherboard index 0 to M-1
00435      * \return the current usrp time
00436      */
00437     virtual uhd::time_spec_t get_time_now(size_t mboard = 0) = 0;
00438 
00439     /*!
00440      * Get the time when the last pps pulse occured.
00441      * \param mboard the motherboard index 0 to M-1
00442      * \return the current usrp time
00443      */
00444     virtual uhd::time_spec_t get_time_last_pps(size_t mboard = 0) = 0;
00445 
00446     /*!
00447      * Sets the time registers immediately.
00448      * \param time_spec the new time
00449      * \param mboard the motherboard index 0 to M-1
00450      */
00451     virtual void set_time_now(const uhd::time_spec_t &time_spec, size_t mboard = 0) = 0;
00452 
00453     /*!
00454      * Set the time registers at the next pps.
00455      * \param time_spec the new time
00456      */
00457     virtual void set_time_next_pps(const uhd::time_spec_t &time_spec) = 0;
00458 
00459     /*!
00460      * Sync the time registers with an unknown pps edge.
00461      * \param time_spec the new time
00462      */
00463     virtual void set_time_unknown_pps(const uhd::time_spec_t &time_spec) = 0;
00464 
00465     /*!
00466      * Set the time at which the control commands will take effect.
00467      *
00468      * A timed command will back-pressure all subsequent timed commands,
00469      * assuming that the subsequent commands occur within the time-window.
00470      * If the time spec is late, the command will be activated upon arrival.
00471      *
00472      * \param time_spec the time at which the next command will activate
00473      * \param mboard which motherboard to set the config
00474      */
00475     virtual void set_command_time(const uhd::time_spec_t &time_spec, size_t mboard = 0) = 0;
00476 
00477     /*!
00478      * Clear the command time so future commands are sent ASAP.
00479      *
00480      * \param mboard which motherboard to set the config
00481      */
00482     virtual void clear_command_time(size_t mboard = 0) = 0;
00483 
00484     /*!
00485      * Get access to the underlying uhd dboard iface object.
00486      * \return the dboard_iface object
00487      */
00488     virtual uhd::usrp::dboard_iface::sptr get_dboard_iface(size_t chan = 0) = 0;
00489 
00490     /*!
00491      * Get access to the underlying uhd device object.
00492      * \return the multi usrp device object
00493      */
00494     virtual uhd::usrp::multi_usrp::sptr get_device(void) = 0;
00495 
00496     /*!
00497      * Perform write on the user configuration register bus.  These only exist if
00498      * the user has implemented custom setting registers in the device FPGA.
00499      * \param addr 8-bit register address
00500      * \param data 32-bit register value
00501      * \param mboard which motherboard to set the user register
00502      */
00503     virtual void set_user_register(const uint8_t addr, const uint32_t data, size_t mboard = 0) = 0;
00504 };
00505 
00506 #endif /* INCLUDED_GR_UHD_USRP_SINK_H */