a7d9d6f5ddc87027defaed48ae467aa806642291
[debian/gnuradio] / grc / scripts / usrp_diagnostics
1 #!/usr/bin/env python
2 """
3 Copyright 2008 Free Software Foundation, Inc.
4 This file is part of GNU Radio
5
6 GNU Radio Companion is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 GNU Radio Companion is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
19 """
20 ##@package Graphics.USRPDiagnostics
21 #A dialog for querying USRP subdevices. USRP interfacing methods encapsulated here.
22 #@author Josh Blum
23
24 from gnuradio import usrp
25 import os
26
27 import pygtk
28 pygtk.require('2.0')
29 import gtk
30
31 from grc.gui.Dialogs import TextDisplay
32
33 from grc_gnuradio.Platform import Platform
34 platform = Platform(block_paths_internal_only=['usrp_diagnostics.xml'])
35
36 from grc.gui.elements.Platform import Platform
37 platform = Platform(platform)
38
39 flow_graph = platform.get_new_flow_graph()
40 block = flow_graph.get_new_block('usrp_diagnostics')
41
42 ##all params
43 usrp_number_param = block.get_param('usrp_number')
44 usrp_type_param = block.get_param('usrp_type')
45 side_subdev_param = block.get_param('side_subdev')
46
47 class USRPDiagnosticsWindow(gtk.Window):
48         """
49         The main window for USRP Dignostics.
50         """
51
52         def delete_event(self, widget, event, data=None): return False
53
54         def destroy(self, widget, data=None): gtk.main_quit()
55
56         def __init__(self):
57                 """
58                 USRPDiagnosticsWindow contructor.
59                 Create a new gtk Dialog with a close button, USRP input paramaters, and output labels.
60                 """
61                 gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
62                 #quit signals
63                 self.connect("delete_event", self.delete_event)
64                 self.connect("destroy", self.destroy)
65                 #set the title
66                 self.set_title('USRP Diagnostics')
67                 #create decorative frame
68                 frame = gtk.Frame()
69                 self.add(frame)
70                 #create vbox for storage
71                 vbox = gtk.VBox()
72                 frame.add(vbox)
73                 vbox.pack_start(usrp_number_param.get_input_object(), False)
74                 vbox.pack_start(usrp_type_param.get_input_object(), False)
75                 vbox.pack_start(side_subdev_param.get_input_object(), False)
76                 self.diagnose_button = gtk.Button('Query')
77                 self.diagnose_button.connect('clicked', self._diagnose_usrp)
78                 vbox.pack_start(self.diagnose_button, False)
79                 #Create a text box for USRP queries
80                 self.query_buffer = TextDisplay()
81                 self.query_buffer.set_text('Press "Query" to retrieve USRP information...')
82                 vbox.pack_start(self.query_buffer)
83                 self.show_all()
84
85         def _diagnose_usrp(self, widget=None):
86                 """Query the USRP device and copy the results into the query text box."""
87                 type = usrp_type_param.evaluate()
88                 if type == 'rx':        #for the rx query, use the source and rx methods
89                         make = usrp.source_c
90                         get_mux = usrp.determine_rx_mux_value
91                 elif type == 'tx':      #for the tx query, use the sink and tx methods
92                         make = usrp.sink_c
93                         get_mux = usrp.determine_tx_mux_value
94                 try:
95                         u = make(usrp_number_param.evaluate())
96                         subdev_spec = eval(side_subdev_param.evaluate())
97                         subdev = usrp.selected_subdev(u, subdev_spec)#get the subdev
98                         msg = ">>> USRP Query\n"
99                         msg = "%s\nName:\n\t%s\n"%(msg, str(subdev.name()))
100                         msg = "%s\nAutomated Mux:\n\t0x%08x\n"%(msg, 0xFFFFFFFFL & long(get_mux(u, subdev_spec))) #ensure that the value is displayed as: 8 nibbles, unsigned, hex
101                         msg = "%s\nConverter Rate:\n\t%s\n"%(msg, u.converter_rate())
102                         msg = "%s\nUses Quadrature:\n\t%s\n"%(msg, str(subdev.is_quadrature()))
103                         gain_min, gain_max, gain_step = subdev.gain_range()
104                         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)
105                         freq_min, freq_max, freq_step = subdev.freq_range()
106                         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)
107                         self.query_buffer.set_text(msg)
108                 except Exception, e:    #display the error message
109                         self.query_buffer.set_text('''\
110 >>> Error\n%s
111
112 If the USRP cannot be found, make sure that the USRP is plugged-in and restart this program. \
113 If the problem persists, there may be a problem with you gnuradio installation or USB 2.0.
114 '''%str(e))
115
116 #enter the mainloop
117 gtk.gdk.threads_init()
118 gtk.gdk.threads_enter()
119 USRPDiagnosticsWindow()
120 gtk.main()
121 gtk.gdk.threads_leave()