summaryrefslogtreecommitdiff
path: root/grc/scripts/usrp_probe
blob: 3d7b6f0cbb521bef5893f6448d2f2a1c0b22685b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python
"""
Copyright 2009 Free Software Foundation, Inc.
This file is part of GNU Radio

GNU Radio Companion 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 2
of the License, or (at your option) any later version.

GNU Radio Companion 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 program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
"""

from gnuradio import usrp
import os

import pygtk
pygtk.require('2.0')
import gtk

from gnuradio.grc.gui.Dialogs import TextDisplay

from gnuradio.grc.platforms.python.Platform import Platform
platform = Platform(block_paths_internal_only=['usrp_probe.xml'])

from gnuradio.grc.platforms.gui.Platform import Platform
platform = Platform(platform)

flow_graph = platform.get_new_flow_graph()
block = flow_graph.get_new_block('usrp_probe')

##all params
usrp_which_param = block.get_param('which')
usrp_dboard_param = block.get_param('dboard')

class USRPProbeWindow(gtk.Window):
	"""
	The main window for USRP Dignostics.
	"""

	def delete_event(self, widget, event, data=None): return False

	def destroy(self, widget, data=None): gtk.main_quit()

	def __init__(self):
		"""
		USRPProbeWindow contructor.
		Create a new gtk Dialog with a close button, USRP input paramaters, and output labels.
		"""
		gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
		#quit signals
		self.connect("delete_event", self.delete_event)
		self.connect("destroy", self.destroy)
		#set the title
		self.set_title('USRP Probe')
		#create decorative frame
		frame = gtk.Frame()
		self.add(frame)
		#create vbox for storage
		vbox = gtk.VBox()
		frame.add(vbox)
		vbox.pack_start(usrp_which_param.get_input_object(), False)
		vbox.pack_start(usrp_dboard_param.get_input_object(), False)
		self.probe_button = gtk.Button('Probe')
		self.probe_button.connect('clicked', self._probe_usrp)
		vbox.pack_start(self.probe_button, False)
		#Create a text box for USRP queries
		self.query_buffer = TextDisplay()
		self.query_buffer.set_text(block.get_doc())
		vbox.pack_start(self.query_buffer)
		self.show_all()

	def _probe_usrp(self, widget=None):
		"""Probe the USRP device and copy the results into the query text box."""
		dboard = usrp_dboard_param.evaluate()
		side = {'a': 0, 'b': 1}[dboard[-1]]
		if dboard.startswith('rx'): make = usrp.source_c
		elif dboard.startswith('tx'): make = usrp.sink_c
		try:
			u = make(which=usrp_which_param.evaluate())
			subdev_spec = (side, 0)
			subdev = usrp.selected_subdev(u, subdev_spec) #get the subdev
			msg = ">>> USRP Probe\n"
			msg = "%s\nName:\n\t%s\n"%(msg, str(subdev.name()))
			msg = "%s\nConverter Rate:\n\t%s\n"%(msg, u.converter_rate())
			msg = "%s\nUses Quadrature:\n\t%s\n"%(msg, str(subdev.is_quadrature()))
			gain_min, gain_max, gain_step = subdev.gain_range()
			msg = "%s\nGain Range (min, max, step size):\n\t%s\n\t%s\n\t%s\n"%(msg, gain_min, gain_max, gain_step)
			freq_min, freq_max, freq_step = subdev.freq_range()
			msg = "%s\nFreq Range (min, max, step size):\n\t%s\n\t%s\n\t%s\n"%(msg, freq_min, freq_max, freq_step)
			self.query_buffer.set_text(msg)
		except Exception, e: #display the error message
			self.query_buffer.set_text('''\
>>> Error\n%s

If the USRP cannot be found, make sure that the USRP is plugged-in and restart this program. \
If the problem persists, there may be a problem with you gnuradio installation or USB 2.0.
'''%str(e))

if __name__ == '__main__':
	#setup icon using icon theme
	try: gtk.window_set_default_icon(gtk.IconTheme().load_icon('gnuradio-grc', 256, 0))
	except: pass
	#enter the mainloop
	USRPProbeWindow()
	gtk.main()