[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8418 - in usrp2/branches/developers/jcorgan/u2/host:
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r8418 - in usrp2/branches/developers/jcorgan/u2/host: apps lib |
Date: |
Tue, 13 May 2008 18:12:06 -0600 (MDT) |
Author: jcorgan
Date: 2008-05-13 18:11:55 -0600 (Tue, 13 May 2008)
New Revision: 8418
Modified:
usrp2/branches/developers/jcorgan/u2/host/apps/Makefile.am
usrp2/branches/developers/jcorgan/u2/host/apps/rx_streaming_samples.cc
usrp2/branches/developers/jcorgan/u2/host/apps/tx_samples.cc
usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h
Log:
Move remaining USRP2 discovery into static methods.
Modified: usrp2/branches/developers/jcorgan/u2/host/apps/Makefile.am
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/apps/Makefile.am 2008-05-13
20:32:56 UTC (rev 8417)
+++ usrp2/branches/developers/jcorgan/u2/host/apps/Makefile.am 2008-05-14
00:11:55 UTC (rev 8418)
@@ -27,8 +27,8 @@
find_usrps \
rx_streaming_samples \
tx_samples \
- gen_const \
- u2_burn_mac_addr
+ gen_const
+# u2_burn_mac_addr
find_usrps_SOURCES = find_usrps.cc
# rx_samples_SOURCES = rx_samples.cc
Modified: usrp2/branches/developers/jcorgan/u2/host/apps/rx_streaming_samples.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/apps/rx_streaming_samples.cc
2008-05-13 20:32:56 UTC (rev 8417)
+++ usrp2/branches/developers/jcorgan/u2/host/apps/rx_streaming_samples.cc
2008-05-14 00:11:55 UTC (rev 8418)
@@ -312,38 +312,29 @@
}
}
- usrp2_basic_sptr u2 = usrp2_make_basic();
+ op_id_reply_t r;
+ if (!usrp2_basic::pick_default_usrp(interface, &r)) {
+ std::cerr << "No default USRP2 found.\n";
+ return 1;
+ }
+ usrp2_basic_sptr u2 = usrp2_make_basic();
if (!u2->open(interface)){
std::cerr << "couldn't open " << interface << std::endl;
return 0;
}
install_sig_handler(SIGINT, sig_handler);
-
- std::vector<op_id_reply_t> r = u2->find_usrps();
- for (size_t i = 0; i < r.size(); i++){
- std::cerr << r[i] << std::endl;
- }
+ u2_mac_addr_t which = r.addr;
- if (r.size() == 0){
- std::cerr << "No USRP2 found.\n";
- return 1;
- }
-
- u2_mac_addr_t which = r[0].addr; // pick the first one
-
-
gr_rt_status_t rt = gr_enable_realtime_scheduling();
if (rt != RT_OK)
std::cerr << "failed to enable realtime scheduling\n";
-
// create writer thread
class file_writer *writer = new file_writer(ofd, rb);
writer->start_undetached();
-
usrp2_tune_result tune_result;
Modified: usrp2/branches/developers/jcorgan/u2/host/apps/tx_samples.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/apps/tx_samples.cc
2008-05-13 20:32:56 UTC (rev 8417)
+++ usrp2/branches/developers/jcorgan/u2/host/apps/tx_samples.cc
2008-05-14 00:11:55 UTC (rev 8418)
@@ -160,6 +160,12 @@
return 1;
}
+ op_id_reply_t r;
+ if (!usrp2_basic::pick_default_usrp(interface, &r)) {
+ std::cerr << "Unable to find USRP2." << std::endl;
+ return 1;
+ }
+
usrp2_basic_sptr u2 = usrp2_make_basic();
if (!u2->open(interface)){
@@ -167,20 +173,7 @@
return 1;
}
- std::vector<op_id_reply_t> r = u2->find_usrps();
-
- for (size_t i = 0; i < r.size(); i++){
- std::cout << r[i] << std::endl;
- }
-
- if (r.size() == 0){
- std::cerr << "No USRP2 found.\n";
- return 1;
- }
-
- u2_mac_addr_t which = r[0].addr; // pick the first one
-
-
+ u2_mac_addr_t which = r.addr;
usrp2_tune_result tune_result;
if (gain != GAIN_NOT_SET){
Modified: usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
2008-05-13 20:32:56 UTC (rev 8417)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
2008-05-14 00:11:55 UTC (rev 8418)
@@ -101,18 +101,10 @@
// ------------------------------------------------------------------------
+// static
std::vector<op_id_reply_t>
-usrp2_basic::find_usrps()
+usrp2_basic::find_usrps(const std::string &ifc)
{
- static u2_mac_addr_t broadcast_mac_addr =
- {{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }};
-
- std::vector<op_id_reply_t> result;
- int r;
-
- uint8_t pktbuf[MAX_PKTLEN];
- memset(pktbuf, 0, sizeof(pktbuf));
-
struct command {
u2_eth_packet_t h;
op_id_t op_id;
@@ -123,39 +115,64 @@
op_id_reply_t op_id_reply;
};
- command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, broadcast_mac_addr, 0, CONTROL_CHAN, -1);
+ int r, len;
+ command *c = 0;
+ std::vector<op_id_reply_t> result;
+ gri_ethernet *enet = 0;
+ gri_pktfilter *pf = 0;
+
+ enet = new GRI_ETHERNET();
+ if (!enet->open(ifc, htons(U2_ETHERTYPE)))
+ goto bail;
+ pf = gri_pktfilter::make_ethertype_inbound(U2_ETHERTYPE, enet->mac());
+ if (!enet->attach_pktfilter(pf))
+ goto bail;
+
+ static u2_mac_addr_t broadcast_mac_addr =
+ {{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }};
+
+ uint8_t pktbuf[MAX_PKTLEN];
+ memset(pktbuf, 0, sizeof(pktbuf));
+
+ c = (command *)pktbuf;
+ c->h.ehdr.ethertype = htons(U2_ETHERTYPE);
+ c->h.ehdr.dst = broadcast_mac_addr;
+ memcpy(&c->h.ehdr.src, enet->mac(), 6);
+ c->h.thdr.flags = 0;
+ c->h.thdr.seqno = 0;
+ c->h.thdr.ack = 0;
+ u2p_set_word0(&c->h.fixed, 0, CONTROL_CHAN);
+ u2p_set_timestamp(&c->h.fixed, -1);
c->op_id.opcode = OP_ID;
c->op_id.len = sizeof(op_id_t);
- int len = std::max((size_t) MIN_PKTLEN, sizeof(command));
- if (d_ethernet->write_packet(c, len) != len){
+ len = std::max((size_t) MIN_PKTLEN, sizeof(command));
+ if (enet->write_packet(c, len) != len)
goto bail;
- }
/*
* Wait no longer than 10ms and read all packets available.
*/
fd_set read_fds;
FD_ZERO(&read_fds);
- FD_SET(d_ethernet->fd(), &read_fds);
+ FD_SET(enet->fd(), &read_fds);
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = 10 * 1000; // 10 ms
- r = select(d_ethernet->fd()+1, &read_fds, 0, 0, &timeout);
+ r = select(enet->fd()+1, &read_fds, 0, 0, &timeout);
- while(1){
+ while(1) {
memset(pktbuf, 0, sizeof(pktbuf));
- int len = d_ethernet->read_packet_dont_block(pktbuf, sizeof(pktbuf));
+ len = enet->read_packet_dont_block(pktbuf, sizeof(pktbuf));
if (len < 0){
perror("usrp2_basic: read_packet_dont_block");
- return result;
+ goto bail;
}
if (len == 0)
break;
- reply *rp = (reply *) pktbuf;
+ reply *rp = (reply *)pktbuf;
if (u2p_chan(&rp->h.fixed) != CONTROL_CHAN) // ignore
continue;
if (rp->op_id_reply.opcode != OP_ID_REPLY) // ignore
@@ -164,26 +181,15 @@
result.push_back(rp->op_id_reply);
}
- bail:
+bail:
+ if (enet)
+ delete enet;
+ if (pf)
+ delete pf;
return result;
}
// static
-std::vector<op_id_reply_t>
-usrp2_basic::find_usrps(const std::string &ifc)
-{
- usrp2_basic *u2 = new usrp2_basic();
- if (!u2 || !u2->open(ifc)) {
- std::cerr << "Unable to open network interface: " << ifc << std::endl;
- return std::vector<op_id_reply_t>(0);
- }
-
- std::vector<op_id_reply_t> r = u2->find_usrps();
- delete u2;
- return r;
-}
-
-// static
bool
usrp2_basic::pick_default_usrp(const std::string &ifc, op_id_reply_t *id)
{
@@ -197,11 +203,10 @@
return true;
}
-
bool
-usrp2_basic::find_usrp_by_mac(const u2_mac_addr_t &addr, op_id_reply_t *id)
+usrp2_basic::find_usrp_by_mac(const std::string &ifc, const u2_mac_addr_t
&addr, op_id_reply_t *id)
{
- std::vector<op_id_reply_t> r = find_usrps();
+ std::vector<op_id_reply_t> r = find_usrps(ifc);
for (unsigned i = 0; i < r.size(); i++){
if (r[i].addr == addr){
if (id)
Modified: usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h 2008-05-13
20:32:56 UTC (rev 8417)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h 2008-05-14
00:11:55 UTC (rev 8418)
@@ -82,15 +82,6 @@
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"
@@ -101,22 +92,7 @@
*/
static bool find_usrp(const std::string &ifc, const u2_mac_addr_t &addr,
op_id_reply_t *u);
- // ---- Instance methods ----
-
- ~usrp2_basic();
-
/*!
- * \param ifname interface name, e.g., "eth0"
- */
- bool open(std::string ifname = "eth0");
- bool close();
-
- /*!
- * Return a vector that describes all usrps found on already open'd interface
- */
- std::vector<op_id_reply_t> find_usrps();
-
- /*!
* \brief Find usrp by mac address
*
* \param[in] addr is the mac address of the USRP to look for
@@ -124,8 +100,16 @@
*
* \returns true iff the specified usrp was found
*/
- bool find_usrp_by_mac(const u2_mac_addr_t &addr, op_id_reply_t *u);
+ static bool find_usrp_by_mac(const std::string &ifc, const u2_mac_addr_t
&addr, op_id_reply_t *u);
+ /*!
+ * \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 Parse short or long format mac address.
@@ -137,7 +121,16 @@
*/
static bool parse_mac_addr(const std::string &s, u2_mac_addr_t *p);
+ // ---- Instance methods ----
+ ~usrp2_basic();
+
+ /*!
+ * \param ifname interface name, e.g., "eth0"
+ */
+ bool open(std::string ifname = "eth0");
+ bool close();
+
/*
* Rx configuration and control
*/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8418 - in usrp2/branches/developers/jcorgan/u2/host: apps lib,
jcorgan <=