Skip to content

Instantly share code, notes, and snippets.

@marcusmueller
Last active December 21, 2015 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusmueller/6251825 to your computer and use it in GitHub Desktop.
Save marcusmueller/6251825 to your computer and use it in GitHub Desktop.
Testcase for timed commands. That fails.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2013 Marcus Müller.
#
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
from gnuradio import gr, blocks, uhd
class continous_frequency_hopper:
def __init__(self):
### Create blocks
self._tb = gr.top_block()
self.src = uhd.usrp_source(
"",
uhd.stream_args(
cpu_format="fc32",
channels=range(1) )
)
self.head = blocks.head(gr.sizeof_gr_complex, int(100e6))
self.sink = blocks.null_sink(gr.sizeof_gr_complex)
self.tag_debug = blocks.tag_debug(gr.sizeof_gr_complex, "src")
###setup USRP source
self.src.set_gain(30)
self.src.set_samp_rate(5e6)
self.src.set_center_freq(2e9)
###start flowgraph
self._tb.connect(self.src, self.head, self.sink)
self._tb.connect(self.src, self.tag_debug)
self._tb.start()
###get current timestamp
time_now = self.src.get_time_now().get_real_secs()
print("time: {:f} freq: {:f} MHz".format(time_now, self.src.get_center_freq()/1e6))
time_next = time_now + 1.0
next_spec = uhd.time_spec(time_next)
print("next time: {:f}".format(next_spec.get_real_secs()))
##issue timed command
self.src.set_command_time(next_spec)
self.src.set_center_freq(1e9)
print "called set_center_freq"
self.src.clear_command_time()
print "called clear_command_time"
###get current time again
time_now = self.src.get_time_now().get_real_secs()
print("time: {:f} freq: {:f} MHz".format(time_now, self.src.get_center_freq()/1e6))
if __name__ == "__main__":
continous_frequency_hopper()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment