add api for manual gain mode control

gr3.6
Dimitri Stolnikov 11 years ago
parent f0ac70fa41
commit 3a47e3661c
  1. 134
      apps/osmosdr_source.grc
  2. 23
      grc/gen_osmosdr_blocks.py
  3. 16
      include/osmosdr/osmosdr_source_c.h
  4. 10
      lib/fcd/fcd_source.cc
  5. 2
      lib/fcd/fcd_source.h
  6. 10
      lib/file/file_source_c.cc
  7. 2
      lib/file/file_source_c.h
  8. 22
      lib/osmosdr_source_c_impl.cc
  9. 2
      lib/osmosdr_source_c_impl.h
  10. 16
      lib/osmosdr_src_iface.h
  11. 46
      lib/rtl/rtl_source_c.cc
  12. 4
      lib/rtl/rtl_source_c.h
  13. 10
      lib/uhd/uhd_source_c.cc
  14. 2
      lib/uhd/uhd_source_c.h

@ -1,6 +1,6 @@
<?xml version='1.0' encoding='ASCII'?>
<flow_graph>
<timestamp>Sat Apr 28 19:58:05 2012</timestamp>
<timestamp>Sat May 5 00:40:44 2012</timestamp>
<block>
<key>options</key>
<param>
@ -44,67 +44,16 @@
<value>True</value>
</param>
<param>
<key>realtime_scheduling</key>
<value></value>
</param>
<param>
<key>_coordinate</key>
<value>(10, 10)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
</block>
<block>
<key>variable_slider</key>
<param>
<key>id</key>
<value>gain</value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>label</key>
<value></value>
</param>
<param>
<key>value</key>
<value>10</value>
</param>
<param>
<key>min</key>
<key>max_nouts</key>
<value>0</value>
</param>
<param>
<key>max</key>
<value>30</value>
</param>
<param>
<key>num_steps</key>
<value>31</value>
</param>
<param>
<key>style</key>
<value>wx.SL_HORIZONTAL</value>
</param>
<param>
<key>converver</key>
<value>float_converter</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>notebook</key>
<key>realtime_scheduling</key>
<value></value>
</param>
<param>
<key>_coordinate</key>
<value>(472, 65)</value>
<value>(10, 10)</value>
</param>
<param>
<key>_rotation</key>
@ -410,6 +359,57 @@
<value>0</value>
</param>
</block>
<block>
<key>variable_chooser</key>
<param>
<key>id</key>
<value>gain_chooser</value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>label</key>
<value></value>
</param>
<param>
<key>value</key>
<value>9.0</value>
</param>
<param>
<key>choices</key>
<value>[-1.0, 1.5, 4.0, 6.5, 9.0, 11.5, 14.0, 16.5, 19.0, 21.5, 24.0, 29.0, 34.0, 42.0, 43.0, 45.0, 47.0, 49.0]</value>
</param>
<param>
<key>labels</key>
<value>[]</value>
</param>
<param>
<key>type</key>
<value>drop_down</value>
</param>
<param>
<key>style</key>
<value>wx.RA_HORIZONTAL</value>
</param>
<param>
<key>grid_pos</key>
<value></value>
</param>
<param>
<key>notebook</key>
<value></value>
</param>
<param>
<key>_coordinate</key>
<value>(461, 63)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
</block>
<block>
<key>osmosdr_source_c</key>
<param>
@ -446,7 +446,11 @@
</param>
<param>
<key>gain0</key>
<value>gain</value>
<value>gain_chooser</value>
</param>
<param>
<key>gain_mode0</key>
<value>1</value>
</param>
<param>
<key>ant0</key>
@ -462,7 +466,11 @@
</param>
<param>
<key>gain1</key>
<value>gain</value>
<value>gain_chooser</value>
</param>
<param>
<key>gain_mode1</key>
<value>0</value>
</param>
<param>
<key>ant1</key>
@ -480,6 +488,10 @@
<key>gain2</key>
<value>0</value>
</param>
<param>
<key>gain_mode2</key>
<value>0</value>
</param>
<param>
<key>ant2</key>
<value></value>
@ -496,6 +508,10 @@
<key>gain3</key>
<value>0</value>
</param>
<param>
<key>gain_mode3</key>
<value>0</value>
</param>
<param>
<key>ant3</key>
<value></value>
@ -512,6 +528,10 @@
<key>gain4</key>
<value>0</value>
</param>
<param>
<key>gain_mode4</key>
<value>0</value>
</param>
<param>
<key>ant4</key>
<value></value>

@ -32,6 +32,7 @@ self.\$(id).set_sample_rate(\$sample_rate)
self.\$(id).set_center_freq(\$freq$(n), $n)
self.\$(id).set_freq_corr(\$corr$(n), $n)
self.\$(id).set_gain(\$gain$(n), $n)
self.\$(id).set_gain_mode(\$gain_mode$(n), $n)
\#if \$ant$(n)()
self.\$(id).set_antenna(\$ant$(n), $n)
\#end if
@ -43,6 +44,7 @@ self.\$(id).set_antenna(\$ant$(n), $n)
<callback>set_center_freq(\$freq$(n), $n)</callback>
<callback>set_freq_corr(\$corr$(n), $n)</callback>
<callback>set_gain(\$gain$(n), $n)</callback>
<callback>set_gain_mode(\$gain_mode$(n), $n)</callback>
<callback>set_antenna(\$ant$(n), $n)</callback>
#end for
<param>
@ -125,7 +127,11 @@ Freq. Corr.:
The frequency correction factor in parts per million (ppm). Leave 0 if unknown.
Gain:
Overall gain of the device's signal path.
Overall gain of the device's signal path. For the gain setting to apply the
manual gain mode must be enabled first for some devices (namely rtlsdr).
Gain Mode:
Chooses between the automatic (default) and manual gain mode where appropriate.
Antenna:
For devices with only one antenna, this may be left blank.
@ -159,6 +165,21 @@ PARAMS_TMPL = """
<type>real</type>
<hide>\#if \$nchan() > $n then 'none' else 'all'#</hide>
</param>
<param>
<name>Ch$(n): Gain Mode</name>
<key>gain_mode$(n)</key>
<value></value>
<type>enum</type>
<hide>\#if \$nchan() > $n then 'none' else 'all'#</hide>
<option>
<name>Auto</name>
<key>0</key>
</option>
<option>
<name>Manual</name>
<key>1</key>
</option>
</param>
<param>
<name>Ch$(n): Antenna</name>
<key>ant$(n)</key>

@ -145,6 +145,22 @@ public:
virtual osmosdr::gain_range_t get_gain_range( const std::string & name,
size_t chan = 0 ) = 0;
/*!
* Set the gain mode for the underlying radio hardware.
* This might be supported only for certain hardware types.
* \param mode the gain mode (true means manual gain mode)
* \param chan the channel index 0 to N-1
* \return the actual gain mode
*/
virtual bool set_gain_mode( bool mode, size_t chan = 0 ) = 0;
/*!
* Get the gain mode selected for the underlying radio hardware.
* \param chan the channel index 0 to N-1
* \return the actual gain mode
*/
virtual bool get_gain_mode( size_t chan = 0 ) = 0;
/*!
* Set the gain for the underlying radio hardware.
* This function will automatically distribute the desired gain value over

@ -186,6 +186,16 @@ osmosdr::gain_range_t fcd_source::get_gain_range( const std::string & name, size
return get_gain_range( chan );
}
bool fcd_source::set_gain_mode( bool mode, size_t chan )
{
return get_gain_mode(chan);
}
bool fcd_source::get_gain_mode( size_t chan )
{
return true;
}
double fcd_source::set_gain( double gain, size_t chan )
{
_src->set_lna_gain(gain);

@ -65,6 +65,8 @@ public:
std::vector<std::string> get_gain_names( size_t chan = 0 );
osmosdr::gain_range_t get_gain_range( size_t chan = 0 );
osmosdr::gain_range_t get_gain_range( const std::string & name, size_t chan = 0 );
bool set_gain_mode( bool mode, size_t chan = 0 );
bool get_gain_mode( size_t chan = 0 );
double set_gain( double gain, size_t chan = 0 );
double set_gain( double gain, const std::string & name, size_t chan = 0 );
double get_gain( size_t chan = 0 );

@ -172,6 +172,16 @@ osmosdr::gain_range_t file_source_c::get_gain_range( const std::string & name, s
return get_gain_range( chan );
}
bool file_source_c::set_gain_mode( bool mode, size_t chan )
{
return get_gain_mode(chan);
}
bool file_source_c::get_gain_mode( size_t chan )
{
return true;
}
double file_source_c::set_gain( double gain, size_t chan )
{
return get_gain(chan);

@ -61,6 +61,8 @@ public:
std::vector<std::string> get_gain_names( size_t chan = 0 );
osmosdr::gain_range_t get_gain_range( size_t chan = 0 );
osmosdr::gain_range_t get_gain_range( const std::string & name, size_t chan = 0 );
bool set_gain_mode( bool mode, size_t chan = 0 );
bool get_gain_mode( size_t chan = 0 );
double set_gain( double gain, size_t chan = 0 );
double set_gain( double gain, const std::string & name, size_t chan = 0 );
double get_gain( size_t chan = 0 );

@ -249,6 +249,28 @@ osmosdr::gain_range_t osmosdr_source_c_impl::get_gain_range( const std::string &
return osmosdr::gain_range_t();
}
bool osmosdr_source_c_impl::set_gain_mode( bool mode, size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->set_gain_mode( mode, chan );
return false;
}
bool osmosdr_source_c_impl::get_gain_mode( size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->get_gain_mode( chan );
return false;
}
double osmosdr_source_c_impl::set_gain( double gain, size_t chan )
{
size_t channel = 0;

@ -43,6 +43,8 @@ public:
std::vector<std::string> get_gain_names( size_t chan = 0 );
osmosdr::gain_range_t get_gain_range( size_t chan = 0 );
osmosdr::gain_range_t get_gain_range( const std::string & name, size_t chan = 0 );
bool set_gain_mode( bool mode, size_t chan = 0 );
bool get_gain_mode( size_t chan = 0 );
double set_gain( double gain, size_t chan = 0 );
double set_gain( double gain, const std::string & name, size_t chan = 0 );
double get_gain( size_t chan = 0 );

@ -123,6 +123,22 @@ public:
virtual osmosdr::gain_range_t get_gain_range( const std::string & name,
size_t chan = 0 ) = 0;
/*!
* Set the gain mode for the underlying radio hardware.
* This might be supported only for certain hardware types.
* \param mode the gain mode (true means manual gain mode)
* \param chan the channel index 0 to N-1
* \return the actual gain mode
*/
virtual bool set_gain_mode( bool mode, size_t chan = 0 ) = 0;
/*!
* Get the gain mode selected for the underlying radio hardware.
* \param chan the channel index 0 to N-1
* \return the actual gain mode
*/
virtual bool get_gain_mode( size_t chan = 0 ) = 0;
/*!
* Set the gain for the underlying radio hardware.
* This function will automatically distribute the desired gain value over

@ -145,6 +145,8 @@ rtl_source_c::rtl_source_c (const std::string &args)
_running = true;
_manual_gain = false;
_thread = gruel::thread(_rtlsdr_wait, this);
}
@ -278,7 +280,12 @@ osmosdr::meta_range_t rtl_source_c::get_sample_rates()
osmosdr::meta_range_t range;
range += osmosdr::range_t( 1024000 ); // known to work
range += osmosdr::range_t( 1800000 ); // known to work
range += osmosdr::range_t( 2048000 ); // known to work
range += osmosdr::range_t( 2400000 ); // may work
range += osmosdr::range_t( 2600000 ); // may work
range += osmosdr::range_t( 2800000 ); // may work
range += osmosdr::range_t( 3000000 ); // may work
range += osmosdr::range_t( 3200000 ); // max rate, may work
// TODO: read from the librtlsdr as soon as the api is available
@ -359,7 +366,24 @@ osmosdr::gain_range_t rtl_source_c::get_gain_range( size_t chan )
{
osmosdr::gain_range_t range;
range += osmosdr::range_t( -5, 30, 2.5 );
range += osmosdr::range_t( -1.0 );
range += osmosdr::range_t( 1.5 );
range += osmosdr::range_t( 4.0 );
range += osmosdr::range_t( 6.5 );
range += osmosdr::range_t( 9.0 );
range += osmosdr::range_t( 11.5 );
range += osmosdr::range_t( 14.0 );
range += osmosdr::range_t( 16.5 );
range += osmosdr::range_t( 19.0 );
range += osmosdr::range_t( 21.5 );
range += osmosdr::range_t( 24.0 );
range += osmosdr::range_t( 29.0 );
range += osmosdr::range_t( 34.0 );
range += osmosdr::range_t( 42.0 );
range += osmosdr::range_t( 43.0 );
range += osmosdr::range_t( 45.0 );
range += osmosdr::range_t( 47.0 );
range += osmosdr::range_t( 49.0 );
// TODO: read from the librtlsdr as soon as the api is available
@ -371,10 +395,26 @@ osmosdr::gain_range_t rtl_source_c::get_gain_range( const std::string & name, si
return get_gain_range( chan );
}
bool rtl_source_c::set_gain_mode( bool mode, size_t chan )
{
if (_dev) {
if (!rtlsdr_set_tuner_gain_mode(_dev, int(mode))) {
_manual_gain = mode;
}
}
return get_gain_mode(chan);
}
bool rtl_source_c::get_gain_mode( size_t chan )
{
return _manual_gain;
}
double rtl_source_c::set_gain( double gain, size_t chan )
{
if (_dev)
rtlsdr_set_tuner_gain( _dev, gain );
rtlsdr_set_tuner_gain( _dev, int(gain * 10.0) );
return get_gain( chan );
}
@ -387,7 +427,7 @@ double rtl_source_c::set_gain( double gain, const std::string & name, size_t cha
double rtl_source_c::get_gain( size_t chan )
{
if ( _dev )
return (double)rtlsdr_get_tuner_gain( _dev );
return ((double)rtlsdr_get_tuner_gain( _dev )) / 10.0;
return 0;
}

@ -98,6 +98,8 @@ public:
std::vector<std::string> get_gain_names( size_t chan = 0 );
osmosdr::gain_range_t get_gain_range( size_t chan = 0 );
osmosdr::gain_range_t get_gain_range( const std::string & name, size_t chan = 0 );
bool set_gain_mode( bool mode, size_t chan = 0 );
bool get_gain_mode( size_t chan = 0 );
double set_gain( double gain, size_t chan = 0 );
double set_gain( double gain, const std::string & name, size_t chan = 0 );
double get_gain( size_t chan = 0 );
@ -127,6 +129,8 @@ private:
unsigned int _buf_offset;
unsigned int _samp_avail;
bool _manual_gain;
};
#endif /* INCLUDED_RTLSDR_SOURCE_C_H */

@ -175,6 +175,16 @@ osmosdr::gain_range_t uhd_source_c::get_gain_range( const std::string & name, si
return range;
}
bool uhd_source_c::set_gain_mode( bool mode, size_t chan )
{
return get_gain_mode(chan);
}
bool uhd_source_c::get_gain_mode( size_t chan )
{
return true;
}
double uhd_source_c::set_gain( double gain, size_t chan )
{
_src->set_gain(gain, chan);

@ -65,6 +65,8 @@ public:
std::vector<std::string> get_gain_names( size_t chan = 0 );
osmosdr::gain_range_t get_gain_range( size_t chan = 0 );
osmosdr::gain_range_t get_gain_range( const std::string & name, size_t chan = 0 );
bool set_gain_mode( bool mode, size_t chan = 0 );
bool get_gain_mode( size_t chan = 0 );
double set_gain( double gain, size_t chan = 0 );
double set_gain( double gain, const std::string & name, size_t chan = 0 );
double get_gain( size_t chan = 0 );

Loading…
Cancel
Save