probe for the usrp2
[debian/gnuradio] / grc / scripts / usrp_probe
1 #!/usr/bin/env python
2 """
3 Copyright 2009 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
21 from gnuradio import usrp
22 import os
23
24 import pygtk
25 pygtk.require('2.0')
26 import gtk
27
28 from gnuradio.grc.gui.Dialogs import TextDisplay
29
30 from gnuradio.grc.platforms.python.Platform import Platform
31 platform = Platform(block_paths_internal_only=['usrp_probe.xml'])
32
33 from gnuradio.grc.platforms.gui.Platform import Platform
34 platform = Platform(platform)
35
36 flow_graph = platform.get_new_flow_graph()
37 block = flow_graph.get_new_block('usrp_probe')
38
39 ##all params
40 usrp_number_param = block.get_param('number')
41 usrp_dboard_param = block.get_param('dboard')
42
43 class USRPProbeWindow(gtk.Window):
44         """
45         The main window for USRP Dignostics.
46         """
47
48         def delete_event(self, widget, event, data=None): return False
49
50         def destroy(self, widget, data=None): gtk.main_quit()
51
52         def __init__(self):
53                 """
54                 USRPProbeWindow contructor.
55                 Create a new gtk Dialog with a close button, USRP input paramaters, and output labels.
56                 """
57                 gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
58                 #quit signals
59                 self.connect("delete_event", self.delete_event)
60                 self.connect("destroy", self.destroy)
61                 #set the title
62                 self.set_title('USRP Probe')
63                 #create decorative frame
64                 frame = gtk.Frame()
65                 self.add(frame)
66                 #create vbox for storage
67                 vbox = gtk.VBox()
68                 frame.add(vbox)
69                 vbox.pack_start(usrp_number_param.get_input_object(), False)
70                 vbox.pack_start(usrp_dboard_param.get_input_object(), False)
71                 self.probe_button = gtk.Button('Probe')
72                 self.probe_button.connect('clicked', self._probe_usrp)
73                 vbox.pack_start(self.probe_button, False)
74                 #Create a text box for USRP queries
75                 self.query_buffer = TextDisplay()
76                 self.query_buffer.set_text(block.get_doc())
77                 vbox.pack_start(self.query_buffer)
78                 self.show_all()
79
80         def _probe_usrp(self, widget=None):
81                 """Probe the USRP device and copy the results into the query text box."""
82                 dboard = usrp_dboard_param.evaluate()
83                 side = {'a': 0, 'b': 1}[dboard[-1]]
84                 if dboard.startswith('rx'): #for the rx query, use the source and rx methods
85                         make = usrp.source_c
86                         get_mux = usrp.determine_rx_mux_value
87                 elif dboard.startswith('tx'): #for the tx query, use the sink and tx methods
88                         make = usrp.sink_c
89                         get_mux = usrp.determine_tx_mux_value
90                 try:
91                         u = make(usrp_number_param.evaluate())
92                         subdev_spec = (side, 0)
93                         subdev = usrp.selected_subdev(u, subdev_spec) #get the subdev
94                         msg = ">>> USRP Probe\n"
95                         msg = "%s\nName:\n\t%s\n"%(msg, str(subdev.name()))
96                         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
97                         msg = "%s\nConverter Rate:\n\t%s\n"%(msg, u.converter_rate())
98                         msg = "%s\nUses Quadrature:\n\t%s\n"%(msg, str(subdev.is_quadrature()))
99                         gain_min, gain_max, gain_step = subdev.gain_range()
100                         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)
101                         freq_min, freq_max, freq_step = subdev.freq_range()
102                         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)
103                         self.query_buffer.set_text(msg)
104                 except Exception, e: #display the error message
105                         self.query_buffer.set_text('''\
106 >>> Error\n%s
107
108 If the USRP cannot be found, make sure that the USRP is plugged-in and restart this program. \
109 If the problem persists, there may be a problem with you gnuradio installation or USB 2.0.
110 '''%str(e))
111
112 if __name__ == '__main__':
113         #setup icon using icon theme
114         try: gtk.window_set_default_icon(gtk.IconTheme().load_icon('gnuradio-grc', 256, 0))
115         except: pass
116         #enter the mainloop
117         USRPProbeWindow()
118         gtk.main()