# How to pass time tag into usrp sink as a parameter ?\[hurry.\]

**URL:** <https://www.ruby-forum.com/t/how-to-pass-time-tag-into-usrp-sink-as-a-parameter-hurry/233473>\
**Category:** GNU Radio\
**Created:** [December 16, 2014, 5:23pm UTC](https://www.ruby-forum.com/t/how-to-pass-time-tag-into-usrp-sink-as-a-parameter-hurry/233473 "2014-12-16T17:23:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [December 16, 2014, 5:23pm UTC](https://www.ruby-forum.com/t/how-to-pass-time-tag-into-usrp-sink-as-a-parameter-hurry/233473/1 "2014-12-16T17:23:16Z")

</div>

Hello,  
I would like to implement the process as follows at the Rx side: Record  
the time when the first sample arrived, and then wait for a certain  
interval and then send ack back to Tx. Meanwhile, finish the cfo  
calculating and compensating.  
Here is my whole flow graph design. (Each means a block)

```
                        pkt_dtc-> cfo_calc -> file_sink
                                         cfo_calc -> cfo_cpst
                                    file_source -> cfo_cpst -> 

```

usrp\_sink

where pkt\_dtc, grab\_time\_tag and cfo\_calc was done myself with C++.  
However, My question are:

1. Is it correct of my whole desgin (I want to implement them in one top  
block) or are there any easier solutions ?
2. After the block grab\_time\_tag, how should I pass the time information  
(directly got from the method get\_tags\_in\_range) into the usrp\_sink as a  
parameter so as to send ack at the intended time? Should I write in  
Python(but they are not the same level) or C++(but I can’t rewrite a  
usrp\_sink) ?

Any doubts or suggestions are highly appreciated !

---

<div class="post-metadata">

**Author:** ![Rui\_Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/278dde/32.png) [@Rui\_Z](https://www.ruby-forum.com/u/Rui_Z)\
**Post date:** [December 16, 2014, 5:36pm UTC](https://www.ruby-forum.com/t/how-to-pass-time-tag-into-usrp-sink-as-a-parameter-hurry/233473/2 "2014-12-16T17:36:11Z")

</div>

Hello Rui,

why do you take the detour through a file? That looks unnecessary.

the USRP sink understands transmission times you specify using tags [1],  
so this will be the easiest way to deal with this. You just need to  
write a really short block (in C++ or python, whatever you prefer) which  
takes the rx\_time tag that the USRP source added to the sample stream  
and generates a tag with the desired point in time [2].

There are some examples of the rx\_time and tx\_time tags usage in gr-uhd,  
so just search for “tx\_time” or “rx\_time” in gnuradio/gr-uhd/examples/ .

Greetings,  
Marcus

[1] [http://gnuradio.org/doc/doxygen/page\_stream\_tags.html](http://gnuradio.org/doc/doxygen/page_stream_tags.html)  
[2] [http://gnuradio.org/doc/doxygen/page\_stream\_tags.html](http://gnuradio.org/doc/doxygen/page_stream_tags.html)

---

<div class="post-metadata">

**Author:** ![Rui\_Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/278dde/32.png) [@Rui\_Z](https://www.ruby-forum.com/u/Rui_Z)\
**Post date:** [December 17, 2014, 3:46pm UTC](https://www.ruby-forum.com/t/how-to-pass-time-tag-into-usrp-sink-as-a-parameter-hurry/233473/3 "2014-12-17T15:46:45Z")

</div>

Hi, Marcus,  
I read the doc and examples you recommended, but I still don’t  
understand fully how to implement my wok.  
Sorry for my previous omission that the first line of my flow graph  
design is:  
usrp\_source -\> ptk\_dtc -\> grab\_time\_tag -\> usrp\_sink

1. Here is the work function of my grab\_time\_tag block(not finished), I  
don’t know how to code next:  
const float \*sigin = (const float \*) input\_items[0];  
const unsigned char \*detect = (const unsigned char \*)  
input\_items[1];  
pmt::pmt\_t \*out = (pmt::pmt\_t \*) output\_items[0];

2. I want to send acks at an intended time at usrp\_sink, how to pass  
this time information into usrp\_sink?  
I know a C++ method gr::uhd::usrp\_sink::set\_command\_time, but don’t know  
how to use it.  
What also confuses me is:  
if I construct a usrp\_sink object in python, how to pass the time  
information posted from grab\_time\_tag into it? (They are not at the same  
level after all). IMHO, Python is not something valuable. It’s just to  
build block objects and connect them.  
but if I do the job in C++, does it mean I have to rewrite a new  
usrp\_sink block(sounds impratical) to receive the desired time value  
posted from grab\_time\_tag ? or else?

BTW, the file\_sink/source was just for testing.  
I 'm purely a green hand. If something is wrongly understood, please  
correct me with no hesitation.  
Hope your kind reply in specific details on the two query above. Many  
thanks!

??? 2014???12???17??? 00:34, Marcus M??ller ???:

---

<div class="post-metadata">

**Author:** ![Rui\_Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/278dde/32.png) [@Rui\_Z](https://www.ruby-forum.com/u/Rui_Z)\
**Post date:** [December 17, 2014, 4:44pm UTC](https://www.ruby-forum.com/t/how-to-pass-time-tag-into-usrp-sink-as-a-parameter-hurry/233473/4 "2014-12-17T16:44:32Z")

</div>

On Wed, Dec 17, 2014 at 3:44 PM, Rui Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> const unsigned char \*detect = (const unsigned char \*) input\_items[1];  
> }  
> 2. I want to send acks at an intended time at usrp\_sink, how to pass this  
> time information into usrp\_sink?

You could tag your ACK burst with “tx\_time” to send your ACK after a  
prefered delay.  
Please look in to Bastian’s packet-pad implementation or pre-cog for  
reference

[1] [https://github.com/bastibl/gr-foo/blob/master/lib/packet\_pad\_impl.cc](https://github.com/bastibl/gr-foo/blob/master/lib/packet_pad_impl.cc)  
[2]  
[https://github.com/jmalsbury/pre-cog/blob/master/python/packet\_framer.py](https://github.com/jmalsbury/pre-cog/blob/master/python/packet_framer.py)
