#!/usr/bin/env python # # Transmitter of IEEE 802.15.4 RADIO Packets. # # Modified by: Thomas Schmid, Sanna Leidelof # from gnuradio import gr, eng_notation from gnuradio import usrp2 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, sys class transmit_path(gr.top_block): def __init__(self, options): gr.top_block.__init__(self) self.normal_gain = 28000 self.u = usrp2.sink_32fc(options.interface, options.mac_addr) dac_rate = self.u.dac_rate(); self.set_gain(self.u.gain_max()) # set max Tx gain self._data_rate = 2000000 self._spb = 2 self._interp = int(128e6 / self._spb / self._data_rate) self.fs = 128e6 / self._interp self.u.set_interp(self._interp) # 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.connect(self.packet_transmitter, self.gain, self.u) #self.filesink = gr.file_sink(gr.sizeof_gr_complex, 'rx_test.dat') #self.connect(self.gain, self.filesink) def set_gain(self, gain): self.gain = gain self.u.set_gain(gain) 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 ("-c", "--cordic-freq", type="eng_float", default=2415000000, help="set Tx cordic 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=35, help="set Rx PGA gain in dB [0,70]") parser.add_option ("-N", "--no-gui", action="store_true", default=False) 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 USRP by MAC address, default is auto-select") (options, args) = parser.parse_args () tb = transmit_path(options) tb.start() for i in range(10): print "send message %d:"%(i+1,) tb.send_pkt(struct.pack('9B', 0x1, 0x80, 0x80, 0xff, 0xff, 0x10, 0x0, 0x20, 0x0)) #this is an other example packet we could send. #tb.send_pkt(struct.pack('BBBBBBBBBBBBBBBBBBBBBBBBBBB', 0x1, 0x8d, 0x8d, 0xff, 0xff, 0xbd, 0x0, 0x22, 0x12, 0xbd, 0x0, 0x1, 0x0, 0xff, 0xff, 0x8e, 0xff, 0xff, 0x0, 0x3, 0x3, 0xbd, 0x0, 0x1, 0x0, 0x0, 0x0)) time.sleep(1) tb.wait() if __name__ == '__main__': main ()