commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r9424 - in usrp2/branches/developers/jcorgan/wip/host-


From: jcorgan
Subject: [Commit-gnuradio] r9424 - in usrp2/branches/developers/jcorgan/wip/host-ng: apps include/usrp2 lib
Date: Tue, 26 Aug 2008 20:02:32 -0600 (MDT)

Author: jcorgan
Date: 2008-08-26 20:02:31 -0600 (Tue, 26 Aug 2008)
New Revision: 9424

Modified:
   usrp2/branches/developers/jcorgan/wip/host-ng/apps/rx_streaming_samples.cc
   usrp2/branches/developers/jcorgan/wip/host-ng/include/usrp2/usrp2.h
   usrp2/branches/developers/jcorgan/wip/host-ng/lib/usrp2.cc
Log:
(Re)implement MAC address normalization, use per-MAC address cache for USRP2 
instances.

Modified: 
usrp2/branches/developers/jcorgan/wip/host-ng/apps/rx_streaming_samples.cc
===================================================================
--- usrp2/branches/developers/jcorgan/wip/host-ng/apps/rx_streaming_samples.cc  
2008-08-26 23:56:41 UTC (rev 9423)
+++ usrp2/branches/developers/jcorgan/wip/host-ng/apps/rx_streaming_samples.cc  
2008-08-27 02:02:31 UTC (rev 9424)
@@ -355,6 +355,7 @@
   }
 
   if (verbose){
+    printf("USRP2 MAC address: %s\n\n", u2->mac_addr().c_str());
     printf("Daughterboard configuration:\n");
     printf("  baseband_freq=%f\n", tr.baseband_freq);
     printf("       ddc_freq=%f\n", tr.dxc_freq);

Modified: usrp2/branches/developers/jcorgan/wip/host-ng/include/usrp2/usrp2.h
===================================================================
--- usrp2/branches/developers/jcorgan/wip/host-ng/include/usrp2/usrp2.h 
2008-08-26 23:56:41 UTC (rev 9423)
+++ usrp2/branches/developers/jcorgan/wip/host-ng/include/usrp2/usrp2.h 
2008-08-27 02:02:31 UTC (rev 9424)
@@ -74,6 +74,7 @@
      *
      * \param ifc   Network interface name, e.g., "eth0"
      * \param addr  Network mac address, e.g., "01:02:03:04:05:06", "05:06" or 
"".
+     *              If \p s is HH:HH, it's treated as if it were 
00:50:c2:85:HH:HH
      *              "" will autoselect a USRP2 if there is only a single one 
on the local ethernet.
      */
     static sptr make(const std::string &ifc, const std::string &addr="");
@@ -86,7 +87,7 @@
     /*!
      * Returns the MAC address associated with this USRP
      */
-     const std::string &mac_addr();
+    const std::string &mac_addr();
 
     /*
      * ----------------------------------------------------------------
@@ -257,13 +258,14 @@
      */
     bool config_mimo(int flags);
 
-
-
     class impl;                // implementation details
 
   private:
-    // Only usrp2::make factory function can instantiate this class
-    usrp2(const std::string &ifc, const std::string &addr);
+    // Static function to retrieve or create usrp2 instance
+    static sptr find_existing_or_make_new(const std::string &ifc, props *p);
+
+    // Only class members can instantiate this class
+    usrp2(const std::string &ifc, props *p);
   
     // All private state is held in opaque pointer
     std::auto_ptr<impl> d_impl;

Modified: usrp2/branches/developers/jcorgan/wip/host-ng/lib/usrp2.cc
===================================================================
--- usrp2/branches/developers/jcorgan/wip/host-ng/lib/usrp2.cc  2008-08-26 
23:56:41 UTC (rev 9423)
+++ usrp2/branches/developers/jcorgan/wip/host-ng/lib/usrp2.cc  2008-08-27 
02:02:31 UTC (rev 9424)
@@ -48,16 +48,11 @@
   static boost::mutex s_table_mutex;
   static usrp_table s_table;
 
-  static usrp2::sptr
-  find_existing_or_make_new(const std::string &ifc, const std::string 
&mac_addr)
+  usrp2::sptr
+  usrp2::find_existing_or_make_new(const std::string &ifc, props *pr)
   {
-    // FIXME normalize addr
+    std::string key = ifc + ":" + pr->addr;
 
-    if (mac_addr.size() != 17)
-      throw std::invalid_argument("invalid mac_addr: " + mac_addr);
-
-    std::string key = ifc + ":" + mac_addr;
-
     boost::mutex::scoped_lock  guard(s_table_mutex);
 
     for (usrp_table::iterator p = s_table.begin(); p != s_table.end();){
@@ -74,7 +69,7 @@
     // We don't have the USRP2 we're looking for
 
     // create a new one and stick it in the table.
-    usrp2::sptr r = usrp2::make(ifc, mac_addr);
+    usrp2::sptr r(new usrp2::usrp2(ifc, pr));
     usrp_table_entry t(key, r);
     s_table.push_back(t);
 
@@ -83,17 +78,63 @@
 
   // --- end of table code ---
 
+  static bool
+  parse_mac_addr(const std::string &s, std::string &ns)
+  {
+    u2_mac_addr_t p;
 
-  // Shared pointer factory function, wraps constructor call
+    p.addr[0] = 0x00;          // Matt's IAB
+    p.addr[1] = 0x50;
+    p.addr[2] = 0xC2;
+    p.addr[3] = 0x85;
+    p.addr[4] = 0x30;
+    p.addr[5] = 0x00;
+    
+    int len = s.size();
+    switch (len) {
+      
+    case 5:
+      if (sscanf(s.c_str(), "%hhx:%hhx", &p.addr[4], &p.addr[5]) != 2)
+       return false;
+      break;
+      
+    case 17:
+      if (sscanf(s.c_str(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
+                &p.addr[0], &p.addr[1], &p.addr[2],
+                &p.addr[3], &p.addr[4], &p.addr[5]) != 6)
+       return false;
+      break;
+
+    default:
+      return false;
+    }
+    
+    char buf[128];
+    snprintf(buf, sizeof(buf),
+            "%02x:%02x:%02x:%02x:%02x:%02x",
+            p.addr[0],p.addr[1],p.addr[2],
+            p.addr[3],p.addr[4],p.addr[5]);
+    ns = std::string(buf);
+    return true;
+  }
+
   usrp2::sptr
   usrp2::make(const std::string &ifc, const std::string &addr)
   {
-    return usrp2::sptr(new usrp2(ifc, addr));
+    std::string naddr = "";
+    if (addr != "" && !parse_mac_addr(addr, naddr))
+      throw std::runtime_error("Invalid MAC address");
+
+    props_vector_t u2s = find(ifc, naddr);
+    if (u2s.size() != 1)
+      throw std::runtime_error("Unable to find requested USRP2.");
+
+    return find_existing_or_make_new(ifc, &u2s[0]);
   }
 
   // Private constructor.  Sole function is to create an impl.
-  usrp2::usrp2(const std::string &ifc, const std::string &addr)
-    : d_impl(new usrp2::impl(ifc, addr))
+  usrp2::usrp2(const std::string &ifc, props *p)
+    : d_impl(new usrp2::impl(ifc, p->addr))
   {
     // NOP
   }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]