[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8409 - in usrp2/trunk/host: gr-usrp2 lib
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r8409 - in usrp2/trunk/host: gr-usrp2 lib |
Date: |
Mon, 12 May 2008 20:25:44 -0600 (MDT) |
Author: jcorgan
Date: 2008-05-12 20:25:43 -0600 (Mon, 12 May 2008)
New Revision: 8409
Added:
usrp2/trunk/host/gr-usrp2/usrp2_table.cc
usrp2/trunk/host/gr-usrp2/usrp2_table.h
Modified:
usrp2/trunk/host/gr-usrp2/Makefile.am
usrp2/trunk/host/gr-usrp2/usrp2_source_base.cc
usrp2/trunk/host/gr-usrp2/usrp2_source_base.h
usrp2/trunk/host/lib/usrp2_basic.cc
usrp2/trunk/host/lib/usrp2_basic.h
Log:
Merged r8393:8399 from jcorgan/u2 into usrp2/trunk. Wip merge to catch up with
Eric's changes, incomplete.
Modified: usrp2/trunk/host/gr-usrp2/Makefile.am
===================================================================
--- usrp2/trunk/host/gr-usrp2/Makefile.am 2008-05-12 23:28:43 UTC (rev
8408)
+++ usrp2/trunk/host/gr-usrp2/Makefile.am 2008-05-13 02:25:43 UTC (rev
8409)
@@ -26,7 +26,8 @@
usrp2_sink_base.cc \
usrp2_sink_c.cc \
usrp2_source_base.cc \
- usrp2_source_c.cc
+ usrp2_source_c.cc \
+ usrp2_table.cc
libgr_usrp2_la_LIBADD = \
../lib/libusrp2.la
@@ -36,6 +37,9 @@
usrp2_sink_c.h \
usrp2_source_base.h \
usrp2_source_c.h
+
+noinst_HEADERS = \
+ usrp2_table.h
# Export C++ GNU Radio driver to Python via SWIG
ourpythondir = $(grpythondir)
Modified: usrp2/trunk/host/gr-usrp2/usrp2_source_base.cc
===================================================================
--- usrp2/trunk/host/gr-usrp2/usrp2_source_base.cc 2008-05-12 23:28:43 UTC
(rev 8408)
+++ usrp2/trunk/host/gr-usrp2/usrp2_source_base.cc 2008-05-13 02:25:43 UTC
(rev 8409)
@@ -25,6 +25,7 @@
#endif
#include <usrp2_source_base.h>
+#include <usrp2_table.h>
#include <gr_io_signature.h>
#include <iostream>
@@ -38,43 +39,36 @@
: gr_sync_block(name,
gr_make_io_signature(0, 0, 0),
output_signature),
- d_u2(0), d_addr()
+ d_u2(0)
{
- 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
+ if (!(d_u2 = find_or_create_usrp2_basic(ifc, id.addr)))
+ throw std::runtime_error("Unable to create usrp2_basic!");
}
usrp2_source_base::~usrp2_source_base ()
{
if (d_u2)
- delete d_u2;
+ release_usrp2_basic(d_u2);
}
int
Modified: usrp2/trunk/host/gr-usrp2/usrp2_source_base.h
===================================================================
--- usrp2/trunk/host/gr-usrp2/usrp2_source_base.h 2008-05-12 23:28:43 UTC
(rev 8408)
+++ usrp2/trunk/host/gr-usrp2/usrp2_source_base.h 2008-05-13 02:25:43 UTC
(rev 8409)
@@ -37,7 +37,6 @@
throw (std::runtime_error);
usrp2_basic *d_u2;
- u2_mac_addr_t d_addr;
public:
~usrp2_source_base();
Copied: usrp2/trunk/host/gr-usrp2/usrp2_table.cc (from rev 8399,
usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.cc)
===================================================================
--- usrp2/trunk/host/gr-usrp2/usrp2_table.cc (rev 0)
+++ usrp2/trunk/host/gr-usrp2/usrp2_table.cc 2008-05-13 02:25:43 UTC (rev
8409)
@@ -0,0 +1,73 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <usrp2_table.h>
+#include <omnithread.h>
+#include <stdexcept>
+
+static omni_mutex lock;
+
+typedef struct {
+ u2_mac_addr_t addr;
+ usrp2_basic *u2;
+} entry_t;
+
+typedef std::vector<entry_t> entry_vector_t;
+typedef entry_vector_t::iterator entry_viter_t;
+
+static entry_vector_t s_table;
+
+usrp2_basic *
+find_or_create_usrp2_basic(const std::string &ifc, const u2_mac_addr_t &addr)
+{
+ omni_mutex_lock l(lock);
+
+ for (entry_viter_t e = s_table.begin(); e != s_table.end(); e++) {
+ if (e->addr == addr)
+ return e->u2;
+ }
+
+ entry_t e;
+ e.addr = addr;
+ e.u2 = new usrp2_basic(); // In future will use ifc and addr
+ s_table.push_back(e);
+ return e.u2;
+}
+
+void
+release_usrp2_basic(usrp2_basic *u2)
+{
+ omni_mutex_lock l(lock);
+
+ for (entry_viter_t e = s_table.begin(); e != s_table.end(); e++) {
+ if (e->u2 == u2) {
+ s_table.erase(e);
+ return;
+ }
+ }
+
+ throw std::runtime_error("Attempt to release non-existent usrp2_basic");
+}
Copied: usrp2/trunk/host/gr-usrp2/usrp2_table.h (from rev 8399,
usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.h)
===================================================================
--- usrp2/trunk/host/gr-usrp2/usrp2_table.h (rev 0)
+++ usrp2/trunk/host/gr-usrp2/usrp2_table.h 2008-05-13 02:25:43 UTC (rev
8409)
@@ -0,0 +1,31 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_USRP2_TABLE_H
+#define INCLUDED_USRP2_TABLE_H
+
+#include <usrp2_basic.h>
+
+usrp2_basic *find_or_create_usrp2_basic(const std::string &ifc, const
u2_mac_addr_t &addr);
+void release_usrp2_basic(usrp2_basic *u2);
+
+#endif /* INCLUDED_USRP2_TABLE_H */
Modified: usrp2/trunk/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.cc 2008-05-12 23:28:43 UTC (rev 8408)
+++ usrp2/trunk/host/lib/usrp2_basic.cc 2008-05-13 02:25:43 UTC (rev 8409)
@@ -173,17 +173,48 @@
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;
}
Modified: usrp2/trunk/host/lib/usrp2_basic.h
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.h 2008-05-12 23:28:43 UTC (rev 8408)
+++ usrp2/trunk/host/lib/usrp2_basic.h 2008-05-13 02:25:43 UTC (rev 8409)
@@ -65,6 +65,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();
@@ -80,11 +110,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
@@ -94,6 +119,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] r8409 - in usrp2/trunk/host: gr-usrp2 lib,
jcorgan <=