diff options
author | Dimitri Stolnikov <horiz0n@gmx.net> | 2012-04-06 15:29:14 +0200 |
---|---|---|
committer | Dimitri Stolnikov <horiz0n@gmx.net> | 2012-04-06 15:29:14 +0200 |
commit | 0efd28de6bc86c3e474cfad70d1e5889575224a7 (patch) | |
tree | d3d12127a6315f026505629bec961d32696271e6 /include |
initial commit
Diffstat (limited to 'include')
-rw-r--r-- | include/osmosdr/CMakeLists.txt | 30 | ||||
-rw-r--r-- | include/osmosdr/osmosdr_api.h | 33 | ||||
-rw-r--r-- | include/osmosdr/osmosdr_pimpl.h | 54 | ||||
-rw-r--r-- | include/osmosdr/osmosdr_ranges.h | 120 | ||||
-rw-r--r-- | include/osmosdr/osmosdr_sink_c.h | 65 | ||||
-rw-r--r-- | include/osmosdr/osmosdr_source_c.h | 213 |
6 files changed, 515 insertions, 0 deletions
diff --git a/include/osmosdr/CMakeLists.txt b/include/osmosdr/CMakeLists.txt new file mode 100644 index 0000000..dd6a0de --- /dev/null +++ b/include/osmosdr/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright 2011 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio 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, +# 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 GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +######################################################################## +# Install public header files +######################################################################## +install(FILES + osmosdr_api.h + osmosdr_pimpl.h + osmosdr_ranges.h + osmosdr_source_c.h + osmosdr_sink_c.h + DESTINATION include/osmosdr +) diff --git a/include/osmosdr/osmosdr_api.h b/include/osmosdr/osmosdr_api.h new file mode 100644 index 0000000..d8a1c4c --- /dev/null +++ b/include/osmosdr/osmosdr_api.h @@ -0,0 +1,33 @@ +/* + * Copyright 2011 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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, + * 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_OSMOSDR_API_H +#define INCLUDED_OSMOSDR_API_H + +#include <gruel/attributes.h> + +#ifdef gnuradio_osmosdr_EXPORTS +# define OSMOSDR_API __GR_ATTR_EXPORT +#else +# define OSMOSDR_API __GR_ATTR_IMPORT +#endif + +#endif /* INCLUDED_OSMOSDR_API_H */ diff --git a/include/osmosdr/osmosdr_pimpl.h b/include/osmosdr/osmosdr_pimpl.h new file mode 100644 index 0000000..84808c7 --- /dev/null +++ b/include/osmosdr/osmosdr_pimpl.h @@ -0,0 +1,54 @@ +// +// Copyright 2010 Ettus Research LLC +// +// 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_OSMOSDR_PIMPL_H +#define INCLUDED_OSMOSDR_PIMPL_H + +#include <boost/shared_ptr.hpp> + +/*! \file pimpl.hpp + * "Pimpl idiom" (pointer to implementation idiom). + * The OSMOSDR_PIMPL_* macros simplify code overhead for declaring and making pimpls. + * + * Each pimpl is implemented as a shared pointer to the implementation: + * - The container class will not have to deallocate the pimpl. + * - The container class will use the pimpl as a regular pointer. + * - Usage: _impl->method(arg0, arg1) + * - Usage: _impl->member = value; + * + * \see http://en.wikipedia.org/wiki/Opaque_pointer + */ + +/*! + * Make a declaration for a pimpl in a header file. + * - Usage: OSMOSDR_PIMPL_DECL(impl) _impl; + * \param _name the name of the pimpl class + */ +#define OSMOSDR_PIMPL_DECL(_name) \ + struct _name; boost::shared_ptr<_name> + +/*! + * Make an instance of a pimpl in a source file. + * - Usage: _impl = OSMOSDR_PIMPL_MAKE(impl, ()); + * - Usage: _impl = OSMOSDR_PIMPL_MAKE(impl, (a0, a1)); + * \param _name the name of the pimpl class + * \param _args the constructor args for the pimpl + */ +#define OSMOSDR_PIMPL_MAKE(_name, _args) \ + boost::shared_ptr<_name>(new _name _args) + +#endif /* INCLUDED_OSMOSDR_PIMPL_H */ diff --git a/include/osmosdr/osmosdr_ranges.h b/include/osmosdr/osmosdr_ranges.h new file mode 100644 index 0000000..b7939df --- /dev/null +++ b/include/osmosdr/osmosdr_ranges.h @@ -0,0 +1,120 @@ +// +// Copyright 2010-2011 Ettus Research LLC +// +// 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_OSMOSDR_RANGES_H +#define INCLUDED_OSMOSDR_RANGES_H + +#include <osmosdr_api.h> +#include <osmosdr_pimpl.h> +#include <string> +#include <vector> + +namespace osmosdr{ + + /*! + * A range object describes a set of discrete values of the form: + * y = start + step*n, where n is an integer between 0 and (stop - start)/step + */ + class OSMOSDR_API range_t{ + public: + + /*! + * Create a range from a single value. + * The step size will be taken as zero. + * \param value the only possible value in this range + */ + range_t(double value = 0); + + /*! + * Create a range from a full set of values. + * A step size of zero implies infinite precision. + * \param start the minimum value for this range + * \param stop the maximum value for this range + * \param step the step size for this range + */ + range_t(double start, double stop, double step = 0); + + //! Get the start value for this range. + double start(void) const; + + //! Get the stop value for this range. + double stop(void) const; + + //! Get the step value for this range. + double step(void) const; + + //! Convert this range to a printable string + const std::string to_pp_string(void) const; + + private: OSMOSDR_PIMPL_DECL(impl) _impl; + }; + + /*! + * A meta-range object holds a list of individual ranges. + */ + struct OSMOSDR_API meta_range_t : std::vector<range_t>{ + + //! A default constructor for an empty meta-range + meta_range_t(void); + + /*! + * Input iterator constructor: + * Makes boost::assign::list_of work. + * \param first the begin iterator + * \param last the end iterator + */ + template <typename InputIterator> + meta_range_t(InputIterator first, InputIterator last): + std::vector<range_t>(first, last){ /* NOP */ } + + /*! + * A convenience constructor for a single range. + * A step size of zero implies infinite precision. + * \param start the minimum value for this range + * \param stop the maximum value for this range + * \param step the step size for this range + */ + meta_range_t(double start, double stop, double step = 0); + + //! Get the overall start value for this meta-range. + double start(void) const; + + //! Get the overall stop value for this meta-range. + double stop(void) const; + + //! Get the overall step value for this meta-range. + double step(void) const; + + /*! + * Clip the target value to a possible range value. + * \param value the value to clip to this range + * \param clip_step if true, clip to steps as well + * \return a value that is in one of the ranges + */ + double clip(double value, bool clip_step = false) const; + + //! Convert this meta-range to a printable string + const std::string to_pp_string(void) const; + + }; + + typedef meta_range_t gain_range_t; + typedef meta_range_t freq_range_t; + +} //namespace osmosdr + +#endif /* INCLUDED_OSMOSDR_RANGES_H */ diff --git a/include/osmosdr/osmosdr_sink_c.h b/include/osmosdr/osmosdr_sink_c.h new file mode 100644 index 0000000..41023ab --- /dev/null +++ b/include/osmosdr/osmosdr_sink_c.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2012 Dimitri Stolnikov <horiz0n@gmx.net> + * + * This file is part of GNU Radio + * + * GNU Radio 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, + * 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +#ifndef INCLUDED_OSMOSDR_SINK_C_H +#define INCLUDED_OSMOSDR_SINK_C_H + +#include <osmosdr_api.h> +#include <gr_hier_block2.h> + +class osmosdr_sink_c; + +/* + * We use boost::shared_ptr's instead of raw pointers for all access + * to gr_blocks (and many other data structures). The shared_ptr gets + * us transparent reference counting, which greatly simplifies storage + * management issues. This is especially helpful in our hybrid + * C++ / Python system. + * + * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm + * + * As a convention, the _sptr suffix indicates a boost::shared_ptr + */ +typedef boost::shared_ptr<osmosdr_sink_c> osmosdr_sink_c_sptr; + +/*! + * \brief Return a shared_ptr to a new instance of osmosdr_sink_c. + * + * To avoid accidental use of raw pointers, osmosdr_sink_c's + * constructor is private. osmosdr_make_sink_c is the public + * interface for creating new instances. + */ +OSMOSDR_API osmosdr_sink_c_sptr osmosdr_make_sink_c (const std::string & args = ""); + +/*! + * \brief Takes a stream of complex samples. + * \ingroup block + * + * This uses the preferred technique: subclassing gr_hier_block2. + */ +class OSMOSDR_API osmosdr_sink_c : virtual public gr_hier_block2 +{ +public: + +}; + +#endif /* INCLUDED_OSMOSDR_SINK_C_H */ diff --git a/include/osmosdr/osmosdr_source_c.h b/include/osmosdr/osmosdr_source_c.h new file mode 100644 index 0000000..e4bb6ca --- /dev/null +++ b/include/osmosdr/osmosdr_source_c.h @@ -0,0 +1,213 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2012 Dimitri Stolnikov <horiz0n@gmx.net> + * + * This file is part of GNU Radio + * + * GNU Radio 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, + * 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +#ifndef INCLUDED_OSMOSDR_SOURCE_C_H +#define INCLUDED_OSMOSDR_SOURCE_C_H + +#include <osmosdr_api.h> +#include <osmosdr_ranges.h> +#include <gr_hier_block2.h> + +class osmosdr_source_c; + +/* + * We use boost::shared_ptr's instead of raw pointers for all access + * to gr_blocks (and many other data structures). The shared_ptr gets + * us transparent reference counting, which greatly simplifies storage + * management issues. This is especially helpful in our hybrid + * C++ / Python system. + * + * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm + * + * As a convention, the _sptr suffix indicates a boost::shared_ptr + */ +typedef boost::shared_ptr<osmosdr_source_c> osmosdr_source_c_sptr; + +/*! + * \brief Return a shared_ptr to a new instance of osmosdr_source_c. + * + * To avoid accidental use of raw pointers, osmosdr_source_c's + * constructor is private. osmosdr_make_source_c is the public + * interface for creating new instances. + */ +OSMOSDR_API osmosdr_source_c_sptr osmosdr_make_source_c (const std::string & args = ""); + +/*! + * \brief Provides a stream of complex samples. + * \ingroup block + * + * \sa osmosdr_sink_c for a version that subclasses gr_hier_block2. + */ +class OSMOSDR_API osmosdr_source_c : virtual public gr_hier_block2 +{ +public: + /*! + * Get the possible sample rates for the OsmoSDR device. + * \return a range of rates in Sps + */ + virtual osmosdr::meta_range_t get_samp_rates( void ) = 0; + + /*! + * Set the sample rate for the OsmoSDR device. + * This also will select the appropriate IF bandpass, if applicable. + * \param rate a new rate in Sps + */ + virtual double set_samp_rate( double rate ) = 0; + + /*! + * Get the sample rate for the OsmoSDR device. + * This is the actual sample rate and may differ from the rate set. + * \return the actual rate in Sps + */ + virtual double get_samp_rate( void ) = 0; + + /*! + * Get the tunable frequency range. + * \return the frequency range in Hz + */ + virtual osmosdr::freq_range_t get_freq_range( size_t chan = 0 ) = 0; + + /*! + * Tune the OsmoSDR device to the desired center frequency. + * This also will select the appropriate RF bandpass. + * \param freq the desired frequency in Hz + * \return a tune result with the actual frequencies + */ + virtual double set_center_freq( double freq, size_t chan = 0 ) = 0; + + /*! + * Get the center frequency. + * \return the frequency in Hz + */ + virtual double get_center_freq( size_t chan = 0 ) = 0; + + /*! + * Set the frequency correction value in parts per million. + * \return correction value in parts per million + */ + virtual double set_freq_correction( double ppm, size_t chan = 0 ) = 0; + + /*! + * Get the frequency correction value. + * \return correction value in parts per million + */ + virtual double get_freq_correction( size_t chan = 0 ) = 0; + + /*! + * Get the actual OsmoSDR gain setting of named stage. + * \return the actual gain in dB + */ + virtual std::vector<std::string> get_gain_names( size_t chan = 0 ) = 0; + + /*! + * Get the settable gain range. + * \param name the name of the gain stage + * \return the gain range in dB + */ + virtual osmosdr::gain_range_t get_gain_range( const std::string & name = "", size_t chan = 0 ) = 0; + + /*! + * Set the gain for the OsmoSDR. + * \param gain the gain in dB + */ + virtual void set_gain( double gain, size_t chan = 0 ) = 0; + + /*! + * Set the named gain on the OsmoSDR. + * \param gain the gain in dB + * \param name the name of the gain stage + */ + virtual void set_gain( double gain, const std::string & name = "", size_t chan = 0 ) = 0; + + /*! + * Get the actual OsmoSDR gain setting of a named stage. + * \param name the name of the gain stage + * \return the actual gain in dB + */ + virtual double get_gain( const std::string & name = "", size_t chan = 0 ) = 0; + +#if 0 + + virtual std::vector< std::string > get_antennas( size_t chan = 0 ) = 0; + virtual std::string set_antenna( const std::string & antenna, size_t chan = 0 ) = 0; + virtual std::string get_antenna( size_t chan = 0 ) = 0; + + /*! + * Enable/disable the automatic DC offset correction. + * The automatic correction subtracts out the long-run average. + * + * When disabled, the averaging option operation is halted. + * Once halted, the average value will be held constant + * until the user re-enables the automatic correction + * or overrides the value by manually setting the offset. + * + * \param enb true to enable automatic DC offset correction + */ + virtual void set_dc_offset(const bool enb) = 0; + + /*! + * Set a constant DC offset value. + * The value is complex to control both I and Q. + * Only set this when automatic correction is disabled. + * \param offset the dc offset (1.0 is full-scale) + */ + virtual void set_dc_offset(const std::complex<double> &offset) = 0; + + /*! + * Set the RX frontend IQ imbalance correction. + * Use this to adjust the magnitude and phase of I and Q. + * + * \param correction the complex correction value + */ + virtual void set_iq_balance(const std::complex<double> &correction) = 0; + + /*! + * Get the master clock rate. + * \return the clock rate in Hz + */ + virtual double get_clock_rate() = 0; + + /*! + * Set the master clock rate. + * \param rate the new rate in Hz + */ + virtual void set_clock_rate(double rate) = 0; + + /*! + * Get automatic gain control status + * \return the clock rate in Hz + */ + virtual bool get_agc() = 0; + + /*! + * Enable/disable the automatic gain control. + * \param enb true to enable automatic gain control + * \param attack attack time of the AGC circuit + * \param decay decay time of the AGC circuit + */ + virtual void set_agc(bool enb, double attack, double decay) = 0; + + /*! TODO: add more */ +#endif +}; + +#endif /* INCLUDED_OSMOSDR_SOURCE_C_H */ |