88if __name__ == '__main__' :
99 import ctypes
1010 import sys
11+
1112 if sys .platform .startswith ('linux' ):
1213 try :
1314 x11 = ctypes .cdll .LoadLibrary ('libX11.so' )
1415 x11 .XInitThreads ()
1516 except :
1617 print "Warning: failed to XInitThreads()"
1718
18- import time , signal , functools
19-
20- from gnuradio import analog
21- from gnuradio import blocks
22- from gnuradio import gr
23- from gnuradio .filter import firdes
19+ import functools
20+ import signal
21+ import time
2422
23+ import bokehgui
2524from bokeh .client import push_session
2625from bokeh .plotting import curdoc
27- import bokehgui
26+ from gnuradio import analog , blocks , gr
27+ from gnuradio .filter import firdes
28+
2829
2930class top_block (gr .top_block ):
3031 def __init__ (self , doc ):
@@ -41,25 +42,38 @@ def __init__(self, doc):
4142 ##################################################
4243 # Blocks
4344 ##################################################
44- self .bokehgui_freq_sink_f_proc_0 = bokehgui .freq_sink_f_proc (1024 , firdes .WIN_BLACKMAN_hARRIS , 0 , samp_rate / 2 , "Frequency Sink" , 2 )
45- self .bokehgui_freq_sink_f_0 = bokehgui .freq_sink_f (self .doc , self .plot_lst , self .bokehgui_freq_sink_f_proc_0 )
46- self .blocks_throttle_0 = blocks .throttle (gr .sizeof_float * 1 , samp_rate ,True )
47- self .blocks_throttle_1 = blocks .throttle (gr .sizeof_float * 1 , samp_rate ,True )
48- self .analog_sig_source_x_0 = analog .sig_source_f (samp_rate , analog .GR_COS_WAVE , 5000 , 3 , 0 )
49- self .analog_sig_source_x_1 = analog .sig_source_f (samp_rate , analog .GR_COS_WAVE , 1000 , 1 , 0 )
50- self .analog_noise_source_x_0 = analog .noise_source_f (analog .GR_GAUSSIAN , 0.001 , 0 )
51- self .analog_noise_source_x_1 = analog .noise_source_f (analog .GR_GAUSSIAN , 0.01 , 0 )
45+ self .bokehgui_freq_sink_f_proc_0 = bokehgui .freq_sink_f_proc (1024 ,
46+ firdes .WIN_BLACKMAN_hARRIS ,
47+ 0 ,
48+ samp_rate / 2 ,
49+ "Frequency Sink" ,
50+ 2 )
51+ self .bokehgui_freq_sink_f_0 = bokehgui .freq_sink_f (self .doc ,
52+ self .plot_lst ,
53+ self .bokehgui_freq_sink_f_proc_0 )
54+ self .blocks_throttle_0 = blocks .throttle (gr .sizeof_float * 1 ,
55+ samp_rate , True )
56+ self .blocks_throttle_1 = blocks .throttle (gr .sizeof_float * 1 ,
57+ samp_rate , True )
58+ self .analog_sig_source_x_0 = analog .sig_source_f (samp_rate ,
59+ analog .GR_COS_WAVE ,
60+ 5000 , 3 , 0 )
61+ self .analog_sig_source_x_1 = analog .sig_source_f (samp_rate ,
62+ analog .GR_COS_WAVE ,
63+ 1000 , 1 , 0 )
64+ self .analog_noise_source_x_0 = analog .noise_source_f (
65+ analog .GR_GAUSSIAN , 0.001 , 0 )
66+ self .analog_noise_source_x_1 = analog .noise_source_f (
67+ analog .GR_GAUSSIAN , 0.01 , 0 )
5268 self .blocks_add_xx_0 = blocks .add_vff (1 )
5369 self .blocks_add_xx_1 = blocks .add_vff (1 )
5470
5571 ##################################################
5672 # Customizing the plot
5773 ##################################################
58- self .bokehgui_freq_sink_f_0 .initialize (legend_list = ['Signal (5000 Hz)' ,
59- 'Signal (1000 Hz)' ,
60- ],
61- update_time = 100
62- )
74+ self .bokehgui_freq_sink_f_0 .initialize (
75+ legend_list = ['Signal (5000 Hz)' , 'Signal (1000 Hz)' , ],
76+ update_time = 100 )
6377
6478 self .bokehgui_freq_sink_f_0 .set_x_label ('Frequency (Hz)' )
6579 self .bokehgui_freq_sink_f_0 .set_y_label ('Relative Gain (dB)' )
@@ -69,20 +83,26 @@ def __init__(self, doc):
6983 self .bokehgui_freq_sink_f_0 .set_line_style (1 , 'dashed' )
7084 self .bokehgui_freq_sink_f_0 .set_line_width (1 , 1 )
7185 self .bokehgui_freq_sink_f_0 .enable_max_hold ()
72- self .bokehgui_freq_sink_f_0 .set_layout (1 ,1 , 1 , 1 )
86+ self .bokehgui_freq_sink_f_0 .set_layout (1 , 1 , 1 , 1 )
7387
7488 self .doc .add_root (bokehgui .BokehLayout .create_layout (self .plot_lst ))
7589 ##################################################
7690 # Connections
7791 ##################################################
78- self .connect ((self .analog_sig_source_x_0 , 0 ), (self .blocks_add_xx_1 , 0 ))
79- self .connect ((self .analog_sig_source_x_1 , 0 ), (self .blocks_add_xx_0 , 0 ))
80- self .connect ((self .analog_noise_source_x_0 , 0 ), (self .blocks_add_xx_0 , 1 ))
81- self .connect ((self .analog_noise_source_x_1 , 0 ), (self .blocks_add_xx_1 , 1 ))
92+ self .connect ((self .analog_sig_source_x_0 , 0 ),
93+ (self .blocks_add_xx_1 , 0 ))
94+ self .connect ((self .analog_sig_source_x_1 , 0 ),
95+ (self .blocks_add_xx_0 , 0 ))
96+ self .connect ((self .analog_noise_source_x_0 , 0 ),
97+ (self .blocks_add_xx_0 , 1 ))
98+ self .connect ((self .analog_noise_source_x_1 , 0 ),
99+ (self .blocks_add_xx_1 , 1 ))
82100 self .connect ((self .blocks_add_xx_0 , 0 ), (self .blocks_throttle_1 , 0 ))
83101 self .connect ((self .blocks_add_xx_1 , 0 ), (self .blocks_throttle_0 , 0 ))
84- self .connect ((self .blocks_throttle_0 , 0 ), (self .bokehgui_freq_sink_f_proc_0 , 0 ))
85- self .connect ((self .blocks_throttle_1 , 0 ), (self .bokehgui_freq_sink_f_proc_0 , 1 ))
102+ self .connect ((self .blocks_throttle_0 , 0 ),
103+ (self .bokehgui_freq_sink_f_proc_0 , 0 ))
104+ self .connect ((self .blocks_throttle_1 , 0 ),
105+ (self .bokehgui_freq_sink_f_proc_0 , 1 ))
86106
87107 def get_samp_rate (self ):
88108 return self .samp_rate
@@ -91,33 +111,39 @@ def set_samp_rate(self, samp_rate):
91111 self .samp_rate = samp_rate
92112 self .blocks_throttle_0 .set_sample_rate (self .samp_rate )
93113 self .analog_sig_source_x_0 .set_sampling_freq (self .samp_rate )
94- self .bokehgui_freq_sink_f_0 .set_frequency_range ([0 , self .samp_rate / 2 ])
114+ self .bokehgui_freq_sink_f_0 .set_frequency_range (
115+ [0 , self .samp_rate / 2 ])
116+
117+
118+ def main (top_block_cls = top_block , options = None ):
119+ serverProc , port = bokehgui .utils .create_server ()
95120
96- def main (top_block_cls = top_block , options = None ):
97- serverProc = bokehgui .utils .create_server ()
98121 def killProc (signum , frame , tb ):
99122 tb .stop ()
100123 tb .wait ()
101124 serverProc .terminate ()
102125 serverProc .kill ()
126+
103127 time .sleep (1 )
104128 try :
105129 # Define the document instance
106130 doc = curdoc ()
107- session = push_session (doc , session_id = "test" )
131+ session = push_session (doc , session_id = "test" ,
132+ url = "http://localhost:" + port + "/bokehgui" )
108133 # Create Top Block instance
109134 tb = top_block_cls (doc )
110135 try :
111136 tb .start ()
112- signal .signal (signal .SIGTERM , functools .partial (killProc , tb = tb ))
137+ signal .signal (signal .SIGTERM , functools .partial (killProc , tb = tb ))
113138 session .loop_until_closed ()
114139 finally :
115140 print "Exiting the simulation. Stopping Bokeh Server"
116141 tb .stop ()
117- tb .wait ()
142+ tb .wait ()
118143 finally :
119144 serverProc .terminate ()
120145 serverProc .kill ()
121146
147+
122148if __name__ == '__main__' :
123149 main ()
0 commit comments