summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnathan Corgan2012-01-27 14:00:52 -0800
committerJohnathan Corgan2012-01-27 14:00:52 -0800
commit29aa72d4499361e661886dbfe7833bcc2c6f3746 (patch)
treee4bcc65ee249bfc940909cc438c81b009c6c5c8b
parent8ddd8fbb0d780072081215db432aaf59d4a46dda (diff)
parent40e186f953abafe4fde19cf2cf34d61d801c31e2 (diff)
downloadgnuradio-29aa72d4499361e661886dbfe7833bcc2c6f3746.tar.gz
gnuradio-29aa72d4499361e661886dbfe7833bcc2c6f3746.tar.bz2
gnuradio-29aa72d4499361e661886dbfe7833bcc2c6f3746.zip
Merge branch 'gr-uhd-async-msg-recv'
-rwxr-xr-xgr-uhd/apps/uhd_fft.py16
-rwxr-xr-xgr-uhd/apps/uhd_rx_cfile.py17
-rwxr-xr-xgr-uhd/apps/uhd_rx_nogui.py15
-rwxr-xr-xgr-uhd/apps/uhd_siggen.py16
-rw-r--r--gr-uhd/include/gr_uhd_amsg_source.h7
-rw-r--r--gr-uhd/lib/gr_uhd_amsg_source.cc5
6 files changed, 69 insertions, 7 deletions
diff --git a/gr-uhd/apps/uhd_fft.py b/gr-uhd/apps/uhd_fft.py
index f311a903b..0d800d185 100755
--- a/gr-uhd/apps/uhd_fft.py
+++ b/gr-uhd/apps/uhd_fft.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2011 Free Software Foundation, Inc.
+# Copyright 2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -20,7 +20,7 @@
# Boston, MA 02110-1301, USA.
#
-from gnuradio import gr
+from gnuradio import gr, gru
from gnuradio import uhd
from gnuradio import eng_notation
from gnuradio.eng_option import eng_option
@@ -75,6 +75,8 @@ class app_top_block(stdgui2.std_top_block):
help="Set wire format from USRP [default=%default]")
parser.add_option("", "--scalar", type="int", default=1024,
help="Set scalar multiplier value sc8 wire format [default=%default]")
+ parser.add_option("", "--show-async-msg", action="store_true", default=False,
+ help="Show asynchronous message notifications from UHD [default=%default]")
(options, args) = parser.parse_args()
if len(args) != 0:
parser.print_help()
@@ -146,6 +148,16 @@ class app_top_block(stdgui2.std_top_block):
if not(self.set_freq(options.freq)):
self._set_status_msg("Failed to set initial frequency")
+ # Direct asynchronous notifications to callback function
+ if self.options.show_async_msg:
+ self.async_msgq = gr.msg_queue(0)
+ self.async_src = uhd.amsg_source("", self.async_msgq)
+ self.async_rcv = gru.msgq_runner(self.async_msgq, self.async_callback)
+
+ def async_callback(self, msg):
+ md = self.async_src.msg_to_async_metadata_t(msg)
+ print "Channel: %i Time: %f Event: %i" % (md.channel, md.time_spec.get_real_secs(), md.event_code)
+
def _set_status_msg(self, msg):
self.frame.GetStatusBar().SetStatusText(msg, 0)
diff --git a/gr-uhd/apps/uhd_rx_cfile.py b/gr-uhd/apps/uhd_rx_cfile.py
index de44d4f56..718bb80b7 100755
--- a/gr-uhd/apps/uhd_rx_cfile.py
+++ b/gr-uhd/apps/uhd_rx_cfile.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2011 Free Software Foundation, Inc.
+# Copyright 2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -26,7 +26,7 @@ outputs single precision complex float values or complex short values
(interleaved 16 bit signed short integers).
"""
-from gnuradio import gr, eng_notation
+from gnuradio import gr, gru, eng_notation
from gnuradio import uhd
from gnuradio.eng_option import eng_option
from optparse import OptionParser
@@ -106,6 +106,17 @@ class rx_cfile_block(gr.top_block):
else:
print "Writing 32-bit complex floats"
print "Output filename:", filename
+
+ # Direct asynchronous notifications to callback function
+ if options.show_async_msg:
+ self.async_msgq = gr.msg_queue(0)
+ self.async_src = uhd.amsg_source("", self.async_msgq)
+ self.async_rcv = gru.msgq_runner(self.async_msgq, self.async_callback)
+
+ def async_callback(self, msg):
+ md = self.async_src.msg_to_async_metadata_t(msg)
+ print "Channel: %i Time: %f Event: %i" % (md.channel, md.time_spec.get_real_secs(), md.event_code)
+
def get_options():
usage="%prog: [options] output_filename"
@@ -134,6 +145,8 @@ def get_options():
help="set wire format from USRP [default=%default")
parser.add_option("", "--scalar", type="int", default=1024,
help="set scalar multiplier value for sc8 wire format [default=%default]")
+ parser.add_option("", "--show-async-msg", action="store_true", default=False,
+ help="Show asynchronous message notifications from UHD [default=%default]")
(options, args) = parser.parse_args ()
if len(args) != 1:
diff --git a/gr-uhd/apps/uhd_rx_nogui.py b/gr-uhd/apps/uhd_rx_nogui.py
index e692e6ea3..bcb52c619 100755
--- a/gr-uhd/apps/uhd_rx_nogui.py
+++ b/gr-uhd/apps/uhd_rx_nogui.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2006,2007,2011 Free Software Foundation, Inc.
+# Copyright 2006,2007,2011,2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -190,6 +190,17 @@ class app_top_block(gr.top_block):
AUDIO = audio.sink(int(options.output_rate),
options.audio_output)
self.connect(tail, AUDIO)
+
+ # Direct asynchronous notifications to callback function
+ if self.options.show_async_msg:
+ self.async_msgq = gr.msg_queue(0)
+ self.async_src = uhd.amsg_source("", self.async_msgq)
+ self.async_rcv = gru.msgq_runner(self.async_msgq, self.async_callback)
+
+ def async_callback(self, msg):
+ md = self.async_src.msg_to_async_metadata_t(msg)
+ print "Channel: %i Time: %f Event: %i" % (md.channel, md.time_spec.get_real_secs(), md.event_code)
+
def main():
parser = OptionParser(option_class=eng_option)
@@ -222,6 +233,8 @@ def main():
help="set CTCSS squelch to FREQ [default=%default]")
parser.add_option("-O", "--audio-output", type="string", default="",
help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp")
+ parser.add_option("", "--show-async-msg", action="store_true", default=False,
+ help="Show asynchronous message notifications from UHD [default=%default]")
(options, args) = parser.parse_args()
if options.frequency is None:
diff --git a/gr-uhd/apps/uhd_siggen.py b/gr-uhd/apps/uhd_siggen.py
index 27e9e8e01..e1af586ae 100755
--- a/gr-uhd/apps/uhd_siggen.py
+++ b/gr-uhd/apps/uhd_siggen.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2008,2009,2011 Free Software Foundation, Inc.
+# Copyright 2008,2009,2011,2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -38,7 +38,7 @@ TYPE_KEY = 'type'
def setter(ps, key, val): ps[key] = val
-from gnuradio import gr, uhd, eng_notation
+from gnuradio import gr, gru, uhd, eng_notation
from gnuradio.gr.pubsub import pubsub
from gnuradio.eng_option import eng_option
from optparse import OptionParser
@@ -114,6 +114,16 @@ class top_block(gr.top_block, pubsub):
if self._verbose:
print str(self._u)
+ # Direct asynchronous notifications to callback function
+ if options.show_async_msg:
+ self.async_msgq = gr.msg_queue(0)
+ self.async_src = uhd.amsg_source("", self.async_msgq)
+ self.async_rcv = gru.msgq_runner(self.async_msgq, self.async_callback)
+
+ def async_callback(self, msg):
+ md = self.async_src.msg_to_async_metadata_t(msg)
+ print "Channel: %i Time: %f Event: %i" % (md.channel, md.time_spec.get_real_secs(), md.event_code)
+
def _set_tx_amplitude(self, ampl):
"""
Sets the transmit amplitude sent to the USRP
@@ -325,6 +335,8 @@ def get_options():
metavar="AMPL")
parser.add_option("-v", "--verbose", action="store_true", default=False,
help="Use verbose console output [default=%default]")
+ parser.add_option("", "--show-async-msg", action="store_true", default=False,
+ help="Show asynchronous message notifications from UHD [default=%default]")
(options, args) = parser.parse_args()
diff --git a/gr-uhd/include/gr_uhd_amsg_source.h b/gr-uhd/include/gr_uhd_amsg_source.h
index accf15ce2..3c1b59fa7 100644
--- a/gr-uhd/include/gr_uhd_amsg_source.h
+++ b/gr-uhd/include/gr_uhd_amsg_source.h
@@ -38,6 +38,13 @@ GR_UHD_API boost::shared_ptr<uhd_amsg_source> uhd_make_amsg_source(
);
class GR_UHD_API uhd_amsg_source{
+public:
+ /*!
+ * Convert a raw asynchronous message to an asynchronous metatdata object.
+ * \return The asynchronous metadata object.
+ */
+ static uhd::async_metadata_t msg_to_async_metadata_t(const gr_message_sptr msg);
+
};
#endif /* INCLUDED_GR_UHD_AMSG_SOURCE_H */
diff --git a/gr-uhd/lib/gr_uhd_amsg_source.cc b/gr-uhd/lib/gr_uhd_amsg_source.cc
index f2958f115..08941584b 100644
--- a/gr-uhd/lib/gr_uhd_amsg_source.cc
+++ b/gr-uhd/lib/gr_uhd_amsg_source.cc
@@ -75,6 +75,11 @@ protected:
bool _running;
};
+uhd::async_metadata_t uhd_amsg_source::msg_to_async_metadata_t(const gr_message_sptr msg)
+{
+ return *(uhd::async_metadata_t *)msg->msg();
+}
+
/***********************************************************************
* Make UHD Asynchronous Message Source
**********************************************************************/