hackf: implement start & stop methods

This allows a block to enable an associated driver to begin
transfering data just before we start to execute the scheduler.
The end result is that this reduces latency in the pipeline
when dealing with audio devices, usrps, etc.
This commit is contained in:
Dimitri Stolnikov 2013-04-26 21:50:50 +02:00
parent 9bd7cbf4e1
commit 37f6383c7c
2 changed files with 35 additions and 7 deletions

View File

@ -176,12 +176,6 @@ hackrf_source_c::hackrf_source_c (const std::string &args)
_buf[i] = (unsigned short *) malloc(_buf_len);
}
ret = hackrf_start_rx( _dev, _hackrf_rx_callback, (void *)this );
if (ret != HACKRF_SUCCESS)
std::cerr << "Failed to start streaming (" << ret << ")" << std::endl;
while ( ! hackrf_is_streaming( _dev ) );
// _thread = gruel::thread(_hackrf_wait, this);
}
@ -191,7 +185,6 @@ hackrf_source_c::hackrf_source_c (const std::string &args)
hackrf_source_c::~hackrf_source_c ()
{
if (_dev) {
hackrf_stop_rx( _dev );
// _thread.join();
hackrf_close( _dev );
_dev = NULL;
@ -253,6 +246,38 @@ void hackrf_source_c::hackrf_wait()
{
}
bool hackrf_source_c::start()
{
if ( ! _dev )
return false;
int ret = hackrf_start_rx( _dev, _hackrf_rx_callback, (void *)this );
if (ret != HACKRF_SUCCESS) {
std::cerr << "Failed to start RX streaming (" << ret << ")" << std::endl;
return false;
}
while ( ! hackrf_is_streaming( _dev ) );
return (bool) hackrf_is_streaming( _dev );
}
bool hackrf_source_c::stop()
{
if ( ! _dev )
return false;
int ret = hackrf_stop_rx( _dev );
if (ret != HACKRF_SUCCESS) {
std::cerr << "Failed to stop RX streaming (" << ret << ")" << std::endl;
return false;
}
while ( hackrf_is_streaming( _dev ) );
return ! (bool) hackrf_is_streaming( _dev );
}
int hackrf_source_c::work( int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items )

View File

@ -78,6 +78,9 @@ private:
public:
~hackrf_source_c (); // public destructor
bool start();
bool stop();
int work( int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items );