[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8398 - in usrp2/branches/developers/jcorgan/u2/host:
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r8398 - in usrp2/branches/developers/jcorgan/u2/host: gr-usrp2 lib |
Date: |
Sun, 11 May 2008 13:56:38 -0600 (MDT) |
Author: jcorgan
Date: 2008-05-11 13:56:35 -0600 (Sun, 11 May 2008)
New Revision: 8398
Modified:
usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc
usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h
usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h
Log:
Refactored auto-discovery
Modified:
usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc
2008-05-11 18:28:26 UTC (rev 8397)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc
2008-05-11 19:56:35 UTC (rev 8398)
@@ -37,44 +37,33 @@
throw (std::runtime_error)
: gr_sync_block(name,
gr_make_io_signature(0, 0, 0),
- output_signature),
- d_u2(0), d_addr()
+ output_signature)
{
- std::vector<op_id_reply_t> r = usrp2_basic::find_usrps(ifc);
- if (r.size() == 0)
- throw std::runtime_error("No USRP2s found on interface.");
+ op_id_reply_t id;
if (mac == "") {
- if (r.size() > 1)
- throw std::runtime_error("Must supply USRP2 MAC address when multiple
devices are present");
- d_addr = r[0].addr;
+ if (!usrp2_basic::pick_default_usrp(ifc, &id))
+ throw std::runtime_error("Unable to pick default USRP2");
}
else {
u2_mac_addr_t addr;
if (!usrp2_basic::parse_mac_addr(mac, &addr))
throw std::runtime_error("Invalid MAC address");
- unsigned int i;
- for (i = 0; i < r.size(); i++)
- if (r[i].addr == addr) {
- d_addr = addr;
- break;
- }
-
- if (i == r.size())
+ if (!usrp2_basic::find_usrp(ifc, addr, &id))
throw std::runtime_error("Unable to find specified USRP2.");
}
if (USRP2_SOURCE_BASE_DEBUG)
- std::cout << "usrp2_source_base: using ifc=" << ifc << " mac=" << d_addr
<< std::endl;
+ std::cout << "usrp2_source_base: using ifc=" << ifc
+ << " mac=" << id.addr
+ << " hw_rev=" << id.hw_rev << std::endl;
- // Now retrieve or make and return usrp2_basic object for MAC address in
d_addr
+ // Now retrieve or make and return usrp2_basic object for selected USRP2
}
usrp2_source_base::~usrp2_source_base ()
{
- if (d_u2)
- delete d_u2;
}
int
Modified: usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h
2008-05-11 18:28:26 UTC (rev 8397)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h
2008-05-11 19:56:35 UTC (rev 8398)
@@ -36,9 +36,6 @@
const std::string &mac = "")
throw (std::runtime_error);
- usrp2_basic *d_u2;
- u2_mac_addr_t d_addr;
-
public:
~usrp2_source_base();
Modified: usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
2008-05-11 18:28:26 UTC (rev 8397)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
2008-05-11 19:56:35 UTC (rev 8398)
@@ -171,22 +171,51 @@
return r;
}
+// static
bool
-usrp2_basic::find_usrp_by_mac(const u2_mac_addr_t &addr, op_id_reply_t *u)
+usrp2_basic::pick_default_usrp(const std::string &ifc, op_id_reply_t *id)
{
+ std::vector<op_id_reply_t> r = usrp2_basic::find_usrps(ifc);
+ if (r.size() != 1)
+ return false;
+
+ if (id)
+ *id = r[0];
+
+ return true;
+}
+
+
+bool
+usrp2_basic::find_usrp_by_mac(const u2_mac_addr_t &addr, op_id_reply_t *id)
+{
std::vector<op_id_reply_t> r = find_usrps();
for (unsigned i = 0; i < r.size(); i++){
if (r[i].addr == addr){
+ if (id)
+ *id = r[i];
+ return true;
+ }
+ }
+ return false;
+}
+
+// static
+bool
+usrp2_basic::find_usrp(const std::string &ifc, const u2_mac_addr_t &addr,
op_id_reply_t *u)
+{
+ std::vector<op_id_reply_t> r = usrp2_basic::find_usrps(ifc);
+ for (unsigned i = 0; i < r.size(); i++){
+ if (r[i].addr == addr){
if (u)
*u = r[i];
return true;
}
}
+
return false;
}
-
-
// ------------------------------------------------------------------------
static int32_t
Modified: usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h 2008-05-11
18:28:26 UTC (rev 8397)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h 2008-05-11
19:56:35 UTC (rev 8398)
@@ -43,6 +43,36 @@
int word0_flags, int chan, uint32_t timestamp);
public:
+ // ---- Static methods ----
+
+ /*!
+ * \brief Return a vector that describes all usrps found on an interface.
+ * \param[in] ifc interface name, e.g., "eth0"
+ */
+ static std::vector<op_id_reply_t> find_usrps(const std::string &ifc);
+
+ /*!
+ * \brief Find a default USRP2 on an interface
+ * \param[in] ifc interface name, e.g., "eth0"
+ * \param[out] id if not 0, is filled in with ID reply information if found
+ *
+ * \returns true iff a single USRP2 is enumerated on the bus
+ */
+ static bool pick_default_usrp(const std::string &ifc, op_id_reply_t *id);
+
+ /*!
+ * \brief Find usrp by interface and mac address
+ *
+ * \param[in] ifc interface name, e.g., "eth0"
+ * \param[in] addr is the mac address of the USRP to look for
+ * \param[out] u if not 0, is filled in with USRP info if found
+ *
+ * \returns true iff the specified usrp was found
+ */
+ static bool find_usrp(const std::string &ifc, const u2_mac_addr_t &addr,
op_id_reply_t *u);
+
+ // ---- Instance methods ----
+
usrp2_basic();
~usrp2_basic();
@@ -58,11 +88,6 @@
std::vector<op_id_reply_t> find_usrps();
/*!
- * Return a vector that describes all usrps found on a specified interface.
- */
- static std::vector<op_id_reply_t> find_usrps(const std::string &ifc);
-
- /*!
* \brief Find usrp by mac address
*
* \param[in] addr is the mac address of the USRP to look for
@@ -72,6 +97,7 @@
*/
bool find_usrp_by_mac(const u2_mac_addr_t &addr, op_id_reply_t *u);
+
/*!
* \brief Parse short or long format mac address.
*
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8398 - in usrp2/branches/developers/jcorgan/u2/host: gr-usrp2 lib,
jcorgan <=