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> 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>:
>>
>> 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 
>> listDiscuss-gnuradio@gnu.orghttps://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
> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
>
>
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to