diff options
Diffstat (limited to 'gr-uhd')
-rw-r--r-- | gr-uhd/lib/uhd_mimo_sink.cc | 4 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_mimo_sink.h | 6 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_mimo_source.cc | 33 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_mimo_source.h | 6 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_simple_sink.cc | 4 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_simple_sink.h | 6 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_simple_source.cc | 4 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_simple_source.h | 6 |
8 files changed, 65 insertions, 4 deletions
diff --git a/gr-uhd/lib/uhd_mimo_sink.cc b/gr-uhd/lib/uhd_mimo_sink.cc index 9226d6004..6d603d7bc 100644 --- a/gr-uhd/lib/uhd_mimo_sink.cc +++ b/gr-uhd/lib/uhd_mimo_sink.cc @@ -92,6 +92,10 @@ public: return _dev->get_tx_antennas(chan); } + uhd::time_spec_t get_time_now(void){ + return _dev->get_time_now(); + } + void set_time_next_pps(const uhd::time_spec_t &time_spec){ return _dev->set_time_next_pps(time_spec); } diff --git a/gr-uhd/lib/uhd_mimo_sink.h b/gr-uhd/lib/uhd_mimo_sink.h index 280f7c0e8..951980908 100644 --- a/gr-uhd/lib/uhd_mimo_sink.h +++ b/gr-uhd/lib/uhd_mimo_sink.h @@ -114,6 +114,12 @@ public: virtual std::vector<std::string> get_antennas(size_t chan) = 0; /*! + * Get the current time registers. + * \return the current usrp time + */ + virtual uhd::time_spec_t get_time_now(void) = 0; + + /*! * Set the time registers at the next pps (across all mboards). * \param time_spec the new time */ diff --git a/gr-uhd/lib/uhd_mimo_source.cc b/gr-uhd/lib/uhd_mimo_source.cc index bcd6aa695..fb811572b 100644 --- a/gr-uhd/lib/uhd_mimo_source.cc +++ b/gr-uhd/lib/uhd_mimo_source.cc @@ -46,10 +46,11 @@ public: { _dev = uhd::usrp::mimo_usrp::make(args); set_streaming(false); + sync_times(); //TODO may want option to disable this } ~uhd_mimo_source_impl(void){ - //NOP + set_streaming(false); } void set_samp_rate_all(double rate){ @@ -93,6 +94,10 @@ public: return _dev->get_rx_antennas(chan); } + uhd::time_spec_t get_time_now(void){ + return _dev->get_time_now(); + } + void set_time_next_pps(const uhd::time_spec_t &time_spec){ return _dev->set_time_next_pps(time_spec); } @@ -126,13 +131,33 @@ protected: const uhd::io_type_t _type; bool _is_streaming; + void sync_times(void){ + //set the times to zero at the next pps and sleep (race condition) + set_time_next_pps(uhd::time_spec_t(0, 0)); sleep(1); + + //catch the seconds rollover at the next pps + double last_frac_secs = 0.0, curr_frac_secs = 0.0; + while(curr_frac_secs > last_frac_secs){ + last_frac_secs = curr_frac_secs; + curr_frac_secs = get_time_now().get_frac_secs(); + } + + //set the times to zero at the next pps and sleep (all boards synced) + set_time_next_pps(uhd::time_spec_t(0, 0)); sleep(1); + } + void set_streaming(bool enb){ - if (enb){ //FIXME TODO handle this better + if (enb){ + //make an estimate of the trip time + uhd::time_spec_t time1 = get_time_now(); + uhd::time_spec_t time2 = get_time_now(); + double rtt = 2*(time2 - time1).get_real_secs(); + + //setup a stream command that starts streaming slightly in the future uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS); stream_cmd.stream_now = false; - stream_cmd.time_spec = uhd::time_spec_t(1, 0); + stream_cmd.time_spec = time2 + uhd::time_spec_t(0, (_dev->get_num_channels()+1)*rtt); _dev->issue_stream_cmd(stream_cmd); - sleep(1); } else _dev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS); diff --git a/gr-uhd/lib/uhd_mimo_source.h b/gr-uhd/lib/uhd_mimo_source.h index 916f50972..e234779df 100644 --- a/gr-uhd/lib/uhd_mimo_source.h +++ b/gr-uhd/lib/uhd_mimo_source.h @@ -114,6 +114,12 @@ public: virtual std::vector<std::string> get_antennas(size_t chan) = 0; /*! + * Get the current time registers. + * \return the current usrp time + */ + virtual uhd::time_spec_t get_time_now(void) = 0; + + /*! * Set the time registers at the next pps (across all mboards). * \param time_spec the new time */ diff --git a/gr-uhd/lib/uhd_simple_sink.cc b/gr-uhd/lib/uhd_simple_sink.cc index 1443490cd..d4bb7d437 100644 --- a/gr-uhd/lib/uhd_simple_sink.cc +++ b/gr-uhd/lib/uhd_simple_sink.cc @@ -95,6 +95,10 @@ public: return _dev->set_clock_config(clock_config); } + uhd::time_spec_t get_time_now(void){ + return _dev->get_time_now(); + } + void set_time_now(const uhd::time_spec_t &time_spec){ return _dev->set_time_now(time_spec); } diff --git a/gr-uhd/lib/uhd_simple_sink.h b/gr-uhd/lib/uhd_simple_sink.h index aad90d098..7f1596259 100644 --- a/gr-uhd/lib/uhd_simple_sink.h +++ b/gr-uhd/lib/uhd_simple_sink.h @@ -111,6 +111,12 @@ public: virtual void set_clock_config(const uhd::clock_config_t &clock_config) = 0; /*! + * Get the current time registers. + * \return the current usrp time + */ + virtual uhd::time_spec_t get_time_now(void) = 0; + + /*! * Set the time registers asap. * \param time_spec the new time */ diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index c680aa313..c734e9244 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -96,6 +96,10 @@ public: return _dev->set_clock_config(clock_config); } + uhd::time_spec_t get_time_now(void){ + return _dev->get_time_now(); + } + void set_time_now(const uhd::time_spec_t &time_spec){ return _dev->set_time_now(time_spec); } diff --git a/gr-uhd/lib/uhd_simple_source.h b/gr-uhd/lib/uhd_simple_source.h index 06e4d2431..8568fc2d4 100644 --- a/gr-uhd/lib/uhd_simple_source.h +++ b/gr-uhd/lib/uhd_simple_source.h @@ -111,6 +111,12 @@ public: virtual void set_clock_config(const uhd::clock_config_t &clock_config) = 0; /*! + * Get the current time registers. + * \return the current usrp time + */ + virtual uhd::time_spec_t get_time_now(void) = 0; + + /*! * Set the time registers asap. * \param time_spec the new time */ |