1 /* -*- c++ -*- */ 2 /* 3 * Copyright 2012 Dimitri Stolnikov <horiz0n@gmx.net> 4 * 5 * GNU Radio is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 3, or (at your option) 8 * any later version. 9 * 10 * GNU Radio is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with GNU Radio; see the file COPYING. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, 18 * Boston, MA 02110-1301, USA. 19 */ 20 #ifndef INCLUDED_OSMOSDR_SOURCE_IMPL_H 21 #define INCLUDED_OSMOSDR_SOURCE_IMPL_H 22 23 #include <osmosdr/source.h> 24 25 #ifdef HAVE_IQBALANCE 26 #include <gnuradio/iqbalance/optimize_c.h> 27 #include <gnuradio/iqbalance/fix_cc.h> 28 #endif 29 30 #include <source_iface.h> 31 32 #include <map> 33 34 class source_impl : public osmosdr::source 35 { 36 public: 37 source_impl( const std::string & args ); 38 39 size_t get_num_channels( void ); 40 41 bool seek( long seek_point, int whence, size_t chan ); 42 43 osmosdr::meta_range_t get_sample_rates( void ); 44 double set_sample_rate( double rate ); 45 double get_sample_rate( void ); 46 47 osmosdr::freq_range_t get_freq_range( size_t chan = 0 ); 48 double set_center_freq( double freq, size_t chan = 0 ); 49 double get_center_freq( size_t chan = 0 ); 50 double set_freq_corr( double ppm, size_t chan = 0 ); 51 double get_freq_corr( size_t chan = 0 ); 52 53 std::vector<std::string> get_gain_names( size_t chan = 0 ); 54 osmosdr::gain_range_t get_gain_range( size_t chan = 0 ); 55 osmosdr::gain_range_t get_gain_range( const std::string & name, size_t chan = 0 ); 56 bool set_gain_mode( bool automatic, size_t chan = 0 ); 57 bool get_gain_mode( size_t chan = 0 ); 58 double set_gain( double gain, size_t chan = 0 ); 59 double set_gain( double gain, const std::string & name, size_t chan = 0 ); 60 double get_gain( size_t chan = 0 ); 61 double get_gain( const std::string & name, size_t chan = 0 ); 62 63 double set_if_gain( double gain, size_t chan = 0 ); 64 double set_bb_gain( double gain, size_t chan = 0 ); 65 66 std::vector< std::string > get_antennas( size_t chan = 0 ); 67 std::string set_antenna( const std::string & antenna, size_t chan = 0 ); 68 std::string get_antenna( size_t chan = 0 ); 69 70 void set_dc_offset_mode( int mode, size_t chan = 0 ); 71 void set_dc_offset( const std::complex<double> &offset, size_t chan = 0 ); 72 73 void set_iq_balance_mode( int mode, size_t chan = 0 ); 74 void set_iq_balance( const std::complex<double> &balance, size_t chan = 0 ); 75 76 double set_bandwidth( double bandwidth, size_t chan = 0 ); 77 double get_bandwidth( size_t chan = 0 ); 78 osmosdr::freq_range_t get_bandwidth_range( size_t chan = 0 ); 79 80 void set_time_source(const std::string &source, const size_t mboard = 0); 81 std::string get_time_source(const size_t mboard); 82 std::vector<std::string> get_time_sources(const size_t mboard); 83 void set_clock_source(const std::string &source, const size_t mboard = 0); 84 std::string get_clock_source(const size_t mboard); 85 std::vector<std::string> get_clock_sources(const size_t mboard); 86 double get_clock_rate(size_t mboard = 0); 87 void set_clock_rate(double rate, size_t mboard = 0); 88 ::osmosdr::time_spec_t get_time_now(size_t mboard = 0); 89 ::osmosdr::time_spec_t get_time_last_pps(size_t mboard = 0); 90 void set_time_now(const ::osmosdr::time_spec_t &time_spec, size_t mboard = 0); 91 void set_time_next_pps(const ::osmosdr::time_spec_t &time_spec); 92 void set_time_unknown_pps(const ::osmosdr::time_spec_t &time_spec); 93 94 private: 95 std::vector< source_iface * > _devs; 96 97 /* cache to prevent multiple device calls with the same value coming from grc */ 98 double _sample_rate; 99 std::map< size_t, double > _center_freq; 100 std::map< size_t, double > _freq_corr; 101 std::map< size_t, bool > _gain_mode; 102 std::map< size_t, double > _gain; 103 std::map< size_t, double > _if_gain; 104 std::map< size_t, double > _bb_gain; 105 std::map< size_t, std::string > _antenna; 106 #ifdef HAVE_IQBALANCE 107 std::vector< gr::iqbalance::fix_cc * > _iq_fix; 108 std::vector< gr::iqbalance::optimize_c * > _iq_opt; 109 std::map< size_t, std::pair<float, float> > _vals; 110 #endif 111 std::map< size_t, double > _bandwidth; 112 }; 113 114 #endif /* INCLUDED_OSMOSDR_SOURCE_IMPL_H */ 115