From 3eeda4841ded1df4b5384df09b1358d5ef440cae Mon Sep 17 00:00:00 2001 From: Thomas Tsou Date: Thu, 29 Mar 2012 19:39:40 -0400 Subject: multi-arfcn, trx: create transceivers based on command line arg Move from the hard coded case of 3 transceiver instances to a command line determined value. 'M' potential channels will be compiled into the build depending on preprocessor selections in radioParams.h. The command line argument must be less M. Channels are selected starting from 0, which is centered on the RF tuning frequency. Subsequent channels are selected by shifting outward from 0 (center) in a left before right pattern. Default channel spacing is 400 kHz. The ordering for supported cases of 1, 5, and 10 path channelizers is as follows. CHAN_M = 1 { 0 } CHAN_M = 5 { 0, 1, 4, 2, 3 } CHAN_M = 10 { 0, 1, 9, 2, 8, 3, 7, 4, 6, 5} Note: Channel 5 for the 10 channel case sits on the Nyquist frequency and is therefor unusable. Signed-off-by: Thomas Tsou --- Transceiver52M/multiTRX.cpp | 81 +++++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 22 deletions(-) diff --git a/Transceiver52M/multiTRX.cpp b/Transceiver52M/multiTRX.cpp index b93d9f0..85d4046 100644 --- a/Transceiver52M/multiTRX.cpp +++ b/Transceiver52M/multiTRX.cpp @@ -55,21 +55,69 @@ static int setupSignals() return 0; } +/* + * Generate the channel-transceiver ordering. Channel 0 is always centered + * at the RF tuning frequecy. Fill remaining channels alternating left and + * right moving out from the center channel. + */ +static void genChanMap(int *chans) +{ + int i, n; + + chans[0] = 0; + + for (i = 1, n = 1; i < CHAN_M; i++) { + if (i % 2) { + chans[i] = n; + } else { + chans[i] = CHAN_M - n; + n++; + } + } +} + +static void createTrx(Transceiver **trx, int *map, int num, + RadioInterface *radio, DriveLoop *drive) +{ + int i; + + for (i = 0; i < num; i++) { + LOG(NOTICE) << "Creating TRX" << i + << " attached on channel " << map[i]; + + radio->activateChan(map[i]); + trx[i] = new Transceiver(5700 + i * 1000, "127.0.0.1", + SAMPSPERSYM, radio, drive, map[i]); + trx[i]->start(); + } +} + int main(int argc, char *argv[]) { + int i, numARFCN = 1; + int chanMap[CHAN_M]; RadioDevice *usrp; RadioInterface* radio; DriveLoop *drive; - Transceiver *trx0, *trx1, *trx2; + Transceiver *trx[CHAN_M]; gLogInit("transceiver", gConfig.getStr("Log.Level").c_str(), LOG_LOCAL7); + if (argc > 1) { + numARFCN = atoi(argv[1]); + if (numARFCN > CHAN_M) { + LOG(ALERT) << numARFCN << " channels not supported with current build"; + exit(-1); + } + } + if (setupSignals() < 0) { LOG(ERR) << "Failed to setup signal handlers, exiting..."; exit(-1); } srandom(time(NULL)); + genChanMap(chanMap); usrp = RadioDevice::make(DEVICERATE); if (!usrp->open()) { @@ -77,41 +125,30 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - radio = new RadioInterface(usrp, 3, SAMPSPERSYM, 0, false); + radio = new RadioInterface(usrp, numARFCN, SAMPSPERSYM, 0, false); drive = new DriveLoop(SAMPSPERSYM, GSM::Time(3,0), radio); - LOG(NOTICE) << "Creating TRX0"; - trx0 = new Transceiver(5700, "127.0.0.1", SAMPSPERSYM, radio, drive, 0); - radio->activateChan(0); - trx0->start(); - - LOG(NOTICE) << "Creating TRX1"; - trx1 = new Transceiver(6700, "127.0.0.1", SAMPSPERSYM, radio, drive, 1); - radio->activateChan(1); - trx1->start(); - - LOG(NOTICE) << "Creating TRX2"; - trx2 = new Transceiver(7700, "127.0.0.1", SAMPSPERSYM, radio, drive, 4); - radio->activateChan(4); - trx2->start(); + /* Create, attach, and activate all transceivers */ + createTrx(trx, chanMap, numARFCN, radio, drive); while (!gbShutdown) { sleep(1); } LOG(NOTICE) << "Shutting down transceivers..."; - trx0->shutdown(); - trx1->shutdown(); - trx2->shutdown(); + for (i = 0; i < numARFCN; i++) { + trx[i]->shutdown(); + } /* * Allow time for threads to end before we start freeing objects */ sleep(2); - delete trx0; - delete trx1; - delete trx2; + for (i = 0; i < numARFCN; i++) { + delete trx[i]; + } + delete drive; delete radio; delete usrp; -- cgit v1.2.3