Changeset 9496
- Timestamp:
- 09/04/08 00:27:32
- Files:
-
- usrp2/trunk/host/Makefile.common (modified) (1 diff)
- usrp2/trunk/host/apps (modified) (1 prop)
- usrp2/trunk/host/apps/Makefile.am (modified) (2 diffs)
- usrp2/trunk/host/apps/usrp2_burn_mac_addr.cc (moved) (moved from usrp2/trunk/host/apps/u2_burn_mac_addr.cc) (7 diffs)
- usrp2/trunk/host/config/Makefile.am (modified) (1 diff)
- usrp2/trunk/host/config/acx_pthread.m4 (copied) (copied from gnuradio/trunk/config/acx_pthread.m4)
- usrp2/trunk/host/configure.ac (modified) (3 diffs)
- usrp2/trunk/host/include/usrp2/usrp2.h (modified) (2 diffs)
- usrp2/trunk/host/lib/Makefile.am (modified) (2 diffs)
- usrp2/trunk/host/lib/control.h (modified) (1 diff)
- usrp2/trunk/host/lib/usrp2.cc (modified) (2 diffs)
- usrp2/trunk/host/lib/usrp2_impl.cc (modified) (1 diff)
- usrp2/trunk/host/lib/usrp2_impl.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
usrp2/trunk/host/Makefile.common
r9442 r9496 22 22 -I$(top_srcdir)/include \ 23 23 -I$(top_srcdir)/../firmware/include \ 24 $(GNURADIO_CORE_CFLAGS) 24 $(GRUEL_CFLAGS) \ 25 $(GR_OMNITHREAD_CFLAGS) 25 26 26 27 usrp2/trunk/host/apps
- Property svn:ignore changed from Makefile Makefile.in .libs .deps test_eth test_usrp2 gen_const find_usrps cerr *.sh tx_samples rx_streaming_samples to Makefile Makefile.in .libs .deps test_eth test_usrp2 gen_const find_usrps cerr *.sh tx_samples rx_streaming_samples u2_burn_mac_addr usrp2_burn_mac_addr
usrp2/trunk/host/apps/Makefile.am
r9445 r9496 25 25 26 26 bin_PROGRAMS = \ 27 find_usrps 27 find_usrps \ 28 usrp2_burn_mac_addr 28 29 29 30 noinst_PROGRAMS = \ … … 32 33 tx_samples 33 34 34 find_usrps = find_usrps.cc 35 find_usrps_SOURCES = find_usrps.cc 36 usrp2_burn_mac_addr_SOURCES = usrp2_burn_mac_addr.cc 35 37 rx_streaming_samples_SOURCES = rx_streaming_samples.cc 36 38 gen_const_SOURCES = gen_const.cc usrp2/trunk/host/apps/usrp2_burn_mac_addr.cc
r9495 r9496 1 1 /* -*- c++ -*- */ 2 2 /* 3 * Copyright 2007 Free Software Foundation, Inc.3 * Copyright 2007,2008 Free Software Foundation, Inc. 4 4 * 5 5 * This program is free software: you can redistribute it and/or modify … … 18 18 19 19 #ifdef HAVE_CONFIG_H 20 #include "config.h"20 #include <config.h> 21 21 #endif 22 #include "usrp2_basic.h"22 #include <usrp2/usrp2.h> 23 23 #include <iostream> 24 24 #include <getopt.h> 25 25 #include <string.h> 26 26 #include <time.h> 27 #include <stdio.h> 28 #include <signal.h> 29 #include <stdexcept> 30 31 32 static volatile bool signaled = false; 33 34 static void 35 sig_handler(int sig) 36 { 37 signaled = true; 38 } 39 40 static void 41 install_sig_handler(int signum, 42 void (*new_handler)(int)) 43 { 44 struct sigaction new_action; 45 memset (&new_action, 0, sizeof (new_action)); 46 47 new_action.sa_handler = new_handler; 48 sigemptyset (&new_action.sa_mask); 49 new_action.sa_flags = 0; 50 51 if (sigaction (signum, &new_action, 0) < 0){ 52 perror ("sigaction (install new)"); 53 throw std::runtime_error ("sigaction"); 54 } 55 } 27 56 28 57 … … 36 65 } 37 66 67 static bool 68 check_mac_addr_syntax(const std::string &s) 69 { 70 unsigned char addr[6]; 71 72 addr[0] = 0x00; // Matt's IAB 73 addr[1] = 0x50; 74 addr[2] = 0xC2; 75 addr[3] = 0x85; 76 addr[4] = 0x30; 77 addr[5] = 0x00; 78 79 int len = s.size(); 80 81 switch (len){ 82 83 case 5: 84 return sscanf(s.c_str(), "%hhx:%hhx", &addr[4], &addr[5]) == 2; 85 86 case 17: 87 return sscanf(s.c_str(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", 88 &addr[0], &addr[1], &addr[2], 89 &addr[3], &addr[4], &addr[5]) == 6; 90 default: 91 return false; 92 } 93 94 return true; 95 } 96 97 38 98 int 39 99 main(int argc, char **argv) … … 41 101 int ch; 42 102 const char *interface = "eth0"; 43 char *old_mac_addr_str = "00:50:c2:85:3f:ff"; 44 char *new_mac_addr_str = 0; 45 u2_mac_addr_t old_mac_addr; 46 u2_mac_addr_t new_mac_addr; 103 const char *old_mac_addr = "00:50:c2:85:3f:ff"; 104 const char *new_mac_addr = 0; 47 105 48 106 while ((ch = getopt(argc, argv, "he:m:")) != EOF){ … … 53 111 54 112 case 'm': 55 old_mac_addr _str= optarg;113 old_mac_addr = optarg; 56 114 break; 57 115 … … 68 126 } 69 127 70 new_mac_addr _str= argv[optind];128 new_mac_addr = argv[optind]; 71 129 72 if (! usrp2_basic::parse_mac_addr(old_mac_addr_str, &old_mac_addr)){73 fprintf(stderr, "invalid mac address: %s\n", old_mac_addr _str);130 if (!check_mac_addr_syntax(old_mac_addr)){ 131 fprintf(stderr, "invalid mac address: %s\n", old_mac_addr); 74 132 exit(1); 75 133 } 76 if (! usrp2_basic::parse_mac_addr(new_mac_addr_str, &new_mac_addr)){77 fprintf(stderr, "invalid mac address: %s\n", new_mac_addr _str);134 if (!check_mac_addr_syntax(new_mac_addr)){ 135 fprintf(stderr, "invalid mac address: %s\n", new_mac_addr); 78 136 exit(1); 79 137 } 80 138 139 install_sig_handler(SIGINT, sig_handler); 81 140 82 usrp2 _basic *u2 = new usrp2_basic();141 usrp2::usrp2::sptr u2; 83 142 84 if (!u2->open(interface)){ 85 std::cerr << "couldn't open " << interface << std::endl; 86 return 0; 143 try { 144 u2 = usrp2::usrp2::make(interface, old_mac_addr); 87 145 } 88 89 if (!u2->find_usrp_by_mac(old_mac_addr, 0)){ 90 std::cerr << "No USRP2 with address " 91 << old_mac_addr << " found.\n"; 146 catch (std::exception const &e){ 147 std::cerr << e.what() << std::endl; 92 148 return 1; 93 149 } 94 150 95 if (!u2->burn_mac_addr(old_mac_addr, new_mac_addr)){ 96 std::cerr << "Failed to burn mac address\n"; 151 if (!u2->burn_mac_addr(new_mac_addr)){ 152 std::cerr << "Failed to burn mac address: " 153 << new_mac_addr << std::endl; 97 154 return 1; 98 155 } 156 157 u2.reset(); // close 99 158 100 159 // wait 250 ms … … 104 163 nanosleep(&ts, 0); 105 164 106 // Now see if we can find it using it's new address 107 if (!u2->find_usrp_by_mac(new_mac_addr, 0)){ 108 std::cerr << "Failed to find USRP2 using new address " 109 << new_mac_addr << ".\n"; 165 try { 166 u2 = usrp2::usrp2::make(interface, new_mac_addr); 167 } 168 catch (std::exception const &e){ 169 std::cerr << "Failed to connect to USRP2 using new addr: " 170 << new_mac_addr << std::endl; 171 std::cerr << e.what() << std::endl; 110 172 return 1; 111 173 } usrp2/trunk/host/config/Makefile.am
r9442 r9496 20 20 21 21 M4FILES = \ 22 acx_pthread.m4 \ 22 23 ax_boost_base.m4 \ 23 24 ax_boost_date_time.m4 \ usrp2/trunk/host/configure.ac
r9442 r9496 90 90 91 91 GR_NO_UNDEFINED dnl do we need the -no-undefined linker flag 92 GR_SCRIPTING92 dnl GR_SCRIPTING 93 93 94 94 dnl AC_CHECK_PROG([XMLTO],[xmlto],[yes],[]) … … 188 188 dnl CXXFLAGS="${CXXFLAGS} $PTHREAD_CFLAGS" 189 189 190 191 190 dnl conditional build stuff 192 191 GR_CHECK_DOXYGEN 193 GR_SET_MD_CPU194 192 195 193 dnl Define where to look for cppunit includes and libs … … 209 207 AX_BOOST_BASE([1.35]) 210 208 211 dnl so we can use some utilities. FIXME hoist them out 212 PKG_CHECK_MODULES(GNURADIO_CORE, gnuradio-core >= 3) 209 dnl calls AC_SUBST(BOOST_THREAD_LIB), AC_SUBST(BOOST_CXXFLAGS) and defines HAVE_BOOST_THREAD 210 AX_BOOST_THREAD 211 CXXFLAGS="$CXXFLAGS $BOOST_CXXFLAGS" dnl often picks up a -pthread or something similar 212 CFLAGS="$CFLAGS $BOOST_CXXFLAGS" dnl often picks up a -pthread or something similar 213 213 214 214 215 # If this is being done from a subversion tree, create variables usrp2/trunk/host/include/usrp2/usrp2.h
r9455 r9496 74 74 * 75 75 * \param ifc Network interface name, e.g., "eth0" 76 * \param addr Network mac address, e.g., "01: 02:03:04:05:06", "05:06" or "".76 * \param addr Network mac address, e.g., "01:23:45:67:89:ab", "89:ab" or "". 77 77 * If \p addr is HH:HH, it's treated as if it were 00:50:c2:85:HH:HH 78 78 * "" will autoselect a USRP2 if there is only a single one on the local ethernet. … … 89 89 */ 90 90 std::string mac_addr(); 91 92 /*! 93 * Burn new mac address into EEPROM on USRP2 94 * 95 * \param new_addr Network mac address, e.g., "01:23:45:67:89:ab" or "89:ab". 96 * If \p addr is HH:HH, it's treated as if it were 00:50:c2:85:HH:HH 97 */ 98 bool burn_mac_addr(const std::string &new_addr); 91 99 92 100 /* usrp2/trunk/host/lib/Makefile.am
r9463 r9496 19 19 20 20 #AM_CXXFLAGS = -Wall -Werror (handle this with: $ ./configure CXXFLAGS="-Wall -Werror -O2 -g") 21 AM_CPPFLAGS = $( STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(GRUEL_CFLAGS) $(BOOST_CFLAGS)21 AM_CPPFLAGS = $(BOOST_CPPFLAGS) $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(GRUEL_CFLAGS) 22 22 23 23 lib_LTLIBRARIES = \ … … 43 43 libusrp2_la_LIBADD = \ 44 44 $(GR_OMNITHREAD_LIBS) \ 45 $(GRUEL_LIBS) 45 $(GRUEL_LIBS) \ 46 $(BOOST_LDFLAGS) $(BOOST_THREAD_LIB) 46 47 47 48 # Private headers not needed for above the API development usrp2/trunk/host/lib/control.h
r9142 r9496 54 54 }; 55 55 56 struct op_burn_mac_addr_cmd 57 { 58 u2_eth_packet_t h; 59 op_burn_mac_addr_t op; 60 op_generic_t eop; 61 }; 56 62 57 63 /*! usrp2/trunk/host/lib/usrp2.cc
r9459 r9496 131 131 if (n == 0) { 132 132 if (addr == "") 133 throw std::runtime_error("No USRPs found on interface .");133 throw std::runtime_error("No USRPs found on interface " + ifc); 134 134 else 135 throw std::runtime_error(" Specified USRP2 not found on interface.");135 throw std::runtime_error("No USRP found with addr " + addr + " on interface " + ifc); 136 136 } 137 137 … … 160 160 return d_impl->mac_addr(); 161 161 } 162 163 bool 164 usrp2::burn_mac_addr(const std::string &new_addr) 165 { 166 return d_impl->burn_mac_addr(new_addr); 167 } 168 162 169 163 170 // Receive usrp2/trunk/host/lib/usrp2_impl.cc
r9459 r9496 411 411 } 412 412 413 414 // ---------------------------------------------------------------- 415 // misc commands 416 // ---------------------------------------------------------------- 417 418 bool 419 usrp2::impl::burn_mac_addr(const std::string &new_addr) 420 { 421 op_burn_mac_addr_cmd cmd; 422 op_generic_t reply; 423 424 memset(&cmd, 0, sizeof(cmd)); 425 init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1); 426 cmd.op.opcode = OP_BURN_MAC_ADDR; 427 cmd.op.len = sizeof(cmd.op); 428 cmd.op.rid = d_next_rid++; 429 if (!parse_mac_addr(new_addr, &cmd.op.addr)) 430 return false; 431 432 pending_reply p(cmd.op.rid, &reply, sizeof(reply)); 433 if (!transmit_cmd(&cmd, sizeof(cmd), &p, 4*DEF_CMD_TIMEOUT)) 434 return false; 435 436 bool success = (ntohx(reply.ok) == 1); 437 return success; 438 } 439 440 413 441 // ---------------------------------------------------------------- 414 442 // Receive usrp2/trunk/host/lib/usrp2_impl.h
r9459 r9496 96 96 97 97 std::string mac_addr() const { return d_addr; } // FIXME: convert from u2_mac_addr_t 98 bool burn_mac_addr(const std::string &new_addr); 99 98 100 bool set_rx_gain(double gain); 99 101 bool set_rx_center_freq(double frequency, tune_result *result);
