From 74b9211cdca744d22917c98dfd05a700f9a37c39 Mon Sep 17 00:00:00 2001 From: Dimitri Stolnikov Date: Mon, 10 Mar 2014 16:25:23 +0100 Subject: [PATCH] rtl: implement methods allowing runtime to control sampling process --- lib/rtl/rtl_source_c.cc | 32 ++++++++++++++++++++++++++------ lib/rtl/rtl_source_c.h | 4 ++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/rtl/rtl_source_c.cc b/lib/rtl/rtl_source_c.cc index 85530d7..e049cd5 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_make_io_signature (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 = gruel::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 = gruel::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 86d6a39..2bd23f3 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);