Changeset 9424
- Timestamp:
- 08/26/08 20:02:31
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
usrp2/branches/developers/jcorgan/wip/host-ng/apps/rx_streaming_samples.cc
r9215 r9424 356 356 357 357 if (verbose){ 358 printf("USRP2 MAC address: %s\n\n", u2->mac_addr().c_str()); 358 359 printf("Daughterboard configuration:\n"); 359 360 printf(" baseband_freq=%f\n", tr.baseband_freq); usrp2/branches/developers/jcorgan/wip/host-ng/include/usrp2/usrp2.h
r9422 r9424 75 75 * \param ifc Network interface name, e.g., "eth0" 76 76 * \param addr Network mac address, e.g., "01:02:03:04:05:06", "05:06" or "". 77 * If \p s is HH:HH, it's treated as if it were 00:50:c2:85:HH:HH 77 78 * "" will autoselect a USRP2 if there is only a single one on the local ethernet. 78 79 */ … … 87 88 * Returns the MAC address associated with this USRP 88 89 */ 89 const std::string &mac_addr();90 const std::string &mac_addr(); 90 91 91 92 /* … … 258 259 bool config_mimo(int flags); 259 260 260 261 262 261 class impl; // implementation details 263 262 264 263 private: 265 // Only usrp2::make factory function can instantiate this class 266 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); 267 269 268 270 // All private state is held in opaque pointer usrp2/branches/developers/jcorgan/wip/host-ng/lib/usrp2.cc
r9422 r9424 49 49 static usrp_table s_table; 50 50 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; 60 55 61 56 boost::mutex::scoped_lock guard(s_table_mutex); … … 75 70 76 71 // 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)); 78 73 usrp_table_entry t(key, r); 79 74 s_table.push_back(t); … … 84 79 // --- end of table code --- 85 80 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 88 121 usrp2::sptr 89 122 usrp2::make(const std::string &ifc, const std::string &addr) 90 123 { 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]); 92 133 } 93 134 94 135 // 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)) 97 138 { 98 139 // NOP
