def __init__(self,Freq): 
        global parser
        parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
	expert_grp = parser.add_option_group("Expert")
	parser.add_option("-s", "--size", type="eng_float", default=1024, help="set packet size [default=%default]")
	parser.add_option("-M", "--megabytes", type="eng_float", default=10.0, help="set megabytes to transmit [default=%default]")
	parser.add_option("","--discontinuous", action="store_true", default=False, help="enable discontinuous mode")
	parser.add_option("","--from-file", default=None, help="use file for packet contents")
        parser.add_option("-e", "--interface", type="string", default="eth0", help="Select ethernet interface. Default is eth0")
	parser.add_option("-m", "--MAC_addr", type="string", default="", help="Select USRP2 by its MAC address.Default is auto-select")
	parser.add_option("-j", "--start", type="eng_float", default=1e7, help="Start ferquency [default = %default]")
	parser.add_option("-k", "--stop", type="eng_float", default=1e8,help="Stop ferquency [default = %default]")
	parser.add_option("", "--tune-delay", type="eng_float", default=1e-3, metavar="SECS", help="time to delay (in seconds) after changing frequency[default=%default]")
	parser.add_option("", "--dwell-delay", type="eng_float",default=1e-3, metavar="SECS", help="time to dwell (in seconds) at a given frequncy[default=%default]")
	parser.add_option("-G", "--gain", type="eng_float", default=None,help="set gain in dB (default is midpoint)")
	parser.add_option("-s", "--fft-size", type="int", default=256, help="specify number of FFT bins [default=%default]")# changed default value(256)
	parser.add_option("-d", "--decim", type="intx", default=16, help="set decimation to DECIM [default=%default]")	# changed default value(16)
        parser.add_option("-i", "--input_file", default="", help="radio input file",metavar="FILE")
        parser.add_option("-S", "--sense-bins", type="int", default=128, help="set number of bins in the OFDM block [default=%default]")
	
	usrp_transmit_path.add_options(parser, expert_grp)
	ofdm.ofdm_mod.add_options(parser, expert_grp)
	(self.options, self.args) = parser.parse_args ()
	if len(self.args) != 0:
		parser.print_help()
		sys.exit(1)
	if self.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)
	self.options.tx_freq=Freq.value
	self.tb = transmit(self.options)
	r = gr.enable_realtime_scheduling()
	if r != gr.RT_OK:
		print "Warning: failed to enable realtime scheduling"
Esempio n. 2
0
    def __init__(self,Freq): 
        global parser
        parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
	expert_grp = parser.add_option_group("Expert")
	parser.add_option("-s", "--size", type="eng_float", default=1024, help="set packet size [default=%default]")
	parser.add_option("-M", "--megabytes", type="eng_float", default=1.0, help="set megabytes to transmit [default=%default]")
	parser.add_option("","--discontinuous", action="store_true", default=False, help="enable discontinuous mode")
	parser.add_option("","--from-file", default=None, help="use file for packet contents")
        parser.add_option("-e", "--interface", type="string", default="eth0", help="Select ethernet interface. Default is eth0")
	parser.add_option("-m", "--MAC_addr", type="string", default="", help="Select USRP2 by its MAC address.Default is auto-select")
	parser.add_option("-j", "--start", type="eng_float", default=1e7, help="Start ferquency [default = %default]")
	parser.add_option("-k", "--stop", type="eng_float", default=1e8,help="Stop ferquency [default = %default]")
	parser.add_option("", "--tune-delay", type="eng_float", default=1e-3, metavar="SECS", help="time to delay (in seconds) after changing frequency[default=%default]")
	parser.add_option("", "--dwell-delay", type="eng_float",default=2e-3, metavar="SECS", help="time to dwell (in seconds) at a given frequncy[default=%default]")
	parser.add_option("-G", "--gain", type="eng_float", default=None,help="set gain in dB (default is midpoint)")
	parser.add_option("-s", "--fft-size", type="int", default=256, help="specify number of FFT bins [default=%default]")# changed default value(256)
	parser.add_option("-d", "--decim", type="intx", default=4, help="set decimation to DECIM [default=%default]")	# changed default value(16)
        parser.add_option("-i", "--input_file", default="", help="radio input file",metavar="FILE")
        parser.add_option("-S", "--sense-bins", type="int", default=128, help="set number of bins in the OFDM block [default=%default]")
	
	usrp_transmit_path.add_options(parser, expert_grp)
	ofdm.ofdm_mod.add_options(parser, expert_grp)
	(self.options, self.args) = parser.parse_args ()
	if len(self.args) != 0:
		parser.print_help()
		sys.exit(1)
	if self.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)
	self.options.tx_freq=Freq.value
	self.tb = transmit(self.options)
	r = gr.enable_realtime_scheduling()
	if r != gr.RT_OK:
		print "Warning: failed to enable realtime scheduling"
    def __init__(self,Freq): 
        global parser
        parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
        parser.add_option("-a", "--args", type="string", default="", help="UHD device address [default=%default]")
	expert_grp = parser.add_option_group("Expert")
	parser.add_option("-s", "--size", type="eng_float", default=400, help="set packet size [default=%default]")
	parser.add_option("-M", "--megabytes", type="eng_float", default=1.0, help="set megabytes to transmit [default=%default]")
	parser.add_option("","--discontinuous", action="store_true", default=False, help="enable discontinuous mode")
	parser.add_option("","--from-file", default=None, help="use file for packet contents")
        parser.add_option("-e", "--interface", type="string", default="eth0", help="Select ethernet interface. Default is eth0")
	parser.add_option("-m", "--MAC_addr", type="string", default="", help="Select USRP2 by its MAC address.Default is auto-select")
	parser.add_option("-j", "--start", type="eng_float", default=1e7, help="Start ferquency [default = %default]")
	parser.add_option("-k", "--stop", type="eng_float", default=1e8,help="Stop ferquency [default = %default]")
	parser.add_option("", "--tune-delay", type="eng_float", default=1e-3, metavar="SECS", help="time to delay (in seconds) after changing frequency[default=%default]")
	parser.add_option("", "--dwell-delay", type="eng_float",default=1e-3, metavar="SECS", help="time to dwell (in seconds) at a given frequncy[default=%default]")
	parser.add_option("-G", "--gain", type="eng_float", default=None,help="set gain in dB (default is midpoint)")
	parser.add_option("-s", "--fft-size", type="int", default=512, help="specify number of FFT bins [default=%default]")
	parser.add_option("-d", "--decim", type="intx", default=16, help="set decimation to DECIM [default=%default]")
        parser.add_option("-i", "--input_file", default="", help="radio input file",metavar="FILE")
        parser.add_option("-S", "--sense-bins", type="int", default=128, help="set number of bins in the OFDM block [default=%default]")
	
	usrp_transmit_path.add_options(parser, expert_grp)
	ofdm.ofdm_mod.add_options(parser, expert_grp)

	(self.options, self.args) = parser.parse_args ()
	#fd= os.open('/home/spann/Dropbox/spec_sense/fifo',os.O_RDONLY) # Open the named pipe to pass on the sensed info to the transmitter part

	if len(self.args) != 0:
		parser.print_help()
		sys.exit(1)

	#if self.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)
	self.options.tx_freq=Freq.value ###value to set when restarted hard coded ie not a command line option any more		
        print "trying to open the source file",self.options.input_file
	#if self.options.input_file is not "":
		#print "reading from file:",self.options.input_file 
		#global source_file
		#source_file = open(self.options.input_file, 'r')


	self.tb = transmit(self.options)

   
	r = gr.enable_realtime_scheduling()
	if r != gr.RT_OK:
		print "Warning: failed to enable realtime scheduling"
    def __init__(self):
	# Creating the optionparser
        global parser
        parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
	expert_grp = parser.add_option_group("Expert")
	
	parser.add_option("-a", "--args", type="string", default="", help="UHD device address [default=%default]")
	parser.add_option("-s", "--size", type="eng_float", default=400, help="set packet size [default=%default]")
	parser.add_option("-M", "--megabytes", type="eng_float", default=1.0, help="set megabytes to transmit [default=%default]")
	parser.add_option("","--discontinuous", action="store_true", default=False, help="enable discontinuous mode")
	parser.add_option("","--from-file", default=None, help="use file for packet contents")
        parser.add_option("-e", "--interface", type="string", default="eth0", help="Select ethernet interface. Default is eth0")
	parser.add_option("-m", "--MAC_addr", type="string", default="", help="Select USRP2 by its MAC address.Default is auto-select")
	parser.add_option("-j", "--start", type="eng_float", default=1e7, help="Start ferquency [default = %default]")
	parser.add_option("-k", "--stop", type="eng_float", default=1e8,help="Stop ferquency [default = %default]")
	parser.add_option("", "--tune-delay", type="eng_float", default=1e-3, metavar="SECS", help="time to delay (in seconds) after changing frequency[default=%default]")
	parser.add_option("", "--dwell-delay", type="eng_float",default=20e-3, metavar="SECS", help="time to dwell (in seconds) at a given frequncy[default=%default]")
	parser.add_option("-G", "--gain", type="eng_float", default=None,help="set gain in dB (default is midpoint)")
	parser.add_option("-s", "--fft-size", type="int", default=256, help="specify number of FFT bins [default=%default]")
	parser.add_option("-d", "--decim", type="intx", default=16, help="set decimation to DECIM [default=%default]")
        parser.add_option("-i", "--input_file", default="", help="radio input file",metavar="FILE")
        parser.add_option("-S", "--sense-bins", type="int", default=128, help="set number of bins in the OFDM block [default=%default]")
	
	usrp_transmit_path.add_options(parser, expert_grp)
	ofdm.ofdm_demod.add_options(parser, expert_grp)

	(self.options, self.args) = parser.parse_args ()
	#fd= os.open('/home/spann/Dropbox/spec_sense/fifo',os.O_RDONLY) # Open the named pipe to pass on the sensed info to the transmitter part

	if len(self.args) != 0:			# if no arguments are given display help options
		parser.print_help()
		sys.exit(1)

	if self.options.tx_freq is None:	# if transmitter frequency is not mentioned
		sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
		#parser.print_help(sys.stderr)
		sys.exit(1)

	if self.options.from_file is not None:	# if source file is mentioned
		source_file = open(options.from_file, 'r')

	self.tb = transmit(self.options)	# Constructing the flowgraph with the given options

	r = gr.enable_realtime_scheduling() 	# Enable the real time scheduling for flowgraph to be able to run.
	if r != gr.RT_OK:			# Checking error in the status of real time scheduling enabling.
	    print "Warning: failed to enable realtime scheduling"
Esempio n. 5
0
    def __init__(self):
        self.macAddr = 0
        args = ["-f", "2.4G", "-R", "B", "-T", "B"]

        demods = modulation_utils.type_1_demods()
        mods = modulation_utils.type_1_mods()

        parser = OptionParser(option_class=eng_option,
                              conflict_handler="resolve")
        expert_grp = parser.add_option_group("Expert")

        parser.add_option(
            "-m",
            "--modulation",
            type="choice",
            choices=mods.keys(),
            default='gmsk',
            help="Select modulation from: %s [default=%%default]" %
            (', '.join(mods.keys()), ))

        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)

        (options, args) = parser.parse_args(args)

        self.tb = my_top_block(demods[options.modulation],
                               mods[options.modulation], self.callback,
                               options)

        r = gr.enable_realtime_scheduling()
        if r != gr.RT_OK:
            print 'Warning: Failed to enable realtime scheduling.'
        self.tb.start()
        self.n_rcvd = 0
        self.n_right = 0
        self.pkt_no = 0

        print "server init ok!"
Esempio n. 6
0
    def add_options(normal, expert):
        """
        Adds usrp-specific options to the Options Parser
        """
        add_freq_option(normal)
        mods = modulation_utils.type_1_mods()
        demods = modulation_utils.type_1_demods()

        normal.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
                      default='gmsk',
                      help="Select modulation from: %s [default=%%default]"
                            % (', '.join(mods.keys()),))

        #other necessary options
        usrp_transmit_path.add_options(normal, expert)
        usrp_receive_path.add_options(normal, expert)
        for mod in mods.values():
            mod.add_options(expert)
        for demod in demods.values():
            demod.add_options(expert)
Esempio n. 7
0
def main():

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")
    parser.add_option("-t", "--runtime", type=int, default=900)
    parser.add_option("-s", "--size", type="intx", default=97, help="set packet size [default=%default]")
    parser.add_option("-p", "--spacing", type="eng_float", default=1, help="set packet spacing in time [default=%default]")
    parser.add_option("-r", "--sample_rate", type="eng_float", default=500000, help="limit sample rate to RATE in throttle (%default)")
    parser.add_option("-l", "--loss", type="eng_float", default=0.2, help="loss rate that white rate tolerates (%default)")
    parser.add_option("", "--snr", type="eng_float", default=30, help="set the SNR of the channel in dB [default=%default]")
    parser.add_option("","--sender", action="store_true", default=False)
    parser.add_option("", "--tx-ip", type="string", default="128.111.52.67", help="Trasmitter's IP, needed for over-Ethernet-ACKs [default=%default]")
    parser.add_option("", "--rx-ip", type="string", default="128.111.52.70", help="Receiver's IP, needed for over-Ethernet-ACKs [default=%default]")
    #parser.add_option("", "--rx-ip", type="string", default="2001:4200:7000:112:227:eff:fe1c:2428", help="Receiver's IP, needed for over-Ethernet-ACKs [default=%default]")
    parser.add_option("", "--rx-port", type="intx", default=2727, help="Receiver's listening port, needed for over-Ethernet-ACKs [default=%default]")
    parser.add_option("", "--ack-timeout", type="eng_float", default=1, help="ACK timeout in seconds [default=%default]")
    parser.add_option("-v", "--verbose", action="store_true", default=False)

    transmit_path.transmit_path.add_options(parser, expert_grp)
    receive_path.receive_path.add_options(parser, expert_grp)
    usrp_transmit_path.add_options(parser, expert_grp)
    usrp_receive_path.add_options(parser, expert_grp)
    flex_ofdm.ofdm_mod.add_options(parser, expert_grp)
    flex_ofdm.ofdm_demod.add_options(parser, expert_grp)

    (options, args) = parser.parse_args ()

    top = top_class(options.loss, options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"

    top.start()                       # start flow graph

    if options.sender:
        top.run(options.runtime)
    top.wait()                       # wait for it to finish
Esempio n. 8
0
    def __init__(self):
        self.macAddr = 1
        args = ["-f", "2.4G", "-R", "B", "-T", "B"]

        demods = modulation_utils.type_1_demods()
        mods = modulation_utils.type_1_mods()

        parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
        expert_grp = parser.add_option_group("Expert")
        
        parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
                      default='gmsk',
                      help="Select modulation from: %s [default=%%default]"
                            % (', '.join(mods.keys()),))

        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)

        (options, args) = parser.parse_args(args)
        
        self.tb = my_top_block(demods[options.modulation], mods[options.modulation], self.callback, options)

        r = gr.enable_realtime_scheduling()
        if r != gr.RT_OK:
            print 'Warning: Failed to enable realtime scheduling.'
        self.tb.start()
        self.n_rcvd = 0
        self.n_right = 0
        self.pkt_no = 0
        self.reqId = 0

        print "client init ok!"
Esempio n. 9
0
    def add_options(normal, expert):
        """
        Adds usrp-specific options to the Options Parser
        """
        add_freq_option(normal)
        mods = modulation_utils.type_1_mods()
        demods = modulation_utils.type_1_demods()

        normal.add_option(
            "-m",
            "--modulation",
            type="choice",
            choices=mods.keys(),
            default='gmsk',
            help="Select modulation from: %s [default=%%default]" %
            (', '.join(mods.keys()), ))

        #other necessary options
        usrp_transmit_path.add_options(normal, expert)
        usrp_receive_path.add_options(normal, expert)
        for mod in mods.values():
            mod.add_options(expert)
        for demod in demods.values():
            demod.add_options(expert)
Esempio n. 10
0
def main():

    def send_pkt(payload='', eof=False):
        return tb.txpath.send_pkt(payload, eof)

    def rx_callback(ok, payload):
        print "ok = %r, payload = '%s'" % (ok, payload)

    mods = modulation_utils.type_1_mods()

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

    parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
                      default='gmsk',
                      help="Select modulation from: %s [default=%%default]"
                            % (', '.join(mods.keys()),))

    parser.add_option("-s", "--size", type="eng_float", default=1500,
                      help="set packet size [default=%default]")
    parser.add_option("-M", "--megabytes", type="eng_float", default=1.0,
                      help="set megabytes to transmit [default=%default]")
    parser.add_option("","--discontinuous", action="store_true", default=False,
                      help="enable discontinous transmission (bursts of 5 packets)")
    parser.add_option("","--from-file", default=None,
                      help="use file for packet contents")
    parser.add_option("","--location", type="string", 
                      default = "[-80.422221051169391, 37.233082631938416]",
                      help="set radio location in [lon, lat] (default=%default)")

    usrp_transmit_path.add_options(parser, expert_grp)

    for mod in mods.values():
        mod.add_options(expert_grp)

    (options, args) = parser.parse_args ()

    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    if 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)

    if options.from_file is not None:
        source_file = open(options.from_file, 'r')

    # build the graph
    tb = my_top_block(mods[options.modulation], options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"

    tb.start()                       # start flow graph
        


    # generate and send packets
    team_ID = 30376

    n = 0
    pktno = 0
    pkt_size = int(options.size)


    f = open('plb_data','r')
    all_lines = f.readlines()
    f.close()
    os.system('cat /dev/null > plb_data')
    all_lines = "".join(all_lines)
    all_lines = all_lines.split("\n")
    all_lines.pop()

    payload4 = struct.pack('!H', team_ID & 0xffff)

    # original location
    # '[-80.422221051169391, 37.233082631938416]'
    loc_payload = format_loc(options.location)
   

    for n in all_lines:

        n = n.split(',')
        data = (pkt_size - 28) * chr(pktno & 0xff)
        payload1 = struct.pack('!H', pktno & 0xffff)
        payload2 = struct.pack('!H', int(n[0]) & 0xffff)
        payload3 = struct.pack('!H', int(n[1]) & 0xffff)
        payload = payload1 + payload2 + payload3 + payload4 + loc_payload + data

        send_pkt(payload)
        sys.stderr.write('.')
        if options.discontinuous and pktno % 5 == 4:
            time.sleep(1)
        pktno += 1
        if pktno % 20 == 0:
            print "\npktno: %d \n" %pktno 
            print "last location: ", options.location
            os.system('echo ' + options.location + ' > last_location')

    print "finished transmitting"


    # import all data from file
    # 
    # send out all pkt numbers
    # fin


         

        
    send_pkt(eof=True)

    tb.wait()                       # wait for it to finish
Esempio n. 11
0
def main():
    def send_pkt(payload='', eof=False):
        return tb.txpath.send_pkt(payload, eof)

    global n_rcvd, n_right

    n_rcvd = 0
    n_right = 0

    def rx_callback(ok, payload):
        global n_rcvd, n_right
        (pktno, ) = struct.unpack('!H', payload[0:2])
        n_rcvd += 1
        if ok:
            n_right += 1

        print "ok = %5s  pktno = %4d  n_rcvd = %4d  n_right = %4d" % (
            ok, pktno, n_rcvd, n_right)

    demods = modulation_utils.type_1_demods()

    mods = modulation_utils.type_1_mods()

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

    parser.add_option("-m",
                      "--modulation",
                      type="choice",
                      choices=mods.keys(),
                      default='gmsk',
                      help="Select modulation from: %s [default=%%default]" %
                      (', '.join(mods.keys()), ))

    parser.add_option("-s",
                      "--size",
                      type="eng_float",
                      default=1500,
                      help="set packet size [default=%default]")
    parser.add_option("-M",
                      "--megabytes",
                      type="eng_float",
                      default=1.0,
                      help="set megabytes to transmit [default=%default]")
    parser.add_option(
        "",
        "--discontinuous",
        action="store_true",
        default=False,
        help="enable discontinous transmission (bursts of 5 packets)")
    parser.add_option("",
                      "--from-file",
                      default=None,
                      help="use file for packet contents")

    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)

    (options, args) = parser.parse_args()

    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    if options.tx_freq is None or options.rx_freq is None:
        sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
        parser.print_help(sys.stderr)
        sys.exit(1)

    tb = my_top_block(demods[options.modulation], mods[options.modulation],
                      rx_callback, options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print 'Warning: Failed to enable realtime scheduling.'

    tb.start()
    # generate and send packets
    nbytes = int(1e6 * options.megabytes)
    n = 0
    pktno = 0
    pkt_size = int(options.size)

    while n < nbytes:
        if options.from_file is None:
            data = (pkt_size - 2) * chr(pktno & 0xff)
        else:
            data = source_file.read(pkt_size - 2)
            if data == '':
                break

        payload = struct.pack('!H', pktno & 0xffff) + data
        send_pkt(payload)
        n += len(payload)
        sys.stderr.write('.')
        time.sleep(0.01)
        if options.discontinuous and pktno % 5 == 4:
            time.sleep(1)
        pktno += 1

    send_pkt('', True)
    tb.wait()
Esempio n. 12
0
def main():

	global n_rcvd, n_right, acked
	n_rcvd = 0
	n_right = 0
	acked = threading.Event()

	def send_pkt(payload='', eof=False, seqno=0):
		return tb.txpath.send_pkt(payload, eof, seqno)

	def rx_callback(ok, payload, int_fo, frac_fo, time_sinr, freq_sinr, ch_gain, avg_gain):
		global n_rcvd, n_right
		n_rcvd += 1
		try:
			(pktno,) = struct.unpack('!H', payload[0:2])
		except:
			pktno = 1
		if ok:
			n_right += 1
		print "ok: %r \t pktno: %d \t n_rcvd: %d \t n_right: %d" % (ok, pktno, n_rcvd, n_right)
		freq_offset = int_fo+frac_fo/math.pi
		print "freq offset: %+.2f(subcarriers) \t SINR: %.2f(time domain), %.2f(freq domain)" % (freq_offset, time_sinr, freq_sinr)
		#print "Channel gain: "+str(ch_gain)
		#print "Average gain: "+str(avg_gain)

		if 1:
			printlst = list()
			for x in payload[2:]:
				t = hex(ord(x)).replace('0x', '')
				if(len(t) == 1):
					t = '0' + t
				printlst.append(t)
			printable = ''.join(printlst)

			print printable
			print "\n"
		acked.set()
		
	parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
	expert_grp = parser.add_option_group("Expert")
	parser.add_option ("-t", "--runtime", type=int, default=4)
	parser.add_option("-s", "--size", type="intx", default=95, help="set packet size [default=%default]")
	parser.add_option("-p", "--spacing", type="eng_float", default=1, help="set packet spacing in time [default=%default]")
	parser.add_option("-r", "--sample_rate", type="eng_float", default=500000, help="limit sample rate to RATE in throttle (%default)") 
	parser.add_option("","--discontinuous", action="store_true", default=False, help="enable discontinuous mode")
	parser.add_option("", "--snr", type="eng_float", default=30, help="set the SNR of the channel in dB [default=%default]")
	my_top_block.add_options(parser, expert_grp)
	transmit_path.transmit_path.add_options(parser, expert_grp)
	receive_path.receive_path.add_options(parser, expert_grp)
	usrp_transmit_path.add_options(parser,expert_grp)
	flex_ofdm.ofdm_mod.add_options(parser, expert_grp)
	flex_ofdm.ofdm_demod.add_options(parser, expert_grp)

	(options, args) = parser.parse_args ()
	
	# build the graph
	tb = my_top_block(rx_callback, options)

	r = gr.enable_realtime_scheduling()
	if r != gr.RT_OK:
		print "Warning: failed to enable realtime scheduling"

	tb.start()                       # start flow graph

	start_time = time.time()

	# generate and send infinite stream of packets, will be
	# interrupted by runtime
	n = 0
	pktno = 0
	pkt_size = int(options.size)

	#while time.time() < start_time + options.runtime:
	while pktno < options.runtime:
		send_pkt(pkt_size * chr(0x05), eof=False, seqno=pktno)
		n += pkt_size
		#sys.stderr.write('.')
		pktno += 1
		print "sent %d packets" % (pktno,)
		#time.sleep(0.1)
		acked.wait(3)
		acked.clear()
		time.sleep(options.spacing)
		#acked.wait()
		if (pktno == 110):
			options.tone_map = "1fffffffffffe7fffffffffff8"
			tb.reset_ofdm_params(options.tone_map, "bpsk")

	send_pkt(eof=True)
	print "\nfinishing: sent %d packets" % (pktno,)
	#raise SystemExit
	tb.wait()                       # wait for it to finish
Esempio n. 13
0
def main():
    def send_pkt(payload='', eof=False):
        return tb.txpath.send_pkt(payload, eof)

    def rx_callback(ok, payload):
        print "ok = %r, payload = '%s'" % (ok, payload)

    mods = modulation_utils.type_1_mods()

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

    parser.add_option("-m",
                      "--modulation",
                      type="choice",
                      choices=mods.keys(),
                      default='gmsk',
                      help="Select modulation from: %s [default=%%default]" %
                      (', '.join(mods.keys()), ))

    parser.add_option("-s",
                      "--size",
                      type="eng_float",
                      default=1500,
                      help="set packet size [default=%default]")
    parser.add_option("-M",
                      "--megabytes",
                      type="eng_float",
                      default=1.0,
                      help="set megabytes to transmit [default=%default]")
    parser.add_option(
        "",
        "--discontinuous",
        action="store_true",
        default=False,
        help="enable discontinous transmission (bursts of 5 packets)")
    parser.add_option("",
                      "--from-file",
                      default=None,
                      help="use file for packet contents")

    usrp_transmit_path.add_options(parser, expert_grp)

    for mod in mods.values():
        mod.add_options(expert_grp)

    (options, args) = parser.parse_args()

    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    if 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)

    if options.from_file is not None:
        source_file = open(options.from_file, 'r')

    # build the graph
    tb = my_top_block(mods[options.modulation], options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"

    tb.start()  # start flow graph

    # generate and send packets
    nbytes = int(1e6 * options.megabytes)
    n = 0
    pktno = 0
    pkt_size = int(options.size)

    try:
        while n < nbytes:
            if options.from_file is None:
                data = (pkt_size - 2) * chr(pktno & 0xff)
            else:
                data = source_file.read(pkt_size - 2)
                if data == '':
                    break

            payload = struct.pack('!H', pktno & 0xffff) + data
            send_pkt(payload)
            n += len(payload)
            sys.stderr.write('.')
            if options.discontinuous and pktno % 5 == 4:
                time.sleep(1)
            pktno += 1
    except KeyboardInterrupt:
        pass

    send_pkt(eof=True)
    tb.stop()
    tb.wait()  # wait for it to finish
Esempio n. 14
0
def main():

    mods = modulation_utils.type_1_mods()
    demods = modulation_utils.type_1_demods()

    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]"
                            % (', '.join(mods.keys()),))
    parser.add_option("-b","--bssid", default="00:00:00:00:00:00",
                    help="set bssid for network in the form xx:xx:xx:xx:xx:xx") #ZLM copy form chenlong



    parser.add_option("-v","--verbose", action="store_true", default=False)
    expert_grp.add_option("-c", "--carrier-threshold", type="eng_float", default=30,
                          help="set carrier detect threshold (dB) [default=%default]")
    parser.add_option("","--tun", action="store_true", default=False,
                    help="use tun device instead of tap to pass packets.") #ZLM copy form chenlong
    expert_grp.add_option("","--tun-device-filename", default="/dev/net/tun",
                          help="path to tun device file [default=%default]")

    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)

    (options, args) = parser.parse_args ()
    if len(args) != 0:
        parser.print_help(sys.stderr)
        sys.exit(1)

    bssid = validate_mac_addr(options.bssid)
    if bssid == 0:
        print "Invalid BSSID ", options.bssid
        parser.print_help()
        sys.exit(1)

    mod_kwargs = {
        'bt' : options.bt,
        }

    pkttype = 'eth'
    tuntype = 'tap'
    mcache = None
    if options.tun:
        pkttype = 'ip'
        tuntype = 'tun'
    # open the TUN/TAP interface
    (tun_fd, tun_ifname) = open_tun_interface(tuntype, options.tun_device_filename)
    tun_mac = get_mac_for_interface(tun_ifname)
    mac_addr = validate_mac_addr(tun_mac)
    if mac_addr == 0:
        print "Invalid MAC address ", tun_mac, " for interface ", tun_ifname
        print "exiting."
        sys.exit(1)
    if options.verbose:
        print "Using MAC address ", tun_mac, " for interface ", tun_ifname


    # Attempt to enable realtime scheduling
    r = gr.enable_realtime_scheduling()
    if r == gr.RT_OK:
        realtime = True
    else:
        realtime = False
        print "Note: failed to enable realtime scheduling"


    # If the user hasn't set the fusb_* parameters on the command line,
    # pick some values that will reduce latency.

    if options.fusb_block_size == 0 and options.fusb_nblocks == 0:
        if realtime:                        # be more aggressive
            options.fusb_block_size = gr.prefs().get_long('fusb', 'rt_block_size', 1024)
            options.fusb_nblocks    = gr.prefs().get_long('fusb', 'rt_nblocks', 16)
        else:
            options.fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096)
            options.fusb_nblocks    = gr.prefs().get_long('fusb', 'nblocks', 16)
    
    #print "fusb_block_size =", options.fusb_block_size
    #print "fusb_nblocks    =", options.fusb_nblocks
    numchan = 3 
    # instantiate the MACi
    DC = [2.810e9,]
    for i in range(numchan):
	DC += [DC[i] + 0.002 * 10**9] #gen channel


    QCH = makeQCH.makeQCH(numchan)[1] #gen QCH number
#    QCH = [1,1,1,1,1,1,1,1,1]
    mac = cs_mac(tun_fd, mac_addr, pkttype, bssid, mcache, DC, QCH, verbose=True)

    # build the graph (PHY)
    fg = my_graph(mods[options.modulation],demods[options.modulation],
                  mac.phy_rx_callback, options)


    mac.set_flow_graph(fg)    # give the MAC a handle for the PHY

    if fg.txpath.bitrate() != fg.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()))
             
    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" % (tb.txpath.interp(),)
    #print "decim:          %3d" % (tb.rxpath.decim(),)

    fg.rxpath.set_carrier_threshold(options.carrier_threshold)
    print "Carrier sense threshold:", options.carrier_threshold, "dB"
    
    print
    print "Allocated virtual ethernet interface: %s" % (tun_ifname,)
    print "You must now use ifconfig to set its IP address. E.g.,"
    print
    print "  $ sudo ifconfig %s 192.168.200.1" % (tun_ifname,)
    print
    print "Be sure to use a different address in the same subnet for each machine."
    print


    fg.start()    # Start executing the flow graph (runs in separate threads)
    f1 = open('reservation_time.txt','w')
    f2 = open('reservation_slot.txt','w')    
    f3 = open('Qlearn.txt','w')
    f4 = open('channel.txt','w')
#    mac.main_loop(f1,f2,f3)  
    mac.main_loop(f1,f2,f3,f4)    # don't expect this to return...
    
    f1.close()
    f2.close()
    f3.close()    

    fg.stop()     # but if it does, tell flow graph to stop.
    fg.wait()     # wait for it to finish
Esempio n. 15
0
def main():

    def send_pkt(payload='', eof=False):
        return tb.txpath.send_pkt(payload, eof)

    def rx_callback(ok, payload):
        print "ok = %r, payload = '%s'" % (ok, payload)

    mods = modulation_utils.type_1_mods()

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

    parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
                      default='gmsk',
                      help="Select modulation from: %s [default=%%default]"
                            % (', '.join(mods.keys()),))
    parser.add_option("-M", "--megabytes", type="eng_float", default=0,
                      help="set megabytes to transmit [default=inf]")
    parser.add_option("-I", "--audio-input", type="string", default="",
                      help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
    usrp_transmit_path.add_options(parser, expert_grp)

    for mod in mods.values():
        mod.add_options(expert_grp)

    parser.set_defaults(bitrate=50e3)  # override default bitrate default
    (options, args) = parser.parse_args ()

    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    if 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)


    # build the graph
    tb = my_top_block(mods[options.modulation], options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"


    tb.start()                       # start flow graph

    # generate and send packets
    nbytes = int(1e6 * options.megabytes)
    n = 0
    pktno = 0

    while nbytes == 0 or n < nbytes:
        packet = tb.audio_rx.get_encoded_voice_packet()
        s = packet.to_string()
        send_pkt(s)
        n += len(s)
        sys.stderr.write('.')
        pktno += 1
        
    send_pkt(eof=True)
    tb.wait()                       # wait for it to finish
Esempio n. 16
0
def main():
    def send_pkt(payload='', carrier_map="FE7F", eof=False):
        return tb.txpath.send_pkt(payload, eof, carrier_map)

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")
    parser.add_option("-s",
                      "--size",
                      type="eng_float",
                      default=1024,
                      help="set packet size [default=%default]")
    parser.add_option("-M",
                      "--megabytes",
                      type="eng_float",
                      default=1.0,
                      help="set megabytes to transmit [default=%default]")
    parser.add_option("",
                      "--discontinuous",
                      action="store_true",
                      default=False,
                      help="enable discontinuous mode")
    parser.add_option("",
                      "--from-file",
                      default=None,
                      help="use file for packet contents")

    usrp_transmit_path.add_options(parser, expert_grp)
    ofdm.ofdm_mod.add_options(parser, expert_grp)

    (options, args) = parser.parse_args()

    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    if 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)

    if options.from_file is not None:
        source_file = open(options.from_file, 'r')

    tb = my_top_block(options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"

    tb.start()  # start flow graph

    # generate and send packets
    # variables used in transmission
    nbytes = int(10e6 * options.megabytes)  # Total number of bytes to be sent.
    n = 0
    pktno = 0
    pkt_size = int(options.size)  # Packet size
    #    udata ="Transmission is success" 		# string which is to be sent	# Added Line
    #    print "udata",udata							# Added Line
    source_file = open("/home/kranthi/tx1.txt",
                       'r')  # Source file location	# Added Line
    #    source_file = open(options.from_file,'r')  				# Added Line
    file_size = os.path.getsize("/home/kranthi/tx1.txt")
    print file_size
    no_packets = math.ceil(file_size / pkt_size)
    print no_packets
    preamble = 0
    while n < nbytes:
        if (pktno < 20):
            data = "This is Garbage data"
        else:
            data = source_file.read(pkt_size -
                                    2)  # data from the file		# Original Line
            if data == '':
                break
        payload = struct.pack('!H', pktno & 0xffff) + struct.pack(
            '!H', preamble & 0xffff
        ) + data  # Constructing a packet. Pack a string in to given format. http://docs.python.org/library/struct.html
        send_pkt(payload)  # Sending packet
        n += len(payload)
        sys.stderr.write('.')  # error message
        if options.discontinuous and pktno % 5 == 4:  # if discontinuous mode is selected pass for 1 sec after every 4 byte transmission.
            time.sleep(1)
        pktno += 1
    send_pkt(eof=True)

    tb.wait()
Esempio n. 17
0
def main():

	def send_pkt(payload='',carrier_map="FE7F",eof=False):
		return tb.txpath.send_pkt(payload, eof,carrier_map)

	parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
	expert_grp = parser.add_option_group("Expert")
	parser.add_option("-s", "--size", type="eng_float", default=1024, help="set packet size [default=%default]")
	parser.add_option("-M", "--megabytes", type="eng_float", default=1.0, help="set megabytes to transmit [default=%default]")
	parser.add_option("","--discontinuous", action="store_true", default=False, help="enable discontinuous mode")
	parser.add_option("","--from-file", default=None, help="use file for packet contents")

	usrp_transmit_path.add_options(parser, expert_grp)
	ofdm.ofdm_mod.add_options(parser, expert_grp)

	(options, args) = parser.parse_args ()

	if len(args) != 0:
		parser.print_help()
		sys.exit(1)

	if 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)

	if options.from_file is not None:
		source_file = open(options.from_file, 'r')


	tb = my_top_block(options)

	r = gr.enable_realtime_scheduling()
	if r != gr.RT_OK:
		print "Warning: failed to enable realtime scheduling"

	tb.start()                       # start flow graph

	# generate and send packets
	# variables used in transmission
	nbytes = int(10e6 * options.megabytes)	# Total number of bytes to be sent.	
	n = 0
	pktno = 0
	pkt_size = int(options.size)		# Packet size
    #    udata ="Transmission is success" 		# string which is to be sent	# Added Line
    #    print "udata",udata							# Added Line
	source_file = open("/home/kranthi/tx1.txt",'r') # Source file location	# Added Line
    #    source_file = open(options.from_file,'r')  				# Added Line
	file_size = os.path.getsize("/home/kranthi/tx1.txt")
	print file_size
	no_packets = math.ceil(file_size/pkt_size)
	print no_packets
	preamble = 0
	while n < nbytes:
	    if (pktno < 20):
		data = "This is Garbage data"	      
	    else:
		data = source_file.read(pkt_size - 2)# data from the file		# Original Line
		if data == '':
		    break;
	    payload = struct.pack('!H', pktno & 0xffff) + struct.pack('!H', preamble & 0xffff) + data # Constructing a packet. Pack a string in to given format. http://docs.python.org/library/struct.html
	    send_pkt(payload)				     	     # Sending packet
	    n += len(payload)
	    sys.stderr.write('.')				     # error message
	    if options.discontinuous and pktno % 5 == 4:	     # if discontinuous mode is selected pass for 1 sec after every 4 byte transmission. 
		time.sleep(1)
	    pktno += 1
	send_pkt(eof=True)

	tb.wait()
Esempio n. 18
0
    def __init__(self):
        # Creating the optionparser
        global parser
        parser = OptionParser(option_class=eng_option,
                              conflict_handler="resolve")
        expert_grp = parser.add_option_group("Expert")

        parser.add_option("-a",
                          "--args",
                          type="string",
                          default="",
                          help="UHD device address [default=%default]")
        parser.add_option("-s",
                          "--size",
                          type="eng_float",
                          default=400,
                          help="set packet size [default=%default]")
        parser.add_option("-M",
                          "--megabytes",
                          type="eng_float",
                          default=1.0,
                          help="set megabytes to transmit [default=%default]")
        parser.add_option("",
                          "--discontinuous",
                          action="store_true",
                          default=False,
                          help="enable discontinuous mode")
        parser.add_option("",
                          "--from-file",
                          default=None,
                          help="use file for packet contents")
        parser.add_option("-e",
                          "--interface",
                          type="string",
                          default="eth0",
                          help="Select ethernet interface. Default is eth0")
        parser.add_option(
            "-m",
            "--MAC_addr",
            type="string",
            default="",
            help="Select USRP2 by its MAC address.Default is auto-select")
        parser.add_option("-j",
                          "--start",
                          type="eng_float",
                          default=1e7,
                          help="Start ferquency [default = %default]")
        parser.add_option("-k",
                          "--stop",
                          type="eng_float",
                          default=1e8,
                          help="Stop ferquency [default = %default]")
        parser.add_option(
            "",
            "--tune-delay",
            type="eng_float",
            default=1e-3,
            metavar="SECS",
            help=
            "time to delay (in seconds) after changing frequency[default=%default]"
        )
        parser.add_option(
            "",
            "--dwell-delay",
            type="eng_float",
            default=20e-3,
            metavar="SECS",
            help=
            "time to dwell (in seconds) at a given frequncy[default=%default]")
        parser.add_option("-G",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-s",
                          "--fft-size",
                          type="int",
                          default=256,
                          help="specify number of FFT bins [default=%default]")
        parser.add_option("-d",
                          "--decim",
                          type="intx",
                          default=16,
                          help="set decimation to DECIM [default=%default]")
        parser.add_option("-i",
                          "--input_file",
                          default="",
                          help="radio input file",
                          metavar="FILE")
        parser.add_option(
            "-S",
            "--sense-bins",
            type="int",
            default=128,
            help="set number of bins in the OFDM block [default=%default]")

        usrp_transmit_path.add_options(parser, expert_grp)
        ofdm.ofdm_demod.add_options(parser, expert_grp)

        (self.options, self.args) = parser.parse_args()
        #fd= os.open('/home/spann/Dropbox/spec_sense/fifo',os.O_RDONLY) # Open the named pipe to pass on the sensed info to the transmitter part

        if len(self.args
               ) != 0:  # if no arguments are given display help options
            parser.print_help()
            sys.exit(1)

        if self.options.tx_freq is None:  # if transmitter frequency is not mentioned
            sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
            #parser.print_help(sys.stderr)
            sys.exit(1)

        if self.options.from_file is not None:  # if source file is mentioned
            source_file = open(options.from_file, 'r')

        self.tb = transmit(
            self.options)  # Constructing the flowgraph with the given options

        r = gr.enable_realtime_scheduling(
        )  # Enable the real time scheduling for flowgraph to be able to run.
        if r != gr.RT_OK:  # Checking error in the status of real time scheduling enabling.
            print "Warning: failed to enable realtime scheduling"
    def __init__(self, Freq):
        global parser
        parser = OptionParser(option_class=eng_option,
                              conflict_handler="resolve")
        parser.add_option("-a",
                          "--args",
                          type="string",
                          default="",
                          help="UHD device address [default=%default]")
        expert_grp = parser.add_option_group("Expert")
        parser.add_option("-s",
                          "--size",
                          type="eng_float",
                          default=400,
                          help="set packet size [default=%default]")
        parser.add_option("-M",
                          "--megabytes",
                          type="eng_float",
                          default=1.0,
                          help="set megabytes to transmit [default=%default]")
        parser.add_option("",
                          "--discontinuous",
                          action="store_true",
                          default=False,
                          help="enable discontinuous mode")
        parser.add_option("",
                          "--from-file",
                          default=None,
                          help="use file for packet contents")
        parser.add_option("-e",
                          "--interface",
                          type="string",
                          default="eth0",
                          help="Select ethernet interface. Default is eth0")
        parser.add_option(
            "-m",
            "--MAC_addr",
            type="string",
            default="",
            help="Select USRP2 by its MAC address.Default is auto-select")
        parser.add_option("-j",
                          "--start",
                          type="eng_float",
                          default=1e7,
                          help="Start ferquency [default = %default]")
        parser.add_option("-k",
                          "--stop",
                          type="eng_float",
                          default=1e8,
                          help="Stop ferquency [default = %default]")
        parser.add_option(
            "",
            "--tune-delay",
            type="eng_float",
            default=1e-3,
            metavar="SECS",
            help=
            "time to delay (in seconds) after changing frequency[default=%default]"
        )
        parser.add_option(
            "",
            "--dwell-delay",
            type="eng_float",
            default=1e-3,
            metavar="SECS",
            help=
            "time to dwell (in seconds) at a given frequncy[default=%default]")
        parser.add_option("-G",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-s",
                          "--fft-size",
                          type="int",
                          default=512,
                          help="specify number of FFT bins [default=%default]")
        parser.add_option("-d",
                          "--decim",
                          type="intx",
                          default=16,
                          help="set decimation to DECIM [default=%default]")
        parser.add_option("-i",
                          "--input_file",
                          default="",
                          help="radio input file",
                          metavar="FILE")
        parser.add_option(
            "-S",
            "--sense-bins",
            type="int",
            default=128,
            help="set number of bins in the OFDM block [default=%default]")

        usrp_transmit_path.add_options(parser, expert_grp)
        ofdm.ofdm_mod.add_options(parser, expert_grp)

        (self.options, self.args) = parser.parse_args()
        #fd= os.open('/home/spann/Dropbox/spec_sense/fifo',os.O_RDONLY) # Open the named pipe to pass on the sensed info to the transmitter part

        if len(self.args) != 0:
            parser.print_help()
            sys.exit(1)

#if self.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)
        self.options.tx_freq = Freq.value  ###value to set when restarted hard coded ie not a command line option any more
        print "trying to open the source file", self.options.input_file
        #if self.options.input_file is not "":
        #print "reading from file:",self.options.input_file
        #global source_file
        #source_file = open(self.options.input_file, 'r')

        self.tb = transmit(self.options)

        r = gr.enable_realtime_scheduling()
        if r != gr.RT_OK:
            print "Warning: failed to enable realtime scheduling"
Esempio n. 20
0
def main():

    time.sleep(5)

    def send_pkt(payload='', eof=False):
        return tb.txpath.send_pkt(payload, eof)

    def rx_callback(ok, payload):
        print "ok = %r, payload = '%s'" % (ok, payload)

    mods = modulation_utils.type_1_mods()

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

    parser.add_option("-m",
                      "--modulation",
                      type="choice",
                      choices=mods.keys(),
                      default='gmsk',
                      help="Select modulation from: %s [default=%%default]" %
                      (', '.join(mods.keys()), ))

    parser.add_option("-s",
                      "--size",
                      type="eng_float",
                      default=1500,
                      help="set packet size [default=%default]")
    parser.add_option("-M",
                      "--megabytes",
                      type="eng_float",
                      default=1.0,
                      help="set megabytes to transmit [default=%default]")
    parser.add_option(
        "",
        "--discontinuous",
        action="store_true",
        default=False,
        help="enable discontinous transmission (bursts of 5 packets)")
    parser.add_option("",
                      "--from-file",
                      default=None,
                      help="use file for packet contents")

    usrp_transmit_path.add_options(parser, expert_grp)

    for mod in mods.values():
        mod.add_options(expert_grp)

    (options, args) = parser.parse_args()

    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    if 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)

    if options.from_file is not None:
        source_file = open(options.from_file, 'r')

    # build the graph
    tb = my_top_block(mods[options.modulation], options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"

    tb.start()  # start flow graph

    # generate and send packets

    f = open('beacon_id', 'r')
    lines = f.readlines()
    f.close()
    if not (len(lines) == 0):
        item = lines.pop(0)
        beacon_ID = int(item.strip('[]\n'))
    else:
        beacon_ID = 909

    nbytes = int(1e6 * options.megabytes)
    n = 0
    pktno = 0
    pkt_size = int(options.size)

    while n < nbytes:
        #18 is new, old value was 4
        if options.from_file is None:
            data = (pkt_size - 18) * chr(pktno & 0xff)
        else:
            data = source_file.read(pkt_size - 2)
            if data == '':
                break

        payload1 = struct.pack('!H', pktno & 0xffff)
        payload2 = struct.pack('!H', beacon_ID & 0xffff)

        #time magic
        t = "%.15f" % time.time()
        t = t.split('.')
        t_mant = t[0]
        t_frac = t[1]

        payload3 = struct.pack('!H', int(t_mant[0:4]) & 0xffff)
        payload4 = struct.pack('!H', int(t_mant[4:8]) & 0xffff)
        payload5 = struct.pack('!H', int(t_mant[8:len(t_mant)]) & 0xffff)

        payload6 = struct.pack('!H', int(t_frac[0:4]) & 0xffff)
        payload7 = struct.pack('!H', int(t_frac[4:8]) & 0xffff)
        payload8 = struct.pack('!H', int(t_frac[8:12]) & 0xffff)
        payload9 = struct.pack('!H', int(t_frac[12:len(t_frac)]) & 0xffff)

        #payloads added here as well
        payload = (payload1 + payload2 + payload3 + payload4 + payload5 +
                   payload6 + payload7 + payload8 + payload9 + data)
        send_pkt(payload)
        n += len(payload)
        sys.stderr.write('.')
        if options.discontinuous and pktno % 5 == 4:
            time.sleep(1)
        pktno += 1

    send_pkt(eof=True)

    tb.wait()  # wait for it to finish
Esempio n. 21
0
def main():

    mods = modulation_utils.type_1_mods()
    demods = modulation_utils.type_1_demods()

    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]"
                            % (', '.join(mods.keys()),))

    parser.add_option("-v","--verbose", action="store_true", default=False)
    expert_grp.add_option("-c", "--carrier-threshold", type="eng_float", default=30,
                          help="set carrier detect threshold (dB) [default=%default]")
    expert_grp.add_option("","--tun-device-filename", default="/dev/net/tun",
                          help="path to tun device file [default=%default]")

    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)

    (options, args) = parser.parse_args ()
    if len(args) != 0:
        parser.print_help(sys.stderr)
        sys.exit(1)

    # open the TUN/TAP interface
    (tun_fd, tun_ifname) = open_tun_interface(options.tun_device_filename)

    # Attempt to enable realtime scheduling
    r = gr.enable_realtime_scheduling()
    if r == gr.RT_OK:
        realtime = True
    else:
        realtime = False
        print "Note: failed to enable realtime scheduling"


    # If the user hasn't set the fusb_* parameters on the command line,
    # pick some values that will reduce latency.

    if options.fusb_block_size == 0 and options.fusb_nblocks == 0:
        if realtime:                        # be more aggressive
            options.fusb_block_size = gr.prefs().get_long('fusb', 'rt_block_size', 1024)
            options.fusb_nblocks    = gr.prefs().get_long('fusb', 'rt_nblocks', 16)
        else:
            options.fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096)
            options.fusb_nblocks    = gr.prefs().get_long('fusb', 'nblocks', 16)
    
    #print "fusb_block_size =", options.fusb_block_size
    #print "fusb_nblocks    =", options.fusb_nblocks

    # instantiate the MAC
    mac = cs_mac(tun_fd, verbose=True)


    # build the graph (PHY)
    tb = my_top_block(mods[options.modulation],
                      demods[options.modulation],
                      mac.phy_rx_callback,
                      options)

    mac.set_top_block(tb)    # give the MAC a handle for the PHY

    if tb.txpath.bitrate() != tb.rxpath.bitrate():
        print "WARNING: Transmit bitrate = %sb/sec, Receive bitrate = %sb/sec" % (
            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(tb.txpath.bitrate()),)
    print "samples/symbol: %3d" % (tb.txpath.samples_per_symbol(),)
    #print "interp:         %3d" % (tb.txpath.interp(),)
    #print "decim:          %3d" % (tb.rxpath.decim(),)

    tb.rxpath.set_carrier_threshold(options.carrier_threshold)
    print "Carrier sense threshold:", options.carrier_threshold, "dB"
    
    print
    print "Allocated virtual ethernet interface: %s" % (tun_ifname,)
    print "You must now use ifconfig to set its IP address. E.g.,"
    print
    print "  $ sudo ifconfig %s 192.168.200.1" % (tun_ifname,)
    print
    print "Be sure to use a different address in the same subnet for each machine."
    print


    tb.start()    # Start executing the flow graph (runs in separate threads)

    mac.main_loop()    # don't expect this to return...

    tb.stop()     # but if it does, tell flow graph to stop.
    tb.wait()     # wait for it to finish
Esempio n. 22
0
def main():
    def send_pkt(payload='', eof=False):
        return tb.txpath.send_pkt(payload, eof)

    def rx_callback(ok, payload):
        print "ok = %r, payload = '%s'" % (ok, payload)

    mods = modulation_utils.type_1_mods()

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

    parser.add_option("-m",
                      "--modulation",
                      type="choice",
                      choices=mods.keys(),
                      default='gmsk',
                      help="Select modulation from: %s [default=%%default]" %
                      (', '.join(mods.keys()), ))

    parser.add_option("-s",
                      "--size",
                      type="eng_float",
                      default=1500,
                      help="set packet size [default=%default]")
    parser.add_option("-M",
                      "--megabytes",
                      type="eng_float",
                      default=1.0,
                      help="set megabytes to transmit [default=%default]")
    parser.add_option(
        "",
        "--discontinuous",
        action="store_true",
        default=False,
        help="enable discontinous transmission (bursts of 5 packets)")
    parser.add_option("",
                      "--from-file",
                      default=None,
                      help="use file for packet contents")
    parser.add_option(
        "",
        "--location",
        type="string",
        default="[-80.422221051169391, 37.233082631938416]",
        help="set radio location in [lon, lat] (default=%default)")

    usrp_transmit_path.add_options(parser, expert_grp)

    for mod in mods.values():
        mod.add_options(expert_grp)

    (options, args) = parser.parse_args()

    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    if 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)

    if options.from_file is not None:
        source_file = open(options.from_file, 'r')

    # build the graph
    tb = my_top_block(mods[options.modulation], options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"

    tb.start()  # start flow graph

    # generate and send packets
    team_ID = 30376

    n = 0
    pktno = 0
    pkt_size = int(options.size)

    f = open('plb_data', 'r')
    all_lines = f.readlines()
    f.close()
    os.system('cat /dev/null > plb_data')
    all_lines = "".join(all_lines)
    all_lines = all_lines.split("\n")
    all_lines.pop()

    payload4 = struct.pack('!H', team_ID & 0xffff)

    # original location
    # '[-80.422221051169391, 37.233082631938416]'
    loc_payload = format_loc(options.location)

    for n in all_lines:

        n = n.split(',')
        data = (pkt_size - 28) * chr(pktno & 0xff)
        payload1 = struct.pack('!H', pktno & 0xffff)
        payload2 = struct.pack('!H', int(n[0]) & 0xffff)
        payload3 = struct.pack('!H', int(n[1]) & 0xffff)
        payload = payload1 + payload2 + payload3 + payload4 + loc_payload + data

        send_pkt(payload)
        sys.stderr.write('.')
        if options.discontinuous and pktno % 5 == 4:
            time.sleep(1)
        pktno += 1
        if pktno % 20 == 0:
            print "\npktno: %d \n" % pktno
            print "last location: ", options.location
            os.system('echo ' + options.location + ' > last_location')

    print "finished transmitting"

    # import all data from file
    #
    # send out all pkt numbers
    # fin

    send_pkt(eof=True)

    tb.wait()  # wait for it to finish
Esempio n. 23
0
def main():

    global stats_array, count_array, time_array, n_rcvd
    global n_right, sync_status, mode, ch, data_packet_delivery_count
    global n_attempts
    data_packet_delivery_count_previous = 0
    n_rcvd = 0
    n_right = 0
    n_attempts = 5
    threshold = 0.01

    count_array = [ 0, 0, 0, 0, 0]
    time_array = [ 0, 0, 0, 0, 0]
    stats_array = [ 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0]


    def send_pkt(self, payload='', eof=False):
        return self.txpath.send_pkt(payload, eof)

    def get_freq_rx():

        return 2.44*1e9

    def get_freq_tx():
#        return 8,900e6
        # Convert hop_freq to our unique channel list
        channel = int(random.choice([1,7]))
            

        hop_freq = float(1e6 * (850+(channel-1)*5))#setting the centre freq frequency for sending packets

        
        stats_array[channel] = stats_array[channel] + 1
        print "\nChannel DSA Selection Statistics (Channel #: Number times selected)"
        print "1: ", stats_array[1], " 7: ",stats_array[7]
        return channel,hop_freq #returning the channel number and hop frequency
    

    def rx_callback(ok, payload):
        
        global n_rcvd, n_right,sync_status,mode,ch,data_packet_delivery_count
        ########################## sync ####################################
        if mode == "sync":
            if ok:
                print "SYNC:GOT CHANNEL PACKET"
                (pktno,) = struct.unpack('!H', payload[0:2])
                (sync_signal,) = struct.unpack('!s', payload[2]) 
                (data_channel,) = struct.unpack('!H', payload[3:5])
                                  
                if str(sync_signal) == 'o' and str(data_channel) == str(ch):
                    sync_status = True
                    #tb.stop()
                    print "SYNC:RECEIVE CONFIRM PACKET...LINK ESTABLISHED"                           
                if str(sync_signal) == 's' and str(data_channel) == str(ch): 
                    print "SYNC:SEND CONFIRM PACKET"
                    sync_status = True
                    data = 'o'
                    pktno=0
                    ack_payload = struct.pack('!HsH', pktno & 0xffff,data,ch & 0xffff) #+ data
                    send_pkt(tb,ack_payload) #sending back the acknowledgement
        ###################################################################
            
        ######################### traffic #################################
        if mode == "traffic":
            if ok: 
                (data_header,) = struct.unpack('!s', payload[0])
                if data_header == 'd':
		    #print "TRAFFIC:SEND ACK"
                    data_packet_delivery_count = data_packet_delivery_count +1
                    comm = struct.unpack('!14s', payload[1:15])
                    data = 'dI am fine.....' #Sending this message
                    payload = struct.pack('!15s', data)
                    send_pkt(tb,payload)
                
        ##############################################################

        n_rcvd += 1
        if ok:
            n_right += 1

    mods = digital.modulation_utils.type_1_mods()
    demods = digital.modulation_utils.type_1_demods()


    #setting up the tx options parser

    parser_tx = OptionParser(option_class=eng_option, conflict_handler="resolve")
    
    parser_tx.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
            default='gmsk',help="Select modulation from: %s [default=%%default]" 
            % (', '.join(mods.keys()),))
    parser_tx.add_option("-s", "--size", type="eng_float", default=1500,
                      help="set packet size [default=%default]")
    parser_tx.add_option("-M", "--megabytes", type="eng_float", default=1.0,
                      help="set megabytes to transmit [default=%default]")
    parser_tx.add_option("","--discontinuous", action="store_true", default=False,
                      help="enable discontinous transmission (bursts of 5 packets)") 
    parser_tx.add_option("","--from-file", default=None,
                          help="use file for packet contents")

 
    expert_grp_tx = parser_tx.add_option_group("Expert_tx")
    dsa_grp = parser_tx.add_option_group("DSA Options")

        
    dsa_grp.add_option("-T", "--threshold", type="eng_float", default=0.01,
                          help="set primary user sensing energy threshold [default=%default]")
  
    usrp_transmit_path.add_options(parser_tx, expert_grp_tx)
    parser_tx.remove_option('-f');
    #parser_tx.remove_option('--tx-freq');

    for mod in mods.values():
        mod.add_options(expert_grp_tx)


    (options_tx, args_tx) = parser_tx.parse_args ()

    if len(args_tx) != 0:
        parser_tx.print_help()
        sys.exit(1)
    
    ############# Setting some default values for tx side of the block
    options_tx.tx_freq = 900e6
    options_tx.samples_per_symbol =  2
    options_tx.modulation = 'gmsk'
    options_tx.fusb_block_size = 4096
    options_tx.fusb_nblocks = 16
    options_tx.bitrate = 0.0125e6
    #############

    parser_rx = OptionParser (option_class=eng_option, conflict_handler="resolve")
    expert_grp_rx = parser_rx.add_option_group("Expert_rx")
    usrp_receive_path.add_options(parser_rx, expert_grp_rx)
    
    parser_rx.remove_option('-f');
 
    (options_rx, args_rx) = parser_rx.parse_args ()

    ############# Setting some default values for rx side of the block
    options_rx.rx_freq = 2.44e9 #setting default rx_freq value
    options_rx.samples_per_symbol =  2
    options_rx.modulation = 'gmsk'
    options_rx.fusb_block_size = 4096
    options_rx.fusb_nblocks = 16
    options_rx.bitrate = 0.0125e6
    #############


    print "[[ Using the RANDOM channel selection algorithm ]]\n\n"
        
    # build the graph

    tb = my_top_block(mods[options_tx.modulation],
                      demods[options_rx.modulation],
                      rx_callback,options_tx,
                      options_rx)
    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"
    
    tb.start()

    #listening to random frequencies untill a match is found
    running = True

    # Scan all channels first for inital data
    #time.sleep(0.1)

    print "\n[[ Scanning channels for network nodes ]]\n"
    timeout = time.time() + timer
    while running:
	if time.time() > timeout:
	    break
        ################################################sync mode####################################
        if mode == "sync":
			if sync_status != True:
                    

                ch,hop_freq = get_freq_tx()
                hop_freq_rx = get_freq_rx()

                tb.txpath.sink.set_freq(hop_freq)
                tb.rxpath.source.set_freq(hop_freq_rx)
                print "RX_FREQ:",hop_freq_rx,"  TX_FREQ:",hop_freq
                ch_energy = level(ch) #check if primary user is present
                #print ch_energy,"*"*30
                if int(ch_energy) > threshold: #if primary user is there then dont transmit on this channel
		    time.sleep(1)
                    continue
                
                nbytes = 5 #int(1e6 * .0003)
                pkt_size = 5
                n = 0
                pktno = 0
                while n < nbytes:
                    if options_tx.from_file is None:
                        data = 's'
                    else:
                        data = source_file.read(pkt_size - 2)
                        if data == '':
                            break;

                    payload = struct.pack('!HsH', pktno & 0xffff,data,ch & 0xffff) #+ data
                            
                    send_pkt(tb,payload)
                    n += len(payload)
                    sys.stderr.write("SEND SYNC PACKET\n")
                    if options_tx.discontinuous and pktno % 5 == 4:
                        time.sleep(1)
                        pktno += 1
                time.sleep(1)
                    
            else:
                print "\n\n[[ Network Node Found: Commencing communications on CHANNEL ", ch, " ]]\n";
                n_attempts_counter = 0
                mode = "traffic"
                data_packet_delivery_count = 0
                sync_status="False"
                start_time = datetime.now() #measuring the time for which the primary user is away
    
        ################################################end of sync mode####################################

        ################################################Communications mode#################################
        if mode == "traffic":
            nbytes = 15
            pkt_size = 15
            data_pktno = 0
            n = 0
            while n < nbytes:
                if options_tx.from_file is None:
                    data = 'dHi how are you' #Sending this message
                else:
                    data = source_file.read(pkt_size - 2)
                    if data == '':
                        break;
    
            
                payload = struct.pack('!15s', data)
                                       
                send_pkt(tb,payload)
                n += len(payload)
                sys.stderr.write("SEND TRAFFIC PACKET\n")
                if options_tx.discontinuous and data_pktno % 5 == 4:
                    time.sleep(1)
                data_pktno += 1
                time.sleep(0.2 + 0.05*int(random.choice([0,1,2,3])))

                if data_packet_delivery_count == data_packet_delivery_count_previous: #checking if the data packet delivery has stagnated
                    n_attempts_counter += 1
                    if n_attempts_counter > n_attempts: #get out of the data channel as it seems that the other node is still trying to rendezvous
                        mode = "sync"
                        continue
		else:
		    data_packet_delivery_count_previous = 0
		    data_packet_delivery_count = 0

		data_packet_delivery_count_previous = data_packet_delivery_count
		ch_energy = level(ch) #check if primary user is present
		print "CHANNEL ENERGY:",ch_energy,"\n"
		if int(ch_energy) > threshold: #if primary user is there then dont transmit on this channel
		    stop_time = datetime.now()    
		    _elapsed_time  = start_time - stop_time
		    print "\n[[ Primary User Detected:  Evacuating Current Channel ]]\n"
		    print "\n[[ Scanning channels for network nodes ]]\n"
		    print "\nAbsent time:",_elapsed_time,"\n"
		    mode = "sync"
Esempio n. 24
0
def main():

    def send_pkt(payload='', eof=False):
        return tb.txpath.send_pkt(payload, eof)

    def rx_callback(ok, payload):
        print "ok = %r, payload = '%s'" % (ok, payload)

    mods = modulation_utils.type_1_mods()

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

    parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
                      default='gmsk',
                      help="Select modulation from: %s [default=%%default]"
                            % (', '.join(mods.keys()),))

    parser.add_option("-s", "--size", type="eng_float", default=1500,
                      help="set packet size [default=%default]")
    parser.add_option("-M", "--megabytes", type="eng_float", default=1.0,
                      help="set megabytes to transmit [default=%default]")
    parser.add_option("","--discontinuous", action="store_true", default=False,
                      help="enable discontinous transmission (bursts of 5 packets)")
    parser.add_option("","--from-file", default=None,
                      help="use file for packet contents")

    usrp_transmit_path.add_options(parser, expert_grp)

    for mod in mods.values():
        mod.add_options(expert_grp)

    (options, args) = parser.parse_args ()

    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    if 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)

    if options.from_file is not None:
        source_file = open(options.from_file, 'r')

    # build the graph
    tb = my_top_block(mods[options.modulation], options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"

    tb.start()                       # start flow graph
        
    # generate and send packets
    nbytes = int(1e6 * options.megabytes)
    n = 0
    pktno = 0
    pkt_size = int(options.size)

    while n < nbytes:
        if options.from_file is None:
            data = (pkt_size - 2) * chr(pktno & 0xff) 
        else:
            data = source_file.read(pkt_size - 2)
            if data == '':
                break;

        payload = struct.pack('!H', pktno & 0xffff) + data
        send_pkt(payload)
        n += len(payload)
        sys.stderr.write('.')
        time.sleep(0.01)	
        if options.discontinuous and pktno % 5 == 4:
            time.sleep(1)
        pktno += 1
        
    send_pkt(eof=True)

    tb.wait()                       # wait for it to finish
Esempio n. 25
0
def main():

    def send_pkt(payload=None, eof=False):
        return tb.txpath.send_pkt(payload, eof)

    def rx_callback(ok, payload):
        print "ok = %r, payload = '%s'" % (ok, payload)

    mods = modulation_utils.type_1_mods()
    print "mods: ",mods

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

    parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
                      default='dbpsk', #'dbpsk', need to add SNR stuff from gmsk
                      help="Select modulation from: %s [default=%%default]"
                            % (', '.join(mods.keys()),))

    parser.add_option("-s", "--size", type="eng_float", default=1500,
                      help="set packet size [default=%default]")
    parser.add_option("-M", "--megabytes", type="eng_float", default=1.0,
                      help="set megabytes to transmit [default=%default]")
    parser.add_option("","--discontinuous", action="store_true", default=False,
                      help="enable discontinous transmission (bursts of 5 packets)")
    parser.add_option("","--from-file", default=None,
                      help="use file for packet contents")

    usrp_transmit_path.add_options(parser, expert_grp)

    for mod in mods.values():
        mod.add_options(expert_grp)

    (options, args) = parser.parse_args ()

    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    if 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)

    if options.from_file is not None:
        source_file = open(options.from_file, 'r')

    # build the graph
    tb = my_top_block(mods[options.modulation], options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"

    tb.start()                       # start flow graph
        
    # generate and send packets
    #nbytes = int(1e6 * options.megabytes)
    nbytes = 100
    n = 0
    pktno = 0
    pkt_size = int(options.size)
    

    f = open('/home/georgios_colleen/gnuradio/gnuradio-examples/python/digital/sent.txt', 'a')

    filedone=False
    while pktno < nbytes: #why are we limiting to 100 pkts being sent???
        print("---------------------pktno = %i, nbytes = %i--------------------"%(pktno,nbytes))
        if options.from_file is None:
            data = (pkt_size - 2) * chr(pktno & 0xff) 
        elif not(filedone):
            fromfile = source_file.read(pkt_size - 2)
            print("fromfile = %s\n"%fromfile)
            if fromfile == '':
                filedone = True
                continue
            data = fromfile#recode(fromfile)
            f.write(fromfile+"\n")
        elif len(packet_utils2.coded) > 0:
            print("CALLING WITH NO PAYLOAD")
            send_pkt(None)
            continue
        else: break #we really, truly have nothing left to send
            
        #struct.pack(fmt, v1, v2, ...)
        #Return a string containing the values v1, v2, ...
        payload = struct.pack('!H', pktno & 0xffff) + data
        print type(data)#struct.pack('!H', pktno & 0xffff)#payload
        
        send_pkt(payload)
        print("returned from send_pkt")
        n += len(payload)
        sys.stderr.write('.')
        if options.discontinuous and pktno % 10 == 9:
            time.sleep(1)
        pktno += 1

    time.sleep(3)
    print("About to send EOF")
    send_pkt(eof=True)
    
    tb.wait()                       # wait for it to finish
Esempio n. 26
0
def main():

    def send_pkt(payload='', eof=False):
        return tb.txpath.send_pkt(payload, eof)

    def rx_callback(ok, payload):
        print "ok = %r, payload = '%s'" % (ok, payload)

    mods = modulation_utils.type_1_mods()

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

    parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
                      default='gmsk',
                      help="Select modulation from: %s [default=%%default]"
                            % (', '.join(mods.keys()),))
    parser.add_option("-M", "--megabytes", type="eng_float", default=0,
                      help="set megabytes to transmit [default=inf]")
    parser.add_option("-I", "--audio-input", type="string", default="",
                      help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
    usrp_transmit_path.add_options(parser, expert_grp)

    for mod in mods.values():
        mod.add_options(expert_grp)

    parser.set_defaults(bitrate=50e3)  # override default bitrate default
    (options, args) = parser.parse_args ()

    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    if 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)


    # build the graph
    tb = my_top_block(mods[options.modulation], options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"


    tb.start()                       # start flow graph

    # generate and send packets
    nbytes = int(1e6 * options.megabytes)
    n = 0
    pktno = 0

    while nbytes == 0 or n < nbytes:
        packet = tb.audio_rx.get_encoded_voice_packet()
        s = packet.to_string()
        send_pkt(s)
        n += len(s)
        sys.stderr.write('.')
        pktno += 1
        
    send_pkt(eof=True)
    tb.wait()                       # wait for it to finish