sdlabo.org

USRP2のプログラム→USRP-N200のプログラム変更のログ

802.15.4のcc2420送信用コードを書き換えたログを残しておきます。
基本的に、USRP2用のコードを実行して引っかかったところの修正をしているだけになります。

  • とりあえず実行
    $ cd gr/gr-ieee802-15-4/src/examples/
    $ python cc2420_txtest_usrp2.py
    Traceback (most recent call last):
      File "cc2420_txtest_usrp2.py", line 10, in <module>
        from gnuradio import usrp2
    ImportError: cannot import name usrp2
    
  • usrp2モジュールはgnuradio-3.6.0では廃止されているため、UHDでの送受信モジュールに該当するuhd_interface.pyを用いる
    $ cp ~/gr/gnuradio-3.6.0/gr-digital/examples/narrowband/uhd_interface.py .
    
    $ vim cc2420_txtest_usrp2.py
    $ diff cc2420_txtest_usrp2.py.20141212.111147 cc2420_txtest_usrp2.py
    10c10,11
    < from gnuradio import usrp2
    ---
    > #from gnuradio import usrp2
    > from uhd_interface import uhd_transmitter
    40c41,46
    <         self.u = usrp2.sink_32fc(options.interface, options.mac_addr)
    ---
    >         #self.u = usrp2.sink_32fc(options.interface, options.mac_addr)
    >         self.u = uhd_transmitter(options.args,       # add
    >                                  options.bandwidth,
    >                                  options.tx_freq, options.tx_gain,
    >                                  options.spec, options.antenna,
    >                                  options.verbose)
    82a89
    >     uhd_transmitter.add_options(parser)
    
  • 再度実行
    $ python cc2420_txtest_usrp2.py
    linux; GNU C++ version 4.6.3; Boost_104601; UHD_003.005.001-49-stable
    
    Traceback (most recent call last):
      File "cc2420_txtest_usrp2.py", line 13, in <module>
        from gnuradio.ucla_blks import ieee802_15_4_pkt
      File "/usr/local/lib/python2.7/dist-packages/gnuradio/ucla_blks/ieee802_15_4_pkt.py", line 27, in <module>
        import Numeric
    ImportError: No module named Numeric
    
    
    $ cd /usr/local/lib/python2.7/dist-packages/gnuradio/ucla_blks/
    $ sudo backup ieee802_15_4_pkt.py
    $ vim ieee802_15_4_pkt.py
    $ diff ieee802_15_4_pkt.py.20141212.111410 ieee802_15_4_pkt.py
    27c27,28
    < import Numeric
    ---
    > #import Numeric
    > import numpy
    30c31
    < from gnruadio import gr, gru
    ---
    > from gnuradio import gr, gru
    
    
    $ python cc2420_txtest_usrp2.py
    linux; GNU C++ version 4.6.3; Boost_104601; UHD_003.005.001-49-stable
    
    Blocked waiting for GDB attach (pid = 12769)
    Press Enter to continue:
    -- Opening a USRP2/N-Series device...
    -- Current recv frame size: 1472 bytes
    -- Current send frame size: 1472 bytes
    
    UHD Warning:
        The recv buffer could not be resized sufficiently.
        Target sock buff size: 50000000 bytes.
        Actual sock buff size: 131071 bytes.
        See the transport application notes on buffer resizing.
        Please run: sudo sysctl -w net.core.rmem_max=50000000
    
    UHD Warning:
        The recv buffer could not be resized sufficiently.
        Target sock buff size: 50000000 bytes.
        Actual sock buff size: 131071 bytes.
        See the transport application notes on buffer resizing.
        Please run: sudo sysctl -w net.core.rmem_max=50000000
    
    UHD Warning:
        The send buffer could not be resized sufficiently.
        Target sock buff size: 1048576 bytes.
        Actual sock buff size: 131071 bytes.
        See the transport application notes on buffer resizing.
        Please run: sudo sysctl -w net.core.wmem_max=1048576
    -- Detecting internal GPSDO.... Found a Jackson Labs GPS
    -- found
    
    UHD Warning:
        Unable to set the thread priority. Performance may be negatively affected.
        Please see the general application notes in the manual for instructions.
        EnvironmentError: OSError: error in pthread_setschedparam
    -- Setting references to the internal GPSDO
    -- Initializing time to the internal GPSDO
    
    No gain specified.
    Setting gain to 17.500000 (from [0.000000, 35.000000])
    You must specify -f FREQ or --freq FREQ
    
  • いろいろ細かいところを変更(下の方に変更点を全て記述)
    $ vim cc2420_txtest_usrp2.py
    $ python cc2420_txtest_usrp2.py
    linux; GNU C++ version 4.6.3; Boost_104601; UHD_003.005.001-49-stable
    
    Blocked waiting for GDB attach (pid = 12938)
    Press Enter to continue:
    -- Opening a USRP2/N-Series device...
    -- Current recv frame size: 1472 bytes
    -- Current send frame size: 1472 bytes
    
    UHD Warning:
        The recv buffer could not be resized sufficiently.
        Target sock buff size: 50000000 bytes.
        Actual sock buff size: 131071 bytes.
        See the transport application notes on buffer resizing.
        Please run: sudo sysctl -w net.core.rmem_max=50000000
    
    UHD Warning:
        The recv buffer could not be resized sufficiently.
        Target sock buff size: 50000000 bytes.
        Actual sock buff size: 131071 bytes.
        See the transport application notes on buffer resizing.
        Please run: sudo sysctl -w net.core.rmem_max=50000000
    
    UHD Warning:
        The send buffer could not be resized sufficiently.
        Target sock buff size: 1048576 bytes.
        Actual sock buff size: 131071 bytes.
        See the transport application notes on buffer resizing.
        Please run: sudo sysctl -w net.core.wmem_max=1048576
    -- Detecting internal GPSDO.... Found a Jackson Labs GPS
    -- found
    
    UHD Warning:
        Unable to set the thread priority. Performance may be negatively affected.
        Please see the general application notes in the manual for instructions.
        EnvironmentError: OSError: error in pthread_setschedparam
    -- Setting references to the internal GPSDO
    -- Initializing time to the internal GPSDO
    
    No gain specified.
    Setting gain to 17.500000 (from [0.000000, 35.000000])
    cordic_freq = 2.425G
    data_rate =  2M
    samples_per_symbol =  2
    usrp_interp =  25
    Using Volk machine: avx_64
    send message 2:
    UUsend message 3:
    Usend message 4:
    Usend message 5:
    UTraceback (most recent call last):
      File "cc2420_txtest_usrp2.py", line 121, in <module>
        main ()
      File "cc2420_txtest_usrp2.py", line 111, in main
        time.sleep(options.msg_interval)
    KeyboardInterrupt
    
    
    # 動いた.
    # cc2420とは通信できなかった…ペイロードが異なる?
    
  • 全ての変更点
    $ diff cc2420_txtest_usrp2.py.20141212.111147 cc2420_txtest_usrp2.py
    10c10,11
    < from gnuradio import usrp2
    ---
    > #from gnuradio import usrp2
    > from uhd_interface import uhd_transmitter
    40d40
    <         self.u = usrp2.sink_32fc(options.interface, options.mac_addr)
    43,44c43,44
    <         self.data_rate = int (self.u.dac_rate()
    <                               / self.samples_per_symbol
    ---
    >         self.dac_rate = 1e6 * 100
    >         self.data_rate = int (self.dac_rate / self.samples_per_symbol
    46,53c46,51
    <
    <         self.u.set_center_freq(ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan_num])
    <         self.u.set_interp(options.interp_rate)
    <         if not options.gain:
    <             g = self.u.gain_range()
    <             options.gain = float(g[0]+g[1])/2
    <
    <         self.u.set_gain(options.gain)
    ---
    >         self.center_freq = ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan_num]
    >         self.u = uhd_transmitter(options.args,       # add
    >                                  self.data_rate,
    >                                  self.center_freq, options.gain,
    >                                  options.spec, options.antenna,
    >                                  options.verbose)
    98a97
    >     uhd_transmitter.add_options(parser)
    
    

プログラム全体

=========================================================
$ cat cc2420_txtest_usrp2.py
#!/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 uhd_interface import uhd_transmitter
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

# insert this in your test code...
import os
print 'Blocked waiting for GDB attach (pid = %d)' % (os.getpid(),)
raw_input ('Press Enter to continue: ')


def pick_subdevice(u):
    """
    The user didn't specify a subdevice on the command line.
    If there's a daughterboard on A, select A.
    If there's a daughterboard on B, select B.
    Otherwise, select A.
    """
    if u.db[0][0].dbid() >= 0:       # dbid is < 0 if there's no d'board or a problem
        return (0, 0)
    if u.db[1][0].dbid() >= 0:
        return (1, 0)
    return (0, 0)

class transmit_path(gr.top_block):
    def __init__(self, options):
        gr.top_block.__init__(self)

        self.samples_per_symbol = 2
        self.chan_num = options.channel
        self.dac_rate = 1e6 * 100
        self.data_rate = int (self.dac_rate / self.samples_per_symbol
                              / options.interp_rate)

        self.center_freq = ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan_num]
        self.u = uhd_transmitter(options.args,       # add
                                 self.data_rate,
                                 self.center_freq, options.gain,
                                 options.spec, options.antenna,
                                 options.verbose)

        print "cordic_freq = %s" % (eng_notation.num_to_str(ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan_num]))
        print "data_rate = ", eng_notation.num_to_str(self.data_rate)
        print "samples_per_symbol = ", self.samples_per_symbol
        print "usrp_interp = ", options.interp_rate

        #self.u.set_pga(0, options.gain)
        #self.u.set_pga(1, options.gain)

        # transmitter
        self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(self,
                spb=self.samples_per_symbol, msgq_limit=2)
        self.gain = gr.multiply_const_cc (1)

        self.connect(self.packet_transmitter, self.gain, self.u)

        #self.filesink = gr.file_sink(gr.sizeof_gr_complex, 'tx_test.dat')
        #self.connect(self.gain, self.filesink)

        #self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        #self.u.set_auto_tr(True)                      # enable Auto Transmit/Receive switching

    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("-T", "--tx-subdev-spec", type="subdev", default=None,
                      help="select USRP Tx side A or B (default=first one with a daughterboard)")
    parser.add_option ("-c", "--channel", type="eng_float", default=15,
                       help="Set 802.15.4 Channel to listen on", metavar="FREQ")
    parser.add_option ("-i", "--interp_rate", type="int", default=25,
                       help="set interpolation rate")
    parser.add_option ("-r", "--data-rate", type="eng_float", default=2000000)
    parser.add_option ("-g", "--gain", type="eng_float", default=None,
            help="set TX gain. Default: midrange.")
    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")
    parser.add_option("-t", "--msg-interval", type="eng_float", default=1.0,
            help="inter-message interval")
    uhd_transmitter.add_options(parser)

    (options, args) = parser.parse_args ()

    tb = transmit_path(options)
    tb.start()

    i = 0
    while True:
        i+=1
        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(options.msg_interval)

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


  添付編集
Last-modified: 2015-02-16 (月) 12:45:20 (916d)