aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitri Stolnikov <horiz0n@gmx.net>2014-03-10 16:25:23 +0100
committerDimitri Stolnikov <horiz0n@gmx.net>2014-03-10 16:25:23 +0100
commit66109099132946b77c5e0b4603384a9194bf6694 (patch)
treef775a243dab8e9c596f5e328ca9089bf49570d3c
parent542a3dbb2beeaab198f025344072438f88cd7747 (diff)
rtl: implement methods allowing runtime to control sampling process
-rw-r--r--lib/rtl/rtl_source_c.cc32
-rw-r--r--lib/rtl/rtl_source_c.h4
2 files changed, 30 insertions, 6 deletions
diff --git a/lib/rtl/rtl_source_c.cc b/lib/rtl/rtl_source_c.cc
index eb24464..3c29e42 100644
--- a/lib/rtl/rtl_source_c.cc
+++ b/lib/rtl/rtl_source_c.cc
@@ -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;
diff --git a/lib/rtl/rtl_source_c.h b/lib/rtl/rtl_source_c.h
index 13008cc..76de400 100644
--- a/lib/rtl/rtl_source_c.h
+++ b/lib/rtl/rtl_source_c.h
@@ -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);