blob: 5e8158609a081d22204076d1c1989b3d5d7ac530 [file] [log] [blame]
Thomas Tsou85b179d2013-11-15 21:14:33 -05001/*
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 Tsou85b179d2013-11-15 21:14:33 -050035/* 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 Tsou0fe41a52016-05-03 15:14:45 -070040 * downsampled to 1 sps. Default to 4 sps for all cases.
Thomas Tsou85b179d2013-11-15 21:14:33 -050041 */
Tom Tsou5cd70dc2016-03-06 01:28:40 -080042#define DEFAULT_TX_SPS 4
Thomas Tsou85b179d2013-11-15 21:14:33 -050043
Tom Tsou5cd70dc2016-03-06 01:28:40 -080044/*
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
Thomas Tsou85b179d2013-11-15 21:14:33 -050052/* Default configuration parameters
53 * Note that these values are only used if the particular key does not
54 * exist in the configuration database. IP port and address values will
55 * typically be overwritten by the OpenBTS.db values. Other values will
56 * not be in the database by default.
57 */
58#define DEFAULT_TRX_PORT 5700
59#define DEFAULT_TRX_IP "127.0.0.1"
60#define DEFAULT_EXTREF false
61#define DEFAULT_DIVERSITY false
62#define DEFAULT_CHANS 1
63
64struct trx_config {
65 std::string log_level;
66 std::string addr;
67 std::string dev_args;
68 unsigned port;
Tom Tsou5cd70dc2016-03-06 01:28:40 -080069 unsigned tx_sps;
70 unsigned rx_sps;
Thomas Tsou85b179d2013-11-15 21:14:33 -050071 unsigned chans;
Tom Tsou64ad7122015-05-19 18:26:31 -070072 unsigned rtsc;
Alexander Chemeris37c52c72016-03-25 18:28:34 +030073 unsigned rach_delay;
Thomas Tsou85b179d2013-11-15 21:14:33 -050074 bool extref;
Tom Tsou2f3e60b2016-07-17 19:29:08 -070075 bool gpsref;
Alexander Chemerisf5fd5782015-05-24 18:56:51 -040076 Transceiver::FillerType filler;
Thomas Tsou85b179d2013-11-15 21:14:33 -050077 bool diversity;
Tom Tsou76764272016-06-24 14:25:39 -070078 bool mcbts;
Thomas Tsou8e17df72014-03-06 14:16:11 -050079 double offset;
Alexander Chemerise8905a02015-06-03 23:47:56 -040080 double rssi_offset;
Alexander Chemeris50747dc2015-06-07 01:07:45 -040081 bool swap_channels;
Tom Tsoub0aefcb2016-03-06 03:44:34 -080082 bool edge;
Thomas Tsou85b179d2013-11-15 21:14:33 -050083};
84
Thomas Tsou4de70be2013-11-17 18:54:52 -050085ConfigurationTable gConfig;
Thomas Tsou85b179d2013-11-15 21:14:33 -050086
87volatile bool gshutdown = false;
88
89/* Run sanity check on configuration table
90 * The global table constructor cannot provide notification in the
Thomas Tsou4de70be2013-11-17 18:54:52 -050091 * event of failure. Make sure that we can access the database,
Thomas Tsou85b179d2013-11-15 21:14:33 -050092 * write to it, and that it contains the bare minimum required keys.
93 */
Thomas Tsou4de70be2013-11-17 18:54:52 -050094bool testConfig()
Thomas Tsou85b179d2013-11-15 21:14:33 -050095{
Thomas Tsou4de70be2013-11-17 18:54:52 -050096 int val = 9999;
Thomas Tsou85b179d2013-11-15 21:14:33 -050097 std::string test = "asldfkjsaldkf";
98 const char *key = "Log.Level";
99
Thomas Tsou85b179d2013-11-15 21:14:33 -0500100 /* Attempt to query */
101 try {
102 gConfig.getStr(key);
103 } catch (...) {
104 std::cerr << std::endl;
105 std::cerr << "Config: Failed query required key " << key
106 << std::endl;
107 return false;
108 }
109
Thomas Tsou4de70be2013-11-17 18:54:52 -0500110 /* Attempt to set a test value in the global config */
111 if (!gConfig.set(test, val)) {
112 std::cerr << std::endl;
113 std::cerr << "Config: Failed to set test key" << std::endl;
114 return false;
115 } else {
116 gConfig.remove(test);
117 }
118
Thomas Tsou85b179d2013-11-15 21:14:33 -0500119 return true;
120}
121
Thomas Tsou4de70be2013-11-17 18:54:52 -0500122
Thomas Tsou85b179d2013-11-15 21:14:33 -0500123/* Setup configuration values
124 * Don't query the existence of the Log.Level because it's a
125 * mandatory value. That is, if it doesn't exist, the configuration
Thomas Tsou4de70be2013-11-17 18:54:52 -0500126 * table will crash or will have already crashed. Everything else we
127 * can survive without and use default values if the database entries
Thomas Tsou85b179d2013-11-15 21:14:33 -0500128 * are empty.
129 */
130bool trx_setup_config(struct trx_config *config)
131{
Tom Tsou76764272016-06-24 14:25:39 -0700132 std::string refstr, fillstr, divstr, mcstr, edgestr;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500133
Thomas Tsou4de70be2013-11-17 18:54:52 -0500134 if (!testConfig())
Thomas Tsou85b179d2013-11-15 21:14:33 -0500135 return false;
136
137 if (config->log_level == "")
138 config->log_level = gConfig.getStr("Log.Level");
139
140 if (!config->port) {
141 if (gConfig.defines("TRX.Port"))
142 config->port = gConfig.getNum("TRX.Port");
143 else
144 config->port = DEFAULT_TRX_PORT;
145 }
146
147 if (config->addr == "") {
148 if (gConfig.defines("TRX.IP"))
149 config->addr = gConfig.getStr("TRX.IP");
150 else
151 config->addr = DEFAULT_TRX_IP;
152 }
153
154 if (!config->extref) {
155 if (gConfig.defines("TRX.Reference"))
156 config->extref = gConfig.getNum("TRX.Reference");
157 else
158 config->extref = DEFAULT_EXTREF;
159 }
160
161 if (!config->diversity) {
162 if (gConfig.defines("TRX.Diversity"))
163 config->diversity = gConfig.getNum("TRX.Diversity");
164 else
165 config->diversity = DEFAULT_DIVERSITY;
166 }
167
Tom Tsou76764272016-06-24 14:25:39 -0700168 if (!config->chans)
169 config->chans = DEFAULT_CHANS;
170
171 if (config->mcbts && ((config->chans < 0) || (config->chans > 5))) {
172 std::cout << "Unsupported number of channels" << std::endl;
173 return false;
174 }
175
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800176 edgestr = config->edge ? "Enabled" : "Disabled";
Thomas Tsou85b179d2013-11-15 21:14:33 -0500177 divstr = config->diversity ? "Enabled" : "Disabled";
Tom Tsou76764272016-06-24 14:25:39 -0700178 mcstr = config->mcbts ? "Enabled" : "Disabled";
179
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700180 if (config->extref)
181 refstr = "External";
182 else if (config->gpsref)
183 refstr = "GPS";
184 else
185 refstr = "Internal";
186
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400187 switch (config->filler) {
188 case Transceiver::FILLER_DUMMY:
189 fillstr = "Dummy bursts";
190 break;
191 case Transceiver::FILLER_ZERO:
192 fillstr = "Disabled";
193 break;
Tom Tsouaf717b22016-03-06 22:19:15 -0800194 case Transceiver::FILLER_NORM_RAND:
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400195 fillstr = "Normal busrts with random payload";
196 break;
Tom Tsouaf717b22016-03-06 22:19:15 -0800197 case Transceiver::FILLER_EDGE_RAND:
198 fillstr = "EDGE busrts with random payload";
199 break;
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300200 case Transceiver::FILLER_ACCESS_RAND:
201 fillstr = "Access busrts with random payload";
202 break;
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400203 }
Thomas Tsou85b179d2013-11-15 21:14:33 -0500204
205 std::ostringstream ost("");
206 ost << "Config Settings" << std::endl;
207 ost << " Log Level............... " << config->log_level << std::endl;
208 ost << " Device args............. " << config->dev_args << std::endl;
209 ost << " TRX Base Port........... " << config->port << std::endl;
210 ost << " TRX Address............. " << config->addr << std::endl;
211 ost << " Channels................ " << config->chans << std::endl;
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800212 ost << " Tx Samples-per-Symbol... " << config->tx_sps << std::endl;
Alexander Chemeris1ab5e7f2016-04-20 08:44:55 +0300213 ost << " Rx Samples-per-Symbol... " << config->rx_sps << std::endl;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800214 ost << " EDGE support............ " << edgestr << std::endl;
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700215 ost << " Reference............... " << refstr << std::endl;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500216 ost << " C0 Filler Table......... " << fillstr << std::endl;
Tom Tsou76764272016-06-24 14:25:39 -0700217 ost << " Multi-Carrier........... " << mcstr << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500218 ost << " Diversity............... " << divstr << std::endl;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500219 ost << " Tuning offset........... " << config->offset << std::endl;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400220 ost << " RSSI to dBm offset...... " << config->rssi_offset << std::endl;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400221 ost << " Swap channels........... " << config->swap_channels << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500222 std::cout << ost << std::endl;
223
224 return true;
225}
226
227/* Create radio interface
228 * The interface consists of sample rate changes, frequency shifts,
229 * channel multiplexing, and other conversions. The transceiver core
230 * accepts input vectors sampled at multiples of the GSM symbol rate.
231 * The radio interface connects the main transceiver with the device
232 * object, which may be operating some other rate.
233 */
234RadioInterface *makeRadioInterface(struct trx_config *config,
235 RadioDevice *usrp, int type)
236{
237 RadioInterface *radio = NULL;
238
239 switch (type) {
240 case RadioDevice::NORMAL:
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800241 radio = new RadioInterface(usrp, config->tx_sps,
242 config->rx_sps, config->chans);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500243 break;
244 case RadioDevice::RESAMP_64M:
245 case RadioDevice::RESAMP_100M:
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800246 radio = new RadioInterfaceResamp(usrp, config->tx_sps,
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700247 config->rx_sps);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500248 break;
249 case RadioDevice::DIVERSITY:
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700250
251
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800252 radio = new RadioInterfaceDiversity(usrp, config->tx_sps,
253 config->chans);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500254 break;
Tom Tsou76764272016-06-24 14:25:39 -0700255 case RadioDevice::MULTI_ARFCN:
256 radio = new RadioInterfaceMulti(usrp, config->tx_sps,
257 config->rx_sps, config->chans);
258 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500259 default:
260 LOG(ALERT) << "Unsupported radio interface configuration";
261 return NULL;
262 }
263
264 if (!radio->init(type)) {
265 LOG(ALERT) << "Failed to initialize radio interface";
266 return NULL;
267 }
268
269 return radio;
270}
271
272/* Create transceiver core
273 * The multi-threaded modem core operates at multiples of the GSM rate of
274 * 270.8333 ksps and consists of GSM specific modulation, demodulation,
275 * and decoding schemes. Also included are the socket interfaces for
276 * connecting to the upper layer stack.
277 */
278Transceiver *makeTransceiver(struct trx_config *config, RadioInterface *radio)
279{
280 Transceiver *trx;
281 VectorFIFO *fifo;
282
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800283 trx = new Transceiver(config->port, config->addr.c_str(),
284 config->tx_sps, config->rx_sps, config->chans,
285 GSM::Time(3,0), radio, config->rssi_offset);
Tom Tsou64464e62016-07-01 03:46:46 -0700286 if (!trx->init(config->filler, config->rtsc,
287 config->rach_delay, config->edge)) {
Thomas Tsou85b179d2013-11-15 21:14:33 -0500288 LOG(ALERT) << "Failed to initialize transceiver";
289 delete trx;
290 return NULL;
291 }
292
293 for (size_t i = 0; i < config->chans; i++) {
294 fifo = radio->receiveFIFO(i);
295 if (fifo && trx->receiveFIFO(fifo, i))
296 continue;
297
298 LOG(ALERT) << "Could not attach FIFO to channel " << i;
299 delete trx;
300 return NULL;
301 }
302
303 return trx;
304}
305
306static void sig_handler(int signo)
307{
308 fprintf(stdout, "Received shutdown signal");
309 gshutdown = true;
310}
311
312static void setup_signal_handlers()
313{
314 if (signal(SIGINT, sig_handler) == SIG_ERR) {
315 fprintf(stderr, "Failed to install SIGINT signal handler\n");
316 exit(EXIT_FAILURE);
317 }
318 if (signal(SIGTERM, sig_handler) == SIG_ERR) {
319 fprintf(stderr, "Couldn't install SIGTERM signal handler\n");
320 exit( EXIT_FAILURE);
321 }
322}
323
324static void print_help()
325{
326 fprintf(stdout, "Options:\n"
327 " -h This text\n"
328 " -a UHD device args\n"
329 " -l Logging level (%s)\n"
330 " -i IP address of GSM core\n"
331 " -p Base port number\n"
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800332 " -e Enable EDGE receiver\n"
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700333 " -d Enable dual channel diversity receiver (deprecated)\n"
Tom Tsou76764272016-06-24 14:25:39 -0700334 " -m Enable multi-ARFCN transceiver (default=disabled)\n"
Thomas Tsou85b179d2013-11-15 21:14:33 -0500335 " -x Enable external 10 MHz reference\n"
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700336 " -g Enable GPSDO reference\n"
Tom Tsou2e4ed102016-06-27 15:39:16 -0700337 " -s Tx samples-per-symbol (1 or 4)\n"
338 " -b Rx samples-per-symbol (1 or 4)\n"
Thomas Tsou15d743e2014-01-25 02:34:03 -0500339 " -c Number of ARFCN channels (default=1)\n"
Thomas Tsou8e17df72014-03-06 14:16:11 -0500340 " -f Enable C0 filler table\n"
Tom Tsou64ad7122015-05-19 18:26:31 -0700341 " -o Set baseband frequency offset (default=auto)\n"
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300342 " -r Random Normal Burst test mode with TSC\n"
343 " -A Random Access Burst test mode with delay\n"
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400344 " -R RSSI to dBm offset in dB (default=0)\n"
345 " -S Swap channels (UmTRX only)\n",
Thomas Tsou85b179d2013-11-15 21:14:33 -0500346 "EMERG, ALERT, CRT, ERR, WARNING, NOTICE, INFO, DEBUG");
347}
348
349static void handle_options(int argc, char **argv, struct trx_config *config)
350{
351 int option;
352
353 config->port = 0;
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800354 config->tx_sps = DEFAULT_TX_SPS;
355 config->rx_sps = DEFAULT_RX_SPS;
Tom Tsou64ad7122015-05-19 18:26:31 -0700356 config->chans = DEFAULT_CHANS;
357 config->rtsc = 0;
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300358 config->rach_delay = 0;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500359 config->extref = false;
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700360 config->gpsref = false;
Tom Tsou64ad7122015-05-19 18:26:31 -0700361 config->filler = Transceiver::FILLER_ZERO;
Tom Tsou76764272016-06-24 14:25:39 -0700362 config->mcbts = false;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500363 config->diversity = false;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500364 config->offset = 0.0;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400365 config->rssi_offset = 0.0;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400366 config->swap_channels = false;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800367 config->edge = false;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500368
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700369 while ((option = getopt(argc, argv, "ha:l:i:p:c:dmxgfo:s:b:r:A:R:Se")) != -1) {
Thomas Tsou85b179d2013-11-15 21:14:33 -0500370 switch (option) {
371 case 'h':
372 print_help();
373 exit(0);
374 break;
375 case 'a':
376 config->dev_args = optarg;
377 break;
378 case 'l':
379 config->log_level = optarg;
380 break;
381 case 'i':
382 config->addr = optarg;
383 break;
384 case 'p':
385 config->port = atoi(optarg);
386 break;
387 case 'c':
388 config->chans = atoi(optarg);
389 break;
Tom Tsou76764272016-06-24 14:25:39 -0700390 case 'm':
391 config->mcbts = true;
392 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500393 case 'd':
394 config->diversity = true;
395 break;
396 case 'x':
397 config->extref = true;
398 break;
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700399 case 'g':
400 config->gpsref = true;
401 break;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500402 case 'f':
Tom Tsou64ad7122015-05-19 18:26:31 -0700403 config->filler = Transceiver::FILLER_DUMMY;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500404 break;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500405 case 'o':
406 config->offset = atof(optarg);
407 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500408 case 's':
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800409 config->tx_sps = atoi(optarg);
Tom Tsou64ad7122015-05-19 18:26:31 -0700410 break;
Tom Tsou2e4ed102016-06-27 15:39:16 -0700411 case 'b':
412 config->rx_sps = atoi(optarg);
413 break;
Tom Tsou64ad7122015-05-19 18:26:31 -0700414 case 'r':
415 config->rtsc = atoi(optarg);
Tom Tsouaf717b22016-03-06 22:19:15 -0800416 config->filler = Transceiver::FILLER_NORM_RAND;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500417 break;
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300418 case 'A':
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300419 config->rach_delay = atoi(optarg);
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300420 config->filler = Transceiver::FILLER_ACCESS_RAND;
421 break;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400422 case 'R':
423 config->rssi_offset = atof(optarg);
424 break;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400425 case 'S':
426 config->swap_channels = true;
427 break;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800428 case 'e':
429 config->edge = true;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800430 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500431 default:
432 print_help();
433 exit(0);
434 }
435 }
Tom Tsou64ad7122015-05-19 18:26:31 -0700436
Tom Tsou76764272016-06-24 14:25:39 -0700437 /* Force 4 SPS for EDGE or multi-ARFCN configurations */
438 if ((config->edge) || (config->mcbts)) {
Tom Tsou2e4ed102016-06-27 15:39:16 -0700439 config->tx_sps = 4;
440 config->rx_sps = 4;
441 }
442
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700443 if (config->gpsref && config->extref) {
444 printf("External and GPSDO references unavailable at the same time\n\n");
445 goto bad_config;
446 }
447
448 /* Special restrictions on (deprecated) diversity configuration */
449 if (config->diversity) {
450 if (config->mcbts || config->edge) {
451 std::cout << "Multi-carrier/EDGE diversity unsupported" << std::endl;
452 goto bad_config;
453 }
454
455 if (config->rx_sps != 1) {
456 std::cout << "Diversity only supported with 1 SPS" << std::endl;
457 goto bad_config;
458 }
459
460 if (config->chans != 2) {
461 std::cout << "Diversity only supported with 2 channels" << std::endl;
462 goto bad_config;
463 }
464 }
465
Tom Tsouaf717b22016-03-06 22:19:15 -0800466 if (config->edge && (config->filler == Transceiver::FILLER_NORM_RAND))
467 config->filler = Transceiver::FILLER_EDGE_RAND;
468
Tom Tsou76764272016-06-24 14:25:39 -0700469 if ((config->tx_sps != 1) && (config->tx_sps != 4) &&
470 (config->rx_sps != 1) && (config->rx_sps != 4)) {
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800471 printf("Unsupported samples-per-symbol %i\n\n", config->tx_sps);
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700472 goto bad_config;
Tom Tsou64ad7122015-05-19 18:26:31 -0700473 }
474
475 if (config->rtsc > 7) {
476 printf("Invalid training sequence %i\n\n", config->rtsc);
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700477 goto bad_config;
Tom Tsou64ad7122015-05-19 18:26:31 -0700478 }
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300479
480 if (config->rach_delay > 68) {
481 printf("RACH delay is too big %i\n\n", config->rach_delay);
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700482 goto bad_config;
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300483 }
Tom Tsou8f0ccf62016-07-20 16:35:03 -0700484
485 return;
486
487bad_config:
488 print_help();
489 exit(0);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500490}
491
492int main(int argc, char *argv[])
493{
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700494 int type, chans, ref;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500495 RadioDevice *usrp;
496 RadioInterface *radio = NULL;
497 Transceiver *trx = NULL;
Tom Tsou05c6feb2016-06-22 16:09:44 -0700498 RadioDevice::InterfaceType iface = RadioDevice::NORMAL;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500499 struct trx_config config;
500
501 handle_options(argc, argv, &config);
502
503 setup_signal_handlers();
504
505 /* Check database sanity */
506 if (!trx_setup_config(&config)) {
507 std::cerr << "Config: Database failure - exiting" << std::endl;
508 return EXIT_FAILURE;
509 }
510
511 gLogInit("transceiver", config.log_level.c_str(), LOG_LOCAL7);
512
513 srandom(time(NULL));
514
515 /* Create the low level device object */
Tom Tsou76764272016-06-24 14:25:39 -0700516 if (config.mcbts)
517 iface = RadioDevice::MULTI_ARFCN;
518
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700519 if (config.extref)
520 ref = RadioDevice::REF_EXTERNAL;
521 else if (config.gpsref)
522 ref = RadioDevice::REF_GPS;
523 else
524 ref = RadioDevice::REF_INTERNAL;
525
Tom Tsou05c6feb2016-06-22 16:09:44 -0700526 usrp = RadioDevice::make(config.tx_sps, config.rx_sps, iface,
527 config.chans, config.offset);
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700528 type = usrp->open(config.dev_args, ref, config.swap_channels);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500529 if (type < 0) {
530 LOG(ALERT) << "Failed to create radio device" << std::endl;
531 goto shutdown;
532 }
533
534 /* Setup the appropriate device interface */
535 radio = makeRadioInterface(&config, usrp, type);
536 if (!radio)
537 goto shutdown;
538
539 /* Create the transceiver core */
540 trx = makeTransceiver(&config, radio);
541 if (!trx)
542 goto shutdown;
543
Thomas Tsou85b179d2013-11-15 21:14:33 -0500544 chans = trx->numChans();
545 std::cout << "-- Transceiver active with "
546 << chans << " channel(s)" << std::endl;
547
548 while (!gshutdown)
549 sleep(1);
550
551shutdown:
552 std::cout << "Shutting down transceiver..." << std::endl;
553
554 delete trx;
555 delete radio;
556 delete usrp;
557
558 return 0;
559}