""" Copyright 2012 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 """ MAIN_TMPL = """\ OsmoSDR $sourk.title() osmosdr_$(sourk)_c 1 import osmosdr osmosdr.$(sourk)_c( args="nchan=" + str(\$nchan) + " " + \$args ) self.\$(id).set_sample_rate(\$sample_rate) #for $n in range($max_nchan) \#if \$nchan() > $n self.\$(id).set_center_freq(\$freq$(n), $n) self.\$(id).set_freq_corr(\$corr$(n), $n) self.\$(id).set_gain_mode(\$gain_mode$(n), $n) self.\$(id).set_gain(\$gain$(n), $n) \#if \$ant$(n)() self.\$(id).set_antenna(\$ant$(n), $n) \#end if \#end if #end for set_sample_rate(\$sample_rate) #for $n in range($max_nchan) set_center_freq(\$freq$(n), $n) set_freq_corr(\$corr$(n), $n) set_gain_mode(\$gain_mode$(n), $n) set_gain(\$gain$(n), $n) set_antenna(\$ant$(n), $n) #end for $(dir.title())put Type type enum Device Arguments args string \#if \$args() none \#else part \#end if Num Channels nchan 1 int #for $n in range(1, $max_nchan+1) #end for Sample Rate (sps) sample_rate samp_rate real $params $max_nchan >= \$nchan \$nchan > 0 <$sourk> $dir \$type.type \$nchan The OsmoSDR $sourk.title() block: While primarily being developed for the OsmoSDR hardware, this block also supports the FunCube Dongle, Ettus UHD, rtl-sdr radios and cfile source. By using the OsmoSDR block you can take advantage of a common software api in your application(s) independent of the underlying radio hardware. Output Type: This parameter controls the data type of the stream in gnuradio. Device Arguments: The device argument is a delimited string used to locate devices on your system. Use the device id or name (if applicable) to specify a specific device or list of devices. If left blank, the first device found will be used. Examples: fcd=0 fcd=1 fcd=2 ... rtl=0 rtl=1 rtl=2,rtl_xtal=28.80001e6,tuner_xtal=26e6,buffers=64 ... uhd=0|name,mcr=52e6,nchan=2,subdev='\\\\'B:0 A:0'\\\\' ... osmosdr=0|name,mcr=64e6,nchan=5,port=/dev/ttyUSB0 ... file=/path/to/file.ext,freq=428e6,rate=1e6,repeat=true,throttle=true Num Channels: Selects the total number of channels in this multi-device configuration. Sample Rate: The sample rate is the number of samples per second output by this block. Frequency: The center frequency is the overall frequency of the RF chain. Freq. Corr.: The frequency correction factor in parts per million (ppm). Leave 0 if unknown. Gain: Overall gain of the device's signal path. For the new gain value to be applied, the manual gain mode must be enabled first. Gain Mode: Chooses between the manual (default) and automatic gain mode where appropriate. Currently, only rtlsdr devices support automatic gain mode. Antenna: For devices with only one antenna, this may be left blank. Otherwise, the user should specify one of the possible antenna choices. See the OsmoSDR project page for more detailed documentation: http://sdr.osmocom.org/trac/ http://sdr.osmocom.org/trac/wiki/GrOsmoSDR """ PARAMS_TMPL = """ Ch$(n): Frequency (Hz) freq$(n) 0 real \#if \$nchan() > $n then 'none' else 'all'# Ch$(n): Freq. Corr. (ppm) corr$(n) 0 real \#if \$nchan() > $n then 'none' else 'all'# Ch$(n): Gain (dB) gain$(n) 0 real \#if \$nchan() > $n then 'none' else 'all'# Ch$(n): Gain Mode gain_mode$(n) enum \#if \$nchan() > $n then 'none' else 'all'# Ch$(n): Antenna ant$(n) string \#if not \$nchan() > $n all \#elif \$ant$(n)() none \#else part \#end if """ def parse_tmpl(_tmpl, **kwargs): from Cheetah import Template return str(Template.Template(_tmpl, kwargs)) max_num_channels = 5 if __name__ == '__main__': import sys for file in sys.argv[1:]: if file.endswith ('source_c.xml'): sourk = 'source' dir = 'out' elif file.endswith ('sink_c.xml'): sourk = 'sink' dir = 'in' else: raise Exception, 'is %s a source or sink?'%file params = ''.join([parse_tmpl(PARAMS_TMPL, n=n) for n in range(max_num_channels)]) open(file, 'w').write(parse_tmpl(MAIN_TMPL, max_nchan=max_num_channels, params=params, sourk=sourk, dir=dir, ))