Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Thomas Tsou <tom@tsou.cc> |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | |
| 19 | #ifdef HAVE_CONFIG_H |
| 20 | #include "config.h" |
| 21 | #endif |
| 22 | |
| 23 | #include "Transceiver.h" |
| 24 | #include "radioDevice.h" |
| 25 | |
| 26 | #include <time.h> |
| 27 | #include <signal.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <unistd.h> |
| 30 | |
| 31 | #include <GSMCommon.h> |
| 32 | #include <Logger.h> |
| 33 | #include <Configuration.h> |
| 34 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 35 | /* Samples-per-symbol for downlink path |
| 36 | * 4 - Uses precision modulator (more computation, less distortion) |
| 37 | * 1 - Uses minimized modulator (less computation, more distortion) |
| 38 | * |
| 39 | * Other values are invalid. Receive path (uplink) is always |
| 40 | * downsampled to 1 sps. Default to 4 sps for all cases except for |
| 41 | * ARM and non-SIMD enabled architectures. |
| 42 | */ |
| 43 | #if defined(HAVE_NEON) || !defined(HAVE_SSE3) |
| 44 | #define DEFAULT_SPS 1 |
| 45 | #else |
| 46 | #define DEFAULT_SPS 4 |
| 47 | #endif |
| 48 | |
| 49 | /* Default configuration parameters |
| 50 | * Note that these values are only used if the particular key does not |
| 51 | * exist in the configuration database. IP port and address values will |
| 52 | * typically be overwritten by the OpenBTS.db values. Other values will |
| 53 | * not be in the database by default. |
| 54 | */ |
| 55 | #define DEFAULT_TRX_PORT 5700 |
| 56 | #define DEFAULT_TRX_IP "127.0.0.1" |
| 57 | #define DEFAULT_EXTREF false |
| 58 | #define DEFAULT_DIVERSITY false |
| 59 | #define DEFAULT_CHANS 1 |
| 60 | |
| 61 | struct trx_config { |
| 62 | std::string log_level; |
| 63 | std::string addr; |
| 64 | std::string dev_args; |
| 65 | unsigned port; |
| 66 | unsigned sps; |
| 67 | unsigned chans; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 68 | unsigned rtsc; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 69 | bool extref; |
Alexander Chemeris | f5fd578 | 2015-05-24 18:56:51 -0400 | [diff] [blame] | 70 | Transceiver::FillerType filler; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 71 | bool diversity; |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 72 | double offset; |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 73 | double rssi_offset; |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 74 | bool swap_channels; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 75 | }; |
| 76 | |
Thomas Tsou | 4de70be | 2013-11-17 18:54:52 -0500 | [diff] [blame] | 77 | ConfigurationTable gConfig; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 78 | |
| 79 | volatile bool gshutdown = false; |
| 80 | |
| 81 | /* Run sanity check on configuration table |
| 82 | * The global table constructor cannot provide notification in the |
Thomas Tsou | 4de70be | 2013-11-17 18:54:52 -0500 | [diff] [blame] | 83 | * event of failure. Make sure that we can access the database, |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 84 | * write to it, and that it contains the bare minimum required keys. |
| 85 | */ |
Thomas Tsou | 4de70be | 2013-11-17 18:54:52 -0500 | [diff] [blame] | 86 | bool testConfig() |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 87 | { |
Thomas Tsou | 4de70be | 2013-11-17 18:54:52 -0500 | [diff] [blame] | 88 | int val = 9999; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 89 | std::string test = "asldfkjsaldkf"; |
| 90 | const char *key = "Log.Level"; |
| 91 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 92 | /* Attempt to query */ |
| 93 | try { |
| 94 | gConfig.getStr(key); |
| 95 | } catch (...) { |
| 96 | std::cerr << std::endl; |
| 97 | std::cerr << "Config: Failed query required key " << key |
| 98 | << std::endl; |
| 99 | return false; |
| 100 | } |
| 101 | |
Thomas Tsou | 4de70be | 2013-11-17 18:54:52 -0500 | [diff] [blame] | 102 | /* Attempt to set a test value in the global config */ |
| 103 | if (!gConfig.set(test, val)) { |
| 104 | std::cerr << std::endl; |
| 105 | std::cerr << "Config: Failed to set test key" << std::endl; |
| 106 | return false; |
| 107 | } else { |
| 108 | gConfig.remove(test); |
| 109 | } |
| 110 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 111 | return true; |
| 112 | } |
| 113 | |
Thomas Tsou | 4de70be | 2013-11-17 18:54:52 -0500 | [diff] [blame] | 114 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 115 | /* Setup configuration values |
| 116 | * Don't query the existence of the Log.Level because it's a |
| 117 | * mandatory value. That is, if it doesn't exist, the configuration |
Thomas Tsou | 4de70be | 2013-11-17 18:54:52 -0500 | [diff] [blame] | 118 | * table will crash or will have already crashed. Everything else we |
| 119 | * can survive without and use default values if the database entries |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 120 | * are empty. |
| 121 | */ |
| 122 | bool trx_setup_config(struct trx_config *config) |
| 123 | { |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 124 | std::string refstr, fillstr, divstr; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 125 | |
Thomas Tsou | 4de70be | 2013-11-17 18:54:52 -0500 | [diff] [blame] | 126 | if (!testConfig()) |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 127 | return false; |
| 128 | |
| 129 | if (config->log_level == "") |
| 130 | config->log_level = gConfig.getStr("Log.Level"); |
| 131 | |
| 132 | if (!config->port) { |
| 133 | if (gConfig.defines("TRX.Port")) |
| 134 | config->port = gConfig.getNum("TRX.Port"); |
| 135 | else |
| 136 | config->port = DEFAULT_TRX_PORT; |
| 137 | } |
| 138 | |
| 139 | if (config->addr == "") { |
| 140 | if (gConfig.defines("TRX.IP")) |
| 141 | config->addr = gConfig.getStr("TRX.IP"); |
| 142 | else |
| 143 | config->addr = DEFAULT_TRX_IP; |
| 144 | } |
| 145 | |
| 146 | if (!config->extref) { |
| 147 | if (gConfig.defines("TRX.Reference")) |
| 148 | config->extref = gConfig.getNum("TRX.Reference"); |
| 149 | else |
| 150 | config->extref = DEFAULT_EXTREF; |
| 151 | } |
| 152 | |
| 153 | if (!config->diversity) { |
| 154 | if (gConfig.defines("TRX.Diversity")) |
| 155 | config->diversity = gConfig.getNum("TRX.Diversity"); |
| 156 | else |
| 157 | config->diversity = DEFAULT_DIVERSITY; |
| 158 | } |
| 159 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 160 | /* Diversity only supported on 2 channels */ |
| 161 | if (config->diversity) |
| 162 | config->chans = 2; |
| 163 | |
| 164 | refstr = config->extref ? "Enabled" : "Disabled"; |
| 165 | divstr = config->diversity ? "Enabled" : "Disabled"; |
Alexander Chemeris | f5fd578 | 2015-05-24 18:56:51 -0400 | [diff] [blame] | 166 | switch (config->filler) { |
| 167 | case Transceiver::FILLER_DUMMY: |
| 168 | fillstr = "Dummy bursts"; |
| 169 | break; |
| 170 | case Transceiver::FILLER_ZERO: |
| 171 | fillstr = "Disabled"; |
| 172 | break; |
| 173 | case Transceiver::FILLER_RAND: |
| 174 | fillstr = "Normal busrts with random payload"; |
| 175 | break; |
| 176 | } |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 177 | |
| 178 | std::ostringstream ost(""); |
| 179 | ost << "Config Settings" << std::endl; |
| 180 | ost << " Log Level............... " << config->log_level << std::endl; |
| 181 | ost << " Device args............. " << config->dev_args << std::endl; |
| 182 | ost << " TRX Base Port........... " << config->port << std::endl; |
| 183 | ost << " TRX Address............. " << config->addr << std::endl; |
| 184 | ost << " Channels................ " << config->chans << std::endl; |
| 185 | ost << " Samples-per-Symbol...... " << config->sps << std::endl; |
| 186 | ost << " External Reference...... " << refstr << std::endl; |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 187 | ost << " C0 Filler Table......... " << fillstr << std::endl; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 188 | ost << " Diversity............... " << divstr << std::endl; |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 189 | ost << " Tuning offset........... " << config->offset << std::endl; |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 190 | ost << " RSSI to dBm offset...... " << config->rssi_offset << std::endl; |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 191 | ost << " Swap channels........... " << config->swap_channels << std::endl; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 192 | std::cout << ost << std::endl; |
| 193 | |
| 194 | return true; |
| 195 | } |
| 196 | |
| 197 | /* Create radio interface |
| 198 | * The interface consists of sample rate changes, frequency shifts, |
| 199 | * channel multiplexing, and other conversions. The transceiver core |
| 200 | * accepts input vectors sampled at multiples of the GSM symbol rate. |
| 201 | * The radio interface connects the main transceiver with the device |
| 202 | * object, which may be operating some other rate. |
| 203 | */ |
| 204 | RadioInterface *makeRadioInterface(struct trx_config *config, |
| 205 | RadioDevice *usrp, int type) |
| 206 | { |
| 207 | RadioInterface *radio = NULL; |
| 208 | |
| 209 | switch (type) { |
| 210 | case RadioDevice::NORMAL: |
| 211 | radio = new RadioInterface(usrp, config->sps, config->chans); |
| 212 | break; |
| 213 | case RadioDevice::RESAMP_64M: |
| 214 | case RadioDevice::RESAMP_100M: |
| 215 | radio = new RadioInterfaceResamp(usrp, |
| 216 | config->sps, config->chans); |
| 217 | break; |
| 218 | case RadioDevice::DIVERSITY: |
| 219 | radio = new RadioInterfaceDiversity(usrp, |
| 220 | config->sps, config->chans); |
| 221 | break; |
| 222 | default: |
| 223 | LOG(ALERT) << "Unsupported radio interface configuration"; |
| 224 | return NULL; |
| 225 | } |
| 226 | |
| 227 | if (!radio->init(type)) { |
| 228 | LOG(ALERT) << "Failed to initialize radio interface"; |
| 229 | return NULL; |
| 230 | } |
| 231 | |
| 232 | return radio; |
| 233 | } |
| 234 | |
| 235 | /* Create transceiver core |
| 236 | * The multi-threaded modem core operates at multiples of the GSM rate of |
| 237 | * 270.8333 ksps and consists of GSM specific modulation, demodulation, |
| 238 | * and decoding schemes. Also included are the socket interfaces for |
| 239 | * connecting to the upper layer stack. |
| 240 | */ |
| 241 | Transceiver *makeTransceiver(struct trx_config *config, RadioInterface *radio) |
| 242 | { |
| 243 | Transceiver *trx; |
| 244 | VectorFIFO *fifo; |
| 245 | |
| 246 | trx = new Transceiver(config->port, config->addr.c_str(), config->sps, |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 247 | config->chans, GSM::Time(3,0), radio, config->rssi_offset); |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 248 | if (!trx->init(config->filler, config->rtsc)) { |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 249 | LOG(ALERT) << "Failed to initialize transceiver"; |
| 250 | delete trx; |
| 251 | return NULL; |
| 252 | } |
| 253 | |
| 254 | for (size_t i = 0; i < config->chans; i++) { |
| 255 | fifo = radio->receiveFIFO(i); |
| 256 | if (fifo && trx->receiveFIFO(fifo, i)) |
| 257 | continue; |
| 258 | |
| 259 | LOG(ALERT) << "Could not attach FIFO to channel " << i; |
| 260 | delete trx; |
| 261 | return NULL; |
| 262 | } |
| 263 | |
| 264 | return trx; |
| 265 | } |
| 266 | |
| 267 | static void sig_handler(int signo) |
| 268 | { |
| 269 | fprintf(stdout, "Received shutdown signal"); |
| 270 | gshutdown = true; |
| 271 | } |
| 272 | |
| 273 | static void setup_signal_handlers() |
| 274 | { |
| 275 | if (signal(SIGINT, sig_handler) == SIG_ERR) { |
| 276 | fprintf(stderr, "Failed to install SIGINT signal handler\n"); |
| 277 | exit(EXIT_FAILURE); |
| 278 | } |
| 279 | if (signal(SIGTERM, sig_handler) == SIG_ERR) { |
| 280 | fprintf(stderr, "Couldn't install SIGTERM signal handler\n"); |
| 281 | exit( EXIT_FAILURE); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | static void print_help() |
| 286 | { |
| 287 | fprintf(stdout, "Options:\n" |
| 288 | " -h This text\n" |
| 289 | " -a UHD device args\n" |
| 290 | " -l Logging level (%s)\n" |
| 291 | " -i IP address of GSM core\n" |
| 292 | " -p Base port number\n" |
| 293 | " -d Enable dual channel diversity receiver\n" |
| 294 | " -x Enable external 10 MHz reference\n" |
| 295 | " -s Samples-per-symbol (1 or 4)\n" |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 296 | " -c Number of ARFCN channels (default=1)\n" |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 297 | " -f Enable C0 filler table\n" |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 298 | " -o Set baseband frequency offset (default=auto)\n" |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 299 | " -r Random burst test mode with TSC\n" |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 300 | " -R RSSI to dBm offset in dB (default=0)\n" |
| 301 | " -S Swap channels (UmTRX only)\n", |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 302 | "EMERG, ALERT, CRT, ERR, WARNING, NOTICE, INFO, DEBUG"); |
| 303 | } |
| 304 | |
| 305 | static void handle_options(int argc, char **argv, struct trx_config *config) |
| 306 | { |
| 307 | int option; |
| 308 | |
| 309 | config->port = 0; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 310 | config->sps = DEFAULT_SPS; |
| 311 | config->chans = DEFAULT_CHANS; |
| 312 | config->rtsc = 0; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 313 | config->extref = false; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 314 | config->filler = Transceiver::FILLER_ZERO; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 315 | config->diversity = false; |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 316 | config->offset = 0.0; |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 317 | config->rssi_offset = 0.0; |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 318 | config->swap_channels = false; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 319 | |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 320 | while ((option = getopt(argc, argv, "ha:l:i:p:c:dxfo:s:r:R:S")) != -1) { |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 321 | switch (option) { |
| 322 | case 'h': |
| 323 | print_help(); |
| 324 | exit(0); |
| 325 | break; |
| 326 | case 'a': |
| 327 | config->dev_args = optarg; |
| 328 | break; |
| 329 | case 'l': |
| 330 | config->log_level = optarg; |
| 331 | break; |
| 332 | case 'i': |
| 333 | config->addr = optarg; |
| 334 | break; |
| 335 | case 'p': |
| 336 | config->port = atoi(optarg); |
| 337 | break; |
| 338 | case 'c': |
| 339 | config->chans = atoi(optarg); |
| 340 | break; |
| 341 | case 'd': |
| 342 | config->diversity = true; |
| 343 | break; |
| 344 | case 'x': |
| 345 | config->extref = true; |
| 346 | break; |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 347 | case 'f': |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 348 | config->filler = Transceiver::FILLER_DUMMY; |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 349 | break; |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 350 | case 'o': |
| 351 | config->offset = atof(optarg); |
| 352 | break; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 353 | case 's': |
| 354 | config->sps = atoi(optarg); |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 355 | break; |
| 356 | case 'r': |
| 357 | config->rtsc = atoi(optarg); |
| 358 | config->filler = Transceiver::FILLER_RAND; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 359 | break; |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 360 | case 'R': |
| 361 | config->rssi_offset = atof(optarg); |
| 362 | break; |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 363 | case 'S': |
| 364 | config->swap_channels = true; |
| 365 | break; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 366 | default: |
| 367 | print_help(); |
| 368 | exit(0); |
| 369 | } |
| 370 | } |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 371 | |
| 372 | if ((config->sps != 1) && (config->sps != 4)) { |
| 373 | printf("Unsupported samples-per-symbol %i\n\n", config->sps); |
| 374 | print_help(); |
| 375 | exit(0); |
| 376 | } |
| 377 | |
| 378 | if (config->rtsc > 7) { |
| 379 | printf("Invalid training sequence %i\n\n", config->rtsc); |
| 380 | print_help(); |
| 381 | exit(0); |
| 382 | } |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | int main(int argc, char *argv[]) |
| 386 | { |
| 387 | int type, chans; |
| 388 | RadioDevice *usrp; |
| 389 | RadioInterface *radio = NULL; |
| 390 | Transceiver *trx = NULL; |
| 391 | struct trx_config config; |
| 392 | |
| 393 | handle_options(argc, argv, &config); |
| 394 | |
| 395 | setup_signal_handlers(); |
| 396 | |
| 397 | /* Check database sanity */ |
| 398 | if (!trx_setup_config(&config)) { |
| 399 | std::cerr << "Config: Database failure - exiting" << std::endl; |
| 400 | return EXIT_FAILURE; |
| 401 | } |
| 402 | |
| 403 | gLogInit("transceiver", config.log_level.c_str(), LOG_LOCAL7); |
| 404 | |
| 405 | srandom(time(NULL)); |
| 406 | |
| 407 | /* Create the low level device object */ |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 408 | usrp = RadioDevice::make(config.sps, config.chans, |
| 409 | config.diversity, config.offset); |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 410 | type = usrp->open(config.dev_args, config.extref, config.swap_channels); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 411 | if (type < 0) { |
| 412 | LOG(ALERT) << "Failed to create radio device" << std::endl; |
| 413 | goto shutdown; |
| 414 | } |
| 415 | |
| 416 | /* Setup the appropriate device interface */ |
| 417 | radio = makeRadioInterface(&config, usrp, type); |
| 418 | if (!radio) |
| 419 | goto shutdown; |
| 420 | |
| 421 | /* Create the transceiver core */ |
| 422 | trx = makeTransceiver(&config, radio); |
| 423 | if (!trx) |
| 424 | goto shutdown; |
| 425 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 426 | chans = trx->numChans(); |
| 427 | std::cout << "-- Transceiver active with " |
| 428 | << chans << " channel(s)" << std::endl; |
| 429 | |
| 430 | while (!gshutdown) |
| 431 | sleep(1); |
| 432 | |
| 433 | shutdown: |
| 434 | std::cout << "Shutting down transceiver..." << std::endl; |
| 435 | |
| 436 | delete trx; |
| 437 | delete radio; |
| 438 | delete usrp; |
| 439 | |
| 440 | return 0; |
| 441 | } |