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 | |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 35 | extern "C" { |
| 36 | #include "convolve.h" |
| 37 | #include "convert.h" |
| 38 | } |
| 39 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 40 | /* Samples-per-symbol for downlink path |
| 41 | * 4 - Uses precision modulator (more computation, less distortion) |
| 42 | * 1 - Uses minimized modulator (less computation, more distortion) |
| 43 | * |
| 44 | * Other values are invalid. Receive path (uplink) is always |
Tom Tsou | 0fe41a5 | 2016-05-03 15:14:45 -0700 | [diff] [blame] | 45 | * downsampled to 1 sps. Default to 4 sps for all cases. |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 46 | */ |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 47 | #define DEFAULT_TX_SPS 4 |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 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 | |
Tom Tsou | de116e9 | 2017-03-30 17:00:42 -0700 | [diff] [blame] | 57 | /* Default configuration parameters */ |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 58 | #define DEFAULT_TRX_PORT 5700 |
| 59 | #define DEFAULT_TRX_IP "127.0.0.1" |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 60 | #define DEFAULT_CHANS 1 |
| 61 | |
| 62 | struct trx_config { |
| 63 | std::string log_level; |
| 64 | std::string addr; |
| 65 | std::string dev_args; |
| 66 | unsigned port; |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 67 | unsigned tx_sps; |
| 68 | unsigned rx_sps; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 69 | unsigned chans; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 70 | unsigned rtsc; |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 71 | unsigned rach_delay; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 72 | bool extref; |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 73 | bool gpsref; |
Alexander Chemeris | f5fd578 | 2015-05-24 18:56:51 -0400 | [diff] [blame] | 74 | Transceiver::FillerType filler; |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 75 | bool mcbts; |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 76 | double offset; |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 77 | double rssi_offset; |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 78 | bool swap_channels; |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 79 | bool edge; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 80 | }; |
| 81 | |
Thomas Tsou | 4de70be | 2013-11-17 18:54:52 -0500 | [diff] [blame] | 82 | ConfigurationTable gConfig; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 83 | |
| 84 | volatile bool gshutdown = false; |
| 85 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 86 | /* Setup configuration values |
| 87 | * Don't query the existence of the Log.Level because it's a |
| 88 | * mandatory value. That is, if it doesn't exist, the configuration |
Thomas Tsou | 4de70be | 2013-11-17 18:54:52 -0500 | [diff] [blame] | 89 | * table will crash or will have already crashed. Everything else we |
| 90 | * can survive without and use default values if the database entries |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 91 | * are empty. |
| 92 | */ |
| 93 | bool trx_setup_config(struct trx_config *config) |
| 94 | { |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 95 | std::string refstr, fillstr, divstr, mcstr, edgestr; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 96 | |
Tom Tsou | 6031734 | 2017-03-30 19:36:41 -0700 | [diff] [blame] | 97 | if (config->mcbts && config->chans > 5) { |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 98 | std::cout << "Unsupported number of channels" << std::endl; |
| 99 | return false; |
| 100 | } |
| 101 | |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 102 | edgestr = config->edge ? "Enabled" : "Disabled"; |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 103 | mcstr = config->mcbts ? "Enabled" : "Disabled"; |
| 104 | |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 105 | if (config->extref) |
| 106 | refstr = "External"; |
| 107 | else if (config->gpsref) |
| 108 | refstr = "GPS"; |
| 109 | else |
| 110 | refstr = "Internal"; |
| 111 | |
Alexander Chemeris | f5fd578 | 2015-05-24 18:56:51 -0400 | [diff] [blame] | 112 | switch (config->filler) { |
| 113 | case Transceiver::FILLER_DUMMY: |
| 114 | fillstr = "Dummy bursts"; |
| 115 | break; |
| 116 | case Transceiver::FILLER_ZERO: |
| 117 | fillstr = "Disabled"; |
| 118 | break; |
Tom Tsou | af717b2 | 2016-03-06 22:19:15 -0800 | [diff] [blame] | 119 | case Transceiver::FILLER_NORM_RAND: |
Alexander Chemeris | f5fd578 | 2015-05-24 18:56:51 -0400 | [diff] [blame] | 120 | fillstr = "Normal busrts with random payload"; |
| 121 | break; |
Tom Tsou | af717b2 | 2016-03-06 22:19:15 -0800 | [diff] [blame] | 122 | case Transceiver::FILLER_EDGE_RAND: |
| 123 | fillstr = "EDGE busrts with random payload"; |
| 124 | break; |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 125 | case Transceiver::FILLER_ACCESS_RAND: |
| 126 | fillstr = "Access busrts with random payload"; |
| 127 | break; |
Alexander Chemeris | f5fd578 | 2015-05-24 18:56:51 -0400 | [diff] [blame] | 128 | } |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 129 | |
| 130 | std::ostringstream ost(""); |
| 131 | ost << "Config Settings" << std::endl; |
| 132 | ost << " Log Level............... " << config->log_level << std::endl; |
| 133 | ost << " Device args............. " << config->dev_args << std::endl; |
| 134 | ost << " TRX Base Port........... " << config->port << std::endl; |
| 135 | ost << " TRX Address............. " << config->addr << std::endl; |
| 136 | ost << " Channels................ " << config->chans << std::endl; |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 137 | ost << " Tx Samples-per-Symbol... " << config->tx_sps << std::endl; |
Alexander Chemeris | 1ab5e7f | 2016-04-20 08:44:55 +0300 | [diff] [blame] | 138 | ost << " Rx Samples-per-Symbol... " << config->rx_sps << std::endl; |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 139 | ost << " EDGE support............ " << edgestr << std::endl; |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 140 | ost << " Reference............... " << refstr << std::endl; |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 141 | ost << " C0 Filler Table......... " << fillstr << std::endl; |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 142 | ost << " Multi-Carrier........... " << mcstr << std::endl; |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 143 | ost << " Tuning offset........... " << config->offset << std::endl; |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 144 | ost << " RSSI to dBm offset...... " << config->rssi_offset << std::endl; |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 145 | ost << " Swap channels........... " << config->swap_channels << std::endl; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 146 | std::cout << ost << std::endl; |
| 147 | |
| 148 | return true; |
| 149 | } |
| 150 | |
| 151 | /* Create radio interface |
| 152 | * The interface consists of sample rate changes, frequency shifts, |
| 153 | * channel multiplexing, and other conversions. The transceiver core |
| 154 | * accepts input vectors sampled at multiples of the GSM symbol rate. |
| 155 | * The radio interface connects the main transceiver with the device |
| 156 | * object, which may be operating some other rate. |
| 157 | */ |
| 158 | RadioInterface *makeRadioInterface(struct trx_config *config, |
| 159 | RadioDevice *usrp, int type) |
| 160 | { |
| 161 | RadioInterface *radio = NULL; |
| 162 | |
| 163 | switch (type) { |
| 164 | case RadioDevice::NORMAL: |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 165 | radio = new RadioInterface(usrp, config->tx_sps, |
| 166 | config->rx_sps, config->chans); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 167 | break; |
| 168 | case RadioDevice::RESAMP_64M: |
| 169 | case RadioDevice::RESAMP_100M: |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 170 | radio = new RadioInterfaceResamp(usrp, config->tx_sps, |
Tom Tsou | 8f0ccf6 | 2016-07-20 16:35:03 -0700 | [diff] [blame] | 171 | config->rx_sps); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 172 | break; |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 173 | case RadioDevice::MULTI_ARFCN: |
| 174 | radio = new RadioInterfaceMulti(usrp, config->tx_sps, |
| 175 | config->rx_sps, config->chans); |
| 176 | break; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 177 | default: |
| 178 | LOG(ALERT) << "Unsupported radio interface configuration"; |
| 179 | return NULL; |
| 180 | } |
| 181 | |
| 182 | if (!radio->init(type)) { |
| 183 | LOG(ALERT) << "Failed to initialize radio interface"; |
| 184 | return NULL; |
| 185 | } |
| 186 | |
| 187 | return radio; |
| 188 | } |
| 189 | |
| 190 | /* Create transceiver core |
| 191 | * The multi-threaded modem core operates at multiples of the GSM rate of |
| 192 | * 270.8333 ksps and consists of GSM specific modulation, demodulation, |
| 193 | * and decoding schemes. Also included are the socket interfaces for |
| 194 | * connecting to the upper layer stack. |
| 195 | */ |
| 196 | Transceiver *makeTransceiver(struct trx_config *config, RadioInterface *radio) |
| 197 | { |
| 198 | Transceiver *trx; |
| 199 | VectorFIFO *fifo; |
| 200 | |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 201 | trx = new Transceiver(config->port, config->addr.c_str(), |
| 202 | config->tx_sps, config->rx_sps, config->chans, |
| 203 | GSM::Time(3,0), radio, config->rssi_offset); |
Tom Tsou | 64464e6 | 2016-07-01 03:46:46 -0700 | [diff] [blame] | 204 | if (!trx->init(config->filler, config->rtsc, |
| 205 | config->rach_delay, config->edge)) { |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 206 | LOG(ALERT) << "Failed to initialize transceiver"; |
| 207 | delete trx; |
| 208 | return NULL; |
| 209 | } |
| 210 | |
| 211 | for (size_t i = 0; i < config->chans; i++) { |
| 212 | fifo = radio->receiveFIFO(i); |
| 213 | if (fifo && trx->receiveFIFO(fifo, i)) |
| 214 | continue; |
| 215 | |
| 216 | LOG(ALERT) << "Could not attach FIFO to channel " << i; |
| 217 | delete trx; |
| 218 | return NULL; |
| 219 | } |
| 220 | |
| 221 | return trx; |
| 222 | } |
| 223 | |
| 224 | static void sig_handler(int signo) |
| 225 | { |
| 226 | fprintf(stdout, "Received shutdown signal"); |
| 227 | gshutdown = true; |
| 228 | } |
| 229 | |
| 230 | static void setup_signal_handlers() |
| 231 | { |
| 232 | if (signal(SIGINT, sig_handler) == SIG_ERR) { |
| 233 | fprintf(stderr, "Failed to install SIGINT signal handler\n"); |
| 234 | exit(EXIT_FAILURE); |
| 235 | } |
| 236 | if (signal(SIGTERM, sig_handler) == SIG_ERR) { |
| 237 | fprintf(stderr, "Couldn't install SIGTERM signal handler\n"); |
| 238 | exit( EXIT_FAILURE); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | static void print_help() |
| 243 | { |
| 244 | fprintf(stdout, "Options:\n" |
| 245 | " -h This text\n" |
| 246 | " -a UHD device args\n" |
| 247 | " -l Logging level (%s)\n" |
| 248 | " -i IP address of GSM core\n" |
| 249 | " -p Base port number\n" |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 250 | " -e Enable EDGE receiver\n" |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 251 | " -m Enable multi-ARFCN transceiver (default=disabled)\n" |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 252 | " -x Enable external 10 MHz reference\n" |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 253 | " -g Enable GPSDO reference\n" |
Tom Tsou | 2e4ed10 | 2016-06-27 15:39:16 -0700 | [diff] [blame] | 254 | " -s Tx samples-per-symbol (1 or 4)\n" |
| 255 | " -b Rx samples-per-symbol (1 or 4)\n" |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 256 | " -c Number of ARFCN channels (default=1)\n" |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 257 | " -f Enable C0 filler table\n" |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 258 | " -o Set baseband frequency offset (default=auto)\n" |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 259 | " -r Random Normal Burst test mode with TSC\n" |
| 260 | " -A Random Access Burst test mode with delay\n" |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 261 | " -R RSSI to dBm offset in dB (default=0)\n" |
| 262 | " -S Swap channels (UmTRX only)\n", |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 263 | "EMERG, ALERT, CRT, ERR, WARNING, NOTICE, INFO, DEBUG"); |
| 264 | } |
| 265 | |
| 266 | static void handle_options(int argc, char **argv, struct trx_config *config) |
| 267 | { |
| 268 | int option; |
| 269 | |
Tom Tsou | de116e9 | 2017-03-30 17:00:42 -0700 | [diff] [blame] | 270 | config->log_level = "NOTICE"; |
| 271 | config->addr = DEFAULT_TRX_IP; |
| 272 | config->port = DEFAULT_TRX_PORT; |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 273 | config->tx_sps = DEFAULT_TX_SPS; |
| 274 | config->rx_sps = DEFAULT_RX_SPS; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 275 | config->chans = DEFAULT_CHANS; |
| 276 | config->rtsc = 0; |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 277 | config->rach_delay = 0; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 278 | config->extref = false; |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 279 | config->gpsref = false; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 280 | config->filler = Transceiver::FILLER_ZERO; |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 281 | config->mcbts = false; |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 282 | config->offset = 0.0; |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 283 | config->rssi_offset = 0.0; |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 284 | config->swap_channels = false; |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 285 | config->edge = false; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 286 | |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 287 | while ((option = getopt(argc, argv, "ha:l:i:p:c:dmxgfo:s:b:r:A:R:Se")) != -1) { |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 288 | switch (option) { |
| 289 | case 'h': |
| 290 | print_help(); |
| 291 | exit(0); |
| 292 | break; |
| 293 | case 'a': |
| 294 | config->dev_args = optarg; |
| 295 | break; |
| 296 | case 'l': |
| 297 | config->log_level = optarg; |
| 298 | break; |
| 299 | case 'i': |
| 300 | config->addr = optarg; |
| 301 | break; |
| 302 | case 'p': |
| 303 | config->port = atoi(optarg); |
| 304 | break; |
| 305 | case 'c': |
| 306 | config->chans = atoi(optarg); |
| 307 | break; |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 308 | case 'm': |
| 309 | config->mcbts = true; |
| 310 | break; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 311 | case 'x': |
| 312 | config->extref = true; |
| 313 | break; |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 314 | case 'g': |
| 315 | config->gpsref = true; |
| 316 | break; |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 317 | case 'f': |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 318 | config->filler = Transceiver::FILLER_DUMMY; |
Thomas Tsou | 15d743e | 2014-01-25 02:34:03 -0500 | [diff] [blame] | 319 | break; |
Thomas Tsou | 8e17df7 | 2014-03-06 14:16:11 -0500 | [diff] [blame] | 320 | case 'o': |
| 321 | config->offset = atof(optarg); |
| 322 | break; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 323 | case 's': |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 324 | config->tx_sps = atoi(optarg); |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 325 | break; |
Tom Tsou | 2e4ed10 | 2016-06-27 15:39:16 -0700 | [diff] [blame] | 326 | case 'b': |
| 327 | config->rx_sps = atoi(optarg); |
| 328 | break; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 329 | case 'r': |
| 330 | config->rtsc = atoi(optarg); |
Tom Tsou | af717b2 | 2016-03-06 22:19:15 -0800 | [diff] [blame] | 331 | config->filler = Transceiver::FILLER_NORM_RAND; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 332 | break; |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 333 | case 'A': |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 334 | config->rach_delay = atoi(optarg); |
Alexander Chemeris | 5efe050 | 2016-03-23 17:06:32 +0300 | [diff] [blame] | 335 | config->filler = Transceiver::FILLER_ACCESS_RAND; |
| 336 | break; |
Alexander Chemeris | e8905a0 | 2015-06-03 23:47:56 -0400 | [diff] [blame] | 337 | case 'R': |
| 338 | config->rssi_offset = atof(optarg); |
| 339 | break; |
Alexander Chemeris | 50747dc | 2015-06-07 01:07:45 -0400 | [diff] [blame] | 340 | case 'S': |
| 341 | config->swap_channels = true; |
| 342 | break; |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 343 | case 'e': |
| 344 | config->edge = true; |
Tom Tsou | b0aefcb | 2016-03-06 03:44:34 -0800 | [diff] [blame] | 345 | break; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 346 | default: |
| 347 | print_help(); |
| 348 | exit(0); |
| 349 | } |
| 350 | } |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 351 | |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 352 | /* Force 4 SPS for EDGE or multi-ARFCN configurations */ |
| 353 | if ((config->edge) || (config->mcbts)) { |
Tom Tsou | 2e4ed10 | 2016-06-27 15:39:16 -0700 | [diff] [blame] | 354 | config->tx_sps = 4; |
| 355 | config->rx_sps = 4; |
| 356 | } |
| 357 | |
Tom Tsou | 8f0ccf6 | 2016-07-20 16:35:03 -0700 | [diff] [blame] | 358 | if (config->gpsref && config->extref) { |
| 359 | printf("External and GPSDO references unavailable at the same time\n\n"); |
| 360 | goto bad_config; |
| 361 | } |
| 362 | |
Tom Tsou | af717b2 | 2016-03-06 22:19:15 -0800 | [diff] [blame] | 363 | if (config->edge && (config->filler == Transceiver::FILLER_NORM_RAND)) |
| 364 | config->filler = Transceiver::FILLER_EDGE_RAND; |
| 365 | |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 366 | if ((config->tx_sps != 1) && (config->tx_sps != 4) && |
| 367 | (config->rx_sps != 1) && (config->rx_sps != 4)) { |
Tom Tsou | 5cd70dc | 2016-03-06 01:28:40 -0800 | [diff] [blame] | 368 | printf("Unsupported samples-per-symbol %i\n\n", config->tx_sps); |
Tom Tsou | 8f0ccf6 | 2016-07-20 16:35:03 -0700 | [diff] [blame] | 369 | goto bad_config; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | if (config->rtsc > 7) { |
| 373 | printf("Invalid training sequence %i\n\n", config->rtsc); |
Tom Tsou | 8f0ccf6 | 2016-07-20 16:35:03 -0700 | [diff] [blame] | 374 | goto bad_config; |
Tom Tsou | 64ad712 | 2015-05-19 18:26:31 -0700 | [diff] [blame] | 375 | } |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 376 | |
| 377 | if (config->rach_delay > 68) { |
| 378 | printf("RACH delay is too big %i\n\n", config->rach_delay); |
Tom Tsou | 8f0ccf6 | 2016-07-20 16:35:03 -0700 | [diff] [blame] | 379 | goto bad_config; |
Alexander Chemeris | 37c52c7 | 2016-03-25 18:28:34 +0300 | [diff] [blame] | 380 | } |
Tom Tsou | 8f0ccf6 | 2016-07-20 16:35:03 -0700 | [diff] [blame] | 381 | |
| 382 | return; |
| 383 | |
| 384 | bad_config: |
| 385 | print_help(); |
| 386 | exit(0); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | int main(int argc, char *argv[]) |
| 390 | { |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 391 | int type, chans, ref; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 392 | RadioDevice *usrp; |
| 393 | RadioInterface *radio = NULL; |
| 394 | Transceiver *trx = NULL; |
Tom Tsou | 05c6feb | 2016-06-22 16:09:44 -0700 | [diff] [blame] | 395 | RadioDevice::InterfaceType iface = RadioDevice::NORMAL; |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 396 | struct trx_config config; |
| 397 | |
Philipp Maier | e51a8f0 | 2017-03-16 12:09:34 +0100 | [diff] [blame] | 398 | #ifdef HAVE_SSE3 |
| 399 | printf("Info: SSE3 support compiled in"); |
| 400 | if (__builtin_cpu_supports("sse3")) |
| 401 | printf(" and supported by CPU\n"); |
| 402 | else |
| 403 | printf(", but not supported by CPU\n"); |
| 404 | #endif |
| 405 | |
| 406 | #ifdef HAVE_SSE4_1 |
| 407 | printf("Info: SSE4.1 support compiled in"); |
| 408 | if (__builtin_cpu_supports("sse4.1")) |
| 409 | printf(" and supported by CPU\n"); |
| 410 | else |
| 411 | printf(", but not supported by CPU\n"); |
| 412 | #endif |
| 413 | |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 414 | convolve_init(); |
| 415 | convert_init(); |
| 416 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 417 | handle_options(argc, argv, &config); |
| 418 | |
| 419 | setup_signal_handlers(); |
| 420 | |
| 421 | /* Check database sanity */ |
| 422 | if (!trx_setup_config(&config)) { |
| 423 | std::cerr << "Config: Database failure - exiting" << std::endl; |
| 424 | return EXIT_FAILURE; |
| 425 | } |
| 426 | |
| 427 | gLogInit("transceiver", config.log_level.c_str(), LOG_LOCAL7); |
| 428 | |
| 429 | srandom(time(NULL)); |
| 430 | |
| 431 | /* Create the low level device object */ |
Tom Tsou | 7676427 | 2016-06-24 14:25:39 -0700 | [diff] [blame] | 432 | if (config.mcbts) |
| 433 | iface = RadioDevice::MULTI_ARFCN; |
| 434 | |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 435 | if (config.extref) |
| 436 | ref = RadioDevice::REF_EXTERNAL; |
| 437 | else if (config.gpsref) |
| 438 | ref = RadioDevice::REF_GPS; |
| 439 | else |
| 440 | ref = RadioDevice::REF_INTERNAL; |
| 441 | |
Tom Tsou | 05c6feb | 2016-06-22 16:09:44 -0700 | [diff] [blame] | 442 | usrp = RadioDevice::make(config.tx_sps, config.rx_sps, iface, |
| 443 | config.chans, config.offset); |
Tom Tsou | 2f3e60b | 2016-07-17 19:29:08 -0700 | [diff] [blame] | 444 | type = usrp->open(config.dev_args, ref, config.swap_channels); |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 445 | if (type < 0) { |
| 446 | LOG(ALERT) << "Failed to create radio device" << std::endl; |
| 447 | goto shutdown; |
| 448 | } |
| 449 | |
| 450 | /* Setup the appropriate device interface */ |
| 451 | radio = makeRadioInterface(&config, usrp, type); |
| 452 | if (!radio) |
| 453 | goto shutdown; |
| 454 | |
| 455 | /* Create the transceiver core */ |
| 456 | trx = makeTransceiver(&config, radio); |
| 457 | if (!trx) |
| 458 | goto shutdown; |
| 459 | |
Thomas Tsou | 85b179d | 2013-11-15 21:14:33 -0500 | [diff] [blame] | 460 | chans = trx->numChans(); |
| 461 | std::cout << "-- Transceiver active with " |
| 462 | << chans << " channel(s)" << std::endl; |
| 463 | |
| 464 | while (!gshutdown) |
| 465 | sleep(1); |
| 466 | |
| 467 | shutdown: |
| 468 | std::cout << "Shutting down transceiver..." << std::endl; |
| 469 | |
| 470 | delete trx; |
| 471 | delete radio; |
| 472 | delete usrp; |
| 473 | |
| 474 | return 0; |
| 475 | } |