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