Changeset 9427

Show
Ignore:
Timestamp:
08/26/08 20:36:26
Author:
jcorgan
Message:

Add gr-usrp2 test program.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • usrp2/branches/developers/jcorgan/wip/host-ng/gr-usrp2/Makefile.am

    r9422 r9427  
    2121 
    2222lib_LTLIBRARIES = \ 
    23         libgr_usrp2.la 
     23        libgr-usrp2.la 
    2424 
    2525bin_PROGRAMS = \ 
     
    2828test_gr_usrp2_SOURCES = test_gr_usrp2.cc 
    2929test_gr_usrp2_LDADD = \ 
    30     libgr_usrp2.la \ 
     30    libgr-usrp2.la \ 
    3131    $(top_builddir)/lib/libusrp2ng.la 
    3232 
  • usrp2/branches/developers/jcorgan/wip/host-ng/gr-usrp2/test_gr_usrp2.cc

    r9422 r9427  
    22/* 
    33 * Copyright 2008 Free Software Foundation, Inc. 
    4  *  
    5  * This file is part of GNU Radio 
    6  *  
    7  * GNU Radio is free software; you can redistribute it and/or modify 
     4 * 
     5 * This program is free software: you can redistribute it and/or modify 
    86 * it under the terms of the GNU General Public License as published by 
    9  * the Free Software Foundation; either version 3, or (at your option) 
    10  * any later version. 
    11  *  
    12  * GNU Radio is distributed in the hope that it will be useful, 
     7 * the Free Software Foundation, either version 3 of the License, or 
     8 * (at your option) any later version. 
     9 * 
     10 * This program is distributed in the hope that it will be useful, 
    1311 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1412 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1513 * GNU General Public License for more details. 
    16  *  
     14 * 
    1715 * You should have received a copy of the GNU General Public License 
    18  * along with GNU Radio; see the file COPYING.  If not, write to 
    19  * the Free Software Foundation, Inc., 51 Franklin Street, 
    20  * Boston, MA 02110-1301, USA. 
     16 * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
    2117 */ 
    2218 
    2319#ifdef HAVE_CONFIG_H 
    24 #include "config.h" 
     20#include <config.h> 
    2521#endif 
    2622 
    27 #include "usrp2_source_c.h" 
     23#include <gruel/realtime.h> 
     24#include <usrp2_source_c.h> 
     25#include <string.h> 
     26#include <iostream> 
     27 
     28static void 
     29usage(const char *progname) 
     30
     31  const char *p = strrchr(progname, '/');       // drop leading directory path 
     32  if (p) 
     33    p++; 
     34 
     35  if (strncmp(p, "lt-", 3) == 0)                // drop lt- libtool prefix 
     36    p += 3; 
     37   
     38  fprintf(stderr, "Usage: %s [options]\n\n", p); 
     39  fprintf(stderr, "Options:\n"); 
     40  fprintf(stderr, "  -h                   show this message and exit\n"); 
     41  fprintf(stderr, "  -e ETH_INTERFACE     specify ethernet interface [default=eth0]\n"); 
     42  fprintf(stderr, "  -m MAC_ADDR          mac address of USRP2 HH:HH [default=first one found]\n"); 
     43#if 0 
     44  fprintf(stderr, "  -f FREQUENCY         specify receive center frequency in Hz [default=0.0]\n"); 
     45  fprintf(stderr, "  -d DECIM             specify receive decimation rate [default=5]\n"); 
     46  fprintf(stderr, "  -g GAIN              specify receive daughterboard gain [default=0]\n"); 
     47  fprintf(stderr, "  -N NSAMPLES          specify number of samples to receive [default=infinite]\n"); 
     48  fprintf(stderr, "  -o OUTPUT_FILENAME   specify file to receive samples [default=none]\n"); 
     49  fprintf(stderr, "  -s                   write complex<short> [default=complex<float>]\n"); 
     50#endif 
     51  fprintf(stderr, "  -v                   verbose output\n"); 
     52
    2853 
    2954int 
    30 main(char *argc, char **argv) 
     55main(int argc, char **argv) 
    3156{ 
    32   usrp2_source_c_sptr u2 = usrp2_make_source_c(); 
    33   printf("Using USRP2 at %s\n", u2->mac_addr().c_str()); 
     57  // options and their defaults 
     58  const char *interface = "eth0"; 
     59  const char *mac_addr_str = ""; 
     60#if 0 
     61  double rx_freq = 0.0; 
     62  int rx_decim = 5; 
     63  double rx_gain = 0.0; 
     64  uint64_t nsamples = 0; 
     65  bool output_shorts = false; 
     66  char *output_filename = 0; 
     67#endif 
     68  bool verbose = false; 
     69 
     70  int ch; 
     71 
     72  //while ((ch = getopt(argc, argv, "he:m:f:d:g:N:o:sv")) != EOF){ 
     73  while ((ch = getopt(argc, argv, "he:m:v")) != EOF){ 
     74    //double tmp; 
     75    switch (ch){ 
     76 
     77    case 'e': 
     78      interface = optarg; 
     79      break; 
     80       
     81    case 'm': 
     82      mac_addr_str = optarg; 
     83      break; 
     84#if 0 
     85    case 'f': 
     86      if (!strtod_si(optarg, &rx_freq)) { 
     87        std::cerr << "invalid number: " << optarg << std::endl; 
     88        usage(argv[0]); 
     89        exit(1); 
     90      } 
     91      break; 
     92 
     93    case 'g': 
     94      if (!strtod_si(optarg, &rx_gain)) { 
     95        std::cerr << "invalid number: " << optarg << std::endl; 
     96        usage(argv[0]); 
     97        exit(1); 
     98      } 
     99      break; 
     100 
     101    case 'd': 
     102      rx_decim = strtol(optarg, 0, 0); 
     103      if (rx_decim < 4 or rx_decim > 512) {  
     104        std::cerr << "invalid decimation rate: " << optarg << std::endl; 
     105        usage(argv[0]); 
     106        exit(1); 
     107      } 
     108      break; 
     109 
     110    case 'N': 
     111      if (!strtod_si(optarg, &tmp)) { 
     112        std::cerr << "invalid number: " << optarg << std::endl; 
     113        usage(argv[0]); 
     114        exit(1); 
     115      } 
     116      nsamples = static_cast<uint64_t>(tmp); 
     117      break; 
     118       
     119    case 's': 
     120      output_shorts = true; 
     121      break; 
     122 
     123    case 'o': 
     124      output_filename = optarg; 
     125      break; 
     126#endif       
     127    case 'v': 
     128      verbose = true; 
     129      break; 
     130 
     131    case 'h': 
     132    default: 
     133      usage(argv[0]); 
     134      exit(1); 
     135    } 
     136  } 
     137 
     138  gruel::rt_status_t rt = gruel::enable_realtime_scheduling(); 
     139  if (rt != gruel::RT_OK) 
     140    std::cerr << "Failed to enable realtime scheduling" << std::endl; 
     141 
     142  usrp2_source_c_sptr u2 = usrp2_make_source_c(interface, mac_addr_str); 
     143 
     144#if 0 
     145  if (!u2->set_rx_gain(rx_gain)){ 
     146    fprintf(stderr, "set_rx_gain(%f) failed\n", rx_gain); 
     147    exit(1); 
     148  } 
     149 
     150  usrp2::tune_result tr; 
     151  if (!u2->set_rx_center_freq(rx_freq, &tr)){ 
     152    fprintf(stderr, "set_rx_center_freq(%g) failed\n", rx_freq); 
     153    exit(1); 
     154  } 
     155#endif 
     156 
     157  if (verbose){ 
     158    printf("USRP2 MAC address: %s\n\n", u2->mac_addr().c_str()); 
     159#if 0 
     160    printf("Daughterboard configuration:\n"); 
     161    printf("  baseband_freq=%f\n", tr.baseband_freq); 
     162    printf("       ddc_freq=%f\n", tr.dxc_freq); 
     163    printf("  residual_freq=%f\n", tr.residual_freq); 
     164    printf("       inverted=%s\n\n", tr.spectrum_inverted ? "yes" : "no"); 
     165#endif 
     166  } 
     167#if 0 
     168  if (!u2->set_rx_decim(rx_decim)) { 
     169    fprintf(stderr, "set_rx_decim(%d) failed\n", rx_decim); 
     170    exit(1); 
     171  } 
     172 
     173  if (verbose) 
     174    printf("USRP2 using decimation rate of %d\n", rx_decim); 
     175     
     176  if (verbose) { 
     177    if (nsamples > 0) 
     178        printf("Receiving %zd samples\n\n", nsamples); 
     179    else 
     180        printf("Receiving infinite samples\n\n"); 
     181  } 
     182   
     183  struct timeval start, end; 
     184  gettimeofday(&start, 0); 
     185 
     186  // Run flowgraph here 
     187 
     188  gettimeofday(&end, 0); 
     189  long n_usecs = end.tv_usec-start.tv_usec; 
     190  long n_secs = end.tv_sec-start.tv_sec; 
     191  double elapsed = (double)n_secs + (double)n_usecs*1e-6; 
     192#endif 
     193 
     194  return 0; 
    34195}