HackRF powered antenna support (pleeeeease :)

Brad Hein k1gto at comcast.net
Fri May 15 21:18:01 UTC 2015


I modified the osmosdr hackrf code to support antenna/phantom power via a new device argument "bias=" (to match bladeRF's existing bias power syntax). 0=disable and 1=enable. My initial testing suggests it works great, but I would invite others to also confirm if they are able. You'll have to apply the patch below. 

I also added a device argument to control bias power at transmit time. I named this option differently - "bias_tx" - to avoid accidentally enabling bias power in transmit mode when an LNA may be attached in an input amplifier configuration. I reached out to the designer of the lna4all to find out if bias power can be supported, from a hardware perspective, in transmit mode (hackrf output connected to lna4all input, lna4all output connected to antenna). We'll see what he says. If so, I look forward to testing transmit mode bias power. 

Patch follows: 

$ git diff 275e6aed19b9ba8563bffd318a227a1196e1da2c 9ca86fdcd068daf44d9dec0dd1993b22c24b02f2 | cat 
diff --git a/lib/hackrf/hackrf_sink_c.cc b/lib/hackrf/hackrf_sink_c.cc 
index 00f9768..0d52c60 100644 
--- a/lib/hackrf/hackrf_sink_c.cc 
+++ b/lib/hackrf/hackrf_sink_c.cc 
@@ -164,6 +164,7 @@ hackrf_sink_c::hackrf_sink_c (const std::string &args) 
_bandwidth(0) 
{ 
int ret; 
+ bool bias = false; 

dict_t dict = params_to_dict(args); 

@@ -184,6 +185,11 @@ hackrf_sink_c::hackrf_sink_c (const std::string &args) 
_usage++; 
} 

+ // Check device args to find out if bias/phantom power is desired. 
+ if ( dict.count("bias_tx") ) { 
+ bias = boost::lexical_cast<bool>( dict["bias_tx"] ); 
+ } 
+ 
_dev = NULL; 
ret = hackrf_open( &_dev ); 
HACKRF_THROW_ON_ERROR(ret, "Failed to open HackRF device") 
@@ -218,6 +224,14 @@ hackrf_sink_c::hackrf_sink_c (const std::string &args) 

set_if_gain( 16 ); /* preset to a reasonable default (non-GRC use case) */ 

+ ret = hackrf_set_antenna_enable(_dev, (uint8_t)bias); 
+ HACKRF_THROW_ON_ERROR( ret, "Failed to enable bias/phantom antenna power"); 
+ if (bias==true) { 
+ std::cerr << "Successfully enabled antenna bias/power (bias_tx=" << bias << ")" << std::endl; 
+ } else { 
+ std::cerr << "Successfully disabled antenna bias/power (bias_tx=" << bias << ")" << std::endl; 
+ } 
+ 
_buf = (char *) malloc( BUF_LEN ); 

cb_init( &_cbuf, _buf_num, BUF_LEN ); 
diff --git a/lib/hackrf/hackrf_source_c.cc b/lib/hackrf/hackrf_source_c.cc 
index e3b3ea4..4ba24ec 100644 
--- a/lib/hackrf/hackrf_source_c.cc 
+++ b/lib/hackrf/hackrf_source_c.cc 
@@ -181,6 +181,16 @@ hackrf_source_c::hackrf_source_c (const std::string &args) 
_buf[i] = (unsigned short *) malloc(_buf_len); 
} 

+ 
+// Enable bias/phantom power on the antenna port if device argument parameter bias= is present. 1=enable, 0=disable. 
+ if ( dict.count("bias") ) { 
+ bool bias = boost::lexical_cast<bool>( dict["bias"] ); 
+ int ret = hackrf_set_antenna_enable(_dev, (uint8_t)bias); 
+ HACKRF_THROW_ON_ERROR( ret, "Failed to enable bias/phantom antenna power"); 
+ std::cerr << "Successfully set antenna power to " << bias << std::endl; 
+ } 
+ 
+ 
// _thread = gr::thread::thread(_hackrf_wait, this); 

ret = hackrf_start_rx( _dev, _hackrf_rx_callback, (void *)this ); 



----- Original Message -----

From: "Brad Hein" <k1gto at comcast.net> 
To: osmocom-sdr at lists.osmocom.org 
Sent: Thursday, January 22, 2015 12:03:57 PM 
Subject: HackRF powered antenna support (pleeeeease :) 


I would like to humbly request support for hackrf antenna power in gr-osmosdr. At runtime preferably, or at least an init string flag to control it 
(hackrf=0,antenna_power=1 for example). The function call seems to be hackrf_set_antenna_enable() but it's not exposed in gr-osmosdr as far as I can tell. 

I have some dev experience (but not in C) but I'm falling short trying to understand the code and add the feature myself. If someone wants to provide some "ELI5" guidance I'll be happy to give it another go. 

Having this feature would open up the powered antenna feature to users of gr-osmosdr such as gnuradio, gqrx, and the list goes on (big win!) 

Reference: 
https://www.mail-archive.com/hackrf-dev@greatscottgadgets.com/msg00423.html 


Thanks! 
Brad 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/osmocom-sdr/attachments/20150515/dd8459ab/attachment.html>


More information about the osmocom-sdr mailing list