Changeset 9496

Show
Ignore:
Timestamp:
09/04/08 00:27:32
Author:
eb
Message:

Reimplemented usrp2_burn_mac_addr; removed dependency on gnuradio-core.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • usrp2/trunk/host/Makefile.common

    r9442 r9496  
    2222  -I$(top_srcdir)/include \ 
    2323  -I$(top_srcdir)/../firmware/include \ 
    24   $(GNURADIO_CORE_CFLAGS) 
     24  $(GRUEL_CFLAGS) \ 
     25  $(GR_OMNITHREAD_CFLAGS) 
    2526 
    2627 
  • usrp2/trunk/host/apps

    • Property svn:ignore changed from Makefile Makefile.in .libs .deps test_eth test_usrp2 gen_const find_usrps cerr *.sh tx_samples rx_streaming_samples to Makefile Makefile.in .libs .deps test_eth test_usrp2 gen_const find_usrps cerr *.sh tx_samples rx_streaming_samples u2_burn_mac_addr usrp2_burn_mac_addr
  • usrp2/trunk/host/apps/Makefile.am

    r9445 r9496  
    2525 
    2626bin_PROGRAMS = \ 
    27         find_usrps 
     27        find_usrps \ 
     28        usrp2_burn_mac_addr 
    2829 
    2930noinst_PROGRAMS = \ 
     
    3233        tx_samples 
    3334 
    34 find_usrps = find_usrps.cc 
     35find_usrps_SOURCES = find_usrps.cc 
     36usrp2_burn_mac_addr_SOURCES = usrp2_burn_mac_addr.cc 
    3537rx_streaming_samples_SOURCES = rx_streaming_samples.cc 
    3638gen_const_SOURCES = gen_const.cc 
  • usrp2/trunk/host/apps/usrp2_burn_mac_addr.cc

    r9495 r9496  
    11/* -*- c++ -*- */ 
    22/* 
    3  * Copyright 2007 Free Software Foundation, Inc. 
     3 * Copyright 2007,2008 Free Software Foundation, Inc. 
    44 * 
    55 * This program is free software: you can redistribute it and/or modify 
     
    1818 
    1919#ifdef HAVE_CONFIG_H 
    20 #include "config.h" 
     20#include <config.h> 
    2121#endif 
    22 #include "usrp2_basic.h" 
     22#include <usrp2/usrp2.h> 
    2323#include <iostream> 
    2424#include <getopt.h> 
    2525#include <string.h> 
    2626#include <time.h> 
     27#include <stdio.h> 
     28#include <signal.h> 
     29#include <stdexcept> 
     30 
     31 
     32static volatile bool signaled = false; 
     33 
     34static void  
     35sig_handler(int sig) 
     36{ 
     37  signaled = true; 
     38} 
     39 
     40static void 
     41install_sig_handler(int signum, 
     42                    void (*new_handler)(int)) 
     43{ 
     44  struct sigaction new_action; 
     45  memset (&new_action, 0, sizeof (new_action)); 
     46 
     47  new_action.sa_handler = new_handler; 
     48  sigemptyset (&new_action.sa_mask); 
     49  new_action.sa_flags = 0; 
     50 
     51  if (sigaction (signum, &new_action, 0) < 0){ 
     52    perror ("sigaction (install new)"); 
     53    throw std::runtime_error ("sigaction"); 
     54  } 
     55} 
    2756 
    2857 
     
    3665} 
    3766 
     67static bool 
     68check_mac_addr_syntax(const std::string &s) 
     69{ 
     70  unsigned char addr[6]; 
     71 
     72  addr[0] = 0x00;               // Matt's IAB 
     73  addr[1] = 0x50; 
     74  addr[2] = 0xC2; 
     75  addr[3] = 0x85; 
     76  addr[4] = 0x30; 
     77  addr[5] = 0x00; 
     78     
     79  int len = s.size(); 
     80     
     81  switch (len){ 
     82       
     83  case 5: 
     84    return sscanf(s.c_str(), "%hhx:%hhx", &addr[4], &addr[5]) == 2; 
     85       
     86  case 17: 
     87    return sscanf(s.c_str(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", 
     88                  &addr[0], &addr[1], &addr[2], 
     89                  &addr[3], &addr[4], &addr[5]) == 6; 
     90  default: 
     91    return false; 
     92  } 
     93 
     94  return true; 
     95} 
     96 
     97 
    3898int 
    3999main(int argc, char **argv) 
     
    41101  int ch; 
    42102  const char *interface = "eth0"; 
    43   char *old_mac_addr_str = "00:50:c2:85:3f:ff"; 
    44   char *new_mac_addr_str = 0; 
    45   u2_mac_addr_t old_mac_addr; 
    46   u2_mac_addr_t new_mac_addr; 
     103  const char *old_mac_addr = "00:50:c2:85:3f:ff"; 
     104  const char *new_mac_addr = 0; 
    47105 
    48106  while ((ch = getopt(argc, argv, "he:m:")) != EOF){ 
     
    53111       
    54112    case 'm': 
    55       old_mac_addr_str = optarg; 
     113      old_mac_addr = optarg; 
    56114      break; 
    57115       
     
    68126  } 
    69127 
    70   new_mac_addr_str = argv[optind]; 
     128  new_mac_addr = argv[optind]; 
    71129 
    72   if (!usrp2_basic::parse_mac_addr(old_mac_addr_str, &old_mac_addr)){ 
    73     fprintf(stderr, "invalid mac address: %s\n", old_mac_addr_str); 
     130  if (!check_mac_addr_syntax(old_mac_addr)){ 
     131    fprintf(stderr, "invalid mac address: %s\n", old_mac_addr); 
    74132    exit(1); 
    75133  } 
    76   if (!usrp2_basic::parse_mac_addr(new_mac_addr_str, &new_mac_addr)){ 
    77     fprintf(stderr, "invalid mac address: %s\n", new_mac_addr_str); 
     134  if (!check_mac_addr_syntax(new_mac_addr)){ 
     135    fprintf(stderr, "invalid mac address: %s\n", new_mac_addr); 
    78136    exit(1); 
    79137  } 
    80138   
     139  install_sig_handler(SIGINT, sig_handler); 
    81140 
    82   usrp2_basic *u2 = new usrp2_basic()
     141  usrp2::usrp2::sptr u2
    83142 
    84   if (!u2->open(interface)){ 
    85     std::cerr << "couldn't open " << interface << std::endl; 
    86     return 0; 
     143  try { 
     144    u2 = usrp2::usrp2::make(interface, old_mac_addr); 
    87145  } 
    88  
    89   if (!u2->find_usrp_by_mac(old_mac_addr, 0)){ 
    90     std::cerr << "No USRP2 with address " 
    91               << old_mac_addr << " found.\n"; 
     146  catch (std::exception const &e){ 
     147    std::cerr << e.what() << std::endl; 
    92148    return 1; 
    93149  } 
    94150 
    95   if (!u2->burn_mac_addr(old_mac_addr, new_mac_addr)){ 
    96     std::cerr << "Failed to burn mac address\n"; 
     151  if (!u2->burn_mac_addr(new_mac_addr)){ 
     152    std::cerr << "Failed to burn mac address: " 
     153              << new_mac_addr << std::endl; 
    97154    return 1; 
    98155  } 
     156 
     157  u2.reset();   // close 
    99158 
    100159  // wait 250 ms 
     
    104163  nanosleep(&ts, 0); 
    105164 
    106   // Now see if we can find it using it's new address 
    107   if (!u2->find_usrp_by_mac(new_mac_addr, 0)){ 
    108     std::cerr << "Failed to find USRP2 using new address " 
    109               << new_mac_addr << ".\n"; 
     165  try { 
     166    u2 = usrp2::usrp2::make(interface, new_mac_addr); 
     167  } 
     168  catch (std::exception const &e){ 
     169    std::cerr << "Failed to connect to USRP2 using new addr: " 
     170              << new_mac_addr << std::endl; 
     171    std::cerr << e.what() << std::endl; 
    110172    return 1; 
    111173  } 
  • usrp2/trunk/host/config/Makefile.am

    r9442 r9496  
    2020 
    2121M4FILES = \ 
     22        acx_pthread.m4 \ 
    2223        ax_boost_base.m4 \ 
    2324        ax_boost_date_time.m4 \ 
  • usrp2/trunk/host/configure.ac

    r9442 r9496  
    9090 
    9191GR_NO_UNDEFINED         dnl do we need the -no-undefined linker flag 
    92 GR_SCRIPTING 
     92dnl GR_SCRIPTING 
    9393 
    9494dnl AC_CHECK_PROG([XMLTO],[xmlto],[yes],[]) 
     
    188188dnl CXXFLAGS="${CXXFLAGS} $PTHREAD_CFLAGS" 
    189189 
    190  
    191190dnl conditional build stuff 
    192191GR_CHECK_DOXYGEN 
    193 GR_SET_MD_CPU 
    194192 
    195193dnl Define where to look for cppunit includes and libs 
     
    209207AX_BOOST_BASE([1.35]) 
    210208 
    211 dnl so we can use some utilities. FIXME hoist them out 
    212 PKG_CHECK_MODULES(GNURADIO_CORE, gnuradio-core >= 3) 
     209dnl calls AC_SUBST(BOOST_THREAD_LIB), AC_SUBST(BOOST_CXXFLAGS) and defines HAVE_BOOST_THREAD 
     210AX_BOOST_THREAD 
     211CXXFLAGS="$CXXFLAGS $BOOST_CXXFLAGS"       dnl often picks up a -pthread or something similar 
     212CFLAGS="$CFLAGS $BOOST_CXXFLAGS"           dnl often picks up a -pthread or something similar 
     213 
    213214 
    214215# If this is being done from a subversion tree, create variables 
  • usrp2/trunk/host/include/usrp2/usrp2.h

    r9455 r9496  
    7474     * 
    7575     * \param ifc   Network interface name, e.g., "eth0" 
    76      * \param addr  Network mac address, e.g., "01:02:03:04:05:06", "05:06" or "". 
     76     * \param addr  Network mac address, e.g., "01:23:45:67:89:ab", "89:ab" or "". 
    7777     *              If \p addr is HH:HH, it's treated as if it were 00:50:c2:85:HH:HH 
    7878     *              "" will autoselect a USRP2 if there is only a single one on the local ethernet. 
     
    8989     */ 
    9090    std::string mac_addr(); 
     91 
     92    /*! 
     93     * Burn new mac address into EEPROM on USRP2 
     94     * 
     95     * \param new_addr  Network mac address, e.g., "01:23:45:67:89:ab" or "89:ab". 
     96     *                  If \p addr is HH:HH, it's treated as if it were 00:50:c2:85:HH:HH 
     97     */ 
     98    bool burn_mac_addr(const std::string &new_addr); 
    9199 
    92100    /* 
  • usrp2/trunk/host/lib/Makefile.am

    r9463 r9496  
    1919 
    2020#AM_CXXFLAGS = -Wall -Werror (handle this with: $ ./configure CXXFLAGS="-Wall -Werror -O2 -g") 
    21 AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(GRUEL_CFLAGS) $(BOOST_CFLAGS) 
     21AM_CPPFLAGS = $(BOOST_CPPFLAGS) $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(GRUEL_CFLAGS)  
    2222 
    2323lib_LTLIBRARIES = \ 
     
    4343libusrp2_la_LIBADD = \ 
    4444        $(GR_OMNITHREAD_LIBS) \ 
    45         $(GRUEL_LIBS) 
     45        $(GRUEL_LIBS) \ 
     46        $(BOOST_LDFLAGS) $(BOOST_THREAD_LIB) 
    4647 
    4748# Private headers not needed for above the API development 
  • usrp2/trunk/host/lib/control.h

    r9142 r9496  
    5454  }; 
    5555 
     56  struct op_burn_mac_addr_cmd  
     57  { 
     58    u2_eth_packet_t    h; 
     59    op_burn_mac_addr_t op; 
     60    op_generic_t       eop; 
     61  }; 
    5662 
    5763  /*! 
  • usrp2/trunk/host/lib/usrp2.cc

    r9459 r9496  
    131131    if (n == 0) { 
    132132      if (addr == "") 
    133         throw std::runtime_error("No USRPs found on interface."); 
     133        throw std::runtime_error("No USRPs found on interface " + ifc); 
    134134      else 
    135         throw std::runtime_error("Specified USRP2 not found on interface."); 
     135        throw std::runtime_error("No USRP found with addr " + addr + " on interface " + ifc); 
    136136    } 
    137137 
     
    160160    return d_impl->mac_addr(); 
    161161  } 
     162 
     163  bool 
     164  usrp2::burn_mac_addr(const std::string &new_addr) 
     165  { 
     166    return d_impl->burn_mac_addr(new_addr); 
     167  } 
     168 
    162169 
    163170  // Receive 
  • usrp2/trunk/host/lib/usrp2_impl.cc

    r9459 r9496  
    411411  } 
    412412 
     413 
     414  // ---------------------------------------------------------------- 
     415  //                       misc commands 
     416  // ---------------------------------------------------------------- 
     417 
     418  bool 
     419  usrp2::impl::burn_mac_addr(const std::string &new_addr) 
     420  { 
     421    op_burn_mac_addr_cmd cmd; 
     422    op_generic_t reply; 
     423 
     424    memset(&cmd, 0, sizeof(cmd)); 
     425    init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1); 
     426    cmd.op.opcode = OP_BURN_MAC_ADDR; 
     427    cmd.op.len = sizeof(cmd.op); 
     428    cmd.op.rid = d_next_rid++; 
     429    if (!parse_mac_addr(new_addr, &cmd.op.addr)) 
     430      return false; 
     431 
     432    pending_reply p(cmd.op.rid, &reply, sizeof(reply)); 
     433    if (!transmit_cmd(&cmd, sizeof(cmd), &p, 4*DEF_CMD_TIMEOUT)) 
     434      return false; 
     435 
     436    bool success = (ntohx(reply.ok) == 1); 
     437    return success; 
     438  } 
     439 
     440 
    413441  // ---------------------------------------------------------------- 
    414442  //                           Receive 
  • usrp2/trunk/host/lib/usrp2_impl.h

    r9459 r9496  
    9696 
    9797    std::string mac_addr() const { return d_addr; } // FIXME: convert from u2_mac_addr_t 
     98    bool burn_mac_addr(const std::string &new_addr); 
     99 
    98100    bool set_rx_gain(double gain); 
    99101    bool set_rx_center_freq(double frequency, tune_result *result);