blob: ac9cc488ecb99a86368a524518dca5925adf54a9 [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;
Alexander Chemerisf5fd5782015-05-24 18:56:51 -040075 Transceiver::FillerType filler;
Thomas Tsou85b179d2013-11-15 21:14:33 -050076 bool diversity;
Tom Tsou76764272016-06-24 14:25:39 -070077 bool mcbts;
Thomas Tsou8e17df72014-03-06 14:16:11 -050078 double offset;
Alexander Chemerise8905a02015-06-03 23:47:56 -040079 double rssi_offset;
Alexander Chemeris50747dc2015-06-07 01:07:45 -040080 bool swap_channels;
Tom Tsoub0aefcb2016-03-06 03:44:34 -080081 bool edge;
Thomas Tsou85b179d2013-11-15 21:14:33 -050082};
83
Thomas Tsou4de70be2013-11-17 18:54:52 -050084ConfigurationTable gConfig;
Thomas Tsou85b179d2013-11-15 21:14:33 -050085
86volatile bool gshutdown = false;
87
88/* Run sanity check on configuration table
89 * The global table constructor cannot provide notification in the
Thomas Tsou4de70be2013-11-17 18:54:52 -050090 * event of failure. Make sure that we can access the database,
Thomas Tsou85b179d2013-11-15 21:14:33 -050091 * write to it, and that it contains the bare minimum required keys.
92 */
Thomas Tsou4de70be2013-11-17 18:54:52 -050093bool testConfig()
Thomas Tsou85b179d2013-11-15 21:14:33 -050094{
Thomas Tsou4de70be2013-11-17 18:54:52 -050095 int val = 9999;
Thomas Tsou85b179d2013-11-15 21:14:33 -050096 std::string test = "asldfkjsaldkf";
97 const char *key = "Log.Level";
98
Thomas Tsou85b179d2013-11-15 21:14:33 -050099 /* Attempt to query */
100 try {
101 gConfig.getStr(key);
102 } catch (...) {
103 std::cerr << std::endl;
104 std::cerr << "Config: Failed query required key " << key
105 << std::endl;
106 return false;
107 }
108
Thomas Tsou4de70be2013-11-17 18:54:52 -0500109 /* Attempt to set a test value in the global config */
110 if (!gConfig.set(test, val)) {
111 std::cerr << std::endl;
112 std::cerr << "Config: Failed to set test key" << std::endl;
113 return false;
114 } else {
115 gConfig.remove(test);
116 }
117
Thomas Tsou85b179d2013-11-15 21:14:33 -0500118 return true;
119}
120
Thomas Tsou4de70be2013-11-17 18:54:52 -0500121
Thomas Tsou85b179d2013-11-15 21:14:33 -0500122/* Setup configuration values
123 * Don't query the existence of the Log.Level because it's a
124 * mandatory value. That is, if it doesn't exist, the configuration
Thomas Tsou4de70be2013-11-17 18:54:52 -0500125 * table will crash or will have already crashed. Everything else we
126 * can survive without and use default values if the database entries
Thomas Tsou85b179d2013-11-15 21:14:33 -0500127 * are empty.
128 */
129bool trx_setup_config(struct trx_config *config)
130{
Tom Tsou76764272016-06-24 14:25:39 -0700131 std::string refstr, fillstr, divstr, mcstr, edgestr;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500132
Thomas Tsou4de70be2013-11-17 18:54:52 -0500133 if (!testConfig())
Thomas Tsou85b179d2013-11-15 21:14:33 -0500134 return false;
135
136 if (config->log_level == "")
137 config->log_level = gConfig.getStr("Log.Level");
138
139 if (!config->port) {
140 if (gConfig.defines("TRX.Port"))
141 config->port = gConfig.getNum("TRX.Port");
142 else
143 config->port = DEFAULT_TRX_PORT;
144 }
145
146 if (config->addr == "") {
147 if (gConfig.defines("TRX.IP"))
148 config->addr = gConfig.getStr("TRX.IP");
149 else
150 config->addr = DEFAULT_TRX_IP;
151 }
152
153 if (!config->extref) {
154 if (gConfig.defines("TRX.Reference"))
155 config->extref = gConfig.getNum("TRX.Reference");
156 else
157 config->extref = DEFAULT_EXTREF;
158 }
159
160 if (!config->diversity) {
161 if (gConfig.defines("TRX.Diversity"))
162 config->diversity = gConfig.getNum("TRX.Diversity");
163 else
164 config->diversity = DEFAULT_DIVERSITY;
165 }
166
Tom Tsou76764272016-06-24 14:25:39 -0700167 if (!config->chans)
168 config->chans = DEFAULT_CHANS;
169
170 if (config->mcbts && ((config->chans < 0) || (config->chans > 5))) {
171 std::cout << "Unsupported number of channels" << std::endl;
172 return false;
173 }
174
175 /* Diversity only supported on 2 channels without multi-carrier */
176 if (config->diversity && config->mcbts) {
177 std::cout << "Multi-carrier diversity unsupported" << std::endl;
178 return false;
179 }
180 if (config->diversity && (config->chans != 2)) {
181 std::cout << "Setting channels to 2 for diversity" << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500182 config->chans = 2;
Tom Tsou76764272016-06-24 14:25:39 -0700183 }
Thomas Tsou85b179d2013-11-15 21:14:33 -0500184
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800185 edgestr = config->edge ? "Enabled" : "Disabled";
Thomas Tsou85b179d2013-11-15 21:14:33 -0500186 refstr = config->extref ? "Enabled" : "Disabled";
187 divstr = config->diversity ? "Enabled" : "Disabled";
Tom Tsou76764272016-06-24 14:25:39 -0700188 mcstr = config->mcbts ? "Enabled" : "Disabled";
189
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400190 switch (config->filler) {
191 case Transceiver::FILLER_DUMMY:
192 fillstr = "Dummy bursts";
193 break;
194 case Transceiver::FILLER_ZERO:
195 fillstr = "Disabled";
196 break;
Tom Tsouaf717b22016-03-06 22:19:15 -0800197 case Transceiver::FILLER_NORM_RAND:
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400198 fillstr = "Normal busrts with random payload";
199 break;
Tom Tsouaf717b22016-03-06 22:19:15 -0800200 case Transceiver::FILLER_EDGE_RAND:
201 fillstr = "EDGE busrts with random payload";
202 break;
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300203 case Transceiver::FILLER_ACCESS_RAND:
204 fillstr = "Access busrts with random payload";
205 break;
Alexander Chemerisf5fd5782015-05-24 18:56:51 -0400206 }
Thomas Tsou85b179d2013-11-15 21:14:33 -0500207
208 std::ostringstream ost("");
209 ost << "Config Settings" << std::endl;
210 ost << " Log Level............... " << config->log_level << std::endl;
211 ost << " Device args............. " << config->dev_args << std::endl;
212 ost << " TRX Base Port........... " << config->port << std::endl;
213 ost << " TRX Address............. " << config->addr << std::endl;
214 ost << " Channels................ " << config->chans << std::endl;
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800215 ost << " Tx Samples-per-Symbol... " << config->tx_sps << std::endl;
Alexander Chemeris1ab5e7f2016-04-20 08:44:55 +0300216 ost << " Rx Samples-per-Symbol... " << config->rx_sps << std::endl;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800217 ost << " EDGE support............ " << edgestr << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500218 ost << " External Reference...... " << refstr << std::endl;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500219 ost << " C0 Filler Table......... " << fillstr << std::endl;
Tom Tsou76764272016-06-24 14:25:39 -0700220 ost << " Multi-Carrier........... " << mcstr << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500221 ost << " Diversity............... " << divstr << std::endl;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500222 ost << " Tuning offset........... " << config->offset << std::endl;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400223 ost << " RSSI to dBm offset...... " << config->rssi_offset << std::endl;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400224 ost << " Swap channels........... " << config->swap_channels << std::endl;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500225 std::cout << ost << std::endl;
226
227 return true;
228}
229
230/* Create radio interface
231 * The interface consists of sample rate changes, frequency shifts,
232 * channel multiplexing, and other conversions. The transceiver core
233 * accepts input vectors sampled at multiples of the GSM symbol rate.
234 * The radio interface connects the main transceiver with the device
235 * object, which may be operating some other rate.
236 */
237RadioInterface *makeRadioInterface(struct trx_config *config,
238 RadioDevice *usrp, int type)
239{
240 RadioInterface *radio = NULL;
241
242 switch (type) {
243 case RadioDevice::NORMAL:
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800244 radio = new RadioInterface(usrp, config->tx_sps,
245 config->rx_sps, config->chans);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500246 break;
247 case RadioDevice::RESAMP_64M:
248 case RadioDevice::RESAMP_100M:
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800249 radio = new RadioInterfaceResamp(usrp, config->tx_sps,
250 config->chans);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500251 break;
252 case RadioDevice::DIVERSITY:
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800253 radio = new RadioInterfaceDiversity(usrp, config->tx_sps,
254 config->chans);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500255 break;
Tom Tsou76764272016-06-24 14:25:39 -0700256 case RadioDevice::MULTI_ARFCN:
257 radio = new RadioInterfaceMulti(usrp, config->tx_sps,
258 config->rx_sps, config->chans);
259 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500260 default:
261 LOG(ALERT) << "Unsupported radio interface configuration";
262 return NULL;
263 }
264
265 if (!radio->init(type)) {
266 LOG(ALERT) << "Failed to initialize radio interface";
267 return NULL;
268 }
269
270 return radio;
271}
272
273/* Create transceiver core
274 * The multi-threaded modem core operates at multiples of the GSM rate of
275 * 270.8333 ksps and consists of GSM specific modulation, demodulation,
276 * and decoding schemes. Also included are the socket interfaces for
277 * connecting to the upper layer stack.
278 */
279Transceiver *makeTransceiver(struct trx_config *config, RadioInterface *radio)
280{
281 Transceiver *trx;
282 VectorFIFO *fifo;
283
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800284 trx = new Transceiver(config->port, config->addr.c_str(),
285 config->tx_sps, config->rx_sps, config->chans,
286 GSM::Time(3,0), radio, config->rssi_offset);
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300287 if (!trx->init(config->filler, config->rtsc, config->rach_delay)) {
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"
Thomas Tsou85b179d2013-11-15 21:14:33 -0500333 " -d Enable dual channel diversity receiver\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 Tsou2e4ed102016-06-27 15:39:16 -0700336 " -s Tx samples-per-symbol (1 or 4)\n"
337 " -b Rx samples-per-symbol (1 or 4)\n"
Thomas Tsou15d743e2014-01-25 02:34:03 -0500338 " -c Number of ARFCN channels (default=1)\n"
Thomas Tsou8e17df72014-03-06 14:16:11 -0500339 " -f Enable C0 filler table\n"
Tom Tsou64ad7122015-05-19 18:26:31 -0700340 " -o Set baseband frequency offset (default=auto)\n"
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300341 " -r Random Normal Burst test mode with TSC\n"
342 " -A Random Access Burst test mode with delay\n"
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400343 " -R RSSI to dBm offset in dB (default=0)\n"
344 " -S Swap channels (UmTRX only)\n",
Thomas Tsou85b179d2013-11-15 21:14:33 -0500345 "EMERG, ALERT, CRT, ERR, WARNING, NOTICE, INFO, DEBUG");
346}
347
348static void handle_options(int argc, char **argv, struct trx_config *config)
349{
350 int option;
351
352 config->port = 0;
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800353 config->tx_sps = DEFAULT_TX_SPS;
354 config->rx_sps = DEFAULT_RX_SPS;
Tom Tsou64ad7122015-05-19 18:26:31 -0700355 config->chans = DEFAULT_CHANS;
356 config->rtsc = 0;
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300357 config->rach_delay = 0;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500358 config->extref = false;
Tom Tsou64ad7122015-05-19 18:26:31 -0700359 config->filler = Transceiver::FILLER_ZERO;
Tom Tsou76764272016-06-24 14:25:39 -0700360 config->mcbts = false;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500361 config->diversity = false;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500362 config->offset = 0.0;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400363 config->rssi_offset = 0.0;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400364 config->swap_channels = false;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800365 config->edge = false;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500366
Tom Tsou76764272016-06-24 14:25:39 -0700367 while ((option = getopt(argc, argv, "ha:l:i:p:c:dmxfo:s:b:r:A:R:Se")) != -1) {
Thomas Tsou85b179d2013-11-15 21:14:33 -0500368 switch (option) {
369 case 'h':
370 print_help();
371 exit(0);
372 break;
373 case 'a':
374 config->dev_args = optarg;
375 break;
376 case 'l':
377 config->log_level = optarg;
378 break;
379 case 'i':
380 config->addr = optarg;
381 break;
382 case 'p':
383 config->port = atoi(optarg);
384 break;
385 case 'c':
386 config->chans = atoi(optarg);
387 break;
Tom Tsou76764272016-06-24 14:25:39 -0700388 case 'm':
389 config->mcbts = true;
390 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500391 case 'd':
392 config->diversity = true;
393 break;
394 case 'x':
395 config->extref = true;
396 break;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500397 case 'f':
Tom Tsou64ad7122015-05-19 18:26:31 -0700398 config->filler = Transceiver::FILLER_DUMMY;
Thomas Tsou15d743e2014-01-25 02:34:03 -0500399 break;
Thomas Tsou8e17df72014-03-06 14:16:11 -0500400 case 'o':
401 config->offset = atof(optarg);
402 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500403 case 's':
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800404 config->tx_sps = atoi(optarg);
Tom Tsou64ad7122015-05-19 18:26:31 -0700405 break;
Tom Tsou2e4ed102016-06-27 15:39:16 -0700406 case 'b':
407 config->rx_sps = atoi(optarg);
408 break;
Tom Tsou64ad7122015-05-19 18:26:31 -0700409 case 'r':
410 config->rtsc = atoi(optarg);
Tom Tsouaf717b22016-03-06 22:19:15 -0800411 config->filler = Transceiver::FILLER_NORM_RAND;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500412 break;
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300413 case 'A':
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300414 config->rach_delay = atoi(optarg);
Alexander Chemeris5efe0502016-03-23 17:06:32 +0300415 config->filler = Transceiver::FILLER_ACCESS_RAND;
416 break;
Alexander Chemerise8905a02015-06-03 23:47:56 -0400417 case 'R':
418 config->rssi_offset = atof(optarg);
419 break;
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400420 case 'S':
421 config->swap_channels = true;
422 break;
Tom Tsoub0aefcb2016-03-06 03:44:34 -0800423 case 'e':
424 config->edge = true;
425 config->rx_sps = 4;
426 break;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500427 default:
428 print_help();
429 exit(0);
430 }
431 }
Tom Tsou64ad7122015-05-19 18:26:31 -0700432
Tom Tsou76764272016-06-24 14:25:39 -0700433 /* Force 4 SPS for EDGE or multi-ARFCN configurations */
434 if ((config->edge) || (config->mcbts)) {
Tom Tsou2e4ed102016-06-27 15:39:16 -0700435 config->tx_sps = 4;
436 config->rx_sps = 4;
437 }
438
Tom Tsouaf717b22016-03-06 22:19:15 -0800439 if (config->edge && (config->filler == Transceiver::FILLER_NORM_RAND))
440 config->filler = Transceiver::FILLER_EDGE_RAND;
441
Tom Tsou76764272016-06-24 14:25:39 -0700442 if ((config->tx_sps != 1) && (config->tx_sps != 4) &&
443 (config->rx_sps != 1) && (config->rx_sps != 4)) {
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800444 printf("Unsupported samples-per-symbol %i\n\n", config->tx_sps);
Tom Tsou64ad7122015-05-19 18:26:31 -0700445 print_help();
446 exit(0);
447 }
448
449 if (config->rtsc > 7) {
450 printf("Invalid training sequence %i\n\n", config->rtsc);
451 print_help();
452 exit(0);
453 }
Alexander Chemeris37c52c72016-03-25 18:28:34 +0300454
455 if (config->rach_delay > 68) {
456 printf("RACH delay is too big %i\n\n", config->rach_delay);
457 print_help();
458 exit(0);
459 }
Thomas Tsou85b179d2013-11-15 21:14:33 -0500460}
461
462int main(int argc, char *argv[])
463{
464 int type, chans;
465 RadioDevice *usrp;
466 RadioInterface *radio = NULL;
467 Transceiver *trx = NULL;
Tom Tsou05c6feb2016-06-22 16:09:44 -0700468 RadioDevice::InterfaceType iface = RadioDevice::NORMAL;
Thomas Tsou85b179d2013-11-15 21:14:33 -0500469 struct trx_config config;
470
471 handle_options(argc, argv, &config);
472
473 setup_signal_handlers();
474
475 /* Check database sanity */
476 if (!trx_setup_config(&config)) {
477 std::cerr << "Config: Database failure - exiting" << std::endl;
478 return EXIT_FAILURE;
479 }
480
481 gLogInit("transceiver", config.log_level.c_str(), LOG_LOCAL7);
482
483 srandom(time(NULL));
484
485 /* Create the low level device object */
Tom Tsou76764272016-06-24 14:25:39 -0700486 if (config.mcbts)
487 iface = RadioDevice::MULTI_ARFCN;
488
Tom Tsou05c6feb2016-06-22 16:09:44 -0700489 usrp = RadioDevice::make(config.tx_sps, config.rx_sps, iface,
490 config.chans, config.offset);
Alexander Chemeris50747dc2015-06-07 01:07:45 -0400491 type = usrp->open(config.dev_args, config.extref, config.swap_channels);
Thomas Tsou85b179d2013-11-15 21:14:33 -0500492 if (type < 0) {
493 LOG(ALERT) << "Failed to create radio device" << std::endl;
494 goto shutdown;
495 }
496
497 /* Setup the appropriate device interface */
498 radio = makeRadioInterface(&config, usrp, type);
499 if (!radio)
500 goto shutdown;
501
502 /* Create the transceiver core */
503 trx = makeTransceiver(&config, radio);
504 if (!trx)
505 goto shutdown;
506
Thomas Tsou85b179d2013-11-15 21:14:33 -0500507 chans = trx->numChans();
508 std::cout << "-- Transceiver active with "
509 << chans << " channel(s)" << std::endl;
510
511 while (!gshutdown)
512 sleep(1);
513
514shutdown:
515 std::cout << "Shutting down transceiver..." << std::endl;
516
517 delete trx;
518 delete radio;
519 delete usrp;
520
521 return 0;
522}