1

I need help regarding gnuradio python script.

I am transmitting and receiving in usrp through binary file. Is it possible to know the time when python script start saving the data in binary file (print(rx_stream_time)--something like this) and how many samples are saved in the binary file (may be with a counter)?

I am attaching my code generated by grc flowgraph. floatgen is generated file name and check6.bin will be the rx file name.

class top_block_10(grc_wxgui.top_block_gui):
  def __init__(self):
    grc_wxgui.top_block_gui.__init__(self, title="Top Block 10")
    _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
    self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

    ##################################################
    # Variables
    ##################################################
    self.samp_rate = samp_rate = 12.5e6
    self.f = f = 2.45e9

    ##################################################
    # Blocks
    ##################################################
    self.uhd_usrp_source_0 = uhd.usrp_source(
        ",".join(("addr=172.22.77.73", "")),
        uhd.stream_args(
            cpu_format="fc32",
            channels=range(1),
        ),
    )
    self.uhd_usrp_source_0.set_clock_source("gpsdo", 0)
    self.uhd_usrp_source_0.set_time_source("gpsdo", 0)
    self.uhd_usrp_source_0.set_subdev_spec("A:0", 0)
    self.uhd_usrp_source_0.set_time_unknown_pps(uhd.time_spec())
    self.uhd_usrp_source_0.set_samp_rate(samp_rate)
    self.uhd_usrp_source_0.set_center_freq(f, 0)
    self.uhd_usrp_source_0.set_gain(27, 0)
    self.uhd_usrp_source_0.set_antenna("RX2", 0)
    self.uhd_usrp_sink_0 = uhd.usrp_sink(
        ",".join(("addr=172.22.77.73", "")),
        uhd.stream_args(
            cpu_format="fc32",
            channels=range(1),
        ),
    )
    self.uhd_usrp_sink_0.set_clock_source("gpsdo", 0)
    self.uhd_usrp_sink_0.set_time_source("gpsdo", 0)
    self.uhd_usrp_sink_0.set_subdev_spec("A:0", 0)
    self.uhd_usrp_sink_0.set_time_unknown_pps(uhd.time_spec())
    self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
    self.uhd_usrp_sink_0.set_center_freq(2.45e9, 0)
    self.uhd_usrp_sink_0.set_gain(0, 0)
    self.uhd_usrp_sink_0.set_antenna("TX/RX", 0)
    self.blocks_throttle_3 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate*2,True)
    self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate*2,True)
    self.blocks_file_source_0 = blocks.file_source(gr.sizeof_gr_complex*1, "/home/sanjoy/Desktop/SISO gen file/floatgen.bin", True)
    self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex*1, "/home/sanjoy/check6.bin", False)
    self.blocks_file_sink_0.set_unbuffered(False)

TIA and please let me know how to do that.

best regards

Sanjoy

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94

1 Answers1

1

The USRP sends an rx_time tag when the RX starts or when an overflow occurs. To get this tag you may use the Tag Debug block, that prints the tag of a stream. However for better handling, I would suggest the Tagged Stream to PDU block that converts a tag of a stream to a message. Then the message can be used with various other blocks to get the information that you want.

For the second part of your question. If you know exactly the file size, you can find easily the number of samples by dividing the file size with the size of each sample.

For example: A file with gr_complex samples of size 2048 bytes contains 2048/sizeof(gr_complex) = 2048/8 = 256 samples.

Manos
  • 2,136
  • 17
  • 28