Hello everyone,
I'm new to gnuradio & usrp devices. I tried to update the
ucla_zigbee_phy examples "cc2420_txtest.py" and "cc2420_rxtest.py" to
work with UHD (see attachments), then I ran the codes separately on two
E100 devices but cannot get any packet from the receiver. To find out
the problem, I connected a vector sink directly to the uhd.usrp_source
in the receiver. Then I got some data but it seems nothing came from the
transmitter side, because even if I do not run the transmitter, the
values of the collected data does not change much, most of which are
smaller than 0.01.
I have been using the E100 boards and RFX2400 daughter boards, with UHD
image 003.002.001.
The options for the usrp devices are:
center frequency: 2.475 GHz
sample rate: 200 000
Now I got confused by what happened, could someone have a look at my
codes and give me a tip about what might be the problem?
Thanks in advance,
Terry
#!/usr/bin/env python
#
# Decoder of IEEE 802.15.4 RADIO Packets.
#
# Modified by: Thomas Schmid, Leslie Choong, Mikhail Tadjikov
#
from gnuradio import gr, eng_notation
from gnuradio import uhd
from gnuradio.ucla_blks import ieee802_15_4_pkt
from gnuradio.eng_option import eng_option
from optparse import OptionParser
import struct, sys, time
n2s = eng_notation.num_to_str
class stats(object):
def __init__(self):
self.npkts = 0
self.nright = 0
class oqpsk_rx_graph (gr.top_block):
def __init__(self, options, rx_callback):
gr.top_block.__init__(self)
# ----------------------------------------------------------------
self.data_rate = options.data_rate
self.samples_per_symbol = 2
self._samp_rate = 200000
print "data_rate = ", n2s(self.data_rate)
print "samples_per_symbol = ", self.samples_per_symbol
self.u = uhd.usrp_source (device_addr=options.address,
io_type=uhd.io_type.COMPLEX_FLOAT32,
num_channels=1)
# set the antenna
self.u.set_antenna(options.antenna, 0)
# set sampling rate
self.u.set_samp_rate(self._samp_rate)
# set and print center frequency
treq = uhd.tune_request(options.center_freq)
self.u.set_center_freq(treq)
cntr_freq = self.u.get_center_freq()
print "Center freqency: %d " % (cntr_freq)
self.packet_receiver = ieee802_15_4_pkt.ieee802_15_4_demod_pkts(self,
callback=rx_callback,
sps=self.samples_per_symbol,
symbol_rate=self.data_rate,
threshold=-1)
self.connect(self.u, self.packet_receiver)
# self.vecsink = gr.vector_sink_c()
# self.connect(self.u, self.vecsink)
def main ():
def rx_callback(ok, payload):
st.npkts += 1
if ok:
st.nright += 1
(pktno,) = struct.unpack('!H', payload[0:2])
print "ok = %5r pktno = %4d len(payload) = %4d %d/%d" % (ok, pktno, len(payload),
st.nright, st.npkts)
print " ------------------------"
sys.stdout.flush()
parser = OptionParser(option_class=eng_option)
parser.add_option("-a", "--address", type="string", default="addr=192.168.10.2",
help="Address of UHD device, [default=%default]")
parser.add_option("-A", "--antenna", type="string", default="RX2",
help="select Rx Antenna where appropiate")
parser.add_option("-c", "--center_freq", type="eng_float", default=2475000000,
help="set Rx center frequency to FREQ", metavar="FREQ")
parser.add_option("-r", "--data_rate", type="eng_float", default=2000000)
parser.add_option("-f", "--filename", type="string", default="rx.dat",
help="write data to FILENAME")
parser.add_option("-g", "--gain", type="eng_float", default=0,
help="set Rx PGA gain in dB [0,20]")
(options, args) = parser.parse_args()
st = stats()
tb = oqpsk_rx_graph(options, rx_callback)
tb.start()
tb.wait()
if __name__ == '__main__':
# insert this in your test code...
#import os
#print 'Blocked waiting for GDB attach (pid = %d)' % (os.getpid(),)
#raw_input ('Press Enter to continue: ')
main ()
#!/usr/bin/env python
#
# Transmitter of IEEE 802.15.4 RADIO Packets.
#
# Modified by: Thomas Schmid, Sanna Leidelof
#
from gnuradio import gr, eng_notation, packet_utils
from gnuradio import uhd
from gnuradio import ucla
from gnuradio.ucla_blks import ieee802_15_4_pkt
from gnuradio.eng_option import eng_option
from optparse import OptionParser
import math, struct, time
import socket, os, stat
class transmit_path(gr.top_block):
def __init__(self, options):
gr.top_block.__init__(self)
# parameter settings
self.normal_gain = 8000
self._data_rate = options.data_rate
self._samp_rate = 200000
self._spb = 2
self.u = uhd.usrp_sink(device_addr=options.address,
io_type=uhd.io_type.COMPLEX_FLOAT32,
num_channels=1)
# set and print sampling rate
self.u.set_samp_rate(self._samp_rate)
smpl_rate = self.u.get_samp_rate()
print "Sampling rate: %d" % (smpl_rate)
# set and print center frequency
treq = uhd.tune_request(options.center_freq)
self.u.set_center_freq(treq)
cntr_freq = self.u.get_center_freq()
print "Center frequency: %d" % (cntr_freq)
# transmitter
self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(self, spb=self._spb, msgq_limit=2)
self.gain = gr.multiply_const_cc (self.normal_gain)
# self.vecsink = gr.vector_sink_c()
self.connect(self.packet_transmitter, self.gain, self.u)
def send_pkt(self, payload='', eof=False):
return self.packet_transmitter.send_pkt(0xe5, struct.pack("HHHH", 192, 168, 10, 2), payload, eof)
def main ():
# this option part is not actually useful when usrp is absent
parser = OptionParser (option_class=eng_option)
parser.add_option ("-a", "--address", type="string", default="addr=192.168.10.2",
help="Address of UHD device, [default=%default]")
parser.add_option ("-c", "--center_freq", type="eng_float", default=2475000000,
help="set Tx center frequency to FREQ", metavar="FREQ")
parser.add_option ("-r", "--data_rate", type="eng_float", default=2000000)
parser.add_option ("-f", "--filename", type="string",
default="rx.dat", help="write data to FILENAME")
parser.add_option ("-g", "--gain", type="eng_float", default=None,
help="set Rx PGA gain in dB [0,20]")
parser.add_option ("-N", "--no-gui", action="store_true", default=False)
(options, args) = parser.parse_args ()
tb = transmit_path(options)
tb.start()
for i in range(100):
print "send message %d:"%(i+1,)
content = struct.pack('9B', 0x1, 0x80, 0x80, 0xff, 0xff, 0x10, 0x0, 0x20, 0x0)
tb.send_pkt(content)
time.sleep(0.1)
tb.stop()
if __name__ == '__main__':
# insert this in your test code...
#import os
#print 'Blocked waiting for GDB attach (pid = %d)' % (os.getpid(),)
#raw_input ('Press Enter to continue: ')
main ()
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio