summaryrefslogtreecommitdiff
path: root/gr-uhd
diff options
context:
space:
mode:
Diffstat (limited to 'gr-uhd')
-rw-r--r--gr-uhd/include/gr_uhd_usrp_sink.h13
-rw-r--r--gr-uhd/include/gr_uhd_usrp_source.h13
-rw-r--r--gr-uhd/lib/gr_uhd_usrp_sink.cc24
-rw-r--r--gr-uhd/lib/gr_uhd_usrp_source.cc20
4 files changed, 65 insertions, 5 deletions
diff --git a/gr-uhd/include/gr_uhd_usrp_sink.h b/gr-uhd/include/gr_uhd_usrp_sink.h
index ce76ec03b..4870982b9 100644
--- a/gr-uhd/include/gr_uhd_usrp_sink.h
+++ b/gr-uhd/include/gr_uhd_usrp_sink.h
@@ -118,6 +118,19 @@ class GR_UHD_API uhd_usrp_sink : virtual public gr_sync_block{
public:
/*!
+ * Set the start time for outgoing samples.
+ * To control when samples are transmitted,
+ * set this value before starting the flow graph.
+ * The value is cleared after each run.
+ * When not specified, the start time will be:
+ * - Immediately for the one channel case
+ * - in the near future for multi-channel
+ *
+ * \param time the absolute time for transmission to begin
+ */
+ virtual void set_start_time(const uhd::time_spec_t &time) = 0;
+
+ /*!
* Set the frontend specification.
* \param spec the subdev spec markup string
* \param mboard the motherboard index 0 to M-1
diff --git a/gr-uhd/include/gr_uhd_usrp_source.h b/gr-uhd/include/gr_uhd_usrp_source.h
index 23373e6fa..10c82711a 100644
--- a/gr-uhd/include/gr_uhd_usrp_source.h
+++ b/gr-uhd/include/gr_uhd_usrp_source.h
@@ -110,6 +110,19 @@ class GR_UHD_API uhd_usrp_source : virtual public gr_sync_block{
public:
/*!
+ * Set the start time for incoming samples.
+ * To control when samples are received,
+ * set this value before starting the flow graph.
+ * The value is cleared after each run.
+ * When not specified, the start time will be:
+ * - Immediately for the one channel case
+ * - in the near future for multi-channel
+ *
+ * \param time the absolute time for reception to begin
+ */
+ virtual void set_start_time(const uhd::time_spec_t &time) = 0;
+
+ /*!
* Set the frontend specification.
* \param spec the subdev spec markup string
* \param mboard the motherboard index 0 to M-1
diff --git a/gr-uhd/lib/gr_uhd_usrp_sink.cc b/gr-uhd/lib/gr_uhd_usrp_sink.cc
index 05237100c..5d8d235a1 100644
--- a/gr-uhd/lib/gr_uhd_usrp_sink.cc
+++ b/gr-uhd/lib/gr_uhd_usrp_sink.cc
@@ -56,7 +56,9 @@ public:
gr_make_io_signature(0, 0, 0)
),
_stream_args(stream_args),
- _nchan(std::max<size_t>(1, stream_args.channels.size()))
+ _nchan(std::max<size_t>(1, stream_args.channels.size())),
+ _stream_now(_nchan == 1),
+ _start_time_set(false)
{
if (stream_args.cpu_format == "fc32") _type = boost::make_shared<uhd::io_type_t>(uhd::io_type_t::COMPLEX_FLOAT32);
if (stream_args.cpu_format == "sc16") _type = boost::make_shared<uhd::io_type_t>(uhd::io_type_t::COMPLEX_INT16);
@@ -372,6 +374,12 @@ public:
}
}
+ void set_start_time(const uhd::time_spec_t &time){
+ _start_time = time;
+ _start_time_set = true;
+ _stream_now = false;
+ }
+
//Send an empty start-of-burst packet to begin streaming.
//Set at a time in the near future to avoid late packets.
bool start(void){
@@ -381,8 +389,14 @@ public:
_metadata.start_of_burst = true;
_metadata.end_of_burst = false;
- _metadata.has_time_spec = _nchan > 1;
- _metadata.time_spec = get_time_now() + uhd::time_spec_t(0.01);
+ _metadata.has_time_spec = not _stream_now;
+ if (_start_time_set){
+ _start_time_set = false; //cleared for next run
+ _metadata.time_spec = _start_time;
+ }
+ else{
+ _metadata.time_spec = get_time_now() + uhd::time_spec_t(0.01);
+ }
#ifdef GR_UHD_USE_STREAM_API
_tx_stream->send(
@@ -423,9 +437,13 @@ private:
uhd::tx_streamer::sptr _tx_stream;
#endif
size_t _nchan;
+ bool _stream_now;
uhd::tx_metadata_t _metadata;
double _sample_rate;
+ uhd::time_spec_t _start_time;
+ bool _start_time_set;
+
//stream tags related stuff
std::vector<gr_tag_t> _tags;
};
diff --git a/gr-uhd/lib/gr_uhd_usrp_source.cc b/gr-uhd/lib/gr_uhd_usrp_source.cc
index 33596e37b..e52782847 100644
--- a/gr-uhd/lib/gr_uhd_usrp_source.cc
+++ b/gr-uhd/lib/gr_uhd_usrp_source.cc
@@ -58,7 +58,8 @@ public:
_stream_args(stream_args),
_nchan(std::max<size_t>(1, stream_args.channels.size())),
_stream_now(_nchan == 1),
- _tag_now(false)
+ _tag_now(false),
+ _start_time_set(false)
{
if (stream_args.cpu_format == "fc32") _type = boost::make_shared<uhd::io_type_t>(uhd::io_type_t::COMPLEX_FLOAT32);
if (stream_args.cpu_format == "sc16") _type = boost::make_shared<uhd::io_type_t>(uhd::io_type_t::COMPLEX_INT16);
@@ -363,6 +364,12 @@ public:
return num_samps;
}
+ void set_start_time(const uhd::time_spec_t &time){
+ _start_time = time;
+ _start_time_set = true;
+ _stream_now = false;
+ }
+
bool start(void){
#ifdef GR_UHD_USE_STREAM_API
_rx_stream = _dev->get_rx_stream(_stream_args);
@@ -372,7 +379,13 @@ public:
static const double reasonable_delay = 0.1; //order of magnitude over RTT
uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS);
stream_cmd.stream_now = _stream_now;
- stream_cmd.time_spec = get_time_now() + uhd::time_spec_t(reasonable_delay);
+ if (_start_time_set){
+ _start_time_set = false; //cleared for next run
+ stream_cmd.time_spec = _start_time;
+ }
+ else{
+ stream_cmd.time_spec = get_time_now() + uhd::time_spec_t(reasonable_delay);
+ }
_dev->issue_stream_cmd(stream_cmd);
_tag_now = true;
return true;
@@ -468,6 +481,9 @@ private:
bool _stream_now, _tag_now;
uhd::rx_metadata_t _metadata;
pmt::pmt_t _id;
+
+ uhd::time_spec_t _start_time;
+ bool _start_time_set;
};