| 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 | |
|---|
| | 28 | static void |
|---|
| | 29 | usage(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 | } |
|---|
| 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; |
|---|