blob: db332511ee59f95b02ccdefb24833a88a5b38588 [file] [log] [blame]
dburgessb3a0ca42011-10-12 07:44:40 +00001/*
2* Copyright 2008, 2009, 2010 Free Software Foundation, Inc.
3* Copyright 2010 Kestrel Signal Processing, Inc.
4*
5* This software is distributed under the terms of the GNU Affero Public License.
6* See the COPYING file in the main directory for details.
7*
8* This use of this software may be subject to additional restrictions.
9* See the LEGAL file in the main directory for details.
10
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU Affero General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU Affero General Public License for more details.
20
21 You should have received a copy of the GNU Affero General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
23
24*/
25
26
27
28#include "Transceiver.h"
kurtis.heimerl67e3d5a2011-11-26 03:19:13 +000029#include "radioDevice.h"
dburgessb3a0ca42011-10-12 07:44:40 +000030#include "DummyLoad.h"
31
32#include <time.h>
33#include <signal.h>
34
35#include <GSMCommon.h>
36#include <Logger.h>
37#include <Configuration.h>
38
kurtis.heimerl67e3d5a2011-11-26 03:19:13 +000039#ifdef RESAMPLE
40 #define DEVICERATE 400e3
41#else
42 #define DEVICERATE 1625e3/6
43#endif
44
dburgessb3a0ca42011-10-12 07:44:40 +000045using namespace std;
46
47ConfigurationTable gConfig("/etc/OpenBTS/OpenBTS.db");
48
49
50volatile bool gbShutdown = false;
51static void ctrlCHandler(int signo)
52{
53 cout << "Received shutdown signal" << endl;;
54 gbShutdown = true;
55}
56
57
58int main(int argc, char *argv[])
59{
ttsouf60dafa2012-10-22 00:07:14 +000060 std::string deviceArgs;
61
62 if (argc == 3)
63 {
64 deviceArgs = std::string(argv[2]);
65 }
66 else
67 {
68 deviceArgs = "";
69 }
70
dburgessb3a0ca42011-10-12 07:44:40 +000071 if ( signal( SIGINT, ctrlCHandler ) == SIG_ERR )
72 {
73 cerr << "Couldn't install signal handler for SIGINT" << endl;
74 exit(1);
75 }
76
77 if ( signal( SIGTERM, ctrlCHandler ) == SIG_ERR )
78 {
79 cerr << "Couldn't install signal handler for SIGTERM" << endl;
80 exit(1);
81 }
82 // Configure logger.
83 gLogInit("transceiver",gConfig.getStr("Log.Level").c_str(),LOG_LOCAL7);
84
85 int numARFCN=1;
86
87 LOG(NOTICE) << "starting transceiver with " << numARFCN << " ARFCNs (argc=" << argc << ")";
88
89 srandom(time(NULL));
90
Thomas Tsoue3e88142013-04-05 20:42:41 -040091 RadioDevice *usrp = RadioDevice::make(DEVICERATE * SAMPSPERSYM, SAMPSPERSYM);
ttsouf60dafa2012-10-22 00:07:14 +000092 if (!usrp->open(deviceArgs)) {
kurtis.heimerle3320322011-11-28 06:26:08 +000093 LOG(ALERT) << "Transceiver exiting..." << std::endl;
kurtis.heimerl67e3d5a2011-11-26 03:19:13 +000094 return EXIT_FAILURE;
95 }
dburgessb3a0ca42011-10-12 07:44:40 +000096
Thomas Tsou312e3872013-04-08 13:45:55 -040097 RadioInterface* radio = new RadioInterface(usrp,3,SAMPSPERSYM,false);
ttsoud3564ff2012-12-16 20:48:47 +000098 Transceiver *trx = new Transceiver(gConfig.getNum("TRX.Port"),gConfig.getStr("TRX.IP").c_str(),SAMPSPERSYM,GSM::Time(3,0),radio);
dburgessb3a0ca42011-10-12 07:44:40 +000099 trx->receiveFIFO(radio->receiveFIFO());
100/*
101 signalVector *gsmPulse = generateGSMPulse(2,1);
102 BitVector normalBurstSeg = "0000101010100111110010101010010110101110011000111001101010000";
103 BitVector normalBurst(BitVector(normalBurstSeg,gTrainingSequence[0]),normalBurstSeg);
104 signalVector *modBurst = modulateBurst(normalBurst,*gsmPulse,8,1);
105 signalVector *modBurst9 = modulateBurst(normalBurst,*gsmPulse,9,1);
106 signalVector *interpolationFilter = createLPF(0.6/mOversamplingRate,6*mOversamplingRate,1);
107 signalVector totalBurst1(*modBurst,*modBurst9);
108 signalVector totalBurst2(*modBurst,*modBurst);
109 signalVector totalBurst(totalBurst1,totalBurst2);
110 scaleVector(totalBurst,usrp->fullScaleInputValue());
111 double beaconFreq = -1.0*(numARFCN-1)*200e3;
112 signalVector finalVec(625*mOversamplingRate);
113 for (int j = 0; j < numARFCN; j++) {
114 signalVector *frequencyShifter = new signalVector(625*mOversamplingRate);
115 frequencyShifter->fill(1.0);
116 frequencyShift(frequencyShifter,frequencyShifter,2.0*M_PI*(beaconFreq+j*400e3)/(1625.0e3/6.0*mOversamplingRate));
117 signalVector *interpVec = polyphaseResampleVector(totalBurst,mOversamplingRate,1,interpolationFilter);
118 multVector(*interpVec,*frequencyShifter);
119 addVector(finalVec,*interpVec);
120 }
121 signalVector::iterator itr = finalVec.begin();
122 short finalVecShort[2*finalVec.size()];
123 short *shortItr = finalVecShort;
124 while (itr < finalVec.end()) {
125 *shortItr++ = (short) (itr->real());
126 *shortItr++ = (short) (itr->imag());
127 itr++;
128 }
129 usrp->loadBurst(finalVecShort,finalVec.size());
130*/
131 trx->start();
132 //int i = 0;
133 while(!gbShutdown) { sleep(1); }//i++; if (i==60) break;}
134
135 cout << "Shutting down transceiver..." << endl;
136
137// trx->stop();
138 delete trx;
139// delete radio;
140}