rtl: implement methods allowing runtime to control sampling process

This commit is contained in:
Dimitri Stolnikov 2014-03-10 16:25:23 +01:00
parent 542a3dbb2b
commit 6610909913
2 changed files with 30 additions and 6 deletions

View File

@ -84,7 +84,7 @@ rtl_source_c::rtl_source_c (const std::string &args)
gr::io_signature::make(MIN_OUT, MAX_OUT, sizeof (gr_complex))),
_dev(NULL),
_buf(NULL),
_running(true),
_running(false),
_no_tuner(false),
_auto_gain(false),
_if_gain(0),
@ -236,8 +236,6 @@ rtl_source_c::rtl_source_c (const std::string &args)
for(unsigned int i = 0; i < _buf_num; ++i)
_buf[i] = (unsigned short *) malloc(_buf_len);
}
_thread = gr::thread::thread(_rtlsdr_wait, this);
}
/*
@ -246,9 +244,13 @@ rtl_source_c::rtl_source_c (const std::string &args)
rtl_source_c::~rtl_source_c ()
{
if (_dev) {
_running = false;
rtlsdr_cancel_async( _dev );
_thread.join();
if (_running)
{
_running = false;
rtlsdr_cancel_async( _dev );
_thread.join();
}
rtlsdr_close( _dev );
_dev = NULL;
}
@ -264,6 +266,24 @@ rtl_source_c::~rtl_source_c ()
}
}
bool rtl_source_c::start()
{
_running = true;
_thread = gr::thread::thread(_rtlsdr_wait, this);
return true;
}
bool rtl_source_c::stop()
{
_running = false;
if (_dev)
rtlsdr_cancel_async( _dev );
_thread.join();
return true;
}
void rtl_source_c::_rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx)
{
rtl_source_c *obj = (rtl_source_c *)ctx;

View File

@ -112,6 +112,10 @@ public:
std::string set_antenna( const std::string & antenna, size_t chan = 0 );
std::string get_antenna( size_t chan = 0 );
protected:
bool start();
bool stop();
private:
static void _rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx);
void rtlsdr_callback(unsigned char *buf, uint32_t len);