I didn't capture the stdout and stderr, but checked with $ dmesg command and could not find anything which could catch my eyes.I am little bit confused about the performance of my code. Sometimes it works properly and sometimes not. Please find the entire code for the Transmitter end:
from gnuradio import gr, gru, modulation_utils
from gnuradio import usrp
from gnuradio.eng_option import eng_option
from gnuradio import eng_notation, tx_debug_gui
from optparse import OptionParser
import random, time, struct, sys
from transmit_path import transmit_path
from receive_path import receive_path
import fusb_options
global tx_buffer, data_counter
class my_tx_graph(gr.flow_graph):
def __init__ (self, modulator_class, options):
gr.flow_graph.__init_
_(self)
self.txpath = transmit_path(self, modulator_class, options)
class my_rx_graph(gr.flow_graph):
def __init__(self, demod_class, rx_callback, options):
gr.flow_graph.__init__(self)
self.rxpath = receive_path(self, demod_class, rx_callback, options)
def main ():
global tx_buffer, data_counter
data_counter=50 #No of data packets to send
def send_pkt(payload='', eof=False):
return fg_tx.txpath.send_pkt(payload, eof)
def rx_callback(ok, payload):
global tx_buffer, data_counter
(rx_data,) = struct.unpack('!H', payload[0:2])
time.sleep(0.25)
if rx_data == 255:
print "Correctly Sent Data = "" % (tx_buffer)
data = "">
send_pkt(struct.pack
('!H', data) + (pkt_size - 2) * chr(data & 0xff))
tx_buffer=data
data_counter-=1
else:
send_pkt(struct.pack
('!H', tx_buffer) + (pkt_size - 2) * chr(tx_buffer & 0xff))
print "Resend Data = "" % (tx_buffer)
if data_counter == 0:
send_pkt(eof=True)
sys.exit(1)
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")
parser.add_option ("-m", "--modulation", type="choice", choices=mods.keys
(),
default='dbpsk',
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]")
receive_path.add_options(parser, expert_grp)
for mod in demods.values():
mod.add_options(expert_grp)
transmit_path.add_options(parser, expert_grp)
for mod in mods.values():
mod.add_options(expert_grp)
fusb_options.add_options(expert_grp)
(options, args) = parser.parse_args ()
if len(args) != 0:
parser.print_help()
raise SystemExit
if options.rx_freq is None:
sys.stderr.write("usrp_siggen: must specify Rxeceiver RF center frequency with -F \n")
parser.print_help()
raise SystemExit
if options.tx_freq is None:
sys.stderr.write("usrp_siggen: must specify Transmitter RF center frequency with -f \n")
parser.print_help()
raise SystemExit
# build the graph
fg_rx = my_rx_graph(demods[options.modulation], rx_callback, options)
fg_tx = my_tx_graph(mods[options.modulation], options)
r = gr.enable_realtime_scheduling()
if r != gr.RT_OK:
print "Warning: Failed to enable realtime scheduling."
fg_rx.start() # start flow graph
fg_tx.start() # start flow graph
# Start the packet transmission
pkt_size = int(options.size)
tx_buffer=0
send_pkt(struct.pack
('!H', tx_buffer) + (pkt_size - 2) * chr(tx_buffer & 0xff))
fg_tx.wait() # wait for it to finish
fg_tx.stop()
fg_rx.stop()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass