In case anyone is interested, I got this to work with code similar to the following. Note that “usrp_alias” must be fetched from an already constructed usrp_sink object, for instance using “self.usrp.alias()” in a Python-based flowgraph.
// gr-my-oot/include/my-oot/clock_manager.h class MY_OOT_API clock_manager : virtual public gr::block { … public: static sptr make(const std::string &usrp_alias); … } // gr-my-oot/lib/clock_manager_impl.h #include <gnuradio/uhd/usrp_sink.h> class clock_manager_impl : public clock_manager { private: gr::uhd::usrp_sink::sptr d_usrp; … } // gr-my-oot/lib/clock_manager_impl.cc #include <gnuradio/block_registry.h> #include <boost/pointer_cast.hpp> #include <pmt/pmt.h> clock_manager_impl::clock_manager_impl(const std::string &usrp_alias) : gr::block(“clock_manager”, …) { basic_block_sptr blk; std::vector<std::string> sensors; try { blk = global_block_registry.block_lookup(pmt::intern(usrp_alias)); d_usrp = boost::dynamic_pointer_cast<gr::uhd::usrp_sink>(blk); } catch(const std::runtime_error& err) { std::cerr << “Unable to find USRP instance in block registry.” << std::endl; } if(d_usrp) { try { std::vector<std::string> sensors; bool found_gpsdo = false; sensors = d_usrp->get_mboard_sensor_names(0); for(std::vector<std::string>::const_iterator it = sensors.begin(); it != sensors.end(); it++) { if(*it == “gps_locked”) { found_gps = true; break; } } if(!found_gpsdo) std::cerr << "USRP device does not have a GPSDO installed." << std::endl; } catch(const std::runtime_error &err) { std::cerr << “Unable to query a valid USRP device.” << std::endl; } } else { std::cerr << “USRP shared pointer is not valid.” << std::endl; } } From: discuss-gnuradio-bounces+sean.nowlan=gtri.gatech....@gnu.org [mailto:discuss-gnuradio-bounces+sean.nowlan=gtri.gatech....@gnu.org] On Behalf Of Martin Braun Sent: Friday, January 29, 2016 5:35 AM To: Marcus Müller <marcus.muel...@ettus.com> Cc: discuss-gnuradio@gnu.org Subject: Re: [Discuss-gnuradio] USRP control thread in GR block - how do I pass a USRP sptr? Marcus is right, but your approach should technically work as well. I rarely get C++ polymorphisms and pointers right at first go, but using dynamic_pointer_cast should work and be safe - ish. M On 29 Jan 2016 10:28, "Marcus Müller" <marcus.muel...@ettus.com<mailto:marcus.muel...@ettus.com>> wrote: Sorry, I just got a friendly reminder that this is a bad idea in many ways; the recommended way of getting a handle to your USRP block is passing the block alias around and looking it up in the block registry; that's why we have it anyway. Make sure the result of the lookup is valid! Best regards, Marcus Am 29. Januar 2016 09:13:42 MEZ, schrieb "Marcus Müller" <marcus.muel...@ettus.com<mailto:marcus.muel...@ettus.com>>: Hi Sean, it's been a while since I did that, but I think that "smart_ptr<A> cannot be casted to smart_ptr<B>" can be remedied using Boost's pointer_cast[1]. Hope that gives you a start. Best regards, Marcus [1] http://www.boost.org/doc/libs/1_60_0/libs/smart_ptr/pointer_cast.html On 01/28/2016 08:34 PM, Nowlan, Sean wrote: I have a USRP with a GPSDO. I am working on a block that will poll a USRP for PPS changes in an attempt to adjust for clock offset between host and USRP. Assume I have explicitly set the USRP time-of-day correctly to UTC using PPS and a set_time_next_pps_call, and GPS is locked. I would like to pass a USRP sink (or source) shared pointer to this block. It will have its own internal thread that will loop waiting for PPS edge transitions, polling with get_time_now, and then measuring offset between PC/system clock and USRP clock. Following guidance from a mailing list thread [1], I attempted to pass a usrp_sink shared pointer as a basic_block_sptr and then dynamic_cast it in the block xtor. Here’s the error I get: clock_manager_impl.cc: In constructor ‘gr::mymodule::clock_manager_impl::clock_manager_impl(gr::basic_block_sptr, double, const string&)’: clock_manager_impl.cc:50:59: error: cannot dynamic_cast ‘usrp’ (of type ‘gr::basic_block_sptr {aka class boost::shared_ptr<gr::basic_block>}’) to type ‘gr::uhd::usrp_sink::sptr {aka class boost::shared_ptr<gr::uhd::usrp_sink>}’ (target is not pointer or reference) d_usrp(dynamic_cast<gr::uhd::usrp_sink::sptr>(usrp)), Any advice on the best way to do this? Is my approach sane? Thanks, Sean _______________________________________________ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org<mailto:Discuss-gnuradio@gnu.org> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio -- Sent from my Android device with K-9 Mail. Please excuse my brevity. _______________________________________________ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org<mailto:Discuss-gnuradio@gnu.org> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
_______________________________________________ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio