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