blob: b95c28ed047b9d262f6d6d3eb310cbfb00f58c12 [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
91 int mOversamplingRate = numARFCN/2 + numARFCN;
kurtis.heimerl67e3d5a2011-11-26 03:19:13 +000092 RadioDevice *usrp = RadioDevice::make(DEVICERATE);
ttsouf60dafa2012-10-22 00:07:14 +000093 if (!usrp->open(deviceArgs)) {
kurtis.heimerle3320322011-11-28 06:26:08 +000094 LOG(ALERT) << "Transceiver exiting..." << std::endl;
kurtis.heimerl67e3d5a2011-11-26 03:19:13 +000095 return EXIT_FAILURE;
96 }
dburgessb3a0ca42011-10-12 07:44:40 +000097
98 RadioInterface* radio = new RadioInterface(usrp,3,SAMPSPERSYM,mOversamplingRate,false);
kurtis.heimerld3d4af32011-11-26 03:19:16 +000099 Transceiver *trx = new Transceiver(5700,"127.0.0.1",SAMPSPERSYM,GSM::Time(3,0),radio);
dburgessb3a0ca42011-10-12 07:44:40 +0000100 trx->receiveFIFO(radio->receiveFIFO());
101/*
102 signalVector *gsmPulse = generateGSMPulse(2,1);
103 BitVector normalBurstSeg = "0000101010100111110010101010010110101110011000111001101010000";
104 BitVector normalBurst(BitVector(normalBurstSeg,gTrainingSequence[0]),normalBurstSeg);
105 signalVector *modBurst = modulateBurst(normalBurst,*gsmPulse,8,1);
106 signalVector *modBurst9 = modulateBurst(normalBurst,*gsmPulse,9,1);
107 signalVector *interpolationFilter = createLPF(0.6/mOversamplingRate,6*mOversamplingRate,1);
108 signalVector totalBurst1(*modBurst,*modBurst9);
109 signalVector totalBurst2(*modBurst,*modBurst);
110 signalVector totalBurst(totalBurst1,totalBurst2);
111 scaleVector(totalBurst,usrp->fullScaleInputValue());
112 double beaconFreq = -1.0*(numARFCN-1)*200e3;
113 signalVector finalVec(625*mOversamplingRate);
114 for (int j = 0; j < numARFCN; j++) {
115 signalVector *frequencyShifter = new signalVector(625*mOversamplingRate);
116 frequencyShifter->fill(1.0);
117 frequencyShift(frequencyShifter,frequencyShifter,2.0*M_PI*(beaconFreq+j*400e3)/(1625.0e3/6.0*mOversamplingRate));
118 signalVector *interpVec = polyphaseResampleVector(totalBurst,mOversamplingRate,1,interpolationFilter);
119 multVector(*interpVec,*frequencyShifter);
120 addVector(finalVec,*interpVec);
121 }
122 signalVector::iterator itr = finalVec.begin();
123 short finalVecShort[2*finalVec.size()];
124 short *shortItr = finalVecShort;
125 while (itr < finalVec.end()) {
126 *shortItr++ = (short) (itr->real());
127 *shortItr++ = (short) (itr->imag());
128 itr++;
129 }
130 usrp->loadBurst(finalVecShort,finalVec.size());
131*/
132 trx->start();
133 //int i = 0;
134 while(!gbShutdown) { sleep(1); }//i++; if (i==60) break;}
135
136 cout << "Shutting down transceiver..." << endl;
137
138// trx->stop();
139 delete trx;
140// delete radio;
141}