#
# Decoder of IEEE 802.15.4 RADIO Packets.
#
# Modified by: Thomas Schmid, Leslie Choong, Mikhail Tadjikov, Kresimir Dabcevic
#
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
from gnuradio.ucla_blks import ieee802_15_4
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)
print "cordic_freq = %s" % (eng_notation.num_to_str (options.cordic_freq))
# ----------------------------------------------------------------
self.data_rate = options.data_rate
self.samples_per_symbol = 2
self.fs = self.data_rate * self.samples_per_symbol
payload_size = 128 # bytes
print "data_rate = ", eng_notation.num_to_str(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)
self.u.set_clock_config(uhd.clock_config.internal(), uhd.ALL_MBOARDS)
# Set the antenna
self.u.set_antenna(options.antenna, 0)
# Set sampling rate
self.u.set_samp_rate(options.sample_rate)
input_rate = self.u.get_samp_rate()
print "USRP sampling rate: %d" %(input_rate)
# Set and read center frequency
self.u.set_center_freq(uhd.tune_request(options.cordic_freq,0))
frekva = self.u.get_center_freq()
print "Center frequency: %d " %(frekva)
#self.u.set_bandwidth(36000000,0)
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.squelch = gr.pwr_squelch_cc(-80, 1, 0, True)
#self.connect(self.u, self.squelch, self.packet_receiver)
self.connect(self.u, self.packet_receiver)
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 " payload: " + str(map(hex, map(ord, payload)))
print " ------------------------"
sys.stdout.flush()
#else:
# print " Bad packet. %d/%d"%(st.nright, st.npkts)
# pass
parser = OptionParser (option_class=eng_option)
parser.add_option("-a", "--address", type="string", default="addr=192.168.10.3",
help="Address of UHD device, [default=%default]")
parser.add_option("-A", "--antenna", type="string", default="J1",
help="select Rx Antenna where appropriate")
parser.add_option ("-c", "--cordic-freq", type="eng_float", default=2475000000,
help="set rx cordic frequency to FREQ", metavar="FREQ")
parser.add_option ("-r", "--data_rate", type="eng_float", default=2000000)
parser.add_option ("-s", "--sample-rate", type="eng_float", default=1000000)
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__':
main ()
#!/usr/bin/env python
#
# Transmitter of IEEE 802.15.4 RADIO Packets.
#
# Modified by: Thomas Schmid, Sanna Leidelof, Kresimir Dabcevic
#
from gnuradio import gr, eng_notation
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
class transmit_path(gr.top_block):
def __init__(self, options):
gr.top_block.__init__(self)
self.normal_gain = 8000
self.u = uhd.usrp_sink(device_addr=options.address,
io_type=uhd.io_type.COMPLEX_FLOAT32,
num_channels=1)
self.u.set_clock_config(uhd.clock_config.internal(), uhd.ALL_MBOARDS)
u = self.u
self._data_rate = options.data_rate #2000000
self._spb = 2
# Set and print sampling rate
self.u.set_samp_rate(options.sample_rate)
input_rate = self.u.get_samp_rate()
print "Sampling rate: %d" %(input_rate)
# Set and print center frequency
self.u.set_center_freq(options.cordic_freq)
frekva = self.u.get_center_freq()
self.u.set_center_freq(frekva)
print "Center frequency: %d" %(frekva)
# 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.u.set_gain(30,0)
print "TX gain set to: %d" %(self.u.get_gain(0))
self.connect(self.packet_transmitter, self.gain, self.u)
#self.filesink = gr.file_sink(gr.sizeof_gr_complex, 'tx_test.txt')
#self.connect(self.gain, self.filesink)
def set_gain(self, gain):
self.gain = gain
self.u.set_gain(gain, 0)
def send_pkt(self, payload='', eof=False):
return self.packet_transmitter.send_pkt(0xe5, struct.pack("HHHH", 0xFFFF, 0xFFFF, 0x10, 0x10), payload, eof)
def main ():
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", "--cordic-freq", type="eng_float", default=2475000000,
help="set Tx cordic frequency to FREQ", metavar="FREQ")
parser.add_option ("-r", "--data-rate", type="eng_float", default=2000000)
parser.add_option ("-s", "--sample_rate", type="eng_float", default=1000000)
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]")
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(1000):
print "send message %d:"%(i+1,)
tb.send_pkt(struct.pack('9B', 0x1, 0x80, 0x80, 0xff, 0xff, 0x10, 0x0, 0x20, 0x0))
time.sleep(1)
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 ()
I am very fresh in the field of SDRs and encounter some problems in
the implementation. But some basic information first.
I am trying to communicate between gnuradio (USRP) and 802.15.4 sensor
nodes, as it has been done before (see Thomas Schmid @ UCLA). Because
the hardware has evolved since then, I am using USRP N210s as the
interface to the computer. The N210s are equipped with XCVR2450
daugtherboards. I am using basically the ucla_zigbee_phy
implementation and found an existing adaptation to the UHD driver
online (Master Thesis by Kresimir Dabcevic).
Now to the problem. After some minor changes in the test codes (see
attachments), I can communicate between two N210s at 2.475 GHz.
Problem 1: When changing the center frequency on both Tx and Rx,
communication does not work any longer. Even a 5 MHz shift does the
deal.
Problem 2: Packets send from a sensor node are not received. The
packets are sent from TinyOS. At the N210 receiver I check whether I
find a SFD in the stream, but this does not happen (sending 1/sec).
When increasing the transmission rate to 1/10msec, I occasionally
detect a SFD. I have tried both with CC2420 and RF230 transceivers
communicating at channel 25 (2.475 GHz).
I checked the received spectrum for both USRP tx and node tx with a
simple FFT application. The result is attached as well. For this test
I let the transmitter send every 10msec. Also here I have the feeling
that
the node signal is only processed occasionally.
I played a bit around with sample rates. When increasing the sample
rate (before 1M) to 10M I seem to find the SFD more often, though it
is hard to tell, as the SFD then is also found relatively often in the
noise. I tried to filter the noise with the power squelch in the code,
but the threshold has to be very low to get something from the node,
which in itself is quite weird.
I hope someone might have an idea or a tip what else I could check out.
Thanks in advance, Sebastian


No comments:
Post a Comment