blob: a13ec1bdad97de29196b4ee7e37c5459c28fcfa1 [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
176 /* Diversity only supported on 2 channels without multi-carrier */
177 if (config->diversity && config->mcbts) {
178 std::cout << "Multi-carrier diversity unsupported" << std::endl;
179 return false;
180 }
181 if (config->diversity && (config->chans != 2)) {
182 std::cout << "Setting channels to 2 for diversity" << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500183 config->chans = 2;
Tom Tsou76764272016-06-24 14:25:39 -0700184 }
Thomas Tsou85b179d2013-11-15 21:14:33 -0500185
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800186 edgestr = config->edge ? "Enabled" : "Disabled";
Thomas Tsou85b179d2013-11-15 21:14:33 -0500187 divstr = config->diversity ? "Enabled" : "Disabled";
Tom Tsou76764272016-06-24 14:25:39 -0700188 mcstr = config->mcbts ? "Enabled" : "Disabled";
189
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700190 if (config->extref)
191 refstr = "External";
192 else if (config->gpsref)
193 refstr = "GPS";
194 else
195 refstr = "Internal";
196
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400197 switch (config->filler) {
198 case Transceiver::FILLER_DUMMY:
199 fillstr = "Dummy bursts";
200 break;
201 case Transceiver::FILLER_ZERO:
202 fillstr = "Disabled";
203 break;
Tom Tsouaf717b22016-03-06 22:19:15 -0800204 case Transceiver::FILLER_NORM_RAND:
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400205 fillstr = "Normal busrts with random payload";
206 break;
Tom Tsouaf717b22016-03-06 22:19:15 -0800207 case Transceiver::FILLER_EDGE_RAND:
208 fillstr = "EDGE busrts with random payload";
209 break;
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300210 case Transceiver::FILLER_ACCESS_RAND:
211 fillstr = "Access busrts with random payload";
212 break;
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400213 }
Thomas Tsou85b179d2013-11-15 21:14:33 -0500214
215 std::ostringstream ost("");
216 ost << "Config Settings" << std::endl;
217 ost << " Log Level............... " << config->log_level << std::endl;
218 ost << " Device args............. " << config->dev_args << std::endl;
219 ost << " TRX Base Port........... " << config->port << std::endl;
220 ost << " TRX Address............. " << config->addr << std::endl;
221 ost << " Channels................ " << config->chans << std::endl;
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800222 ost << " Tx Samples-per-Symbol... " << config->tx_sps << std::endl;
Alexander Chemeris1ab5e7f2016-04-20 08:44:55 +0300223 ost << " Rx Samples-per-Symbol... " << config->rx_sps << std::endl;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800224 ost << " EDGE support............ " << edgestr << std::endl;
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700225 ost << " Reference............... " << refstr << std::endl;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500226 ost << " C0 Filler Table......... " << fillstr << std::endl;
Tom Tsou76764272016-06-24 14:25:39 -0700227 ost << " Multi-Carrier........... " << mcstr << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500228 ost << " Diversity............... " << divstr << std::endl;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500229 ost << " Tuning offset........... " << config->offset << std::endl;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400230 ost << " RSSI to dBm offset...... " << config->rssi_offset << std::endl;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400231 ost << " Swap channels........... " << config->swap_channels << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500232 std::cout << ost << std::endl;
233
234 return true;
235}
236
237/* Create radio interface
238 * The interface consists of sample rate changes, frequency shifts,
239 * channel multiplexing, and other conversions. The transceiver core
240 * accepts input vectors sampled at multiples of the GSM symbol rate.
241 * The radio interface connects the main transceiver with the device
242 * object, which may be operating some other rate.
243 */
244RadioInterface *makeRadioInterface(struct trx_config *config,
245 RadioDevice *usrp, int type)
246{
247 RadioInterface *radio = NULL;
248
249 switch (type) {
250 case RadioDevice::NORMAL:
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800251 radio = new RadioInterface(usrp, config->tx_sps,
252 config->rx_sps, config->chans);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500253 break;
254 case RadioDevice::RESAMP_64M:
255 case RadioDevice::RESAMP_100M:
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800256 radio = new RadioInterfaceResamp(usrp, config->tx_sps,
257 config->chans);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500258 break;
259 case RadioDevice::DIVERSITY:
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800260 radio = new RadioInterfaceDiversity(usrp, config->tx_sps,
261 config->chans);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500262 break;
Tom Tsou76764272016-06-24 14:25:39 -0700263 case RadioDevice::MULTI_ARFCN:
264 radio = new RadioInterfaceMulti(usrp, config->tx_sps,
265 config->rx_sps, config->chans);
266 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500267 default:
268 LOG(ALERT) << "Unsupported radio interface configuration";
269 return NULL;
270 }
271
272 if (!radio->init(type)) {
273 LOG(ALERT) << "Failed to initialize radio interface";
274 return NULL;
275 }
276
277 return radio;
278}
279
280/* Create transceiver core
281 * The multi-threaded modem core operates at multiples of the GSM rate of
282 * 270.8333 ksps and consists of GSM specific modulation, demodulation,
283 * and decoding schemes. Also included are the socket interfaces for
284 * connecting to the upper layer stack.
285 */
286Transceiver *makeTransceiver(struct trx_config *config, RadioInterface *radio)
287{
288 Transceiver *trx;
289 VectorFIFO *fifo;
290
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800291 trx = new Transceiver(config->port, config->addr.c_str(),
292 config->tx_sps, config->rx_sps, config->chans,
293 GSM::Time(3,0), radio, config->rssi_offset);
Tom Tsou64464e62016-07-01 03:46:46 -0700294 if (!trx->init(config->filler, config->rtsc,
295 config->rach_delay, config->edge)) {
Thomas Tsou85b179d2013-11-15 21:14:33 -0500296 LOG(ALERT) << "Failed to initialize transceiver";
297 delete trx;
298 return NULL;
299 }
300
301 for (size_t i = 0; i < config->chans; i++) {
302 fifo = radio->receiveFIFO(i);
303 if (fifo && trx->receiveFIFO(fifo, i))
304 continue;
305
306 LOG(ALERT) << "Could not attach FIFO to channel " << i;
307 delete trx;
308 return NULL;
309 }
310
311 return trx;
312}
313
314static void sig_handler(int signo)
315{
316 fprintf(stdout, "Received shutdown signal");
317 gshutdown = true;
318}
319
320static void setup_signal_handlers()
321{
322 if (signal(SIGINT, sig_handler) == SIG_ERR) {
323 fprintf(stderr, "Failed to install SIGINT signal handler\n");
324 exit(EXIT_FAILURE);
325 }
326 if (signal(SIGTERM, sig_handler) == SIG_ERR) {
327 fprintf(stderr, "Couldn't install SIGTERM signal handler\n");
328 exit( EXIT_FAILURE);
329 }
330}
331
332static void print_help()
333{
334 fprintf(stdout, "Options:\n"
335 " -h This text\n"
336 " -a UHD device args\n"
337 " -l Logging level (%s)\n"
338 " -i IP address of GSM core\n"
339 " -p Base port number\n"
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800340 " -e Enable EDGE receiver\n"
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700341 " -d Enable dual channel diversity receiver (deprecated)\n"
Tom Tsou76764272016-06-24 14:25:39 -0700342 " -m Enable multi-ARFCN transceiver (default=disabled)\n"
Thomas Tsou85b179d2013-11-15 21:14:33 -0500343 " -x Enable external 10 MHz reference\n"
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700344 " -g Enable GPSDO reference\n"
Tom Tsou2e4ed102016-06-27 15:39:16 -0700345 " -s Tx samples-per-symbol (1 or 4)\n"
346 " -b Rx samples-per-symbol (1 or 4)\n"
Thomas Tsou15d743e2014-01-25 02:34:03 -0500347 " -c Number of ARFCN channels (default=1)\n"
Thomas Tsou8e17df72014-03-06 14:16:11 -0500348 " -f Enable C0 filler table\n"
Tom Tsou64ad7122015-05-19 18:26:31 -0700349 " -o Set baseband frequency offset (default=auto)\n"
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300350 " -r Random Normal Burst test mode with TSC\n"
351 " -A Random Access Burst test mode with delay\n"
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400352 " -R RSSI to dBm offset in dB (default=0)\n"
353 " -S Swap channels (UmTRX only)\n",
Thomas Tsou85b179d2013-11-15 21:14:33 -0500354 "EMERG, ALERT, CRT, ERR, WARNING, NOTICE, INFO, DEBUG");
355}
356
357static void handle_options(int argc, char **argv, struct trx_config *config)
358{
359 int option;
360
361 config->port = 0;
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800362 config->tx_sps = DEFAULT_TX_SPS;
363 config->rx_sps = DEFAULT_RX_SPS;
Tom Tsou64ad7122015-05-19 18:26:31 -0700364 config->chans = DEFAULT_CHANS;
365 config->rtsc = 0;
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300366 config->rach_delay = 0;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500367 config->extref = false;
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700368 config->gpsref = false;
Tom Tsou64ad7122015-05-19 18:26:31 -0700369 config->filler = Transceiver::FILLER_ZERO;
Tom Tsou76764272016-06-24 14:25:39 -0700370 config->mcbts = false;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500371 config->diversity = false;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500372 config->offset = 0.0;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400373 config->rssi_offset = 0.0;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400374 config->swap_channels = false;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800375 config->edge = false;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500376
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700377 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 -0500378 switch (option) {
379 case 'h':
380 print_help();
381 exit(0);
382 break;
383 case 'a':
384 config->dev_args = optarg;
385 break;
386 case 'l':
387 config->log_level = optarg;
388 break;
389 case 'i':
390 config->addr = optarg;
391 break;
392 case 'p':
393 config->port = atoi(optarg);
394 break;
395 case 'c':
396 config->chans = atoi(optarg);
397 break;
Tom Tsou76764272016-06-24 14:25:39 -0700398 case 'm':
399 config->mcbts = true;
400 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500401 case 'd':
402 config->diversity = true;
403 break;
404 case 'x':
405 config->extref = true;
406 break;
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700407 case 'g':
408 config->gpsref = true;
409 break;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500410 case 'f':
Tom Tsou64ad7122015-05-19 18:26:31 -0700411 config->filler = Transceiver::FILLER_DUMMY;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500412 break;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500413 case 'o':
414 config->offset = atof(optarg);
415 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500416 case 's':
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800417 config->tx_sps = atoi(optarg);
Tom Tsou64ad7122015-05-19 18:26:31 -0700418 break;
Tom Tsou2e4ed102016-06-27 15:39:16 -0700419 case 'b':
420 config->rx_sps = atoi(optarg);
421 break;
Tom Tsou64ad7122015-05-19 18:26:31 -0700422 case 'r':
423 config->rtsc = atoi(optarg);
Tom Tsouaf717b22016-03-06 22:19:15 -0800424 config->filler = Transceiver::FILLER_NORM_RAND;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500425 break;
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300426 case 'A':
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300427 config->rach_delay = atoi(optarg);
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300428 config->filler = Transceiver::FILLER_ACCESS_RAND;
429 break;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400430 case 'R':
431 config->rssi_offset = atof(optarg);
432 break;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400433 case 'S':
434 config->swap_channels = true;
435 break;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800436 case 'e':
437 config->edge = true;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800438 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500439 default:
440 print_help();
441 exit(0);
442 }
443 }
Tom Tsou64ad7122015-05-19 18:26:31 -0700444
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700445 if (config->gpsref && config->extref) {
446 printf("External and GPSDO references unavailable at the same time\n\n");
447 print_help();
448 exit(0);
449 }
450
Tom Tsou76764272016-06-24 14:25:39 -0700451 /* Force 4 SPS for EDGE or multi-ARFCN configurations */
452 if ((config->edge) || (config->mcbts)) {
Tom Tsou2e4ed102016-06-27 15:39:16 -0700453 config->tx_sps = 4;
454 config->rx_sps = 4;
455 }
456
Tom Tsouaf717b22016-03-06 22:19:15 -0800457 if (config->edge && (config->filler == Transceiver::FILLER_NORM_RAND))
458 config->filler = Transceiver::FILLER_EDGE_RAND;
459
Tom Tsou76764272016-06-24 14:25:39 -0700460 if ((config->tx_sps != 1) && (config->tx_sps != 4) &&
461 (config->rx_sps != 1) && (config->rx_sps != 4)) {
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800462 printf("Unsupported samples-per-symbol %i\n\n", config->tx_sps);
Tom Tsou64ad7122015-05-19 18:26:31 -0700463 print_help();
464 exit(0);
465 }
466
467 if (config->rtsc > 7) {
468 printf("Invalid training sequence %i\n\n", config->rtsc);
469 print_help();
470 exit(0);
471 }
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300472
473 if (config->rach_delay > 68) {
474 printf("RACH delay is too big %i\n\n", config->rach_delay);
475 print_help();
476 exit(0);
477 }
Thomas Tsou85b179d2013-11-15 21:14:33 -0500478}
479
480int main(int argc, char *argv[])
481{
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700482 int type, chans, ref;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500483 RadioDevice *usrp;
484 RadioInterface *radio = NULL;
485 Transceiver *trx = NULL;
Tom Tsou05c6feb2016-06-22 16:09:44 -0700486 RadioDevice::InterfaceType iface = RadioDevice::NORMAL;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500487 struct trx_config config;
488
489 handle_options(argc, argv, &config);
490
491 setup_signal_handlers();
492
493 /* Check database sanity */
494 if (!trx_setup_config(&config)) {
495 std::cerr << "Config: Database failure - exiting" << std::endl;
496 return EXIT_FAILURE;
497 }
498
499 gLogInit("transceiver", config.log_level.c_str(), LOG_LOCAL7);
500
501 srandom(time(NULL));
502
503 /* Create the low level device object */
Tom Tsou76764272016-06-24 14:25:39 -0700504 if (config.mcbts)
505 iface = RadioDevice::MULTI_ARFCN;
506
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700507 if (config.extref)
508 ref = RadioDevice::REF_EXTERNAL;
509 else if (config.gpsref)
510 ref = RadioDevice::REF_GPS;
511 else
512 ref = RadioDevice::REF_INTERNAL;
513
Tom Tsou05c6feb2016-06-22 16:09:44 -0700514 usrp = RadioDevice::make(config.tx_sps, config.rx_sps, iface,
515 config.chans, config.offset);
Tom Tsou2f3e60b2016-07-17 19:29:08 -0700516 type = usrp->open(config.dev_args, ref, config.swap_channels);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500517 if (type < 0) {
518 LOG(ALERT) << "Failed to create radio device" << std::endl;
519 goto shutdown;
520 }
521
522 /* Setup the appropriate device interface */
523 radio = makeRadioInterface(&config, usrp, type);
524 if (!radio)
525 goto shutdown;
526
527 /* Create the transceiver core */
528 trx = makeTransceiver(&config, radio);
529 if (!trx)
530 goto shutdown;
531
Thomas Tsou85b179d2013-11-15 21:14:33 -0500532 chans = trx->numChans();
533 std::cout << "-- Transceiver active with "
534 << chans << " channel(s)" << std::endl;
535
536 while (!gshutdown)
537 sleep(1);
538
539shutdown:
540 std::cout << "Shutting down transceiver..." << std::endl;
541
542 delete trx;
543 delete radio;
544 delete usrp;
545
546 return 0;
547}