From 7a8084bf365a592f18f3b1e8a6516ccfa9c0d04d Mon Sep 17 00:00:00 2001
From: Lucas Teske <lucas@teske.net.br>
Date: Mon, 20 Feb 2017 18:54:17 -0300
Subject: [PATCH 1/1] Added BiasT support for default API

---
 include/osmosdr/source.h      | 13 +++++++++++++
 lib/airspy/airspy_source_c.cc |  9 +++++++++
 lib/airspy/airspy_source_c.h  |  4 ++++
 lib/hackrf/hackrf_source_c.cc | 11 +++++++++++
 lib/hackrf/hackrf_source_c.h  |  4 ++++
 lib/osmosdr/osmosdr_src_c.cc  |  2 +-
 lib/source_iface.h            | 12 ++++++++++++
 lib/source_impl.cc            | 18 ++++++++++++++++++
 lib/source_impl.h             |  3 +++
 9 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/include/osmosdr/source.h b/include/osmosdr/source.h
index 88f8385..b157b19 100644
--- a/include/osmosdr/source.h
+++ b/include/osmosdr/source.h
@@ -415,6 +415,19 @@ public:
    * \param time_spec the new time
    */
   virtual void set_time_unknown_pps(const ::osmosdr::time_spec_t &time_spec) = 0;
+
+
+  /*!
+   * Enabled the Bias T (Power Injection) for supported radios.
+   * \param enabled true for enabled
+   */
+  virtual void set_biast( bool enabled ) = 0;
+
+  /*!
+   * Gets the state of Bias T for supported radios.
+   */
+  virtual bool get_biast() = 0;
+
 };
 
 } /* namespace osmosdr */
diff --git a/lib/airspy/airspy_source_c.cc b/lib/airspy/airspy_source_c.cc
index 25f73d4..a83c2d9 100644
--- a/lib/airspy/airspy_source_c.cc
+++ b/lib/airspy/airspy_source_c.cc
@@ -654,3 +654,12 @@ osmosdr::freq_range_t airspy_source_c::get_bandwidth_range( size_t chan )
 
   return bandwidths;
 }
+
+void airspy_source_c::set_biast( bool enabled ) {
+  airspy_set_rf_bias(_dev, enabled ? 1 : 0);
+  _biasT = enabled;
+}
+
+bool airspy_source_c::get_biast() {
+  return _biasT;
+}
\ No newline at end of file
diff --git a/lib/airspy/airspy_source_c.h b/lib/airspy/airspy_source_c.h
index 3a6d833..2063661 100644
--- a/lib/airspy/airspy_source_c.h
+++ b/lib/airspy/airspy_source_c.h
@@ -122,6 +122,9 @@ public:
   double get_bandwidth( size_t chan = 0 );
   osmosdr::freq_range_t get_bandwidth_range( size_t chan = 0 );
 
+  void set_biast( bool enabled );
+  bool get_biast();
+
 private:
   static int _airspy_rx_callback(airspy_transfer* transfer);
   int airspy_rx_callback(void *samples, int sample_count);
@@ -148,6 +151,7 @@ private:
   double _mix_gain;
   double _vga_gain;
   double _bandwidth;
+  bool _biasT;
 };
 
 #endif /* INCLUDED_AIRSPY_SOURCE_C_H */
diff --git a/lib/hackrf/hackrf_source_c.cc b/lib/hackrf/hackrf_source_c.cc
index 4211603..8fb59c0 100644
--- a/lib/hackrf/hackrf_source_c.cc
+++ b/lib/hackrf/hackrf_source_c.cc
@@ -108,6 +108,8 @@ hackrf_source_c::hackrf_source_c (const std::string &args)
 
   _buf_num = _buf_len = _buf_head = _buf_used = _buf_offset = 0;
 
+  _biasT = false;
+
   if (dict.count("buffers"))
     _buf_num = boost::lexical_cast< unsigned int >( dict["buffers"] );
 
@@ -766,3 +768,12 @@ osmosdr::freq_range_t hackrf_source_c::get_bandwidth_range( size_t chan )
 
   return bandwidths;
 }
+
+void hackrf_source_c::set_biast( bool enabled ) {
+  hackrf_set_antenna_enable(_dev, enabled ? 1 : 0);
+  _biasT = enabled;
+}
+
+bool hackrf_source_c::get_biast() {
+  return _biasT;
+}
\ No newline at end of file
diff --git a/lib/hackrf/hackrf_source_c.h b/lib/hackrf/hackrf_source_c.h
index 6ae81d2..e799fb7 100644
--- a/lib/hackrf/hackrf_source_c.h
+++ b/lib/hackrf/hackrf_source_c.h
@@ -120,6 +120,9 @@ public:
   double get_bandwidth( size_t chan = 0 );
   osmosdr::freq_range_t get_bandwidth_range( size_t chan = 0 );
 
+  void set_biast( bool enabled );
+  bool get_biast();
+
 private:
   static int _hackrf_rx_callback(hackrf_transfer* transfer);
   int hackrf_rx_callback(unsigned char *buf, uint32_t len);
@@ -152,6 +155,7 @@ private:
   double _lna_gain;
   double _vga_gain;
   double _bandwidth;
+  bool _biasT;
 };
 
 #endif /* INCLUDED_HACKRF_SOURCE_C_H */
diff --git a/lib/osmosdr/osmosdr_src_c.cc b/lib/osmosdr/osmosdr_src_c.cc
index de65373..a27f390 100644
--- a/lib/osmosdr/osmosdr_src_c.cc
+++ b/lib/osmosdr/osmosdr_src_c.cc
@@ -530,4 +530,4 @@ std::string osmosdr_src_c::set_antenna( const std::string & antenna, size_t chan
 std::string osmosdr_src_c::get_antenna( size_t chan )
 {
   return "RX";
-}
+}
\ No newline at end of file
diff --git a/lib/source_iface.h b/lib/source_iface.h
index abb70eb..a826369 100644
--- a/lib/source_iface.h
+++ b/lib/source_iface.h
@@ -395,6 +395,18 @@ public:
    * \param time_spec the new time
    */
   virtual void set_time_unknown_pps(const ::osmosdr::time_spec_t &time_spec) { }
+
+  /*!
+   * Enabled the Bias T (Power Injection) for supported radios.
+   * \param enabled true for enabled
+   */
+  virtual void set_biast( bool enabled ) { std::cout << "NOT IMPLEMENTED BIAST(" << enabled << ")" << std::endl; }
+
+  /*!
+   * Gets the state of Bias T for supported radios.
+   */
+  virtual bool get_biast() { return false; }
+
 };
 
 #endif // OSMOSDR_SOURCE_IFACE_H
diff --git a/lib/source_impl.cc b/lib/source_impl.cc
index 3aa17f9..a8628bc 100644
--- a/lib/source_impl.cc
+++ b/lib/source_impl.cc
@@ -966,3 +966,21 @@ void source_impl::set_time_unknown_pps(const osmosdr::time_spec_t &time_spec)
     dev->set_time_unknown_pps( time_spec );
   }
 }
+
+
+void source_impl::set_biast( bool enabled ) {
+  BOOST_FOREACH( source_iface *dev, _devs )
+  {
+    dev->set_biast(enabled);
+  }
+}
+
+bool source_impl::get_biast() {
+  BOOST_FOREACH( source_iface *dev, _devs )
+  {
+    if (dev->get_biast()) {
+      return true;
+    }
+  }
+  return false;
+}
diff --git a/lib/source_impl.h b/lib/source_impl.h
index 4b65125..093dee6 100644
--- a/lib/source_impl.h
+++ b/lib/source_impl.h
@@ -91,6 +91,9 @@ public:
   void set_time_next_pps(const ::osmosdr::time_spec_t &time_spec);
   void set_time_unknown_pps(const ::osmosdr::time_spec_t &time_spec);
 
+  void set_biast( bool enabled );
+  bool get_biast();
+
 private:
   std::vector< source_iface * > _devs;
 
-- 
2.7.4

