Changeset 9430

Show
Ignore:
Timestamp:
08/26/08 21:47:00
Author:
jcorgan
Message:

Merged changeset -r9421:9429 from jcorgan/wip into trunk. WIP on gr-usrp2 classes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • usrp2/trunk/host-ng

    • Property svn:ignore changed from configure Makefile.in config.log config.status config.guess stamp-h1 config.h ltmain.sh config.sub config.h.in libtool autom4te.cache missing aclocal.m4 Makefile install-sh depcomp usrp2*.tar.gz to configure Makefile.in config.log config.status config.guess stamp-h1 config.h ltmain.sh config.sub config.h.in libtool autom4te.cache missing aclocal.m4 Makefile install-sh depcomp usrp2*.tar.gz py-compile
  • usrp2/trunk/host-ng/Makefile.am

    r8515 r9430  
    2727        config.h.in 
    2828 
    29 SUBDIRS = config include lib apps 
     29SUBDIRS = config include lib gr-usrp2 apps 
  • usrp2/trunk/host-ng/apps/rx_streaming_samples.cc

    r9215 r9430  
    356356 
    357357  if (verbose){ 
     358    printf("USRP2 MAC address: %s\n\n", u2->mac_addr().c_str()); 
    358359    printf("Daughterboard configuration:\n"); 
    359360    printf("  baseband_freq=%f\n", tr.baseband_freq); 
  • usrp2/trunk/host-ng/configure.ac

    r9410 r9430  
    222222    include/Makefile \ 
    223223    include/usrp2/Makefile \ 
     224    gr-usrp2/Makefile \ 
    224225    lib/Makefile \ 
    225226]) 
  • usrp2/trunk/host-ng/include/usrp2/usrp2.h

    r9142 r9430  
    7575     * \param ifc   Network interface name, e.g., "eth0" 
    7676     * \param addr  Network mac address, e.g., "01:02:03:04:05:06", "05:06" or "". 
     77     *              If \p addr is HH:HH, it's treated as if it were 00:50:c2:85:HH:HH 
    7778     *              "" will autoselect a USRP2 if there is only a single one on the local ethernet. 
    7879     */ 
     
    8384     */ 
    8485    ~usrp2();   
     86 
     87    /*! 
     88     * Returns the MAC address associated with this USRP 
     89     */ 
     90    const std::string &mac_addr(); 
    8591 
    8692    /* 
     
    253259    bool config_mimo(int flags); 
    254260 
    255  
    256  
    257261    class impl;         // implementation details 
    258262 
    259263  private: 
    260     // Only usrp2::make factory function can instantiate this class 
    261     usrp2(const std::string &ifc, const std::string &addr); 
     264    // Static function to retrieve or create usrp2 instance 
     265    static sptr find_existing_or_make_new(const std::string &ifc, props *p); 
     266 
     267    // Only class members can instantiate this class 
     268    usrp2(const std::string &ifc, props *p); 
    262269   
    263270    // All private state is held in opaque pointer 
  • usrp2/trunk/host-ng/lib/usrp2.cc

    r9411 r9430  
    4949  static usrp_table s_table; 
    5050 
    51   static usrp2::sptr 
    52   find_existing_or_make_new(const std::string &ifc, const std::string &mac_addr) 
    53   { 
    54     // FIXME normalize addr 
    55  
    56     if (mac_addr.size() != 17) 
    57       throw std::invalid_argument("invalid mac_addr: " + mac_addr); 
    58  
    59     std::string key = ifc + ":" + mac_addr; 
     51  usrp2::sptr 
     52  usrp2::find_existing_or_make_new(const std::string &ifc, props *pr) 
     53  { 
     54    std::string key = ifc + ":" + pr->addr; 
    6055 
    6156    boost::mutex::scoped_lock   guard(s_table_mutex); 
     
    7570 
    7671    // create a new one and stick it in the table. 
    77     usrp2::sptr r = usrp2::make(ifc, mac_addr); 
     72    usrp2::sptr r(new usrp2::usrp2(ifc, pr)); 
    7873    usrp_table_entry t(key, r); 
    7974    s_table.push_back(t); 
     
    8479  // --- end of table code --- 
    8580 
    86  
    87   // Shared pointer factory function, wraps constructor call 
     81  static bool 
     82  parse_mac_addr(const std::string &s, std::string &ns) 
     83  { 
     84    u2_mac_addr_t p; 
     85 
     86    p.addr[0] = 0x00;           // Matt's IAB 
     87    p.addr[1] = 0x50; 
     88    p.addr[2] = 0xC2; 
     89    p.addr[3] = 0x85; 
     90    p.addr[4] = 0x30; 
     91    p.addr[5] = 0x00; 
     92     
     93    int len = s.size(); 
     94    switch (len) { 
     95       
     96    case 5: 
     97      if (sscanf(s.c_str(), "%hhx:%hhx", &p.addr[4], &p.addr[5]) != 2) 
     98        return false; 
     99      break; 
     100       
     101    case 17: 
     102      if (sscanf(s.c_str(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", 
     103                 &p.addr[0], &p.addr[1], &p.addr[2], 
     104                 &p.addr[3], &p.addr[4], &p.addr[5]) != 6) 
     105        return false; 
     106      break; 
     107 
     108    default: 
     109      return false; 
     110    } 
     111     
     112    char buf[128]; 
     113    snprintf(buf, sizeof(buf), 
     114             "%02x:%02x:%02x:%02x:%02x:%02x", 
     115             p.addr[0],p.addr[1],p.addr[2], 
     116             p.addr[3],p.addr[4],p.addr[5]); 
     117    ns = std::string(buf); 
     118    return true; 
     119  } 
     120 
    88121  usrp2::sptr 
    89122  usrp2::make(const std::string &ifc, const std::string &addr) 
    90123  { 
    91     return usrp2::sptr(new usrp2(ifc, addr)); 
     124    std::string naddr = ""; 
     125    if (addr != "" && !parse_mac_addr(addr, naddr)) 
     126      throw std::runtime_error("Invalid MAC address"); 
     127 
     128    props_vector_t u2s = find(ifc, naddr); 
     129    if (u2s.size() != 1) 
     130      throw std::runtime_error("Unable to find requested USRP2."); 
     131 
     132    return find_existing_or_make_new(ifc, &u2s[0]); 
    92133  } 
    93134 
    94135  // Private constructor.  Sole function is to create an impl. 
    95   usrp2::usrp2(const std::string &ifc, const std::string &addr
    96     : d_impl(new usrp2::impl(ifc, addr)) 
     136  usrp2::usrp2(const std::string &ifc, props *p
     137    : d_impl(new usrp2::impl(ifc, p->addr)) 
    97138  { 
    98139    // NOP 
     
    105146  } 
    106147   
     148  const std::string & 
     149  usrp2::mac_addr() 
     150  { 
     151    return d_impl->mac_addr(); 
     152  } 
     153 
    107154  // Receive 
    108155 
  • usrp2/trunk/host-ng/lib/usrp2_impl.h

    r9142 r9430  
    4444    eth_buffer    *d_eth_buf; 
    4545    pktfilter     *d_pf; 
    46     std::string    d_addr; 
     46    std::string    d_addr;       // FIXME: use u2_mac_addr_t instead 
    4747    usrp2_thread  *d_bg_thread; 
    4848    volatile bool  d_bg_running; // TODO: multistate if needed 
     
    9595    void bg_loop(); 
    9696 
     97    const std::string &mac_addr() const { return d_addr; } // FIXME: convert from u2_mac_addr_t 
    9798    bool set_rx_gain(double gain); 
    9899    bool set_rx_center_freq(double frequency, tune_result *result); 
  • usrp2/trunk/host/Makefile.am

    r8391 r9430  
    2727        config.h.in 
    2828 
    29 SUBDIRS = config lib gr-usrp2 apps 
     29SUBDIRS = config lib apps 
  • usrp2/trunk/host/configure.ac

    r8391 r9430  
    206206    config/Makefile \ 
    207207    apps/Makefile \ 
    208     gr-usrp2/Makefile \ 
    209208    lib/Makefile \ 
    210209])