#!/usr/bin/env python
#
-# Copyright 2005,2006 Free Software Foundation, Inc.
+# Copyright 2005,2006,2009 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio 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, or (at your option)
+# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
import os
# from current dir
-from transmit_path import transmit_path
-from receive_path import receive_path
-import fusb_options
+import usrp_transmit_path
+import usrp_receive_path
#print os.getpid()
#raw_input('Attach and press enter')
# the flow graph
# /////////////////////////////////////////////////////////////////////////////
-class my_graph(gr.flow_graph):
+class my_top_block(gr.top_block):
def __init__(self, mod_class, demod_class,
rx_callback, options):
- gr.flow_graph.__init__(self)
- self.txpath = transmit_path(self, mod_class, options)
- self.rxpath = receive_path(self, demod_class, rx_callback, options)
+ gr.top_block.__init__(self)
+ self.txpath = usrp_transmit_path.usrp_transmit_path(mod_class, options)
+ self.rxpath = usrp_receive_path.usrp_receive_path(demod_class, rx_callback, options)
+ self.connect(self.txpath)
+ self.connect(self.rxpath)
def send_pkt(self, payload='', eof=False):
return self.txpath.send_pkt(payload, eof)
def __init__(self, tun_fd, verbose=False):
self.tun_fd = tun_fd # file descriptor for TUN/TAP interface
self.verbose = verbose
- self.fg = None # flow graph (access to PHY)
+ self.tb = None # top block (access to PHY)
- def set_flow_graph(self, fg):
- self.fg = fg
+ def set_top_block(self, tb):
+ self.tb = tb
def phy_rx_callback(self, ok, payload):
"""
while 1:
payload = os.read(self.tun_fd, 10*1024)
if not payload:
- self.fg.send_pkt(eof=True)
+ self.tb.send_pkt(eof=True)
break
if self.verbose:
print "Tx: len(payload) = %4d" % (len(payload),)
delay = min_delay
- while self.fg.carrier_sensed():
+ while self.tb.carrier_sensed():
sys.stderr.write('B')
time.sleep(delay)
if delay < 0.050:
delay = delay * 2 # exponential back-off
- self.fg.send_pkt(payload)
+ self.tb.send_pkt(payload)
# /////////////////////////////////////////////////////////////////////////////
parser = OptionParser (option_class=eng_option, conflict_handler="resolve")
expert_grp = parser.add_option_group("Expert")
-
+ expert_grp.add_option("", "--rx-freq", type="eng_float", default=None,
+ help="set Rx frequency to FREQ [default=%default]", metavar="FREQ")
+ expert_grp.add_option("", "--tx-freq", type="eng_float", default=None,
+ help="set transmit frequency to FREQ [default=%default]", metavar="FREQ")
parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
default='gmsk',
help="Select modulation from: %s [default=%%default]"
expert_grp.add_option("","--tun-device-filename", default="/dev/net/tun",
help="path to tun device file [default=%default]")
- transmit_path.add_options(parser, expert_grp)
- receive_path.add_options(parser, expert_grp)
+ usrp_transmit_path.add_options(parser, expert_grp)
+ usrp_receive_path.add_options(parser, expert_grp)
for mod in mods.values():
mod.add_options(expert_grp)
for demod in demods.values():
demod.add_options(expert_grp)
- fusb_options.add_options(expert_grp)
-
(options, args) = parser.parse_args ()
if len(args) != 0:
parser.print_help(sys.stderr)
sys.exit(1)
- if options.rx_freq is None or options.tx_freq is None:
- sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
- parser.print_help(sys.stderr)
- sys.exit(1)
-
# open the TUN/TAP interface
(tun_fd, tun_ifname) = open_tun_interface(options.tun_device_filename)
# build the graph (PHY)
- fg = my_graph(mods[options.modulation],
- demods[options.modulation],
- mac.phy_rx_callback,
- options)
+ tb = my_top_block(mods[options.modulation],
+ demods[options.modulation],
+ mac.phy_rx_callback,
+ options)
- mac.set_flow_graph(fg) # give the MAC a handle for the PHY
+ mac.set_top_block(tb) # give the MAC a handle for the PHY
- if fg.txpath.bitrate() != fg.rxpath.bitrate():
+ if tb.txpath.bitrate() != tb.rxpath.bitrate():
print "WARNING: Transmit bitrate = %sb/sec, Receive bitrate = %sb/sec" % (
- eng_notation.num_to_str(fg.txpath.bitrate()),
- eng_notation.num_to_str(fg.rxpath.bitrate()))
+ eng_notation.num_to_str(tb.txpath.bitrate()),
+ eng_notation.num_to_str(tb.rxpath.bitrate()))
print "modulation: %s" % (options.modulation,)
print "freq: %s" % (eng_notation.num_to_str(options.tx_freq))
- print "bitrate: %sb/sec" % (eng_notation.num_to_str(fg.txpath.bitrate()),)
- print "samples/symbol: %3d" % (fg.txpath.samples_per_symbol(),)
- #print "interp: %3d" % (fg.txpath.interp(),)
- #print "decim: %3d" % (fg.rxpath.decim(),)
+ print "bitrate: %sb/sec" % (eng_notation.num_to_str(tb.txpath.bitrate()),)
+ print "samples/symbol: %3d" % (tb.txpath.samples_per_symbol(),)
+ #print "interp: %3d" % (tb.txpath.interp(),)
+ #print "decim: %3d" % (tb.rxpath.decim(),)
- fg.rxpath.set_carrier_threshold(options.carrier_threshold)
+ tb.rxpath.set_carrier_threshold(options.carrier_threshold)
print "Carrier sense threshold:", options.carrier_threshold, "dB"
print
print
- fg.start() # Start executing the flow graph (runs in separate threads)
+ tb.start() # Start executing the flow graph (runs in separate threads)
mac.main_loop() # don't expect this to return...
- fg.stop() # but if it does, tell flow graph to stop.
- fg.wait() # wait for it to finish
+ tb.stop() # but if it does, tell flow graph to stop.
+ tb.wait() # wait for it to finish
if __name__ == '__main__':